From 4b042a562a47a9bd6789bc8b5001392c02159c72 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Mon, 13 Mar 2023 21:41:32 +0100 Subject: [PATCH] exclude default cimport declarations from completions --- src/features/completions.zig | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/features/completions.zig b/src/features/completions.zig index 50bcbf4..29f05ca 100644 --- a/src/features/completions.zig +++ b/src/features/completions.zig @@ -330,7 +330,23 @@ fn declToCompletion(context: DeclToCompletionContext, decl_handle: Analyser.Decl const tree = decl_handle.handle.tree; const decl = decl_handle.decl.*; - switch (decl) { + const is_cimport = std.mem.eql(u8, std.fs.path.basename(decl_handle.handle.uri), "cimport.zig"); + if (is_cimport) { + const name = tree.tokenSlice(decl_handle.nameToken()); + if (std.mem.startsWith(u8, name, "_")) return; + // TODO figuring out which declarations should be excluded could be made more complete and accurate + // by translating an empty file to acquire all exclusions + const exclusions = std.ComptimeStringMap(void, .{ + .{ "linux", {} }, + .{ "unix", {} }, + .{ "WIN32", {} }, + .{ "WINNT", {} }, + .{ "WIN64", {} }, + }); + if (exclusions.has("name")) return; + } + + switch (decl_handle.decl.*) { .ast_node => |node| try nodeToCompletion( context.server, context.completions,