thqby / vscode-autohotkey2-lsp

Autohotkey v2 Language Support using vscode-lsp.
https://marketplace.visualstudio.com/items?itemName=thqby.vscode-autohotkey2-lsp
GNU Lesser General Public License v3.0
210 stars 21 forks source link

#Include with brackets failing to find libraries #448

Closed RaptorX closed 8 months ago

RaptorX commented 9 months ago

Type: Bug

Using #include with a new project is having issues when using bracket syntax as opposed to using paths as shown in the image below:

image

Restarting vscode is not fixing the issue.


Extension version: 2.2.8 VS Code version: Code 1.84.2 (1a5daa3a0231a0fbba4f14db7ec463cf99d7768e, 2023-11-09T10:51:52.184Z) OS version: Windows_NT x64 10.0.22621 Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz (4 x 3198)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|31.88GB (19.54GB free)| |Process Argv|--crash-reporter-id 3e042e59-cb22-4371-968a-6f3e35abe666| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 vscorecescf:30445987 vscod805:30301674 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 pythonvs932:30410667 py29gd2263:30899288 vsclangdc:30486549 c4g48928:30535728 dsvsc012:30540252 azure-dev_surveyone:30548225 3biah626:30602489 f6dab269:30613381 showlangstatbar:30737416 fixshowwlkth:30771522 showindicator:30805244 pythongtdpath:30769146 i26e3531:30792625 welcomedialogc:30910334 pythonnosmt12:30797651 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 dsvsc013:30795093 dsvsc014:30804076 dsvsc015:30845448 pythontestfixt:30902429 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 2e7ec940:30885897 pythontbext0:30879054 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 aa_t_chat:30882232 ```
thqby commented 9 months ago

Not enough information to reproduce.

PythonYunfei commented 9 months ago

就像我们上次聊天谈到的,应该是目录不对.. Vscode默认是"工作区文件夹"下的Lib,而AHK默认是"脚本文件夹"下的Lib。这两个文件夹有时未必是同一个,有出入..

fashionableDark commented 9 months ago

Not enough information to reproduce.

Steps to reproduce:

  1. Create a new folder and open it in VSCode

  2. Create a lib folder and blah folder

  3. Create common.ahk in the lib folder

  4. Write a function in common.ahk:

    Hello()
    {
        MsgBox("Hello")
    }
  5. Create code.ahk in the blah folder

  6. Add to it:

    #Include <common>
    
    Hello()
  7. Set language to ahk2 if it isn't already

  8. See errors "Invalid file path" and "Variable 'Hello' appears to never be assigned a value"

If you add a main.ahk to the root and include "blah\code.ahk", it will run properly while code.ahk will not run on its own because AHK is looking for common.ahk in %A_ScriptDir%\lib (relative to the running script of course). To get working syntax highlighting in code.ahk you need to set AutoHotkey2.WorkingDirs, but annoyingly, it doesn't support the VSCode variable ${workspaceFolder}, so it has to be hard-coded.

PythonYunfei commented 9 months ago

把${workspaceFolder}换成${file}或许可以试一下..

fashionableDark commented 9 months ago

把${workspaceFolder}换成${file}或许可以试一下..

Nope, neither ${file} nor ${fileWorkspaceFolder} worked for me in any variation I tried. image

thqby commented 9 months ago

you can open main.ahk first, then open blah\code.ahk.

PythonYunfei commented 9 months ago

现在发现。就算获得了脚本文件夹路径。还是要把所有导入到该路径的#include 检验一遍。 存在因为打开先后顺序的不同,而自相矛盾的地方。麻烦且令人头疼,这个Issue,不太值得再继续做进一步的改进了。

fashionableDark commented 9 months ago

you can open main.ahk first, then open blah\code.ahk.

You are correct; that is a workaround, but I don't think people should be expected to always make sure their editor always opens on main.ahk and restart if it doesn't. This shouldn't be a part of anyone's workflow.

Guess I'll be using relative imports (#Import "..\lib\common.ahk) as a workaround for now. Not the end of the world.