diff --git a/src/fuzzy_match.cc b/src/fuzzy_match.cc index af1dd532..a32691fa 100644 --- a/src/fuzzy_match.cc +++ b/src/fuzzy_match.cc @@ -95,7 +95,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; @@ -103,6 +105,8 @@ int FuzzyMatcher::Match(std::string_view text) { for (int i = 0; i < n; i++) low_text[i] = (char)::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); diff --git a/src/fuzzy_match.hh b/src/fuzzy_match.hh index e4d6ead1..c76a7af4 100644 --- a/src/fuzzy_match.hh +++ b/src/fuzzy_match.hh @@ -17,7 +17,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; diff --git a/src/messages/textDocument_completion.cc b/src/messages/textDocument_completion.cc index 3f6fa3fb..843a985c 100644 --- a/src/messages/textDocument_completion.cc +++ b/src/messages/textDocument_completion.cc @@ -163,7 +163,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(), diff --git a/src/messages/workspace.cc b/src/messages/workspace.cc index 87483aa2..6e0c51c6 100644 --- a/src/messages/workspace.cc +++ b/src/messages/workspace.cc @@ -168,8 +168,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); });