diff options
-rw-r--r-- | clang-tools-extra/clangd/ClangdLSPServer.cpp | 4 | ||||
-rw-r--r-- | clang-tools-extra/clangd/ClangdServer.cpp | 10 | ||||
-rw-r--r-- | clang-tools-extra/clangd/ClangdServer.h | 10 |
3 files changed, 19 insertions, 5 deletions
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index 353d387d132..7eaacd26e55 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -491,14 +491,14 @@ void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params, 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) { diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 294810f1c46..46ab61393b2 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -325,7 +325,7 @@ void ClangdServer::enumerateTweaks(PathRef File, Range Sel, } 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 File, Range Sel, StringRef TweakID, *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, diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h index db6ed2d2f87..5fe9e9f54bb 100644 --- a/clang-tools-extra/clangd/ClangdServer.h +++ b/clang-tools-extra/clangd/ClangdServer.h @@ -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 |