[clang-tools-extra] r363150 - [clangd] Return TextEdits from ClangdServer::applyTweak

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 12 05:03:24 PDT 2019


Author: ibiryukov
Date: Wed Jun 12 05:03:24 2019
New Revision: 363150

URL: http://llvm.org/viewvc/llvm-project?rev=363150&view=rev
Log:
[clangd] Return TextEdits from ClangdServer::applyTweak

Summary:
Instead of `tooling::Replacements`. So that embedders do not need to store
the contents of the file.

This also aligns better with `ClangdServer::rename`.

Reviewers: kadircet, hokein

Reviewed By: hokein

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63140

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

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=363150&r1=363149&r2=363150&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Jun 12 05:03:24 2019
@@ -482,13 +482,13 @@ void ClangdLSPServer::onCommand(const Ex
 
     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));

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=363150&r1=363149&r2=363150&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Jun 12 05:03:24 2019
@@ -321,7 +321,7 @@ void ClangdServer::enumerateTweaks(PathR
 }
 
 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 @@ void ClangdServer::applyTweak(PathRef Fi
     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,

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=363150&r1=363149&r2=363150&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Wed Jun 12 05:03:24 2019
@@ -234,7 +234,7 @@ public:
 
   /// 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




More information about the cfe-commits mailing list