@@ -320,20 +320,34 @@ export default class Analyzer {
320320 // checked.
321321 let definedVariableInExpression = false
322322
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+
330340 definedSymbol = n . descendantsOfType ( 'variable_name' ) . at ( 0 )
331341 definedVariableInExpression =
332- n . type === 'variable_assignment' &&
333342 n . endPosition . row >= position . line &&
334343 ! ! definedSymbol &&
335344 ( definedSymbol . endPosition . column < position . character ||
336345 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 )
337351 } else if ( kind === LSP . SymbolKind . Function && n . type === 'function_definition' ) {
338352 definedSymbol = n . firstNamedChild
339353 }
@@ -382,6 +396,7 @@ export default class Analyzer {
382396 if ( definedVariable ?. text === word && ! definedVariableInExpression ) {
383397 declaration = definedVariable
384398 continueSearching = false
399+ break
385400 }
386401 }
387402
0 commit comments