Don't include system header files for #include " (#i") completion

This commit is contained in:
Fangrui Song 2018-03-18 14:26:15 -07:00
parent 282ef8ce74
commit 2d1c990f1a
2 changed files with 30 additions and 24 deletions

View File

@ -90,8 +90,7 @@ int FuzzyMatcher::Match(std::string_view text) {
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
low_text[i] = (char)::tolower(text[i]); low_text[i] = (char)::tolower(text[i]);
CalculateRoles(text, text_role, &text_set); CalculateRoles(text, text_role, &text_set);
dp[0][0][0] = 0; dp[0][0][0] = dp[0][0][1] = 0;
dp[0][0][1] = kMinScore * 2;
for (int j = 0; j < n; j++) { for (int j = 0; j < n; j++) {
dp[0][j + 1][0] = dp[0][j][0] + MissScore(j, false); dp[0][j + 1][0] = dp[0][j][0] + MissScore(j, false);
dp[0][j + 1][1] = kMinScore * 2; dp[0][j + 1][1] = kMinScore * 2;
@ -143,6 +142,10 @@ TEST_SUITE("fuzzy_match") {
} }
TEST_CASE("test") { TEST_CASE("test") {
FuzzyMatcher fuzzy("");
CHECK(fuzzy.Match("") == 0);
CHECK(fuzzy.Match("aaa") < 0);
// case // case
Ranks("monad", {"monad", "Monad", "mONAD"}); Ranks("monad", {"monad", "Monad", "mONAD"});
// initials // initials

View File

@ -98,7 +98,7 @@ void DecorateIncludePaths(const std::smatch& match,
struct ParseIncludeLineResult { struct ParseIncludeLineResult {
bool ok; bool ok;
std::string text; // include the "include" part std::string pattern;
std::smatch match; std::smatch match;
}; };
@ -115,7 +115,7 @@ ParseIncludeLineResult ParseIncludeLine(const std::string& line) {
"(.*)"); // [7]: suffix after quote char "(.*)"); // [7]: suffix after quote char
std::smatch match; std::smatch match;
bool ok = std::regex_match(line, match, pattern); bool ok = std::regex_match(line, match, pattern);
std::string text = match[3].str() + match[6].str(); std::string text = match[6].str();
return {ok, text, match}; return {ok, text, match};
} }
@ -298,22 +298,24 @@ struct TextDocumentCompletionHandler : MessageHandler {
Out_TextDocumentComplete out; Out_TextDocumentComplete out;
out.id = request->id; out.id = request->id;
std::string text = result.match[3];
if (std::string_view("include").compare(0, text.size(), text) == 0) {
{ {
std::unique_lock<std::mutex> lock( std::unique_lock<std::mutex> lock(
include_complete->completion_items_mutex, std::defer_lock); include_complete->completion_items_mutex, std::defer_lock);
if (include_complete->is_scanning) if (include_complete->is_scanning)
lock.lock(); lock.lock();
out.result.items.assign(include_complete->completion_items.begin(), std::string quote = result.match[5];
include_complete->completion_items.end()); for (auto& item : include_complete->completion_items)
if (lock) if (quote.empty() || quote == (item.use_angle_brackets_ ? "<" : "\""))
lock.unlock(); out.result.items.push_back(item);
} }
// Needed by |FilterAndSortCompletionResponse|. // Needed by |FilterAndSortCompletionResponse|.
for (lsCompletionItem& item : out.result.items) for (lsCompletionItem& item : out.result.items)
item.filterText = "include" + item.label; item.filterText = item.label;
FilterAndSortCompletionResponse(&out, result.text, FilterAndSortCompletionResponse(&out, result.pattern,
config->completion.filterAndSort); config->completion.filterAndSort);
DecorateIncludePaths(result.match, &out.result.items); DecorateIncludePaths(result.match, &out.result.items);
@ -323,6 +325,7 @@ struct TextDocumentCompletionHandler : MessageHandler {
item.textEdit->range.end.line = request->params.position.line; item.textEdit->range.end.line = request->params.position.line;
item.textEdit->range.end.character = (int)buffer_line.size(); item.textEdit->range.end.character = (int)buffer_line.size();
} }
}
QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out); QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out);
} else { } else {