Mercurial > hg > CbC > CbC_llvm
comparison clang-tools-extra/clangd/DraftStore.h @ 173:0572611fdcc8 llvm10 llvm12
reorgnization done
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 11:55:54 +0900 |
parents | 1d019706d866 |
children | 2e18cbf3894f |
comparison
equal
deleted
inserted
replaced
172:9fbae9c8bf63 | 173:0572611fdcc8 |
---|---|
7 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
8 | 8 |
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DRAFTSTORE_H | 9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DRAFTSTORE_H |
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DRAFTSTORE_H | 10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DRAFTSTORE_H |
11 | 11 |
12 #include "Path.h" | |
13 #include "Protocol.h" | 12 #include "Protocol.h" |
13 #include "support/Path.h" | |
14 #include "clang/Basic/LLVM.h" | 14 #include "clang/Basic/LLVM.h" |
15 #include "llvm/ADT/StringMap.h" | 15 #include "llvm/ADT/StringMap.h" |
16 #include <mutex> | 16 #include <mutex> |
17 #include <string> | 17 #include <string> |
18 #include <vector> | 18 #include <vector> |
21 namespace clangd { | 21 namespace clangd { |
22 | 22 |
23 /// A thread-safe container for files opened in a workspace, addressed by | 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 | 24 /// filenames. The contents are owned by the DraftStore. This class supports |
25 /// both whole and incremental updates of the documents. | 25 /// both whole and incremental updates of the documents. |
26 /// Each time a draft is updated, it is assigned a version number. This can be | |
27 /// specified by the caller or incremented from the previous version. | |
26 class DraftStore { | 28 class DraftStore { |
27 public: | 29 public: |
30 struct Draft { | |
31 std::string Contents; | |
32 int64_t Version = -1; | |
33 }; | |
34 | |
28 /// \return Contents of the stored document. | 35 /// \return Contents of the stored document. |
29 /// For untracked files, a llvm::None is returned. | 36 /// For untracked files, a llvm::None is returned. |
30 llvm::Optional<std::string> getDraft(PathRef File) const; | 37 llvm::Optional<Draft> getDraft(PathRef File) const; |
31 | 38 |
32 /// \return List of names of the drafts in this store. | 39 /// \return List of names of the drafts in this store. |
33 std::vector<Path> getActiveFiles() const; | 40 std::vector<Path> getActiveFiles() const; |
34 | 41 |
35 /// Replace contents of the draft for \p File with \p Contents. | 42 /// Replace contents of the draft for \p File with \p Contents. |
36 void addDraft(PathRef File, StringRef Contents); | 43 /// If no version is specified, one will be automatically assigned. |
44 /// Returns the version. | |
45 int64_t addDraft(PathRef File, llvm::Optional<int64_t> Version, | |
46 StringRef Contents); | |
37 | 47 |
38 /// Update the contents of the draft for \p File based on \p Changes. | 48 /// 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 | 49 /// If a position in \p Changes is invalid (e.g. out-of-range), the |
40 /// draft is not modified. | 50 /// draft is not modified. |
51 /// If no version is specified, one will be automatically assigned. | |
41 /// | 52 /// |
42 /// \return The new version of the draft for \p File, or an error if the | 53 /// \return The new version of the draft for \p File, or an error if the |
43 /// changes couldn't be applied. | 54 /// changes couldn't be applied. |
44 llvm::Expected<std::string> | 55 llvm::Expected<Draft> |
45 updateDraft(PathRef File, | 56 updateDraft(PathRef File, llvm::Optional<int64_t> Version, |
46 llvm::ArrayRef<TextDocumentContentChangeEvent> Changes); | 57 llvm::ArrayRef<TextDocumentContentChangeEvent> Changes); |
47 | 58 |
48 /// Remove the draft from the store. | 59 /// Remove the draft from the store. |
49 void removeDraft(PathRef File); | 60 void removeDraft(PathRef File); |
50 | 61 |
51 private: | 62 private: |
52 mutable std::mutex Mutex; | 63 mutable std::mutex Mutex; |
53 llvm::StringMap<std::string> Drafts; | 64 llvm::StringMap<Draft> Drafts; |
54 }; | 65 }; |
55 | 66 |
56 } // namespace clangd | 67 } // namespace clangd |
57 } // namespace clang | 68 } // namespace clang |
58 | 69 |