fix field access type

This commit is contained in:
SuperAuguste 2020-05-14 12:14:35 -04:00
parent 353c9b3261
commit 40235cbdbb
2 changed files with 31 additions and 3 deletions

View File

@ -341,12 +341,38 @@ pub fn getFieldAccessTypeNode(analysis_ctx: *AnalysisContext, tokenizer: *std.zi
return current_node;
}
pub fn isPublic(tree: *ast.Tree, node: *ast.Node) bool {
switch (node.id) {
.VarDecl => {
const var_decl = node.cast(ast.Node.VarDecl).?;
if (var_decl.visib_token) |visib_token| {
return std.mem.eql(u8, tree.tokenSlice(visib_token), "pub");
} else return false;
},
.FnProto => {
const func = node.cast(ast.Node.FnProto).?;
if (func.visib_token) |visib_token| {
return std.mem.eql(u8, tree.tokenSlice(visib_token), "pub");
} else return false;
},
.ContainerField => {
return true;
},
else => {
return false;
}
}
return false;
}
pub fn getCompletionsFromNode(allocator: *std.mem.Allocator, tree: *ast.Tree, node: *ast.Node) ![]*ast.Node {
var nodes = std.ArrayList(*ast.Node).init(allocator);
var index: usize = 0;
while (node.iterate(index)) |child_node| {
try nodes.append(child_node);
if (isPublic(tree, node))
try nodes.append(child_node);
index += 1;
}

View File

@ -277,8 +277,10 @@ fn completeFieldAccess(id: i64, handle: *DocumentStore.Handle, position: types.P
if (analysis.getFieldAccessTypeNode(&analysis_ctx, &tokenizer)) |node| {
var index: usize = 0;
while (node.iterate(index)) |child_node| {
if (try nodeToCompletion(&arena.allocator, analysis_ctx.tree, child_node, config)) |completion| {
try completions.append(completion);
if (analysis.isPublic(analysis_ctx.tree, child_node)) {
if (try nodeToCompletion(&arena.allocator, analysis_ctx.tree, child_node, config)) |completion| {
try completions.append(completion);
}
}
index += 1;
}