A couple of more changes

This commit is contained in:
Alexandros Naskos 2020-05-18 14:53:40 +03:00
parent 4ad33c16f9
commit e65d3388e4
2 changed files with 6 additions and 12 deletions

View File

@ -206,7 +206,6 @@ pub fn getChild(tree: *ast.Tree, node: *ast.Node, name: []const u8) ?*ast.Node {
/// Gets the child of slice /// Gets the child of slice
pub fn getChildOfSlice(tree: *ast.Tree, nodes: []*ast.Node, name: []const u8) ?*ast.Node { pub fn getChildOfSlice(tree: *ast.Tree, nodes: []*ast.Node, name: []const u8) ?*ast.Node {
// var index: usize = 0;
for (nodes) |child| { for (nodes) |child| {
switch (child.id) { switch (child.id) {
.VarDecl => { .VarDecl => {
@ -227,7 +226,6 @@ pub fn getChildOfSlice(tree: *ast.Tree, nodes: []*ast.Node, name: []const u8) ?*
}, },
else => {}, else => {},
} }
// index += 1;
} }
return null; return null;
} }
@ -386,9 +384,7 @@ pub fn getFieldAccessTypeNode(analysis_ctx: *AnalysisContext, tokenizer: *std.zi
while (true) { while (true) {
var next = tokenizer.next(); var next = tokenizer.next();
switch (next.id) { switch (next.id) {
.Eof => { .Eof => return current_node,
return current_node;
},
.Identifier => { .Identifier => {
const identifier = std.mem.dupe(&analysis_ctx.arena.allocator, u8, tokenizer.buffer[next.start..next.end]) catch return null; const identifier = std.mem.dupe(&analysis_ctx.arena.allocator, u8, tokenizer.buffer[next.start..next.end]) catch return null;
if (getChildOfSlice(analysis_ctx.tree, analysis_ctx.scope_nodes, identifier)) |child| { if (getChildOfSlice(analysis_ctx.tree, analysis_ctx.scope_nodes, identifier)) |child| {
@ -409,9 +405,7 @@ pub fn getFieldAccessTypeNode(analysis_ctx: *AnalysisContext, tokenizer: *std.zi
} else return null; } else return null;
} }
}, },
else => { else => std.debug.warn("Not implemented; {}\n", .{next.id}),
std.debug.warn("Not implemented; {}\n", .{next.id});
},
} }
} }
@ -481,11 +475,11 @@ pub fn declsFromIndexInternal(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree,
} }
}, },
.VarDecl, .ParamDecl => try decls.append(node), .VarDecl, .ParamDecl => try decls.append(node),
else => try getCompletionsFromNode(decls, tree, node), else => try addChildrenNodes(decls, tree, node),
} }
} }
pub fn getCompletionsFromNode(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree, node: *ast.Node) !void { pub fn addChildrenNodes(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree, node: *ast.Node) !void {
var index: usize = 0; var index: usize = 0;
while (node.iterate(index)) |child_node| : (index += 1) { while (node.iterate(index)) |child_node| : (index += 1) {
try decls.append(child_node); try decls.append(child_node);
@ -495,7 +489,7 @@ pub fn getCompletionsFromNode(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree,
pub fn declsFromIndex(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree, index: usize) !void { pub fn declsFromIndex(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree, index: usize) !void {
var node = &tree.root_node.base; var node = &tree.root_node.base;
try getCompletionsFromNode(decls, tree, node); try addChildrenNodes(decls, tree, node);
var node_index: usize = 0; var node_index: usize = 0;
while (node.iterate(node_index)) |inode| : (node_index += 1) { 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 (tree.tokens.at(inode.firstToken()).start < index and index < tree.tokens.at(inode.lastToken()).end) {

View File

@ -259,7 +259,7 @@ pub const AnalysisContext = struct {
fn refreshScopeNodes(self: *AnalysisContext) !void { fn refreshScopeNodes(self: *AnalysisContext) !void {
var scope_nodes = std.ArrayList(*std.zig.ast.Node).init(&self.arena.allocator); var scope_nodes = std.ArrayList(*std.zig.ast.Node).init(&self.arena.allocator);
try analysis.getCompletionsFromNode(&scope_nodes, self.tree, &self.tree.root_node.base); try analysis.addChildrenNodes(&scope_nodes, self.tree, &self.tree.root_node.base);
self.scope_nodes = scope_nodes.items; self.scope_nodes = scope_nodes.items;
} }