Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 an 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
Loading