Skip to content

Commit

Permalink
Migrate ScopeProvider type to cursorless common
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey committed Oct 11, 2023
1 parent 4627f69 commit 77a64ba
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 47 deletions.
2 changes: 2 additions & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
GeneralizedRange,
Range,
ScopeType,
SpokenForm,
TextEditor,
} from "@cursorless/common";
import { SpokenForm } from "../generateSpokenForm";
} from "..";

export interface ScopeProvider {
/**
Expand Down
14 changes: 14 additions & 0 deletions packages/common/src/types/SpokenForm.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion packages/cursorless-engine/src/api/CursorlessEngineApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/cursorless-engine/src/cursorlessEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/cursorless-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ export * from "./core/StoredTargets";
export * from "./typings/TreeSitter";
export * from "./cursorlessEngine";
export * from "./api/CursorlessEngineApi";
export * from "./api/ScopeProvider";
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Position,
ScopeSupport,
ScopeType,
SimpleScopeTypeType,
TextEditor,
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions packages/cursorless-vscode/src/ScopeTreeProvider.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
3 changes: 3 additions & 0 deletions packages/cursorless-vscode/src/constructTestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
HatTokenMap,
IDE,
NormalizedIDE,
ScopeProvider,
SerializedMarks,
TargetPlainObject,
TestCaseSnapshot,
Expand All @@ -29,13 +30,15 @@ export function constructTestHelpers(
vscodeIDE: VscodeIDE,
normalizedIde: NormalizedIDE,
spokenFormsJsonPath: string,
scopeProvider: ScopeProvider,
injectIde: (ide: IDE) => void,
runIntegrationTests: () => Promise<void>,
): TestHelpers | undefined {
return {
commandServerApi: commandServerApi!,
ide: normalizedIde,
injectIde,
scopeProvider,

toVscodeEditor,

Expand Down
3 changes: 2 additions & 1 deletion packages/cursorless-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
isTesting,
NormalizedIDE,
Range,
ScopeProvider,
ScopeType,
TextDocument,
} from "@cursorless/common";
import {
createCursorlessEngine,
ScopeProvider,
TreeSitter,
} from "@cursorless/cursorless-engine";
import {
Expand Down Expand Up @@ -127,6 +127,7 @@ export async function activate(
vscodeIDE,
normalizedIde as NormalizedIDE,
spokenFormsJsonPath,
scopeProvider,
injectIde,
runIntegrationTests,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions packages/vscode-common/src/getExtensionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
HatTokenMap,
IDE,
NormalizedIDE,
ScopeProvider,
SerializedMarks,
SnippetMap,
TargetPlainObject,
Expand All @@ -19,6 +20,8 @@ export interface TestHelpers {
ide: NormalizedIDE;
injectIde: (ide: IDE) => void;

scopeProvider: ScopeProvider;

hatTokenMap: HatTokenMap;

commandServerApi: CommandServerApi;
Expand Down

0 comments on commit 77a64ba

Please sign in to comment.