This commit is contained in:
Fangrui Song 2018-04-01 20:55:10 -07:00
parent daf7a41278
commit 38cc501a8a
3 changed files with 14 additions and 4 deletions

View File

@ -24,7 +24,7 @@ add_executable(ccls "")
# debug: -g # debug: -g
# release: -O3 -DNDEBUG # 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 17)
set_property(TARGET ccls PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET ccls PROPERTY CXX_STANDARD_REQUIRED ON)
# Disable gnu extensions except for Cygwin which needs them to build properly # Disable gnu extensions except for Cygwin which needs them to build properly

View File

@ -46,7 +46,9 @@ void CalculateRoles(std::string_view s, int roles[], int* class_set) {
} // namespace } // namespace
int FuzzyMatcher::MissScore(int j, bool last) { int FuzzyMatcher::MissScore(int j, bool last) {
int s = last ? -10 : 0; int s = -3;
if (last)
s -= 10;
if (text_role[j] == Head) if (text_role[j] == Head)
s -= 10; s -= 10;
return s; return s;
@ -54,8 +56,10 @@ int FuzzyMatcher::MissScore(int j, bool last) {
int FuzzyMatcher::MatchScore(int i, int j, bool last) { int FuzzyMatcher::MatchScore(int i, int j, bool last) {
int s = 0; int s = 0;
// Case matching.
if (pat[i] == text[j]) { if (pat[i] == text[j]) {
s++; s++;
// pat contains uppercase letters or prefix matching.
if ((pat_set & 1 << Upper) || i == j) if ((pat_set & 1 << Upper) || i == j)
s++; s++;
} }
@ -65,8 +69,10 @@ int FuzzyMatcher::MatchScore(int i, int j, bool last) {
else if (text_role[j] == Tail) else if (text_role[j] == Tail)
s -= 10; s -= 10;
} }
// Matching a tail while previous char wasn't matched.
if (text_role[j] == Tail && i && !last) if (text_role[j] == Tail && i && !last)
s -= 30; s -= 30;
// First char of pat matches a tail.
if (i == 0 && text_role[j] == Tail) if (i == 0 && text_role[j] == Tail)
s -= 40; s -= 40;
return s; return s;
@ -119,7 +125,7 @@ int FuzzyMatcher::Match(std::string_view text) {
// character has a penulty. // character has a penulty.
int ret = kMinScore; int ret = kMinScore;
for (int j = pat.size(); j <= n; j++) 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; return ret;
} }

View File

@ -284,9 +284,12 @@ void TraceMe() {
std::string GetExternalCommandOutput(const std::vector<std::string>& command, std::string GetExternalCommandOutput(const std::vector<std::string>& command,
std::string_view input) { std::string_view input) {
int pin[2], pout[2]; int pin[2], pout[2];
if (pipe(pin) < 0) if (pipe(pin) < 0) {
perror("pipe(stdin)");
return ""; return "";
}
if (pipe(pout) < 0) { if (pipe(pout) < 0) {
perror("pipe(stdout)");
close(pin[0]); close(pin[0]);
close(pin[1]); close(pin[1]);
return ""; return "";
@ -316,6 +319,7 @@ std::string GetExternalCommandOutput(const std::vector<std::string>& command,
ssize_t n; ssize_t n;
while ((n = read(pin[0], buf, sizeof buf)) > 0) while ((n = read(pin[0], buf, sizeof buf)) > 0)
ret.append(buf, n); ret.append(buf, n);
close(pin[0]);
waitpid(child, NULL, 0); waitpid(child, NULL, 0);
return ret; return ret;
} }