ClangRefactoring: Improve follow symbol and usage

Change-Id: Idb42010443e4560489ef067e54d05b4e567598e9
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2019-08-22 16:10:38 +02:00
parent c174eb378a
commit 9f805b7e8a
19 changed files with 324 additions and 53 deletions

View File

@@ -68,7 +68,8 @@ void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &,
CppTools::Usages RefactoringEngine::locationsAt(const CppTools::CursorInEditor &data) const
{
CppTools::Usages usages;
if (data.cursor().isNull())
return {};
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
Utils::OptionalLineColumn lineColumn = Utils::Text::convertPosition(cursor.document(),
@@ -78,10 +79,30 @@ CppTools::Usages RefactoringEngine::locationsAt(const CppTools::CursorInEditor &
const QByteArray filePath = data.filePath().toString().toUtf8();
const ClangBackEnd::FilePathId filePathId = m_filePathCache.filePathId(ClangBackEnd::FilePathView(filePath));
usages = m_symbolQuery.sourceUsagesAt(filePathId, lineColumn->line, lineColumn->column);
return m_symbolQuery.sourceUsagesAt(filePathId, lineColumn->line, lineColumn->column);
}
return usages;
return {};
}
CppTools::Usages RefactoringEngine::declarationAt(const CppTools::CursorInEditor &data) const
{
if (data.cursor().isNull())
return {};
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
Utils::OptionalLineColumn lineColumn = Utils::Text::convertPosition(cursor.document(),
cursor.position());
if (lineColumn) {
const QByteArray filePath = data.filePath().toString().toUtf8();
const ClangBackEnd::FilePathId filePathId = m_filePathCache.filePathId(
ClangBackEnd::FilePathView(filePath));
return m_symbolQuery.declarationsAt(filePathId, lineColumn->line, lineColumn->column);
}
return {};
}
void RefactoringEngine::globalRename(const CppTools::CursorInEditor &data,
@@ -104,16 +125,13 @@ void RefactoringEngine::globalFollowSymbol(const CppTools::CursorInEditor &data,
CppTools::SymbolFinder *,
bool) const
{
// TODO: replace that with specific followSymbol query
const CppTools::Usages usages = locationsAt(data);
const CppTools::Usages usages = declarationAt(data);
CppTools::Usage usage = Utils::findOrDefault(usages, [&data](const CppTools::Usage &usage) {
// We've already searched in the current file, skip it.
if (usage.path == data.filePath().toString())
return false;
return true;
return usage.path != data.filePath().toString();
});
processLinkCallback(Link(usage.path, usage.line, usage.column));
processLinkCallback(Link(usage.path, usage.line, usage.column - 1));
}
bool RefactoringEngine::isRefactoringEngineAvailable() const