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 1 0.0 %
Date: 2018-02-25 19:55:18 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 <cstdint>
      17             : #include <mutex>
      18             : #include <string>
      19             : #include <vector>
      20             : 
      21             : namespace clang {
      22             : namespace clangd {
      23             : 
      24             : /// Using unsigned int type here to avoid undefined behaviour on overflow.
      25             : typedef uint64_t DocVersion;
      26             : 
      27             : /// Document draft with a version of this draft.
      28             : struct VersionedDraft {
      29             :   DocVersion Version;
      30             :   /// If the value of the field is None, draft is now deleted
      31             :   llvm::Optional<std::string> Draft;
      32             : };
      33             : 
      34             : /// A thread-safe container for files opened in a workspace, addressed by
      35             : /// filenames. The contents are owned by the DraftStore. Versions are mantained
      36             : /// for the all added documents, including removed ones. The document version is
      37             : /// incremented on each update and removal of the document.
      38           0 : class DraftStore {
      39             : public:
      40             :   /// \return version and contents of the stored document.
      41             :   /// For untracked files, a (0, None) pair is returned.
      42             :   VersionedDraft getDraft(PathRef File) const;
      43             : 
      44             :   /// \return List of names of active drafts in this store.  Drafts that were
      45             :   /// removed (which still have an entry in the Drafts map) are not returned by
      46             :   /// this function.
      47             :   std::vector<Path> getActiveFiles() const;
      48             : 
      49             :   /// \return version of the tracked document.
      50             :   /// For untracked files, 0 is returned.
      51             :   DocVersion getVersion(PathRef File) const;
      52             : 
      53             :   /// Replace contents of the draft for \p File with \p Contents.
      54             :   /// \return The new version of the draft for \p File.
      55             :   DocVersion updateDraft(PathRef File, StringRef Contents);
      56             :   /// Remove the contents of the draft
      57             :   /// \return The new version of the draft for \p File.
      58             :   DocVersion removeDraft(PathRef File);
      59             : 
      60             : private:
      61             :   mutable std::mutex Mutex;
      62             :   llvm::StringMap<VersionedDraft> Drafts;
      63             : };
      64             : 
      65             : } // namespace clangd
      66             : } // namespace clang
      67             : 
      68             : #endif

Generated by: LCOV version 1.13