Skip to content

Commit fa4f0b4

Browse files
Add interior scope to visualize sidebar (#3291)
1 parent eda69e0 commit fa4f0b4

6 files changed

Lines changed: 25 additions & 34 deletions

File tree

packages/app-vscode/src/createScopeVisualizer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
ScopeProvider,
66
ScopeType,
77
} from "@cursorless/lib-common";
8-
import { isPseudoScope } from "@cursorless/lib-common";
8+
import { isPseudoScopeType } from "@cursorless/lib-common";
99
import type { VscodeScopeVisualizer } from "./ide/vscode/VSCodeScopeVisualizer";
1010
import { createVscodeScopeVisualizer } from "./ide/vscode/VSCodeScopeVisualizer";
1111
import type {
@@ -25,7 +25,7 @@ export function createScopeVisualizer(
2525

2626
return {
2727
start(scopeType: ScopeType, visualizationType: VisualizationType) {
28-
if (isPseudoScope(scopeType)) {
28+
if (isPseudoScopeType(scopeType)) {
2929
throw new Error(
3030
`Can't visualize pseudo scopes like '${scopeType.type}'`,
3131
);

packages/lib-common/src/types/command/PartialTargetDescriptor.types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,8 @@ const simpleScopeTypeTypesSet = new Set(simpleScopeTypeTypes);
215215

216216
export type SimpleScopeTypeType = (typeof simpleScopeTypeTypes)[number];
217217

218-
export const pseudoScopes = new Set<SimpleScopeTypeType>([
218+
export const pseudoScopeTypeTypes = new Set<SimpleScopeTypeType>([
219219
"instance",
220-
"interior",
221220
"className",
222221
"functionName",
223222
]);
@@ -228,8 +227,10 @@ export function isSimpleScopeType(
228227
return (simpleScopeTypeTypesSet as Set<string>).has(scopeType.type);
229228
}
230229

231-
export function isPseudoScope(scopeType: ScopeType): boolean {
232-
return isSimpleScopeType(scopeType) && pseudoScopes.has(scopeType.type);
230+
export function isPseudoScopeType(scopeType: ScopeType): boolean {
231+
return (
232+
isSimpleScopeType(scopeType) && pseudoScopeTypeTypes.has(scopeType.type)
233+
);
233234
}
234235

235236
export interface SimpleScopeType {

packages/lib-engine/src/languages/TreeSitterQuery/captureNames.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { pseudoScopes, simpleScopeTypeTypes } from "@cursorless/lib-common";
2-
3-
const scopeCaptureNames = [
4-
...simpleScopeTypeTypes.filter((s) => !pseudoScopes.has(s)),
5-
// Interior is a pseudo scope, but it's implemented with an actual internal scope
6-
"interior",
7-
] as const;
1+
import {
2+
pseudoScopeTypeTypes,
3+
simpleScopeTypeTypes,
4+
} from "@cursorless/lib-common";
5+
6+
const scopeCaptureNames = simpleScopeTypeTypes.filter(
7+
(s) => !pseudoScopeTypeTypes.has(s),
8+
);
89

910
export type ScopeCaptureName = (typeof scopeCaptureNames)[number];
1011

packages/lib-engine/src/processTargets/modifiers/scopeHandlers/ScopeHandlerFactoryImpl.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type { IDE, ScopeType } from "@cursorless/lib-common";
2-
import { isPseudoScope, UnsupportedScopeError } from "@cursorless/lib-common";
2+
import {
3+
isPseudoScopeType,
4+
UnsupportedScopeError,
5+
} from "@cursorless/lib-common";
36
import type { LanguageDefinitions } from "../../../languages/LanguageDefinitions";
47
import {
58
BoundedNonWhitespaceSequenceScopeHandler,
@@ -139,7 +142,7 @@ export class ScopeHandlerFactoryImpl implements ScopeHandlerFactory {
139142
return ConditionalScopeHandler.maybeCreate(this, scopeType, languageId);
140143
default:
141144
// Pseudoscopes are handled separately in their own modifiers.
142-
if (isPseudoScope(scopeType)) {
145+
if (isPseudoScopeType(scopeType)) {
143146
throw new Error(`Unexpected pseudo scope type '${scopeType.type}'`);
144147
}
145148
return this.languageDefinitions

packages/lib-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/InteriorScopeHandler.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
import type {
2-
Direction,
3-
Position,
4-
ScopeType,
5-
TextEditor,
6-
} from "@cursorless/lib-common";
7-
import { NoContainingScopeError } from "@cursorless/lib-common";
1+
import type { Direction, Position, TextEditor } from "@cursorless/lib-common";
82
import type { LanguageDefinitions } from "../../../../languages/LanguageDefinitions";
93
import type { Target } from "../../../../typings/target.types";
104
import { InteriorTarget } from "../../../targets";
115
import { BaseScopeHandler } from "../BaseScopeHandler";
126
import type { TargetScope } from "../scope.types";
13-
import type {
14-
ComplexScopeType,
15-
ScopeIteratorRequirements,
16-
} from "../scopeHandler.types";
7+
import type { ScopeIteratorRequirements } from "../scopeHandler.types";
178
import type { TreeSitterScopeHandler } from "../TreeSitterScopeHandler";
189

1910
export class InteriorScopeHandler extends BaseScopeHandler {
2011
public readonly scopeType = { type: "interior" } as const;
12+
public readonly iterationScopeType = { type: "document" } as const;
2113
protected isHierarchical = true;
2214

2315
static maybeCreate(
@@ -39,12 +31,6 @@ export class InteriorScopeHandler extends BaseScopeHandler {
3931
super();
4032
}
4133

42-
get iterationScopeType(): ScopeType | ComplexScopeType {
43-
throw new NoContainingScopeError(
44-
"Iteration scope for InteriorScopeHandler",
45-
);
46-
}
47-
4834
*generateScopeCandidates(
4935
editor: TextEditor,
5036
position: Position,

packages/lib-engine/src/scopeProviders/ScopeInfoProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
SurroundingPairScopeType,
88
} from "@cursorless/lib-common";
99
import {
10-
isPseudoScope,
10+
isPseudoScopeType,
1111
simpleScopeTypeTypes,
1212
surroundingPairNames,
1313
} from "@cursorless/lib-common";
@@ -70,7 +70,7 @@ export class ScopeInfoProvider {
7070
// Create simple scope types from simple scope type types
7171
.map((scopeTypeType) => ({ type: scopeTypeType }))
7272
// Ignore pseudo-scope because it's not really a scope
73-
.filter((scopeType) => !isPseudoScope(scopeType)),
73+
.filter((scopeType) => !isPseudoScopeType(scopeType)),
7474

7575
...surroundingPairNames.map(
7676
(surroundingPairName): SurroundingPairScopeType => ({

0 commit comments

Comments
 (0)