From a2620d7f6989d9f519ca1fb19ac22171eef7bf31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20H=C3=A4hne?= Date: Fri, 26 Mar 2021 10:20:20 +0100 Subject: [PATCH] Add option for builtin completion insert text --- build.zig | 22 ++++++++++++++++++---- src/config.zig | 3 +++ src/main.zig | 12 +++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index 799ecf3..69ff75d 100644 --- a/build.zig +++ b/build.zig @@ -55,11 +55,26 @@ pub fn config(step: *std.build.Step) anyerror!void { } else { std.debug.print("Found zig executable '{s}'\n", .{zig_exe_path.?}); } + + const editor = try zinput.askSelectOne("Which code editor do you use?", enum { VSCode, Sublime, Kate, Neovim, Vim8, Emacs, Doom, Other }); const snippets = try zinput.askBool("Do you want to enable snippets?"); const style = try zinput.askBool("Do you want to enable style warnings?"); const semantic_tokens = try zinput.askBool("Do you want to enable semantic highlighting?"); - const operator_completions = try zinput.askBool("Do you want to enable .* and .? completions"); - + const operator_completions = try zinput.askBool("Do you want to enable .* and .? completions?"); + const include_at_in_builtins = switch (editor) { + .Sublime => + true, + .VSCode, + .Kate, + .Neovim, + .Vim8, + .Emacs, + .Doom => + false, + else => + try zinput.askBool("Should the @ sign be included in completions of builtin functions?\nChange this later if `@inc` completes to `include` or `@@include`") + }; + var dir = try std.fs.cwd().openDir(builder.exe_dir, .{}); defer dir.close(); @@ -76,11 +91,10 @@ pub fn config(step: *std.build.Step) anyerror!void { .warn_style = style, .enable_semantic_tokens = semantic_tokens, .operator_completions = operator_completions, + .include_at_in_builtins = include_at_in_builtins, }, std.json.StringifyOptions{}, out); std.debug.warn("Successfully saved configuration options!\n", .{}); - - const editor = try zinput.askSelectOne("Which code editor do you use?", enum { VSCode, Sublime, Kate, Neovim, Vim8, Emacs, Doom, Other }); std.debug.warn("\n", .{}); switch (editor) { diff --git a/src/config.zig b/src/config.zig index fe224e2..93a92d3 100644 --- a/src/config.zig +++ b/src/config.zig @@ -26,6 +26,9 @@ enable_semantic_tokens: bool = true, /// Whether to enable `*` and `?` operators in completion lists operator_completions: bool = true, +/// Whether the @ sign should be part of the completion of builtins +include_at_in_builtins: bool = false, + /// Skips references to std. This will improve lookup speeds. /// Going to definition however will continue to work skip_std_references: bool = false, diff --git a/src/main.zig b/src/main.zig index a9c60bb..86d2026 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1026,15 +1026,21 @@ fn completeBuiltin(arena: *std.heap.ArenaAllocator, id: types.RequestId, config: }, }; + var insert_text: []const u8 = undefined; if (config.enable_snippets) { - builtin_completions.?[idx].insertText = builtin.snippet[1..]; + insert_text = builtin.snippet; builtin_completions.?[idx].insertTextFormat = .Snippet; } else { - builtin_completions.?[idx].insertText = builtin.name[1..]; + insert_text = builtin.name; } + builtin_completions.?[idx].insertText = + if (config.include_at_in_builtins) + insert_text + else + insert_text[1..]; } } - + try send(arena, types.Response{ .id = id, .result = .{