diff options
27 files changed, 133 insertions, 265 deletions
diff --git a/src/libs/clangsupport/requestfollowsymbolmessage.cpp b/src/libs/clangsupport/requestfollowsymbolmessage.cpp index 92fe71062e..f0efe23f6b 100644 --- a/src/libs/clangsupport/requestfollowsymbolmessage.cpp +++ b/src/libs/clangsupport/requestfollowsymbolmessage.cpp @@ -36,7 +36,6 @@ QDebug operator<<(QDebug debug, const RequestFollowSymbolMessage &message) debug.nospace() << "RequestFollowSymbolMessage("; debug.nospace() << message.m_fileContainer << ", "; - debug.nospace() << message.m_dependentFiles << ", "; debug.nospace() << message.m_ticketNumber << ", "; debug.nospace() << message.m_line << ", "; debug.nospace() << message.m_column << ", "; diff --git a/src/libs/clangsupport/requestfollowsymbolmessage.h b/src/libs/clangsupport/requestfollowsymbolmessage.h index a68a6d956c..ebfdc09831 100644 --- a/src/libs/clangsupport/requestfollowsymbolmessage.h +++ b/src/libs/clangsupport/requestfollowsymbolmessage.h @@ -38,14 +38,12 @@ class RequestFollowSymbolMessage public: RequestFollowSymbolMessage() = default; RequestFollowSymbolMessage(const FileContainer &fileContainer, - const QVector<Utf8String> &dependentFiles, quint32 line, quint32 column) : m_fileContainer(fileContainer) , m_ticketNumber(++ticketCounter) , m_line(line) , m_column(column) - , m_dependentFiles(dependentFiles) { } @@ -54,11 +52,6 @@ public: return m_fileContainer; } - const QVector<Utf8String> &dependentFiles() const - { - return m_dependentFiles; - } - quint32 line() const { return m_line; @@ -77,7 +70,6 @@ public: friend QDataStream &operator<<(QDataStream &out, const RequestFollowSymbolMessage &message) { out << message.m_fileContainer; - out << message.m_dependentFiles; out << message.m_ticketNumber; out << message.m_line; out << message.m_column; @@ -88,7 +80,6 @@ public: friend QDataStream &operator>>(QDataStream &in, RequestFollowSymbolMessage &message) { in >> message.m_fileContainer; - in >> message.m_dependentFiles; in >> message.m_ticketNumber; in >> message.m_line; in >> message.m_column; @@ -102,8 +93,7 @@ public: return first.m_ticketNumber == second.m_ticketNumber && first.m_line == second.m_line && first.m_column == second.m_column - && first.m_fileContainer == second.m_fileContainer - && first.m_dependentFiles == second.m_dependentFiles; + && first.m_fileContainer == second.m_fileContainer; } friend CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const RequestFollowSymbolMessage &message); @@ -112,7 +102,6 @@ private: quint64 m_ticketNumber = 0; quint32 m_line = 0; quint32 m_column = 0; - QVector<Utf8String> m_dependentFiles; static CLANGSUPPORT_EXPORT quint64 ticketCounter; }; diff --git a/src/plugins/clangcodemodel/clangbackendcommunicator.cpp b/src/plugins/clangcodemodel/clangbackendcommunicator.cpp index 00f5c9a8e6..5650479312 100644 --- a/src/plugins/clangcodemodel/clangbackendcommunicator.cpp +++ b/src/plugins/clangcodemodel/clangbackendcommunicator.cpp @@ -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); diff --git a/src/plugins/clangcodemodel/clangbackendcommunicator.h b/src/plugins/clangcodemodel/clangbackendcommunicator.h index baafa3c2a6..bd7494a6c2 100644 --- a/src/plugins/clangcodemodel/clangbackendcommunicator.h +++ b/src/plugins/clangcodemodel/clangbackendcommunicator.h @@ -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, diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp index 04bdccf893..6eb98b2c92 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp @@ -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)); } diff --git a/src/plugins/clangcodemodel/clangfollowsymbol.cpp b/src/plugins/clangcodemodel/clangfollowsymbol.cpp index e9a9e841d0..49d63d03c0 100644 --- a/src/plugins/clangcodemodel/clangfollowsymbol.cpp +++ b/src/plugins/clangcodemodel/clangfollowsymbol.cpp @@ -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); } diff --git a/src/plugins/clangcodemodel/clangfollowsymbol.h b/src/plugins/clangcodemodel/clangfollowsymbol.h index 5dcf5d389d..8c9da83592 100644 --- a/src/plugins/clangcodemodel/clangfollowsymbol.h +++ b/src/plugins/clangcodemodel/clangfollowsymbol.h @@ -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 diff --git a/src/plugins/clangcodemodel/clangrefactoringengine.h b/src/plugins/clangcodemodel/clangrefactoringengine.h index e72a4f5f4d..300ca4e72f 100644 --- a/src/plugins/clangcodemodel/clangrefactoringengine.h +++ b/src/plugins/clangcodemodel/clangrefactoringengine.h @@ -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 diff --git a/src/plugins/clangrefactoring/refactoringengine.cpp b/src/plugins/clangrefactoring/refactoringengine.cpp index d76c5d61d6..75f79a7a2b 100644 --- a/src/plugins/clangrefactoring/refactoringengine.cpp +++ b/src/plugins/clangrefactoring/refactoringengine.cpp @@ -35,6 +35,7 @@ #include <clangsupport/filepathcachinginterface.h> +#include <utils/algorithm.h> #include <utils/textutils.h> #include <QTextCursor> @@ -115,6 +116,24 @@ void RefactoringEngine::findUsages(const CppTools::CursorInEditor &data, showUsagesCallback(locationsAt(data)); } +RefactoringEngine::Link RefactoringEngine::globalFollowSymbol(const CppTools::CursorInEditor &data, + const CPlusPlus::Snapshot &, + const CPlusPlus::Document::Ptr &, + CppTools::SymbolFinder *, + bool) const +{ + // TODO: replace that with specific followSymbol query + const CppTools::Usages usages = locationsAt(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 Link(usage.path, usage.line, usage.column); +} + bool RefactoringEngine::isRefactoringEngineAvailable() const { return m_server.isAvailable(); diff --git a/src/plugins/clangrefactoring/refactoringengine.h b/src/plugins/clangrefactoring/refactoringengine.h index 9f8450e961..951a18fb53 100644 --- a/src/plugins/clangrefactoring/refactoringengine.h +++ b/src/plugins/clangrefactoring/refactoringengine.h @@ -36,6 +36,8 @@ class RefactoringClientInterface; class RefactoringServerInterface; } +namespace CppTools { class SymbolFinder; } + namespace ClangRefactoring { class RefactoringEngine : public CppTools::RefactoringEngineInterface @@ -55,6 +57,11 @@ public: const QString &) override; void findUsages(const CppTools::CursorInEditor &data, CppTools::UsagesCallback &&showUsagesCallback) const override; + Link globalFollowSymbol(const CppTools::CursorInEditor &data, + const CPlusPlus::Snapshot &, + const CPlusPlus::Document::Ptr &, + CppTools::SymbolFinder *, + bool) const override; bool isRefactoringEngineAvailable() const override; void setRefactoringEngineAvailable(bool isAvailable); diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index e41c8f8145..ad255459b2 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -289,7 +289,7 @@ void CppModelManager::startLocalRenaming(const CursorInEditor &data, CppTools::ProjectPart *projectPart, RenameCallback &&renameSymbolsCallback) { - RefactoringEngineInterface *engine = getRefactoringEngine(instance()->d->m_refactoringEngines, + RefactoringEngineInterface *engine = getRefactoringEngine(d->m_refactoringEngines, false); QTC_ASSERT(engine, return;); engine->startLocalRenaming(data, projectPart, std::move(renameSymbolsCallback)); @@ -298,7 +298,7 @@ void CppModelManager::startLocalRenaming(const CursorInEditor &data, void CppModelManager::globalRename(const CursorInEditor &data, UsagesCallback &&renameCallback, const QString &replacement) { - RefactoringEngineInterface *engine = getRefactoringEngine(instance()->d->m_refactoringEngines); + RefactoringEngineInterface *engine = getRefactoringEngine(d->m_refactoringEngines); QTC_ASSERT(engine, return;); engine->globalRename(data, std::move(renameCallback), replacement); } @@ -306,11 +306,24 @@ void CppModelManager::globalRename(const CursorInEditor &data, UsagesCallback && void CppModelManager::findUsages(const CppTools::CursorInEditor &data, UsagesCallback &&showUsagesCallback) const { - RefactoringEngineInterface *engine = getRefactoringEngine(instance()->d->m_refactoringEngines); + RefactoringEngineInterface *engine = getRefactoringEngine(d->m_refactoringEngines); QTC_ASSERT(engine, return;); engine->findUsages(data, std::move(showUsagesCallback)); } +CppModelManager::Link CppModelManager::globalFollowSymbol( + const CursorInEditor &data, + const CPlusPlus::Snapshot &snapshot, + const CPlusPlus::Document::Ptr &documentFromSemanticInfo, + SymbolFinder *symbolFinder, + bool inNextSplit) const +{ + RefactoringEngineInterface *engine = getRefactoringEngine(d->m_refactoringEngines); + QTC_ASSERT(engine, return Link();); + return engine->globalFollowSymbol(data, snapshot, documentFromSemanticInfo, + symbolFinder, inNextSplit); +} + void CppModelManager::addRefactoringEngine(RefactoringEngineType type, RefactoringEngineInterface *refactoringEngine) { diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index 1cf660f83a..3eb06eca65 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -155,6 +155,11 @@ public: const QString &replacement) final; void findUsages(const CppTools::CursorInEditor &data, UsagesCallback &&showUsagesCallback) const final; + Link globalFollowSymbol(const CursorInEditor &data, + const CPlusPlus::Snapshot &snapshot, + const CPlusPlus::Document::Ptr &documentFromSemanticInfo, + SymbolFinder *symbolFinder, + bool inNextSplit) const final; void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context, const QString &replacement = QString()); diff --git a/src/plugins/cpptools/cpprefactoringengine.cpp b/src/plugins/cpptools/cpprefactoringengine.cpp index ba391ec279..1f66829e96 100644 --- a/src/plugins/cpptools/cpprefactoringengine.cpp +++ b/src/plugins/cpptools/cpprefactoringengine.cpp @@ -28,6 +28,7 @@ #include "cpprefactoringengine.h" #include "cppsemanticinfo.h" #include "cpptoolsreuse.h" +#include "cppfollowsymbolundercursor.h" #include <texteditor/texteditor.h> @@ -99,4 +100,16 @@ void CppRefactoringEngine::findUsages(const CursorInEditor &data, } } +CppRefactoringEngine::Link CppRefactoringEngine::globalFollowSymbol( + const CursorInEditor &data, + const CPlusPlus::Snapshot &snapshot, + const CPlusPlus::Document::Ptr &documentFromSemanticInfo, + SymbolFinder *symbolFinder, + bool inNextSplit) const +{ + FollowSymbolUnderCursor followSymbol; + return followSymbol.findLink(data, true, snapshot, documentFromSemanticInfo, + symbolFinder, inNextSplit); +} + } // namespace CppEditor diff --git a/src/plugins/cpptools/cpprefactoringengine.h b/src/plugins/cpptools/cpprefactoringengine.h index 44684821bf..72a81136e3 100644 --- a/src/plugins/cpptools/cpprefactoringengine.h +++ b/src/plugins/cpptools/cpprefactoringengine.h @@ -38,6 +38,11 @@ public: void globalRename(const CursorInEditor &data, UsagesCallback &&, const QString &replacement) override; void findUsages(const CursorInEditor &data, UsagesCallback &&) const override; + Link globalFollowSymbol(const CursorInEditor &data, + const CPlusPlus::Snapshot &snapshot, + const CPlusPlus::Document::Ptr &documentFromSemanticInfo, + SymbolFinder *symbolFinder, + bool inNextSplit) const override; }; } // namespace CppEditor diff --git a/src/plugins/cpptools/refactoringengineinterface.h b/src/plugins/cpptools/refactoringengineinterface.h index 2bcb51afc3..84ecf501ab 100644 --- a/src/plugins/cpptools/refactoringengineinterface.h +++ b/src/plugins/cpptools/refactoringengineinterface.h @@ -29,12 +29,15 @@ #include "cursorineditor.h" #include "usages.h" +#include <utils/link.h> #include <utils/fileutils.h> #include <utils/smallstring.h> #include <clangsupport/sourcelocationscontainer.h> #include <clangsupport/refactoringclientinterface.h> +#include <cplusplus/CppDocument.h> + namespace TextEditor { class TextEditorWidget; } // namespace TextEditor @@ -42,6 +45,7 @@ class TextEditorWidget; namespace CppTools { class ProjectPart; +class SymbolFinder; enum class CallType { @@ -54,6 +58,7 @@ class CPPTOOLS_EXPORT RefactoringEngineInterface { public: using RenameCallback = ClangBackEnd::RefactoringClientInterface::RenameCallback; + using Link = Utils::Link; virtual ~RefactoringEngineInterface() {} @@ -65,6 +70,11 @@ public: const QString &replacement) = 0; virtual void findUsages(const CppTools::CursorInEditor &data, UsagesCallback &&showUsagesCallback) const = 0; + virtual Link globalFollowSymbol(const CursorInEditor &data, + const CPlusPlus::Snapshot &snapshot, + const CPlusPlus::Document::Ptr &documentFromSemanticInfo, + SymbolFinder *symbolFinder, + bool inNextSplit) const = 0; virtual bool isRefactoringEngineAvailable() const { return true; } }; diff --git a/src/plugins/cpptools/usages.h b/src/plugins/cpptools/usages.h index a3cea0f9e5..60d29ddbcd 100644 --- a/src/plugins/cpptools/usages.h +++ b/src/plugins/cpptools/usages.h @@ -37,6 +37,7 @@ namespace CppTools { class Usage { public: + Usage() {} Usage(Utils::SmallStringView path, int line, int column) : path(QString::fromUtf8(path.data(), int(path.size()))), line(line), @@ -52,8 +53,8 @@ public: public: QString path; - int line; - int column; + int line = 0; + int column = 0; }; using Usages = std::vector<Usage>; diff --git a/src/tools/clangbackend/source/clangcodemodelserver.cpp b/src/tools/clangbackend/source/clangcodemodelserver.cpp index df8f138158..20a6e65920 100644 --- a/src/tools/clangbackend/source/clangcodemodelserver.cpp +++ b/src/tools/clangbackend/source/clangcodemodelserver.cpp @@ -281,7 +281,6 @@ void ClangCodeModelServer::requestFollowSymbol(const RequestFollowSymbolMessage JobRequest jobRequest = processor.createJobRequest(JobRequest::Type::FollowSymbol); fillJobRequest(jobRequest, message); - jobRequest.dependentFiles = message.dependentFiles(); processor.addJob(jobRequest); processor.process(); } catch (const std::exception &exception) { diff --git a/src/tools/clangbackend/source/clangfollowsymbol.cpp b/src/tools/clangbackend/source/clangfollowsymbol.cpp index bc151bc93c..26de30ed34 100644 --- a/src/tools/clangbackend/source/clangfollowsymbol.cpp +++ b/src/tools/clangbackend/source/clangfollowsymbol.cpp @@ -133,47 +133,6 @@ static SourceRangeContainer extractMatchingTokenRange(const Cursor &cursor, return SourceRangeContainer(); } -static void handleDeclaration(CXClientData client_data, const CXIdxDeclInfo *declInfo) -{ - if (!declInfo || !declInfo->isDefinition) - return; - - const Cursor currentCursor(declInfo->cursor); - auto* data = reinterpret_cast<FollowSymbolData*>(client_data); - if (data->ready()) - return; - - if (data->usr() != currentCursor.canonical().unifiedSymbolResolution()) - return; - - QString str = Utf8String(currentCursor.displayName()); - if (currentCursor.isFunctionLike() || currentCursor.isConstructorOrDestructor()) { - if (!data->isFunctionLike()) - return; - str = str.mid(0, str.indexOf('(')); - } else if (data->isFunctionLike()) { - return; - } - if (!str.endsWith(data->spelling())) - return; - const CXTranslationUnit tu = clang_Cursor_getTranslationUnit(declInfo->cursor); - Tokens tokens(currentCursor); - - for (uint i = 0; i < tokens.tokenCount; ++i) { - Utf8String curSpelling = ClangString(clang_getTokenSpelling(tu, tokens.data[i])); - if (data->spelling() == curSpelling) { - if (data->isFunctionLike() - && (i+1 >= tokens.tokenCount - || !(ClangString(clang_getTokenSpelling(tu, tokens.data[i+1])) == "("))) { - continue; - } - data->setResult(SourceRange(clang_getTokenExtent(tu, tokens.data[i]))); - data->setReady(); - return; - } - } -} - static int getTokenIndex(CXTranslationUnit tu, const Tokens &tokens, uint line, uint column) { int tokenIndex = -1; @@ -187,90 +146,10 @@ static int getTokenIndex(CXTranslationUnit tu, const Tokens &tokens, uint line, return tokenIndex; } -static IndexerCallbacks createIndexerCallbacks() -{ - return { - [](CXClientData client_data, void *) { - auto* data = reinterpret_cast<FollowSymbolData*>(client_data); - return data->ready() ? 1 : 0; - }, - [](CXClientData, CXDiagnosticSet, void *) {}, - [](CXClientData, CXFile, void *) { return CXIdxClientFile(); }, - [](CXClientData, const CXIdxIncludedFileInfo *) { return CXIdxClientFile(); }, - [](CXClientData, const CXIdxImportedASTFileInfo *) { return CXIdxClientASTFile(); }, - [](CXClientData, void *) { return CXIdxClientContainer(); }, - handleDeclaration, - [](CXClientData, const CXIdxEntityRefInfo *) {} - }; -} - -static SourceRangeContainer followSymbolInDependentFiles(CXIndex index, - const Cursor &cursor, - const Utf8String &tokenSpelling, - const QVector<Utf8String> &dependentFiles, - const CommandLineArguments ¤tArgs) -{ - int argsCount = 0; - if (currentArgs.data()) - argsCount = currentArgs.count() - 1; - - const Utf8String usr = cursor.canonical().unifiedSymbolResolution(); - - // ready is shared for all data in vector - std::atomic<bool> ready {false}; - std::vector<FollowSymbolData> dataVector( - dependentFiles.size(), - FollowSymbolData(usr, tokenSpelling, - cursor.isFunctionLike() || cursor.isConstructorOrDestructor(), - ready)); - - std::vector<std::future<void>> indexFutures; - - for (int i = 0; i < dependentFiles.size(); ++i) { - if (i > 0 && ready) - break; - indexFutures.emplace_back(std::async([&, i]() { - TIME_SCOPE_DURATION("Dependent file " + dependentFiles.at(i) + " indexer runner"); - - const CXIndexAction indexAction = clang_IndexAction_create(index); - IndexerCallbacks callbacks = createIndexerCallbacks(); - clang_indexSourceFile(indexAction, - &dataVector[i], - &callbacks, - sizeof(callbacks), - CXIndexOpt_SkipParsedBodiesInSession - | CXIndexOpt_SuppressRedundantRefs - | CXIndexOpt_SuppressWarnings, - dependentFiles.at(i).constData(), - currentArgs.data(), - argsCount, - nullptr, - 0, - nullptr, - CXTranslationUnit_SkipFunctionBodies - | CXTranslationUnit_KeepGoing); - clang_IndexAction_dispose(indexAction); - })); - } - - for (const std::future<void> &future: indexFutures) - future.wait(); - - for (const FollowSymbolData &data: dataVector) { - if (!data.result().start().filePath().isEmpty()) { - return data.result(); - } - } - return SourceRangeContainer(); -} - SourceRangeContainer FollowSymbol::followSymbol(CXTranslationUnit tu, - CXIndex index, const Cursor &fullCursor, uint line, - uint column, - const QVector<Utf8String> &dependentFiles, - const CommandLineArguments ¤tArgs) + uint column) { std::unique_ptr<Tokens> tokens(new Tokens(fullCursor)); @@ -303,35 +182,23 @@ SourceRangeContainer FollowSymbol::followSymbol(CXTranslationUnit tu, if (cursor.isDefinition()) return extractMatchingTokenRange(cursor.canonical(), tokenSpelling); - SourceRangeContainer result; if (!cursor.isDeclaration()) { // This is the symbol usage - // We want to return definition or at least declaration of this symbol - const Cursor referencedCursor = cursor.referenced(); - if (referencedCursor.isNull() || referencedCursor == cursor) + // We want to return definition + cursor = cursor.referenced(); + if (cursor.isNull() || !cursor.isDefinition()) { + // We can't find definition in this TU return SourceRangeContainer(); - result = extractMatchingTokenRange(referencedCursor, tokenSpelling); - - // We've already found what we need - if (referencedCursor.isDefinition()) - return result; - cursor = referencedCursor; + } + return extractMatchingTokenRange(cursor, tokenSpelling); } - const Cursor definitionCursor = cursor.definition(); - if (!definitionCursor.isNull() && definitionCursor != cursor) { - // If we are able to find a definition in current TU - return extractMatchingTokenRange(definitionCursor, tokenSpelling); - } + cursor = cursor.definition(); + // If we are able to find a definition in current TU + if (!cursor.isNull()) + return extractMatchingTokenRange(cursor, tokenSpelling); - // Search for the definition in the dependent files - SourceRangeContainer dependentFilesResult = followSymbolInDependentFiles(index, - cursor, - tokenSpelling, - dependentFiles, - currentArgs); - return dependentFilesResult.start().filePath().isEmpty() ? - result : dependentFilesResult; + return SourceRangeContainer(); } } // namespace ClangBackEnd diff --git a/src/tools/clangbackend/source/clangfollowsymbol.h b/src/tools/clangbackend/source/clangfollowsymbol.h index a881bd9631..07db59a836 100644 --- a/src/tools/clangbackend/source/clangfollowsymbol.h +++ b/src/tools/clangbackend/source/clangfollowsymbol.h @@ -41,12 +41,9 @@ class FollowSymbol { public: static SourceRangeContainer followSymbol(CXTranslationUnit tu, - CXIndex index, const Cursor &fullCursor, uint line, - uint column, - const QVector<Utf8String> &dependentFiles, - const CommandLineArguments ¤tArgs); + uint column); }; } // namespace ClangBackEnd diff --git a/src/tools/clangbackend/source/clangfollowsymboljob.cpp b/src/tools/clangbackend/source/clangfollowsymboljob.cpp index 7136db3432..20836fddea 100644 --- a/src/tools/clangbackend/source/clangfollowsymboljob.cpp +++ b/src/tools/clangbackend/source/clangfollowsymboljob.cpp @@ -42,17 +42,12 @@ IAsyncJob::AsyncPrepareResult FollowSymbolJob::prepareAsyncRun() const TranslationUnit translationUnit = *m_translationUnit; const TranslationUnitUpdateInput updateInput = m_pinnedDocument.createUpdateInput(); - const CommandLineArguments currentArgs(updateInput.filePath.constData(), - updateInput.projectArguments, - updateInput.fileArguments, - false); const quint32 line = jobRequest.line; const quint32 column = jobRequest.column; - const QVector<Utf8String> &dependentFiles = jobRequest.dependentFiles; - setRunner([translationUnit, line, column, dependentFiles, currentArgs]() { + setRunner([translationUnit, line, column]() { TIME_SCOPE_DURATION("FollowSymbolJobRunner"); - return translationUnit.followSymbol(line, column, dependentFiles, currentArgs); + return translationUnit.followSymbol(line, column); }); return AsyncPrepareResult{translationUnit.id()}; diff --git a/src/tools/clangbackend/source/clangjobrequest.h b/src/tools/clangbackend/source/clangjobrequest.h index 2df63e126d..fb72491e4b 100644 --- a/src/tools/clangbackend/source/clangjobrequest.h +++ b/src/tools/clangbackend/source/clangjobrequest.h @@ -117,7 +117,6 @@ public: qint32 funcNameStartLine = -1; qint32 funcNameStartColumn = -1; quint64 ticketNumber = 0; - Utf8StringVector dependentFiles; bool localReferences = false; }; diff --git a/src/tools/clangbackend/source/clangtranslationunit.cpp b/src/tools/clangbackend/source/clangtranslationunit.cpp index 6f54deab46..9482780113 100644 --- a/src/tools/clangbackend/source/clangtranslationunit.cpp +++ b/src/tools/clangbackend/source/clangtranslationunit.cpp @@ -238,13 +238,9 @@ void TranslationUnit::extractDiagnostics(DiagnosticContainer &firstHeaderErrorDi } } -SourceRangeContainer TranslationUnit::followSymbol(uint line, - uint column, - const QVector<Utf8String> &dependentFiles, - const CommandLineArguments ¤tArgs) const +SourceRangeContainer TranslationUnit::followSymbol(uint line, uint column) const { - return FollowSymbol::followSymbol(m_cxTranslationUnit, m_cxIndex, cursorAt(line, column), line, - column, dependentFiles, currentArgs); + return FollowSymbol::followSymbol(m_cxTranslationUnit, cursorAt(line, column), line, column); } } // namespace ClangBackEnd diff --git a/src/tools/clangbackend/source/clangtranslationunit.h b/src/tools/clangbackend/source/clangtranslationunit.h index 9110d637d1..76ba3f0055 100644 --- a/src/tools/clangbackend/source/clangtranslationunit.h +++ b/src/tools/clangbackend/source/clangtranslationunit.h @@ -100,10 +100,7 @@ public: TokenInfos tokenInfosInRange(const SourceRange &range) const; SkippedSourceRanges skippedSourceRanges() const; - SourceRangeContainer followSymbol(uint line, - uint column, - const QVector<Utf8String> &dependentFiles, - const CommandLineArguments ¤tArgs) const; + SourceRangeContainer followSymbol(uint line, uint column) const; private: const Utf8String m_id; diff --git a/tests/unit/unittest/clangcodemodelserver-test.cpp b/tests/unit/unittest/clangcodemodelserver-test.cpp index bb20a5fa35..1b2c95c8a1 100644 --- a/tests/unit/unittest/clangcodemodelserver-test.cpp +++ b/tests/unit/unittest/clangcodemodelserver-test.cpp @@ -619,7 +619,7 @@ void ClangCodeModelServer::requestFollowSymbol(quint32 documentRevision) { const FileContainer fileContainer{filePathC, projectPartId, Utf8StringVector(), documentRevision}; - const RequestFollowSymbolMessage message{fileContainer, QVector<Utf8String>(), 43, 9}; + const RequestFollowSymbolMessage message{fileContainer, 43, 9}; clangServer.requestFollowSymbol(message); } diff --git a/tests/unit/unittest/clangfollowsymbol-test.cpp b/tests/unit/unittest/clangfollowsymbol-test.cpp index fcc970b3a8..f42e8e6399 100644 --- a/tests/unit/unittest/clangfollowsymbol-test.cpp +++ b/tests/unit/unittest/clangfollowsymbol-test.cpp @@ -133,23 +133,12 @@ class FollowSymbol : public ::testing::Test protected: SourceRangeContainer followSymbol(uint line, uint column) { - ClangBackEnd::TranslationUnitUpdateInput updateInput = document.createUpdateInput(); - const ClangBackEnd::CommandLineArguments currentArgs(updateInput.filePath.constData(), - updateInput.projectArguments, - updateInput.fileArguments, - false); - return document.translationUnit().followSymbol(line, column, deps, currentArgs); + return document.translationUnit().followSymbol(line, column); } SourceRangeContainer followHeaderSymbol(uint line, uint column) { - ClangBackEnd::TranslationUnitUpdateInput updateInput - = headerDocument.createUpdateInput(); - const ClangBackEnd::CommandLineArguments currentArgs(updateInput.filePath.constData(), - updateInput.projectArguments, - updateInput.fileArguments, - false); - return headerDocument.translationUnit().followSymbol(line, column, deps, currentArgs); + return headerDocument.translationUnit().followSymbol(line, column); } static void SetUpTestCase(); @@ -162,6 +151,10 @@ private: const QVector<Utf8String> &deps{data->deps}; }; +// NOTE: some tests are disabled because clang code model does not need to follow symbols +// to other translation units. When there's infrastructure to test database based follow symbol +// they should be moved there. + TEST_F(FollowSymbol, CursorOnNamespace) { const auto namespaceDefinition = followSymbol(27, 1); @@ -183,7 +176,7 @@ TEST_F(FollowSymbol, CursorOnClassForwardDeclarationFollowToHeader) ASSERT_THAT(classDefinition, MatchesHeaderSourceRange(34, 7, 3)); } -TEST_F(FollowSymbol, CursorOnClassForwardDeclarationFollowToCpp) +TEST_F(FollowSymbol, DISABLED_CursorOnClassForwardDeclarationFollowToCpp) { const auto classDefinition = followHeaderSymbol(48, 9); @@ -204,7 +197,7 @@ TEST_F(FollowSymbol, CursorOnClassDefinitionInCpp) ASSERT_THAT(classForwardDeclaration, MatchesHeaderSourceRange(48, 7, 8)); } -TEST_F(FollowSymbol, CursorOnConstructorDeclaration) +TEST_F(FollowSymbol, DISABLED_CursorOnConstructorDeclaration) { const auto constructorDefinition = followHeaderSymbol(36, 5); @@ -239,14 +232,14 @@ TEST_F(FollowSymbol, CursorOnFunctionReference) ASSERT_THAT(functionDefinition, MatchesSourceRange(35, 5, 3)); } -TEST_F(FollowSymbol, CursorOnMemberFunctionReference) +TEST_F(FollowSymbol, DISABLED_CursorOnMemberFunctionReference) { const auto memberFunctionDefinition = followSymbol(42, 12); ASSERT_THAT(memberFunctionDefinition, MatchesSourceRange(49, 21, 3)); } -TEST_F(FollowSymbol, CursorOnFunctionWithoutDefinitionReference) +TEST_F(FollowSymbol, DISABLED_CursorOnFunctionWithoutDefinitionReference) { const auto functionDeclaration = followSymbol(43, 5); @@ -267,7 +260,7 @@ TEST_F(FollowSymbol, CursorOnMemberFunctionDefinition) ASSERT_THAT(memberFunctionDeclaration, MatchesHeaderSourceRange(43, 9, 3)); } -TEST_F(FollowSymbol, CursorOnMemberFunctionDeclaration) +TEST_F(FollowSymbol, DISABLED_CursorOnMemberFunctionDeclaration) { const auto memberFunctionDefinition = followHeaderSymbol(43, 9); @@ -302,14 +295,14 @@ TEST_F(FollowSymbol, CursorOnStaticVariable) ASSERT_THAT(staticVariableDeclaration, MatchesHeaderSourceRange(30, 7, 7)); } -TEST_F(FollowSymbol, CursorOnFunctionFromOtherClass) +TEST_F(FollowSymbol, DISABLED_CursorOnFunctionFromOtherClass) { const auto functionDefinition = followSymbol(62, 39); ASSERT_THAT(functionDefinition, MatchesFileSourceRange(cursorPath, 104, 22, 8)); } -TEST_F(FollowSymbol, CursorOnDefineReference) +TEST_F(FollowSymbol, DISABLED_CursorOnDefineReference) { const auto functionDefinition = followSymbol(66, 43); diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 710544f44d..2c106ec0e5 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -531,7 +531,6 @@ std::ostream &operator<<(std::ostream &os, const RequestFollowSymbolMessage &mes { os << "(" << message.fileContainer() << ", " - << message.dependentFiles() << ", " << message.ticketNumber() << ", " << message.line() << ", " << message.column() << ", " diff --git a/tests/unit/unittest/readandwritemessageblock-test.cpp b/tests/unit/unittest/readandwritemessageblock-test.cpp index cf69837dc0..8f3d1e848c 100644 --- a/tests/unit/unittest/readandwritemessageblock-test.cpp +++ b/tests/unit/unittest/readandwritemessageblock-test.cpp @@ -205,10 +205,7 @@ TEST_F(ReadAndWriteMessageBlock, CompareRequestReferences) TEST_F(ReadAndWriteMessageBlock, CompareRequestFollowSymbol) { - QVector<Utf8String> dependentFiles; - dependentFiles.push_back(QString("somefile.cpp")); - dependentFiles.push_back(QString("otherfile.cpp")); - CompareMessage(ClangBackEnd::RequestFollowSymbolMessage{fileContainer, dependentFiles, 13, 37}); + CompareMessage(ClangBackEnd::RequestFollowSymbolMessage{fileContainer, 13, 37}); } TEST_F(ReadAndWriteMessageBlock, CompareReferences) |