Skip to content

Commit

Permalink
Separate argument placeholder completions from enable_snippets to `…
Browse files Browse the repository at this point in the history
…enable_argument_placeholders` option [fixes zigtools#685]
  • Loading branch information
peteruhnak committed Oct 9, 2022
1 parent f204f34 commit b556a07
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ The following options are currently available.
| Option | Type | Default value | What it Does |
| --- | --- | --- | --- |
| `enable_snippets` | `bool` | `false` | Enables snippet completions when the client also supports them. |
| `enable_argument_placeholders` | `bool` | `false` | Enabes argument placeholder completions, e.g. `@intCast` completes to `@intCast(comptime DestType: type, int: anytype)` instead of `@intCast()`. |
| `enable_ast_check_diagnostics` | `bool` | `true`| Whether to enable ast-check diagnostics |
| `enable_autofix` | `bool` | `false`| Whether to automatically fix errors on save. Currently supports adding and removing discards. |
| `enable_import_embedfile_argument_completions` | `bool` | `false` | Whether to enable import/embedFile argument completions |
Expand Down
3 changes: 3 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"type": "boolean",
"default": "false"
},
"enable_argument_placeholders": {
"description": "Enabes argument placeholder completions, e.g. `@intCast` completes to `@intCast(comptime DestType: type, int: anytype)` instead of `@intCast()`"
},
"enable_ast_check_diagnostics": {
"description": "Whether to enable ast-check diagnostics",
"type": "boolean",
Expand Down
3 changes: 3 additions & 0 deletions src/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const logger = std.log.scoped(.config);
/// Whether to enable snippet completions
enable_snippets: bool = false,

/// Whether to enable argument placeholder completions
enable_argument_placeholders: bool = false,

/// Whether to enable ast-check diagnostics
enable_ast_check_diagnostics: bool = true,

Expand Down
10 changes: 5 additions & 5 deletions src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ fn nodeToCompletion(
var buf: [1]Ast.Node.Index = undefined;
const func = ast.fnProto(tree, node, &buf).?;
if (func.name_token) |name_token| {
const use_snippets = server.config.enable_snippets and server.client_capabilities.supports_snippets;
const insert_text = if (use_snippets) blk: {
const use_placeholders = server.config.enable_argument_placeholders and server.client_capabilities.supports_snippets;
const insert_text = if (use_placeholders) blk: {
const skip_self_param = !(parent_is_type_val orelse true) and
try analysis.hasSelfParam(&server.arena, &server.document_store, handle, func);
break :blk try analysis.getFunctionSnippet(server.arena.allocator(), tree, func, skip_self_param);
Expand All @@ -517,7 +517,7 @@ fn nodeToCompletion(
.documentation = doc,
.detail = analysis.getFunctionSignature(handle.tree, func),
.insertText = insert_text,
.insertTextFormat = if (use_snippets) .Snippet else .PlainText,
.insertTextFormat = if (use_placeholders) .Snippet else .PlainText,
});
}
},
Expand Down Expand Up @@ -2542,14 +2542,14 @@ pub fn init(
errdefer builtin_completions.deinit();

for (data.builtins) |builtin| {
const insert_text = if (config.enable_snippets) builtin.snippet else builtin.name;
const insert_text = if (config.enable_argument_placeholders) builtin.snippet else builtin.name;
builtin_completions.appendAssumeCapacity(.{
.label = builtin.name,
.kind = .Function,
.filterText = builtin.name[1..],
.detail = builtin.signature,
.insertText = if (config.include_at_in_builtins) insert_text else insert_text[1..],
.insertTextFormat = if (config.enable_snippets) .Snippet else .PlainText,
.insertTextFormat = if (config.enable_argument_placeholders) .Snippet else .PlainText,
.documentation = .{
.kind = .Markdown,
.value = builtin.documentation,
Expand Down
2 changes: 2 additions & 0 deletions src/setup.zig
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ pub fn wizard(allocator: std.mem.Allocator) !void {

const editor = try askSelectOne("Which code editor do you use?", enum { VSCode, Sublime, Kate, Neovim, Vim8, Emacs, Doom, Spacemacs, Helix, Other });
const snippets = try askBool("Do you want to enable snippets?");
const placeholders = try askBool("Do you want to enable argument placeholders?");
const ast_check = try askBool("Do you want to enable ast-check diagnostics?");
const autofix = try askBool("Do you want to zls to automatically try to fix errors on save? (supports adding & removing discards)");
const ief_apc = try askBool("Do you want to enable @import/@embedFile argument path completion?");
Expand All @@ -193,6 +194,7 @@ pub fn wizard(allocator: std.mem.Allocator) !void {
.@"$schema" = "https://raw.githubusercontent.com/zigtools/zls/master/schema.json",
.zig_exe_path = zig_exe_path,
.enable_snippets = snippets,
.enable_argument_placeholders = placeholders,
.enable_ast_check_diagnostics = ast_check,
.enable_autofix = autofix,
.enable_import_embedfile_argument_completions = ief_apc,
Expand Down

0 comments on commit b556a07

Please sign in to comment.