LCOV - code coverage report
Current view: top level - clang/tools/extra/clangd - DraftStore.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 0 2 0.0 %
Date: 2017-09-14 15:23:50 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       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 "clang/Basic/LLVM.h"
      15             : #include "llvm/ADT/StringMap.h"
      16             : #include <mutex>
      17             : #include <string>
      18             : #include <vector>
      19             : 
      20             : namespace clang {
      21             : namespace clangd {
      22             : 
      23             : /// Using 'unsigned' here to avoid undefined behaviour on overflow.
      24             : typedef unsigned DocVersion;
      25             : 
      26             : /// Document draft with a version of this draft.
      27           0 : struct VersionedDraft {
      28             :   DocVersion Version;
      29             :   /// If the value of the field is None, draft is now deleted
      30             :   llvm::Optional<std::string> Draft;
      31             : };
      32             : 
      33             : /// A thread-safe container for files opened in a workspace, addressed by
      34             : /// filenames. The contents are owned by the DraftStore. Versions are mantained
      35             : /// for the all added documents, including removed ones. The document version is
      36             : /// incremented on each update and removal of the document.
      37           0 : class DraftStore {
      38             : public:
      39             :   /// \return version and contents of the stored document.
      40             :   /// For untracked files, a (0, None) pair is returned.
      41             :   VersionedDraft getDraft(PathRef File) const;
      42             :   /// \return version of the tracked document.
      43             :   /// For untracked files, 0 is returned.
      44             :   DocVersion getVersion(PathRef File) const;
      45             : 
      46             :   /// Replace contents of the draft for \p File with \p Contents.
      47             :   /// \return The new version of the draft for \p File.
      48             :   DocVersion updateDraft(PathRef File, StringRef Contents);
      49             :   /// Remove the contents of the draft
      50             :   /// \return The new version of the draft for \p File.
      51             :   DocVersion removeDraft(PathRef File);
      52             : 
      53             : private:
      54             :   mutable std::mutex Mutex;
      55             :   llvm::StringMap<VersionedDraft> Drafts;
      56             : };
      57             : 
      58             : } // namespace clangd
      59             : } // namespace clang
      60             : 
      61             : #endif

Generated by: LCOV version 1.13