Closed wilkster closed 1 year ago
Re-implementation of parsing reference relationships, there may be bugs.
It is best to provide short examples that reproduce the issue.
I found the issue. I had two lib files that referenced each other (via #include statements), and did this for a prior version to not show undefined variable references. I removed one of the #includes and it cleared the issue up. Is it now the case that you no longer walk the #include path to determine references, but just use all of the files in the current folder tree to build the references?
One other datapoint, it appears I had AutoLibInclude enabled for local. I put it back to disabled (default). Given you made some parsing changes with this update I recommend closing this issue. If it crops up again I will try to reproduce on a small set of files,
I think I can re-create the issue now (using 2.2.3). Create a main file with the following (main.ahk2)
#Requires AutoHotkey >=2.0
#Include %A_ScriptDir%\Lib
#Include MyLib.ahk2
#Include MyOtherLib.ahk2
LogMessage(A_ScriptName ": Loading Autohotkey Version " A_AhkVersion)
OtherLog(A_ScriptName ": Loading Autohotkey Version " A_AhkVersion)
And in a subfolder called lib add MyLib.ahk2
#Requires AutoHotkey >=2.0
#include MyOtherLib.ahk2
LogMessage(txt) {
OutputDebug(txt)
}
As well as a file called MyOtherLib.ahk2
#Requires AutoHotkey >=2.0
#Include MyLib.ahk2
OtherLog(txt) {
OutputDebug(txt)
}
Notice how the two lib files reference each other (I know, not good practice...), the two log calls in the main file then get the Variable never assigned a value. If you comment out one of the #includes in either of the lib files (then toggle commenting on the main file #Include %A_ScriptDir%\Lib
statement to force a scan, the issue clears up.
I have a similar issue in paring include files, espacially the lib is in form of #Include <lib_path>
. And my lib files are located in "directory-of-the-currently-running-AutoHotkey.exe\Lib\"
This issue is easy to reproduce. Save the following three scripts and open "3. ahk" to see the effect.
; This file is "1.ahk"
#Requires AutoHotkey v2.0
#Include "2.ahk"
This_Is_1()
{
MsgBox(1)
}
; This file is "2.ahk"
#Requires AutoHotkey v2.0
#Include "1.ahk"
This_Is_2()
{
MsgBox(2)
}
; This file is "3.ahk"
#Requires AutoHotkey v2.0
#Include "1.ahk"
This_Is_1() ; VSCode will mark this line as an error. But this is actually completely correct.
This_Is_2() ; VSCode will mark this line as an error. But this is actually completely correct.
@aseiot The above issues are caused by circular references. Is yours too?
@aseiot The above issues are caused by circular references. Is yours too?
I get the same issues as described. I only use <lib>
references from the local lib
folder.
I don't use circular references (that might even trigger AHK to complain i think, so might be a valid error).
In my case forcing the lexer to re-parse libs fixes the issue temporarily. It shows up again from time to time when I open the script.
@aseiot The above issues are caused by circular references. Is yours too?
No, my issue still exist after the update
I found it related with 'libdirs' does not contain the "directory-of-the-currently-running-AutoHotkey.exe\Lib"
. It only contains the A_ScriptDir "\Lib\"
_this.libdirs
contains %A_ScriptDir%/Lib
, %A_MyDocuments%/Lib
, %A_AhkPath%/../Lib
Your common_1.libdirs
is empty?
You mean _this.libdirs
? It contains %A_ScriptDir%/Lib
only
https://github.com/thqby/vscode-autohotkey2-lsp/blob/main/server/src/server.ts#L277
check common_1.libdirs
and common_1.a_vars
, they are imported from common.ts
.
I notice the samefolder
is true
thus bypass the initial of libdirs
. And if I change the ahkpath_cur = ''
to anything other than blank eg. ahkpath_cur = ' '
fix this issue.
https://github.com/thqby/vscode-autohotkey2-lsp/blob/main/server/src/common.ts#L102
Not sure if this is unique to me, but with 2.2.2 (just installed), the references to functions in #include files are no longer found and are flagged with errors. The #include files themselves are still found as there is no error under the file name.
I reverted to 2.2.1/2.2.0 and the errors go away.