mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-21 15:15:07 +00:00
Fuzzy
This commit is contained in:
parent
daf7a41278
commit
38cc501a8a
@ -24,7 +24,7 @@ add_executable(ccls "")
|
||||
# debug: -g
|
||||
# release: -O3 -DNDEBUG
|
||||
|
||||
# Enable C++14 (Required)
|
||||
# Enable C++17 (Required)
|
||||
set_property(TARGET ccls PROPERTY CXX_STANDARD 17)
|
||||
set_property(TARGET ccls PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
# Disable gnu extensions except for Cygwin which needs them to build properly
|
||||
|
@ -46,7 +46,9 @@ void CalculateRoles(std::string_view s, int roles[], int* class_set) {
|
||||
} // namespace
|
||||
|
||||
int FuzzyMatcher::MissScore(int j, bool last) {
|
||||
int s = last ? -10 : 0;
|
||||
int s = -3;
|
||||
if (last)
|
||||
s -= 10;
|
||||
if (text_role[j] == Head)
|
||||
s -= 10;
|
||||
return s;
|
||||
@ -54,8 +56,10 @@ int FuzzyMatcher::MissScore(int j, bool last) {
|
||||
|
||||
int FuzzyMatcher::MatchScore(int i, int j, bool last) {
|
||||
int s = 0;
|
||||
// Case matching.
|
||||
if (pat[i] == text[j]) {
|
||||
s++;
|
||||
// pat contains uppercase letters or prefix matching.
|
||||
if ((pat_set & 1 << Upper) || i == j)
|
||||
s++;
|
||||
}
|
||||
@ -65,8 +69,10 @@ int FuzzyMatcher::MatchScore(int i, int j, bool last) {
|
||||
else if (text_role[j] == Tail)
|
||||
s -= 10;
|
||||
}
|
||||
// Matching a tail while previous char wasn't matched.
|
||||
if (text_role[j] == Tail && i && !last)
|
||||
s -= 30;
|
||||
// First char of pat matches a tail.
|
||||
if (i == 0 && text_role[j] == Tail)
|
||||
s -= 40;
|
||||
return s;
|
||||
@ -119,7 +125,7 @@ int FuzzyMatcher::Match(std::string_view text) {
|
||||
// character has a penulty.
|
||||
int ret = kMinScore;
|
||||
for (int j = pat.size(); j <= n; j++)
|
||||
ret = std::max(ret, dp[pat.size() & 1][j][1] - 3 * (n - j));
|
||||
ret = std::max(ret, dp[pat.size() & 1][j][1] - 2 * (n - j));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -284,9 +284,12 @@ void TraceMe() {
|
||||
std::string GetExternalCommandOutput(const std::vector<std::string>& command,
|
||||
std::string_view input) {
|
||||
int pin[2], pout[2];
|
||||
if (pipe(pin) < 0)
|
||||
if (pipe(pin) < 0) {
|
||||
perror("pipe(stdin)");
|
||||
return "";
|
||||
}
|
||||
if (pipe(pout) < 0) {
|
||||
perror("pipe(stdout)");
|
||||
close(pin[0]);
|
||||
close(pin[1]);
|
||||
return "";
|
||||
@ -316,6 +319,7 @@ std::string GetExternalCommandOutput(const std::vector<std::string>& command,
|
||||
ssize_t n;
|
||||
while ((n = read(pin[0], buf, sizeof buf)) > 0)
|
||||
ret.append(buf, n);
|
||||
close(pin[0]);
|
||||
waitpid(child, NULL, 0);
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user