diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -150,22 +150,24 @@ llvm_unreachable("Unhandled clang::index::SymbolKind."); } -CompletionItemKind -toCompletionItemKind(CodeCompletionResult::ResultKind ResKind, - const NamedDecl *Decl, - CodeCompletionContext::Kind CtxKind) { - if (Decl) - return toCompletionItemKind(index::getSymbolInfo(Decl).Kind); +CompletionItemKind toCompletionItemKind(const CodeCompletionResult &Res, + CodeCompletionContext::Kind CtxKind) { + if (Res.Declaration) + return toCompletionItemKind(index::getSymbolInfo(Res.Declaration).Kind); if (CtxKind == CodeCompletionContext::CCC_IncludedFile) return CompletionItemKind::File; - switch (ResKind) { + switch (Res.Kind) { case CodeCompletionResult::RK_Declaration: llvm_unreachable("RK_Declaration without Decl"); case CodeCompletionResult::RK_Keyword: return CompletionItemKind::Keyword; case CodeCompletionResult::RK_Macro: - return CompletionItemKind::Text; // unfortunately, there's no 'Macro' - // completion items in LSP. + // There is no 'Macro' kind in LSP. + // Avoid using 'Text' to avoid confusion with client-side word-based + // completion proposals. + return Res.MacroDefInfo && Res.MacroDefInfo->isFunctionLike() + ? CompletionItemKind::Function + : CompletionItemKind::Variable; case CodeCompletionResult::RK_Pattern: return CompletionItemKind::Snippet; } @@ -337,8 +339,7 @@ Completion.Scope = std::string( splitQualifiedName(printQualifiedName(*ND)).first); } - Completion.Kind = toCompletionItemKind( - C.SemaResult->Kind, C.SemaResult->Declaration, ContextKind); + Completion.Kind = toCompletionItemKind(*C.SemaResult, ContextKind); // Sema could provide more info on whether the completion was a file or // folder. if (Completion.Kind == CompletionItemKind::File && diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp --- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -627,7 +627,7 @@ has("variable", CompletionItemKind::Variable), has("int", CompletionItemKind::Keyword), has("Struct", CompletionItemKind::Struct), - has("MACRO", CompletionItemKind::Text), + has("MACRO", CompletionItemKind::Variable), has("indexFunction", CompletionItemKind::Function), has("indexVariable", CompletionItemKind::Variable), has("indexClass", CompletionItemKind::Class))); @@ -3789,7 +3789,7 @@ kind(CompletionItemKind::Constructor)))); EXPECT_THAT(completions(Context + "MAC^(2)", {}, Opts).Completions, Contains(AllOf(labeled("MACRO(x)"), snippetSuffix(""), - kind(CompletionItemKind::Text)))); + kind(CompletionItemKind::Function)))); } TEST(CompletionTest, NoCrashDueToMacroOrdering) {