From 077a17e2f51e7630ae7e782a3ce2a96493f25ab8 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Sat, 23 May 2020 00:02:26 +0300 Subject: [PATCH] Do not add every node when adding decls, just the supported nodes --- src/analysis.zig | 6 +++--- src/main.zig | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index ddb2abf..750681b 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -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); } } diff --git a/src/main.zig b/src/main.zig index 643e7cd..7375a08 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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); }