annotate clang-tools-extra/clangd/DraftStore.h @ 150:1d019706d866

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