From f65aaf7c569f3238b15e6e7bb0d3c28ffb244c69 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 27 Nov 2026 20:32:29 -0300 Subject: Fix macOS tag rendering and cancel LSP preload on exit Hide retired tag layers and draw every row of live compact layers, including picker rows and their caret. Cancel the language-server opener with the rest of the inbox on shutdown and let the preload handshake unwind while keeping query startup protected. Verified AppKit picker rendering and retirement, PDF and image rasters, and shutdown with a stalled language server. --- dev/lsp/lsp_client.zig | 20 +++---- dev/macos/Sources/PardesView.swift | 104 ++++++++++++++++++++----------------- 2 files changed, 66 insertions(+), 58 deletions(-) (limited to 'dev') 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 diff --git a/dev/macos/Sources/PardesView.swift b/dev/macos/Sources/PardesView.swift index 8dbaea0e..0a429428 100644 --- a/dev/macos/Sources/PardesView.swift +++ b/dev/macos/Sources/PardesView.swift @@ -1206,6 +1206,11 @@ final class PardesView: NSView { drawBodyLayers(ctx, hideCursor:hideCursor) drawTagLayers(ctx, hideCursor:hideCursor, canonical:cells, cols:cols, rows:rows) } else { + for layer in presentedBodyLayers { + layer.cells.withUnsafeBufferPointer { cells in + if let base = cells.baseAddress { drawBodyLayer(ctx, values:layer.values, cells:base, hideCursor:true) } + } + } for layer in presentedTagLayers { layer.cells.withUnsafeBufferPointer { tagCells in if let base = tagCells.baseAddress { @@ -1215,11 +1220,6 @@ final class PardesView: NSView { } drawTagGrip(ctx, values: layer.values, canonical: cells, cols: cols, rows: rows) } - for layer in presentedBodyLayers { - layer.cells.withUnsafeBufferPointer { cells in - if let base = cells.baseAddress { drawBodyLayer(ctx, values:layer.values, cells:base, hideCursor:true) } - } - } drawTagRules(ctx, layers: presentedTagLayers.map { $0.values }) } drawHoverGlass(ctx, cells: cells, cols: cols, rows: rows) @@ -1230,10 +1230,10 @@ final class PardesView: NSView { private func snapshotTagLayers() -> [FrozenBodyLayer] { var result: [FrozenBodyLayer] = [] for index in 0.., cols: Int, rows: Int) { var layers: [[Int]] = [] for index in 0.. 0, let cells = pardes_tag_layer_cells(index) else { continue } layers.append(values) // The layer's full-row fill must land before the grip: the row // background now spans the anchor columns, and the grip glyph // and the anchor fills have to come back on top of it. - if let cells = pardes_tag_layer_cells(index) { - drawTagLayer(ctx, values: values, cells: cells, hideCursor: hideCursor, - canonical: canonical, cols: cols) - } + drawTagLayer(ctx, values: values, cells: cells, hideCursor: hideCursor, + canonical: canonical, cols: cols) drawTagGrip(ctx, values: values, canonical: canonical, cols: cols, rows: rows) } drawTagRules(ctx, layers: layers) @@ -1261,12 +1259,14 @@ final class PardesView: NSView { /// one-point rules above the full-row tag backgrounds as well. private func drawTagRules(_ ctx: CGContext, layers: [[Int]]) { let pixel = CGFloat(1) - for values in layers where values[1] != 0 { - let kind = values[1] - let bottom = kind == 2 && values[11] != 0 + let picker = layers.first { $0[1] == 5 } + for values in layers where values[1] == 2 { + let bottom = values[11] != 0 let left = CGFloat(max(0, values[4] - Int(pardes_tag_text_inset()))) * cellWidth let right = CGFloat(values[4] + values[6]) * cellWidth - let y = CGFloat(values[5] + (bottom ? 0 : 1)) * cellHeight - (bottom ? 0 : pixel) + let tagEnd = values[5] + values[7] + let pickerEnd = picker.flatMap { $0[2] == values[2] ? $0[5] + $0[7] : nil } + let y = CGFloat(bottom ? values[5] : max(tagEnd, pickerEnd ?? tagEnd)) * cellHeight - (bottom ? 0 : pixel) fillBackground(ctx, CGRect(x: left, y: y, width: right-left, height: pixel), UInt32(values[12]), backgroundAlpha) } @@ -1328,7 +1328,6 @@ final class PardesView: NSView { private func drawTagLayer(_ ctx: CGContext, values: [Int], cells: UnsafePointer, hideCursor: Bool, canonical: UnsafePointer, cols: Int) { let left = CGFloat(values[4]) * cellWidth - let y = CGFloat(values[5]) * cellHeight + taglines.top(row: values[5], canvasHeight: bounds.height) // SDL gives the tag a full body-row background; only its glyphs // and per-cell highlights use the compact band. The band spans the // row's whole extent, not just its text: the grip and the mode box @@ -1336,10 +1335,12 @@ final class PardesView: NSView { // own fills cover only the compact band — a row background that // stops at the text leaves holes of ground under those anchors. // The rule in drawTagRules spans exactly this left-to-right range. - let rowLeft = CGFloat(max(0, values[4] - Int(pardes_tag_text_inset()))) * cellWidth + // Workspace words and inline notices already start at their own left edge. + let inset = values[1] == 0 || values[1] == 3 ? 0 : Int(pardes_tag_text_inset()) + let rowLeft = CGFloat(max(0, values[4] - inset)) * cellWidth let rowRight = CGFloat(values[4] + values[6]) * cellWidth let viewport = CGRect(x: rowLeft, y: CGFloat(values[5]) * cellHeight, - width: rowRight - rowLeft, height: cellHeight) + width: rowRight - rowLeft, height: CGFloat(values[7]) * cellHeight) ctx.saveGState() ctx.clip(to: viewport) fillBackground(ctx, viewport, UInt32(values[10]), backgroundAlpha) @@ -1355,35 +1356,39 @@ final class PardesView: NSView { if style.visible { fillBackground(ctx, square.integral, style.bg, backgroundAlpha) } } - for pass in 0...1 { - for col in 0.. CGRect? { + guard values[1] == 1 || values[1] == 2 else { return nil } let anchorX = max(0, values[4] - Int(pardes_tag_text_inset())) guard anchorX < values[4] else { return nil } let pad = (cellHeight - taglines.height) / 2 -- cgit v1.3