|
| 1 | +import { getCursorlessApi, openNewEditor } from "@cursorless/vscode-common"; |
| 2 | +import { |
| 3 | + ScopeSupport, |
| 4 | + ScopeSupportInfo, |
| 5 | + ScopeSupportLevels, |
| 6 | +} from "@cursorless/common"; |
| 7 | +import Sinon = require("sinon"); |
| 8 | +import { sleepWithBackoff } from "../../endToEndTestSetup"; |
| 9 | +import { commands } from "vscode"; |
| 10 | +import { assertCalledWithScopeInfo } from "./assertCalledWithScopeInfo"; |
| 11 | + |
| 12 | +/** |
| 13 | + * Tests that the scope provider correctly reports the scope support for a |
| 14 | + * simple named function. |
| 15 | + */ |
| 16 | +export async function runBasicScopeInfoTest() { |
| 17 | + const { scopeProvider } = (await getCursorlessApi()).testHelpers!; |
| 18 | + const fake = Sinon.fake<[scopeInfos: ScopeSupportLevels], void>(); |
| 19 | + |
| 20 | + await commands.executeCommand("workbench.action.closeAllEditors"); |
| 21 | + |
| 22 | + const disposable = scopeProvider.onDidChangeScopeSupport(fake); |
| 23 | + |
| 24 | + try { |
| 25 | + assertCalledWithScopeInfo(fake, unsupported); |
| 26 | + |
| 27 | + await openNewEditor(contents, { |
| 28 | + languageId: "typescript", |
| 29 | + }); |
| 30 | + await sleepWithBackoff(25); |
| 31 | + |
| 32 | + assertCalledWithScopeInfo(fake, present); |
| 33 | + |
| 34 | + await commands.executeCommand("workbench.action.closeAllEditors"); |
| 35 | + await sleepWithBackoff(25); |
| 36 | + |
| 37 | + assertCalledWithScopeInfo(fake, unsupported); |
| 38 | + } finally { |
| 39 | + disposable.dispose(); |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +const contents = ` |
| 44 | +function helloWorld() { |
| 45 | +
|
| 46 | +} |
| 47 | +`; |
| 48 | + |
| 49 | +function getExpectedScope(scopeSupport: ScopeSupport): ScopeSupportInfo { |
| 50 | + return { |
| 51 | + humanReadableName: "named function", |
| 52 | + isLanguageSpecific: true, |
| 53 | + iterationScopeSupport: scopeSupport, |
| 54 | + scopeType: { |
| 55 | + type: "namedFunction", |
| 56 | + }, |
| 57 | + spokenForm: { |
| 58 | + alternatives: [], |
| 59 | + preferred: "funk", |
| 60 | + type: "success", |
| 61 | + }, |
| 62 | + support: scopeSupport, |
| 63 | + }; |
| 64 | +} |
| 65 | + |
| 66 | +const unsupported = getExpectedScope(ScopeSupport.unsupported); |
| 67 | +const present = getExpectedScope(ScopeSupport.supportedAndPresentInEditor); |
0 commit comments