Skip to content

zls 0.14 build on save diagnostic not refreshing on macOS 15.3.1 #2221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Sped0n opened this issue Mar 8, 2025 · 4 comments
Open

zls 0.14 build on save diagnostic not refreshing on macOS 15.3.1 #2221

Sped0n opened this issue Mar 8, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@Sped0n
Copy link

Sped0n commented Mar 8, 2025

Zig Version

0.14.0

ZLS Version

0.14.0

Client / Code Editor / Extensions

nvim 0.10.4 with nvim-lspconfig

Steps to Reproduce and Observed Behavior

  1. clone https://github.com/Sped0n/zh (commit 13832c3)
  2. open src/input.zig, go to line 143, change .pop() to .popOrNull()
  3. save file, no build on save error appeared (it works in 0.13)
  4. restart lsp, it give build on save error (zls: no field or member function named 'popOrNull' in 'array_list.ArrayListAligned(u8,null)')
  5. change .popOrNull() back to .pop(), then save
  6. after saved, build on save error persist (doesnt refresh)
  7. restart lsp, build on save error no longer shows

Expected Behavior

build on save diagnostic could refresh normally after save

Relevant log output

----- zls log -----
info  ( main ): Starting ZLS      0.14.0 @ '/Users/spedon/.local/share/mise/installs/zls/0.14.0/zls'
info  ( main ): Log File:         /Users/spedon/Library/Caches/zls/zls.log (info)
info  (server): Client Info:      Neovim-0.10.4
info  (server): Autofix Mode:     source.fixall
info  (server): added Workspace Folder: file:///Users/spedon/eden/zig/zh
info  (server): Set config option 'builtin_path' to "/Users/spedon/Library/Caches/zls/builtin.zig"
info  (server): Set config option 'zig_lib_path' to "/Users/spedon/.local/share/mise/installs/zig/0.14.0/lib"
info  (server): Set config option 'zig_exe_path' to "/Users/spedon/.local/share/mise/installs/zig/0.14.0/bin/zig"
info  (server): Set config option 'build_runner_path' to "/Users/spedon/Library/Caches/zls/build_runner/66ed948cb34b142db738951608c6140d/build_runner.zig"
info  (server): Set config option 'global_cache_path' to "/Users/spedon/Library/Caches/zls"
info  (server): Loaded config:      /Users/spedon/Library/Application Support/zls.json
info  (server): Set config option 'enable_build_on_save' to true
info  (store ): Loaded build file 'file:///Users/spedon/eden/zig/zh/build.zig'
info  (server): trying to start Build-On-Save for 'file:///Users/spedon/eden/zig/zh'
info  ( main ): Starting ZLS      0.14.0 @ '/Users/spedon/.local/share/mise/installs/zls/0.14.0/zls'
info  ( main ): Log File:         /Users/spedon/Library/Caches/zls/zls.log (info)
info  (server): Client Info:      Neovim-0.10.4
info  (server): Autofix Mode:     source.fixall
info  (server): added Workspace Folder: file:///Users/spedon/eden/zig/zh
info  (server): Set config option 'builtin_path' to "/Users/spedon/Library/Caches/zls/builtin.zig"
info  (server): Set config option 'zig_lib_path' to "/Users/spedon/.local/share/mise/installs/zig/0.14.0/lib"
info  (server): Set config option 'zig_exe_path' to "/Users/spedon/.local/share/mise/installs/zig/0.14.0/bin/zig"
info  (server): Set config option 'build_runner_path' to "/Users/spedon/Library/Caches/zls/build_runner/66ed948cb34b142db738951608c6140d/build_runner.zig"
info  (server): Set config option 'global_cache_path' to "/Users/spedon/Library/Caches/zls"
info  (server): Loaded config:      /Users/spedon/Library/Application Support/zls.json
info  (server): Set config option 'enable_build_on_save' to true
info  (store ): Loaded build file 'file:///Users/spedon/eden/zig/zh/build.zig'
info  (server): trying to start Build-On-Save for 'file:///Users/spedon/eden/zig/zh'
info  ( main ): Starting ZLS      0.14.0 @ '/Users/spedon/.local/share/mise/installs/zls/0.14.0/zls'
info  ( main ): Log File:         /Users/spedon/Library/Caches/zls/zls.log (info)
info  (server): Client Info:      Neovim-0.10.4
info  (server): Autofix Mode:     source.fixall
info  (server): added Workspace Folder: file:///Users/spedon/eden/zig/zh
info  (server): Set config option 'builtin_path' to "/Users/spedon/Library/Caches/zls/builtin.zig"
info  (server): Set config option 'zig_lib_path' to "/Users/spedon/.local/share/mise/installs/zig/0.14.0/lib"
info  (server): Set config option 'zig_exe_path' to "/Users/spedon/.local/share/mise/installs/zig/0.14.0/bin/zig"
info  (server): Set config option 'build_runner_path' to "/Users/spedon/Library/Caches/zls/build_runner/66ed948cb34b142db738951608c6140d/build_runner.zig"
info  (server): Set config option 'global_cache_path' to "/Users/spedon/Library/Caches/zls"
info  (server): Loaded config:      /Users/spedon/Library/Application Support/zls.json
info  (server): Set config option 'enable_build_on_save' to true
info  (store ): Loaded build file 'file:///Users/spedon/eden/zig/zh/build.zig'
info  (server): trying to start Build-On-Save for 'file:///Users/spedon/eden/zig/zh'

