zls icon indicating copy to clipboard operation
zls copied to clipboard

no diagnostics for everything that depends on semantic analysis

Open Techatrix opened this issue 1 year ago • 7 comments

In its current state, ZLS is only able to report syntax errors and errors that are provided by zig ast-check. Everything else (like semantic analysis) is not available. Here are some examples of errors that are not being reported:

  • no field named 'foo' in 'bar'
  • function expected x argument(s), found y
  • expected type 'x', found 'y'
  • comptime conditional calls to @compileError (used by std.debug.print to report errors)

There have been attempts in the past that tried to partially address this:

The most viable solution right now is the build-on-save feature. This issue will remain open until it is enabled by default. Probably once incremental compilation has matured enough.

Techatrix avatar Aug 31 '24 17:08 Techatrix

Related is interfacing ZLS more directly with the compiler, for instance to provide accurate type information for variables even when complex comptime evaluation is involved. Upstream issue is ziglang/zig#615. I'm planning to begin work on this once incremental compilation is a little more mature -- @Techatrix, I'm hoping we'd be able to collaborate on integrating this with ZLS?

mlugg avatar Aug 31 '24 21:08 mlugg

@Techatrix, I'm hoping we'd be able to collaborate on integrating this with ZLS?

Definitely. I'd be happy to help wherever I can to get the compiler protocol (or whatever it will be called) going.

I also see #2001 as a necessary precursor to get this feature integrated into ZLS. The first step is to get ZLS to keep the build runner in the background (and exchange error messages). This can then be expand to use the actual compiler protocol once it manifests.

Techatrix avatar Sep 01 '24 19:09 Techatrix

Yep, agreed. I'd love to see #2001 get off the ground soon, since using incremental for a faster dev loop is somewhat viable now (there are definitely bugs, but I have used it while working on the compiler and it sorta-works!)

mlugg avatar Sep 01 '24 20:09 mlugg

Instead of opening a separate issue, I'm guessing this problem will also be solved when this issue has been finished.

Running zig test gives me error: expected error set type, found 'f32' on the line where I define maybe_thing. While ZLS doesn't show anything inside my editor.

test "own error" {
    const maybe_thing: f32!u8 = 0;
    const thing = maybe_thing catch 0.0;

    try expect(@TypeOf(thing) == u8);
    try expect(thing == 0);
}

I am new to the language and wanted to see if it had to be an error set or if it was more open, though my example with two kinds of numbers is a bit contrived.

seffradev avatar Oct 08 '24 18:10 seffradev

I had a question and feel this is the best place to ask it

Would ZLS with build-on-save enabled be able to auto-complete for types generated at comptime?

Huzaifa-MS avatar Sep 25 '25 01:09 Huzaifa-MS

Would ZLS with build-on-save enabled be able to auto-complete for types generated at comptime?

ZLS's build-on-save feature in it's current form is only providing diagnostic messages. With ziglang/zig#615, ZLS can interface with the compiler to acquire diagnostic messages as well type information that can the be used for autocompletion and much more.

Techatrix avatar Oct 15 '25 15:10 Techatrix

Thank you

Huzaifa-MS avatar Oct 21 '25 15:10 Huzaifa-MS