[PATCH] D38720: [clangd] Report proper kinds for 'Keyword' and 'Snippet' completion items.
Phabricator via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 22 23:06:38 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316311: [clangd] Report proper kinds for 'Keyword' and 'Snippet' completion items. (authored by ibiryukov).
Repository:
rL LLVM
https://reviews.llvm.org/D38720
Files:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -268,8 +268,8 @@
namespace {
-CompletionItemKind getKind(CXCursorKind K) {
- switch (K) {
+CompletionItemKind getKindOfDecl(CXCursorKind CursorKind) {
+ switch (CursorKind) {
case CXCursor_MacroInstantiation:
case CXCursor_MacroDefinition:
return CompletionItemKind::Text;
@@ -311,6 +311,22 @@
}
}
+CompletionItemKind getKind(CodeCompletionResult::ResultKind ResKind,
+ CXCursorKind CursorKind) {
+ switch (ResKind) {
+ case CodeCompletionResult::RK_Declaration:
+ return getKindOfDecl(CursorKind);
+ case CodeCompletionResult::RK_Keyword:
+ return CompletionItemKind::Keyword;
+ case CodeCompletionResult::RK_Macro:
+ return CompletionItemKind::Text; // unfortunately, there's no 'Macro'
+ // completion items in LSP.
+ case CodeCompletionResult::RK_Pattern:
+ return CompletionItemKind::Snippet;
+ }
+ llvm_unreachable("Unhandled CodeCompletionResult::ResultKind.");
+}
+
std::string escapeSnippet(const llvm::StringRef Text) {
std::string Result;
Result.reserve(Text.size()); // Assume '$', '}' and '\\' are rare.
@@ -395,7 +411,7 @@
ProcessChunks(CCS, Item);
// Fill in the kind field of the CompletionItem.
- Item.kind = getKind(Result.CursorKind);
+ Item.kind = getKind(Result.Kind, Result.CursorKind);
FillSortText(CCS, Item);
Index: clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
===================================================================
--- clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
+++ clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
@@ -0,0 +1,37 @@
+# RUN: clangd -enable-snippets -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+Content-Length: 220
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"#define MACRO X\nint variable;\nstruct Struct {};\n int function();\nint X = "}}}
+Content-Length: 148
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":4,"character":7}}}
+Content-Length: 58
+# CHECK: {"jsonrpc":"2.0","id":1,"result":[
+#
+# Keyword
+# CHECK-DAG: {"label":"int","kind":14,"sortText":"000050int","filterText":"int","insertText":"int","insertTextFormat":1}
+#
+# Code pattern
+# CHECK-DAG: {"label":"static_cast<type>(expression)","kind":15,"sortText":"000040static_cast","filterText":"static_cast","insertText":"static_cast<${1:type}>(${2:expression})","insertTextFormat":2}
+#
+# Struct
+# CHECK-DAG: {"label":"Struct","kind":7,"sortText":"000050Struct","filterText":"Struct","insertText":"Struct","insertTextFormat":1}
+#
+# Macro
+# CHECK-DAG: {"label":"MACRO","kind":1,"sortText":"000070MACRO","filterText":"MACRO","insertText":"MACRO","insertTextFormat":1}
+#
+# Variable
+# CHECK-DAG: {"label":"variable","kind":6,"detail":"int","sortText":"000012variable","filterText":"variable","insertText":"variable","insertTextFormat":1}
+#
+# Function
+# CHECK-DAG: {"label":"function()","kind":3,"detail":"int","sortText":"000012function","filterText":"function","insertText":"function()","insertTextFormat":1}
+#
+#
+# CHECK: ]}
+
+{"jsonrpc":"2.0","id":3,"method":"shutdown","params":null}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38720.119812.patch
Type: text/x-patch
Size: 3766 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171023/6275441a/attachment.bin>
More information about the cfe-commits
mailing list