summaryrefslogtreecommitdiff
path: root/core/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/File.zig')
-rw-r--r--core/File.zig67
1 files changed, 38 insertions, 29 deletions
diff --git a/core/File.zig b/core/File.zig
index 217531fd..d54d5011 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -60,35 +60,39 @@ pub const History = struct {
}
};
-/// Owned syntax results: a text's declarations at a revision.
+/// Owned syntax results: a text's declarations and symbols at a revision.
pub const ContextCache = struct {
/// Its revision is dumped and digested: a worker's parse is an input,
/// which a client joined since never saw, and a step reads what it
- /// left (Query.ownerDecls). The declarations are made again from the
- /// text at a load (`reload`), with the allocator that made them.
- pub const replica = .{ .local = .{"allocator"}, .derived = .{"declarations"} };
+ /// left (Query.ownerDecls, the Symbols source). The declarations and
+ /// symbols are made again from the text at a load (`reload`), with the
+ /// allocator that made them.
+ pub const replica = .{ .local = .{"allocator"}, .derived = .{ "declarations", "symbols" } };
allocator: ?std.mem.Allocator = null,
declarations: []syntax.ContextDeclaration = &.{},
+ symbols: []syntax.Symbol = &.{},
revision: ?u32 = null,
pub fn deinit(self: *ContextCache) void {
- if (self.allocator) |gpa| gpa.free(self.declarations);
+ if (self.allocator) |gpa| {
+ gpa.free(self.declarations);
+ gpa.free(self.symbols);
+ }
self.* = .{};
}
- /// A loaded text's (its revision the dump's): its declarations parsed
- /// again where they are of the text it has.
+ /// A loaded text's (its revision the dump's): its context parsed
+ /// again where it is of the text it has.
pub fn reload(self: *ContextCache, gpa: std.mem.Allocator, path: []const u8, content: []const u8, revision: u32) void {
const at = self.revision orelse return;
if (at != revision) return;
- const declarations = syntax.contextDeclarations(gpa, path, content) catch return;
- self.replace(gpa, declarations, at);
+ self.replace(gpa, syntax.context(gpa, path, content) catch return, at);
}
- /// Takes ownership of declarations allocated by gpa.
- pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, declarations: []syntax.ContextDeclaration, revision: u32) void {
+ /// Takes ownership of a context allocated by gpa.
+ pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, made: syntax.Context, revision: u32) void {
self.deinit();
- self.* = .{ .allocator = gpa, .declarations = declarations, .revision = revision };
+ self.* = .{ .allocator = gpa, .declarations = made.declarations, .symbols = made.symbols, .revision = revision };
}
};
@@ -922,7 +926,13 @@ pub fn open(p: *Pardes, id: usize, path: []const u8, line: usize) !*Pane {
pane.body.cur_pinned = true;
pane.body.cur_row = @intCast(scroll);
p.installPane(id, pane);
- if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
+ if (filesystem.localPath(path) != null) {
+ p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
+ // Its language's server started now, off the loop: the first
+ // question asked of it finds it ready. Not a picker's preview's,
+ // which opens no pane (Pick.preview).
+ p.emit(.{ .lsp_open = .{ .pane = .at(id) } });
+ }
return pane;
}
@@ -2495,8 +2505,7 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void {
pub fn refreshContext(p: *Pardes, pane: *Pane, f: *State) void {
if (!f.tree_context or !supportsContext(pane) or f.context.revision == f.revision) return;
// The file's declarations, in its lines (the layer's are none of it).
- const declarations = syntax.contextDeclarations(p.tree_sitter_gpa, f.path, fileText(f, p.scratch.allocator()) catch return) catch return;
- f.context.replace(p.tree_sitter_gpa, declarations, f.revision);
+ f.context.replace(p.tree_sitter_gpa, syntax.context(p.tree_sitter_gpa, f.path, fileText(f, p.scratch.allocator()) catch return) catch return, f.revision);
}
pub fn refreshHighlights(p: *Pardes) void {
@@ -2922,7 +2931,8 @@ pub const Layers = struct {
pub const SynStyle = struct { fg: [3]u8, bold: bool };
pub fn synStyle(p: *Pardes, sy: syntax.Syn) ?SynStyle {
- return .{ .fg = Colors.synInk(p.theme(), sy) orelse return null, .bold = false };
+ if (sy == .none) return null;
+ return .{ .fg = p.chrome().syntax[@intFromEnum(sy)], .bold = false };
}
/// syntax colors: recolor each content cell from its tree-sitter style byte;
@@ -2945,9 +2955,9 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
const tz_recolor = tracy.zone(@src(), "synRecolor");
defer tz_recolor.end();
// A row whose first byte names a hue (syntax.ground_add, _del): its
- // grounds, the theme's, worked out once a frame and only for one.
- var grounds: ?Colors.Grounds = null;
- const ink = ansi.inkOf(p.theme());
+ // grounds, the chrome's (R10).
+ const chrome = p.chrome();
+ const ink = ansi.inkOf(p);
var filtered_storage: pardes.Term.Filter = undefined;
const filtered: ?*pardes.Term.Filter = if (pane.tty_filter and spans.len > 0) blk: {
filtered_storage = pardes.Term.filter(&ink, &p.tty_filter_palette);
@@ -2985,14 +2995,11 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
const row_index: usize = @intCast(@max(0, pane.wrapAt(p.settings.tab, vr).line));
const metadata: ?locations.Row = if (row_index < f.location_rows.len) f.location_rows[row_index] else null;
const decoration = Output.decorateRow(f.output, line, metadata);
- const chrome: ?*const pardes.ChromeTheme = if (decoration.plain()) null else p.bodyChrome();
+ const decorated = !decoration.plain();
// The row's first byte: its hue and its ground, on every wrapped
// row of it (syntax.ground_add).
const lead: u8 = if (base >= highlight_start and base - highlight_start < highlights.len) highlights[base - highlight_start] else 0;
- const tint: ?Colors.Grounds.Ground = if (lead & (syntax.ground_add | syntax.ground_del) == 0) null else (grounds orelse ground: {
- grounds = .of(p.theme());
- break :ground grounds.?;
- }).forStyle(lead);
+ const tint: ?*const Colors.Chrome.Diff = if (lead & syntax.ground_add != 0) &chrome.add else if (lead & syntax.ground_del != 0) &chrome.del else null;
// 2, the patch: the row's ground.
if (tint) |t| if (prefix_width < tw) {
const ground: ?[3]u8 = if (lead & syntax.ground_emph != 0) t.row else if (lead & syntax.ground_line != 0) t.line else null;
@@ -3009,7 +3016,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
var c: usize = 0;
const pad: usize = if (vr < pane.wrap_n) pane.wrap_pad[vr] else 0;
for (0..@min(pad, tw -| prefix_width)) |col| {
- s.at(tx + @as(u16, @intCast(prefix_width + col)), body_y + vr).style.fg = .{ .rgb = p.bodyChrome().diagnostic_info };
+ s.at(tx + @as(u16, @intCast(prefix_width + col)), body_y + vr).style.fg = .{ .rgb = chrome.page.dim };
}
var screen_c: usize = pad;
var table_buf: [Tables.max_pads]Tables.Pad = undefined;
@@ -3057,7 +3064,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
}
// Results keep their exact live text. Only the location,
// matched source range and diagnostic label gain emphasis.
- if (if (chrome) |ch| decoration.styleAt(ch, hs + c) else null) |style| {
+ if (if (decorated) decoration.styleAt(chrome, hs + c) else null) |style| {
var fill: usize = 0;
while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) {
const cell = s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr);
@@ -3109,6 +3116,7 @@ pub fn paintWordSelection(
word_lo: i32,
word_hi: i32,
bg: [3]u8,
+ fg: ?[3]u8,
) void {
const tx = r.x + config.GUTTER;
const tw = r.w - config.GUTTER;
@@ -3127,7 +3135,7 @@ pub fn paintWordSelection(
const c1 = @as(i32, prefix_width) + here.pad + displayEndOffset(p.settings.tab, pane, row, here.at, hi - 1);
const col = @max(@as(i32, prefix_width), c0);
const end = @min(c1 + 1, @as(i32, tw));
- if (col < end) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(vr)), @intCast(end - col), bg, null);
+ if (col < end) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(vr)), @intCast(end - col), bg, fg);
}
}
@@ -3620,12 +3628,13 @@ test "context cache frees each allocation with its original allocator" {
defer std.testing.expect(second.deinit() == .ok) catch @panic("second allocator leaked");
var cache: ContextCache = .{};
defer cache.deinit();
- cache.replace(first.allocator(), try first.allocator().alloc(syntax.ContextDeclaration, 1), 1);
- cache.replace(second.allocator(), try second.allocator().alloc(syntax.ContextDeclaration, 2), 2);
+ cache.replace(first.allocator(), .{ .declarations = try first.allocator().alloc(syntax.ContextDeclaration, 1), .symbols = try first.allocator().alloc(syntax.Symbol, 1) }, 1);
+ cache.replace(second.allocator(), .{ .declarations = try second.allocator().alloc(syntax.ContextDeclaration, 2), .symbols = try second.allocator().alloc(syntax.Symbol, 2) }, 2);
try std.testing.expectEqual(@as(?u32, 2), cache.revision);
cache.deinit();
try std.testing.expect(cache.allocator == null);
try std.testing.expectEqual(@as(usize, 0), cache.declarations.len);
+ try std.testing.expectEqual(@as(usize, 0), cache.symbols.len);
}
/// The inks of row `row`'s first `n` text cells of pane `id` as `s` draws them.