Skip to content

Commit

Permalink
Merge pull request #1795 from zigtools/techatrix/completion-insert-re…
Browse files Browse the repository at this point in the history
…place

use client capability for insert/replace code completions
  • Loading branch information
llogick authored Feb 29, 2024
2 parents 2720509 + 8a4e6c7 commit a4c13e6
Show file tree
Hide file tree
Showing 8 changed files with 1,046 additions and 488 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ The following options are currently available.
| `build_runner_path` | `?[]const u8` | `null` | Path to the `build_runner.zig` file provided by zls. null is equivalent to `${executable_directory}/build_runner.zig` |
| `global_cache_path` | `?[]const u8` | `null` | Path to a directory that will be used as zig's cache. null is equivalent to `${KnownFolders.Cache}/zls` |
| `build_runner_global_cache_path` | `?[]const u8` | `null` | Path to a directory that will be used as the global cache path when executing a projects build.zig. null is equivalent to the path shown by `zig env` |
| `completions_with_replace` | `bool` | `true` | Completions confirm behavior. If 'true', replace the text after the cursor |
| `completion_label_details` | `bool` | `true` | When false, the function signature of completion results is hidden. Improves readability in some editors |
<!-- DO NOT EDIT -->

Expand Down
5 changes: 0 additions & 5 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@
"type": "string",
"default": null
},
"completions_with_replace": {
"description": "Completions confirm behavior. If 'true', replace the text after the cursor",
"type": "boolean",
"default": true
},
"completion_label_details": {
"description": "When false, the function signature of completion results is hidden. Improves readability in some editors",
"type": "boolean",
Expand Down
3 changes: 0 additions & 3 deletions src/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ global_cache_path: ?[]const u8 = null,
/// Path to a directory that will be used as the global cache path when executing a projects build.zig. null is equivalent to the path shown by `zig env`
build_runner_global_cache_path: ?[]const u8 = null,

/// Completions confirm behavior. If 'true', replace the text after the cursor
completions_with_replace: bool = true,

/// When false, the function signature of completion results is hidden. Improves readability in some editors
completion_label_details: bool = true,

Expand Down
14 changes: 3 additions & 11 deletions src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const ClientCapabilities = struct {
hover_supports_md: bool = false,
signature_help_supports_md: bool = false,
completion_doc_supports_md: bool = false,
supports_completion_insert_replace_support: bool = false,
/// deprecated can be marked through the `CompletionItem.deprecated` field
supports_completion_deprecated_old: bool = false,
/// deprecated can be marked through the `CompletionItem.tags` field
Expand All @@ -77,8 +78,6 @@ 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
Expand Down Expand Up @@ -375,19 +374,11 @@ fn initializeHandler(server: *Server, _: std.mem.Allocator, request: types.Initi
if (request.clientInfo) |clientInfo| {
log.info("client is '{s}-{s}'", .{ clientInfo.name, clientInfo.version orelse "<no version>" });

if (std.mem.eql(u8, clientInfo.name, "Sublime Text LSP")) blk: {
if (std.mem.eql(u8, clientInfo.name, "Sublime Text LSP")) {
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;

const version_str = clientInfo.version orelse break :blk;
const version = std.SemanticVersion.parse(version_str) catch break :blk;
// 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.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;
skip_set_fixall = true;
Expand Down Expand Up @@ -438,6 +429,7 @@ fn initializeHandler(server: *Server, _: std.mem.Allocator, request: types.Initi
server.client_capabilities.label_details_support = completionItem.labelDetailsSupport orelse false;
server.client_capabilities.supports_snippets = completionItem.snippetSupport orelse false;
server.client_capabilities.supports_completion_deprecated_old = completionItem.deprecatedSupport orelse false;
server.client_capabilities.supports_completion_insert_replace_support = completionItem.insertReplaceSupport orelse false;
if (completionItem.tagSupport) |tagSupport| {
for (tagSupport.valueSet) |tag| {
switch (tag) {
Expand Down
6 changes: 0 additions & 6 deletions src/config_gen/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,6 @@
"type": "?[]const u8",
"default": null
},
{
"name": "completions_with_replace",
"description": "Completions confirm behavior. If 'true', replace the text after the cursor",
"type": "bool",
"default": true
},
{
"name": "completion_label_details",
"description": "When false, the function signature of completion results is hidden. Improves readability in some editors",
Expand Down
Loading

0 comments on commit a4c13e6

Please sign in to comment.