From 7f12928fe926e1991ea79e0c01746041916f17ac Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Sun, 14 Jun 2020 13:03:14 +0300 Subject: [PATCH] Dont show fields in global completions and from usingnamespaced scopes --- src/analysis.zig | 7 +++++-- src/main.zig | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index 1dc409c..125bf12 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -1209,6 +1209,7 @@ pub fn iterateSymbolsContainer( orig_handle: *DocumentStore.Handle, comptime callback: var, context: var, + include_fields: bool, ) error{OutOfMemory}!void { const container = container_handle.node; const handle = container_handle.handle; @@ -1216,6 +1217,7 @@ pub fn iterateSymbolsContainer( if (findContainerScope(container_handle)) |container_scope| { var decl_it = container_scope.decls.iterator(); while (decl_it.next()) |entry| { + if (!include_fields and entry.value == .ast_node and entry.value.ast_node.id == .ContainerField) continue; const decl = DeclWithHandle{ .decl = &entry.value, .handle = handle }; if (handle != orig_handle and !decl.isPublic()) continue; try callback(context, decl); @@ -1224,7 +1226,7 @@ pub fn iterateSymbolsContainer( for (container_scope.uses) |use| { if (handle != orig_handle and use.visib_token == null) continue; const use_expr = (try resolveTypeOfNode(store, arena, .{ .node = use.expr, .handle = handle })) orelse continue; - try iterateSymbolsContainer(store, arena, use_expr, orig_handle, callback, context); + try iterateSymbolsContainer(store, arena, use_expr, orig_handle, callback, context, false); } } @@ -1243,12 +1245,13 @@ pub fn iterateSymbolsGlobal( if (source_index >= scope.range.start and source_index < scope.range.end) { var decl_it = scope.decls.iterator(); while (decl_it.next()) |entry| { + if (entry.value == .ast_node and entry.value.ast_node.id == .ContainerField) continue; try callback(context, DeclWithHandle{ .decl = &entry.value, .handle = handle }); } for (scope.uses) |use| { const use_expr = (try resolveTypeOfNode(store, arena, .{ .node = use.expr, .handle = handle })) orelse continue; - try iterateSymbolsContainer(store, arena, use_expr, handle, callback, context); + try iterateSymbolsContainer(store, arena, use_expr, handle, callback, context, false); } } diff --git a/src/main.zig b/src/main.zig index 056678f..3719a55 100644 --- a/src/main.zig +++ b/src/main.zig @@ -258,7 +258,7 @@ fn nodeToCompletion( .arena = arena, .orig_handle = orig_handle, }; - try analysis.iterateSymbolsContainer(&document_store, arena, node_handle, orig_handle, declToCompletion, context); + try analysis.iterateSymbolsContainer(&document_store, arena, node_handle, orig_handle, declToCompletion, context, true); }, .FnProto => { const func = node.cast(std.zig.ast.Node.FnProto).?;