11 #include "llvm/Support/Errc.h" 17 std::lock_guard<std::mutex> Lock(Mutex);
19 auto It = Drafts.find(File);
20 if (It == Drafts.end())
27 std::lock_guard<std::mutex> Lock(Mutex);
28 std::vector<Path> ResultVector;
30 for (
auto DraftIt = Drafts.begin(); DraftIt != Drafts.end(); DraftIt++)
31 ResultVector.push_back(DraftIt->getKey());
37 std::lock_guard<std::mutex> Lock(Mutex);
44 std::lock_guard<std::mutex> Lock(Mutex);
46 auto EntryIt = Drafts.find(File);
47 if (EntryIt == Drafts.end()) {
48 return llvm::make_error<llvm::StringError>(
49 "Trying to do incremental update on non-added document: " +
File,
50 llvm::errc::invalid_argument);
53 std::string
Contents = EntryIt->second;
57 Contents = Change.text;
61 const Position &Start = Change.range->start;
62 llvm::Expected<size_t> StartIndex =
65 return StartIndex.takeError();
67 const Position &End = Change.range->end;
70 return EndIndex.takeError();
72 if (*EndIndex < *StartIndex)
73 return llvm::make_error<llvm::StringError>(
75 "Range's end position ({0}) is before start position ({1})", End,
77 llvm::errc::invalid_argument);
86 ssize_t ComputedRangeLength =
87 lspLength(Contents.substr(*StartIndex, *EndIndex - *StartIndex));
89 if (Change.rangeLength && ComputedRangeLength != *Change.rangeLength)
90 return llvm::make_error<llvm::StringError>(
91 llvm::formatv(
"Change's rangeLength ({0}) doesn't match the " 92 "computed range length ({1}).",
93 *Change.rangeLength, *EndIndex - *StartIndex),
94 llvm::errc::invalid_argument);
96 std::string NewContents;
97 NewContents.reserve(*StartIndex + Change.text.length() +
98 (Contents.length() - *EndIndex));
100 NewContents = Contents.substr(0, *StartIndex);
101 NewContents += Change.text;
102 NewContents += Contents.substr(*EndIndex);
104 Contents = std::move(NewContents);
112 std::lock_guard<std::mutex> Lock(Mutex);
size_t lspLength(llvm::StringRef Code)
llvm::StringRef PathRef
A typedef to represent a ref to file path.
void addDraft(PathRef File, StringRef Contents)
Replace contents of the draft for File with Contents.
Documents should not be synced at all.
llvm::Expected< std::string > updateDraft(PathRef File, llvm::ArrayRef< TextDocumentContentChangeEvent > Changes)
Update the contents of the draft for File based on Changes.
llvm::Expected< size_t > positionToOffset(llvm::StringRef Code, Position P, bool AllowColumnsBeyondLineLength)
Turn a [line, column] pair into an offset in Code.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::vector< Path > getActiveFiles() const
void removeDraft(PathRef File)
Remove the draft from the store.
llvm::Optional< std::string > getDraft(PathRef File) const