diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 734dcf30..8584b5ad 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -802,3 +802,17 @@ std::shared_ptr ClangCompleteManager::TryGetSession( return completion_session; } + +void ClangCompleteManager::FlushSession(const std::string& filename) { + std::lock_guard lock(sessions_lock_); + + preloaded_sessions_.TryTake(filename); + completion_sessions_.TryTake(filename); +} + +void ClangCompleteManager::FlushAllSessions() { + std::lock_guard lock(sessions_lock_); + + preloaded_sessions_.Clear(); + completion_sessions_.Clear(); +} diff --git a/src/clang_complete.h b/src/clang_complete.h index ef506005..03197a60 100644 --- a/src/clang_complete.h +++ b/src/clang_complete.h @@ -110,6 +110,11 @@ struct ClangCompleteManager { bool mark_as_completion, bool create_if_needed); + // Flushes all saved sessions with the supplied filename + void FlushSession(const std::string& filename); + // Flushes all saved sessions + void FlushAllSessions(void); + // TODO: make these configurable. const int kMaxPreloadedSessions = 10; const int kMaxCompletionSessions = 5; diff --git a/src/diagnostics_engine.cc b/src/diagnostics_engine.cc index 36453ea2..15253d1d 100644 --- a/src/diagnostics_engine.cc +++ b/src/diagnostics_engine.cc @@ -13,11 +13,6 @@ void DiagnosticsEngine::Init(Config* config) { void DiagnosticsEngine::Publish(WorkingFiles* working_files, std::string path, std::vector diagnostics) { - // Cache diagnostics so we can show fixits. - working_files->DoActionOnFile(path, [&](WorkingFile* working_file) { - if (working_file) - working_file->diagnostics_ = diagnostics; - }); int64_t now = std::chrono::duration_cast( diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index 3fcff636..03d8f47c 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -408,6 +408,12 @@ void ParseFile(Config* config, for (std::unique_ptr& new_index : *indexes) { Timer time; + // Cache diagnostics so we can show fixits. + working_files->DoActionOnFile(path, [&](WorkingFile* working_file) { + if (working_file) + working_file->diagnostics_ = diagnostics; + }); + // Only emit diagnostics for non-interactive sessions, which makes it easier // to identify indexing problems. For interactive sessions, diagnostics are // handled by code completion. diff --git a/src/lru_cache.h b/src/lru_cache.h index 5539cc78..c6e3d9c4 100644 --- a/src/lru_cache.h +++ b/src/lru_cache.h @@ -29,6 +29,9 @@ struct LruCache { template void IterateValues(TFunc func); + // Empties the cache + void Clear(void); + private: // There is a global score counter, when we access an element we increase // its score to the current global value, so it has the highest overall @@ -124,3 +127,9 @@ void LruCache::IncrementScore() { entry.score = next_score_++; } } + +template +void LruCache::Clear(void) { + entries_.clear(); + next_score_ = 0; +} diff --git a/src/messages/workspace_did_change_configuration.cc b/src/messages/workspace_did_change_configuration.cc index 7b90fc8d..3506cf59 100644 --- a/src/messages/workspace_did_change_configuration.cc +++ b/src/messages/workspace_did_change_configuration.cc @@ -1,10 +1,13 @@ #include "cache_manager.h" +#include "clang_complete.h" #include "message_handler.h" #include "project.h" #include "queue_manager.h" #include "timer.h" #include "working_files.h" +#include + namespace { struct lsDidChangeConfigurationParams { bool placeholder; @@ -32,6 +35,9 @@ struct WorkspaceDidChangeConfigurationHandler std::monostate()); time.ResetAndPrint( "[perf] Dispatched workspace/didChangeConfiguration index requests"); + + clang_complete->FlushAllSessions(); + LOG_S(INFO) << "Flushed all clang complete sessions"; } }; REGISTER_MESSAGE_HANDLER(WorkspaceDidChangeConfigurationHandler);