@@ -8,6 +8,7 @@ import skipRules from './linter/skipRules';
8
8
import * as Project from "./project" ;
9
9
import { getInterfaces } from './project/exportInterfaces' ;
10
10
import Parser from '../../../../language/parser' ;
11
+ import { Token } from '../../../../language/types' ;
11
12
12
13
const completionKind = {
13
14
function : CompletionItemKind . Interface ,
@@ -46,17 +47,19 @@ export default async function completionItemProvider(handler: CompletionParams):
46
47
47
48
// This means we're just looking for subfields in the struct
48
49
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 ) ;
50
52
51
53
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 ) ;
56
57
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 ) ;
60
63
61
64
let currentDef : Declaration | undefined ;
62
65
0 commit comments