summaryrefslogtreecommitdiff
path: root/src/plugins/clangrefactoring
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2019-08-22 16:10:38 +0200
committerMarco Bubke <marco.bubke@qt.io>2019-08-27 11:53:45 +0000
commit9f805b7e8aad04f72203828b89f389f73a5ffcd7 (patch)
tree914959e9a44677f10be6481de659db363bd0a1e9 /src/plugins/clangrefactoring
parentc174eb378a7957b8b123e2054cce0e166842a8aa (diff)
downloadqt-creator-9f805b7e8aad04f72203828b89f389f73a5ffcd7.tar.gz
ClangRefactoring: Improve follow symbol and usage
Change-Id: Idb42010443e4560489ef067e54d05b4e567598e9 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/plugins/clangrefactoring')
-rw-r--r--src/plugins/clangrefactoring/querysqlitestatementfactory.h15
-rw-r--r--src/plugins/clangrefactoring/refactoringengine.cpp38
-rw-r--r--src/plugins/clangrefactoring/refactoringengine.h1
-rw-r--r--src/plugins/clangrefactoring/symbolquery.h30
-rw-r--r--src/plugins/clangrefactoring/symbolqueryinterface.h7
5 files changed, 80 insertions, 11 deletions
diff --git a/src/plugins/clangrefactoring/querysqlitestatementfactory.h b/src/plugins/clangrefactoring/querysqlitestatementfactory.h
index 14fc27149d..65d8289579 100644
--- a/src/plugins/clangrefactoring/querysqlitestatementfactory.h
+++ b/src/plugins/clangrefactoring/querysqlitestatementfactory.h
@@ -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 ?",
diff --git a/src/plugins/clangrefactoring/refactoringengine.cpp b/src/plugins/clangrefactoring/refactoringengine.cpp
index cc9121331d..6b5546cc88 100644
--- a/src/plugins/clangrefactoring/refactoringengine.cpp
+++ b/src/plugins/clangrefactoring/refactoringengine.cpp
@@ -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
diff --git a/src/plugins/clangrefactoring/refactoringengine.h b/src/plugins/clangrefactoring/refactoringengine.h
index 739b545310..4dfef3ba0c 100644
--- a/src/plugins/clangrefactoring/refactoringengine.h
+++ b/src/plugins/clangrefactoring/refactoringengine.h
@@ -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;
diff --git a/src/plugins/clangrefactoring/symbolquery.h b/src/plugins/clangrefactoring/symbolquery.h
index b5a46ab7e6..2468369c82 100644
--- a/src/plugins/clangrefactoring/symbolquery.h
+++ b/src/plugins/clangrefactoring/symbolquery.h
@@ -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
{
diff --git a/src/plugins/clangrefactoring/symbolqueryinterface.h b/src/plugins/clangrefactoring/symbolqueryinterface.h
index 568d26568f..6ea6c97304 100644
--- a/src/plugins/clangrefactoring/symbolqueryinterface.h
+++ b/src/plugins/clangrefactoring/symbolqueryinterface.h
@@ -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;