From 9f688cf4ed58126af3caced4bc1c7d4e91bbb4f4 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Mon, 17 Oct 2022 20:20:34 +0200 Subject: [PATCH] simplify tagStoreCompletionItems --- src/DocumentStore.zig | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index 571afdc..d8943be 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -856,34 +856,21 @@ fn tagStoreCompletionItems(self: DocumentStore, arena: std.mem.Allocator, handle const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); - const completion_set: analysis.CompletionSet = @field(handle.document_scope, name); + var dependencies = std.ArrayListUnmanaged(Uri){}; + try dependencies.append(self.allocator, handle); + try collectDependencies(self.allocator, self, handle, dependencies); // TODO Better solution for deciding what tags to include var result_set = analysis.CompletionSet{}; - try result_set.ensureTotalCapacity(arena, completion_set.entries.items(.key).len); - for (completion_set.entries.items(.key)) |completion| { - result_set.putAssumeCapacityNoClobber(completion, {}); - } - - for (handle.import_uris.items) |uri| { - const curr_set = @field(self.handles.get(uri).?.document_scope, name); + for (dependencies) |uri| { + // not every dependency is loaded which results in incomplete completion + const hdl = self.handles.get(uri) orelse continue; + const curr_set = @field(hdl.document_scope, name); for (curr_set.entries.items(.key)) |completion| { try result_set.put(arena, completion, {}); } } - for (handle.cimports.items(.hash)) |hash| { - const result = self.cimports.get(hash) orelse continue; - switch (result) { - .success => |uri| { - const curr_set = @field(self.handles.get(uri).?.document_scope, name); - for (curr_set.entries.items(.key)) |completion| { - try result_set.put(arena, completion, {}); - } - }, - .failure => {}, - } - } return result_set.entries.items(.key); }