[clang-tools-extra] r363691 - [clangd] Return vector<TextEdit> from applyTweak. NFC

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 18 08:15:41 PDT 2019


Author: ibiryukov
Date: Tue Jun 18 08:15:41 2019
New Revision: 363691

URL: http://llvm.org/viewvc/llvm-project?rev=363691&view=rev
Log:
[clangd] Return vector<TextEdit> from applyTweak. NFC

For the same reasons as r363150, which got overwritten by changes in
r363680.

Sending without review to unbreak our integrate.

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=363691&r1=363690&r2=363691&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Jun 18 08:15:41 2019
@@ -491,14 +491,14 @@ void ClangdLSPServer::onCommand(const Ex
 
     auto Action = [this, ApplyEdit](decltype(Reply) Reply, URIForFile File,
                                     std::string Code,
-                                    llvm::Expected<Tweak::Effect> R) {
+                                    llvm::Expected<ResolvedEffect> R) {
       if (!R)
         return Reply(R.takeError());
 
       if (R->ApplyEdit) {
         WorkspaceEdit WE;
         WE.changes.emplace();
-        (*WE.changes)[File.uri()] = replacementsToEdits(Code, *R->ApplyEdit);
+        (*WE.changes)[File.uri()] = *R->ApplyEdit;
         ApplyEdit(std::move(WE));
       }
       if (R->ShowMessage) {

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=363691&r1=363690&r2=363691&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Jun 18 08:15:41 2019
@@ -325,7 +325,7 @@ void ClangdServer::enumerateTweaks(PathR
 }
 
 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
-                              Callback<Tweak::Effect> CB) {
+                              Callback<ResolvedEffect> CB) {
   auto Action = [Sel](decltype(CB) CB, std::string File, std::string TweakID,
                       Expected<InputsAndAST> InpAST) {
     if (!InpAST)
@@ -348,7 +348,13 @@ void ClangdServer::applyTweak(PathRef Fi
                                             *Effect->ApplyEdit, Style))
         Effect->ApplyEdit = std::move(*Formatted);
     }
-    return CB(std::move(*Effect));
+
+    ResolvedEffect R;
+    R.ShowMessage = std::move(Effect->ShowMessage);
+    if (Effect->ApplyEdit)
+      R.ApplyEdit =
+          replacementsToEdits(InpAST->Inputs.Contents, *Effect->ApplyEdit);
+    return CB(std::move(R));
   };
   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=363691&r1=363690&r2=363691&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Tue Jun 18 08:15:41 2019
@@ -57,6 +57,14 @@ public:
 using ClangTidyOptionsBuilder = std::function<tidy::ClangTidyOptions(
     llvm::vfs::FileSystem &, llvm::StringRef /*File*/)>;
 
+/// Like Tweak::Effect, but stores TextEdits instead of tooling::Replacements.
+/// Slightly nicer to embedders of ClangdServer.
+/// FIXME: figure out how to remove this duplication.
+struct ResolvedEffect {
+  llvm::Optional<std::string> ShowMessage;
+  llvm::Optional<std::vector<TextEdit>> ApplyEdit;
+};
+
 /// Manages a collection of source files and derived data (ASTs, indexes),
 /// and provides language-aware features such as code completion.
 ///
@@ -239,7 +247,7 @@ public:
 
   /// Apply the code tweak with a specified \p ID.
   void applyTweak(PathRef File, Range Sel, StringRef ID,
-                  Callback<Tweak::Effect> CB);
+                  Callback<ResolvedEffect> 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