Skip to content

Commit

Permalink
remove unnecessary config options (#1467)
Browse files Browse the repository at this point in the history
`enable_import_embedfile_argument_completions` existed because this
option has been buggy in the past but not anymore.

`include_at_in_builtins` is a workaround for builtin completions in
sublime text 3 which can instead be detected by
inspecting the `clientInfo` field in initialize request.

`max_detail_length` is a workaround for long completion detail entries
bricking the preview window in Sublime Text #261 which can also be
detected through the `clientInfo` field.

`operator_completions` this option has been added when
this feature was implemented but is there anyone who needs it?
  • Loading branch information
Techatrix authored Oct 1, 2023
1 parent 3b71890 commit 8d5eb78
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 90 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ The following options are currently available.
| `enable_ast_check_diagnostics` | `bool` | `true` | Whether to enable ast-check diagnostics |
| `enable_build_on_save` | `bool` | `false` | Whether to enable build-on-save diagnostics |
| `enable_autofix` | `bool` | `true` | Whether to automatically fix errors on save. Currently supports adding and removing discards. |
| `enable_import_embedfile_argument_completions` | `bool` | `true` | Whether to enable import/embedFile argument completions |
| `semantic_tokens` | `enum` | `.full` | Set level of semantic tokens. Partial only includes information that requires semantic analysis. |
| `enable_inlay_hints` | `bool` | `true` | Enables inlay hint support when the client also supports it |
| `inlay_hints_show_variable_declaration` | `bool` | `true` | Enable inlay hints for variable declarations |
Expand All @@ -70,13 +69,10 @@ The following options are currently available.
| `inlay_hints_exclude_single_argument` | `bool` | `true` | Don't show inlay hints for single argument calls |
| `inlay_hints_hide_redundant_param_names` | `bool` | `false` | Hides inlay hints when parameter name matches the identifier (e.g. foo: foo) |
| `inlay_hints_hide_redundant_param_names_last_token` | `bool` | `false` | Hides inlay hints when parameter name matches the last token of a parameter node (e.g. foo: bar.foo, foo: &foo) |
| `operator_completions` | `bool` | `true` | Enables `*` and `?` operators in completion lists |
| `warn_style` | `bool` | `false` | Enables warnings for style guideline mismatches |
| `highlight_global_var_declarations` | `bool` | `false` | Whether to highlight global var declarations |
| `dangerous_comptime_experiments_do_not_enable` | `bool` | `false` | Whether to use the comptime interpreter |
| `include_at_in_builtins` | `bool` | `false` | Whether the @ sign should be part of the completion of builtins |
| `skip_std_references` | `bool` | `false` | When true, skips searching for references in std. Improves lookup speed for functions in user's code. Renaming and go-to-definition will continue to work as is |
| `max_detail_length` | `usize` | `1048576` | The detail field of completions is truncated to be no longer than this (in bytes) |
| `prefer_ast_check_as_child_process` | `bool` | `true` | Can be used in conjuction with `enable_ast_check_diagnostics` to favor using `zig ast-check` instead of ZLS's fork |
| `record_session` | `bool` | `false` | When true, zls will record all request is receives and write in into `record_session_path`, so that they can replayed with `zls replay` |
| `record_session_path` | `?[]const u8` | `null` | Output file path when `record_session` is set. The recommended file extension *.zlsreplay |
Expand Down
20 changes: 0 additions & 20 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
"type": "boolean",
"default": "true"
},
"enable_import_embedfile_argument_completions": {
"description": "Whether to enable import/embedFile argument completions",
"type": "boolean",
"default": "true"
},
"semantic_tokens": {
"description": "Set level of semantic tokens. Partial only includes information that requires semantic analysis.",
"type": "string",
Expand Down Expand Up @@ -79,11 +74,6 @@
"type": "boolean",
"default": "false"
},
"operator_completions": {
"description": "Enables `*` and `?` operators in completion lists",
"type": "boolean",
"default": "true"
},
"warn_style": {
"description": "Enables warnings for style guideline mismatches",
"type": "boolean",
Expand All @@ -99,21 +89,11 @@
"type": "boolean",
"default": "false"
},
"include_at_in_builtins": {
"description": "Whether the @ sign should be part of the completion of builtins",
"type": "boolean",
"default": "false"
},
"skip_std_references": {
"description": "When true, skips searching for references in std. Improves lookup speed for functions in user's code. Renaming and go-to-definition will continue to work as is",
"type": "boolean",
"default": "false"
},
"max_detail_length": {
"description": "The detail field of completions is truncated to be no longer than this (in bytes)",
"type": "integer",
"default": "1048576"
},
"prefer_ast_check_as_child_process": {
"description": "Can be used in conjuction with `enable_ast_check_diagnostics` to favor using `zig ast-check` instead of ZLS's fork",
"type": "boolean",
Expand Down
12 changes: 0 additions & 12 deletions src/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ enable_build_on_save: bool = false,
/// Whether to automatically fix errors on save. Currently supports adding and removing discards.
enable_autofix: bool = true,

/// Whether to enable import/embedFile argument completions
enable_import_embedfile_argument_completions: bool = true,

/// Set level of semantic tokens. Partial only includes information that requires semantic analysis.
semantic_tokens: enum {
none,
Expand Down Expand Up @@ -50,9 +47,6 @@ inlay_hints_hide_redundant_param_names: bool = false,
/// Hides inlay hints when parameter name matches the last token of a parameter node (e.g. foo: bar.foo, foo: &foo)
inlay_hints_hide_redundant_param_names_last_token: bool = false,

/// Enables `*` and `?` operators in completion lists
operator_completions: bool = true,

/// Enables warnings for style guideline mismatches
warn_style: bool = false,

Expand All @@ -62,15 +56,9 @@ highlight_global_var_declarations: bool = false,
/// Whether to use the comptime interpreter
dangerous_comptime_experiments_do_not_enable: bool = false,

/// Whether the @ sign should be part of the completion of builtins
include_at_in_builtins: bool = false,

/// When true, skips searching for references in std. Improves lookup speed for functions in user's code. Renaming and go-to-definition will continue to work as is
skip_std_references: bool = false,

/// The detail field of completions is truncated to be no longer than this (in bytes)
max_detail_length: usize = 1048576,

/// Can be used in conjuction with `enable_ast_check_diagnostics` to favor using `zig ast-check` instead of ZLS's fork
prefer_ast_check_as_child_process: bool = true,

Expand Down
10 changes: 8 additions & 2 deletions src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ const ClientCapabilities = struct {
supports_configuration: bool = false,
supports_workspace_did_change_configuration_dynamic_registration: bool = false,
supports_textDocument_definition_linkSupport: bool = false,
/// workaround for builtin completion in Sublime Text 3
include_at_in_builtins: bool = false,
/// The detail entries for big structs such as std.zig.CrossTarget were
/// bricking the preview window in Sublime Text.
/// https://github.com/zigtools/zls/pull/261
max_detail_length: u32 = 1024 * 1024,
workspace_folders: []types.URI = &.{},

fn deinit(self: *ClientCapabilities, allocator: std.mem.Allocator) void {
Expand Down Expand Up @@ -355,7 +361,7 @@ fn initializeHandler(server: *Server, _: std.mem.Allocator, request: types.Initi
log.info("client is '{s}-{s}'", .{ clientInfo.name, clientInfo.version orelse "<no version>" });

if (std.mem.eql(u8, clientInfo.name, "Sublime Text LSP")) blk: {
server.config.max_detail_length = 256;
server.client_capabilities.max_detail_length = 256;
// TODO investigate why fixall doesn't work in sublime text
server.client_capabilities.supports_code_action_fixall = false;
skip_set_fixall = true;
Expand All @@ -365,7 +371,7 @@ fn initializeHandler(server: *Server, _: std.mem.Allocator, request: types.Initi
// this indicates a LSP version for sublime text 3
// this check can be made more precise if the version that fixed this issue is known
if (version.major == 0) {
server.config.include_at_in_builtins = true;
server.client_capabilities.include_at_in_builtins = true;
}
} else if (std.mem.eql(u8, clientInfo.name, "Visual Studio Code")) {
server.client_capabilities.supports_code_action_fixall = true;
Expand Down
24 changes: 0 additions & 24 deletions src/config_gen/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
"type": "bool",
"default": "true"
},
{
"name": "enable_import_embedfile_argument_completions",
"description": "Whether to enable import/embedFile argument completions",
"type": "bool",
"default": "true"
},
{
"name": "semantic_tokens",
"description": "Set level of semantic tokens. Partial only includes information that requires semantic analysis.",
Expand Down Expand Up @@ -89,12 +83,6 @@
"type": "bool",
"default": "false"
},
{
"name": "operator_completions",
"description": "Enables `*` and `?` operators in completion lists",
"type": "bool",
"default": "true"
},
{
"name": "warn_style",
"description": "Enables warnings for style guideline mismatches",
Expand All @@ -113,24 +101,12 @@
"type": "bool",
"default": "false"
},
{
"name": "include_at_in_builtins",
"description": "Whether the @ sign should be part of the completion of builtins",
"type": "bool",
"default": "false"
},
{
"name": "skip_std_references",
"description": "When true, skips searching for references in std. Improves lookup speed for functions in user's code. Renaming and go-to-definition will continue to work as is",
"type": "bool",
"default": "false"
},
{
"name": "max_detail_length",
"description": "The detail field of completions is truncated to be no longer than this (in bytes)",
"type": "usize",
"default": "1048576"
},
{
"name": "prefer_ast_check_as_child_process",
"description": "Can be used in conjuction with `enable_ast_check_diagnostics` to favor using `zig ast-check` instead of ZLS's fork",
Expand Down
47 changes: 19 additions & 28 deletions src/features/completions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ fn typeToCompletion(
}
},
.pointer => |t| {
if (server.config.operator_completions) {
try list.append(arena, .{
.label = "*",
.kind = .Operator,
.insertText = "*",
.insertTextFormat = .PlainText,
});
}
try list.append(arena, .{
.label = "*",
.kind = .Operator,
.insertText = "*",
.insertTextFormat = .PlainText,
});
try typeToCompletion(server, analyser, arena, list, .{ .original = t.* }, orig_handle, null);
},
.other => |n| try nodeToCompletion(
Expand Down Expand Up @@ -305,7 +303,7 @@ fn nodeToCompletion(
const ptr_type = ast.fullPtrType(tree, node).?;

switch (ptr_type.size) {
.One, .C, .Many => if (server.config.operator_completions) {
.One, .C, .Many => {
try list.append(arena, .{
.label = "*",
.kind = .Operator,
Expand Down Expand Up @@ -337,15 +335,12 @@ fn nodeToCompletion(
return;
},
.optional_type => {
if (server.config.operator_completions) {
try list.append(arena, .{
.label = "?",
.kind = .Operator,
.insertText = "?",
.insertTextFormat = .PlainText,
});
}
return;
try list.append(arena, .{
.label = "?",
.kind = .Operator,
.insertText = "?",
.insertTextFormat = .PlainText,
});
},
.multiline_string_literal,
.string_literal,
Expand Down Expand Up @@ -537,7 +532,7 @@ fn completeBuiltin(server: *Server, arena: std.mem.Allocator) error{OutOfMemory}
.kind = .Function,
.filterText = builtin.name[1..],
.detail = builtin.signature,
.insertText = if (server.config.include_at_in_builtins) insert_text else insert_text[1..],
.insertText = if (server.client_capabilities.include_at_in_builtins) insert_text else insert_text[1..],
.insertTextFormat = if (use_snippets) .Snippet else .PlainText,
.documentation = .{
.MarkupContent = .{
Expand Down Expand Up @@ -1442,13 +1437,9 @@ pub fn completionAtIndex(server: *Server, analyser: *Analyser, arena: std.mem.Al
.import_string_literal,
.cinclude_string_literal,
.embedfile_string_literal,
=> blk: {
if (!server.config.enable_import_embedfile_argument_completions) break :blk null;

break :blk completeFileSystemStringLiteral(arena, server.document_store, handle.*, pos_context) catch |err| {
log.err("failed to get file system completions: {}", .{err});
return null;
};
=> completeFileSystemStringLiteral(arena, server.document_store, handle.*, pos_context) catch |err| {
log.err("failed to get file system completions: {}", .{err});
return null;
},
else => null,
};
Expand Down Expand Up @@ -1490,8 +1481,8 @@ pub fn completionAtIndex(server: *Server, analyser: *Analyser, arena: std.mem.Al
// truncate completions
for (completions) |*item| {
if (item.detail) |det| {
if (det.len > server.config.max_detail_length) {
item.detail = det[0..server.config.max_detail_length];
if (det.len > server.client_capabilities.max_detail_length) {
item.detail = det[0..server.client_capabilities.max_detail_length];
}
}
}
Expand Down

0 comments on commit 8d5eb78

Please sign in to comment.