mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-10-31 12:42:34 +00:00 
			
		
		
		
	Flush all clang-complete sessions on workspace/didChangeConfiguration
This commit is contained in:
		
							parent
							
								
									f137ec6a6d
								
							
						
					
					
						commit
						f17196e3da
					
				| @ -802,3 +802,17 @@ std::shared_ptr<CompletionSession> ClangCompleteManager::TryGetSession( | ||||
| 
 | ||||
|   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(); | ||||
| } | ||||
|  | ||||
| @ -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; | ||||
|  | ||||
| @ -13,11 +13,6 @@ void DiagnosticsEngine::Init(Config* config) { | ||||
| void DiagnosticsEngine::Publish(WorkingFiles* working_files, | ||||
|                                 std::string path, | ||||
|                                 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 = | ||||
|       std::chrono::duration_cast<std::chrono::milliseconds>( | ||||
|  | ||||
| @ -408,6 +408,12 @@ void ParseFile(Config* config, | ||||
|   for (std::unique_ptr<IndexFile>& 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.
 | ||||
|  | ||||
| @ -29,6 +29,9 @@ struct LruCache { | ||||
|   template <typename TFunc> | ||||
|   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<TKey, TValue>::IncrementScore() { | ||||
|       entry.score = next_score_++; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| template <typename TKey, typename TValue> | ||||
| void LruCache<TKey, TValue>::Clear(void) { | ||||
| 	entries_.clear(); | ||||
| 	next_score_ = 0; | ||||
| } | ||||
|  | ||||
| @ -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 <loguru.hpp> | ||||
| 
 | ||||
| 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); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user