diff options
Diffstat (limited to 'dev/lsp')
| -rw-r--r-- | dev/lsp/lsp_client.zig | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/dev/lsp/lsp_client.zig b/dev/lsp/lsp_client.zig index 10a3a3ce..9264a690 100644 --- a/dev/lsp/lsp_client.zig +++ b/dev/lsp/lsp_client.zig @@ -784,7 +784,7 @@ pub fn open(io: std.Io, arena: std.mem.Allocator, req: lsp.Req) Err!void { return; } var tr: Trace = .{}; - _ = try ensure(c, io, si, arena, req, &tr); + _ = try ensure(c, io, si, arena, req, &tr, false); var uri: std.ArrayList(u8) = .empty; try uriOf(&uri, arena, req.path); try syncDoc(c, io, si, arena, uri.items, req.source); @@ -806,7 +806,7 @@ fn answer(io: std.Io, arena: std.mem.Allocator, si: usize, req: lsp.Req, out: *s const c = &conns[si]; try c.mu.lock(io); defer c.mu.unlock(io); - const g = try ensure(c, io, si, arena, req, tr); + const g = try ensure(c, io, si, arena, req, tr, true); const before = out.end; try attempt(c, io, si, arena, req, out, tr, g); // An empty answer can beat the startup progress notification onto the wire. @@ -2024,7 +2024,7 @@ fn findBin(name: []const u8, path: []const u8, home: []const u8, buf: *[4096:0]u /// Spawn-or-return, and tell an existing server about a new project root. /// Returns the generation the caller's whole query is bound to. -fn ensure(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, req: lsp.Req, tr: *Trace) Err!u32 { +fn ensure(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, req: lsp.Req, tr: *Trace, protect_startup: bool) Err!u32 { c.si = si; if (c.state == .disabled) { tr.note("STOP: {s} is disabled for this session (no binary; set {s})", .{ specs[si].name, specs[si].env }); @@ -2155,14 +2155,16 @@ fn ensure(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, req: lsp.Re post(si, .always, "{s} starting — {s}", .{ specs[si].name, root }); tr.note("spawned {s} (pid {d}) at {s}", .{ specs[si].name, pid, root }); - // A start runs to the end however soon the query that began it is - // canceled: killing a half-started server would only make the next - // query start it again. The cancel lands at the next wait instead. - const protection = io.swapCancelProtection(.blocked); - const started = handshake(c, io, arena, root); - _ = io.swapCancelProtection(protection); + // A replaced query leaves its startup to the next query. The file-open + // worker is canceled only during teardown and can abandon its handshake. + const started = if (protect_startup) started: { + const protection = io.swapCancelProtection(.blocked); + defer _ = io.swapCancelProtection(protection); + break :started handshake(c, io, arena, root); + } else handshake(c, io, arena, root); started catch |e| { shutdownIf(c, io, g); + if (e == error.Canceled) return e; // NOT a session disable. A handshake that misses the deadline is // routinely environmental — a rustup shim deciding to download the // project's pinned toolchain before launching the real server was |
