LanguageClient: Allow to pre-set the new symbol name

... when renaming.
There are contexts which provide the new name in advance.

Change-Id: I4bda689405060c343c0654d0aca274f10ee22752
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Christian Kandeler
2022-09-21 11:22:20 +02:00
parent 6a720c5bba
commit 718086dea8
2 changed files with 7 additions and 4 deletions

View File

@@ -288,14 +288,16 @@ bool SymbolSupport::supportsRename(TextEditor::TextDocument *document)
return LanguageClient::supportsRename(m_client, document, prepareSupported); return LanguageClient::supportsRename(m_client, document, prepareSupported);
} }
void SymbolSupport::renameSymbol(TextEditor::TextDocument *document, const QTextCursor &cursor) void SymbolSupport::renameSymbol(TextEditor::TextDocument *document, const QTextCursor &cursor,
const QString &newSymbolName)
{ {
const TextDocumentPositionParams params = generateDocPosParams(document, cursor); const TextDocumentPositionParams params = generateDocPosParams(document, cursor);
QTextCursor tc = cursor; QTextCursor tc = cursor;
tc.select(QTextCursor::WordUnderCursor); tc.select(QTextCursor::WordUnderCursor);
const QString oldSymbolName = tc.selectedText(); const QString oldSymbolName = tc.selectedText();
const QString placeholder = m_defaultSymbolMapper ? m_defaultSymbolMapper(oldSymbolName) QString placeholder = newSymbolName;
: oldSymbolName; if (placeholder.isEmpty())
placeholder = m_defaultSymbolMapper ? m_defaultSymbolMapper(oldSymbolName) : oldSymbolName;
bool prepareSupported; bool prepareSupported;
if (!LanguageClient::supportsRename(m_client, document, prepareSupported)) { if (!LanguageClient::supportsRename(m_client, document, prepareSupported)) {

View File

@@ -42,7 +42,8 @@ public:
const ResultHandler &handler = {}); const ResultHandler &handler = {});
bool supportsRename(TextEditor::TextDocument *document); bool supportsRename(TextEditor::TextDocument *document);
void renameSymbol(TextEditor::TextDocument *document, const QTextCursor &cursor); void renameSymbol(TextEditor::TextDocument *document, const QTextCursor &cursor,
const QString &newSymbolName = {});
static Core::Search::TextRange convertRange(const LanguageServerProtocol::Range &range); static Core::Search::TextRange convertRange(const LanguageServerProtocol::Range &range);
static QStringList getFileContents(const Utils::FilePath &filePath); static QStringList getFileContents(const Utils::FilePath &filePath);