forked from qt-creator/qt-creator
ClangRefactoring: Improve follow symbol and usage
Change-Id: Idb42010443e4560489ef067e54d05b4e567598e9 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -47,7 +47,20 @@ public:
|
||||
ReadStatement selectSourceUsagesForSymbolLocation{
|
||||
"SELECT directoryPath || '/' || sourceName, line, column "
|
||||
"FROM locations NATURAL JOIN sources NATURAL JOIN directories "
|
||||
"WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND column=?)",
|
||||
"WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND "
|
||||
"column=?)",
|
||||
database};
|
||||
ReadStatement selectSourceUsagesOrderedForSymbolLocation{
|
||||
"SELECT directoryPath || '/' || sourceName, line, column "
|
||||
"FROM locations NATURAL JOIN sources NATURAL JOIN directories "
|
||||
"WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND "
|
||||
"column=?) ORDER BY locationKind LIMIT 2",
|
||||
database};
|
||||
ReadStatement selectSourceUsagesByLocationKindForSymbolLocation{
|
||||
"SELECT directoryPath || '/' || sourceName, line, column "
|
||||
"FROM locations NATURAL JOIN sources NATURAL JOIN directories "
|
||||
"WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND "
|
||||
"column=?) AND locationKind = ?",
|
||||
database};
|
||||
ReadStatement selectSymbolsForKindAndStartsWith{
|
||||
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind = ? AND symbolName LIKE ?",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -74,6 +74,7 @@ public:
|
||||
|
||||
private:
|
||||
CppTools::Usages locationsAt(const CppTools::CursorInEditor &data) const;
|
||||
CppTools::Usages declarationAt(const CppTools::CursorInEditor &data) const;
|
||||
|
||||
ClangBackEnd::RefactoringServerInterface &m_server;
|
||||
ClangBackEnd::RefactoringClientInterface &m_client;
|
||||
|
||||
@@ -75,6 +75,36 @@ public:
|
||||
utf8Column);
|
||||
}
|
||||
|
||||
CppTools::Usages sourceUsagesAtByLocationKind(ClangBackEnd::FilePathId filePathId,
|
||||
int line,
|
||||
int utf8Column,
|
||||
ClangBackEnd::SourceLocationKind kind) const override
|
||||
{
|
||||
ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesByLocationKindForSymbolLocation;
|
||||
|
||||
const std::size_t reserveSize = 128;
|
||||
|
||||
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
|
||||
filePathId.filePathId,
|
||||
line,
|
||||
utf8Column,
|
||||
int(kind));
|
||||
}
|
||||
|
||||
CppTools::Usages declarationsAt(ClangBackEnd::FilePathId filePathId,
|
||||
int line,
|
||||
int utf8Column) const override
|
||||
{
|
||||
ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesOrderedForSymbolLocation;
|
||||
|
||||
const std::size_t reserveSize = 128;
|
||||
|
||||
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
|
||||
filePathId.filePathId,
|
||||
line,
|
||||
utf8Column);
|
||||
}
|
||||
|
||||
Symbols symbolsWithOneSymbolKinds(ClangBackEnd::SymbolKind symbolKind,
|
||||
Utils::SmallStringView searchTerm) const
|
||||
{
|
||||
|
||||
@@ -46,10 +46,17 @@ public:
|
||||
virtual CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId,
|
||||
int line,
|
||||
int utf8Column) const = 0;
|
||||
virtual CppTools::Usages sourceUsagesAtByLocationKind(ClangBackEnd::FilePathId filePathId,
|
||||
int line,
|
||||
int utf8Column,
|
||||
ClangBackEnd::SourceLocationKind) const = 0;
|
||||
virtual Symbols symbols(const ClangBackEnd::SymbolKinds &symbolKinds,
|
||||
Utils::SmallStringView searchTerm) const = 0;
|
||||
virtual Utils::optional<SourceLocation> locationForSymbolId(SymbolId symbolId,
|
||||
ClangBackEnd::SourceLocationKind kind) const = 0;
|
||||
virtual CppTools::Usages declarationsAt(ClangBackEnd::FilePathId filePathId,
|
||||
int line,
|
||||
int utf8Column) const = 0;
|
||||
|
||||
protected:
|
||||
~SymbolQueryInterface() = default;
|
||||
|
||||
Reference in New Issue
Block a user