Skip to content

Commit

Permalink
Clean up one of scope handler
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Jan 30, 2025
1 parent 3266cc7 commit b49b31d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,8 @@ export class CollectionItemScopeHandler extends BaseScopeHandler {

return OneOfScopeHandler.createFromScopeHandlers(
scopeHandlerFactory,
{
type: "oneOf",
scopeTypes: [
languageScopeHandler.scopeType,
textualScopeHandler.scopeType,
],
},
[languageScopeHandler, textualScopeHandler],
languageId,
[languageScopeHandler, textualScopeHandler],
);
})();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,8 @@ export class NotebookCellScopeHandler extends BaseScopeHandler {

return OneOfScopeHandler.createFromScopeHandlers(
scopeHandlerFactory,
{
type: "oneOf",
scopeTypes: [
languageScopeHandler.scopeType,
apiScopeHandler.scopeType,
],
},
[languageScopeHandler, apiScopeHandler],
languageId,
[languageScopeHandler, apiScopeHandler],
);
})();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {

export class OneOfScopeHandler extends BaseScopeHandler {
protected isHierarchical = true;
public scopeType = undefined;
private iterationScopeHandler: OneOfScopeHandler | undefined;
private lastYieldedIndex: number | undefined;

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

return this.createFromScopeHandlers(
scopeHandlerFactory,
scopeType,
scopeHandlers,
languageId,
scopeHandlers,
);
}

static createFromScopeHandlers(
scopeHandlerFactory: ScopeHandlerFactory,
scopeType: OneOfScopeType,
scopeHandlers: ScopeHandler[],
languageId: string,
scopeHandlers: ScopeHandler[],
): ScopeHandler {
const getIterationScopeHandler = () =>
new OneOfScopeHandler(
undefined,
scopeHandlers.map((scopeHandler) =>
scopeHandlerFactory.create(
scopeHandler.iterationScopeType,
Expand All @@ -57,11 +55,14 @@ export class OneOfScopeHandler extends BaseScopeHandler {
},
);

return new OneOfScopeHandler(
scopeType,
scopeHandlers,
getIterationScopeHandler,
);
return new OneOfScopeHandler(scopeHandlers, getIterationScopeHandler);
}

private constructor(
private scopeHandlers: ScopeHandler[],
private getIterationScopeHandler: () => OneOfScopeHandler,
) {
super();
}

get iterationScopeType(): CustomScopeType {
Expand All @@ -74,21 +75,13 @@ export class OneOfScopeHandler extends BaseScopeHandler {
};
}

private constructor(
public readonly scopeType: OneOfScopeType | undefined,
private scopeHandlers: ScopeHandler[],
private getIterationScopeHandler: () => OneOfScopeHandler,
) {
super();
}

*generateScopeCandidates(
editor: TextEditor,
position: Position,
direction: Direction,
hints: ScopeIteratorRequirements,
): Iterable<TargetScope> {
// If we have used the iteration scope handler, we only want to yield from its handler.
// If we have used a iteration scope handler, we only want to yield additional scopes from its handler.
if (this.iterationScopeHandler?.lastYieldedIndex != null) {
const handlerIndex = this.iterationScopeHandler.lastYieldedIndex;
const handler = this.scopeHandlers[handlerIndex];
Expand Down

0 comments on commit b49b31d

Please sign in to comment.