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:
parent
8cf18d7481
commit
68b3fe1624
2 changed files with 14 additions and 0 deletions
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue