[clang-tools-extra] c4972d3 - [clangd] Avoid using CompletionItemKind.Text for macro completions
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 24 01:41:43 PST 2023
Author: Nathan Ridge
Date: 2023-02-24T04:41:27-05:00
New Revision: c4972d37290ff5ab1228ecfc7280bc07a9280f92
URL: https://github.com/llvm/llvm-project/commit/c4972d37290ff5ab1228ecfc7280bc07a9280f92
DIFF: https://github.com/llvm/llvm-project/commit/c4972d37290ff5ab1228ecfc7280bc07a9280f92.diff
LOG: [clangd] Avoid using CompletionItemKind.Text for macro completions
Fixes https://github.com/clangd/clangd/issues/1484
Differential Revision: https://reviews.llvm.org/D144703
Added:
Modified:
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 04494f9cda5b4..98fa285f71051 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -150,22 +150,24 @@ CompletionItemKind toCompletionItemKind(index::SymbolKind Kind) {
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::Constant;
case CodeCompletionResult::RK_Pattern:
return CompletionItemKind::Snippet;
}
@@ -337,8 +339,7 @@ struct CodeCompletionBuilder {
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
index 56e156dd84b75..f57f266c3c511 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -639,7 +639,7 @@ TEST(CompletionTest, Kinds) {
has("variable", CompletionItemKind::Variable),
has("int", CompletionItemKind::Keyword),
has("Struct", CompletionItemKind::Struct),
- has("MACRO", CompletionItemKind::Text),
+ has("MACRO", CompletionItemKind::Constant),
has("indexFunction", CompletionItemKind::Function),
has("indexVariable", CompletionItemKind::Variable),
has("indexClass", CompletionItemKind::Class)));
@@ -3801,7 +3801,7 @@ TEST(CompletionTest, FunctionArgsExist) {
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) {
More information about the cfe-commits
mailing list