blob: 3455699a83b16575e919ed9ac3decd8cf472db14 [file] [log] [blame]
Ilya Biryukov38d79772017-05-16 09:38:59 +00001//===--- DraftStore.cpp - 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#include "DraftStore.h"
11
12using namespace clang::clangd;
13
14VersionedDraft DraftStore::getDraft(PathRef File) const {
15 std::lock_guard<std::mutex> Lock(Mutex);
16
17 auto It = Drafts.find(File);
18 if (It == Drafts.end())
19 return {0, llvm::None};
20 return It->second;
21}
22
23DocVersion DraftStore::getVersion(PathRef File) const {
24 std::lock_guard<std::mutex> Lock(Mutex);
25
26 auto It = Drafts.find(File);
27 if (It == Drafts.end())
28 return 0;
29 return It->second.Version;
30}
31
32DocVersion DraftStore::updateDraft(PathRef File, StringRef Contents) {
33 std::lock_guard<std::mutex> Lock(Mutex);
34
35 auto &Entry = Drafts[File];
36 DocVersion NewVersion = ++Entry.Version;
37 Entry.Draft = Contents;
38 return NewVersion;
39}
40
41DocVersion DraftStore::removeDraft(PathRef File) {
42 std::lock_guard<std::mutex> Lock(Mutex);
43
44 auto &Entry = Drafts[File];
45 DocVersion NewVersion = ++Entry.Version;
46 Entry.Draft = llvm::None;
47 return NewVersion;
48}