Skip to content

Commit e98bf94

Browse files
Clean up one of scope handler (#2792)
Passing in the scope type is only necessary if you're creating the scope handlers from that scope type. In the case where you're creating a one of handler from a list of scope handlers. Passing in the scope type as well just makes the code more verbose for no reason. ## Checklist - [/] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet --------- Co-authored-by: Phil Cohen <[email protected]>
1 parent a0e39b4 commit e98bf94

File tree

3 files changed

+14
-35
lines changed

3 files changed

+14
-35
lines changed

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/CollectionItemScopeHandler/CollectionItemScopeHandler.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,8 @@ export class CollectionItemScopeHandler extends BaseScopeHandler {
4848

4949
return OneOfScopeHandler.createFromScopeHandlers(
5050
scopeHandlerFactory,
51-
{
52-
type: "oneOf",
53-
scopeTypes: [
54-
languageScopeHandler.scopeType,
55-
textualScopeHandler.scopeType,
56-
],
57-
},
58-
[languageScopeHandler, textualScopeHandler],
5951
languageId,
52+
[languageScopeHandler, textualScopeHandler],
6053
);
6154
})();
6255
}

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/NotebookCellScopeHandler.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,8 @@ export class NotebookCellScopeHandler extends BaseScopeHandler {
4646

4747
return OneOfScopeHandler.createFromScopeHandlers(
4848
scopeHandlerFactory,
49-
{
50-
type: "oneOf",
51-
scopeTypes: [
52-
languageScopeHandler.scopeType,
53-
apiScopeHandler.scopeType,
54-
],
55-
},
56-
[languageScopeHandler, apiScopeHandler],
5749
languageId,
50+
[languageScopeHandler, apiScopeHandler],
5851
);
5952
})();
6053
}

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/OneOfScopeHandler.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717

1818
export class OneOfScopeHandler extends BaseScopeHandler {
1919
protected isHierarchical = true;
20+
public scopeType = undefined;
2021
private iterationScopeHandler: OneOfScopeHandler | undefined;
2122
private lastYieldedIndex: number | undefined;
2223

@@ -31,21 +32,18 @@ export class OneOfScopeHandler extends BaseScopeHandler {
3132

3233
return this.createFromScopeHandlers(
3334
scopeHandlerFactory,
34-
scopeType,
35-
scopeHandlers,
3635
languageId,
36+
scopeHandlers,
3737
);
3838
}
3939

4040
static createFromScopeHandlers(
4141
scopeHandlerFactory: ScopeHandlerFactory,
42-
scopeType: OneOfScopeType,
43-
scopeHandlers: ScopeHandler[],
4442
languageId: string,
43+
scopeHandlers: ScopeHandler[],
4544
): ScopeHandler {
4645
const getIterationScopeHandler = () =>
4746
new OneOfScopeHandler(
48-
undefined,
4947
scopeHandlers.map((scopeHandler) =>
5048
scopeHandlerFactory.create(
5149
scopeHandler.iterationScopeType,
@@ -57,11 +55,14 @@ export class OneOfScopeHandler extends BaseScopeHandler {
5755
},
5856
);
5957

60-
return new OneOfScopeHandler(
61-
scopeType,
62-
scopeHandlers,
63-
getIterationScopeHandler,
64-
);
58+
return new OneOfScopeHandler(scopeHandlers, getIterationScopeHandler);
59+
}
60+
61+
private constructor(
62+
private scopeHandlers: ScopeHandler[],
63+
private getIterationScopeHandler: () => OneOfScopeHandler,
64+
) {
65+
super();
6566
}
6667

6768
get iterationScopeType(): CustomScopeType {
@@ -74,21 +75,13 @@ export class OneOfScopeHandler extends BaseScopeHandler {
7475
};
7576
}
7677

77-
private constructor(
78-
public readonly scopeType: OneOfScopeType | undefined,
79-
private scopeHandlers: ScopeHandler[],
80-
private getIterationScopeHandler: () => OneOfScopeHandler,
81-
) {
82-
super();
83-
}
84-
8578
*generateScopeCandidates(
8679
editor: TextEditor,
8780
position: Position,
8881
direction: Direction,
8982
hints: ScopeIteratorRequirements,
9083
): Iterable<TargetScope> {
91-
// If we have used the iteration scope handler, we only want to yield from its handler.
84+
// If we have used an iteration scope handler, we only want to yield additional scopes from its handler.
9285
if (this.iterationScopeHandler?.lastYieldedIndex != null) {
9386
const handlerIndex = this.iterationScopeHandler.lastYieldedIndex;
9487
const handler = this.scopeHandlers[handlerIndex];

0 commit comments

Comments
 (0)