Do not add every node when adding decls, just the supported nodes

This commit is contained in:
Alexandros Naskos 2020-05-23 00:02:26 +03:00
parent 39bbf9c8bc
commit 077a17e2f5
2 changed files with 6 additions and 3 deletions

View File

@ -513,7 +513,7 @@ pub fn nodeToString(tree: *ast.Tree, node: *ast.Node) ?[]const u8 {
return null;
}
pub fn declsFromIndexInternal(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree, node: *ast.Node) anyerror!void {
pub fn declsFromIndexInternal(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree, node: *ast.Node) error{OutOfMemory}!void {
switch (node.id) {
.FnProto => {
const func = node.cast(ast.Node.FnProto).?;
@ -536,7 +536,7 @@ pub fn declsFromIndexInternal(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree,
}
},
.VarDecl, .ParamDecl => try decls.append(node),
else => try addChildrenNodes(decls, tree, node),
else => {},
}
}
@ -553,7 +553,7 @@ pub fn declsFromIndex(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree, index:
try addChildrenNodes(decls, tree, node);
var node_index: usize = 0;
while (node.iterate(node_index)) |inode| : (node_index += 1) {
if (tree.tokens.at(inode.firstToken()).start < index and index < tree.tokens.at(inode.lastToken()).end) {
if (nodeContainsSourceIndex(tree, inode, index)) {
try declsFromIndexInternal(decls, tree, inode);
}
}

View File

@ -190,6 +190,8 @@ fn nodeToCompletion(list: *std.ArrayList(types.CompletionItem), analysis_ctx: *D
else
null;
std.debug.warn("{}\n", .{node.id});
switch (node.id) {
.ErrorSetDecl, .Root, .ContainerDecl => {
try containerToCompletion(list, analysis_ctx, node, config);
@ -411,6 +413,7 @@ fn completeGlobal(id: i64, pos_index: usize, handle: *DocumentStore.Handle, conf
try analysis.declsFromIndex(&decl_nodes, analysis_ctx.tree, pos_index);
for (decl_nodes.items) |decl_ptr| {
var decl = decl_ptr.*;
std.debug.warn("Global completion: {}\n", .{decl});
try nodeToCompletion(&completions, &analysis_ctx, decl_ptr, config);
}