clang-tools 8.0.0

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