fix: highlight references only when the lsp is finished sending them

This commit is contained in:
CJ van den Berg 2026-01-15 22:56:54 +01:00
parent 08f47edd6a
commit 82f9429e3c
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -365,6 +365,7 @@ pub const Editor = struct {
find_history: ?std.ArrayListUnmanaged([]const u8) = null,
find_operation: ?enum { goto_next_match, goto_prev_match } = null,
highlight_references_state: enum { adding, done } = .done,
highlight_references_pending: Match.List = .empty,
prefix_buf: [8]u8 = undefined,
prefix: []const u8 = &[_]u8{},
@ -622,6 +623,7 @@ pub const Editor = struct {
self.cancel_all_tabstops();
self.cursels.deinit(self.allocator);
self.matches.deinit(self.allocator);
self.highlight_references_pending.deinit(self.allocator);
self.handlers.deinit();
self.logger.deinit();
if (self.buffer) |p| self.buffer_manager.retire(p, meta.written());
@ -6239,7 +6241,7 @@ pub const Editor = struct {
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();
self.highlight_references_pending.clearRetainingCapacity();
}
self.match_type = .highlight_references;
const root = self.buf_root() catch return;
@ -6247,13 +6249,16 @@ pub const Editor = struct {
match.begin.row -|= 1;
match.end.row -|= 1;
match = match.from_pos(root, self.metrics);
(self.matches.addOne(self.allocator) catch return).* = match;
self.need_render();
(self.highlight_references_pending.addOne(self.allocator) catch return).* = match;
}
pub fn done_highlight_reference(self: *Self) void {
self.cancel_all_matches();
for (self.highlight_references_pending.items) |match|
(self.matches.addOne(self.allocator) catch return).* = match;
self.sort_matches();
self.highlight_references_state = .done;
self.need_render();
}
pub fn add_diagnostic(