diff --git a/src/tui/editor.zig b/src/tui/editor.zig index b882c5e..b222d79 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -328,6 +328,7 @@ pub const Editor = struct { last_find_query: ?[]const u8 = null, find_history: ?std.ArrayListUnmanaged([]const u8) = null, find_operation: ?enum { goto_next_match, goto_prev_match } = null, + highlight_references_state: enum { adding, done } = .done, prefix_buf: [8]u8 = undefined, prefix: []const u8 = &[_]u8{}, @@ -5798,6 +5799,34 @@ pub const Editor = struct { self.need_render(); } + pub fn highlight_references(self: *Self, _: Context) Result { + const file_path = self.file_path orelse return; + const primary = self.get_primary(); + return project_manager.highlight_references(file_path, primary.cursor.row, primary.cursor.col); + } + pub const highlight_references_meta: Meta = .{ .description = "Language: Highlight references" }; + + pub fn add_highlight_reference(self: *Self, match_: Match) void { + if (self.highlight_references_state == .done) { + self.highlight_references_state = .adding; + self.cancel_all_matches(); + } + const root = self.buf_root() catch return; + const begin_row = match_.begin.row - @min(match_.begin.row, 1); + const begin_col = root.pos_to_width(begin_row, match_.begin.col, self.metrics) catch return; + const end_row = match_.end.row - @min(match_.end.row, 1); + const end_col = root.pos_to_width(end_row, match_.end.col, self.metrics) catch return; + (self.matches.addOne(self.allocator) catch return).* = .{ + .begin = .{ .row = begin_row, .col = begin_col }, + .end = .{ .row = end_row, .col = end_col }, + }; + self.need_render(); + } + + pub fn done_highlight_reference(self: *Self) void { + self.highlight_references_state = .done; + } + pub fn add_diagnostic( self: *Self, file_path: []const u8, diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 9ceee95..a0f3e9b 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -140,6 +140,15 @@ pub fn receive(self: *Self, from_: tp.pid_ref, m: tp.message) error{Exit}!bool { } self.find_in_files_state = .done; return true; + } else if (try m.match(.{ "HREF", tp.extract(&path), tp.extract(&begin_line), tp.extract(&begin_pos), tp.extract(&end_line), tp.extract(&end_pos), tp.extract(&lines) })) { + if (self.get_active_editor()) |editor| editor.add_highlight_reference(.{ + .begin = .{ .row = begin_line, .col = begin_pos }, + .end = .{ .row = end_line, .col = end_pos }, + }); + return true; + } else if (try m.match(.{ "HREF", "done" })) { + if (self.get_active_editor()) |editor| editor.done_highlight_reference(); + return true; } else if (try m.match(.{ "hover", tp.extract(&path), tp.string, tp.extract(&lines), tp.extract(&begin_line), tp.extract(&begin_pos), tp.extract(&end_line), tp.extract(&end_pos) })) { try self.add_info_content(lines); if (self.get_active_editor()) |editor|