[PATCH] D63140: [clangd] Return TextEdits from ClangdServer::applyTweak

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 12 05:00:09 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL363150: [clangd] Return TextEdits from ClangdServer::applyTweak (authored by ibiryukov, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63140?vs=204067&id=204264#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63140/new/

https://reviews.llvm.org/D63140

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h


Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
@@ -482,13 +482,13 @@
 
     auto Action = [ApplyEdit](decltype(Reply) Reply, URIForFile File,
                               std::string Code,
-                              llvm::Expected<tooling::Replacements> R) {
+                              llvm::Expected<std::vector<TextEdit>> R) {
       if (!R)
         return Reply(R.takeError());
 
       WorkspaceEdit WE;
       WE.changes.emplace();
-      (*WE.changes)[File.uri()] = replacementsToEdits(Code, *R);
+      (*WE.changes)[File.uri()] = std::move(*R);
 
       Reply("Fix applied.");
       ApplyEdit(std::move(WE));
Index: clang-tools-extra/trunk/clangd/ClangdServer.h
===================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.h
+++ clang-tools-extra/trunk/clangd/ClangdServer.h
@@ -234,7 +234,7 @@
 
   /// Apply the code tweak with a specified \p ID.
   void applyTweak(PathRef File, Range Sel, StringRef ID,
-                  Callback<tooling::Replacements> CB);
+                  Callback<std::vector<TextEdit>> CB);
 
   /// Only for testing purposes.
   /// Waits until all requests to worker thread are finished and dumps AST for
Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -321,7 +321,7 @@
 }
 
 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
-                              Callback<tooling::Replacements> CB) {
+                              Callback<std::vector<TextEdit>> CB) {
   auto Action = [Sel](decltype(CB) CB, std::string File, std::string TweakID,
                       Expected<InputsAndAST> InpAST) {
     if (!InpAST)
@@ -332,15 +332,18 @@
     auto A = prepareTweak(TweakID, *Selection);
     if (!A)
       return CB(A.takeError());
-    auto RawReplacements = (*A)->apply(*Selection);
-    if (!RawReplacements)
-      return CB(RawReplacements.takeError());
+    auto Raw = (*A)->apply(*Selection);
+    if (!Raw)
+      return CB(Raw.takeError());
     // FIXME: this function has I/O operations (find .clang-format file), figure
     // out a way to cache the format style.
     auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
                                        InpAST->Inputs.FS.get());
-    return CB(
-        cleanupAndFormat(InpAST->Inputs.Contents, *RawReplacements, Style));
+    auto Formatted =
+        cleanupAndFormat(InpAST->Inputs.Contents, *Raw, Style);
+    if (!Formatted)
+      return CB(Formatted.takeError());
+    return CB(replacementsToEdits(InpAST->Inputs.Contents, *Formatted));
   };
   WorkScheduler.runWithAST(
       "ApplyTweak", File,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63140.204264.patch
Type: text/x-patch
Size: 2995 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190612/100cb40b/attachment.bin>


More information about the llvm-commits mailing list