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