Skip to content

Commit a983928

Browse files
committed
add function declarations to workspace symbols
1 parent 5cfbb0d commit a983928

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

src/TrigramStore.zig

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,20 @@ pub fn init(
4949
const old_in_function = context.in_function;
5050
defer context.in_function = old_in_function;
5151

52+
var name_token_maybe: ?Ast.TokenIndex = null;
5253
switch (cb_tree.nodeTag(node)) {
53-
.fn_decl => {
54-
if (!context.in_function) {}
55-
56-
context.in_function = true;
54+
.fn_proto,
55+
.fn_proto_multi,
56+
.fn_proto_one,
57+
.fn_proto_simple,
58+
.fn_decl,
59+
=> |tag| skip: {
60+
context.in_function = tag == .fn_decl;
61+
62+
const fn_token = cb_tree.nodeMainToken(node);
63+
if (cb_tree.tokenTag(fn_token + 1) != .identifier) break :skip;
64+
65+
name_token_maybe = fn_token + 1;
5766
},
5867
.root => unreachable,
5968
.container_decl,
@@ -74,26 +83,25 @@ pub fn init(
7483
.local_var_decl,
7584
.simple_var_decl,
7685
.aligned_var_decl,
77-
=> {
78-
if (!context.in_function) {
79-
const token = cb_tree.fullVarDecl(node).?.ast.mut_token + 1;
80-
const name = cb_tree.tokenSlice(token);
81-
82-
if (name.len >= 3) {
83-
const loc = offsets.tokenToLoc(cb_tree, token);
84-
85-
try context.store.appendDeclaration(
86-
context.allocator,
87-
name,
88-
.{ .start = @intCast(loc.start), .end = @intCast(loc.end) },
89-
);
90-
}
91-
}
86+
=> skip: {
87+
if (context.in_function) break :skip;
88+
name_token_maybe = cb_tree.nodeMainToken(node) + 1;
9289
},
93-
9490
else => {},
9591
}
9692

93+
if (name_token_maybe) |name_token| skip: {
94+
const loc = offsets.tokenToLoc(cb_tree, name_token);
95+
const name = offsets.locToSlice(cb_tree.source, loc);
96+
if (name.len < 3) break :skip;
97+
98+
try context.store.appendDeclaration(
99+
context.allocator,
100+
name,
101+
.{ .start = @intCast(loc.start), .end = @intCast(loc.end) },
102+
);
103+
}
104+
97105
try ast.iterateChildren(cb_tree, node, context, Error, callback);
98106
}
99107
};

0 commit comments

Comments
 (0)