From 68b3fe162423480cae6b66c32d954e3f746f173c Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Mon, 26 Jan 2026 12:32:58 +0100 Subject: [PATCH] fix: deduplicate completion results Some LSPs may return duplicate results for some queries, so we no force de-duplication when loading the completion palettes. closes #469 --- src/tui/mode/overlay/completion_dropdown.zig | 7 +++++++ src/tui/mode/overlay/completion_palette.zig | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/tui/mode/overlay/completion_dropdown.zig b/src/tui/mode/overlay/completion_dropdown.zig index 480d9f4..ccb4205 100644 --- a/src/tui/mode/overlay/completion_dropdown.zig +++ b/src/tui/mode/overlay/completion_dropdown.zig @@ -43,6 +43,9 @@ pub fn load_entries(self: *Type) !usize { max_description = 0; var max_label_len: usize = 0; + var existing: std.StringHashMapUnmanaged(void) = .empty; + defer existing.deinit(self.allocator); + const editor = tui.get_active_editor() orelse return error.NotFound; self.value.start = editor.get_primary().*; var iter: []const u8 = editor.completions.items; @@ -50,6 +53,10 @@ pub fn load_entries(self: *Type) !usize { var cbor_item: []const u8 = undefined; if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion; const values = get_values(cbor_item); + + if (existing.contains(values.sort_text)) continue; + try existing.put(self.allocator, values.sort_text, {}); + if (self.value.replace == null) if (get_replace_selection(values.replace)) |replace| { self.value.replace = replace; }; diff --git a/src/tui/mode/overlay/completion_palette.zig b/src/tui/mode/overlay/completion_palette.zig index b913a19..7045136 100644 --- a/src/tui/mode/overlay/completion_palette.zig +++ b/src/tui/mode/overlay/completion_palette.zig @@ -38,6 +38,9 @@ pub fn load_entries(palette: *Type) !usize { max_description = 0; var max_label_len: usize = 0; + var existing: std.StringHashMapUnmanaged(void) = .empty; + defer existing.deinit(palette.allocator); + const editor = tui.get_active_editor() orelse return error.NotFound; palette.value.start = editor.get_primary().*; var iter: []const u8 = editor.completions.items; @@ -45,6 +48,10 @@ pub fn load_entries(palette: *Type) !usize { var cbor_item: []const u8 = undefined; if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion; const values = get_values(cbor_item); + + if (existing.contains(values.sort_text)) continue; + try existing.put(palette.allocator, values.sort_text, {}); + if (palette.value.replace == null) if (get_replace_selection(values.replace)) |replace| { palette.value.replace = replace; };