#pragma once #include "LibLsp/lsp/lsp_diagnostic.h" #include "LibLsp/lsp/AbsolutePath.h" #include "LibLsp/lsp/textDocument/did_change.h" #include "LibLsp/lsp/textDocument/did_close.h" #include "LibLsp/lsp/textDocument/did_open.h" #include #include #include #include "Directory.h" struct WorkingFiles; struct WorkingFilesData; struct WorkingFile { int version = 0; AbsolutePath filename; Directory directory; WorkingFiles& parent; std::atomic counter; WorkingFile(WorkingFiles& ,const AbsolutePath& filename, const std::string& buffer_content); WorkingFile(WorkingFiles&, const AbsolutePath& filename, std::string&& buffer_content); const std::string& GetContentNoLock() const { return buffer_content; } protected: friend struct WorkingFiles; std::string buffer_content; }; struct WorkingFiles { WorkingFiles(); ~WorkingFiles(); void CloseFilesInDirectory(const std::vector&); std::shared_ptr OnOpen(lsTextDocumentItem& open); std::shared_ptr OnChange(const lsTextDocumentDidChangeParams& change); bool OnClose(const lsTextDocumentIdentifier& close); std::shared_ptr OnSave(const lsTextDocumentIdentifier& _save); bool GetFileBufferContent(const AbsolutePath& filename, std::wstring& out) { auto file = GetFileByFilename(filename); if(!file) return false; return GetFileBufferContent(file, out); } bool GetFileBufferContent(const AbsolutePath& filename,std::string& out) { auto file = GetFileByFilename(filename); if (!file) return false; return GetFileBufferContent(file, out); } bool GetFileBufferContent(std::shared_ptr&, std::string& out); bool GetFileBufferContent(std::shared_ptr&, std::wstring& out); // Find the file with the given filename. std::shared_ptr GetFileByFilename(const AbsolutePath& filename); void Clear(); private: std::shared_ptr GetFileByFilenameNoLock(const AbsolutePath& filename); WorkingFilesData* d_ptr; };