[PATCH] D85721: [clangd] Unify macro matching in code completion for AST and Index based macros
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 11 06:54:07 PDT 2020
kadircet updated this revision to Diff 284694.
kadircet added a comment.
- Drop the comment
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85721/new/
https://reviews.llvm.org/D85721
Files:
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -194,9 +194,14 @@
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) {
Index: clang-tools-extra/clangd/CodeComplete.cpp
===================================================================
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -1617,8 +1617,10 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85721.284694.patch
Type: text/x-patch
Size: 1935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200811/23fdd5d4/attachment.bin>
More information about the cfe-commits
mailing list