diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/Host.zig | 3 | ||||
| -rw-r--r-- | dev/Inbox.zig | 11 | ||||
| -rw-r--r-- | dev/Lsp.zig | 40 | ||||
| -rw-r--r-- | dev/gui/gui.zig | 163 | ||||
| -rw-r--r-- | dev/lsp/lsp_client.zig | 127 | ||||
| -rw-r--r-- | dev/macos/Sources/PardesView.swift | 16 | ||||
| -rw-r--r-- | dev/tui/tui.zig | 10 |
7 files changed, 268 insertions, 102 deletions
diff --git a/dev/Host.zig b/dev/Host.zig index 52205518..0a175754 100644 --- a/dev/Host.zig +++ b/dev/Host.zig @@ -54,6 +54,9 @@ pub const VTable = struct { /// startDetached. Null once it runs, else why not. start: ?*const fn (ctx: ?*anyopaque, line: []const u8, why: []u8) ?[]const u8 = null, lsp: ?*const fn (ctx: ?*anyopaque, req: Lsp.Request) void = null, + /// Start the language server of the file `pane` opened, and tell it of + /// the file, on a worker (Lsp.open). + lsp_open: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null, pipe: ?*const fn (ctx: ?*anyopaque, id: u32) void = null, /// Start the streaming search of this generation on a worker /// (pardes.Stream.start); absent, it runs on the loop. diff --git a/dev/Inbox.zig b/dev/Inbox.zig index bc7c7e8a..a0b9494d 100644 --- a/dev/Inbox.zig +++ b/dev/Inbox.zig @@ -67,6 +67,9 @@ gpa: std.mem.Allocator, lsp_allocator: std.mem.Allocator, /// The query in flight; the UI thread's alone (spawnLsp, teardown). lsp_task: ?Lsp.Task = null, +/// The server start a file's opening asked for (openLsp); the UI +/// thread's alone. +lsp_opener: Lsp.Opener = .{}, /// The `|` pipes' and the addons' jobs' and draws' workers in flight, each /// posting its answer here (`pushPipe`, `pushJob`); the loop's thread's /// alone: joined as their answers land (`land`), canceled at the end. @@ -290,6 +293,8 @@ pub fn deinit(q: *Inbox) void { // The workers in flight end first: what they still deliver is dropped. if (q.lsp_task) |*t| t.future.cancel(q.io); q.lsp_task = null; + if (q.lsp_opener.future) |*f| f.cancel(q.io); + q.lsp_opener.future = null; q.pipe_tasks.cancelAll(q.io); q.job_tasks.cancelAll(q.io); q.close(); @@ -343,6 +348,12 @@ pub fn startLsp(q: *Inbox, core: *pardes.Pardes, e: Lsp.Request) void { Lsp.start(q.io, q.lsp_allocator, core, &q.lsp_task, e, q, pushLspRows); } +/// The language server of the file `pane` opened started, on a worker of +/// its own (Lsp.open). +pub fn openLsp(q: *Inbox, core: *const pardes.Pardes, pane: pardes.Pane.Id) void { + Lsp.open(q.io, q.lsp_allocator, core, &q.lsp_opener, pane); +} + /// A worker's answer taken off the queue, to the core (whichever frontend /// took it), its worker joined: a language server's answer or status line, /// a pipe's, a search's rows, an addon's job or draw, a handover's end. diff --git a/dev/Lsp.zig b/dev/Lsp.zig index b799c9f6..d7638c83 100644 --- a/dev/Lsp.zig +++ b/dev/Lsp.zig @@ -138,6 +138,46 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, task: *?T task.* = .{ .id = req.id, .future = future }; } +/// The server start a file's opening asks for (`open`), one at a time: +/// `busy` while its worker runs. +pub const Opener = struct { + future: ?std.Io.Future(void) = null, + busy: std.atomic.Value(bool) = .init(false), +}; + +/// Pane `pane`'s file just opened: the server of its language started and +/// told of it (lsp_client.open) on a worker of its own, so its first query +/// finds both done (that query paid a spawn and a handshake, 2.5 s of zls's +/// over the comparison video's project). Not through `start`, whose cancel +/// of the query in flight waits out a handshake on the loop, nor `work`, +/// whose fixed region is the queries'. One at a time: a file opened while +/// one is under way is let go, and told at its first query (syncDoc); one +/// done is awaited (at once) before the next. +pub fn open(io: std.Io, gpa: std.mem.Allocator, core: *const pardes.Pardes, opener: *Opener, pane: pardes.Pane.Id) void { + if (opener.busy.load(.acquire)) return; + if (opener.future) |*f| f.await(io); + opener.future = null; + const p = core.panes[pane.index()] orelse return; + const f = p.file orelse return; + if (!pardes.lsp.speaks(f.path)) return; + const job = snapshot(gpa, core, .{ .id = 0, .kind = .definition, .pane = pane, .offset = 0, .arg = "" }) catch return; + opener.busy.store(true, .release); + opener.future = io.concurrent(tell, .{ io, gpa, job, &opener.busy }) catch { + opener.busy.store(false, .release); + return job.free(gpa); + }; +} + +fn tell(io: std.Io, gpa: std.mem.Allocator, job: *Job, busy: *std.atomic.Value(bool)) void { + defer busy.store(false, .release); + defer job.free(gpa); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + // A server that failed to start says so itself (`ensure`); one not + // started for want of memory is started by the file's first query. + pardes.lsp.open(io, arena.allocator(), .{ .kind = job.kind, .path = job.path, .source = job.source, .offset = 0, .root = job.root }) catch {}; +} + pub fn work(io: std.Io, gpa: std.mem.Allocator, job: *Job, ctx: ?*anyopaque, deliver: Deliver) void { defer job.free(gpa); // The query's memory is the fixed region memory.zig reserved at diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 5d4c051a..ccf9387b 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -45,8 +45,10 @@ const log = std.log.scoped(.gui); const font_ttf = @embedFile("AdwaitaMono-Regular.ttf"); -const bg_default = [3]u8{ 18, 18, 18 }; -const fg_default = [3]u8{ 204, 204, 204 }; +/// The page and text a window draws for a theme that leaves them to the +/// host (`dark`): the chrome's one null page (DESIGN.md R1). +const null_page = pardes.colors.null_page; +const null_text = pardes.colors.null_text; const p9_arrow_clr = [32]u8{ 0xFF, 0xFF, 0x80, 0x01, 0x80, 0x02, 0x80, 0x0C, @@ -2648,6 +2650,7 @@ const Shell = struct { .open_link = openLink, .start = host_io.startDetached, .lsp = lsp, + .lsp_open = lspOpen, .pipe = pipe, .search = search, .hand_over = handOver, @@ -3223,6 +3226,13 @@ fn lsp(ctx: ?*anyopaque, req: host_io.Lsp.Request) void { s.core.reportError(req.pane, "lsp", error.WorkersUnavailable); } +/// Not held for `threads_ok`: the boot's file and a restored session's are +/// opened before `start`. +fn lspOpen(ctx: ?*anyopaque, pane: pardes.Pane.Id) void { + const s = shellOf(ctx); + s.queue.openLsp(s.core, pane); +} + fn pipe(ctx: ?*anyopaque, id: u32) void { const s = shellOf(ctx); if (s.threads_ok) return selection_pipe.start(s.io, s.gpa, s.core, &s.queue.pipe_tasks, id, s.queue, Queue.pushPipe); @@ -4017,7 +4027,7 @@ fn renderFrame( coverFrame(covered, surface.cols, surface.rows, surface.bodyLayers(), surface.tagLayers(), surface.regionList()); try buildDecor(g, gpa, surface, &groups, layout, win_w, win_h, cursors_shown); - const page = chrome.page orelse bg_default; + const page = chrome.page orelse null_page; const background_opacity = backgroundOpacity(g.applied_window_opacity); const clear: c.SDL_FColor = .{ .r = @as(f32, @floatFromInt(page[0])) / 255.0 * background_opacity, @@ -4163,13 +4173,13 @@ const taglineBandOffset = pardes.Layer.taglineBandOffset; /// in `line`, block or bar: shaping breaks around it. fn resolveCell(g: *Gui, line: []const pardes.Cell, at: usize, cursor: ?usize, role: pardes.FontRole, is_cursor: bool, page: [3]u8) ResolvedCell { const cell = &line[at]; - var fg = fg_default; + var fg = null_text; var bg = page; var reverse = is_cursor; if (!cell.default) { const st = cell.style; fg = switch (st.fg) { - .default => fg_default, + .default => null_text, .index => |i| pardes.colors.xterm[i], .rgb => |rgb| rgb, }; @@ -4185,9 +4195,9 @@ fn resolveCell(g: *Gui, line: []const pardes.Cell, at: usize, cursor: ?usize, ro // full opacity would expose text that the terminal concealed, so // cellSlot draws a concealed cell blank. } - if (st.dim) for (&fg) |*ch| { - ch.* = @intCast(@as(u16, ch.*) * 6 / 10); - }; + // SGR faint: the ink toward its ground to the dim floor (DESIGN.md + // R15), so fainter on a light page too, never darkened to black. + if (st.dim) fg = fadeToward(fg, bg, 1, @min(pardes.colors.contrast(fg, bg), pardes.colors.Chrome.dim_floor)); } if (reverse) std.mem.swap([3]u8, &fg, &bg); @@ -4345,13 +4355,14 @@ fn gripButton(g: *const Gui, chrome: *const pardes.Chrome, col: u16, row: u16, l fn gripFill(chrome: *const pardes.Chrome, focus: bool, dirty: bool, reading: bool) [3]u8 { if (dirty) return chrome.grip_dirty; if (focus) return chrome.grip_focus_ring; - // The ring's inside is the tag's ground: a reading pane's tint. + // The ring's inside is the tag's ground. return if (reading) chrome.tag_reading_bg else chrome.tag_bg; } -fn inkOn(bg: [3]u8) [3]u8 { - const lum = (@as(u16, bg[0]) * 3 + @as(u16, bg[1]) * 6 + @as(u16, bg[2])) / 10; - return if (lum > 140) .{ 0x00, 0x00, 0x00 } else .{ 0xff, 0xff, 0xff }; +/// The ink on a pane's button (DESIGN.md R6): the chrome's grip ink on a +/// fill, the tag's own on its ground. +fn gripInk(chrome: *const pardes.Chrome, focus: bool, dirty: bool) [3]u8 { + return if (focus or dirty) chrome.grip_ink else chrome.tag_fg; } /// Cuts an instance's quad to a pixel rectangle (left, top, right, bottom), @@ -4463,8 +4474,8 @@ fn emitSurfaceCell( // or dirty (UX D4). const ink = if (mark) switch (glyph.style.fg) { .rgb => |rgb| pardes.colors.pushAway(rgb, &.{fill}, pardes.colors.Roles.ink_floor), - else => inkOn(fill), - } else if (here.pane_grip) inkOn(fill) else resolved.fg; + else => gripInk(chrome, here.focus, here.dirty), + } else if (here.pane_grip) gripInk(chrome, here.focus, here.dirty) else resolved.fg; instances[next.*].fr = @as(f32, @floatFromInt(ink[0])) / 255; instances[next.*].fg = @as(f32, @floatFromInt(ink[1])) / 255; instances[next.*].fb = @as(f32, @floatFromInt(ink[2])) / 255; @@ -5141,7 +5152,7 @@ fn laneStrip(g: *Gui, gpa: std.mem.Allocator, lane: pardes.Lane, row: i32, ride: /// coloured gutter with a thin track and its thumb, running down through the /// pixels past the last whole row. fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, tags: []const pardes.Layer, ticks: []const pardes.RailTick, heat: []const pardes.RailHeat, chrome: *const pardes.Chrome, layout: CellLayout, cols: u16, rows: u16, win_w: f32, win_h: f32) !void { - const page = chrome.page orelse bg_default; + const page = chrome.page orelse null_page; for (regions) |rail| { if (rail.kind != .rail or rail.rect.h == 0) continue; const tag = for (regions) |region| { @@ -5165,7 +5176,7 @@ fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ta if (!tag_bottom and head.rows > 0) tag_end = @max(tag_end, head.viewport.y + head.rows); if (!tag_bottom and band.rows > 0 and band.kind == .band and band.id == rail.owner) tag_end = @max(tag_end, band.viewport.y + band.rows); const rule_y = @as(f32, @floatFromInt(if (tag_bottom) tag.rect.y else tag_end)) * layout.h; - try addDecor(g, gpa, x0, if (tag_bottom) rule_y else rule_y - dp(1), rule_x1, if (tag_bottom) rule_y + dp(1) else rule_y, chrome.tag_rule orelse mixRgb(chrome.tag_bg, page), 1, win_w, win_h); + try addDecor(g, gpa, x0, if (tag_bottom) rule_y else rule_y - dp(1), rule_x1, if (tag_bottom) rule_y + dp(1) else rule_y, chrome.tag_rule, 1, win_w, win_h); // Stacked panes are ruled apart as columns are, where one pane's // body meets the next one's tag (acme's Border). { @@ -5238,9 +5249,6 @@ fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ta } } -/// Halfway between two colours. -const mixRgb = pardes.colors.mix; - /// A rule's width: the theme's own, or one pixel. fn rulePx(chrome: *const pardes.Chrome) f32 { return dp(@floatFromInt(@max(1, chrome.rule_px))); @@ -5270,17 +5278,15 @@ fn updateDisplayScale(window: *c.SDL_Window) void { /// InactiveDim: the unfocused panes' text faded toward its ground by the /// setting's percent, never below the pair's own contrast or 4.5, whichever -/// is lower. The window's alone, from the regions' focus: renderFrame -/// begins it each frame. ponytail: one window per process, as display_scale. +/// is lower (`fadeToward`: worked out, no search, so nothing is kept). The +/// window's alone, from the regions' focus: renderFrame begins it each +/// frame. ponytail: one window per process, as display_scale. var dim: Dim = .{}; const Dim = struct { amount: f32 = 0, /// The pane with the keyboard, from its regions. focused: u16 = pardes.Region.none, - /// The few ink and paper pairs a frame has, each faded once. - keys: [32]?[6]u8 = @splat(null), - values: [32][3]u8 = undefined, fn begin(d: *Dim, percent: u8, regions: []const pardes.Region) void { d.* = .{ .amount = @as(f32, @floatFromInt(@min(percent, 100))) / 100 }; @@ -5297,35 +5303,15 @@ const Dim = struct { } /// A cell instance's ink faded toward its ground. - fn fade(d: *Dim, instance: *CellInstance) void { - const ink = d.faded(byteRgb(.{ instance.fr, instance.fg, instance.fb }), byteRgb(.{ instance.br, instance.bg, instance.bb })); + fn fade(d: *const Dim, instance: *CellInstance) void { + const from = byteRgb(.{ instance.fr, instance.fg, instance.fb }); + const paper = byteRgb(.{ instance.br, instance.bg, instance.bb }); + const ink = fadeToward(from, paper, d.amount, @min(pardes.colors.contrast(from, paper), 4.5)); instance.fr = @as(f32, @floatFromInt(ink[0])) / 255.0; instance.fg = @as(f32, @floatFromInt(ink[1])) / 255.0; instance.fb = @as(f32, @floatFromInt(ink[2])) / 255.0; } - fn faded(d: *Dim, ink: [3]u8, paper: [3]u8) [3]u8 { - const key = ink ++ paper; - const slot = (@as(usize, ink[0]) *% 31 +% @as(usize, ink[1]) *% 7 +% ink[2] +% @as(usize, paper[0]) *% 13 +% @as(usize, paper[1]) *% 3 +% paper[2]) % d.keys.len; - if (d.keys[slot]) |held| if (std.mem.eql(u8, &held, &key)) return d.values[slot]; - // Contrast falls as the ink nears its paper: the most of `amount` - // that keeps the pair at its own contrast or 4.5, whichever is lower. - const floor = @min(pardes.colors.contrast(ink, paper), 4.5); - var t = d.amount; - if (pardes.colors.contrast(blendLinear(ink, paper, t), paper) < floor) { - var lo: f32 = 0; - var hi: f32 = t; - for (0..8) |_| { - const mid = (lo + hi) / 2; - if (pardes.colors.contrast(blendLinear(ink, paper, mid), paper) >= floor) lo = mid else hi = mid; - } - t = lo; - } - d.keys[slot] = key; - d.values[slot] = blendLinear(ink, paper, t); - return d.values[slot]; - } - fn byteRgb(rgb: [3]f32) [3]u8 { var out: [3]u8 = undefined; for (&out, rgb) |*o, v| o.* = @intFromFloat(@round(std.math.clamp(v, 0, 1) * 255)); @@ -5333,6 +5319,19 @@ const Dim = struct { } }; +/// `ink` toward `paper` in linear light, `most` of the way at most and +/// never under `floor`:1 on it. Luminance runs straight in linear light, so +/// the most that keeps the floor is worked out, never searched (a hair +/// inside it, for the bytes' rounding). +fn fadeToward(ink: [3]u8, paper: [3]u8, most: f32, floor: f32) [3]u8 { + const yi = pardes.colors.relativeLuminance(ink); + const yp = pardes.colors.relativeLuminance(paper); + if (@abs(yi - yp) < 1e-6) return ink; + const f = floor * 1.02; + const stop = if (yi > yp) f * (yp + 0.05) - 0.05 else (yp + 0.05) / f - 0.05; + return blendLinear(ink, paper, std.math.clamp((yi - stop) / (yi - yp), 0, most)); +} + /// `t` of the way from one colour to the other in linear light, so a /// coloured ink does not muddy on its way to the paper. fn blendLinear(from: [3]u8, to: [3]u8, t: f32) [3]u8 { @@ -5378,10 +5377,12 @@ fn gripDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ce try addDecor(g, gpa, button[2], button[1], right, button[3], band, 1, win_w, win_h); if (grip.kind != .grip) continue; // acme's button ring, two pixels (ButtonBorder) inside the button: - // the focused one's in its own fill. An unfocused dirty one keeps a - // pixel of band inside its ring, so the four states differ in shape - // whatever a theme's colours (a focused dirty one is acme's - // modbutton, filled up to its ring). + // the focused one's in its own fill, a reading pane's in the mode's + // ink (DESIGN.md G1'). An unfocused dirty one and a reading one keep + // a pixel of band inside the ring, so the fill never touches the + // mode's ring and the four states differ in shape whatever a theme's + // colours (a focused dirty held one is acme's modbutton, filled up to + // its ring). { // The rules drawn over the row (paneDecor, after this) cut into // it: the ring runs inside them, from rule to rule. @@ -5401,14 +5402,14 @@ fn gripDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ce const x1 = button[2]; const y0 = button[1] + top_rule; const y1 = button[3] - bottom_rule; - const ring = if (grip.active) chrome.grip_focus_ring else chrome.grip_border; + const ring = if (grip.reading) chrome.grip_mode else if (grip.active) chrome.grip_focus_ring else chrome.grip_border; // acme's ButtonBorder: two logical pixels. const b = dp(2); try addDecor(g, gpa, x0, y0, x1, y0 + b, ring, 1, win_w, win_h); try addDecor(g, gpa, x0, y1 - b, x1, y1, ring, 1, win_w, win_h); try addDecor(g, gpa, x0, y0 + b, x0 + b, y1 - b, ring, 1, win_w, win_h); try addDecor(g, gpa, x1 - b, y0 + b, x1, y1 - b, ring, 1, win_w, win_h); - if (grip.dirty and !grip.active) { + if (grip.reading or (grip.dirty and !grip.active)) { const gap = b + dp(1); try addDecor(g, gpa, x0 + b, y0 + b, x1 - b, y0 + gap, band, 1, win_w, win_h); try addDecor(g, gpa, x0 + b, y1 - gap, x1 - b, y1 - b, band, 1, win_w, win_h); @@ -5424,7 +5425,7 @@ fn gripDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ce if (x >= cols) continue; const cell = &cells[@as(usize, y) * cols + x]; if (cell.default or cell.printableAscii() != ' ' or boxMark(cells[@as(usize, y) * cols ..][0..cols], x)) continue; - const rgb = inkOn(gripFill(chrome, grip.active, grip.dirty, grip.reading)); + const rgb = gripInk(chrome, grip.active, grip.dirty); const center_x = @floor((button[0] + button[2]) / 2); const center_y = @as(f32, @floatFromInt(y)) * layout.h + @as(f32, @floatFromInt(taglineBandOffset(y, win_h, g.cell_h, g.tagline_height))) + @as(f32, @floatFromInt(g.tagline_height)) / 2; const half_w = @max(dp(1), @min(dp(3), @floor((button[2] - button[0] - 2 * dp(3)) / 2))); @@ -5757,7 +5758,7 @@ fn appendJumpTrail(g: *Gui, on: bool, surface: *const pardes.Surface, now_ns: u6 if (region.kind == .body and cursor.x >= region.rect.x and cursor.x < @as(u32, region.rect.x) + region.rect.w and cursor.y >= region.rect.y and cursor.y < @as(u32, region.rect.y) + region.rect.h) break region.rect; } else return; - const page = surface.chrome.page orelse bg_default; + const page = surface.chrome.page orelse null_page; const w: f32 = @floatFromInt(g.cell_w); const h: f32 = @floatFromInt(g.cell_h); for (lit) |cell| { @@ -5769,7 +5770,7 @@ fn appendJumpTrail(g: *Gui, on: bool, surface: *const pardes.Surface, now_ns: u6 else => page, }; if (!std.mem.eql(u8, &ground, &page)) continue; - var color = overlayRgb(surface.chrome.fg orelse fg_default); + var color = overlayRgb(surface.chrome.fg orelse null_text); color.a = cell.strength; const x0 = @as(f32, @floatFromInt(cell.x)) * w; const y0 = @as(f32, @floatFromInt(cell.y)) * h; @@ -5855,7 +5856,7 @@ fn appendCursorGlide(g: *Gui, surface: *const pardes.Surface, now_ns: u64, build } // Its colour: the cursor the cells would draw nearest the quad. var boxes: [max_cursors]CursorBox = undefined; - var rgb: [3]u8 = chrome.fg orelse fg_default; + var rgb: [3]u8 = chrome.fg orelse null_text; var nearest: f32 = std.math.inf(f32); for (boxes[0..cursorBoxes(g, surface, layout, builder.win_h, &boxes)]) |box| { const dx = (box.x0 + box.x1) / 2 - centre[0]; @@ -6030,7 +6031,7 @@ fn cursorColor(chrome: *const pardes.Chrome, cell: *const pardes.Cell, role: par return if (role == .tagline) switch (cell.style.fg) { .rgb => |rgb| rgb, else => chrome.tag_fg, - } else chrome.fg orelse fg_default; + } else chrome.fg orelse null_text; } test "FreeType and HarfBuzz allocate from the gui allocator and give it all back" { @@ -7171,7 +7172,7 @@ test "a touchpad's fraction over a body whose context rows went (scrolled out of for (&s.body_layers) |*layer| layer.cells = blank[0..layer.cells.len]; @memset(wr.g.scroll_edge, .{}); const held = if (s.facts.pane(id)) |shown| shown.context_rows else 0; - const n = emitScrollRows(&wr.g, instances.ptr, 0, &s, fixedCellLayout(&wr.g), 800, 480, bg_default, held); + const n = emitScrollRows(&wr.g, instances.ptr, 0, &s, fixedCellLayout(&wr.g), 800, 480, null_page, held); // The body's moving rows under the held ones, the layer's // rows past the grid's while there is a layer, and the row // that left. @@ -7198,24 +7199,24 @@ test "a scroll's body taller than its body layer (the pane shrunk under a glide) g.scroll_body_h = 19; var instances: [3 * 40 * 20]CellInstance = undefined; const layout = fixedCellLayout(&g); - try std.testing.expectEqual(@as(u32, 0), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, bg_default, 2)); + try std.testing.expectEqual(@as(u32, 0), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, null_page, 2)); // As tall as the body, its cells short of its rows: the same. surface.body_layers[0].rows = 21; - try std.testing.expectEqual(@as(u32, 0), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, bg_default, 2)); + try std.testing.expectEqual(@as(u32, 0), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, null_page, 2)); // Its cells all there: the body's moving rows under the two held, and // the layer's two past the grid's. var whole: [38 * 21]pardes.Cell = @splat(.{}); surface.body_layers[0].cells = &whole; - try std.testing.expectEqual(@as(u32, (19 - 2 + 2) * 38), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, bg_default, 2)); + try std.testing.expectEqual(@as(u32, (19 - 2 + 2) * 38), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, null_page, 2)); } test "concealed terminal text emits no ink on its ground" { var g = testGui(10, 20, 6, 12); var cell: pardes.Cell = .{ .default = false, .style = .{ .invisible = true, .ul = .single } }; cell.text[0] = 'X'; - const resolved = resolveCell(&g, (&cell)[0..1], 0, null, .body, false, bg_default); + const resolved = resolveCell(&g, (&cell)[0..1], 0, null, .body, false, null_page); try std.testing.expectEqualDeep(g.atlas.space_slot, resolved.slot); - try std.testing.expectEqual(bg_default, resolved.bg); + try std.testing.expectEqual(null_page, resolved.bg); } test "a block cursor's cell is drawn reversed: the cell's ink its ground, its ground its ink" { @@ -7227,8 +7228,8 @@ test "a block cursor's cell is drawn reversed: the cell's ink its ground, its gr .default = false, .style = .{ .fg = .{ .rgb = .{ 10, 20, 30 } }, .bg = .{ .rgb = .{ 200, 210, 220 } } }, }; - const plain = resolveCell(&g, (&cell)[0..1], 0, null, .body, false, bg_default); - const cursor = resolveCell(&g, (&cell)[0..1], 0, 0, .body, true, bg_default); + const plain = resolveCell(&g, (&cell)[0..1], 0, null, .body, false, null_page); + const cursor = resolveCell(&g, (&cell)[0..1], 0, 0, .body, true, null_page); try std.testing.expectEqual([3]u8{ 10, 20, 30 }, plain.fg); try std.testing.expectEqual(plain.fg, cursor.bg); try std.testing.expectEqual(plain.bg, cursor.fg); @@ -7355,7 +7356,7 @@ test "every pixel of a grip column is band, button or ring, and the button sits const row: u16 = grip.rect.y + @as(u16, @intCast(line)); const at = @as(usize, row) * s.cols; var next: u32 = 0; - emitSurfaceCell(&g, &s.chrome, &instances, &next, col, row, layout, win_w, win_h, s.cells[at..][0..s.cols], cover[at..][0..s.cols], col, null, false, bg_default); + emitSurfaceCell(&g, &s.chrome, &instances, &next, col, row, layout, win_w, win_h, s.cells[at..][0..s.cols], cover[at..][0..s.cols], col, null, false, null_page); for (instances[0..next]) |i| paint.quad(pixels, i.x0, i.y0, i.x1, i.y1, .{ i.br, i.bg, i.bb }, win_w, win_h, x_px, y_px, w_px, h_px); }; for (g.decor.items) |i| if (i.fr >= 1 and i.clip_x1 < i.clip_x0) paint.quad(pixels, i.x0, i.y0, i.x1, i.y1, .{ i.br, i.bg, i.bb }, win_w, win_h, x_px, y_px, w_px, h_px); @@ -7371,8 +7372,8 @@ test "every pixel of a grip column is band, button or ring, and the button sits const band = if (pardes.Trail.reading(core, core.panes[0].?)) chrome.tag_reading_bg else if (focus == 0) chrome.tag_focus_bg else chrome.tag_bg; // Band, fills, rings, the rules between stacked panes and under the // tag, and the mode marks' ink (the grip's first cell's). - const ink = inkOn(gripFill(chrome, grip.active, grip.dirty, grip.reading)); - const allowed = [_][3]f32{ rgb(band), rgb(core.chromeTheme().box), rgb(pardes.draw.boxDirty(core)), rgb(chrome.grip_border), rgb(chrome.grip_focus_ring), rgb(chrome.border), rgb(ink), rgb(chrome.tag_rule orelse mixRgb(chrome.tag_bg, chrome.page orelse bg_default)) }; + const ink = gripInk(chrome, grip.active, grip.dirty); + const allowed = [_][3]f32{ rgb(band), rgb(chrome.grip_focus_ring), rgb(chrome.grip_dirty), rgb(chrome.grip_border), rgb(chrome.grip_mode), rgb(chrome.border), rgb(ink), rgb(chrome.tag_rule) }; for (pixels, 0..) |pixel, n| { const got = pixel orelse return error.TestUnpaintedGripPixel; const known = for (allowed) |a| { @@ -7386,7 +7387,7 @@ test "every pixel of a grip column is band, button or ring, and the button sits } // The rule under the tag runs unbroken across the grip column. for (pixels[(h_px - 1) * w_px ..][0..w_px]) |pixel| - try std.testing.expectEqual(rgb(chrome.tag_rule orelse mixRgb(chrome.tag_bg, chrome.page orelse bg_default)), pixel.?); + try std.testing.expectEqual(rgb(chrome.tag_rule), pixel.?); // The button's edges are the scrollbar's. const button = gripButton(&g, chrome, grip.rect.x, grip.rect.y, layout); const column = scrollColumn(&g, chrome, s.region(.rail, 0).?.rect.x, layout); @@ -7404,7 +7405,7 @@ test "small tagline fonts leave no background gutters between adjacent tags" { var next: u32 = 0; for (0..3) |row| { // Column 1: past the anchor's inset edge at the column's left. - emitSurfaceCell(&g, &chrome, &instances, &next, 1, @intCast(row), fixedCellLayout(&g), 800, 480, (&cell)[0..1], &.{.{}}, 0, null, false, bg_default); + emitSurfaceCell(&g, &chrome, &instances, &next, 1, @intCast(row), fixedCellLayout(&g), 800, 480, (&cell)[0..1], &.{.{}}, 0, null, false, null_page); const base = instances[row * 2]; const ink = instances[row * 2 + 1]; try std.testing.expectApproxEqAbs(@as(f32, 20.0 / 480.0 * 2), base.y0 - base.y1, 0.0001); @@ -7417,7 +7418,7 @@ test "small tagline fonts leave no background gutters between adjacent tags" { // Column 0 is an anchor's edge: its ink is inset by the band's margin // (2 px here) and its underlay still covers the whole cell. next = 0; - emitSurfaceCell(&g, &chrome, &instances, &next, 0, 1, fixedCellLayout(&g), 800, 480, (&cell)[0..1], &.{.{ .anchor = true }}, 0, null, false, bg_default); + emitSurfaceCell(&g, &chrome, &instances, &next, 0, 1, fixedCellLayout(&g), 800, 480, (&cell)[0..1], &.{.{ .anchor = true }}, 0, null, false, null_page); try std.testing.expectApproxEqAbs(@as(f32, 10.0 / 800.0 * 2), instances[0].x1 - instances[0].x0, 0.0001); try std.testing.expectApproxEqAbs(@as(f32, 8.0 / 800.0 * 2), instances[1].x1 - instances[1].x0, 0.0001); try std.testing.expectApproxEqAbs(@as(f32, 8) / atlas_w, instances[1].u1 - instances[1].u0, 0.0001); @@ -7428,7 +7429,7 @@ test "block cursor alone overrides transparent cell background" { const cell: pardes.Cell = .{}; var instances: [2]CellInstance = undefined; for ([_]bool{ false, true }, 0..) |cursor, i| { - emitInstance(&g, &instances, @intCast(i), 0, 0, fixedCellLayout(&g), 800, 480, .body, (&cell)[0..1], 0, null, cursor, bg_default); + emitInstance(&g, &instances, @intCast(i), 0, 0, fixedCellLayout(&g), 800, 480, .body, (&cell)[0..1], 0, null, cursor, null_page); try std.testing.expectEqual(cursor, instances[i].effect & opaque_bg_bit != 0); } } @@ -7597,7 +7598,7 @@ test "pane indicator halves are safe on an exhausted atlas" { var instances: [4]CellInstance = undefined; var next: u32 = 0; for (0..2) |col| { - emitSurfaceCell(&g, &chrome, &instances, &next, @intCast(col), 0, fixedCellLayout(&g), 100, 100, cells[0..6], cover[0..6], col, null, false, bg_default); + emitSurfaceCell(&g, &chrome, &instances, &next, @intCast(col), 0, fixedCellLayout(&g), 100, 100, cells[0..6], cover[0..6], col, null, false, null_page); try std.testing.expectEqual(@as(f32, 0), instances[col * 2 + 1].u0); } try std.testing.expectEqual(@as(u32, 4), next); @@ -8038,7 +8039,7 @@ test "compact body layer rendering fills recovered rows and clips the final glyp layer.setContextLines(&.{ 0, 4, 5, 6 }); var instances: [32]CellInstance = undefined; var next: u32 = 0; - emitBodyLayer(&g, &instances, &next, &layer, 200, 200, bg_default, false, .{ 80, 90, 100 }); + emitBodyLayer(&g, &instances, &next, &layer, 200, 200, null_page, false, .{ 80, 90, 100 }); // Four compact header rows (48px), then three body rows: two complete // and a third clipped to the remaining12px of the100px viewport. try std.testing.expectEqual(@as(u32, 20), next); @@ -8053,7 +8054,7 @@ test "compact body layer rendering fills recovered rows and clips the final glyp // A drag preview reserves the last physical column without changing cells. layer.viewport.w = 1; next = 0; - emitBodyLayer(&g, &instances, &next, &layer, 200, 200, bg_default, false, .{ 80, 90, 100 }); + emitBodyLayer(&g, &instances, &next, &layer, 200, 200, null_page, false, .{ 80, 90, 100 }); for (instances[0..next]) |instance| try std.testing.expect(instance.x1 <= -0.6 + 0.0001); } @@ -8063,14 +8064,14 @@ test "compact tag layers fill available width and clip at their physical edge" { const layer: pardes.Layer = .{ .kind = .pane, .id = 0, .serial = 7, .viewport = .{ .x = 2, .y = 3, .w = 3, .h = 1 }, .cols = 6, .rows = 1, .cells = &cells, .bg = .{ 20, 30, 40 } }; var instances: [8]CellInstance = undefined; var next: u32 = 0; - emitTagLayer(&g, &instances, &next, &layer, 100, 100, bg_default, false); + emitTagLayer(&g, &instances, &next, &layer, 100, 100, null_page, false); // Five six-pixel cells fit in the three body-column viewport. try std.testing.expectEqual(@as(u32, 6), next); try std.testing.expectApproxEqAbs(@as(f32, -0.6), instances[1].x0, 0.0001); try std.testing.expectApproxEqAbs(@as(f32, 0), instances[5].x1, 0.0001); g.tagline_width = 8; next = 0; - emitTagLayer(&g, &instances, &next, &layer, 100, 100, bg_default, false); + emitTagLayer(&g, &instances, &next, &layer, 100, 100, null_page, false); try std.testing.expectEqual(@as(u32, 5), next); try std.testing.expectApproxEqAbs(@as(f32, 0), instances[4].x1, 0.0001); try std.testing.expectApproxEqAbs(@as(f32, 6) / atlas_w, instances[4].u1 - instances[4].u0, 0.0001); @@ -8335,7 +8336,7 @@ test "a `│` in a tag layer runs its row's whole height at a tagline smaller th var instances: [8]CellInstance = undefined; var next: u32 = 0; const win_h: f32 = 200; - emitTagLayer(&g, &instances, &next, &layer, 200, win_h, bg_default, false); + emitTagLayer(&g, &instances, &next, &layer, 200, win_h, null_page, false); try std.testing.expectEqual(@as(u32, 3), next); const bh: f32 = @floatFromInt(g.cell_h); // [0] the row's ground, [1] `a` at the tagline's height, [2] `│` the @@ -8403,7 +8404,7 @@ test "a pane's mark is its button's glyph where the mode draws none, in its kind defer g.decor.deinit(gpa); var instances: [4]CellInstance = undefined; var next: u32 = 0; - for (0..2) |col| emitSurfaceCell(&g, &chrome, &instances, &next, @intCast(col), 0, fixedCellLayout(&g), 100, 100, cells[0..6], cover[0..6], col, null, false, bg_default); + for (0..2) |col| emitSurfaceCell(&g, &chrome, &instances, &next, @intCast(col), 0, fixedCellLayout(&g), 100, 100, cells[0..6], cover[0..6], col, null, false, null_page); try std.testing.expectEqual(@as(u32, 4), next); // Each of the box's two cells draws its slice of the mark's glyph, in // the err ink pushed off the focused button's fill. diff --git a/dev/lsp/lsp_client.zig b/dev/lsp/lsp_client.zig index a53ff57f..d90f655a 100644 --- a/dev/lsp/lsp_client.zig +++ b/dev/lsp/lsp_client.zig @@ -6,9 +6,10 @@ //! //! THE PROCESS LIFECYCLE IS THE DESIGN. `lsp.query` is a synchronous call on a //! worker thread, and a language server costs tens of milliseconds to start -//! and MINUTES to index a large workspace. So a server is spawned lazily on -//! the first query that needs it, kept for the life of the editor, and each -//! spec gets at most one — `conns[i]` guards itself with an `Io.Mutex` +//! and MINUTES to index a large workspace. So a server is spawned when a +//! file of its language opens in a pane (`open`, on a worker of its own) or +//! by the first query that needs it, kept for the life of the editor, and +//! each spec gets at most one — `conns[i]` guards itself with an `Io.Mutex` //! because a canceled query can still be inside `run` when the next arrives. //! Every wait is an `Io` cancelation point: a shell cancels the worker of a //! query it no longer wants, and the worker stops there. @@ -40,7 +41,8 @@ //! (ignoring SIGPIPE process-wide would be inherited by every pty shell we //! fork and would change what `yes | head` does in a pane), //! - a binary missing from PATH costs one cached probe, disables the spec -//! for the session, and says so ONCE on the message row. +//! for the session, and says so ONCE on the message row (a query's; a +//! file opened says nothing). //! //! Position encoding is negotiated to utf-8 and the SERVER'S ANSWER is //! believed, not our request; the utf-16 conversion is implemented in both @@ -50,6 +52,7 @@ const std = @import("std"); const builtin = @import("builtin"); const libc = std.c; const lsp = @import("core").lsp; +const SymbolKind = @import("core").syntax.SymbolKind; const Scip = @import("Scip.zig"); extern "c" fn execv(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int; @@ -478,8 +481,8 @@ fn status(io: std.Io, path: []const u8, out: *std.Io.Writer) !void { const thier = c.caps.type_hier; c.mu.unlock(io); const env_v = if (libc.getenv(s.env)) |v| std.mem.span(v) else null; - // Never spawned is not off: the first query of its files starts it. - try out.print(" {s:<28} {s}", .{ s.name, if (state == .off) "not started yet (its first query starts it)" else @tagName(state) }); + // Never spawned is not off: a file of its opened starts it. + try out.print(" {s:<28} {s}", .{ s.name, if (state == .off) "not started yet (a file of its opened starts it)" else @tagName(state) }); if (state == .ready or state == .starting) { try out.print(" root {s} {s}", .{ root, @tagName(enc) }); if (pull) try out.print(" pull-diags", .{}); @@ -757,6 +760,36 @@ pub fn query(io: std.Io, arena: std.mem.Allocator, asked: lsp.Req, out: *std.Io. try out.writeAll(scratch.buffered()); } +/// A file opened in a pane (dev/Lsp.zig open): the server of its language +/// started as its first query would start it (`ensure`, which says +/// `starting` and `ready` on the message row) and told of the file +/// (didOpen), so that query finds both done. A server not installed is +/// disabled without a word: the file's first query says it is not found, +/// not every file opened. Nothing in the query log: none was asked. +/// PARDES_LSP_OPEN=off starts none (the process harnesses' default), and a +/// test binary starts none unless it says `on` (the behaviour harness's +/// language sessions, their servers the mock): no test starts a server of +/// this machine's by opening a file. +pub fn open(io: std.Io, arena: std.mem.Allocator, req: lsp.Req) Err!void { + const said = if (libc.getenv("PARDES_LSP_OPEN")) |v| std.mem.span(v) else ""; + if (std.mem.eql(u8, said, "off") or (builtin.is_test and !std.mem.eql(u8, said, "on"))) return; + const si = specFor(req.path) orelse return; + const c = &conns[si]; + try c.mu.lock(io); + defer c.mu.unlock(io); + if (c.state == .disabled) return; + var exe_buf: [4096:0]u8 = undefined; + if (!c.alive() and binOf(&specs[si], &exe_buf) == null) { + c.state = .disabled; + return; + } + var tr: Trace = .{}; + _ = try ensure(c, io, si, arena, req, &tr); + var uri: std.ArrayList(u8) = .empty; + try uriOf(&uri, arena, req.path); + try syncDoc(c, io, si, arena, uri.items, req.source); +} + fn traceOut(tr: *const Trace, req: lsp.Req, out: *std.Io.Writer, rows: usize, us: u64) std.Io.Writer.Error!void { if (req.kind != .explain) return; try out.print("lsp explain — the {s} query at byte {d} of {s}\n\n", .{ @@ -1002,7 +1035,11 @@ fn run(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, req: lsp.Req, .document_symbols => { const b = try docParams(arena, uri.items); const result = (try call(c, io, arena, "textDocument/documentSymbol", b.items, deadline)) orelse return; - try walkSymbols(&cx, c.caps.enc, uri.items, result, 0); + // Types, functions, fields, then the rest, each in the + // server's order (UX DESIGN N, the Symbols picker's). + var found: std.ArrayList(Symbol) = .empty; + try walkSymbols(arena, &found, uri.items, result, "", 0); + for (0..4) |group| for (found.items) |sym| if (sym.kind.group() == group) try emitRange(&cx, c.caps.enc, sym.uri, sym.range, sym.note); }, .workspace_symbols => { var b: std.ArrayList(u8) = .empty; @@ -1106,20 +1143,42 @@ fn locations(cx: *Cx, enc: Enc, result: std.json.Value) Err!void { } } -/// DocumentSymbol[] nests (`children`), SymbolInformation[] is flat. -fn walkSymbols(cx: *Cx, enc: Enc, uri: []const u8, node: std.json.Value, depth: u8) Err!void { +/// A symbol a server listed: its row's place and words, `t Shape.area`. +const Symbol = struct { kind: SymbolKind, uri: []const u8, range: ?std.json.Value, note: []const u8 }; + +/// DocumentSymbol[] nests (`children`), SymbolInformation[] is flat: each +/// its kind's mark and its name qualified by the ones it is in (the +/// nesting, or SymbolInformation's `containerName`), into `out`. +fn walkSymbols(arena: std.mem.Allocator, out: *std.ArrayList(Symbol), uri: []const u8, node: std.json.Value, qualifier: []const u8, depth: u8) Err!void { if (depth > 8) return; for (items(node)) |sym| { const name = str(get(sym, "name")) orelse continue; + const kind = symbolKind(num(get(sym, "kind")) orelse 0); + const container = if (qualifier.len > 0) qualifier else str(get(sym, "containerName")) orelse ""; + const qualified = if (container.len > 0) try std.fmt.allocPrint(arena, "{s}.{s}", .{ container, name }) else name; + const note = try std.fmt.allocPrint(arena, "{s} {s}", .{ kind.mark(), qualified }); if (get(get(sym, "location"), "range")) |r| { - try emitRange(cx, enc, str(get(get(sym, "location"), "uri")) orelse uri, r, name); + try out.append(arena, .{ .kind = kind, .uri = str(get(get(sym, "location"), "uri")) orelse uri, .range = r, .note = note }); } else { - try emitRange(cx, enc, uri, get(sym, "selectionRange") orelse get(sym, "range"), name); + try out.append(arena, .{ .kind = kind, .uri = uri, .range = get(sym, "selectionRange") orelse get(sym, "range"), .note = note }); } - if (get(sym, "children")) |kids| try walkSymbols(cx, enc, uri, kids, depth + 1); + if (get(sym, "children")) |kids| try walkSymbols(arena, out, uri, kids, qualified, depth + 1); } } +/// LSP's SymbolKind as the Symbols picker's (UX DESIGN N2). +fn symbolKind(lsp_kind: i64) SymbolKind { + return switch (lsp_kind) { + 5, 10, 11, 23, 26 => .type, + 6, 9, 12, 25 => .function, + 7, 8, 22 => .field, + 14 => .constant, + 13, 15...21, 24 => .variable, + 1...4 => .module, + else => .other, + }; +} + /// Pull when the server does (LSP 3.17), the push store otherwise. The store /// path waits briefly for a publish that postdates the didChange we just /// sent, so `]d` right after an edit sees the new truth, not the old one. @@ -3162,11 +3221,53 @@ test "a language with no server to start says so, not that it did not answer" { try std.testing.expectEqualStrings("@none language server for .py not found\n", out.buffered()); } +test "a file opened whose server is not installed disables it without a word, at every file's open; a query of it then says it is not found" { + const host_io = @import("../host_io.zig"); + const io = std.testing.io; + const si = specFor("/x/a.py") orelse return; + const c = &conns[si]; + const was_state = c.state; + defer c.state = was_state; + // A test binary's files start servers only where it says so. + const names = [_][*:0]const u8{ "PARDES_LSP_PY", "PARDES_LSP_OPEN" }; + var was_buf: [names.len][4096:0]u8 = undefined; + var was: [names.len]?[:0]const u8 = undefined; + for (names, &was, &was_buf) |name, *w, *b| w.* = if (libc.getenv(name)) |v| try std.fmt.bufPrintSentinel(b, "{s}", .{std.mem.span(v)}, 0) else null; + defer for (names, was) |name, w| { + _ = if (w) |v| host_io.Shell.setenv(name, v.ptr, 1) else host_io.testUnsetenv(name); + }; + _ = host_io.Shell.setenv("PARDES_LSP_PY", "/nonexistent/pyright-langserver", 1); + _ = host_io.Shell.setenv("PARDES_LSP_OPEN", "on", 1); + const Said = struct { + var n: usize = 0; + fn post(_: ?*anyopaque, _: []const u8) void { + n += 1; + } + }; + Said.n = 0; + // A word said before is never said twice in a row (`post`): forgotten. + sink_last_len[si] = 0; + setStatusSink(null, Said.post); + defer setStatusSink(null, null); + c.state = .off; + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + for ([_][]const u8{ "/x/a.py", "/x/b.py" }) |path| { + try open(io, arena.allocator(), .{ .kind = .definition, .path = path, .source = "", .offset = 0, .root = "/x" }); + try std.testing.expectEqual(State.disabled, c.state); + } + try std.testing.expectEqual(@as(usize, 0), Said.n); + var buf: [256]u8 = undefined; + var out: std.Io.Writer = .fixed(&buf); + try query(io, arena.allocator(), .{ .kind = .hover, .path = "/x/a.py", .source = "", .offset = 0 }, &out); + try std.testing.expectEqualStrings("@none language server for .py not found\n", out.buffered()); +} + test "Lspinfo before any query says a server is not started yet, not off" { var out: std.Io.Writer.Allocating = .init(std.testing.allocator); defer out.deinit(); try status(std.testing.io, "/x/notes.txt", &out.writer); - try std.testing.expect(std.mem.indexOf(u8, out.written(), "not started yet (its first query starts it)") != null); + try std.testing.expect(std.mem.indexOf(u8, out.written(), "not started yet (a file of its opened starts it)") != null); } test "a server that failed a moment ago is said to have failed, and when it is tried again, not to be missing" { diff --git a/dev/macos/Sources/PardesView.swift b/dev/macos/Sources/PardesView.swift index 11818e10..8dbaea0e 100644 --- a/dev/macos/Sources/PardesView.swift +++ b/dev/macos/Sources/PardesView.swift @@ -96,14 +96,16 @@ private let sRGB: CGColorSpace = CGColorSpace(name: CGColorSpace.sRGB) ?? CGColo // a CTFont instead of being bridged to NSFont on the way in. private let fontAttribute = NSAttributedString.Key(kCTFontAttributeName as String) -// The named sixteen, then xterm's 6x6x6 cube, then the 24-step grey ramp. These -// sixteen are app.mjs's, not gui.zig's: gui.zig borrows ghostty's palette -// because it already links it, and the two disagree on the base colors. +// The named sixteen, then xterm's 6x6x6 cube, then the 24-step grey ramp. A +// window is handed a program's sixteen as the theme's own colours (the core's +// terminal paint, colors.Chrome's ansi), so an index under 16 reaches it only +// from elsewhere; these are core/colors.zig's `xterm`, the gui's, so an index +// is one colour in every window. private let ansi16: [UInt32] = [ - 0x00_00_00, 0xCC_00_00, 0x4E_9A_06, 0xC4_A0_00, - 0x34_65_A4, 0x75_50_7B, 0x06_98_9A, 0xD3_D7_CF, - 0x55_57_53, 0xEF_29_29, 0x8A_E2_34, 0xFC_E9_4F, - 0x72_9F_CF, 0xAD_7F_A8, 0x34_E2_E2, 0xEE_EE_EC, + 0x1D_1F_21, 0xCC_66_66, 0xB5_BD_68, 0xF0_C6_74, + 0x81_A2_BE, 0xB2_94_BB, 0x8A_BE_B7, 0xC5_C8_C6, + 0x66_66_66, 0xD5_4E_53, 0xB9_CA_4A, 0xE7_C5_47, + 0x7A_A6_DA, 0xC3_97_D8, 0x70_C0_B1, 0xEA_EA_EA, ] private func paletteColor(_ index: UInt8) -> UInt32 { diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 300e9fea..8cb06b05 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -1328,6 +1328,7 @@ const Shell = struct { .open_link = openLink, .start = host_io.startDetached, .lsp = lsp, + .lsp_open = lspOpen, .pipe = pipe, .search = search, .job = job, @@ -2047,6 +2048,13 @@ const Shell = struct { s.core.reportError(req.pane, "lsp", error.WorkersUnavailable); } + /// Not held for `threads_ok`: the boot's file and a restored + /// session's are opened before `start`. + fn lspOpen(ctx: ?*anyopaque, pane: pardes.Pane.Id) void { + const s = of(ctx); + s.ptys.queue.openLsp(s.core, pane); + } + fn pipe(ctx: ?*anyopaque, id: u32) void { const s = of(ctx); if (!s.threads_ok) { @@ -2236,7 +2244,7 @@ fn trailCells(arena: std.mem.Allocator, shown: *const pardes.Surface, trail: *Ju if (region.kind == .body and cursor.x >= region.rect.x and cursor.x < @as(u32, region.rect.x) + region.rect.w and cursor.y >= region.rect.y and cursor.y < @as(u32, region.rect.y) + region.rect.h) break region.rect; } else return shown; - const ink = shown.chrome.fg orelse .{ 0xcc, 0xcc, 0xcc }; + const ink = shown.chrome.fg orelse pardes.colors.null_text; const page = shown.chrome.page orelse pardes.colors.null_page; const out = try arena.create(pardes.Surface); out.* = shown.*; |
