diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 1a35bff5..81bc8cac 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -439,7 +439,7 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) { while (true) { // Fetching the completion request blocks until we have a request. std::unique_ptr request = - completion_manager->completion_request_.Take(); + completion_manager->completion_request_.Dequeue(); std::string path = request->document.uri.GetPath(); std::shared_ptr 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& request_storage) { - // Ensure that we have a request. - if (!request_storage) - request_storage = MakeUnique(); - - // 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(completion_location.textDocument, + completion_location.position, + on_complete, + false)); } void ClangCompleteManager::DiagnosticsUpdate( const lsTextDocumentIdentifier& document) { - completion_request_.WithLock( - [&](std::unique_ptr& request_storage) { - // Ensure that we have a request. - if (!request_storage) - request_storage = MakeUnique(); - - // Make the request emit diagnostics. - request_storage->document = document; - request_storage->emit_diagnostics = true; - }); + completion_request_.PushBack(MakeUnique(document, + true)); } void ClangCompleteManager::NotifyView(const std::string& filename) { diff --git a/src/clang_complete.h b/src/clang_complete.h index fda498d6..7cb06871 100644 --- a/src/clang_complete.h +++ b/src/clang_complete.h @@ -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 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 completion_request_; + ThreadedQueue> completion_request_; // Parse requests. The path may already be parsed, in which case it should be // reparsed. ThreadedQueue parse_requests_;