Add option to disable filtering and sorting completion response.

This commit is contained in:
Chao Shen 2018-01-19 11:25:23 +08:00 committed by Jacob Dufault
parent 567a6e6e99
commit b0bf107f71
2 changed files with 22 additions and 5 deletions

View File

@ -95,6 +95,9 @@ struct Config {
// plain // /* // plain // /*
int enableComments = 0; int enableComments = 0;
// If true, filter and sort completion response.
bool filterAndSortCompletionResponse = true;
//// For debugging //// For debugging
// Dump AST after parsing if some pattern matches the source filename. // Dump AST after parsing if some pattern matches the source filename.
@ -138,6 +141,8 @@ MAKE_REFLECT_STRUCT(Config,
enableComments, enableComments,
filterAndSortCompletionResponse,
dumpAST); dumpAST);
// Expected client version. We show an error if this doesn't match. // Expected client version. We show an error if this doesn't match.

View File

@ -99,10 +99,11 @@ char* tofixedbase64(T input, char* out) {
// Pre-filters completion responses before sending to vscode. This results in a // Pre-filters completion responses before sending to vscode. This results in a
// significantly snappier completion experience as vscode is easily overloaded // significantly snappier completion experience as vscode is easily overloaded
// when given 1000+ completion items. // when given 1000+ completion items.
void SortAndFilterCompletionResponse( void FilterAndSortCompletionResponse(
Out_TextDocumentComplete* complete_response, Out_TextDocumentComplete* complete_response,
const std::string& complete_text) { const std::string& complete_text,
ScopedPerfTimer timer("SortAndFilterCompletionResponse"); bool enable) {
ScopedPerfTimer timer("FilterAndSortCompletionResponse");
// Used to inject more completions. // Used to inject more completions.
#if false #if false
@ -120,6 +121,14 @@ void SortAndFilterCompletionResponse(
auto& items = complete_response->result.items; auto& items = complete_response->result.items;
if (!enable) {
// Just set the |sortText| to be the priority and return.
char buf[16];
for (auto& item : items)
item.sortText = tofixedbase64(item.priority_, buf);
return;
}
// Find the appearance of |complete_text| in all candidates. // Find the appearance of |complete_text| in all candidates.
bool found = false; bool found = false;
for (auto& item : items) { for (auto& item : items) {
@ -295,7 +304,8 @@ struct TextDocumentCompletionHandler : MessageHandler {
} }
TrimInPlace(buffer_line); TrimInPlace(buffer_line);
SortAndFilterCompletionResponse(&out, buffer_line); FilterAndSortCompletionResponse(&out, buffer_line,
config->filterAndSortCompletionResponse);
QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out); QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out);
} else { } else {
// If existing completion is empty, dont return clang-based completion // If existing completion is empty, dont return clang-based completion
@ -321,7 +331,9 @@ struct TextDocumentCompletionHandler : MessageHandler {
out.result.items = results; out.result.items = results;
// Emit completion results. // Emit completion results.
SortAndFilterCompletionResponse(&out, existing_completion); FilterAndSortCompletionResponse(
&out, existing_completion,
config->filterAndSortCompletionResponse);
QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out); QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out);
// Cache completion results. // Cache completion results.