@@ -205,6 +205,7 @@ export class AutoCompleteTree {
205205 column : lines [ lines . length - 1 ] . length + 1 ,
206206 } ) ;
207207 }
208+
208209 let result : WordCompletion [ ] = [ ] ;
209210 if ( tokens . length == 0 ) {
210211 for ( const r of this . roots ) {
@@ -220,13 +221,16 @@ export class AutoCompleteTree {
220221 nodes : AutoCompleteNode [ ] ,
221222 tokens : Token [ ] ,
222223 index : number ,
224+ cameFromFinal = false ,
223225 skipStartCheck = false ,
224226 ) : WordCompletion [ ] {
225227 // check for new start
226228 if ( ! skipStartCheck && tokens [ index ] . column == 1 ) {
227229 const matchesAnyRoot = this . roots . some ( ( n ) => n . word . verifyWord ( tokens [ index ] . text ) . length === 0 ) ;
228230 if ( matchesAnyRoot ) {
229- return this . completeNode ( this . roots , tokens , index , true ) ;
231+ return this . completeNode ( this . roots , tokens , index , cameFromFinal , true ) ;
232+ } else if ( cameFromFinal || nodes . length == 0 ) {
233+ return this . completeNode ( [ ...this . roots , ...nodes ] , tokens , index , cameFromFinal , true ) ;
230234 }
231235 }
232236
@@ -241,7 +245,7 @@ export class AutoCompleteTree {
241245 if ( n . word . verifyWord ( tokens [ index ] . text ) . length > 0 ) {
242246 continue ;
243247 }
244- result = result . concat ( this . completeNode ( n . children , tokens , index + 1 ) ) ;
248+ result = result . concat ( this . completeNode ( n . children , tokens , index + 1 , n . canBeFinal || false ) ) ;
245249 }
246250 return result ;
247251 }
0 commit comments