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
This commit is contained in:
CJ van den Berg 2026-01-26 12:32:58 +01:00
parent 8cf18d7481
commit 68b3fe1624
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 14 additions and 0 deletions

View file

@ -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;
};

View file

@ -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;
};