@@ -8,6 +8,7 @@ import skipRules from './linter/skipRules';
88import * as Project from "./project" ;
99import { getInterfaces } from './project/exportInterfaces' ;
1010import Parser from '../../../../language/parser' ;
11+ import { Token } from '../../../../language/types' ;
1112
1213const completionKind = {
1314 function : CompletionItemKind . Interface ,
@@ -46,17 +47,19 @@ export default async function completionItemProvider(handler: CompletionParams):
4647
4748 // This means we're just looking for subfields in the struct
4849 if ( trigger === `.` ) {
49- const tokens = Parser . lineTokens ( isFree ? currentLine : currentLine . length >= 7 ? currentLine . substring ( 7 ) : `` , 0 , 0 , true ) ;
50+ const cursorIndex = handler . position . character ;
51+ let tokens = Parser . lineTokens ( isFree ? currentLine : currentLine . length >= 7 ? `` . padEnd ( 7 ) + currentLine . substring ( 7 ) : `` , 0 , 0 , true ) ;
5052
5153 if ( tokens . length > 0 ) {
52- const cursorIndex = handler . position . character ;
53- let tokenIndex = tokens . findIndex ( token => cursorIndex > token . range . start && cursorIndex <= token . range . end ) ;
54- console . log ( tokens ) ;
55- console . log ( { cPos : handler . position . character , tokenIndex } ) ;
54+
55+ // We need to find the innermost block we are part of
56+ tokens = Parser . fromBlocksGetTokens ( tokens , cursorIndex ) ;
5657
57- while ( tokens [ tokenIndex ] && [ `block` , `word` , `dot` ] . includes ( tokens [ tokenIndex ] . type ) && tokenIndex > 0 ) {
58- tokenIndex -- ;
59- }
58+ // Remove any tokens after the cursor
59+ tokens = tokens . filter ( token => token . range . end <= cursorIndex ) ;
60+
61+ // Get the possible variable we're referring to
62+ let tokenIndex = Parser . getReference ( tokens , cursorIndex ) ;
6063
6164 let currentDef : Declaration | undefined ;
6265
0 commit comments