LanguageClient: correctly cancel running rename request

When requesting rename results while we have not received the response
to the previous rename request, we have to cancel that previous request
otherwise we end up with duplicated replace operations that potentially
can invalidate the document.

Task-number: QTCREATORBUG-29389
Change-Id: I3be425b8306c18b64fca7bb71bf65c32ae50fed1
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2023-08-21 15:18:55 +02:00
parent 8f9e75a3b8
commit e6b8791fa9
2 changed files with 8 additions and 3 deletions

View File

@@ -452,21 +452,24 @@ void SymbolSupport::requestPrepareRename(TextEditor::TextDocument *document,
void SymbolSupport::requestRename(const TextDocumentPositionParams &positionParams,
Core::SearchResult *search)
{
if (m_renameRequestIds[search].isValid())
m_client->cancelRequest(m_renameRequestIds[search]);
RenameParams params(positionParams);
params.setNewName(search->textToReplace());
RenameRequest request(params);
request.setResponseCallback([this, search](const RenameRequest::Response &response) {
handleRenameResponse(search, response);
});
m_renameRequestIds[search] = request.id();
m_client->sendMessage(request);
if (search->isInteractive())
search->popup();
}
Utils::SearchResultItems generateReplaceItems(const WorkspaceEdit &edits,
Core::SearchResult *search,
bool limitToProjects,
const DocumentUri::PathMapper &pathMapper)
Core::SearchResult *search,
bool limitToProjects,
const DocumentUri::PathMapper &pathMapper)
{
auto convertEdits = [](const QList<TextEdit> &edits) {
return Utils::transform(edits, [](const TextEdit &edit) {
@@ -546,6 +549,7 @@ void SymbolSupport::startRenameSymbol(const TextDocumentPositionParams &position
void SymbolSupport::handleRenameResponse(Core::SearchResult *search,
const RenameRequest::Response &response)
{
m_renameRequestIds.remove(search);
const std::optional<PrepareRenameRequest::Response::Error> &error = response.error();
QString errorMessage;
if (error.has_value()) {

View File

@@ -78,6 +78,7 @@ private:
Client *m_client = nullptr;
SymbolMapper m_defaultSymbolMapper;
QHash<Core::SearchResult *, LanguageServerProtocol::MessageId> m_renameRequestIds;
bool m_limitRenamingToProjects = false;
};