11#include "llvm/ADT/StringExtras.h"
12#include "llvm/Support/VirtualFileSystem.h"
20 std::lock_guard<std::mutex> Lock(Mutex);
22 auto It = Drafts.find(
File);
23 if (It == Drafts.end())
30 std::lock_guard<std::mutex> Lock(Mutex);
31 std::vector<Path> ResultVector;
33 for (
auto DraftIt = Drafts.begin(); DraftIt != Drafts.end(); DraftIt++)
34 ResultVector.push_back(std::string(DraftIt->getKey()));
41 if (S.empty() || !llvm::isDigit(S.back())) {
46 auto I = S.rbegin(),
E = S.rend();
48 if (I ==
E || !llvm::isDigit(*I)) {
50 S.insert(I.base(),
'1');
63 llvm::StringRef SpecifiedVersion) {
64 if (!SpecifiedVersion.empty()) {
66 if (SpecifiedVersion.compare_numeric(D.Version) <= 0)
67 log(
"File version went from {0} to {1}", D.Version, SpecifiedVersion);
68 D.Version = SpecifiedVersion.str();
76 llvm::StringRef Contents) {
77 std::lock_guard<std::mutex> Lock(Mutex);
79 auto &D = Drafts[
File];
82 D.D.Contents = std::make_shared<std::string>(Contents);
87 std::lock_guard<std::mutex> Lock(Mutex);
96class SharedStringBuffer :
public llvm::MemoryBuffer {
97 const std::shared_ptr<const std::string> BufferContents;
98 const std::string
Name;
101 BufferKind getBufferKind()
const override {
102 return MemoryBuffer::MemoryBuffer_Malloc;
105 StringRef getBufferIdentifier()
const override {
return Name; }
107 SharedStringBuffer(std::shared_ptr<const std::string> Data, StringRef Name)
108 : BufferContents(std::move(Data)),
Name(
Name) {
109 assert(BufferContents &&
"Can't create from empty shared_ptr");
110 MemoryBuffer::init(BufferContents->c_str(),
111 BufferContents->c_str() + BufferContents->size(),
118 auto MemFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
119 std::lock_guard<std::mutex> Guard(Mutex);
120 for (
const auto &
Draft : Drafts)
121 MemFS->addFile(
Draft.getKey(),
Draft.getValue().MTime,
122 std::make_unique<SharedStringBuffer>(
llvm::SmallString< 256U > Name
std::vector< Path > getActiveFiles() const
std::optional< Draft > getDraft(PathRef File) const
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > asVFS() const
void removeDraft(PathRef File)
Remove the draft from the store.
std::string addDraft(PathRef File, llvm::StringRef Version, StringRef Contents)
Replace contents of the draft for File with Contents.
static void updateVersion(DraftStore::Draft &D, llvm::StringRef SpecifiedVersion)
static void increment(std::string &S)
void log(const char *Fmt, Ts &&... Vals)
llvm::StringRef PathRef
A typedef to represent a ref to file path.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::shared_ptr< const std::string > Contents