Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp @@ -541,19 +541,13 @@ Server->rename( File, Params.position, Params.newName, Bind( - [File, Code, Params]( - decltype(Reply) Reply, - llvm::Expected> Replacements) { - if (!Replacements) - return Reply(Replacements.takeError()); - - // Turn the replacements into the format specified by the Language - // Server Protocol. Fuse them into one big JSON array. - std::vector Edits; - for (const auto &R : *Replacements) - Edits.push_back(replacementToEdit(*Code, R)); + [File, Code, Params](decltype(Reply) Reply, + llvm::Expected> Edits) { + if (!Edits) + return Reply(Edits.takeError()); + WorkspaceEdit WE; - WE.changes = {{Params.textDocument.uri.uri(), Edits}}; + WE.changes = {{Params.textDocument.uri.uri(), *Edits}}; Reply(WE); }, std::move(Reply))); Index: clang-tools-extra/trunk/clangd/ClangdServer.h =================================================================== --- clang-tools-extra/trunk/clangd/ClangdServer.h +++ clang-tools-extra/trunk/clangd/ClangdServer.h @@ -217,7 +217,7 @@ /// 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> CB); + Callback> CB); struct TweakRef { std::string ID; /// ID to pass for applyTweak. Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ClangdServer.cpp +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp @@ -280,9 +280,9 @@ } void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName, - Callback> CB) { + Callback> CB) { auto Action = [Pos](Path File, std::string NewName, - Callback> CB, + Callback> CB, llvm::Expected InpAST) { if (!InpAST) return CB(InpAST.takeError()); @@ -306,7 +306,7 @@ if (!ResultCollector.Result.getValue()) return CB(ResultCollector.Result->takeError()); - std::vector Replacements; + std::vector Replacements; for (const tooling::AtomicChange &Change : ResultCollector.Result->get()) { tooling::Replacements ChangeReps = Change.getReplacements(); for (const auto &Rep : ChangeReps) { @@ -320,7 +320,8 @@ // * 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)); Index: clang-tools-extra/trunk/unittests/clangd/SyncAPI.h =================================================================== --- clang-tools-extra/trunk/unittests/clangd/SyncAPI.h +++ clang-tools-extra/trunk/unittests/clangd/SyncAPI.h @@ -38,7 +38,7 @@ llvm::Expected> runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos); -llvm::Expected> +llvm::Expected> runRename(ClangdServer &Server, PathRef File, Position Pos, StringRef NewName); std::string runDumpAST(ClangdServer &Server, PathRef File); Index: clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp +++ clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp @@ -98,10 +98,10 @@ return std::move(*Result); } -llvm::Expected> -runRename(ClangdServer &Server, PathRef File, Position Pos, - llvm::StringRef NewName) { - llvm::Optional>> Result; +llvm::Expected> runRename(ClangdServer &Server, + PathRef File, Position Pos, + llvm::StringRef NewName) { + llvm::Optional>> Result; Server.rename(File, Pos, NewName, capture(Result)); return std::move(*Result); }