[clang-tools-extra] b626f45 - [clangd] Unify macro matching in code completion for AST and Index based macros
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 11 07:00:47 PDT 2020
Author: Kadir Cetinkaya
Date: 2020-08-11T16:00:39+02:00
New Revision: b626f45329e8575f72e6cd444b444942d4913e9c
URL: https://github.com/llvm/llvm-project/commit/b626f45329e8575f72e6cd444b444942d4913e9c
DIFF: https://github.com/llvm/llvm-project/commit/b626f45329e8575f72e6cd444b444942d4913e9c.diff
LOG: [clangd] Unify macro matching in code completion for AST and Index based macros
fixes https://github.com/clangd/clangd/issues/489
Differential Revision: https://reviews.llvm.org/D85721
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 f79033ac9514..92ebc4c39f64 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -1617,8 +1617,10 @@ class CodeCompleteFlow {
llvm::Optional<float> fuzzyScore(const CompletionCandidate &C) {
// Macros can be very spammy, so we only support prefix completion.
- // We won't end up with underfull index results, as macros are sema-only.
- if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
+ if (((C.SemaResult &&
+ C.SemaResult->Kind == CodeCompletionResult::RK_Macro) ||
+ (C.IndexResult &&
+ C.IndexResult->SymInfo.Kind == index::SymbolKind::Macro)) &&
!C.Name.startswith_lower(Filter->pattern()))
return None;
return Filter->match(C.Name);
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 31a1c2d46c09..fd144d9391d3 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -194,9 +194,14 @@ TEST(CompletionTest, Filter) {
EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").Completions,
AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux"))));
- // Macros require prefix match.
- EXPECT_THAT(completions(Body + "int main() { C^ }").Completions,
- AllOf(Has("Car"), Not(Has("MotorCar"))));
+ // Macros require prefix match, either from index or AST.
+ Symbol Sym = var("MotorCarIndex");
+ Sym.SymInfo.Kind = index::SymbolKind::Macro;
+ EXPECT_THAT(
+ completions(Body + "int main() { C^ }", {Sym}).Completions,
+ AllOf(Has("Car"), Not(Has("MotorCar")), Not(Has("MotorCarIndex"))));
+ EXPECT_THAT(completions(Body + "int main() { M^ }", {Sym}).Completions,
+ AllOf(Has("MotorCar"), Has("MotorCarIndex")));
}
void testAfterDotCompletion(clangd::CodeCompleteOptions Opts) {
More information about the cfe-commits
mailing list