genius257 / vscode-autoit

AutoIt language extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=genius257.autoit
MIT License
4 stars 3 forks source link

Incorrect variable declaration lookup within function #34

Closed genius257 closed 6 months ago

genius257 commented 1 year ago

Variable lookup within a function does not work as expected.

          @genius257 Unfortunately, the latest update appears to have broken the GTD functionality for functions. ☹️

Originally posted by @Danp2 in https://github.com/genius257/vscode-autoit/issues/24#issuecomment-1483173951

Example:

#include <Array.au3>

$x = 123

Func x()
    $x = 321
    $MB_HELP
    $x
EndFunc

The issue with the $MB_HELP declaration is caused partially by the parser: https://github.com/genius257/autoit3-pegjs/issues/33#issue-1640268416

The remaining declaration resolve problem is caused by the Local/Global/Auto scope of a variable not being taken into account, within a function.

As matching variable declarations are found within the function (before the lookup origin), the scope of the declaration must be updated.

genius257 commented 6 months ago

The behavior of goto declaration feature within a function scope is tricky. Global matching still is not perfect, and I am unsure if the current implementation is correct. I will mark this as completed for now, expecting an issue specificlly for global variable lookup behavior can be discussed, at a later date if need be.