diff --git a/src/analysis.zig b/src/analysis.zig index 0ce83b9..94d497d 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -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; } diff --git a/src/main.zig b/src/main.zig index 51051f2..e47285b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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; }