Merge pull request #260 from InterplanetaryEngineer/master

Add option for builtin completion insert text
This commit is contained in:
Alexandros Naskos 2021-03-26 11:32:01 +02:00 committed by GitHub
commit 2a57789be8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 7 deletions

View File

@ -55,11 +55,26 @@ pub fn config(step: *std.build.Step) anyerror!void {
} else { } else {
std.debug.print("Found zig executable '{s}'\n", .{zig_exe_path.?}); 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 snippets = try zinput.askBool("Do you want to enable snippets?");
const style = try zinput.askBool("Do you want to enable style warnings?"); 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 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, .{}); var dir = try std.fs.cwd().openDir(builder.exe_dir, .{});
defer dir.close(); defer dir.close();
@ -76,11 +91,10 @@ pub fn config(step: *std.build.Step) anyerror!void {
.warn_style = style, .warn_style = style,
.enable_semantic_tokens = semantic_tokens, .enable_semantic_tokens = semantic_tokens,
.operator_completions = operator_completions, .operator_completions = operator_completions,
.include_at_in_builtins = include_at_in_builtins,
}, std.json.StringifyOptions{}, out); }, std.json.StringifyOptions{}, out);
std.debug.warn("Successfully saved configuration options!\n", .{}); 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", .{}); std.debug.warn("\n", .{});
switch (editor) { switch (editor) {

View File

@ -26,6 +26,9 @@ enable_semantic_tokens: bool = true,
/// Whether to enable `*` and `?` operators in completion lists /// Whether to enable `*` and `?` operators in completion lists
operator_completions: bool = true, 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. /// Skips references to std. This will improve lookup speeds.
/// Going to definition however will continue to work /// Going to definition however will continue to work
skip_std_references: bool = false, skip_std_references: bool = false,

View File

@ -1026,15 +1026,21 @@ fn completeBuiltin(arena: *std.heap.ArenaAllocator, id: types.RequestId, config:
}, },
}; };
var insert_text: []const u8 = undefined;
if (config.enable_snippets) { if (config.enable_snippets) {
builtin_completions.?[idx].insertText = builtin.snippet[1..]; insert_text = builtin.snippet;
builtin_completions.?[idx].insertTextFormat = .Snippet; builtin_completions.?[idx].insertTextFormat = .Snippet;
} else { } 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{ try send(arena, types.Response{
.id = id, .id = id,
.result = .{ .result = .{