lsplog.txt

@Sped0n Sped0n added the bug Something isn't working label Mar 8, 2025
@Sped0n
Copy link
Author

Sped0n commented Mar 8, 2025

Download vscode to test and get the same weird behaviour

Image

@Sped0n
Copy link
Author

Sped0n commented Mar 9, 2025

Have done some investigations myself, it seems the behaviour is caused by the watch implementation

After force it use manual implementation instead of zig's builtin watch, refreshing works normally.

Also, zig build --watch failed to detect file changes made by neovim(havn't try other editor yet), kinda like what happens in ziglang/zig#21905 (my laptop is on macOS 15.3.1 though).

Maybe we can provide a config option to disable watch implementation? I'm willing to make a pr.


Edited

Below is my monkey patch diff, just for those who are impatient just like me

diff --git a/src/Server.zig b/src/Server.zig
index 13ae7d1..96aa565 100644
--- a/src/Server.zig
+++ b/src/Server.zig
@@ -765,7 +765,7 @@ const Workspace = struct {
 
         if (args.server.runtime_zig_version) |runtime_zig_version| {
             workspace.build_on_save_mode = switch (BuildOnSaveSupport.isSupportedRuntime(runtime_zig_version)) {
-                .supported => .watch,
+                .supported => .manual,
                 // If if build on save has been explicitly enabled, fallback to the implementation with manual updates
                 else => if (args.server.config.enable_build_on_save orelse false) .manual else null,
             };
diff --git a/src/build_runner/0.14.0.zig b/src/build_runner/0.14.0.zig
index d3480df..6c2dfca 100644
--- a/src/build_runner/0.14.0.zig
+++ b/src/build_runner/0.14.0.zig
@@ -468,30 +468,21 @@ const Watch = struct {
     fn init() !Watch {
         return .{
             .fs_watch = if (@TypeOf(std.Build.Watch) != void) try std.Build.Watch.init() else {},
-            .supports_fs_watch = @TypeOf(std.Build.Watch) != void and shared.BuildOnSaveSupport.isSupportedRuntime(builtin.zig_version) == .supported,
+            .supports_fs_watch = false,
             .manual_event = .{},
             .steps = &.{},
         };
     }
 
-    fn update(w: *Watch, gpa: Allocator, steps: []const *Step) !void {
-        if (@TypeOf(std.Build.Watch) != void and w.supports_fs_watch) {
-            return try w.fs_watch.update(gpa, steps);
-        }
+    fn update(w: *Watch, _: Allocator, steps: []const *Step) !void {
         w.steps = steps;
     }
 
     fn trigger(w: *Watch) void {
-        if (w.supports_fs_watch) {
-            @panic("received manualy filesystem event even though std.Build.Watch is supported");
-        }
         w.manual_event.set();
     }
 
     fn wait(w: *Watch, gpa: Allocator, timeout: std.Build.Watch.Timeout) !std.Build.Watch.WaitResult {
-        if (@TypeOf(std.Build.Watch) != void and w.supports_fs_watch) {
-            return try w.fs_watch.wait(gpa, timeout);
-        }
         switch (timeout) {
             .none => w.manual_event.wait(),
             .ms => |ms| w.manual_event.timedWait(@as(u64, ms) * std.time.ns_per_ms) catch return .timeout,

@Sped0n Sped0n changed the title zls 0.14 build on save diagnostic not refreshing zls 0.14 build on save diagnostic not refreshing on macOS 15.3.1 Mar 9, 2025
@GreyElaina
Copy link

GreyElaina commented Mar 21, 2025

After my tracking it seems manual impl is the best way for now, rather than keep it broken right now.

see ziglang/zig#21905, ziglang/zig#1333, ziglang/zig#1349 and https://github.com/tpoechtrager/osxcross.

My patch here, added new config item build_on_save_alternative_watch to force zls use manual way.

@lordnoriyuki
Copy link

Works for me. Thank you @GreyElaina!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants