From 6704049e133236dbdfabb763ff05b3a9d3b7bdb8 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Wed, 27 Sep 2017 13:44:54 -0700 Subject: [PATCH] Disable real-time indexing. It adds a bit too much latency to code completion. I suspect this can be removed by running real-time indexing in a separate thread (though this will require a dedicated CXTranslationUnit instance). --- src/clang_complete.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/clang_complete.cc b/src/clang_complete.cc index a5ba96c4..adfe1455 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -462,10 +462,12 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) { completion_manager->on_diagnostic_(session->file.filename, ls_diagnostics); + /* timer.Reset(); completion_manager->on_index_(session->tu.get(), unsaved, session->file.filename, session->file.args); timer.ResetAndPrint("[complete] Reindex file"); + */ } continue; @@ -578,9 +580,11 @@ void ClangCompleteManager::NotifyView(const std::string& filename) { std::lock_guard lock(sessions_lock_); + // Already a view session, do nothing. if (view_sessions_.TryGetEntry(filename)) return; + // Create new view session. view_sessions_.InsertEntry(std::make_shared( project_->FindCompilationEntryForFile(filename), working_files_)); parse_requests_.Enqueue(ParseRequest(filename)); @@ -598,15 +602,18 @@ void ClangCompleteManager::NotifyEdit(const std::string& filename) { if (edit_sessions_.TryGetEntry(filename)) return; - std::shared_ptr session = + // Move the session from view to edit. + std::shared_ptr view_session = view_sessions_.TryTakeEntry(filename); - if (session) { - edit_sessions_.InsertEntry(session); - } else { - edit_sessions_.InsertEntry(std::make_shared( - project_->FindCompilationEntryForFile(filename), working_files_)); - parse_requests_.PriorityEnqueue(ParseRequest(filename)); + if (view_session) { + edit_sessions_.InsertEntry(view_session); + return; } + + // No view session, create a new session. + edit_sessions_.InsertEntry(std::make_shared( + project_->FindCompilationEntryForFile(filename), working_files_)); + parse_requests_.PriorityEnqueue(ParseRequest(filename)); } void ClangCompleteManager::NotifySave(const std::string& filename) {