mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 23:55:08 +00:00
Add option to disable filtering and sorting completion response.
This commit is contained in:
parent
567a6e6e99
commit
b0bf107f71
@ -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.
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user