@@ -320,20 +320,34 @@ export default class Analyzer {
320
320
// checked.
321
321
let definedVariableInExpression = false
322
322
323
- if (
324
- kind === LSP . SymbolKind . Variable &&
325
- ( [ 'declaration_command' , 'variable_assignment' , 'for_statement' ] . includes (
326
- n . type ,
327
- ) ||
328
- ( n . type === 'command' && n . text . includes ( ':=' ) ) )
329
- ) {
323
+ if ( kind === LSP . SymbolKind . Variable && n . type === 'variable_assignment' ) {
324
+ const declarationCommand = TreeSitterUtil . findParentOfType (
325
+ n ,
326
+ 'declaration_command' ,
327
+ )
328
+
329
+ if (
330
+ declarationCommand &&
331
+ TreeSitterUtil . findParentOfType ( declarationCommand , 'function_definition' )
332
+ ?. lastChild ?. type === 'compound_statement' &&
333
+ [ 'local' , 'declare' , 'typeset' ] . includes (
334
+ declarationCommand . firstChild ?. text as any ,
335
+ )
336
+ ) {
337
+ return false
338
+ }
339
+
330
340
definedSymbol = n . descendantsOfType ( 'variable_name' ) . at ( 0 )
331
341
definedVariableInExpression =
332
- n . type === 'variable_assignment' &&
333
342
n . endPosition . row >= position . line &&
334
343
! ! definedSymbol &&
335
344
( definedSymbol . endPosition . column < position . character ||
336
345
definedSymbol . endPosition . row < position . line )
346
+ } else if (
347
+ kind === LSP . SymbolKind . Variable &&
348
+ ( n . type === 'for_statement' || ( n . type === 'command' && n . text . includes ( ':=' ) ) )
349
+ ) {
350
+ definedSymbol = n . descendantsOfType ( 'variable_name' ) . at ( 0 )
337
351
} else if ( kind === LSP . SymbolKind . Function && n . type === 'function_definition' ) {
338
352
definedSymbol = n . firstNamedChild
339
353
}
@@ -382,6 +396,7 @@ export default class Analyzer {
382
396
if ( definedVariable ?. text === word && ! definedVariableInExpression ) {
383
397
declaration = definedVariable
384
398
continueSearching = false
399
+ break
385
400
}
386
401
}
387
402
0 commit comments