[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 03:24:27 PDT 2018
sammccall created this revision.
sammccall added a reviewer: ioeric.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ilya-biryukov.
Macros are terribly spammy at the moment and this offers some relief.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D47936
Files:
clangd/CodeComplete.cpp
unittests/clangd/CodeCompleteTests.cpp
Index: unittests/clangd/CodeCompleteTests.cpp
===================================================================
--- unittests/clangd/CodeCompleteTests.cpp
+++ 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"))));
Index: clangd/CodeComplete.cpp
===================================================================
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -1015,6 +1015,14 @@
return std::move(Top).items();
}
+ Optional<float> fuzzyScore(const CompletionCandidate &C) {
+ // Macros can be very spammy, so we only support prefix completion.
+ 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 +1035,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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47936.150476.patch
Type: text/x-patch
Size: 1872 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180608/4af4a1d9/attachment-0001.bin>
More information about the cfe-commits
mailing list