zls
zls copied to clipboard
zls can't parse packages on windows in vscode
I build the latest zls using the master version of zig 0.10.0-dev.1902+42ed34d1f
, but I had this issue with a previous version as well.
For any package other than std
zls doesnt seem to notice the packages I use with addPackage
. On Linux however, someone else confirmed to me that the same project works with zls and vscode.
I tried flattening the project structure completely to minimize the potential for any issues, so I just have 3 files:
- build.zig
- main.zig
- nanoid.zig (the package I want to use)
I even tried specifying the package directly in my build.zig
.
const std = @import("std");
pub fn build(b: *std.build.Builder) void
{
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const pkg = std.build.Pkg{
.name = "nanoid",
.path = .{ .path = "nanoid.zig" },
.dependencies = null,
};
const exe = b.addExecutable("example", "main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.addPackage(pkg);
exe.install();
}
I also did zls config
and added the following lines to my settings.json
:
"zigLanguageClient.path": "C:/Tools/zls",
"zigLanguageClient.debugLog": true
I enabled debug logging and the logs show that it just doesn't extract any package.
Enabled debug logging
[Info - 09:41:00] [info-main] Using zig executable C:\Tools\zig\0.10.0-dev.1902+42ed34d1f\files\zig.exe
[Info - 09:41:00] [info-main] Using zig lib path 'C:\Tools\zig\0.10.0-dev.1902+42ed34d1f\files\lib'
[Info - 09:41:00] [info-main] zls initialized
[Info - 09:41:00] [info-main] ClientCapabilities{ .supports_snippets = true, .supports_semantic_tokens = true, .hover_supports_md = true, .completion_doc_supports_md = true }
[Info - 09:41:00] [info-main] Using offset encoding: utf16
[debug-main] Took 0ms to process method initialize
[debug-main] Took 0ms to process method initialized
[debug-doc_store] Opened document: file:///c%3A/Users/LucaSas/Documents/Projects/ZigExample/main.zig
[debug-doc_store] Opened document: file:///c%3A/Users/LucaSas/Documents/Projects/ZigExample/build.zig
[debug-doc_store] Document is a build file, extracting packages...
[Info - 09:41:00] [info-doc_store] builtin config not found, falling back to default: file:///c%3A/ProgramData/builtin.zig
[debug-doc_store] Associated build file `file:///c%3A/Users/LucaSas/Documents/Projects/ZigExample/build.zig` to document `file:///c%3A/Users/LucaSas/Documents/Projects/ZigExample/main.zig`
[debug-doc_store] Opened document: file:///c%3A/Tools/zig/0.10.0-dev.1902%2B42ed34d1f/files/lib/std/std.zig
[debug-doc_store] Opened document: file:///c%3A/Tools/zig/0.10.0-dev.1902%2B42ed34d1f/files/lib/std/log.zig
[debug-main] Took 43ms to process method textDocument/didOpen
[debug-main] Method without return value not implemented: $/setTrace
I would have expected it to find the package I added.
To further clarify, if I moved the thirdparty
folder into my src
folder and directly imported the zig files in my main.zig
like so:
const nanoid = @import("thirdparty/zig-nanoid/src/nanoid.zig");
I get all the zls features without issue doing this. So it seems pretty clear to me that the problem has something to do with how the info regarding packages is extracted from build.zig
.
I have the same problem, here is something interesting in the debug log
[debug-doc_store] Opened document: file:///c%3A/dev/kdomz/build.zig
[debug-doc_store] Document is a build file, extracting packages...
[Info - 12:28:12 PM] [info-doc_store] builtin config not found, falling back to default: file:///c%3A/Users/ryuukk/AppData/Local/builtin.zig
[Warn - 12:28:12 PM] [warn-doc_store] Failed to load packages of build file file:///c%3A/dev/kdomz/build.zig (error: error.RunFailed)
I'd guess somewhere is a path issue
After testing with random stuff, now it works
I don't understand, and i don't remember what i did exactly
I think i removed all the files related to zls, and restarted vscode, but i'm not sure
@ryuukk You haven't had this issue since? I'm seeing the same thing on Windows, but macOS is fine. On Windows I have the std
package but not added packages.
If you are still getting this issue can you check the output in vscode again as a much better error should be provided due to #569
Thanks for the info! I made sure I was up to date with master and saw in the output that ZLS was finding a much older version of zig as default. I'm sure that's my fault, but I've been just downloading from ziglang.org and changing my PATH to zig for new versions, letting the older ones hang around. I'm not sure why ZLS decided to not use the one in PATH and use an older version instead but deleting all the older versions I had seemed to fix the issue.
People have had issues before with setting their path in for example zsh but having the path of gui applications be different, meaning when vscode was launched from a terminal it would get the correct path but from the application launcher it would not, I have no idea if Windows can experience issues like this.
I will close this, don't hesitate to open another for any other issues.