LanguageClient: Allow to not pre-select non-project files for renaming

In alignment with what we already do in CppEditor/ClangCodeModel.

Change-Id: Ic68eca1879ed06887d3c5e39a09982bdd8c61065
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-09-21 10:34:09 +02:00
parent 993fd2a92a
commit eccbfc9459
2 changed files with 16 additions and 4 deletions

View File

@@ -10,6 +10,8 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/find/searchresultwindow.h>
#include <projectexplorer/session.h>
#include <utils/mimeutils.h>
#include <QFile>
@@ -162,7 +164,9 @@ QStringList SymbolSupport::getFileContents(const Utils::FilePath &filePath)
}
QList<Core::SearchResultItem> generateSearchResultItems(
const QMap<Utils::FilePath, QList<ItemData>> &rangesInDocument)
const QMap<Utils::FilePath, QList<ItemData>> &rangesInDocument,
Core::SearchResult *search = nullptr,
bool limitToProjects = false)
{
QList<Core::SearchResultItem> result;
for (auto it = rangesInDocument.begin(); it != rangesInDocument.end(); ++it) {
@@ -171,6 +175,8 @@ QList<Core::SearchResultItem> 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<Core::SearchResultItem> generateReplaceItems(const WorkspaceEdit &edits)
QList<Core::SearchResultItem> generateReplaceItems(const WorkspaceEdit &edits,
Core::SearchResult *search,
bool limitToProjects)
{
auto convertEdits = [](const QList<TextEdit> &edits) {
return Utils::transform(edits, [](const TextEdit &edit) {
@@ -362,7 +370,7 @@ QList<Core::SearchResultItem> 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<WorkspaceEdit> &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);

View File

@@ -50,6 +50,8 @@ public:
using SymbolMapper = std::function<QString(const QString &)>;
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