I have this minimal working example with just doing zig init and changing main.zig to this.
const std = @import("std");
const Allocator = std.mem.Allocator;
const MyType = struct {
const Self = @This();
pub fn init(a: Allocator, somedata: usize) Self {
_ = a;
_ = somedata;
return Self{};
}
};
pub fn main(init: std.process.Init) !void {
// incorrect usage of MyType.init, missing arg somedata
const my_instance = MyType.init(init.gpa);
_ = my_instance;
}
And when I run :lua vim.diagnostic.open_float() it shows nothing, and if I press my diagnostic key <leader>X for trouble.nvim it just says no diagnostics.
Is my editor setup wrong or zls setup incorrect?
➜ zls_mwe zig version
0.16.0
➜ zls_mwe zls version
0.16.0
➜ zls_mwe zls env
{
"version": "0.16.0",
"global_cache_dir": "/home/cocoa/.cache/zls",
"global_config_dir": "/home/cocoa/.config/kdedefaults",
"local_config_dir": "/home/cocoa/.config",
"config_file": null,
"log_file": "/home/cocoa/.cache/zls/zls.log"
}
You need to ensure zls is compiling your code, otherwise its diagnostics are very limited Build-On-Save - zigtools
You dont have to duplicate everything, that is only needed to avoid a bug in the build system that will generate and install the executable even if the installation step is never run. The custom backends, and incremental, are fast enough that it doesn’t have any impact, and the bug will be fixed in the future.
1 Like
Yay! tysm for the fix. One question tho, why doesn’t this also show me errors on the src/root.zig file?
//! By convention, root.zig is the root source file when making a package.
const std = @import("std");
const Io = std.Io;
pub fn f(_: usize) void {}
// calls f() incorrectly
pub fn g() void {
return f();
}
I added the following to my build.zig
// Step that makes zls compile check
const check = b.step("check", "check if it compiles");
check.dependOn(&exe.step);
// also make it check root.zig hopefully?
check.dependOn(&mod.step);
First part works, second part doesn’t because the module doesn’t have an associated compilation step I think?
That is likely because of lazy evaluation by the compiler.
Are you actually calling g anywhere?