diff options
| -rw-r--r-- | dev/lsp/lsp_client.zig | 20 | ||||
| -rw-r--r-- | dev/macos/Sources/PardesView.swift | 104 | ||||
| -rw-r--r-- | runtime/macos.zig | 26 | ||||
| -rw-r--r-- | test/macos-snapshots/addon-rasters.golden | 0 | ||||
| -rw-r--r-- | test/macos-snapshots/addon-rasters.snap | 9 | ||||
| -rw-r--r-- | test/macos-snapshots/leader-hints.golden | 0 | ||||
| -rw-r--r-- | test/macos-snapshots/leader-hints.snap | 8 | ||||
| -rw-r--r-- | test/macos-snapshots/picker-layers.golden | 2 | ||||
| -rw-r--r-- | test/macos-snapshots/picker-layers.snap | 13 | ||||
| -rw-r--r-- | test/macos_e2e.swift | 60 |
10 files changed, 170 insertions, 72 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 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..<pardes_tag_layer_limit() { - let values = (0...12).map { Int(pardes_tag_layer_value(index, UInt32($0))) } + let values = (0...13).map { Int(pardes_tag_layer_value(index, UInt32($0))) } if values[0] == 0 { continue } if let cells = pardes_tag_layer_cells(index) { - result.append(FrozenBodyLayer(values: values, cells: Array(UnsafeBufferPointer(start: cells, count: values[0])))) + result.append(FrozenBodyLayer(values: values, cells: Array(UnsafeBufferPointer(start: cells, count: values[0] * values[7])))) } } return result @@ -1242,16 +1242,14 @@ final class PardesView: NSView { private func drawTagLayers(_ ctx: CGContext, hideCursor: Bool, canonical: UnsafePointer<pardes_cell_s>, cols: Int, rows: Int) { var layers: [[Int]] = [] for index in 0..<pardes_tag_layer_limit() { - let values = (0...12).map { Int(pardes_tag_layer_value(index, UInt32($0))) } - if values[0] == 0 { continue } + let values = (0...13).map { Int(pardes_tag_layer_value(index, UInt32($0))) } + guard values[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<pardes_cell_s>, hideCursor: Bool, canonical: UnsafePointer<pardes_cell_s>, 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..<values[0] { - var cell = cells[col] - let isCursor = !hideCursor && col == values[8] - let block = isCursor && values[9] == 0 - let style = resolve(cell, block: block, ground: UInt32(values[10]), clearGround: false) - let x = left + CGFloat(col) * taglines.width - if pass == 0 { - fillBackground(ctx, CGRect(x: x, y: y, width: taglines.width, height: taglines.height), - style.bg, block ? 1 : backgroundAlpha) - continue - } - let text = withUnsafeBytes(of: &cell.text) { String(decoding: $0.prefix(Int(cell.len)), as: UTF8.self) } - if style.visible && !text.isEmpty && text != " " { - let face = Face(bold: cell.attrs & UInt16(PARDES_ATTR_BOLD) != 0, italic: cell.attrs & UInt16(PARDES_ATTR_ITALIC) != 0) - ctx.saveGState() - ctx.translateBy(x: 0, y: bounds.height) - ctx.scaleBy(x: 1, y: -1) - let baseline = bounds.height - y - taglines.ascent - drawRules(ctx, cell, style, x: x, width: taglines.width, baseline: baseline) - setFill(ctx, style.fg, style.alpha) - ctx.textPosition = CGPoint(x: x, y: baseline) - let line = NSAttributedString(string: text, attributes: [fontAttribute: taglines.fonts[face.rawValue], - NSAttributedString.Key(kCTForegroundColorFromContextAttributeName as String): true]) - CTLineDraw(CTLineCreateWithAttributedString(line as CFAttributedString), ctx) - ctx.restoreGState() - } - if isCursor && values[9] != 0 { - fill(ctx, CGRect(x: x, y: y, width: max(1, taglines.width / 8), height: taglines.height), style.fg, 1) + for row in 0..<values[7] { + let gridRow = values[5] + row + let y = CGFloat(gridRow) * cellHeight + taglines.top(row: gridRow, canvasHeight: bounds.height) + for pass in 0...1 { + for col in 0..<values[0] { + var cell = cells[row * values[0] + col] + let isCursor = !hideCursor && col == values[8] && row == values[13] + let block = isCursor && values[9] == 0 + let style = resolve(cell, block: block, ground: UInt32(values[10]), clearGround: false) + let x = left + CGFloat(col) * taglines.width + if pass == 0 { + fillBackground(ctx, CGRect(x: x, y: y, width: taglines.width, height: taglines.height), + style.bg, block ? 1 : backgroundAlpha) + continue + } + let text = withUnsafeBytes(of: &cell.text) { String(decoding: $0.prefix(Int(cell.len)), as: UTF8.self) } + if style.visible && !text.isEmpty && text != " " { + let face = Face(bold: cell.attrs & UInt16(PARDES_ATTR_BOLD) != 0, italic: cell.attrs & UInt16(PARDES_ATTR_ITALIC) != 0) + ctx.saveGState() + ctx.translateBy(x: 0, y: bounds.height) + ctx.scaleBy(x: 1, y: -1) + let baseline = bounds.height - y - taglines.ascent + drawRules(ctx, cell, style, x: x, width: taglines.width, baseline: baseline) + setFill(ctx, style.fg, style.alpha) + ctx.textPosition = CGPoint(x: x, y: baseline) + let line = NSAttributedString(string: text, attributes: [fontAttribute: taglines.fonts[face.rawValue], + NSAttributedString.Key(kCTForegroundColorFromContextAttributeName as String): true]) + CTLineDraw(CTLineCreateWithAttributedString(line as CFAttributedString), ctx) + ctx.restoreGState() + } + if isCursor && values[9] != 0 { + fill(ctx, CGRect(x: x, y: y, width: max(1, taglines.width / 8), height: taglines.height), style.fg, 1) + } } } } @@ -1395,6 +1400,7 @@ final class PardesView: NSView { /// shared by the fill in drawTagLayer and the glyph in drawTagGrip so /// the two can never disagree. private func anchorSquare(values: [Int]) -> 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 diff --git a/runtime/macos.zig b/runtime/macos.zig index 7485f472..1b0ecd83 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -411,10 +411,6 @@ export fn pardes_deinit() void { } pardes.lsp.setStatusSink(null, null); host_io.setExitWake(null, null); - if (st.inbox.lsp_task) |*t| { - t.future.cancel(st.io); - st.inbox.lsp_task = null; - } st.pipe_tasks.cancelAll(st.io); for (0..pardes.MAX_PANES) |pane| if (st.file_watches.entries[pane] != null) { const id: u8 = @intCast(pane); @@ -426,7 +422,7 @@ export fn pardes_deinit() void { hostWatchFile(theme_watch_pane, generation, null, 0); } for (0..pardes.MAX_PANES) |pane| reap(st, @intCast(pane)); - st.inbox.close(); + st.inbox.deinit(); st.file_watches.deinit(st.gpa); if (st.cells.len > 0) st.gpa.free(st.cells); for (st.layer_cells) |cells| st.gpa.free(cells); @@ -847,6 +843,7 @@ export fn pardes_tick() bool { did = did or drained.count != 0; if (drained.pending) wake(st); } + st.core.advance(@intCast(std.Io.Clock.awake.now(st.io).nanoseconds)); while (st.core.nextEffect()) |effect| { did = true; st.core.perform(effect); @@ -912,17 +909,14 @@ export fn pardes_animation_tick() bool { const st = &(state orelse return false); const now: u64 = @intCast(std.Io.Clock.awake.now(st.io).nanoseconds); + st.core.advance(now); const spend = spendTickTime(st.last_tick_ns, now, st.tick_bank_ns); st.last_tick_ns = now; st.tick_bank_ns = spend.bank_ns; - var changed = false; + var changed = st.core.needs_frame; for (0..spend.steps) |_| { - if (st.core.animationActive()) { - st.core.update(.tick); - changed = true; - } if (st.scroll_coasting) { const spent_now = spendScroll( st, @@ -1220,20 +1214,22 @@ fn clearFrame(st: *State) void { fn blankTagCells(cells: []Cell, cols: u16, rows: u16, source: []const pardes.Cell, layers: []const pardes.Layer) void { for (layers) |layer| { if (layer.rows == 0 or layer.viewport.y >= rows or layer.viewport.x >= cols) continue; - const start = @as(usize, layer.viewport.y) * cols + layer.viewport.x; const count = @min(layer.viewport.w, cols - layer.viewport.x); // The tag text is the layer's to draw. (The look-hover's glass // rect went with the core's hover bit, stage 8's follow-up.) _ = source; - for (cells[start..][0..count]) |*cell| cell.* = encodeCell(.{}); + for (layer.viewport.y..@min(rows, @as(usize, layer.viewport.y) + layer.rows)) |row| { + const start = row * cols + layer.viewport.x; + for (cells[start..][0..count]) |*cell| cell.* = encodeCell(.{}); + } } } fn tagCursorCovered(core: *const pardes.Pardes) bool { const cursor = core.surface.cursor orelse return false; for (core.surface.tag_layers) |layer| { - if (layer.rows != 0 and cursor.y == layer.viewport.y and cursor.x >= layer.viewport.x and - cursor.x - layer.viewport.x < layer.viewport.w) return true; + if (cursor.y >= layer.viewport.y and cursor.y - layer.viewport.y < layer.rows and + cursor.x >= layer.viewport.x and cursor.x - layer.viewport.x < layer.viewport.w) return true; } return false; } @@ -1402,6 +1398,7 @@ export fn pardes_tag_layer_value(index: u32, field: u32) u32 { const st = &(state orelse return 0); if (index >= pardes.MAX_TAG_LAYERS) return 0; const layer = &st.core.surface.tag_layers[index]; + if (layer.rows == 0) return 0; return switch (field) { 0 => layer.cols, 1 => @backingInt(layer.kind), @@ -1420,6 +1417,7 @@ export fn pardes_tag_layer_value(index: u32, field: u32) u32 { const border = st.core.chrome().rule; break :rgb @as(u32, border[0]) << 16 | @as(u32, border[1]) << 8 | border[2]; }, + 13 => if (layer.cursor) |c| c.y else 65535, else => 0, }; } diff --git a/test/macos-snapshots/addon-rasters.golden b/test/macos-snapshots/addon-rasters.golden new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/macos-snapshots/addon-rasters.golden diff --git a/test/macos-snapshots/addon-rasters.snap b/test/macos-snapshots/addon-rasters.snap new file mode 100644 index 00000000..94d920f9 --- /dev/null +++ b/test/macos-snapshots/addon-rasters.snap @@ -0,0 +1,9 @@ +# Open both formats in fresh cores so each must produce its own raster. +start 32 105 +native-metrics +open-fixture ../../docs/9p.pdf +wait-raster +start 32 105 +native-metrics +open-fixture ../../docs/site/media/chords.png +wait-raster diff --git a/test/macos-snapshots/leader-hints.golden b/test/macos-snapshots/leader-hints.golden new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/macos-snapshots/leader-hints.golden diff --git a/test/macos-snapshots/leader-hints.snap b/test/macos-snapshots/leader-hints.snap new file mode 100644 index 00000000..eaf186a7 --- /dev/null +++ b/test/macos-snapshots/leader-hints.snap @@ -0,0 +1,8 @@ +start 28 110 +native-metrics +open-fixture context.zig +wait 3000 ) u32 +key space +wait 2000 b buffer +capture leader-hints +key esc diff --git a/test/macos-snapshots/picker-layers.golden b/test/macos-snapshots/picker-layers.golden new file mode 100644 index 00000000..5796f112 --- /dev/null +++ b/test/macos-snapshots/picker-layers.golden @@ -0,0 +1,2 @@ +== picker second row drawn from its layer +== picker layer retired diff --git a/test/macos-snapshots/picker-layers.snap b/test/macos-snapshots/picker-layers.snap new file mode 100644 index 00000000..1ee4c5a7 --- /dev/null +++ b/test/macos-snapshots/picker-layers.snap @@ -0,0 +1,13 @@ +start 24 80 +native-metrics +wait 8000 $ +text for n in a b c; do touch "$n.txt"; done; printf 'PICKER_FIX''TURES_READY\n' +key enter +wait 8000 PICKER_FIXTURES_READY +key c-b +text ff +stable 250 3000 +check-picker +key esc +stable 100 3000 +check-retired-picker diff --git a/test/macos_e2e.swift b/test/macos_e2e.swift index 25d83957..a4998d39 100644 --- a/test/macos_e2e.swift +++ b/test/macos_e2e.swift @@ -671,6 +671,59 @@ private final class Driver: PardesViewDelegate { output += "== context \(label) compact separators verified\n" } + private func checkPicker() throws { + let view = try live() + guard let layer = (0..<pardes_tag_layer_limit()).first(where: { + pardes_tag_layer_value($0, 0) > 0 && pardes_tag_layer_value($0, 1) == 5 + }), pardes_tag_layer_value(layer, 7) > 1, let grid = pardes_frame_cells() else { + throw ScriptError(message: "picker: expected multiple rows") + } + let column = Int(pardes_tag_layer_value(layer, 4)) + let row = Int(pardes_tag_layer_value(layer, 5)) + 1 + let cell = grid[row * Int(pardes_frame_cols()) + column] + guard cell.flags & UInt8(PARDES_CELL_DEFAULT) != 0 else { + throw ScriptError(message: "picker: the second row still has a copy in the canonical grid") + } + let image = try renderedCapture("picker") + let scale = CGFloat(image.pixelsWide) / view.bounds.width + let x = Int(CGFloat(column) * view.cellWidth * scale) + let y = Int(CGFloat(row) * view.cellHeight * scale) + let width = min(image.pixelsWide - x, Int(view.cellWidth * scale * 24)) + let height = Int(view.cellHeight * scale) + guard width > 0, height > 0, y + height <= image.pixelsHigh else { + throw ScriptError(message: "picker: the second row is outside the render") + } + let pixels = (y..<(y + height)).flatMap { py in + (x..<(x + width)).compactMap { px in image.colorAt(x: px, y: py)?.redComponent } + } + guard let low = pixels.min(), let high = pixels.max(), high - low > 0.15 else { + throw ScriptError(message: "picker: the second row has no rendered ink") + } + output += "== picker second row drawn from its layer\n" + } + + private func checkRetiredPicker() throws { + for index in 0..<pardes_tag_layer_limit() where pardes_tag_layer_value(index, 1) == 5 { + throw ScriptError(message: "picker: retired layer still advertises its geometry") + } + output += "== picker layer retired\n" + } + + private func waitForRaster() throws { + let deadline = Date().addingTimeInterval(8) + repeat { + pump() + _ = readFrame() + if let images = pardes_frame_image_list(), + (0..<Int(pardes_frame_images())).contains(where: { images[$0].iw > 1 && images[$0].ih > 1 }) { + _ = try renderedCapture("raster") + return + } + RunLoop.current.run(until: Date().addingTimeInterval(0.02)) + } while Date() < deadline + throw ScriptError(message: "no decoded image placement") + } + private func checkPDF(_ label: String) throws { let view = try live(), rep = try renderedCapture(label) guard nativeMetrics, pardes_frame_images() > 0, let images = pardes_frame_image_list() else { @@ -744,6 +797,12 @@ private final class Driver: PardesViewDelegate { try checkBackgrounds(rest) case "check-context": try checkContext(rest) + case "check-picker": + try checkPicker() + case "check-retired-picker": + try checkRetiredPicker() + case "wait-raster": + try waitForRaster() case "check-pdf": try checkPDF(rest) case "capture": @@ -1128,6 +1187,7 @@ private final class Driver: PardesViewDelegate { /// `pgup`/`pageup`) so a script reads the same in either suite. private func keyStroke(_ name: String) throws -> (cp: UInt32, mods: UInt32) { switch name { + case "space": return (32, 0) case "enter", "ret": return (UInt32(PARDES_KEY_ENTER), 0) case "escape", "esc": return (UInt32(PARDES_KEY_ESCAPE), 0) case "tab": return (UInt32(PARDES_KEY_TAB), 0) |
