diff --git a/packages/app-vscode/src/createScopeVisualizer.ts b/packages/app-vscode/src/createScopeVisualizer.ts index d5d788aea1..f953393910 100644 --- a/packages/app-vscode/src/createScopeVisualizer.ts +++ b/packages/app-vscode/src/createScopeVisualizer.ts @@ -5,7 +5,7 @@ import type { ScopeProvider, ScopeType, } from "@cursorless/lib-common"; -import { isPseudoScope } from "@cursorless/lib-common"; +import { isPseudoScopeType } from "@cursorless/lib-common"; import type { VscodeScopeVisualizer } from "./ide/vscode/VSCodeScopeVisualizer"; import { createVscodeScopeVisualizer } from "./ide/vscode/VSCodeScopeVisualizer"; import type { @@ -25,7 +25,7 @@ export function createScopeVisualizer( return { start(scopeType: ScopeType, visualizationType: VisualizationType) { - if (isPseudoScope(scopeType)) { + if (isPseudoScopeType(scopeType)) { throw new Error( `Can't visualize pseudo scopes like '${scopeType.type}'`, ); diff --git a/packages/lib-common/src/types/command/PartialTargetDescriptor.types.ts b/packages/lib-common/src/types/command/PartialTargetDescriptor.types.ts index da47dab585..8d627abcdc 100644 --- a/packages/lib-common/src/types/command/PartialTargetDescriptor.types.ts +++ b/packages/lib-common/src/types/command/PartialTargetDescriptor.types.ts @@ -215,9 +215,8 @@ const simpleScopeTypeTypesSet = new Set(simpleScopeTypeTypes); export type SimpleScopeTypeType = (typeof simpleScopeTypeTypes)[number]; -export const pseudoScopes = new Set([ +export const pseudoScopeTypeTypes = new Set([ "instance", - "interior", "className", "functionName", ]); @@ -228,8 +227,10 @@ export function isSimpleScopeType( return (simpleScopeTypeTypesSet as Set).has(scopeType.type); } -export function isPseudoScope(scopeType: ScopeType): boolean { - return isSimpleScopeType(scopeType) && pseudoScopes.has(scopeType.type); +export function isPseudoScopeType(scopeType: ScopeType): boolean { + return ( + isSimpleScopeType(scopeType) && pseudoScopeTypeTypes.has(scopeType.type) + ); } export interface SimpleScopeType { diff --git a/packages/lib-engine/src/languages/TreeSitterQuery/captureNames.ts b/packages/lib-engine/src/languages/TreeSitterQuery/captureNames.ts index a7c68ecf52..12f0b203ce 100644 --- a/packages/lib-engine/src/languages/TreeSitterQuery/captureNames.ts +++ b/packages/lib-engine/src/languages/TreeSitterQuery/captureNames.ts @@ -1,10 +1,11 @@ -import { pseudoScopes, simpleScopeTypeTypes } from "@cursorless/lib-common"; - -const scopeCaptureNames = [ - ...simpleScopeTypeTypes.filter((s) => !pseudoScopes.has(s)), - // Interior is a pseudo scope, but it's implemented with an actual internal scope - "interior", -] as const; +import { + pseudoScopeTypeTypes, + simpleScopeTypeTypes, +} from "@cursorless/lib-common"; + +const scopeCaptureNames = simpleScopeTypeTypes.filter( + (s) => !pseudoScopeTypeTypes.has(s), +); export type ScopeCaptureName = (typeof scopeCaptureNames)[number]; diff --git a/packages/lib-engine/src/processTargets/modifiers/scopeHandlers/ScopeHandlerFactoryImpl.ts b/packages/lib-engine/src/processTargets/modifiers/scopeHandlers/ScopeHandlerFactoryImpl.ts index 7fd0eaebf0..5769ea0d53 100644 --- a/packages/lib-engine/src/processTargets/modifiers/scopeHandlers/ScopeHandlerFactoryImpl.ts +++ b/packages/lib-engine/src/processTargets/modifiers/scopeHandlers/ScopeHandlerFactoryImpl.ts @@ -1,5 +1,8 @@ import type { IDE, ScopeType } from "@cursorless/lib-common"; -import { isPseudoScope, UnsupportedScopeError } from "@cursorless/lib-common"; +import { + isPseudoScopeType, + UnsupportedScopeError, +} from "@cursorless/lib-common"; import type { LanguageDefinitions } from "../../../languages/LanguageDefinitions"; import { BoundedNonWhitespaceSequenceScopeHandler, @@ -139,7 +142,7 @@ export class ScopeHandlerFactoryImpl implements ScopeHandlerFactory { return ConditionalScopeHandler.maybeCreate(this, scopeType, languageId); default: // Pseudoscopes are handled separately in their own modifiers. - if (isPseudoScope(scopeType)) { + if (isPseudoScopeType(scopeType)) { throw new Error(`Unexpected pseudo scope type '${scopeType.type}'`); } return this.languageDefinitions diff --git a/packages/lib-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/InteriorScopeHandler.ts b/packages/lib-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/InteriorScopeHandler.ts index e8b4878043..75d73a8a90 100644 --- a/packages/lib-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/InteriorScopeHandler.ts +++ b/packages/lib-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/InteriorScopeHandler.ts @@ -1,23 +1,15 @@ -import type { - Direction, - Position, - ScopeType, - TextEditor, -} from "@cursorless/lib-common"; -import { NoContainingScopeError } from "@cursorless/lib-common"; +import type { Direction, Position, TextEditor } from "@cursorless/lib-common"; import type { LanguageDefinitions } from "../../../../languages/LanguageDefinitions"; import type { Target } from "../../../../typings/target.types"; import { InteriorTarget } from "../../../targets"; import { BaseScopeHandler } from "../BaseScopeHandler"; import type { TargetScope } from "../scope.types"; -import type { - ComplexScopeType, - ScopeIteratorRequirements, -} from "../scopeHandler.types"; +import type { ScopeIteratorRequirements } from "../scopeHandler.types"; import type { TreeSitterScopeHandler } from "../TreeSitterScopeHandler"; export class InteriorScopeHandler extends BaseScopeHandler { public readonly scopeType = { type: "interior" } as const; + public readonly iterationScopeType = { type: "document" } as const; protected isHierarchical = true; static maybeCreate( @@ -39,12 +31,6 @@ export class InteriorScopeHandler extends BaseScopeHandler { super(); } - get iterationScopeType(): ScopeType | ComplexScopeType { - throw new NoContainingScopeError( - "Iteration scope for InteriorScopeHandler", - ); - } - *generateScopeCandidates( editor: TextEditor, position: Position, diff --git a/packages/lib-engine/src/scopeProviders/ScopeInfoProvider.ts b/packages/lib-engine/src/scopeProviders/ScopeInfoProvider.ts index a10fd436e4..55709e15ca 100644 --- a/packages/lib-engine/src/scopeProviders/ScopeInfoProvider.ts +++ b/packages/lib-engine/src/scopeProviders/ScopeInfoProvider.ts @@ -7,7 +7,7 @@ import type { SurroundingPairScopeType, } from "@cursorless/lib-common"; import { - isPseudoScope, + isPseudoScopeType, simpleScopeTypeTypes, surroundingPairNames, } from "@cursorless/lib-common"; @@ -70,7 +70,7 @@ export class ScopeInfoProvider { // Create simple scope types from simple scope type types .map((scopeTypeType) => ({ type: scopeTypeType })) // Ignore pseudo-scope because it's not really a scope - .filter((scopeType) => !isPseudoScope(scopeType)), + .filter((scopeType) => !isPseudoScopeType(scopeType)), ...surroundingPairNames.map( (surroundingPairName): SurroundingPairScopeType => ({