Making completion_request_ ThreadedQueue from AtomicObject (#459)

This commit is contained in:
Patil Arpith 2018-02-18 22:45:39 +05:30 committed by Fangrui Song
parent be4d37dac3
commit afdde4d59f
2 changed files with 24 additions and 23 deletions

View File

@ -439,7 +439,7 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
while (true) {
// Fetching the completion request blocks until we have a request.
std::unique_ptr<ClangCompleteManager::CompletionRequest> request =
completion_manager->completion_request_.Take();
completion_manager->completion_request_.Dequeue();
std::string path = request->document.uri.GetPath();
std::shared_ptr<CompletionSession> session =
@ -625,6 +625,15 @@ CompletionSession::~CompletionSession() {}
ClangCompleteManager::ParseRequest::ParseRequest(const std::string& path)
: request_time(std::chrono::high_resolution_clock::now()), path(path) {}
ClangCompleteManager::CompletionRequest::CompletionRequest(const lsTextDocumentIdentifier& document,
const bool& emit_diagnostics)
: document(document), emit_diagnostics(emit_diagnostics) {}
ClangCompleteManager::CompletionRequest::CompletionRequest(const lsTextDocumentIdentifier& document,
const lsPosition& position,
const OnComplete& on_complete,
const bool& emit_diagnostics)
: document(document), position(position), on_complete(on_complete), emit_diagnostics(emit_diagnostics) {}
ClangCompleteManager::ClangCompleteManager(Config* config,
Project* project,
WorkingFiles* working_files,
@ -653,31 +662,16 @@ ClangCompleteManager::~ClangCompleteManager() {}
void ClangCompleteManager::CodeComplete(
const lsTextDocumentPositionParams& completion_location,
const OnComplete& on_complete) {
completion_request_.WithLock(
[&](std::unique_ptr<CompletionRequest>& request_storage) {
// Ensure that we have a request.
if (!request_storage)
request_storage = MakeUnique<CompletionRequest>();
// Make the request send out code completion information.
request_storage->document = completion_location.textDocument;
request_storage->position = completion_location.position;
request_storage->on_complete = on_complete;
});
completion_request_.PushBack(MakeUnique<CompletionRequest>(completion_location.textDocument,
completion_location.position,
on_complete,
false));
}
void ClangCompleteManager::DiagnosticsUpdate(
const lsTextDocumentIdentifier& document) {
completion_request_.WithLock(
[&](std::unique_ptr<CompletionRequest>& request_storage) {
// Ensure that we have a request.
if (!request_storage)
request_storage = MakeUnique<CompletionRequest>();
// Make the request emit diagnostics.
request_storage->document = document;
request_storage->emit_diagnostics = true;
});
completion_request_.PushBack(MakeUnique<CompletionRequest>(document,
true));
}
void ClangCompleteManager::NotifyView(const std::string& filename) {

View File

@ -55,6 +55,13 @@ struct ClangCompleteManager {
std::string path;
};
struct CompletionRequest {
CompletionRequest(const lsTextDocumentIdentifier& document,
const bool& emit_diagnostics);
CompletionRequest(const lsTextDocumentIdentifier& document,
const lsPosition& position,
const OnComplete& on_complete,
const bool& emit_diagnostics);
lsTextDocumentIdentifier document;
optional<lsPosition> position;
OnComplete on_complete; // May be null/empty.
@ -120,7 +127,7 @@ struct ClangCompleteManager {
std::mutex sessions_lock_;
// Request a code completion at the given location.
AtomicObject<CompletionRequest> completion_request_;
ThreadedQueue<std::unique_ptr<CompletionRequest>> completion_request_;
// Parse requests. The path may already be parsed, in which case it should be
// reparsed.
ThreadedQueue<ParseRequest> parse_requests_;