| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "LibLsp/lsp/lsp_diagnostic.h" |
| 4 |
#include "LibLsp/lsp/AbsolutePath.h" |
| 5 |
#include "LibLsp/lsp/textDocument/did_change.h" |
| 6 |
#include "LibLsp/lsp/textDocument/did_close.h" |
| 7 |
#include "LibLsp/lsp/textDocument/did_open.h" |
| 8 |
#include <mutex> |
| 9 |
#include <string> |
| 10 |
#include <memory> |
| 11 |
#include "Directory.h" |
| 12 |
|
| 13 |
struct WorkingFiles; |
| 14 |
struct WorkingFilesData; |
| 15 |
struct WorkingFile |
| 16 |
{ |
| 17 |
|
| 18 |
int version = 0; |
| 19 |
AbsolutePath filename; |
| 20 |
Directory directory; |
| 21 |
WorkingFiles& parent; |
| 22 |
std::atomic<long long> counter; |
| 23 |
WorkingFile(WorkingFiles&, AbsolutePath const& filename, std::string const& buffer_content); |
| 24 |
WorkingFile(WorkingFiles&, AbsolutePath const& filename, std::string&& buffer_content); |
| 25 |
std::string const& GetContentNoLock() const |
| 26 |
{ |
| 27 |
return buffer_content; |
| 28 |
} |
| 29 |
|
| 30 |
protected: |
| 31 |
friend struct WorkingFiles; |
| 32 |
std::string buffer_content; |
| 33 |
}; |
| 34 |
|
| 35 |
struct WorkingFiles |
| 36 |
{ |
| 37 |
|
| 38 |
WorkingFiles(); |
| 39 |
~WorkingFiles(); |
| 40 |
|
| 41 |
void CloseFilesInDirectory(std::vector<Directory> const&); |
| 42 |
std::shared_ptr<WorkingFile> OnOpen(lsTextDocumentItem& open); |
| 43 |
std::shared_ptr<WorkingFile> OnChange(lsTextDocumentDidChangeParams const& change); |
| 44 |
bool OnClose(lsTextDocumentIdentifier const& close); |
| 45 |
std::shared_ptr<WorkingFile> OnSave(lsTextDocumentIdentifier const& _save); |
| 46 |
|
| 47 |
bool GetFileBufferContent(AbsolutePath const& filename, std::wstring& out) |
| 48 |
{ |
| 49 |
auto file = GetFileByFilename(filename); |
| 50 |
if (!file) |
| 51 |
{ |
| 52 |
return false; |
| 53 |
} |
| 54 |
return GetFileBufferContent(file, out); |
| 55 |
} |
| 56 |
bool GetFileBufferContent(AbsolutePath const& filename, std::string& out) |
| 57 |
{ |
| 58 |
auto file = GetFileByFilename(filename); |
| 59 |
if (!file) |
| 60 |
{ |
| 61 |
return false; |
| 62 |
} |
| 63 |
return GetFileBufferContent(file, out); |
| 64 |
} |
| 65 |
bool GetFileBufferContent(std::shared_ptr<WorkingFile>&, std::string& out); |
| 66 |
bool GetFileBufferContent(std::shared_ptr<WorkingFile>&, std::wstring& out); |
| 67 |
|
| 68 |
// Find the file with the given filename. |
| 69 |
std::shared_ptr<WorkingFile> GetFileByFilename(AbsolutePath const& filename); |
| 70 |
|
| 71 |
void Clear(); |
| 72 |
|
| 73 |
private: |
| 74 |
std::shared_ptr<WorkingFile> GetFileByFilenameNoLock(AbsolutePath const& filename); |
| 75 |
|
| 76 |
WorkingFilesData* d_ptr; |
| 77 |
}; |