Flush all clang-complete sessions on workspace/didChangeConfiguration

This commit is contained in:
Elliot Berman 2018-03-20 08:33:02 -04:00 committed by Jacob Dufault
parent f137ec6a6d
commit f17196e3da
6 changed files with 40 additions and 5 deletions

View File

@ -802,3 +802,17 @@ std::shared_ptr<CompletionSession> ClangCompleteManager::TryGetSession(
return completion_session; return completion_session;
} }
void ClangCompleteManager::FlushSession(const std::string& filename) {
std::lock_guard<std::mutex> lock(sessions_lock_);
preloaded_sessions_.TryTake(filename);
completion_sessions_.TryTake(filename);
}
void ClangCompleteManager::FlushAllSessions() {
std::lock_guard<std::mutex> lock(sessions_lock_);
preloaded_sessions_.Clear();
completion_sessions_.Clear();
}

View File

@ -110,6 +110,11 @@ struct ClangCompleteManager {
bool mark_as_completion, bool mark_as_completion,
bool create_if_needed); 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. // TODO: make these configurable.
const int kMaxPreloadedSessions = 10; const int kMaxPreloadedSessions = 10;
const int kMaxCompletionSessions = 5; const int kMaxCompletionSessions = 5;

View File

@ -13,11 +13,6 @@ void DiagnosticsEngine::Init(Config* config) {
void DiagnosticsEngine::Publish(WorkingFiles* working_files, void DiagnosticsEngine::Publish(WorkingFiles* working_files,
std::string path, std::string path,
std::vector<lsDiagnostic> diagnostics) { std::vector<lsDiagnostic> 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 = int64_t now =
std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::duration_cast<std::chrono::milliseconds>(

View File

@ -408,6 +408,12 @@ void ParseFile(Config* config,
for (std::unique_ptr<IndexFile>& new_index : *indexes) { for (std::unique_ptr<IndexFile>& new_index : *indexes) {
Timer time; 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 // Only emit diagnostics for non-interactive sessions, which makes it easier
// to identify indexing problems. For interactive sessions, diagnostics are // to identify indexing problems. For interactive sessions, diagnostics are
// handled by code completion. // handled by code completion.

View File

@ -29,6 +29,9 @@ struct LruCache {
template <typename TFunc> template <typename TFunc>
void IterateValues(TFunc func); void IterateValues(TFunc func);
// Empties the cache
void Clear(void);
private: private:
// There is a global score counter, when we access an element we increase // 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 // its score to the current global value, so it has the highest overall
@ -124,3 +127,9 @@ void LruCache<TKey, TValue>::IncrementScore() {
entry.score = next_score_++; entry.score = next_score_++;
} }
} }
template <typename TKey, typename TValue>
void LruCache<TKey, TValue>::Clear(void) {
entries_.clear();
next_score_ = 0;
}

View File

@ -1,10 +1,13 @@
#include "cache_manager.h" #include "cache_manager.h"
#include "clang_complete.h"
#include "message_handler.h" #include "message_handler.h"
#include "project.h" #include "project.h"
#include "queue_manager.h" #include "queue_manager.h"
#include "timer.h" #include "timer.h"
#include "working_files.h" #include "working_files.h"
#include <loguru.hpp>
namespace { namespace {
struct lsDidChangeConfigurationParams { struct lsDidChangeConfigurationParams {
bool placeholder; bool placeholder;
@ -32,6 +35,9 @@ struct WorkspaceDidChangeConfigurationHandler
std::monostate()); std::monostate());
time.ResetAndPrint( time.ResetAndPrint(
"[perf] Dispatched workspace/didChangeConfiguration index requests"); "[perf] Dispatched workspace/didChangeConfiguration index requests");
clang_complete->FlushAllSessions();
LOG_S(INFO) << "Flushed all clang complete sessions";
} }
}; };
REGISTER_MESSAGE_HANDLER(WorkspaceDidChangeConfigurationHandler); REGISTER_MESSAGE_HANDLER(WorkspaceDidChangeConfigurationHandler);