clang-tools 10.0.0

DraftStore.h
Go to the documentation of this file.
1 //===--- DraftStore.h - File contents container -----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DRAFTSTORE_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DRAFTSTORE_H
11
12 #include "Path.h"
13 #include "Protocol.h"
14 #include "clang/Basic/LLVM.h"
15 #include "llvm/ADT/StringMap.h"
16 #include <mutex>
17 #include <string>
18 #include <vector>
19
20 namespace clang {
21 namespace clangd {
22
23 /// A thread-safe container for files opened in a workspace, addressed by
24 /// filenames. The contents are owned by the DraftStore. This class supports
25 /// both whole and incremental updates of the documents.
26 class DraftStore {
27 public:
28 /// \return Contents of the stored document.
29 /// For untracked files, a llvm::None is returned.
30 llvm::Optional<std::string> getDraft(PathRef File) const;
31
32 /// \return List of names of the drafts in this store.
33 std::vector<Path> getActiveFiles() const;
34
35 /// Replace contents of the draft for \p File with \p Contents.
36 void addDraft(PathRef File, StringRef Contents);
37
38 /// Update the contents of the draft for \p File based on \p Changes.
39 /// If a position in \p Changes is invalid (e.g. out-of-range), the
40 /// draft is not modified.
41 ///
42 /// \return The new version of the draft for \p File, or an error if the
43 /// changes couldn't be applied.
44 llvm::Expected<std::string>
45 updateDraft(PathRef File,
46 llvm::ArrayRef<TextDocumentContentChangeEvent> Changes);
47
48 /// Remove the draft from the store.
49 void removeDraft(PathRef File);
50
51 private:
52 mutable std::mutex Mutex;
53 llvm::StringMap<std::string> Drafts;
54 };
55
56 } // namespace clangd
57 } // namespace clang
58
59 #endif
Contents
llvm::StringRef Contents
Definition: CodeComplete.cpp:1021
Changes
tooling::Replacements Changes
Definition: Format.cpp:108
Protocol.h
clang::clangd::PathRef
llvm::StringRef PathRef
A typedef to represent a ref to file path.
Definition: Path.h:23
clang::clangd::DraftStore::addDraft
void addDraft(PathRef File, StringRef Contents)
Replace contents of the draft for File with Contents.
Definition: DraftStore.cpp:36
clang::clangd::DraftStore::updateDraft
llvm::Expected< std::string > updateDraft(PathRef File, llvm::ArrayRef< TextDocumentContentChangeEvent > Changes)
Update the contents of the draft for File based on Changes.
Definition: DraftStore.cpp:42
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
Path.h
clang::clangd::DraftStore
A thread-safe container for files opened in a workspace, addressed by filenames.
Definition: DraftStore.h:26
clang::clangd::DraftStore::getActiveFiles
std::vector< Path > getActiveFiles() const
Definition: DraftStore.cpp:26
clang::clangd::DraftStore::removeDraft
void removeDraft(PathRef File)
Remove the draft from the store.
Definition: DraftStore.cpp:111
clang::clangd::CompletionItemKind::File
clang::clangd::DraftStore::getDraft
llvm::Optional< std::string > getDraft(PathRef File) const
Definition: DraftStore.cpp:16