diff --git a/src/plugins/languageclient/languageclientsymbolsupport.cpp b/src/plugins/languageclient/languageclientsymbolsupport.cpp index 56f66b49645..d86ac58ba93 100644 --- a/src/plugins/languageclient/languageclientsymbolsupport.cpp +++ b/src/plugins/languageclient/languageclientsymbolsupport.cpp @@ -10,6 +10,8 @@ #include #include +#include + #include #include @@ -162,7 +164,9 @@ QStringList SymbolSupport::getFileContents(const Utils::FilePath &filePath) } QList generateSearchResultItems( - const QMap> &rangesInDocument) + const QMap> &rangesInDocument, + Core::SearchResult *search = nullptr, + bool limitToProjects = false) { QList result; for (auto it = rangesInDocument.begin(); it != rangesInDocument.end(); ++it) { @@ -171,6 +175,8 @@ QList generateSearchResultItems( Core::SearchResultItem item; item.setFilePath(filePath); item.setUseTextEditorFont(true); + if (search && search->supportsReplace() && limitToProjects) + item.setSelectForReplacement(ProjectExplorer::SessionManager::projectForFile(filePath)); QStringList lines = SymbolSupport::getFileContents(filePath); for (const ItemData &data : it.value()) { @@ -343,7 +349,9 @@ void SymbolSupport::requestRename(const TextDocumentPositionParams &positionPara search->popup(); } -QList generateReplaceItems(const WorkspaceEdit &edits) +QList generateReplaceItems(const WorkspaceEdit &edits, + Core::SearchResult *search, + bool limitToProjects) { auto convertEdits = [](const QList &edits) { return Utils::transform(edits, [](const TextEdit &edit) { @@ -362,7 +370,7 @@ QList generateReplaceItems(const WorkspaceEdit &edits) for (auto it = changes.begin(), end = changes.end(); it != end; ++it) rangesInDocument[it.key().toFilePath()] = convertEdits(it.value()); } - return generateSearchResultItems(rangesInDocument); + return generateSearchResultItems(rangesInDocument, search, limitToProjects); } Core::SearchResult *SymbolSupport::createSearch(const TextDocumentPositionParams &positionParams, @@ -419,7 +427,8 @@ void SymbolSupport::handleRenameResponse(Core::SearchResult *search, const std::optional &edits = response.result(); if (edits.has_value()) { - search->addResults(generateReplaceItems(*edits), Core::SearchResult::AddOrdered); + search->addResults(generateReplaceItems(*edits, search, m_limitRenamingToProjects), + Core::SearchResult::AddOrdered); search->additionalReplaceWidget()->setVisible(false); search->setReplaceEnabled(true); search->setSearchAgainEnabled(false); diff --git a/src/plugins/languageclient/languageclientsymbolsupport.h b/src/plugins/languageclient/languageclientsymbolsupport.h index 38d40fa3689..79b250ffcc4 100644 --- a/src/plugins/languageclient/languageclientsymbolsupport.h +++ b/src/plugins/languageclient/languageclientsymbolsupport.h @@ -50,6 +50,8 @@ public: using SymbolMapper = std::function; void setDefaultRenamingSymbolMapper(const SymbolMapper &mapper); + void setLimitRenamingToProjects(bool limit) { m_limitRenamingToProjects = limit; } + private: void handleFindReferencesResponse( const LanguageServerProtocol::FindReferencesRequest::Response &response, @@ -71,6 +73,7 @@ private: Client *m_client = nullptr; SymbolMapper m_defaultSymbolMapper; + bool m_limitRenamingToProjects = false; }; } // namespace LanguageClient