diff --git a/cursorless-talon/src/command.py b/cursorless-talon/src/command.py index cee63df523..13d5033983 100644 --- a/cursorless-talon/src/command.py +++ b/cursorless-talon/src/command.py @@ -5,10 +5,12 @@ from .fallback import perform_fallback +COMMAND_VERSION = 7 + @dataclasses.dataclass class CursorlessCommand: - version = 7 + version = COMMAND_VERSION spokenForm: str usePrePhraseSnapshot: bool action: dict diff --git a/cursorless-talon/src/fallback.py b/cursorless-talon/src/fallback.py index 12ad3dc51a..ea476ecb6d 100644 --- a/cursorless-talon/src/fallback.py +++ b/cursorless-talon/src/fallback.py @@ -2,6 +2,11 @@ from talon import actions +from .command import COMMAND_VERSION + +# This ensures that we remember to update fallback if the response payload changes +assert COMMAND_VERSION == 7 + action_callbacks = { "getText": lambda: [actions.edit.selected_text()], "setSelection": actions.skip, diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index 7a663b6d77..61badf4813 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -96,7 +96,7 @@ export * from "./types/TestCaseFixture"; export * from "./util/getEnvironmentVariableStrict"; export * from "./util/CompositeKeyDefaultMap"; export * from "./util/toPlainObject"; -export * from "./util/clientSupportsFallBack"; +export * from "./util/clientSupportsFallback"; export * from "./scopeSupportFacets/scopeSupportFacets.types"; export * from "./scopeSupportFacets/scopeSupportFacetInfos"; export * from "./scopeSupportFacets/textualScopeSupportFacetInfos"; diff --git a/packages/common/src/testUtil/serializeTestFixture.ts b/packages/common/src/testUtil/serializeTestFixture.ts index edf04d43fb..07c5ef45c1 100644 --- a/packages/common/src/testUtil/serializeTestFixture.ts +++ b/packages/common/src/testUtil/serializeTestFixture.ts @@ -7,6 +7,7 @@ function reorderFields( ): EnforceUndefined { return { languageId: fixture.languageId, + focusedElementType: fixture.focusedElementType, postEditorOpenSleepTimeMs: fixture.postEditorOpenSleepTimeMs, postCommandSleepTimeMs: fixture.postCommandSleepTimeMs, command: fixture.command, diff --git a/packages/common/src/types/TestCaseFixture.ts b/packages/common/src/types/TestCaseFixture.ts index 7fceab66d0..7b366e694a 100644 --- a/packages/common/src/types/TestCaseFixture.ts +++ b/packages/common/src/types/TestCaseFixture.ts @@ -1,4 +1,4 @@ -import type { Command, CommandLatest, Fallback } from ".."; +import type { Command, CommandLatest, Fallback, FocusedElementType } from ".."; import type { TestCaseSnapshot } from "../testUtil/TestCaseSnapshot"; import type { PlainSpyIDERecordedValues } from "../testUtil/spyToPlainObject"; @@ -12,6 +12,11 @@ interface TestCaseFixtureBase { postCommandSleepTimeMs?: number; spokenFormError?: string; + /** + * The type of element that is focused before the command is executed. If undefined default to text editor. + */ + focusedElementType?: FocusedElementType | "other"; + /** * A list of marks to check in the case of navigation map test otherwise undefined */ diff --git a/packages/cursorless-engine/src/testCaseRecorder/TestCase.ts b/packages/cursorless-engine/src/testCaseRecorder/TestCase.ts index 8f365afba9..0dd2dad532 100644 --- a/packages/cursorless-engine/src/testCaseRecorder/TestCase.ts +++ b/packages/cursorless-engine/src/testCaseRecorder/TestCase.ts @@ -6,6 +6,7 @@ import { extractTargetedMarks, ExtraSnapshotField, Fallback, + FocusedElementType, marksToPlainObject, PartialTargetDescriptor, PlainSpyIDERecordedValues, @@ -43,6 +44,7 @@ export class TestCase { constructor( command: CommandLatest, + private focusedElementType: FocusedElementType | undefined, private hatTokenMap: ReadOnlyHatMap, private storedTargets: StoredTargetMap, private spyIde: SpyIDE, @@ -138,6 +140,10 @@ export class TestCase { } const fixture: EnforceUndefined = { languageId: this.languageId, + focusedElementType: + this.focusedElementType !== "textEditor" + ? this.focusedElementType ?? "other" + : undefined, postEditorOpenSleepTimeMs: undefined, postCommandSleepTimeMs: undefined, command: this.command, diff --git a/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts b/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts index 52e9d97924..8be2e5bb06 100644 --- a/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts +++ b/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts @@ -2,6 +2,7 @@ import { CommandComplete, CommandLatest, CommandResponse, + CommandServerApi, DecoratedSymbolMark, DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST, extractTargetedMarks, @@ -64,6 +65,7 @@ export class TestCaseRecorder { private spokenFormGenerator = new SpokenFormGenerator(defaultSpokenFormMap); constructor( + private commandServerApi: CommandServerApi | null, private hatTokenMap: HatTokenMap, private storedTargets: StoredTargetMap, ) { @@ -293,6 +295,7 @@ export class TestCaseRecorder { ? spokenForm.spokenForms[0] : command.spokenForm, }, + this.commandServerApi?.getFocusedElementType(), hatTokenMap, this.storedTargets, this.spyIde, diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/bringFine.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/bringFine.yml index c2edc066b9..ea198925ff 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/bringFine.yml +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/bringFine.yml @@ -1,4 +1,5 @@ languageId: plaintext +focusedElementType: other command: version: 7 spokenForm: bring fine diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/bringFine2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/bringFine2.yml new file mode 100644 index 0000000000..c958dbced7 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/bringFine2.yml @@ -0,0 +1,30 @@ +languageId: plaintext +focusedElementType: terminal +command: + version: 7 + spokenForm: bring fine + action: + name: replaceWithTarget + source: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: f} + destination: {type: implicit} + usePrePhraseSnapshot: true +initialState: + documentContents: foo + selections: + - anchor: {line: 0, character: 3} + active: {line: 0, character: 3} + marks: + default.f: + start: {line: 0, character: 0} + end: {line: 0, character: 3} +finalState: + documentContents: foo + selections: + - anchor: {line: 0, character: 3} + active: {line: 0, character: 3} +fallback: + action: insert + modifiers: [] + text: foo diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/chuckFine.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/chuckFine.yml new file mode 100644 index 0000000000..a985094caa --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/chuckFine.yml @@ -0,0 +1,25 @@ +languageId: plaintext +focusedElementType: terminal +command: + version: 7 + spokenForm: chuck fine + action: + name: remove + target: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: f} + usePrePhraseSnapshot: true +initialState: + documentContents: foo + selections: + - anchor: {line: 0, character: 3} + active: {line: 0, character: 3} + marks: + default.f: + start: {line: 0, character: 0} + end: {line: 0, character: 3} +finalState: + documentContents: "" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/chuckFine2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/chuckFine2.yml new file mode 100644 index 0000000000..11d80818b5 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/chuckFine2.yml @@ -0,0 +1,25 @@ +languageId: plaintext +focusedElementType: other +command: + version: 7 + spokenForm: chuck fine + action: + name: remove + target: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: f} + usePrePhraseSnapshot: true +initialState: + documentContents: foo + selections: + - anchor: {line: 0, character: 3} + active: {line: 0, character: 3} + marks: + default.f: + start: {line: 0, character: 0} + end: {line: 0, character: 3} +finalState: + documentContents: "" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/moveFine.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/moveFine.yml index 4522b35e13..7bf0f45f6b 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/moveFine.yml +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/moveFine.yml @@ -1,4 +1,5 @@ languageId: plaintext +focusedElementType: other command: version: 7 spokenForm: move fine diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/takeThis.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/takeThis.yml index d1020fe6ca..3ede086e32 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/takeThis.yml +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/takeThis.yml @@ -1,4 +1,5 @@ languageId: plaintext +focusedElementType: other command: version: 7 spokenForm: take this diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/takeToken.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/takeToken.yml index 4aa0779335..e42b5c19c3 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/takeToken.yml +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/fallback/takeToken.yml @@ -1,4 +1,5 @@ languageId: plaintext +focusedElementType: other command: version: 7 spokenForm: take token diff --git a/packages/cursorless-vscode-e2e/src/suite/recorded.vscode.test.ts b/packages/cursorless-vscode-e2e/src/suite/recorded.vscode.test.ts index 9158290e80..22258d170c 100644 --- a/packages/cursorless-vscode-e2e/src/suite/recorded.vscode.test.ts +++ b/packages/cursorless-vscode-e2e/src/suite/recorded.vscode.test.ts @@ -105,7 +105,9 @@ async function runTest(file: string, spyIde: SpyIDE) { } commandServerApi.setFocusedElementType( - fixture.fallback == null ? "textEditor" : undefined, + fixture.focusedElementType === "other" + ? undefined + : fixture.focusedElementType ?? "textEditor", ); // Ensure that the expected hats are present diff --git a/packages/cursorless-vscode/src/extension.ts b/packages/cursorless-vscode/src/extension.ts index 38c5d3a9b9..fcc7e2334d 100644 --- a/packages/cursorless-vscode/src/extension.ts +++ b/packages/cursorless-vscode/src/extension.ts @@ -104,7 +104,11 @@ export async function activate( new CommandHistory(normalizedIde, commandServerApi, fileSystem), ); - const testCaseRecorder = new TestCaseRecorder(hatTokenMap, storedTargets); + const testCaseRecorder = new TestCaseRecorder( + commandServerApi, + hatTokenMap, + storedTargets, + ); addCommandRunnerDecorator(testCaseRecorder); const statusBarItem = StatusBarItem.create("cursorless.showQuickPick"); diff --git a/packages/cursorless-vscode/src/scripts/populateDist/transformPackageJson.ts b/packages/cursorless-vscode/src/scripts/populateDist/transformPackageJson.ts index d33c31dbdc..92572383d4 100644 --- a/packages/cursorless-vscode/src/scripts/populateDist/transformPackageJson.ts +++ b/packages/cursorless-vscode/src/scripts/populateDist/transformPackageJson.ts @@ -28,7 +28,7 @@ export async function transformPackageJson( json.version = `${major}.${minor}.${commitCount}`; } else { const gitSha = (await runCommand("git rev-parse --short HEAD")).trim(); - json.version = `${json.version}-${gitSha}`; + // json.version = `${json.version}-${gitSha}`; } return json;