diff clang-tools-extra/clangd/DraftStore.h @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
line wrap: on
line diff
--- a/clang-tools-extra/clangd/DraftStore.h	Mon May 25 11:50:15 2020 +0900
+++ b/clang-tools-extra/clangd/DraftStore.h	Mon May 25 11:55:54 2020 +0900
@@ -9,8 +9,8 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DRAFTSTORE_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DRAFTSTORE_H
 
-#include "Path.h"
 #include "Protocol.h"
+#include "support/Path.h"
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringMap.h"
 #include <mutex>
@@ -23,26 +23,37 @@
 /// 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
+/// specified by the caller or incremented from the previous version.
 class DraftStore {
 public:
+  struct Draft {
+    std::string Contents;
+    int64_t Version = -1;
+  };
+
   /// \return Contents of the stored document.
   /// For untracked files, a llvm::None is returned.
-  llvm::Optional<std::string> getDraft(PathRef File) const;
+  llvm::Optional<Draft> getDraft(PathRef File) const;
 
   /// \return List of names of the drafts in this store.
   std::vector<Path> getActiveFiles() const;
 
   /// Replace contents of the draft for \p File with \p Contents.
-  void addDraft(PathRef File, StringRef Contents);
+  /// If no version is specified, 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<std::string>
-  updateDraft(PathRef File,
+  llvm::Expected<Draft>
+  updateDraft(PathRef File, llvm::Optional<int64_t> Version,
               llvm::ArrayRef<TextDocumentContentChangeEvent> Changes);
 
   /// Remove the draft from the store.
@@ -50,7 +61,7 @@
 
 private:
   mutable std::mutex Mutex;
-  llvm::StringMap<std::string> Drafts;
+  llvm::StringMap<Draft> Drafts;
 };
 
 } // namespace clangd