diff options
author | David Schulz <david.schulz@qt.io> | 2022-12-08 14:47:24 +0100 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2022-12-08 14:27:29 +0000 |
commit | 6d8f6ab39595350afe67e2649dce658613a46abd (patch) | |
tree | be5a13c25c780e9a1c2d500909a37c11d3c6cd7d | |
parent | 55ba10be38767ba5d59170e51b212fef8e2653a4 (diff) | |
download | qt-creator-6d8f6ab39595350afe67e2649dce658613a46abd.tar.gz |
LanguageClient: robustify renaming symbols
Guard against using a symbol support from a deleted client. Additionally
cancel active replace operations and provide a sensible error message.
Change-Id: I92ca0038fa5f6acbb8369a48c4e8051adfadb30e
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r-- | src/plugins/languageclient/languageclientsymbolsupport.cpp | 39 | ||||
-rw-r--r-- | src/plugins/languageclient/languageclientsymbolsupport.h | 2 |
2 files changed, 21 insertions, 20 deletions
diff --git a/src/plugins/languageclient/languageclientsymbolsupport.cpp b/src/plugins/languageclient/languageclientsymbolsupport.cpp index a6c1a1659d..163162d8b0 100644 --- a/src/plugins/languageclient/languageclientsymbolsupport.cpp +++ b/src/plugins/languageclient/languageclientsymbolsupport.cpp @@ -285,11 +285,9 @@ void SymbolSupport::handleFindReferencesResponse(const FindReferencesRequest::Re Core::SearchResult *search = Core::SearchResultWindow::instance()->startNewSearch( tr("Find References with %1 for:").arg(m_client->name()), "", wordUnderCursor); search->addResults(generateSearchResultItems(*result), Core::SearchResult::AddOrdered); - QObject::connect(search, - &Core::SearchResult::activated, - [](const Core::SearchResultItem &item) { - Core::EditorManager::openEditorAtSearchResult(item); - }); + connect(search, &Core::SearchResult::activated, [](const Core::SearchResultItem &item) { + Core::EditorManager::openEditorAtSearchResult(item); + }); search->finishSearch(false); search->popup(); } @@ -493,27 +491,30 @@ Core::SearchResult *SymbolSupport::createSearch( const auto extraWidget = new ReplaceWidget; search->setAdditionalReplaceWidget(extraWidget); - QObject::connect(search, &Core::SearchResult::activated, [](const Core::SearchResultItem &item) { + connect(search, &Core::SearchResult::activated, [](const Core::SearchResultItem &item) { Core::EditorManager::openEditorAtSearchResult(item); }); - QObject::connect(search, &Core::SearchResult::replaceTextChanged, [search, extraWidget]() { + connect(search, &Core::SearchResult::replaceTextChanged, this, [search, extraWidget]() { extraWidget->showLabel(true); search->setUserData(search->userData().toList().first(2)); search->setSearchAgainEnabled(true); search->setReplaceEnabled(false); }); - QObject::connect(search, - &Core::SearchResult::searchAgainRequested, - [this, positionParams, search]() { - search->restart(); - requestRename(positionParams, search->textToReplace(), search); - }); - QObject::connect(search, - &Core::SearchResult::replaceButtonClicked, - [this, positionParams, search](const QString & /*replaceText*/, - const QList<Core::SearchResultItem> &checkedItems) { - applyRename(checkedItems, search); - }); + connect(search, &Core::SearchResult::searchAgainRequested, this, + [this, positionParams, search]() { + search->restart(); + requestRename(positionParams, search->textToReplace(), search); + }); + connect(search, &Core::SearchResult::replaceButtonClicked, this, + [this, positionParams, search](const QString & /*replaceText*/, + const QList<Core::SearchResultItem> &checkedItems) { + applyRename(checkedItems, search); + }); + + connect(this, &QObject::destroyed, search, [search, clientName = m_client->name()](){ + search->restart(); // clears potential current results + search->finishSearch(true, tr("%1 is not reachable anymore.").arg(clientName)); + }); return search; } diff --git a/src/plugins/languageclient/languageclientsymbolsupport.h b/src/plugins/languageclient/languageclientsymbolsupport.h index 9c55481e51..304eeabeea 100644 --- a/src/plugins/languageclient/languageclientsymbolsupport.h +++ b/src/plugins/languageclient/languageclientsymbolsupport.h @@ -23,7 +23,7 @@ namespace LanguageClient { class Client; -class LANGUAGECLIENT_EXPORT SymbolSupport +class LANGUAGECLIENT_EXPORT SymbolSupport : public QObject { Q_DECLARE_TR_FUNCTIONS(SymbolSupport) public: |