mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-24 08:35:08 +00:00
Add strict
to FuzzyMatcher::Match
In completion, underscore prefixed builtin macros may be annoying when the first type character is not an underscore. When `strict` is true, `Match` enforces the first characters should be loosely of the same category.
This commit is contained in:
parent
e0a6db8d9b
commit
18e4be616c
@ -107,7 +107,9 @@ FuzzyMatcher::FuzzyMatcher(std::string_view pattern, int sensitivity) {
|
||||
}
|
||||
}
|
||||
|
||||
int FuzzyMatcher::Match(std::string_view text) {
|
||||
int FuzzyMatcher::Match(std::string_view text, bool strict) {
|
||||
if (pat.empty() != text.empty())
|
||||
return kMinScore;
|
||||
int n = int(text.size());
|
||||
if (n > kMaxText)
|
||||
return kMinScore + 1;
|
||||
@ -115,6 +117,8 @@ int FuzzyMatcher::Match(std::string_view text) {
|
||||
for (int i = 0; i < n; i++)
|
||||
low_text[i] = ::tolower(text[i]);
|
||||
CalculateRoles(text, text_role, &text_set);
|
||||
if (strict && n && !!pat_role[0] != !!text_role[0])
|
||||
return kMinScore;
|
||||
dp[0][0][0] = dp[0][0][1] = 0;
|
||||
for (int j = 0; j < n; j++) {
|
||||
dp[0][j + 1][0] = dp[0][j][0] + MissScore(j, false);
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
constexpr static int kMinScore = INT_MIN / 4;
|
||||
|
||||
FuzzyMatcher(std::string_view pattern, int case_sensitivity);
|
||||
int Match(std::string_view text);
|
||||
int Match(std::string_view text, bool strict);
|
||||
|
||||
private:
|
||||
int case_sensitivity;
|
||||
|
@ -175,7 +175,7 @@ void FilterCandidates(CompletionList &result, const std::string &complete_text,
|
||||
const std::string &filter =
|
||||
item.filterText.size() ? item.filterText : item.label;
|
||||
item.score_ = ReverseSubseqMatch(complete_text, filter, sensitive) >= 0
|
||||
? fuzzy.Match(filter)
|
||||
? fuzzy.Match(filter, true)
|
||||
: FuzzyMatcher::kMinScore;
|
||||
}
|
||||
items.erase(std::remove_if(items.begin(), items.end(),
|
||||
|
@ -180,8 +180,8 @@ done_add:
|
||||
longest, int(db->GetSymbolName(std::get<2>(cand), true).size()));
|
||||
FuzzyMatcher fuzzy(query, g_config->workspaceSymbol.caseSensitivity);
|
||||
for (auto &cand : cands)
|
||||
std::get<1>(cand) =
|
||||
fuzzy.Match(db->GetSymbolName(std::get<2>(cand), std::get<1>(cand)));
|
||||
std::get<1>(cand) = fuzzy.Match(
|
||||
db->GetSymbolName(std::get<2>(cand), std::get<1>(cand)), false);
|
||||
std::sort(cands.begin(), cands.end(), [](const auto &l, const auto &r) {
|
||||
return std::get<1>(l) > std::get<1>(r);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user