zigtools / zls

A Zig language server supporting Zig developers with features like autocomplete and goto definition
MIT License
2.82k stars 283 forks source link

ZLS can't find module imports when the project is on an external drive #1927

Open Zylann opened 2 months ago

Zylann commented 2 months ago

Zig Version

0.12

Zig Language Server Version

0.12.0

Client / Code Editor / Extensions

VSCode 1.90.2

Steps to Reproduce and Observed Behavior

I have my Zig project on an external SSD (plugged in USB), and noticed that module imports added via the package manager like raylib or ztracy fail to resolve. "Go to definition", completion or highlighting don't work. image

In this project, raylib is added via automatic download, while ztracy is manually installed in the project itself. But either way, neither are found.

Inspecting logs shows this gets printed often:

error: (store ): Failed to load build configuration for file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig (error: error.RunFailed)
error: (store ): Failed to execute build runner to collect build configuration, command:
D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig
Error: error: FileNotFound

My project compiles and runs fine though. Not sure which file exactly it can't find, but i suspect it's build.zig itself?

I'm on Windows 10 and my external SSD is currently called F:. I tried copying my project to my internal drive D:, and imports magically worked. So there might be something wrong with the handling of external drives?

Expected Behavior

ZLS should resolve imports correctly even if the project is on an USB drive.

Relevant log output

error: (store ): Failed to load build configuration for file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig (error: error.RunFailed)
error: (store ): Failed to execute build runner to collect build configuration, command:
D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig
Error: error: FileNotFound

Additional note: on a separate computer, using Windows 11, my SSD had the character D: and imports seemed to resolve. Not sure what factor is at play here.

Techatrix commented 2 months ago

