summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2022-11-21 08:31:44 +0100
committerDavid Schulz <david.schulz@qt.io>2022-11-21 11:47:52 +0000
commitfd177245976f01b4d61e27759fb51bb0ea8eaf2d (patch)
tree43c6f5886654d56c17f3ba5e515e355d8f184f75
parent02c041c13a747d2cf42866b441715d2858ecaa66 (diff)
downloadqt-creator-fd177245976f01b4d61e27759fb51bb0ea8eaf2d.tar.gz
LanguageClient: use reported rename placeholder
Using the reported range to create a usable placeholder if the cursor ('|') is placed on the end of an identifier like in: int global|; Change-Id: I2ebacf3b9b54cff8f8887526479792374f67c881 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/plugins/languageclient/languageclientsymbolsupport.cpp35
-rw-r--r--src/plugins/languageclient/languageclientsymbolsupport.h6
2 files changed, 35 insertions, 6 deletions
diff --git a/src/plugins/languageclient/languageclientsymbolsupport.cpp b/src/plugins/languageclient/languageclientsymbolsupport.cpp
index fdce784322..a6c1a1659d 100644
--- a/src/plugins/languageclient/languageclientsymbolsupport.cpp
+++ b/src/plugins/languageclient/languageclientsymbolsupport.cpp
@@ -373,22 +373,33 @@ void SymbolSupport::renameSymbol(TextEditor::TextDocument *document, const QText
const QString error = tr("Renaming is not supported with %1").arg(m_client->name());
createSearch(params, placeholder, {}, {})->finishSearch(true, error);
} else if (prepareSupported) {
- requestPrepareRename(generateDocPosParams(document, cursor), placeholder, oldSymbolName,
+ requestPrepareRename(document,
+ generateDocPosParams(document, cursor),
+ placeholder,
+ oldSymbolName,
preferLowerCaseFileNames);
} else {
- startRenameSymbol(generateDocPosParams(document, cursor), placeholder, oldSymbolName,
+ startRenameSymbol(generateDocPosParams(document, cursor),
+ placeholder,
+ oldSymbolName,
preferLowerCaseFileNames);
}
}
void SymbolSupport::requestPrepareRename(
+ TextEditor::TextDocument *document,
const TextDocumentPositionParams &params,
const QString &placeholder,
const QString &oldSymbolName,
bool preferLowerCaseFileNames)
{
PrepareRenameRequest request(params);
- request.setResponseCallback([this, params, placeholder, oldSymbolName, preferLowerCaseFileNames](
+ request.setResponseCallback([this,
+ params,
+ placeholder,
+ oldSymbolName,
+ preferLowerCaseFileNames,
+ document = QPointer<TextEditor::TextDocument>(document)](
const PrepareRenameRequest::Response &response) {
const std::optional<PrepareRenameRequest::Response::Error> &error = response.error();
if (error.has_value()) {
@@ -404,7 +415,23 @@ void SymbolSupport::requestPrepareRename(
preferLowerCaseFileNames);
} else if (std::holds_alternative<Range>(*result)) {
auto range = std::get<Range>(*result);
- startRenameSymbol(params, placeholder, oldSymbolName, preferLowerCaseFileNames);
+ if (document) {
+ const int start = range.start().toPositionInDocument(document->document());
+ const int end = range.end().toPositionInDocument(document->document());
+ const QString reportedSymbolName = document->textAt(start, end - start);
+ const QString newPlaceholder = m_defaultSymbolMapper
+ ? m_defaultSymbolMapper(reportedSymbolName)
+ : reportedSymbolName;
+ startRenameSymbol(params,
+ newPlaceholder,
+ reportedSymbolName,
+ preferLowerCaseFileNames);
+ } else {
+ startRenameSymbol(params,
+ placeholder,
+ oldSymbolName,
+ preferLowerCaseFileNames);
+ }
}
}
});
diff --git a/src/plugins/languageclient/languageclientsymbolsupport.h b/src/plugins/languageclient/languageclientsymbolsupport.h
index 92d0bdcf97..9c55481e51 100644
--- a/src/plugins/languageclient/languageclientsymbolsupport.h
+++ b/src/plugins/languageclient/languageclientsymbolsupport.h
@@ -59,8 +59,10 @@ private:
const QString &wordUnderCursor,
const ResultHandler &handler);
- void requestPrepareRename(const LanguageServerProtocol::TextDocumentPositionParams &params,
- const QString &placeholder, const QString &oldSymbolName,
+ void requestPrepareRename(TextEditor::TextDocument *document,
+ const LanguageServerProtocol::TextDocumentPositionParams &params,
+ const QString &placeholder,
+ const QString &oldSymbolName,
bool preferLowerCaseFileNames);
void requestRename(const LanguageServerProtocol::TextDocumentPositionParams &positionParams,
const QString &newName, Core::SearchResult *search);