diff --git a/CMakeLists.txt b/CMakeLists.txt index d73ce893..86125809 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/fuzzy_match.cc b/src/fuzzy_match.cc index c72e958c..182680ae 100644 --- a/src/fuzzy_match.cc +++ b/src/fuzzy_match.cc @@ -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; } diff --git a/src/platform_posix.cc b/src/platform_posix.cc index b03ec4b7..d41cee68 100644 --- a/src/platform_posix.cc +++ b/src/platform_posix.cc @@ -284,9 +284,12 @@ void TraceMe() { std::string GetExternalCommandOutput(const std::vector& 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& 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; }