From 6057d290b4f4fcd772426a9e4c6e361cb0179d35 Mon Sep 17 00:00:00 2001 From: rhysd Date: Mon, 15 Mar 2021 20:16:16 +0900 Subject: [PATCH] Fix falsy value for filterText and insertText 'filterText' and 'insertText' fields of 'CompletionItem' can only have "" or undefined as falsy value. https://github.com/microsoft/language-server-protocol/issues/1222 --- src/main.zig | 2 +- src/types.zig | 4 ++-- tests/sessions.zig | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.zig b/src/main.zig index 6d99c02..a9c60bb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -415,7 +415,7 @@ fn nodeToCompletion( } else false; break :blk try analysis.getFunctionSnippet(&arena.allocator, tree, func, skip_self_param); - } else null; + } else ""; const is_type_function = analysis.isTypeFunction(handle.tree, func); diff --git a/src/types.zig b/src/types.zig index bd13ef1..13633a3 100644 --- a/src/types.zig +++ b/src/types.zig @@ -230,8 +230,8 @@ pub const CompletionItem = struct { label: []const u8, kind: Kind, textEdit: ?TextEdit = null, - filterText: ?[]const u8 = null, - insertText: ?[]const u8 = null, + filterText: []const u8 = "", + insertText: []const u8 = "", insertTextFormat: ?InsertTextFormat = .PlainText, detail: ?[]const u8 = null, documentation: ?MarkupContent = null, diff --git a/tests/sessions.zig b/tests/sessions.zig index 0ba3a4b..dce35e9 100644 --- a/tests/sessions.zig +++ b/tests/sessions.zig @@ -138,7 +138,7 @@ test "Requesting a completion with no trailing whitespace" { try sendRequest(completion_req, process); try sendRequest(shutdown_message, process); try consumeOutputAndWait(process, .{ - \\{"jsonrpc":"2.0","id":2,"result":{"isIncomplete":false,"items":[{"label":"std","kind":21,"textEdit":null,"filterText":null,"insertText":null,"insertTextFormat":1,"detail":"const std = @import(\"std\")","documentation":null}]}} + \\{"jsonrpc":"2.0","id":2,"result":{"isIncomplete":false,"items":[{"label":"std","kind":21,"textEdit":null,"filterText":"","insertText":"","insertTextFormat":1,"detail":"const std = @import(\"std\")","documentation":null}]}} }); }