| ... | ... | @@ -809,6 +809,11 @@ pub fn main(init: process.Init.Minimal) !void { |
| 809 | 809 | var select: Io.Select(Event) = .init(io, &select_buffer); |
| 810 | 810 | defer select.cancelDiscard(); |
| 811 | 811 | |
| 812 | // File watching cannot be canceled without blocking |
| 813 | // https://codeberg.org/ziglang/zig/issues/31693 |
| 814 | var is_fs_watching = false; |
| 815 | defer if (is_fs_watching) @panic("(zig build system) TODO file watching cannot be canceled without blocking"); |
| 816 | |
| 812 | 817 | try select.concurrent(.message, Server.receiveMessage, .{s}); |
| 813 | 818 | |
| 814 | 819 | var in_debounce = false; |
| ... | ... | @@ -816,8 +821,14 @@ pub fn main(init: process.Init.Minimal) !void { |
| 816 | 821 | .message => |payload| { |
| 817 | 822 | const header: Client.Message.Header = try payload; |
| 818 | 823 | switch (header.tag) { |
| 819 | | .exit => return cleanExit(io, &scanned_config), |
| 824 | .exit => { |
| 825 | // exit early until file watching supports cancelation without blocking |
| 826 | if (is_fs_watching) std.process.exit(0); |
| 827 | return cleanExit(io, &scanned_config); |
| 828 | }, |
| 820 | 829 | .bsp_build_steps => { |
| 830 | if (is_fs_watching) @panic("(zig build system) TODO file watching cannot be canceled without blocking"); |
| 831 | |
| 821 | 832 | // Cancel existing file watching |
| 822 | 833 | select.cancelDiscard(); |
| 823 | 834 | in_debounce = false; |
| ... | ... | @@ -851,6 +862,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 851 | 862 | &watch.?, |
| 852 | 863 | if (in_debounce) .{ .ms = debounce_interval_ms } else .none, |
| 853 | 864 | }); |
| 865 | is_fs_watching = true; |
| 854 | 866 | } else if (watch) |*w| { |
| 855 | 867 | w.deinit(); |
| 856 | 868 | watch = null; |
| ... | ... | @@ -862,6 +874,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 862 | 874 | } |
| 863 | 875 | }, |
| 864 | 876 | .fs_event => |payload| { |
| 877 | is_fs_watching = false; |
| 865 | 878 | if (!Watch.have_impl) unreachable; |
| 866 | 879 | switch (payload catch |err| switch (err) { |
| 867 | 880 | error.MustReconfigure => { |
| ... | ... | @@ -883,6 +896,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 883 | 896 | &watch.?, |
| 884 | 897 | if (in_debounce) .{ .ms = debounce_interval_ms } else .none, |
| 885 | 898 | }); |
| 899 | is_fs_watching = true; |
| 886 | 900 | continue :loop try select.await(); |
| 887 | 901 | }, |
| 888 | 902 | } |