Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp @@ -577,7 +577,7 @@ "onRename called for non-added file", ErrorCode::InvalidParams)); Server->rename( - File, Params.position, Params.newName, + File, Params.position, Params.newName, /*WantFormat=*/true, Bind( [File, Code, Params](decltype(Reply) Reply, llvm::Expected> Edits) { Index: clang-tools-extra/trunk/clangd/ClangdServer.h =================================================================== --- clang-tools-extra/trunk/clangd/ClangdServer.h +++ clang-tools-extra/trunk/clangd/ClangdServer.h @@ -240,8 +240,11 @@ /// Rename all occurrences of the symbol at the \p Pos in \p File to /// \p NewName. + /// If WantFormat is false, the final TextEdit will be not formatted, + /// embedders could use this method to get all occurrences of the symbol (e.g. + /// highlighting them in prepare stage). void rename(PathRef File, Position Pos, llvm::StringRef NewName, - Callback> CB); + bool WantFormat, 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 @@ -283,23 +283,25 @@ } void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName, - Callback> CB) { - auto Action = [Pos, this](Path File, std::string NewName, - Callback> CB, - llvm::Expected InpAST) { + bool WantFormat, Callback> CB) { + auto Action = [Pos, WantFormat, this](Path File, std::string NewName, + Callback> CB, + llvm::Expected InpAST) { if (!InpAST) return CB(InpAST.takeError()); auto Changes = renameWithinFile(InpAST->AST, File, Pos, NewName, Index); if (!Changes) return CB(Changes.takeError()); - auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents, - InpAST->Inputs.FS.get()); - if (auto Formatted = - cleanupAndFormat(InpAST->Inputs.Contents, *Changes, Style)) - *Changes = std::move(*Formatted); - else - elog("Failed to format replacements: {0}", Formatted.takeError()); + if (WantFormat) { + auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents, + InpAST->Inputs.FS.get()); + if (auto Formatted = + cleanupAndFormat(InpAST->Inputs.Contents, *Changes, Style)) + *Changes = std::move(*Formatted); + else + elog("Failed to format replacements: {0}", Formatted.takeError()); + } std::vector Edits; for (const auto &Rep : *Changes) Index: clang-tools-extra/trunk/clangd/unittests/SyncAPI.cpp =================================================================== --- clang-tools-extra/trunk/clangd/unittests/SyncAPI.cpp +++ clang-tools-extra/trunk/clangd/unittests/SyncAPI.cpp @@ -102,7 +102,7 @@ PathRef File, Position Pos, llvm::StringRef NewName) { llvm::Optional>> Result; - Server.rename(File, Pos, NewName, capture(Result)); + Server.rename(File, Pos, NewName, /*WantFormat=*/true, capture(Result)); return std::move(*Result); }