simplify dependency collection in references.zig

This commit is contained in:
Techatrix 2022-10-17 21:20:27 +02:00
parent 8fb7379d71
commit 2755d8d8b7
2 changed files with 9 additions and 31 deletions

View File

@ -258,7 +258,7 @@ fn garbageCollectionImports(self: *DocumentStore) error{OutOfMemory}!void {
try reachable_handles.put(self.allocator, handle.uri, {});
try collectDependencies(self.allocator, self, handle.*, &queue);
try self.collectDependencies(self.allocator, handle.*, &queue);
}
while (queue.popOrNull()) |uri| {
@ -268,7 +268,7 @@ fn garbageCollectionImports(self: *DocumentStore) error{OutOfMemory}!void {
const handle = self.handles.get(uri) orelse continue;
try collectDependencies(self.allocator, self, handle.*, &queue);
try self.collectDependencies(self.allocator, handle.*, &queue);
}
var i: usize = 0;
@ -763,8 +763,8 @@ fn collectCIncludes(self: *const DocumentStore, handle: Handle) error{OutOfMemor
/// collects every file uri the given handle depends on
/// includes imports, cimports & packages
pub fn collectDependencies(
allocator: std.mem.Allocator,
store: *const DocumentStore,
allocator: std.mem.Allocator,
handle: Handle,
dependencies: *std.ArrayListUnmanaged(Uri),
) error{OutOfMemory}!void {
@ -879,7 +879,7 @@ fn tagStoreCompletionItems(self: DocumentStore, arena: std.mem.Allocator, handle
var dependencies = std.ArrayListUnmanaged(Uri){};
try dependencies.append(self.allocator, handle.uri);
try collectDependencies(self.allocator, &self, handle, &dependencies);
try self.collectDependencies(self.allocator, handle, &dependencies);
// TODO Better solution for deciding what tags to include
var result_set = analysis.CompletionSet{};

View File

@ -483,41 +483,19 @@ pub fn symbolReferences(
if (decl_handle.decl.* != .ast_node) return builder.locations;
if (!workspace) return builder.locations;
var imports = std.ArrayListUnmanaged(*const DocumentStore.Handle){};
for (store.handles.values()) |handle| {
if (skip_std_references and std.mem.indexOf(u8, handle.uri, "std") != null) {
if (!include_decl or !std.mem.eql(u8, handle.uri, curr_handle.uri))
continue;
}
// Check entry's transitive imports
try imports.append(arena.allocator(), handle);
var i: usize = 0;
blk: while (i < imports.items.len) : (i += 1) {
const import = imports.items[i];
// TODO handle cimports
for (import.import_uris.items) |uri| {
const h = store.getHandle(uri) orelse break;
var dependencies = std.ArrayListUnmanaged([]const u8){};
try store.collectDependencies(store.allocator, handle.*, &dependencies);
if (h == curr_handle) {
// entry does import curr_handle
try symbolReferencesInternal(&builder, 0, handle);
break :blk;
}
select: {
for (imports.items) |item| {
if (item == h) {
// already checked this import
break :select;
}
}
try imports.append(arena.allocator(), h);
}
}
for (dependencies.items) |uri| {
const hdl = store.getHandle(uri) orelse continue;
try symbolReferencesInternal(&builder, 0, hdl);
}
try imports.resize(arena.allocator(), 0);
}
},
.param_payload => |pay| blk: {