@@ -48,25 +48,18 @@ export default async function completionItemProvider(handler: CompletionParams):
48
48
// This means we're just looking for subfields in the struct
49
49
if ( trigger === `.` ) {
50
50
const cursorIndex = handler . position . character ;
51
- let tokens = Parser . lineTokens ( isFree ? currentLine : currentLine . length >= 7 ? currentLine . substring ( 7 ) : `` , 0 , 0 , true ) ;
51
+ let tokens = Parser . lineTokens ( isFree ? currentLine : currentLine . length >= 7 ? `` . padEnd ( 7 ) + currentLine . substring ( 7 ) : `` , 0 , 0 , true ) ;
52
52
53
53
if ( tokens . length > 0 ) {
54
54
55
55
// We need to find the innermost block we are part of
56
- let insideBlock : Token | undefined ;
57
- while ( insideBlock = tokens . find ( t => t . type === `block` && t . block && t . range . start <= cursorIndex && t . range . end >= cursorIndex ) ) {
58
- tokens = insideBlock . block || [ ] ;
59
- }
56
+ tokens = Parser . fromBlocksGetTokens ( tokens , cursorIndex ) ;
60
57
61
- let tokenIndex = tokens . findIndex ( token => cursorIndex > token . range . start && cursorIndex <= token . range . end ) ;
62
- console . log ( tokens ) ;
63
- console . log ( { cPos : handler . position . character , tokenIndex } ) ;
58
+ // Remove any tokens after the cursor
59
+ tokens = tokens . filter ( token => token . range . end <= cursorIndex ) ;
64
60
65
- let lastToken : Token | undefined ;
66
- while ( tokens [ tokenIndex ] && [ `block` , `word` , `dot` ] . includes ( tokens [ tokenIndex ] . type ) && lastToken ?. type !== tokens [ tokenIndex ] . type && tokenIndex > 0 ) {
67
- lastToken = tokens [ tokenIndex ] ;
68
- tokenIndex -- ;
69
- }
61
+ // Get the possible variable we're referring to
62
+ let tokenIndex = Parser . getReference ( tokens , cursorIndex ) ;
70
63
71
64
let currentDef : Declaration | undefined ;
72
65
0 commit comments