summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clangd/ClangdLSPServer.cpp2
-rw-r--r--clang-tools-extra/clangd/ClangdServer.cpp24
-rw-r--r--clang-tools-extra/clangd/ClangdServer.h5
-rw-r--r--clang-tools-extra/clangd/unittests/SyncAPI.cpp2
4 files changed, 19 insertions, 14 deletions
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index e59da26a982..2b25058c967 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -577,7 +577,7 @@ void ClangdLSPServer::onRename(const RenameParams &Params,
"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<std::vector<TextEdit>> Edits) {
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 55e00e24c91..f0606871013 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -283,23 +283,25 @@ ClangdServer::formatOnType(llvm::StringRef Code, PathRef File, Position Pos,
}
void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
- Callback<std::vector<TextEdit>> CB) {
- auto Action = [Pos, this](Path File, std::string NewName,
- Callback<std::vector<TextEdit>> CB,
- llvm::Expected<InputsAndAST> InpAST) {
+ bool WantFormat, Callback<std::vector<TextEdit>> CB) {
+ auto Action = [Pos, WantFormat, this](Path File, std::string NewName,
+ Callback<std::vector<TextEdit>> CB,
+ llvm::Expected<InputsAndAST> 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<TextEdit> Edits;
for (const auto &Rep : *Changes)
diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index dcb3d79261a..768428574e5 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -240,8 +240,11 @@ public:
/// 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<std::vector<TextEdit>> CB);
+ bool WantFormat, Callback<std::vector<TextEdit>> CB);
struct TweakRef {
std::string ID; /// ID to pass for applyTweak.
diff --git a/clang-tools-extra/clangd/unittests/SyncAPI.cpp b/clang-tools-extra/clangd/unittests/SyncAPI.cpp
index 102cecb55c7..6064489688a 100644
--- a/clang-tools-extra/clangd/unittests/SyncAPI.cpp
+++ b/clang-tools-extra/clangd/unittests/SyncAPI.cpp
@@ -102,7 +102,7 @@ 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));
+ Server.rename(File, Pos, NewName, /*WantFormat=*/true, capture(Result));
return std::move(*Result);
}
OpenPOWER on IntegriCloud