forked from qt-creator/qt-creator
Clang: add globalFollowSymbol to RefactoringEngine
Allows to follow outside of current TU. Change-Id: Ieea2fd72bfdf6d60a988b40efcf2f41c5a71d045 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -394,12 +394,10 @@ QFuture<CppTools::CursorInfo> BackendCommunicator::requestLocalReferences(
|
||||
|
||||
QFuture<CppTools::SymbolInfo> BackendCommunicator::requestFollowSymbol(
|
||||
const FileContainer &curFileContainer,
|
||||
const QVector<Utf8String> &dependentFiles,
|
||||
quint32 line,
|
||||
quint32 column)
|
||||
{
|
||||
const RequestFollowSymbolMessage message(curFileContainer,
|
||||
dependentFiles,
|
||||
line,
|
||||
column);
|
||||
m_sender->requestFollowSymbol(message);
|
||||
|
||||
@@ -83,7 +83,6 @@ public:
|
||||
quint32 column,
|
||||
QTextDocument *textDocument);
|
||||
QFuture<CppTools::SymbolInfo> requestFollowSymbol(const FileContainer &curFileContainer,
|
||||
const QVector<Utf8String> &dependentFiles,
|
||||
quint32 line,
|
||||
quint32 column);
|
||||
void completeCode(ClangCompletionAssistProcessor *assistProcessor, const QString &filePath,
|
||||
|
||||
@@ -367,50 +367,10 @@ QFuture<CppTools::CursorInfo> ClangEditorDocumentProcessor::requestLocalReferenc
|
||||
textDocument());
|
||||
}
|
||||
|
||||
static QVector<Utf8String> prioritizeByBaseName(const QString &curPath,
|
||||
const ::Utils::FileNameList &fileDeps)
|
||||
{
|
||||
QList<Utf8String> dependentFiles;
|
||||
dependentFiles.reserve(fileDeps.size());
|
||||
for (const ::Utils::FileName &dep: fileDeps)
|
||||
dependentFiles.push_back(dep.toString());
|
||||
|
||||
const QString curFilename = QFileInfo(curPath).fileName();
|
||||
if (CppTools::ProjectFile::isHeader(CppTools::ProjectFile::classify(curFilename))) {
|
||||
const QString withoutExt = QFileInfo(curFilename).baseName();
|
||||
int posToMove = 0;
|
||||
// Move exact match to the first place and partial matches after it
|
||||
for (int i = 0; i < dependentFiles.size(); ++i) {
|
||||
const QString baseName = QFileInfo(dependentFiles[i]).baseName();
|
||||
if (withoutExt == baseName) {
|
||||
dependentFiles.move(i, 0);
|
||||
posToMove++;
|
||||
continue;
|
||||
}
|
||||
if (baseName.contains(withoutExt))
|
||||
dependentFiles.move(i, posToMove++);
|
||||
}
|
||||
}
|
||||
// Limit the number of scans (don't search for overrides)
|
||||
if (dependentFiles.size() > 5)
|
||||
dependentFiles.erase(dependentFiles.begin() + 5, dependentFiles.end());
|
||||
return QVector<Utf8String>::fromList(dependentFiles);
|
||||
}
|
||||
|
||||
QFuture<CppTools::SymbolInfo>
|
||||
ClangEditorDocumentProcessor::requestFollowSymbol(int line, int column)
|
||||
{
|
||||
QVector<Utf8String> dependentFiles;
|
||||
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
||||
if (modelManager && !modelManager->projectPart(filePath()).isEmpty()) {
|
||||
// This might be not so fast - index will change that
|
||||
const ::Utils::FileNameList fileDeps
|
||||
= modelManager->snapshot().filesDependingOn(filePath());
|
||||
dependentFiles = prioritizeByBaseName(filePath(), fileDeps);
|
||||
}
|
||||
|
||||
return m_communicator.requestFollowSymbol(simpleFileContainer(),
|
||||
dependentFiles,
|
||||
static_cast<quint32>(line),
|
||||
static_cast<quint32>(column));
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "clangeditordocumentprocessor.h"
|
||||
#include "clangfollowsymbol.h"
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <clangsupport/tokeninfocontainer.h>
|
||||
@@ -94,10 +95,10 @@ static Utils::Link linkAtCursor(QTextCursor cursor, const QString &filePath, uin
|
||||
|
||||
Utils::Link ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data,
|
||||
bool resolveTarget,
|
||||
const CPlusPlus::Snapshot &,
|
||||
const CPlusPlus::Document::Ptr &,
|
||||
CppTools::SymbolFinder *,
|
||||
bool)
|
||||
const CPlusPlus::Snapshot &snapshot,
|
||||
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
|
||||
CppTools::SymbolFinder *symbolFinder,
|
||||
bool inNextSplit)
|
||||
{
|
||||
int lineNumber = 0, positionInBlock = 0;
|
||||
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
|
||||
@@ -130,8 +131,12 @@ Utils::Link ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data,
|
||||
CppTools::SymbolInfo result = info.result();
|
||||
|
||||
// We did not fail but the result is empty
|
||||
if (result.fileName.isEmpty())
|
||||
return Link();
|
||||
if (result.fileName.isEmpty()) {
|
||||
const CppTools::RefactoringEngineInterface &refactoringEngine
|
||||
= *CppTools::CppModelManager::instance();
|
||||
return refactoringEngine.globalFollowSymbol(data, snapshot, documentFromSemanticInfo,
|
||||
symbolFinder, inNextSplit);
|
||||
}
|
||||
|
||||
return Link(result.fileName, result.startLine, result.startColumn - 1);
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ class ClangFollowSymbol : public CppTools::FollowSymbolInterface
|
||||
public:
|
||||
Link findLink(const CppTools::CursorInEditor &data,
|
||||
bool resolveTarget,
|
||||
const CPlusPlus::Snapshot &,
|
||||
const CPlusPlus::Document::Ptr &,
|
||||
CppTools::SymbolFinder *,
|
||||
bool) override;
|
||||
const CPlusPlus::Snapshot &snapshot,
|
||||
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
|
||||
CppTools::SymbolFinder *symbolFinder,
|
||||
bool inNextSplit) override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -43,6 +43,12 @@ public:
|
||||
void globalRename(const CppTools::CursorInEditor &, CppTools::UsagesCallback &&,
|
||||
const QString &) override {}
|
||||
void findUsages(const CppTools::CursorInEditor &, CppTools::UsagesCallback &&) const override {}
|
||||
Link globalFollowSymbol(const CppTools::CursorInEditor &, const CPlusPlus::Snapshot &,
|
||||
const CPlusPlus::Document::Ptr &, CppTools::SymbolFinder *,
|
||||
bool) const override
|
||||
{
|
||||
return Link();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
Reference in New Issue
Block a user