diff options
Diffstat (limited to 'src/panes.zig')
| -rw-r--r-- | src/panes.zig | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/panes.zig b/src/panes.zig index 886d4b28..315b0b0f 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -271,8 +271,13 @@ pub const Pane = struct { pub fn colorAlgo(pane: *const Pane) ColorAlgo { if (pane.isTerminal()) return .tty; if (pane.file) |f| { + if (f.mini != null) return .source; if (std.mem.endsWith(u8, f.path, ".diff") or std.mem.endsWith(u8, f.path, ".patch")) return .diff; - if (f.output != null and !Output.fileTraits(f.output).saves) return .locations; + if (f.output != null) { + const tr = Output.fileTraits(f.output); + if (tr.locations) return .locations; + if (!tr.saves) return .none; + } return .source; } return .none; @@ -1811,6 +1816,7 @@ pub const File = struct { else @max(start, lineStart(p.gpa, f, f.scroll + pane.rows + SYNTAX_CONTEXT_AFTER_ROWS + slack)); const new_highlights = (switch (pane.colorAlgo()) { + .none => @as([]u8, &.{}), .diff => syntax.highlightDiff(p.tree_sitter_gpa, f.content, start, end), .locations => if (f.location_rows.len > 0) syntax.highlightLocationRows(p.tree_sitter_gpa, f.content, f.location_rows) @@ -2187,6 +2193,7 @@ pub const Output = struct { fn decorateRow(output: ?State, line: []const u8, metadata: ?locations.Row) RowDecoration { const origin = (output orelse return .{}).from; + if (!traits(origin).locations) return .{}; const target = locations.parse(line); const spot = if (metadata) |m| m.at else target.at; if (spot.line == 0) return .{}; @@ -2238,6 +2245,18 @@ pub const Output = struct { try std.testing.expect(malformed.mark_end <= "src/a.rs:3:99999999999999999999-99999999999999999999 text".len); } + test "plain output does not opt into location decoration" { + const report = rowDecoration(.{ .from = .{ .cmd = .LocationsConfig } }, "LocationsConfig context:5 tscontext:on"); + try std.testing.expectEqualDeep(RowDecoration{}, report); + const prose = rowDecoration(.{ .from = .{ .query = .hover } }, "src/a.rs:3:5-7 error: prose"); + try std.testing.expectEqualDeep(RowDecoration{}, prose); + const errors = rowDecoration(.{ .from = .errors }, "src/a.rs:3:5-7 error: prose"); + try std.testing.expectEqualDeep(RowDecoration{}, errors); + try std.testing.expect(!traits(.{ .cmd = .Find }).locations); + try std.testing.expect(traits(.{ .cmd = .Grep }).locations); + try std.testing.expect(traits(.{ .query = .completion }).locations); + } + pub fn setArg(o: *State, text: []const u8) error{ArgumentTooLong}!void { if (text.len > max_arg) return error.ArgumentTooLong; o.arg_len = @intCast(text.len); @@ -2251,18 +2270,19 @@ pub const Output = struct { pub fn traits(o: Origin) Traits { return switch (o) { // rows are `location text`, so n/N walk them - .search => .{ .name = config.search_buffer, .steps = true }, + .search => .{ .name = config.search_buffer, .steps = true, .locations = true }, .errors => .{ .name = config.errors_buffer, .doc = true }, - .pdf_links => .{ .name = config.pdf_links_buffer, .steps = true }, + .pdf_links => .{ .name = config.pdf_links_buffer, .steps = true, .locations = true }, .cmd => |b| builtins.registry.outputTraits(b) orelse unreachable, .query => |k| switch (k) { .hover => .{ .name = config.hover_buffer }, // prose: an action list, a diff, a report about the backend .code_action, .format, .status, .explain => .{ .name = config.lsp_buffer }, - .rename => .{ .name = config.search_buffer, .steps = true }, + .rename => .{ .name = config.search_buffer, .steps = true, .locations = true }, .definition, .declaration, .type_definition, .implementation, .references => .{ .name = config.search_buffer, .steps = true, + .locations = true, .jumps = true, }, // The hierarchy kinds behave like references: a list of places, @@ -2270,11 +2290,13 @@ pub const Output = struct { .incoming_calls, .outgoing_calls, .supertypes, .subtypes => .{ .name = config.search_buffer, .steps = true, + .locations = true, .jumps = true, }, .document_symbols, .workspace_symbols, .diagnostics, .workspace_diagnostics, .select_refs, .completion => .{ .name = config.search_buffer, .steps = true, + .locations = true, }, }, }; |
