summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-04-11 13:27:15 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-04-11 13:27:15 +0000
commit4714f7cba93b83dca7feb0d4bf13e7b4412c27b3 (patch)
treeacb0e36b2a66bc90197f224771faacbc02c72f9a
parent0df645dda4e72df379be3bd88410e2e7646f7716 (diff)
downloadbcm5719-llvm-4714f7cba93b83dca7feb0d4bf13e7b4412c27b3.tar.gz
bcm5719-llvm-4714f7cba93b83dca7feb0d4bf13e7b4412c27b3.zip
[clangd] Implement item kind for completion results
Summary: The patch implements the conversion method from CXCursorKind to clangd::CompletionItemKind. Contributed by stanionascu! Reviewers: cfe-commits, bkramer, krasimir Reviewed By: krasimir Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D31853 llvm-svn: 299935
-rw-r--r--clang-tools-extra/clangd/ASTManager.cpp47
-rw-r--r--clang-tools-extra/clangd/Protocol.cpp2
-rw-r--r--clang-tools-extra/test/clangd/completion.test6
3 files changed, 50 insertions, 5 deletions
diff --git a/clang-tools-extra/clangd/ASTManager.cpp b/clang-tools-extra/clangd/ASTManager.cpp
index b85d0d8269c..04cbf582bf0 100644
--- a/clang-tools-extra/clangd/ASTManager.cpp
+++ b/clang-tools-extra/clangd/ASTManager.cpp
@@ -76,6 +76,49 @@ static int getSeverity(DiagnosticsEngine::Level L) {
llvm_unreachable("Unknown diagnostic level!");
}
+static CompletionItemKind getKind(CXCursorKind K) {
+ switch (K) {
+ case CXCursor_MacroInstantiation:
+ case CXCursor_MacroDefinition:
+ return CompletionItemKind::Text;
+ case CXCursor_CXXMethod:
+ return CompletionItemKind::Method;
+ case CXCursor_FunctionDecl:
+ case CXCursor_FunctionTemplate:
+ return CompletionItemKind::Function;
+ case CXCursor_Constructor:
+ case CXCursor_Destructor:
+ return CompletionItemKind::Constructor;
+ case CXCursor_FieldDecl:
+ return CompletionItemKind::Field;
+ case CXCursor_VarDecl:
+ case CXCursor_ParmDecl:
+ return CompletionItemKind::Variable;
+ case CXCursor_ClassDecl:
+ case CXCursor_StructDecl:
+ case CXCursor_UnionDecl:
+ case CXCursor_ClassTemplate:
+ case CXCursor_ClassTemplatePartialSpecialization:
+ return CompletionItemKind::Class;
+ case CXCursor_Namespace:
+ case CXCursor_NamespaceAlias:
+ case CXCursor_NamespaceRef:
+ return CompletionItemKind::Module;
+ case CXCursor_EnumConstantDecl:
+ return CompletionItemKind::Value;
+ case CXCursor_EnumDecl:
+ return CompletionItemKind::Enum;
+ case CXCursor_TypeAliasDecl:
+ case CXCursor_TypeAliasTemplateDecl:
+ case CXCursor_TypedefDecl:
+ case CXCursor_MemberRef:
+ case CXCursor_TypeRef:
+ return CompletionItemKind::Reference;
+ default:
+ return CompletionItemKind::Missing;
+ }
+}
+
ASTManager::ASTManager(JSONOutput &Output, DocumentStore &Store,
bool RunSynchronously)
: Output(Output), Store(Store), RunSynchronously(RunSynchronously),
@@ -334,13 +377,15 @@ public:
CodeCompletionResult *Results,
unsigned NumResults) override {
for (unsigned I = 0; I != NumResults; ++I) {
- CodeCompletionString *CCS = Results[I].CreateCodeCompletionString(
+ CodeCompletionResult &Result = Results[I];
+ CodeCompletionString *CCS = Result.CreateCodeCompletionString(
S, Context, *Allocator, CCTUInfo,
CodeCompleteOpts.IncludeBriefComments);
if (CCS) {
CompletionItem Item;
assert(CCS->getTypedText());
Item.label = CCS->getTypedText();
+ Item.kind = getKind(Result.CursorKind);
if (CCS->getBriefComment())
Item.documentation = CCS->getBriefComment();
Items->push_back(std::move(Item));
diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp
index 6e3fadc045f..5c5d3a27c52 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -672,7 +672,7 @@ std::string CompletionItem::unparse(const CompletionItem &CI) {
assert(!CI.label.empty() && "completion item label is required");
Os << R"("label":")" << llvm::yaml::escape(CI.label) << R"(",)";
if (CI.kind != CompletionItemKind::Missing)
- Os << R"("kind":)" << static_cast<int>(CI.kind) << R"(",)";
+ Os << R"("kind":)" << static_cast<int>(CI.kind) << R"(,)";
if (!CI.detail.empty())
Os << R"("detail":")" << llvm::yaml::escape(CI.detail) << R"(",)";
if (!CI.documentation.empty())
diff --git a/clang-tools-extra/test/clangd/completion.test b/clang-tools-extra/test/clangd/completion.test
index bf5e2ab8fef..3d004a3dc7c 100644
--- a/clang-tools-extra/test/clangd/completion.test
+++ b/clang-tools-extra/test/clangd/completion.test
@@ -16,9 +16,9 @@ Content-Length: 148
# nondeterministic, so we check regardless of order.
#
# CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a"}
-# CHECK-DAG: {"label":"bb"}
-# CHECK-DAG: {"label":"ccc"}
+# CHECK-DAG: {"label":"a","kind":5}
+# CHECK-DAG: {"label":"bb","kind":5}
+# CHECK-DAG: {"label":"ccc","kind":5}
# CHECK: ]}
Content-Length: 44
OpenPOWER on IntegriCloud