From 77a64baa24e3ab8d364e57002b79b9220a913737 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Wed, 11 Oct 2023 09:27:15 +0100 Subject: [PATCH] Migrate ScopeProvider type to cursorless common --- packages/common/src/index.ts | 2 ++ .../api => common/src/types}/ScopeProvider.ts | 4 ++-- packages/common/src/types/SpokenForm.ts | 14 ++++++++++++++ .../src/api/CursorlessEngineApi.ts | 2 +- .../cursorless-engine/src/cursorlessEngine.ts | 4 ++-- .../src/generateSpokenForm/generateSpokenForm.ts | 16 +--------------- packages/cursorless-engine/src/index.ts | 1 - .../src/scopeProviders/ScopeInfoProvider.ts | 5 +++-- .../src/scopeProviders/ScopeRangeProvider.ts | 5 +++-- .../src/scopeProviders/ScopeRangeWatcher.ts | 8 +++++--- .../src/scopeProviders/ScopeSupportChecker.ts | 2 +- .../src/scopeProviders/ScopeSupportWatcher.ts | 10 ++++++++-- .../scopeProviders/getIterationScopeRanges.ts | 3 +-- .../src/scopeProviders/getScopeRanges.ts | 4 ++-- .../src/scopeProviders/getTargetRanges.ts | 7 +++++-- .../cursorless-vscode/src/ScopeTreeProvider.ts | 7 ++++--- .../src/constructTestHelpers.ts | 3 +++ packages/cursorless-vscode/src/extension.ts | 3 ++- .../VscodeIterationScopeVisualizer.ts | 8 ++++++-- .../VscodeScopeTargetVisualizer.ts | 3 ++- .../VscodeScopeVisualizer.ts | 3 ++- .../createVscodeScopeVisualizer.ts | 3 +-- packages/vscode-common/src/getExtensionApi.ts | 3 +++ 23 files changed, 73 insertions(+), 47 deletions(-) rename packages/{cursorless-engine/src/api => common/src/types}/ScopeProvider.ts (98%) create mode 100644 packages/common/src/types/SpokenForm.ts diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index 60c346b54ad..caf991772f6 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -44,6 +44,8 @@ export * from "./types/TextEditorOptions"; export * from "./types/TextLine"; export * from "./types/Token"; export * from "./types/HatTokenMap"; +export * from "./types/ScopeProvider"; +export * from "./types/SpokenForm"; export * from "./util/textFormatters"; export * from "./types/snippet.types"; export * from "./testUtil/fromPlainObject"; diff --git a/packages/cursorless-engine/src/api/ScopeProvider.ts b/packages/common/src/types/ScopeProvider.ts similarity index 98% rename from packages/cursorless-engine/src/api/ScopeProvider.ts rename to packages/common/src/types/ScopeProvider.ts index d655ecc7040..cb715a2f45f 100644 --- a/packages/cursorless-engine/src/api/ScopeProvider.ts +++ b/packages/common/src/types/ScopeProvider.ts @@ -3,9 +3,9 @@ import { GeneralizedRange, Range, ScopeType, + SpokenForm, TextEditor, -} from "@cursorless/common"; -import { SpokenForm } from "../generateSpokenForm"; +} from ".."; export interface ScopeProvider { /** diff --git a/packages/common/src/types/SpokenForm.ts b/packages/common/src/types/SpokenForm.ts new file mode 100644 index 00000000000..5170af44e1f --- /dev/null +++ b/packages/common/src/types/SpokenForm.ts @@ -0,0 +1,14 @@ +export interface SpokenFormSuccess { + type: "success"; + preferred: string; + alternatives: string[]; +} + +export interface SpokenFormError { + type: "error"; + reason: string; + requiresTalonUpdate: boolean; + isSecret: boolean; +} + +export type SpokenForm = SpokenFormSuccess | SpokenFormError; diff --git a/packages/cursorless-engine/src/api/CursorlessEngineApi.ts b/packages/cursorless-engine/src/api/CursorlessEngineApi.ts index d7c400618a5..a25e4dfea76 100644 --- a/packages/cursorless-engine/src/api/CursorlessEngineApi.ts +++ b/packages/cursorless-engine/src/api/CursorlessEngineApi.ts @@ -2,7 +2,7 @@ import { Command, HatTokenMap, IDE } from "@cursorless/common"; import { Snippets } from "../core/Snippets"; import { StoredTargetMap } from "../core/StoredTargets"; import { TestCaseRecorder } from "../testCaseRecorder/TestCaseRecorder"; -import { ScopeProvider } from "./ScopeProvider"; +import { ScopeProvider } from "@cursorless/common"; export interface CursorlessEngine { commandApi: CommandApi; diff --git a/packages/cursorless-engine/src/cursorlessEngine.ts b/packages/cursorless-engine/src/cursorlessEngine.ts index 31826edebb8..438fdd32b61 100644 --- a/packages/cursorless-engine/src/cursorlessEngine.ts +++ b/packages/cursorless-engine/src/cursorlessEngine.ts @@ -4,10 +4,10 @@ import { FileSystem, Hats, IDE, + ScopeProvider, } from "@cursorless/common"; import { StoredTargetMap, TestCaseRecorder, TreeSitter } from "."; import { CursorlessEngine } from "./api/CursorlessEngineApi"; -import { ScopeProvider } from "./api/ScopeProvider"; import { Debug } from "./core/Debug"; import { HatTokenMapImpl } from "./core/HatTokenMapImpl"; import { Snippets } from "./core/Snippets"; @@ -24,8 +24,8 @@ import { ScopeRangeProvider } from "./scopeProviders/ScopeRangeProvider"; import { ScopeRangeWatcher } from "./scopeProviders/ScopeRangeWatcher"; import { ScopeSupportChecker } from "./scopeProviders/ScopeSupportChecker"; import { ScopeSupportWatcher } from "./scopeProviders/ScopeSupportWatcher"; -import { injectIde } from "./singletons/ide.singleton"; import { TalonSpokenFormsJsonReader } from "./scopeProviders/getSpokenFormEntries"; +import { injectIde } from "./singletons/ide.singleton"; export function createCursorlessEngine( treeSitter: TreeSitter, diff --git a/packages/cursorless-engine/src/generateSpokenForm/generateSpokenForm.ts b/packages/cursorless-engine/src/generateSpokenForm/generateSpokenForm.ts index 33f02b38f44..9d5bea37b82 100644 --- a/packages/cursorless-engine/src/generateSpokenForm/generateSpokenForm.ts +++ b/packages/cursorless-engine/src/generateSpokenForm/generateSpokenForm.ts @@ -23,21 +23,7 @@ import { SpokenFormComponent, getGeneratorSpokenForms, } from "./GeneratorSpokenFormMap"; - -export interface SpokenFormSuccess { - type: "success"; - preferred: string; - alternatives: string[]; -} - -export interface SpokenFormError { - type: "error"; - reason: string; - requiresTalonUpdate: boolean; - isSecret: boolean; -} - -export type SpokenForm = SpokenFormSuccess | SpokenFormError; +import { SpokenForm } from "@cursorless/common"; export class SpokenFormGenerator { private primitiveGenerator: PrimitiveTargetSpokenFormGenerator; diff --git a/packages/cursorless-engine/src/index.ts b/packages/cursorless-engine/src/index.ts index 45b58818242..9348e847e26 100644 --- a/packages/cursorless-engine/src/index.ts +++ b/packages/cursorless-engine/src/index.ts @@ -6,4 +6,3 @@ export * from "./core/StoredTargets"; export * from "./typings/TreeSitter"; export * from "./cursorlessEngine"; export * from "./api/CursorlessEngineApi"; -export * from "./api/ScopeProvider"; diff --git a/packages/cursorless-engine/src/scopeProviders/ScopeInfoProvider.ts b/packages/cursorless-engine/src/scopeProviders/ScopeInfoProvider.ts index f9e9eb798e9..d24981ce56a 100644 --- a/packages/cursorless-engine/src/scopeProviders/ScopeInfoProvider.ts +++ b/packages/cursorless-engine/src/scopeProviders/ScopeInfoProvider.ts @@ -2,16 +2,17 @@ import { Disposable, Disposer, ScopeType, + ScopeTypeInfo, + ScopeTypeInfoEventCallback, SurroundingPairScopeType, simpleScopeTypeTypes, surroundingPairNames, } from "@cursorless/common"; import { pull } from "lodash"; -import { ScopeTypeInfo, ScopeTypeInfoEventCallback } from ".."; +import { SpeakableSurroundingPairName } from "../SpokenFormMap"; import { CustomSpokenFormGeneratorImpl } from "../generateSpokenForm/CustomSpokenFormGeneratorImpl"; import { scopeTypeToString } from "./scopeTypeToString"; -import { SpeakableSurroundingPairName } from "../SpokenFormMap"; /** * Maintains a list of all scope types and notifies listeners when it changes. diff --git a/packages/cursorless-engine/src/scopeProviders/ScopeRangeProvider.ts b/packages/cursorless-engine/src/scopeProviders/ScopeRangeProvider.ts index 62f39039f9f..0e1ae1d0b85 100644 --- a/packages/cursorless-engine/src/scopeProviders/ScopeRangeProvider.ts +++ b/packages/cursorless-engine/src/scopeProviders/ScopeRangeProvider.ts @@ -1,10 +1,11 @@ -import { TextEditor } from "@cursorless/common"; import { IterationScopeRangeConfig, IterationScopeRanges, ScopeRangeConfig, ScopeRanges, -} from ".."; + TextEditor, +} from "@cursorless/common"; + import { ModifierStageFactory } from "../processTargets/ModifierStageFactory"; import { ScopeHandlerFactory } from "../processTargets/modifiers/scopeHandlers/ScopeHandlerFactory"; import { getIterationRange } from "./getIterationRange"; diff --git a/packages/cursorless-engine/src/scopeProviders/ScopeRangeWatcher.ts b/packages/cursorless-engine/src/scopeProviders/ScopeRangeWatcher.ts index 6a4a7971b5d..92ef7daba3b 100644 --- a/packages/cursorless-engine/src/scopeProviders/ScopeRangeWatcher.ts +++ b/packages/cursorless-engine/src/scopeProviders/ScopeRangeWatcher.ts @@ -1,12 +1,14 @@ -import { Disposable, showError } from "@cursorless/common"; -import { pull } from "lodash"; import { + Disposable, IterationScopeChangeEventCallback, IterationScopeRangeConfig, ScopeChangeEventCallback, ScopeRangeConfig, ScopeRanges, -} from ".."; + showError, +} from "@cursorless/common"; +import { pull } from "lodash"; + import { Debouncer } from "../core/Debouncer"; import { LanguageDefinitions } from "../languages/LanguageDefinitions"; import { ide } from "../singletons/ide.singleton"; diff --git a/packages/cursorless-engine/src/scopeProviders/ScopeSupportChecker.ts b/packages/cursorless-engine/src/scopeProviders/ScopeSupportChecker.ts index d9ee8f16646..894d3b5262a 100644 --- a/packages/cursorless-engine/src/scopeProviders/ScopeSupportChecker.ts +++ b/packages/cursorless-engine/src/scopeProviders/ScopeSupportChecker.ts @@ -1,5 +1,6 @@ import { Position, + ScopeSupport, ScopeType, SimpleScopeTypeType, TextEditor, @@ -9,7 +10,6 @@ import { LegacyLanguageId } from "../languages/LegacyLanguageId"; import { languageMatchers } from "../languages/getNodeMatcher"; import { ScopeHandlerFactory } from "../processTargets/modifiers/scopeHandlers/ScopeHandlerFactory"; import { ScopeHandler } from "../processTargets/modifiers/scopeHandlers/scopeHandler.types"; -import { ScopeSupport } from "../api/ScopeProvider"; /** * Determines the level of support for a given scope type in a given editor. diff --git a/packages/cursorless-engine/src/scopeProviders/ScopeSupportWatcher.ts b/packages/cursorless-engine/src/scopeProviders/ScopeSupportWatcher.ts index 50bff837dab..1723fa13645 100644 --- a/packages/cursorless-engine/src/scopeProviders/ScopeSupportWatcher.ts +++ b/packages/cursorless-engine/src/scopeProviders/ScopeSupportWatcher.ts @@ -1,6 +1,12 @@ -import { Disposable, ScopeType } from "@cursorless/common"; +import { + Disposable, + ScopeSupport, + ScopeSupportEventCallback, + ScopeSupportInfo, + ScopeType, +} from "@cursorless/common"; import { pull } from "lodash"; -import { ScopeSupport, ScopeSupportEventCallback, ScopeSupportInfo } from ".."; + import { Debouncer } from "../core/Debouncer"; import { LanguageDefinitions } from "../languages/LanguageDefinitions"; import { ide } from "../singletons/ide.singleton"; diff --git a/packages/cursorless-engine/src/scopeProviders/getIterationScopeRanges.ts b/packages/cursorless-engine/src/scopeProviders/getIterationScopeRanges.ts index feb42bffe9f..a28b6eb8b8e 100644 --- a/packages/cursorless-engine/src/scopeProviders/getIterationScopeRanges.ts +++ b/packages/cursorless-engine/src/scopeProviders/getIterationScopeRanges.ts @@ -1,6 +1,5 @@ -import { Range, TextEditor } from "@cursorless/common"; +import { IterationScopeRanges, Range, TextEditor } from "@cursorless/common"; import { map } from "itertools"; -import { IterationScopeRanges } from ".."; import { ModifierStage } from "../processTargets/PipelineStages.types"; import { ScopeHandler } from "../processTargets/modifiers/scopeHandlers/scopeHandler.types"; import { Target } from "../typings/target.types"; diff --git a/packages/cursorless-engine/src/scopeProviders/getScopeRanges.ts b/packages/cursorless-engine/src/scopeProviders/getScopeRanges.ts index 56e47dde503..3e36c4f7686 100644 --- a/packages/cursorless-engine/src/scopeProviders/getScopeRanges.ts +++ b/packages/cursorless-engine/src/scopeProviders/getScopeRanges.ts @@ -1,6 +1,6 @@ -import { Range, TextEditor } from "@cursorless/common"; +import { Range, ScopeRanges, TextEditor } from "@cursorless/common"; import { map } from "itertools"; -import { ScopeRanges } from ".."; + import { ScopeHandler } from "../processTargets/modifiers/scopeHandlers/scopeHandler.types"; import { getTargetRanges } from "./getTargetRanges"; diff --git a/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts b/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts index 5fd843310cd..8be5e52e722 100644 --- a/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts +++ b/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts @@ -1,6 +1,9 @@ -import { toCharacterRange, toLineRange } from "@cursorless/common"; +import { + TargetRanges, + toCharacterRange, + toLineRange, +} from "@cursorless/common"; import { Target } from "../typings/target.types"; -import { TargetRanges } from "../api/ScopeProvider"; export function getTargetRanges(target: Target): TargetRanges { return { diff --git a/packages/cursorless-vscode/src/ScopeTreeProvider.ts b/packages/cursorless-vscode/src/ScopeTreeProvider.ts index 545b53b8670..17f1ecb5b03 100644 --- a/packages/cursorless-vscode/src/ScopeTreeProvider.ts +++ b/packages/cursorless-vscode/src/ScopeTreeProvider.ts @@ -1,11 +1,12 @@ -import { CursorlessCommandId, Disposer } from "@cursorless/common"; import { - CustomSpokenFormGenerator, + CursorlessCommandId, + Disposer, ScopeProvider, ScopeSupport, ScopeSupportLevels, ScopeTypeInfo, -} from "@cursorless/cursorless-engine"; +} from "@cursorless/common"; +import { CustomSpokenFormGenerator } from "@cursorless/cursorless-engine"; import { VscodeApi } from "@cursorless/vscode-common"; import { CURSORLESS_SCOPE_TREE_VIEW_ID } from "@cursorless/vscode-common"; import { isEqual } from "lodash"; diff --git a/packages/cursorless-vscode/src/constructTestHelpers.ts b/packages/cursorless-vscode/src/constructTestHelpers.ts index 053d157711b..4e3ec799a62 100644 --- a/packages/cursorless-vscode/src/constructTestHelpers.ts +++ b/packages/cursorless-vscode/src/constructTestHelpers.ts @@ -5,6 +5,7 @@ import { HatTokenMap, IDE, NormalizedIDE, + ScopeProvider, SerializedMarks, TargetPlainObject, TestCaseSnapshot, @@ -29,6 +30,7 @@ export function constructTestHelpers( vscodeIDE: VscodeIDE, normalizedIde: NormalizedIDE, spokenFormsJsonPath: string, + scopeProvider: ScopeProvider, injectIde: (ide: IDE) => void, runIntegrationTests: () => Promise, ): TestHelpers | undefined { @@ -36,6 +38,7 @@ export function constructTestHelpers( commandServerApi: commandServerApi!, ide: normalizedIde, injectIde, + scopeProvider, toVscodeEditor, diff --git a/packages/cursorless-vscode/src/extension.ts b/packages/cursorless-vscode/src/extension.ts index 3568cee494e..ab718bf00ec 100644 --- a/packages/cursorless-vscode/src/extension.ts +++ b/packages/cursorless-vscode/src/extension.ts @@ -6,12 +6,12 @@ import { isTesting, NormalizedIDE, Range, + ScopeProvider, ScopeType, TextDocument, } from "@cursorless/common"; import { createCursorlessEngine, - ScopeProvider, TreeSitter, } from "@cursorless/cursorless-engine"; import { @@ -127,6 +127,7 @@ export async function activate( vscodeIDE, normalizedIde as NormalizedIDE, spokenFormsJsonPath, + scopeProvider, injectIde, runIntegrationTests, ) diff --git a/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeIterationScopeVisualizer.ts b/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeIterationScopeVisualizer.ts index b160f8631c6..da3dca3fefd 100644 --- a/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeIterationScopeVisualizer.ts +++ b/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeIterationScopeVisualizer.ts @@ -1,7 +1,11 @@ -import { Disposable, TextEditor, toCharacterRange } from "@cursorless/common"; +import { + Disposable, + ScopeSupport, + TextEditor, + toCharacterRange, +} from "@cursorless/common"; import { VscodeTextEditorImpl } from "../VscodeTextEditorImpl"; import { VscodeScopeVisualizer } from "./VscodeScopeVisualizer"; -import { ScopeSupport } from "@cursorless/cursorless-engine"; export class VscodeIterationScopeVisualizer extends VscodeScopeVisualizer { protected getScopeSupport(editor: TextEditor): ScopeSupport { diff --git a/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeScopeTargetVisualizer.ts b/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeScopeTargetVisualizer.ts index 6303d6ee3cb..f52862a4007 100644 --- a/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeScopeTargetVisualizer.ts +++ b/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeScopeTargetVisualizer.ts @@ -1,10 +1,11 @@ import { Disposable, GeneralizedRange, + ScopeSupport, + TargetRanges, TextEditor, toCharacterRange, } from "@cursorless/common"; -import { ScopeSupport, TargetRanges } from "@cursorless/cursorless-engine"; import { VscodeScopeVisualizer } from "."; import { VscodeTextEditorImpl } from "../VscodeTextEditorImpl"; diff --git a/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeScopeVisualizer.ts b/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeScopeVisualizer.ts index 862a75e41b0..a5e9c69e586 100644 --- a/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeScopeVisualizer.ts +++ b/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeScopeVisualizer.ts @@ -1,11 +1,12 @@ import { Disposable, IDE, + ScopeProvider, + ScopeSupport, ScopeType, TextEditor, showError, } from "@cursorless/common"; -import { ScopeProvider, ScopeSupport } from "@cursorless/cursorless-engine"; import { ScopeRangeType, ScopeVisualizerColorConfig, diff --git a/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/createVscodeScopeVisualizer.ts b/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/createVscodeScopeVisualizer.ts index 4abd4b65150..aad6cd3ec90 100644 --- a/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/createVscodeScopeVisualizer.ts +++ b/packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/createVscodeScopeVisualizer.ts @@ -1,5 +1,4 @@ -import { IDE, ScopeType } from "@cursorless/common"; -import { ScopeProvider } from "@cursorless/cursorless-engine"; +import { IDE, ScopeProvider, ScopeType } from "@cursorless/common"; import { VisualizationType } from "../../../ScopeVisualizerCommandApi"; import { VscodeIterationScopeVisualizer } from "./VscodeIterationScopeVisualizer"; import { diff --git a/packages/vscode-common/src/getExtensionApi.ts b/packages/vscode-common/src/getExtensionApi.ts index 8638aa7a006..72151c0a878 100644 --- a/packages/vscode-common/src/getExtensionApi.ts +++ b/packages/vscode-common/src/getExtensionApi.ts @@ -5,6 +5,7 @@ import type { HatTokenMap, IDE, NormalizedIDE, + ScopeProvider, SerializedMarks, SnippetMap, TargetPlainObject, @@ -19,6 +20,8 @@ export interface TestHelpers { ide: NormalizedIDE; injectIde: (ide: IDE) => void; + scopeProvider: ScopeProvider; + hatTokenMap: HatTokenMap; commandServerApi: CommandServerApi;