summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/lsp/lsp_client.zig20
-rw-r--r--dev/macos/Sources/PardesView.swift104
2 files changed, 66 insertions, 58 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