[clang-tools-extra] r357561 - [clangd] Return clangd::TextEdit in ClangdServer::rename. NFC
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 3 00:18:43 PDT 2019
Author: ibiryukov
Date: Wed Apr 3 00:18:43 2019
New Revision: 357561
URL: http://llvm.org/viewvc/llvm-project?rev=357561&view=rev
Log:
[clangd] Return clangd::TextEdit in ClangdServer::rename. NFC
Summary:
Instead of tooling::Replacement. To avoid the need to have contents of
the file at the caller site. This also aligns better with other methods
in ClangdServer, majority of those already return LSP-specific data
types.
Reviewers: hokein, ioeric, sammccall
Reviewed By: sammccall
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D60179
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.h
Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=357561&r1=357560&r2=357561&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Apr 3 00:18:43 2019
@@ -541,19 +541,13 @@ void ClangdLSPServer::onRename(const Ren
Server->rename(
File, Params.position, Params.newName,
Bind(
- [File, Code, Params](
- decltype(Reply) Reply,
- llvm::Expected<std::vector<tooling::Replacement>> Replacements) {
- if (!Replacements)
- return Reply(Replacements.takeError());
+ [File, Code, Params](decltype(Reply) Reply,
+ llvm::Expected<std::vector<TextEdit>> Edits) {
+ if (!Edits)
+ return Reply(Edits.takeError());
- // Turn the replacements into the format specified by the Language
- // Server Protocol. Fuse them into one big JSON array.
- std::vector<TextEdit> Edits;
- for (const auto &R : *Replacements)
- Edits.push_back(replacementToEdit(*Code, R));
WorkspaceEdit WE;
- WE.changes = {{Params.textDocument.uri.uri(), Edits}};
+ WE.changes = {{Params.textDocument.uri.uri(), *Edits}};
Reply(WE);
},
std::move(Reply)));
Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=357561&r1=357560&r2=357561&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Apr 3 00:18:43 2019
@@ -280,9 +280,9 @@ ClangdServer::formatOnType(llvm::StringR
}
void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
- Callback<std::vector<tooling::Replacement>> CB) {
+ Callback<std::vector<TextEdit>> CB) {
auto Action = [Pos](Path File, std::string NewName,
- Callback<std::vector<tooling::Replacement>> CB,
+ Callback<std::vector<TextEdit>> CB,
llvm::Expected<InputsAndAST> InpAST) {
if (!InpAST)
return CB(InpAST.takeError());
@@ -306,7 +306,7 @@ void ClangdServer::rename(PathRef File,
if (!ResultCollector.Result.getValue())
return CB(ResultCollector.Result->takeError());
- std::vector<tooling::Replacement> Replacements;
+ std::vector<TextEdit> Replacements;
for (const tooling::AtomicChange &Change : ResultCollector.Result->get()) {
tooling::Replacements ChangeReps = Change.getReplacements();
for (const auto &Rep : ChangeReps) {
@@ -320,7 +320,8 @@ void ClangdServer::rename(PathRef File,
// * rename globally in project
// * rename in open files
if (Rep.getFilePath() == File)
- Replacements.push_back(Rep);
+ Replacements.push_back(
+ replacementToEdit(InpAST->Inputs.Contents, Rep));
}
}
return CB(std::move(Replacements));
Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=357561&r1=357560&r2=357561&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Wed Apr 3 00:18:43 2019
@@ -217,7 +217,7 @@ public:
/// Rename all occurrences of the symbol at the \p Pos in \p File to
/// \p NewName.
void rename(PathRef File, Position Pos, llvm::StringRef NewName,
- Callback<std::vector<tooling::Replacement>> CB);
+ Callback<std::vector<TextEdit>> CB);
struct TweakRef {
std::string ID; /// ID to pass for applyTweak.
Modified: clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp?rev=357561&r1=357560&r2=357561&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp Wed Apr 3 00:18:43 2019
@@ -98,10 +98,10 @@ runFindDocumentHighlights(ClangdServer &
return std::move(*Result);
}
-llvm::Expected<std::vector<tooling::Replacement>>
-runRename(ClangdServer &Server, PathRef File, Position Pos,
- llvm::StringRef NewName) {
- llvm::Optional<llvm::Expected<std::vector<tooling::Replacement>>> Result;
+llvm::Expected<std::vector<TextEdit>> runRename(ClangdServer &Server,
+ PathRef File, Position Pos,
+ llvm::StringRef NewName) {
+ llvm::Optional<llvm::Expected<std::vector<TextEdit>>> Result;
Server.rename(File, Pos, NewName, capture(Result));
return std::move(*Result);
}
Modified: clang-tools-extra/trunk/unittests/clangd/SyncAPI.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SyncAPI.h?rev=357561&r1=357560&r2=357561&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/SyncAPI.h (original)
+++ clang-tools-extra/trunk/unittests/clangd/SyncAPI.h Wed Apr 3 00:18:43 2019
@@ -38,7 +38,7 @@ runLocateSymbolAt(ClangdServer &Server,
llvm::Expected<std::vector<DocumentHighlight>>
runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos);
-llvm::Expected<std::vector<tooling::Replacement>>
+llvm::Expected<std::vector<TextEdit>>
runRename(ClangdServer &Server, PathRef File, Position Pos, StringRef NewName);
std::string runDumpAST(ClangdServer &Server, PathRef File);
More information about the cfe-commits
mailing list