diff --git a/src/config.h b/src/config.h index 6fb0198f..3d3088d9 100644 --- a/src/config.h +++ b/src/config.h @@ -95,6 +95,9 @@ struct Config { // plain // /* int enableComments = 0; + // If true, filter and sort completion response. + bool filterAndSortCompletionResponse = true; + //// For debugging // Dump AST after parsing if some pattern matches the source filename. @@ -138,6 +141,8 @@ MAKE_REFLECT_STRUCT(Config, enableComments, + filterAndSortCompletionResponse, + dumpAST); // Expected client version. We show an error if this doesn't match. diff --git a/src/messages/text_document_completion.cc b/src/messages/text_document_completion.cc index b945ed35..80c3c2f5 100644 --- a/src/messages/text_document_completion.cc +++ b/src/messages/text_document_completion.cc @@ -99,10 +99,11 @@ char* tofixedbase64(T input, char* out) { // Pre-filters completion responses before sending to vscode. This results in a // significantly snappier completion experience as vscode is easily overloaded // when given 1000+ completion items. -void SortAndFilterCompletionResponse( +void FilterAndSortCompletionResponse( Out_TextDocumentComplete* complete_response, - const std::string& complete_text) { - ScopedPerfTimer timer("SortAndFilterCompletionResponse"); + const std::string& complete_text, + bool enable) { + ScopedPerfTimer timer("FilterAndSortCompletionResponse"); // Used to inject more completions. #if false @@ -120,6 +121,14 @@ void SortAndFilterCompletionResponse( 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. bool found = false; for (auto& item : items) { @@ -295,7 +304,8 @@ struct TextDocumentCompletionHandler : MessageHandler { } TrimInPlace(buffer_line); - SortAndFilterCompletionResponse(&out, buffer_line); + FilterAndSortCompletionResponse(&out, buffer_line, + config->filterAndSortCompletionResponse); QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out); } else { // If existing completion is empty, dont return clang-based completion @@ -321,7 +331,9 @@ struct TextDocumentCompletionHandler : MessageHandler { out.result.items = results; // Emit completion results. - SortAndFilterCompletionResponse(&out, existing_completion); + FilterAndSortCompletionResponse( + &out, existing_completion, + config->filterAndSortCompletionResponse); QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out); // Cache completion results.