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