Would be nice if the FileNotFound error would show which file it is talking about.. :(

Could you post ZLS's entire log output. Ideally with the `zig.zls.debugLog option enabled in VS Code.

Could you try deleting any local zig-cache and any global cache directory? The global cache directories for Zig and ZLS should be here:

Could you try opening a terminal in the f:/PROJETS/INFO/Zig/TestZigRaylib/Project/ directory and run D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig. Check to make sure that ZLS has previously created the build_runner_0.12.0.zig file. Does it produce the same file not found error?

Does this happen with a new zig init project or just this one?

Zylann commented 2 months ago

Could you post ZLS's entire log output. Ideally with the `zig.zls.debugLog option enabled in VS Code.

Only doing that gives that log:

info : ( main ): Enabled debug logging.
info : ( main ): Starting ZLS 0.12.0 @ 'c:\Users\Marc\AppData\Roaming\Code\User\globalStorage\ziglang.vscode-zig\zls_install\zls.exe'
info : (server): Client is 'Visual Studio Code-1.90.2'
debug: (server): Offset Encoding: utf-16
info : (server): No config file zls.json found. This is not an error.
info : (server): Set config option 'builtin_path' to 'C:\Users\Marc\AppData\Local\Temp\zls\builtin.zig'
info : (server): Set config option 'zig_lib_path' to 'D:\Apps\Zig\zig-windows-x86_64-0.12.0\lib'
info : (server): Set config option 'zig_exe_path' to 'D:\Apps\Zig\zig-windows-x86_64-0.12.0\zig.exe'
info : (server): Set config option 'build_runner_path' to 'C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig'
info : (server): Set config option 'global_cache_path' to 'C:\Users\Marc\AppData\Local\Temp\zls'
info : (server): Set config option 'build_runner_global_cache_path' to 'C:\Users\Marc\AppData\Local\zig'
debug: (server): Took 76ms to process request-0-initialize on Thread 6052
debug: (server): Dynamically registering method 'workspace/didChangeConfiguration'
debug: (server): Took 0ms to process notification-initialized on Thread 6052
debug: (store ): Resolved build file of `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/tests/terrain_test.zig` as `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/tests/terrain_test.zig`
debug: (server): Took 0ms to process notification-textDocument/didOpen on Thread 6052
debug: (server): Took 0ms to process response-register-workspace/didChangeConfiguration on Thread 6052
error: (store ): Failed to execute build runner to collect build configuration, command:
D:\Apps\Zig\zig-windows-x86_64-0.12.0\zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig
Error: error: FileNotFound

error: (store ): Failed to load build configuration for file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig (error: error.RunFailed)
info : (server): Set config option 'semantic_tokens' to 'partial'
info : (server): Set config option 'enable_inlay_hints' to 'false'
info : (server): Set config option 'inlay_hints_show_builtin' to 'false'
info : (server): Set config option 'zig_exe_path' to 'D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe'
debug: (server): Took 53ms to process response-i_haz_configuration on Thread 6052
debug: (server): Took 0ms to process request-1-textDocument/inlayHint on Thread 13384
debug: (server): Took 0ms to process notification-$/setTrace on Thread 6052
debug: (server): Took 0ms to process notification-workspace/didChangeConfiguration on Thread 6052
error: (store ): Failed to execute build runner to collect build configuration, command:
D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig
Error: error: FileNotFound

error: (store ): Failed to load build configuration for file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig (error: error.RunFailed)
debug: (server): Took 30ms to process request-2-textDocument/codeAction on Thread 6052
debug: (server): Took 0ms to process response-semantic_tokens_refresh on Thread 6052
debug: (server): Took 0ms to process notification-$/setTrace on Thread 6052
debug: (server): Took 0ms to process notification-workspace/didChangeConfiguration on Thread 6052
debug: (store ): Opened document `file:///d%3A/Apps/Zig/zig-windows-x86_64-0.12.0/lib/std/std.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/math/math.zig`
debug: (store ): Resolved build file of `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/cube.zig` as `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/cube.zig`
debug: (store ): Resolved build file of `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/util/free_camera.zig` as `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/util/free_camera.zig`
debug: (store ): Resolved build file of `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/mesher.zig` as `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/mesher.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/math/vector3f.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/math/vector2f.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/math/vector3i.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/math/vector2i.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/math/box3i.zig`
debug: (store ): Resolved build file of `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/terrain.zig` as `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/terrain.zig`
debug: (store ): Resolved build file of `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/terrain_renderer.zig` as `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/terrain_renderer.zig`
debug: (store ): Resolved build file of `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/light.zig` as `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/light.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/dda.zig`
debug: (store ): Resolved build file of `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/util/raylib_util.zig` as `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/util/raylib_util.zig`
debug: (store ): Opened document `file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/src/voxel/blocks.zig`
debug: (store ): Opened document `file:///d%3A/Apps/Zig/zig-windows-x86_64-0.12.0/lib/std/mem.zig`
debug: (store ): Opened document `file:///d%3A/Apps/Zig/zig-windows-x86_64-0.12.0/lib/std/mem/Allocator.zig`
debug: (store ): Opened document `file:///d%3A/Apps/Zig/zig-windows-x86_64-0.12.0/lib/std/time.zig`
debug: (store ): Opened document `file:///d%3A/Apps/Zig/zig-windows-x86_64-0.12.0/lib/std/debug.zig`
debug: (store ): Opened document `file:///d%3A/Apps/Zig/zig-windows-x86_64-0.12.0/lib/std/fmt.zig`
debug: (store ): Opened document `file:///d%3A/Apps/Zig/zig-windows-x86_64-0.12.0/lib/std/math.zig`
debug: (server): Took 44ms to process request-3-textDocument/semanticTokens/full on Thread 13384
debug: (server): Took 90ms to process response-i_haz_configuration on Thread 6052
debug: (server): Took 0ms to process notification-$/cancelRequest on Thread 17212
debug: (server): Took 0ms to process notification-$/cancelRequest on Thread 13384
debug: (server): Took 0ms to process request-4-textDocument/foldingRange on Thread 6052
debug: (server): Took 70ms to process request-5-textDocument/codeAction on Thread 17212
error: (store ): Failed to execute build runner to collect build configuration, command:
D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig
Error: error: FileNotFound

error: (store ): Failed to load build configuration for file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig (error: error.RunFailed)
debug: (server): Took 100ms to process request-6-textDocument/codeAction on Thread 13384
debug: (server): Took 0ms to process notification-$/setTrace on Thread 6052
debug: (server): Took 0ms to process notification-workspace/didChangeConfiguration on Thread 6052
debug: (server): Took 75ms to process response-i_haz_configuration on Thread 6052
debug: (server): Took 0ms to process request-7-textDocument/documentSymbol on Thread 17212
debug: (server): Took 0ms to process response-semantic_tokens_refresh on Thread 6052
debug: (server): Took 2ms to process request-8-textDocument/semanticTokens/full on Thread 1236
debug: (server): Took 0ms to process notification-$/setTrace on Thread 6052
debug: (server): Took 0ms to process notification-workspace/didChangeConfiguration on Thread 6052
debug: (server): Took 90ms to process response-i_haz_configuration on Thread 6052
debug: (server): Took 0ms to process response-semantic_tokens_refresh on Thread 6052
error: (store ): Failed to execute build runner to collect build configuration, command:
D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig
Error: error: FileNotFound

error: (store ): Failed to load build configuration for file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig (error: error.RunFailed)
debug: (server): Took 69ms to process response-i_haz_configuration on Thread 6052
debug: (server): Took 0ms to process response-semantic_tokens_refresh on Thread 6052
debug: (server): Took 2ms to process request-9-textDocument/semanticTokens/full on Thread 1236
debug: (server): Took 0ms to process response-semantic_tokens_refresh on Thread 6052
error: (store ): Failed to execute build runner to collect build configuration, command:
D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig
Error: error: FileNotFound

error: (store ): Failed to load build configuration for file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig (error: error.RunFailed)
error: (store ): Failed to execute build runner to collect build configuration, command:
D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig
Error: error: FileNotFound

error: (store ): Failed to load build configuration for file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig (error: error.RunFailed)
debug: (server): Took 1ms to process request-10-textDocument/semanticTokens/full on Thread 1588
debug: (server): Took 22ms to process request-11-textDocument/codeAction on Thread 1236
debug: (server): Took 0ms to process notification-$/setTrace on Thread 6052
debug: (server): Took 0ms to process notification-workspace/didChangeConfiguration on Thread 6052
debug: (server): Took 51ms to process response-i_haz_configuration on Thread 6052
debug: (server): Took 0ms to process response-semantic_tokens_refresh on Thread 6052
debug: (server): Took 1ms to process request-12-textDocument/semanticTokens/full on Thread 17212
error: (store ): Failed to execute build runner to collect build configuration, command:
D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig
Error: error: FileNotFound

error: (store ): Failed to load build configuration for file:///f%3A/PROJETS/INFO/Zig/TestZigRaylib/Project/build.zig (error: error.RunFailed)
debug: (server): Took 16ms to process request-13-textDocument/codeAction on Thread 1588
debug: (server): Took 17ms to process request-14-textDocument/codeAction on Thread 1236
debug: (server): Took 0ms to process request-15-textDocument/inlayHint on Thread 17212
debug: (server): Took 0ms to process request-16-textDocument/inlayHint on Thread 13384
debug: (server): Took 0ms to process request-17-textDocument/inlayHint on Thread 1588
debug: (server): Took 0ms to process request-18-textDocument/inlayHint on Thread 1236
debug: (server): Took 0ms to process request-19-textDocument/inlayHint on Thread 17212
debug: (server): Took 17ms to process request-20-textDocument/codeAction on Thread 13384
debug: (server): Took 15ms to process request-21-textDocument/codeAction on Thread 1588

Could you try deleting any local zig-cache and any global cache directory?

Deleting my zig-cache got rid of the problem. Something to note is that I've not cleared that cache in a while, so by now I have compiled this project several times on more than one computer (all Windows). Although everytime compiling succeeds just fine, so I'd expect ZLS to not have such issue. For some reason it might be clinging onto something outdated that's not getting updated in the cache?

I brought back the offending cache (which brought back the issue) and tried clearing the global cache instead. Doing that apparently fixed the problem as well, and bringing back the old global cache brings back the issue too.

Could you try opening a terminal in the f:/PROJETS/INFO/Zig/TestZigRaylib/Project/ directory and run D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig. Check to make sure that ZLS has previously created the build_runner_0.12.0.zig file. Does it produce the same file not found error?

Doing this runs some stuff and gives a JSON output, it doesn't print errors:

PS F:\PROJETS\INFO\Zig\TestZigRaylib\Project> D:/Apps/Zig/zig-windows-x86_64-0.12.0/zig.exe build --build-runner C:\Users\Marc\AppData\Local\Temp\zls\build_runner_0.12.0.zig
{
 "deps_build_roots": [
  {
   "name": "raylib-zig",
   "path": "C:\\Users\\Marc\\AppData\\Local\\zig\\p\\12204a223b19043e17b79300413d02f60fc8004c0d9629b8d8072831e352a78bf212\\build.zig"
  },
  {
   "name": "ztracy",
   "path": "F:\\PROJETS\\INFO\\Zig\\TestZigRaylib\\Project\\src\\thirdparty\\ztracy\\build.zig"
  }
 ],
 "packages": [
  {
   "name": "root",
   "path": "F:\\PROJETS\\INFO\\Zig\\TestZigRaylib\\Project\\src\\main.zig"
  },
  {
   "name": "raylib",
   "path": "C:\\Users\\Marc\\AppData\\Local\\zig\\p\\12204a223b19043e17b79300413d02f60fc8004c0d9629b8d8072831e352a78bf212\\lib\\raylib.zig"
  },
  {
   "name": "ztracy",
   "path": "F:\\PROJETS\\INFO\\Zig\\TestZigRaylib\\Project\\src\\thirdparty\\ztracy\\src\\ztracy.zig"
  },
  {
   "name": "ztracy_options",
   "path": "F:\\PROJETS\\INFO\\Zig\\TestZigRaylib\\Project\\zig-cache\\c\\2859f576435c83a0468141622833ef35\\options.zig"
  }
 ],
 "include_dirs": [
  "C:\\Users\\Marc\\AppData\\Local\\zig\\p\\1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26\\src\\external\\glfw\\include",
  "C:\\Users\\Marc\\AppData\\Local\\zig\\p\\1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26\\src",
  "C:\\Users\\Marc\\AppData\\Local\\zig\\p\\122002d98ca255ec706ef8e5497b3723d6c6e163511761d116dac3aee87747d46cf1\\src",
  "F:\\PROJETS\\INFO\\Zig\\TestZigRaylib\\Project\\zig-cache\\o\\12b084dadfe2d9ceaa40c3d586a8d495",
  "F:\\PROJETS\\INFO\\Zig\\TestZigRaylib\\Project\\src\\thirdparty\\ztracy\\libs\\tracy\\tracy"
 ]
}

If you meant launching VSCode again afterwards to see if it prints the error, then it still prints it.

Does this happen with a new zig init project or just this one?

Havent tried that one but given what I found above it might not have the issue until I switch computer.

Techatrix commented 2 months ago

Deleting my zig-cache got rid of the problem.

Then it seems like you somehow had a corrupted Zig cache. I doubt that an issue with the caching system is caused by ZLS but I also don't know the cause of this. If you find a reproducible way to create a corrupted cache then this can be reported to Zig but otherwise I don't think there is anything to resolve here.