diff clang-tools-extra/clangd/DraftStore.h @ 221:79ff65ed7e25

LLVM12 Original
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:15:29 +0900
parents 0572611fdcc8
children c4bab56944e8
line wrap: on
line diff
--- a/clang-tools-extra/clangd/DraftStore.h	Tue Jun 15 19:13:43 2021 +0900
+++ b/clang-tools-extra/clangd/DraftStore.h	Tue Jun 15 19:15:29 2021 +0900
@@ -13,6 +13,7 @@
 #include "support/Path.h"
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include <mutex>
 #include <string>
 #include <vector>
@@ -21,15 +22,14 @@
 namespace clangd {
 
 /// A thread-safe container for files opened in a workspace, addressed by
-/// filenames. The contents are owned by the DraftStore. This class supports
-/// both whole and incremental updates of the documents.
-/// Each time a draft is updated, it is assigned a version number. This can be
+/// filenames. The contents are owned by the DraftStore.
+/// Each time a draft is updated, it is assigned a version. This can be
 /// specified by the caller or incremented from the previous version.
 class DraftStore {
 public:
   struct Draft {
-    std::string Contents;
-    int64_t Version = -1;
+    std::shared_ptr<const std::string> Contents;
+    std::string Version;
   };
 
   /// \return Contents of the stored document.
@@ -40,28 +40,23 @@
   std::vector<Path> getActiveFiles() const;
 
   /// Replace contents of the draft for \p File with \p Contents.
-  /// If no version is specified, one will be automatically assigned.
+  /// If version is empty, one will be automatically assigned.
   /// Returns the version.
-  int64_t addDraft(PathRef File, llvm::Optional<int64_t> Version,
-                   StringRef Contents);
-
-  /// Update the contents of the draft for \p File based on \p Changes.
-  /// If a position in \p Changes is invalid (e.g. out-of-range), the
-  /// draft is not modified.
-  /// If no version is specified, one will be automatically assigned.
-  ///
-  /// \return The new version of the draft for \p File, or an error if the
-  /// changes couldn't be applied.
-  llvm::Expected<Draft>
-  updateDraft(PathRef File, llvm::Optional<int64_t> Version,
-              llvm::ArrayRef<TextDocumentContentChangeEvent> Changes);
+  std::string addDraft(PathRef File, llvm::StringRef Version,
+                       StringRef Contents);
 
   /// Remove the draft from the store.
   void removeDraft(PathRef File);
 
+  llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> asVFS() const;
+
 private:
+  struct DraftAndTime {
+    Draft D;
+    std::time_t MTime;
+  };
   mutable std::mutex Mutex;
-  llvm::StringMap<Draft> Drafts;
+  llvm::StringMap<DraftAndTime> Drafts;
 };
 
 } // namespace clangd