[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 04:32:31 PDT 2020
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous.
Herald added a project: clang.
kadircet requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
fixes https://github.com/clangd/clangd/issues/489
Repository:
rG LLVM Github Monorepo
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
@@ -1618,7 +1618,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.284656.patch
Type: text/x-patch
Size: 1933 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200811/f27edac7/attachment.bin>
More information about the cfe-commits
mailing list