11#include "llvm/ADT/StringExtras.h"
12#include "llvm/Support/VirtualFileSystem.h"
19 std::lock_guard<std::mutex>
Lock(Mutex);
21 auto It = Drafts.find(
File);
22 if (
It == Drafts.end())
29 std::lock_guard<std::mutex>
Lock(Mutex);
38static void increment(std::string &
S) {
40 if (
S.empty() || !llvm::isDigit(
S.back())) {
45 auto I =
S.rbegin(), E =
S.rend();
47 if (
I == E || !llvm::isDigit(*
I)) {
49 S.insert(
I.base(),
'1');
66 elog(
"unexpected non-numeric version {0}",
Encoded);
89 llvm::StringRef Contents) {
90 std::lock_guard<std::mutex>
Lock(Mutex);
92 auto &D = Drafts[
File];
93 updateVersion(D.D, Version);
95 D.D.
Contents = std::make_shared<std::string>(Contents);
100 std::lock_guard<std::mutex>
Lock(Mutex);
109class SharedStringBuffer :
public llvm::MemoryBuffer {
110 const std::shared_ptr<const std::string> BufferContents;
111 const std::string Name;
115 return MemoryBuffer::MemoryBuffer_Malloc;
120 SharedStringBuffer(std::shared_ptr<const std::string>
Data,
121 llvm::StringRef Name)
122 : BufferContents(std::
move(
Data)), Name(Name) {
123 assert(BufferContents &&
"Can't create from empty shared_ptr");
124 MemoryBuffer::init(BufferContents->c_str(),
125 BufferContents->c_str() + BufferContents->size(),
132 auto MemFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
133 std::lock_guard<std::mutex>
Guard(Mutex);
134 for (
const auto &
Draft : Drafts)
136 std::make_unique<SharedStringBuffer>(
static std::string encodeVersion(std::optional< int64_t > LSPVersion)
std::vector< Path > getActiveFiles() const
std::optional< Draft > getDraft(PathRef File) const
void removeDraft(PathRef File)
Remove the draft from the store.
std::string addDraft(PathRef File, llvm::StringRef Version, llvm::StringRef Contents)
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > asVFS() const
static std::optional< int64_t > decodeVersion(llvm::StringRef Encoded)
Whether current platform treats paths case insensitively.
bool fromJSON(const llvm::json::Value &, URIForFile &, llvm::json::Path)
void elog(const char *Fmt, Ts &&...Vals)
void log(const char *Fmt, Ts &&...Vals)
std::shared_ptr< const std::string > Contents