@@ -17,6 +17,8 @@ import type {
1717
1818export class OneOfScopeHandler extends BaseScopeHandler {
1919 protected isHierarchical = true ;
20+ private iterationScopeHandler : OneOfScopeHandler | undefined ;
21+ private lastYieldedIndex : number | undefined ;
2022
2123 static create (
2224 scopeHandlerFactory : ScopeHandlerFactory ,
@@ -47,9 +49,8 @@ export class OneOfScopeHandler extends BaseScopeHandler {
4749 scopeHandlers : ScopeHandler [ ] ,
4850 languageId : string ,
4951 ) : ScopeHandler {
50- const iterationScopeType = ( ) : CustomScopeType => ( {
51- type : "custom" ,
52- scopeHandler : new OneOfScopeHandler (
52+ const getIterationScopeHandler = ( ) =>
53+ new OneOfScopeHandler (
5354 undefined ,
5455 scopeHandlers . map (
5556 ( scopeHandler ) =>
@@ -61,20 +62,29 @@ export class OneOfScopeHandler extends BaseScopeHandler {
6162 ( ) => {
6263 throw new Error ( "Not implemented" ) ;
6364 } ,
64- ) ,
65- } ) ;
65+ ) ;
6666
67- return new OneOfScopeHandler ( scopeType , scopeHandlers , iterationScopeType ) ;
67+ return new OneOfScopeHandler (
68+ scopeType ,
69+ scopeHandlers ,
70+ getIterationScopeHandler ,
71+ ) ;
6872 }
6973
7074 get iterationScopeType ( ) : CustomScopeType {
71- return this . getIterationScopeType ( ) ;
75+ if ( this . iterationScopeHandler == null ) {
76+ this . iterationScopeHandler = this . getIterationScopeHandler ( ) ;
77+ }
78+ return {
79+ type : "custom" ,
80+ scopeHandler : this . iterationScopeHandler ,
81+ } ;
7282 }
7383
7484 private constructor (
7585 public readonly scopeType : OneOfScopeType | undefined ,
7686 private scopeHandlers : ScopeHandler [ ] ,
77- private getIterationScopeType : ( ) => CustomScopeType ,
87+ private getIterationScopeHandler : ( ) => OneOfScopeHandler ,
7888 ) {
7989 super ( ) ;
8090 }
@@ -85,6 +95,14 @@ export class OneOfScopeHandler extends BaseScopeHandler {
8595 direction : Direction ,
8696 hints : ScopeIteratorRequirements ,
8797 ) : Iterable < TargetScope > {
98+ // If we have used the iteration scope handler we only want to yield from it's handler
99+ if ( this . iterationScopeHandler ?. lastYieldedIndex != null ) {
100+ const handlerIndex = this . iterationScopeHandler . lastYieldedIndex ;
101+ const handler = this . scopeHandlers [ handlerIndex ] ;
102+ yield * handler . generateScopes ( editor , position , direction , hints ) ;
103+ return ;
104+ }
105+
88106 const iterators = this . scopeHandlers . map ( ( scopeHandler ) =>
89107 scopeHandler
90108 . generateScopes ( editor , position , direction , hints )
@@ -99,7 +117,9 @@ export class OneOfScopeHandler extends BaseScopeHandler {
99117 ) ;
100118
101119 // Pick minimum scope according to canonical scope ordering
102- const currentScope = iteratorInfos [ 0 ] . value ;
120+ const iteratorInfo = iteratorInfos [ 0 ] ;
121+ const currentScope = iteratorInfo . value ;
122+ this . lastYieldedIndex = iteratorInfo . index ;
103123
104124 yield currentScope ;
105125
0 commit comments