mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 12:05:50 +00:00
Drop old completion requests.
Also increase xref limit.
This commit is contained in:
parent
e785d3f477
commit
fae959e0ee
@ -440,6 +440,14 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
|
|||||||
// Fetching the completion request blocks until we have a request.
|
// Fetching the completion request blocks until we have a request.
|
||||||
std::unique_ptr<ClangCompleteManager::CompletionRequest> request =
|
std::unique_ptr<ClangCompleteManager::CompletionRequest> request =
|
||||||
completion_manager->completion_request_.Dequeue();
|
completion_manager->completion_request_.Dequeue();
|
||||||
|
|
||||||
|
// Drop older requests if we're not buffering.
|
||||||
|
while (completion_manager->config_->completion.dropOldRequests &&
|
||||||
|
!completion_manager->completion_request_.IsEmpty()) {
|
||||||
|
completion_manager->on_dropped_(request->id);
|
||||||
|
request = completion_manager->completion_request_.Dequeue();
|
||||||
|
}
|
||||||
|
|
||||||
std::string path = request->document.uri.GetPath();
|
std::string path = request->document.uri.GetPath();
|
||||||
|
|
||||||
std::shared_ptr<CompletionSession> session =
|
std::shared_ptr<CompletionSession> session =
|
||||||
@ -625,25 +633,35 @@ CompletionSession::~CompletionSession() {}
|
|||||||
ClangCompleteManager::ParseRequest::ParseRequest(const std::string& path)
|
ClangCompleteManager::ParseRequest::ParseRequest(const std::string& path)
|
||||||
: request_time(std::chrono::high_resolution_clock::now()), path(path) {}
|
: request_time(std::chrono::high_resolution_clock::now()), path(path) {}
|
||||||
|
|
||||||
ClangCompleteManager::CompletionRequest::CompletionRequest(const lsTextDocumentIdentifier& document,
|
ClangCompleteManager::CompletionRequest::CompletionRequest(
|
||||||
const bool& emit_diagnostics)
|
const lsRequestId& id,
|
||||||
: document(document), emit_diagnostics(emit_diagnostics) {}
|
const lsTextDocumentIdentifier& document,
|
||||||
ClangCompleteManager::CompletionRequest::CompletionRequest(const lsTextDocumentIdentifier& document,
|
bool emit_diagnostics)
|
||||||
|
: id(id), document(document), emit_diagnostics(emit_diagnostics) {}
|
||||||
|
ClangCompleteManager::CompletionRequest::CompletionRequest(
|
||||||
|
const lsRequestId& id,
|
||||||
|
const lsTextDocumentIdentifier& document,
|
||||||
const lsPosition& position,
|
const lsPosition& position,
|
||||||
const OnComplete& on_complete,
|
const OnComplete& on_complete,
|
||||||
const bool& emit_diagnostics)
|
bool emit_diagnostics)
|
||||||
: document(document), position(position), on_complete(on_complete), emit_diagnostics(emit_diagnostics) {}
|
: id(id),
|
||||||
|
document(document),
|
||||||
|
position(position),
|
||||||
|
on_complete(on_complete),
|
||||||
|
emit_diagnostics(emit_diagnostics) {}
|
||||||
|
|
||||||
ClangCompleteManager::ClangCompleteManager(Config* config,
|
ClangCompleteManager::ClangCompleteManager(Config* config,
|
||||||
Project* project,
|
Project* project,
|
||||||
WorkingFiles* working_files,
|
WorkingFiles* working_files,
|
||||||
OnDiagnostic on_diagnostic,
|
OnDiagnostic on_diagnostic,
|
||||||
OnIndex on_index)
|
OnIndex on_index,
|
||||||
|
OnDropped on_dropped)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
project_(project),
|
project_(project),
|
||||||
working_files_(working_files),
|
working_files_(working_files),
|
||||||
on_diagnostic_(on_diagnostic),
|
on_diagnostic_(on_diagnostic),
|
||||||
on_index_(on_index),
|
on_index_(on_index),
|
||||||
|
on_dropped_(on_dropped),
|
||||||
preloaded_sessions_(kMaxPreloadedSessions),
|
preloaded_sessions_(kMaxPreloadedSessions),
|
||||||
completion_sessions_(kMaxCompletionSessions) {
|
completion_sessions_(kMaxCompletionSessions) {
|
||||||
new std::thread([&]() {
|
new std::thread([&]() {
|
||||||
@ -660,16 +678,19 @@ ClangCompleteManager::ClangCompleteManager(Config* config,
|
|||||||
ClangCompleteManager::~ClangCompleteManager() {}
|
ClangCompleteManager::~ClangCompleteManager() {}
|
||||||
|
|
||||||
void ClangCompleteManager::CodeComplete(
|
void ClangCompleteManager::CodeComplete(
|
||||||
|
const lsRequestId& id,
|
||||||
const lsTextDocumentPositionParams& completion_location,
|
const lsTextDocumentPositionParams& completion_location,
|
||||||
const OnComplete& on_complete) {
|
const OnComplete& on_complete) {
|
||||||
completion_request_.PushBack(MakeUnique<CompletionRequest>(
|
completion_request_.PushBack(MakeUnique<CompletionRequest>(
|
||||||
completion_location.textDocument, completion_location.position,
|
id, completion_location.textDocument, completion_location.position,
|
||||||
on_complete, false));
|
on_complete, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangCompleteManager::DiagnosticsUpdate(
|
void ClangCompleteManager::DiagnosticsUpdate(
|
||||||
|
const lsRequestId& id,
|
||||||
const lsTextDocumentIdentifier& document) {
|
const lsTextDocumentIdentifier& document) {
|
||||||
completion_request_.PushBack(MakeUnique<CompletionRequest>(document, true));
|
completion_request_.PushBack(
|
||||||
|
MakeUnique<CompletionRequest>(id, document, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangCompleteManager::NotifyView(const std::string& filename) {
|
void ClangCompleteManager::NotifyView(const std::string& filename) {
|
||||||
|
@ -47,6 +47,7 @@ struct ClangCompleteManager {
|
|||||||
using OnComplete =
|
using OnComplete =
|
||||||
std::function<void(const std::vector<lsCompletionItem>& results,
|
std::function<void(const std::vector<lsCompletionItem>& results,
|
||||||
bool is_cached_result)>;
|
bool is_cached_result)>;
|
||||||
|
using OnDropped = std::function<void(lsRequestId request_id)>;
|
||||||
|
|
||||||
struct ParseRequest {
|
struct ParseRequest {
|
||||||
ParseRequest(const std::string& path);
|
ParseRequest(const std::string& path);
|
||||||
@ -55,13 +56,16 @@ struct ClangCompleteManager {
|
|||||||
std::string path;
|
std::string path;
|
||||||
};
|
};
|
||||||
struct CompletionRequest {
|
struct CompletionRequest {
|
||||||
CompletionRequest(const lsTextDocumentIdentifier& document,
|
CompletionRequest(const lsRequestId& id,
|
||||||
const bool& emit_diagnostics);
|
const lsTextDocumentIdentifier& document,
|
||||||
CompletionRequest(const lsTextDocumentIdentifier& document,
|
bool emit_diagnostics);
|
||||||
|
CompletionRequest(const lsRequestId& id,
|
||||||
|
const lsTextDocumentIdentifier& document,
|
||||||
const lsPosition& position,
|
const lsPosition& position,
|
||||||
const OnComplete& on_complete,
|
const OnComplete& on_complete,
|
||||||
const bool& emit_diagnostics);
|
bool emit_diagnostics);
|
||||||
|
|
||||||
|
lsRequestId id;
|
||||||
lsTextDocumentIdentifier document;
|
lsTextDocumentIdentifier document;
|
||||||
optional<lsPosition> position;
|
optional<lsPosition> position;
|
||||||
OnComplete on_complete; // May be null/empty.
|
OnComplete on_complete; // May be null/empty.
|
||||||
@ -72,15 +76,18 @@ struct ClangCompleteManager {
|
|||||||
Project* project,
|
Project* project,
|
||||||
WorkingFiles* working_files,
|
WorkingFiles* working_files,
|
||||||
OnDiagnostic on_diagnostic,
|
OnDiagnostic on_diagnostic,
|
||||||
OnIndex on_index);
|
OnIndex on_index,
|
||||||
|
OnDropped on_dropped);
|
||||||
~ClangCompleteManager();
|
~ClangCompleteManager();
|
||||||
|
|
||||||
// Start a code completion at the given location. |on_complete| will run when
|
// Start a code completion at the given location. |on_complete| will run when
|
||||||
// completion results are available. |on_complete| may run on any thread.
|
// completion results are available. |on_complete| may run on any thread.
|
||||||
void CodeComplete(const lsTextDocumentPositionParams& completion_location,
|
void CodeComplete(const lsRequestId& request_id,
|
||||||
|
const lsTextDocumentPositionParams& completion_location,
|
||||||
const OnComplete& on_complete);
|
const OnComplete& on_complete);
|
||||||
// Request a diagnostics update.
|
// Request a diagnostics update.
|
||||||
void DiagnosticsUpdate(const lsTextDocumentIdentifier& document);
|
void DiagnosticsUpdate(const lsRequestId& request_id,
|
||||||
|
const lsTextDocumentIdentifier& document);
|
||||||
|
|
||||||
// Notify the completion manager that |filename| has been viewed and we
|
// Notify the completion manager that |filename| has been viewed and we
|
||||||
// should begin preloading completion data.
|
// should begin preloading completion data.
|
||||||
@ -113,6 +120,7 @@ struct ClangCompleteManager {
|
|||||||
WorkingFiles* working_files_;
|
WorkingFiles* working_files_;
|
||||||
OnDiagnostic on_diagnostic_;
|
OnDiagnostic on_diagnostic_;
|
||||||
OnIndex on_index_;
|
OnIndex on_index_;
|
||||||
|
OnDropped on_dropped_;
|
||||||
|
|
||||||
using LruSessionCache = LruCache<std::string, CompletionSession>;
|
using LruSessionCache = LruCache<std::string, CompletionSession>;
|
||||||
|
|
||||||
|
@ -71,7 +71,8 @@ bool ShouldDisplayIpcTiming(IpcId id) {
|
|||||||
REGISTER_IPC_MESSAGE(Ipc_CancelRequest);
|
REGISTER_IPC_MESSAGE(Ipc_CancelRequest);
|
||||||
|
|
||||||
void PrintHelp() {
|
void PrintHelp() {
|
||||||
std::cout << R"help(cquery is a low-latency C/C++/Objective-C language server.
|
std::cout
|
||||||
|
<< R"help(cquery is a low-latency C/C++/Objective-C language server.
|
||||||
|
|
||||||
Mode:
|
Mode:
|
||||||
--clang-sanity-check
|
--clang-sanity-check
|
||||||
@ -186,6 +187,15 @@ void RunQueryDbThread(const std::string& bin_name,
|
|||||||
const std::string& path, const std::vector<std::string>& args) {
|
const std::string& path, const std::vector<std::string>& args) {
|
||||||
IndexWithTuFromCodeCompletion(config, &file_consumer_shared, tu,
|
IndexWithTuFromCodeCompletion(config, &file_consumer_shared, tu,
|
||||||
unsaved, path, args);
|
unsaved, path, args);
|
||||||
|
},
|
||||||
|
[](lsRequestId id) {
|
||||||
|
if (!std::holds_alternative<std::monostate>(id)) {
|
||||||
|
Out_Error out;
|
||||||
|
out.id = id;
|
||||||
|
out.error.code = lsErrorCodes::InternalError;
|
||||||
|
out.error.message = "Dropped completion request";
|
||||||
|
QueueManager::WriteStdout(IpcId::Unknown, out);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
IncludeComplete include_complete(config, &project);
|
IncludeComplete include_complete(config, &project);
|
||||||
|
@ -110,6 +110,12 @@ struct Config {
|
|||||||
// items can end up truncated by the UIs.
|
// items can end up truncated by the UIs.
|
||||||
bool detailedLabel = false;
|
bool detailedLabel = false;
|
||||||
|
|
||||||
|
// On large projects, completion can take a long time. By default if cquery
|
||||||
|
// receives multiple completion requests while completion is still running
|
||||||
|
// it will only service the newest request. If this is set to false then all
|
||||||
|
// completion requests will be serviced.
|
||||||
|
bool dropOldRequests = true;
|
||||||
|
|
||||||
// If true, filter and sort completion response. cquery filters and sorts
|
// If true, filter and sort completion response. cquery filters and sorts
|
||||||
// completions to try to be nicer to clients that can't handle big numbers
|
// completions to try to be nicer to clients that can't handle big numbers
|
||||||
// of completion candidates. This behaviour can be disabled by specifying
|
// of completion candidates. This behaviour can be disabled by specifying
|
||||||
|
@ -223,7 +223,8 @@ struct TextDocumentCompletionHandler : MessageHandler {
|
|||||||
std::string character = *request->params.context->triggerCharacter;
|
std::string character = *request->params.context->triggerCharacter;
|
||||||
int preceding_index = request->params.position.character - 2;
|
int preceding_index = request->params.position.character - 2;
|
||||||
|
|
||||||
// If the character is '"', '<' or '/', make sure that the line starts with '#'.
|
// If the character is '"', '<' or '/', make sure that the line starts
|
||||||
|
// with '#'.
|
||||||
if (character == "\"" || character == "<" || character == "/") {
|
if (character == "\"" || character == "<" || character == "/") {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while (i < buffer_line.size() && isspace(buffer_line[i]))
|
while (i < buffer_line.size() && isspace(buffer_line[i]))
|
||||||
@ -361,7 +362,8 @@ struct TextDocumentCompletionHandler : MessageHandler {
|
|||||||
callback(global_code_complete_cache->cached_results_,
|
callback(global_code_complete_cache->cached_results_,
|
||||||
true /*is_cached_result*/);
|
true /*is_cached_result*/);
|
||||||
});
|
});
|
||||||
clang_complete->CodeComplete(request->params, freshen_global);
|
clang_complete->CodeComplete(request->id, request->params,
|
||||||
|
freshen_global);
|
||||||
} else if (non_global_code_complete_cache->IsCacheValid(
|
} else if (non_global_code_complete_cache->IsCacheValid(
|
||||||
request->params)) {
|
request->params)) {
|
||||||
non_global_code_complete_cache->WithLock([&]() {
|
non_global_code_complete_cache->WithLock([&]() {
|
||||||
@ -369,7 +371,7 @@ struct TextDocumentCompletionHandler : MessageHandler {
|
|||||||
true /*is_cached_result*/);
|
true /*is_cached_result*/);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
clang_complete->CodeComplete(request->params, callback);
|
clang_complete->CodeComplete(request->id, request->params, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ struct TextDocumentDidChangeHandler
|
|||||||
working_files->OnChange(request->params);
|
working_files->OnChange(request->params);
|
||||||
clang_complete->NotifyEdit(path);
|
clang_complete->NotifyEdit(path);
|
||||||
clang_complete->DiagnosticsUpdate(
|
clang_complete->DiagnosticsUpdate(
|
||||||
|
std::monostate(),
|
||||||
request->params.textDocument.AsTextDocumentIdentifier());
|
request->params.textDocument.AsTextDocumentIdentifier());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -164,7 +164,7 @@ struct TextDocumentSignatureHelpHandler : MessageHandler {
|
|||||||
callback(signature_cache->cached_results_, true /*is_cached_result*/);
|
callback(signature_cache->cached_results_, true /*is_cached_result*/);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
clang_complete->CodeComplete(params, std::move(callback));
|
clang_complete->CodeComplete(request->id, params, std::move(callback));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user