Skip to content

Commit 8bd33cc

Browse files
committed
only report workspace symbols on files inside a workspace folder
1 parent a93d9c5 commit 8bd33cc

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/DocumentStore.zig

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,16 +1077,28 @@ fn invalidateBuildFileWorker(self: *DocumentStore, build_file: *BuildFile) void
10771077
}
10781078
}
10791079

1080-
pub fn loadTrigramStores(store: *DocumentStore) error{OutOfMemory}![]*DocumentStore.Handle {
1080+
pub fn loadTrigramStores(
1081+
store: *DocumentStore,
1082+
filter_paths: []const []const u8,
1083+
) error{OutOfMemory}![]*DocumentStore.Handle {
10811084
const tracy_zone = tracy.trace(@src());
10821085
defer tracy_zone.end();
10831086

10841087
var handles: std.ArrayListUnmanaged(*DocumentStore.Handle) = try .initCapacity(store.allocator, store.handles.count());
10851088
errdefer handles.deinit(store.allocator);
10861089

10871090
for (store.handles.values()) |handle| {
1088-
// TODO check if the handle is in a workspace folder instead
1089-
if (isInStd(handle.uri)) continue;
1091+
if (URI.toFsPath(store.allocator, handle.uri)) |path| {
1092+
defer store.allocator.free(path);
1093+
for (filter_paths) |filter_path| {
1094+
if (std.mem.startsWith(u8, path, filter_path)) break;
1095+
} else break;
1096+
} else |err| switch (err) {
1097+
error.OutOfMemory => return error.OutOfMemory,
1098+
else => {
1099+
// The URI is either invalid or not a `file` scheme. Either way, we should include it.
1100+
},
1101+
}
10901102
handles.appendAssumeCapacity(handle);
10911103
}
10921104

src/features/workspace_symbols.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,22 @@ const DocumentStore = @import("../DocumentStore.zig");
99
const offsets = @import("../offsets.zig");
1010
const Server = @import("../Server.zig");
1111
const TrigramStore = @import("../TrigramStore.zig");
12+
const URI = @import("../uri.zig");
1213

1314
pub fn handler(server: *Server, arena: std.mem.Allocator, request: types.WorkspaceSymbolParams) error{OutOfMemory}!lsp.ResultType("workspace/symbol") {
1415
if (request.query.len < 3) return null;
1516

16-
const handles = try server.document_store.loadTrigramStores();
17+
var workspace_paths: std.ArrayList([]const u8) = try .initCapacity(arena, server.workspaces.items.len);
18+
for (server.workspaces.items) |workspace| {
19+
const path = URI.toFsPath(arena, workspace.uri) catch |err| switch (err) {
20+
error.OutOfMemory => return error.OutOfMemory,
21+
error.UnsupportedScheme => continue,
22+
else => continue,
23+
};
24+
workspace_paths.appendAssumeCapacity(path);
25+
}
26+
27+
const handles = try server.document_store.loadTrigramStores(workspace_paths.items);
1728
defer server.document_store.allocator.free(handles);
1829

1930
var symbols: std.ArrayListUnmanaged(lsp.types.WorkspaceSymbol) = .empty;

0 commit comments

Comments
 (0)