summaryrefslogtreecommitdiff
path: root/graphics/asymptote/LspCpp/include/LibLsp/lsp/working_files.h
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-02-06 03:01:17 +0000
committerNorbert Preining <norbert@preining.info>2022-02-06 03:01:17 +0000
commit350b3e35109171f0edd6fe9d697b91d5e76561f9 (patch)
treec6eac90d0b35dec36fa17ee58b736e55d6e42755 /graphics/asymptote/LspCpp/include/LibLsp/lsp/working_files.h
parent08ccf305ee79ab8e5ba9d1a8f3d22e74dccedd80 (diff)
CTAN sync 202202060301
Diffstat (limited to 'graphics/asymptote/LspCpp/include/LibLsp/lsp/working_files.h')
-rw-r--r--graphics/asymptote/LspCpp/include/LibLsp/lsp/working_files.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/graphics/asymptote/LspCpp/include/LibLsp/lsp/working_files.h b/graphics/asymptote/LspCpp/include/LibLsp/lsp/working_files.h
new file mode 100644
index 0000000000..e305fee8d0
--- /dev/null
+++ b/graphics/asymptote/LspCpp/include/LibLsp/lsp/working_files.h
@@ -0,0 +1,72 @@
+#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 <mutex>
+#include <string>
+#include <memory>
+#include "Directory.h"
+
+struct WorkingFiles;
+struct WorkingFilesData;
+struct WorkingFile {
+
+ int version = 0;
+ AbsolutePath filename;
+ Directory directory;
+ WorkingFiles& parent;
+ std::atomic<long long> 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<Directory>&);
+ std::shared_ptr<WorkingFile> OnOpen(lsTextDocumentItem& open);
+ std::shared_ptr<WorkingFile> OnChange(const lsTextDocumentDidChangeParams& change);
+ bool OnClose(const lsTextDocumentIdentifier& close);
+ std::shared_ptr<WorkingFile> 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<WorkingFile>&, std::string& out);
+ bool GetFileBufferContent(std::shared_ptr<WorkingFile>&, std::wstring& out);
+
+
+ // Find the file with the given filename.
+ std::shared_ptr<WorkingFile> GetFileByFilename(const AbsolutePath& filename);
+
+ void Clear();
+private:
+ std::shared_ptr<WorkingFile> GetFileByFilenameNoLock(const AbsolutePath& filename);
+
+ WorkingFilesData* d_ptr;
+
+
+};