Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame^] | 1 | //===--- 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 | |
| 12 | using namespace clang::clangd; |
| 13 | |
| 14 | VersionedDraft 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 | |
| 23 | DocVersion 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 | |
| 32 | DocVersion 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 | |
| 41 | DocVersion 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 | } |