#pragma once #include "LSPDiagnosticsAggregator.h" #include #include #include #include #include namespace whetstone { class LSPErrorRecovery { public: void markCrashed(const std::string& source) { crashed_.insert(source); } void markRecovered(const std::string& source) { crashed_.erase(source); } // Unknown sources are healthy (optimistic default). bool isHealthy(const std::string& source) const { return crashed_.count(source) == 0; } std::vector healthySources( const std::vector& all) const { std::vector result; for (const auto& s : all) if (isHealthy(s)) result.push_back(s); return result; } void cacheDiagnostics(const std::string& source, const std::string& uri, const std::vector& diags) { cache_[{source, uri}] = diags; } // Returns cached diags if source is crashed, else empty. std::vector fallbackDiagnostics(const std::string& source, const std::string& uri) const { if (isHealthy(source)) return {}; auto it = cache_.find({source, uri}); if (it == cache_.end()) return {}; return it->second; } void clearCache(const std::string& source) { for (auto it = cache_.begin(); it != cache_.end(); ) { if (it->first.first == source) it = cache_.erase(it); else ++it; } } int crashedCount() const { return static_cast(crashed_.size()); } private: std::set crashed_; std::map, std::vector> cache_; }; } // namespace whetstone