[PATCH] D47936: [clangd] Require case-insensitive prefix match for macro completions.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 8 06:36:48 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334287: [clangd] Require case-insensitive prefix match for macro completions. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D47936?vs=150476&id=150510#toc
Repository:
rL LLVM
https://reviews.llvm.org/D47936
Files:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
Index: clang-tools-extra/trunk/clangd/CodeComplete.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp
@@ -1015,6 +1015,15 @@
return std::move(Top).items();
}
+ 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 &&
+ !C.Name.startswith_lower(Filter->pattern()))
+ return None;
+ return Filter->match(C.Name);
+ }
+
// Scores a candidate and adds it to the TopN structure.
void addCandidate(TopN<ScoredCandidate, ScoredCandidateGreater> &Candidates,
const CodeCompletionResult *SemaResult,
@@ -1027,7 +1036,7 @@
SymbolQualitySignals Quality;
SymbolRelevanceSignals Relevance;
Relevance.Query = SymbolRelevanceSignals::CodeComplete;
- if (auto FuzzyScore = Filter->match(C.Name))
+ if (auto FuzzyScore = fuzzyScore(C))
Relevance.NameMatch = *FuzzyScore;
else
return;
Index: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
@@ -193,6 +193,7 @@
TEST(CompletionTest, Filter) {
std::string Body = R"cpp(
+ #define FooBarMacro
int Abracadabra;
int Alakazam;
struct S {
@@ -202,7 +203,8 @@
};
)cpp";
EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").items,
- AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux"))));
+ AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("FooBarMacro")),
+ Not(Has("Qux"))));
EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux"))));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47936.150510.patch
Type: text/x-patch
Size: 2095 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180608/4d85b810/attachment.bin>
More information about the cfe-commits
mailing list