diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2022-04-25 13:37:58 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2022-04-28 09:47:52 +0000 |
commit | f2c267f3283ef70ad053b507b17513be068b2e6b (patch) | |
tree | f7dd540213b7042a6e51e83f6252d55f5fa248b4 /src | |
parent | 8e586dfa022232a82762503c896a0088429cd8c7 (diff) |
ClangCodeModel: Remove libclang fallback for "follow symbol"
... and "switch between declaration/definition".
It's either clangd or built-in code model now.
Use the opportunity to dissolve the pointless FollowSymbolInterface
class hierarchy, which introduced a confusing parallel inheritance
chain.
Change-Id: I792ad55656c5dd9f10c6b4db7c5c36cf7be45125
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src')
23 files changed, 117 insertions, 523 deletions
diff --git a/src/plugins/clangcodemodel/CMakeLists.txt b/src/plugins/clangcodemodel/CMakeLists.txt index 1e8b9a53e9..153bc4ae62 100644 --- a/src/plugins/clangcodemodel/CMakeLists.txt +++ b/src/plugins/clangcodemodel/CMakeLists.txt @@ -35,7 +35,6 @@ add_qtc_plugin(ClangCodeModel clangeditordocumentprocessor.cpp clangeditordocumentprocessor.h clangfixitoperation.cpp clangfixitoperation.h clangfixitoperationsextractor.cpp clangfixitoperationsextractor.h - clangfollowsymbol.cpp clangfollowsymbol.h clangfunctionhintmodel.cpp clangfunctionhintmodel.h clangdlocatorfilters.cpp clangdlocatorfilters.h clanghighlightingresultreporter.cpp clanghighlightingresultreporter.h diff --git a/src/plugins/clangcodemodel/clangcodemodel.qbs b/src/plugins/clangcodemodel/clangcodemodel.qbs index 75a7f6bc90..f6a62d42cb 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.qbs +++ b/src/plugins/clangcodemodel/clangcodemodel.qbs @@ -78,8 +78,6 @@ QtcPlugin { "clangfixitoperation.h", "clangfixitoperationsextractor.cpp", "clangfixitoperationsextractor.h", - "clangfollowsymbol.cpp", - "clangfollowsymbol.h", "clangfunctionhintmodel.cpp", "clangfunctionhintmodel.h", "clanghighlightingresultreporter.cpp", diff --git a/src/plugins/clangcodemodel/clangfollowsymbol.cpp b/src/plugins/clangcodemodel/clangfollowsymbol.cpp deleted file mode 100644 index c81bbe1268..0000000000 --- a/src/plugins/clangcodemodel/clangfollowsymbol.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "clangfollowsymbol.h" - -#include "clangdclient.h" -#include "clangeditordocumentprocessor.h" -#include "clangmodelmanagersupport.h" - -#include <coreplugin/editormanager/editormanager.h> -#include <cppeditor/cppmodelmanager.h> -#include <cppeditor/cppfollowsymbolundercursor.h> -#include <texteditor/texteditor.h> - -#include <clangsupport/tokeninfocontainer.h> - -#include <utils/textutils.h> -#include <utils/algorithm.h> - -#include <memory> - -namespace ClangCodeModel { -namespace Internal { - -// Returns invalid Mark if it is not found at (line, column) -static bool findMark(const QVector<ClangBackEnd::TokenInfoContainer> &marks, - int line, - int column, - ClangBackEnd::TokenInfoContainer &mark) -{ - mark = Utils::findOrDefault(marks, - [line, column](const ClangBackEnd::TokenInfoContainer &curMark) { - if (curMark.line != line) - return false; - if (curMark.column == column) - return true; - if (curMark.column < column && curMark.column + curMark.length > column) - return true; - return false; - }); - if (mark.isInvalid()) - return false; - return true; -} - -static int getMarkPos(QTextCursor cursor, const ClangBackEnd::TokenInfoContainer &mark) -{ - cursor.setPosition(0); - cursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, mark.line - 1); - cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, mark.column - 1); - return cursor.position(); -} - -static bool isValidIncludePathToken(const ClangBackEnd::TokenInfoContainer &token) -{ - if (!token.extraInfo.includeDirectivePath) - return false; - const Utf8String &tokenName = token.extraInfo.token; - return !tokenName.startsWith("include") && tokenName != Utf8String("<") - && tokenName != Utf8String(">") && tokenName != Utf8String("#"); -} - -static int includePathStartIndex(const QVector<ClangBackEnd::TokenInfoContainer> &marks, - int currentIndex) -{ - int startIndex = currentIndex - 1; - while (startIndex >= 0 && isValidIncludePathToken(marks[startIndex])) - --startIndex; - return startIndex + 1; -} - -static int includePathEndIndex(const QVector<ClangBackEnd::TokenInfoContainer> &marks, - int currentIndex) -{ - int endIndex = currentIndex + 1; - while (endIndex < marks.size() && isValidIncludePathToken(marks[endIndex])) - ++endIndex; - return endIndex - 1; -} - -static Utils::Link linkAtCursor(const QTextCursor &cursor, - const QString &filePath, - uint line, - uint column, - ClangEditorDocumentProcessor *processor) -{ - using Link = Utils::Link; - - const QVector<ClangBackEnd::TokenInfoContainer> &marks - = processor->tokenInfos(); - ClangBackEnd::TokenInfoContainer mark; - if (!findMark(marks, line, column, mark)) - return Link(); - - if (mark.extraInfo.includeDirectivePath && !isValidIncludePathToken(mark)) - return Link(); - - Link token(Utils::FilePath::fromString(filePath), mark.line, mark.column); - token.linkTextStart = getMarkPos(cursor, mark); - token.linkTextEnd = token.linkTextStart + mark.length; - - if (mark.extraInfo.includeDirectivePath) { - // Tweak include paths to cover everything between "" or <>. - if (mark.extraInfo.token.startsWith("\"")) { - token.linkTextStart++; - token.linkTextEnd--; - } else { - // '#include <path/file.h>' case. Clang gives us a separate token for each part of - // the path. We want to have the full range instead therefore we search for < and > - // tokens around the current token. - const int index = marks.indexOf(mark); - const int startIndex = includePathStartIndex(marks, index); - const int endIndex = includePathEndIndex(marks, index); - - if (startIndex != index) - token.linkTextStart = getMarkPos(cursor, marks[startIndex]); - if (endIndex != index) - token.linkTextEnd = getMarkPos(cursor, marks[endIndex]) + marks[endIndex].length; - } - return token; - } - - if (mark.extraInfo.identifier || mark.extraInfo.token == "operator" - || mark.extraInfo.token == "auto") { - return token; - } - return Link(); -} - -static ::Utils::ProcessLinkCallback extendedCallback(::Utils::ProcessLinkCallback &&callback, - const CppEditor::SymbolInfo &result) -{ - // If globalFollowSymbol finds nothing follow to the declaration. - return [original_callback = std::move(callback), result](const ::Utils::Link &link) { - if (link.linkTextStart < 0 && result.isResultOnlyForFallBack) { - return original_callback(Utils::Link( - Utils::FilePath::fromString(result.fileName).cleanPath(), - result.startLine, - result.startColumn - 1)); - } - return original_callback(link); - }; -} - -static bool isSameInvocationContext(const Utils::FilePath &filePath) -{ - return TextEditor::BaseTextEditor::currentTextEditor()->editorWidget()->isVisible() - && Core::EditorManager::currentDocument()->filePath() == filePath; -} - -void ClangFollowSymbol::findLink(const CppEditor::CursorInEditor &data, - ::Utils::ProcessLinkCallback &&processLinkCallback, - bool resolveTarget, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &documentFromSemanticInfo, - CppEditor::SymbolFinder *symbolFinder, - bool inNextSplit) -{ - ClangdClient * const client - = ClangModelManagerSupport::instance()->clientForFile(data.filePath()); - if (client && client->isFullyIndexed()) { - client->followSymbol(data.textDocument(), data.cursor(), data.editorWidget(), - std::move(processLinkCallback), resolveTarget, inNextSplit); - return; - } - - int line = 0; - int column = 0; - QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor()); - Utils::Text::convertPosition(cursor.document(), cursor.position(), &line, &column); - - ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get( - data.filePath().toString()); - if (!processor) - return processLinkCallback(Utils::Link()); - - if (!resolveTarget) { - Utils::Link link = linkAtCursor(cursor, - data.filePath().toString(), - static_cast<uint>(line), - static_cast<uint>(column), - processor); - if (link == Utils::Link()) { - CppEditor::FollowSymbolUnderCursor followSymbol; - return followSymbol.findLink(data, - std::move(processLinkCallback), - false, - snapshot, - documentFromSemanticInfo, - symbolFinder, - inNextSplit); - } - return processLinkCallback(link); - } - - QFuture<CppEditor::SymbolInfo> infoFuture - = processor->requestFollowSymbol(static_cast<int>(line), - static_cast<int>(column)); - - if (infoFuture.isCanceled()) - return processLinkCallback(Utils::Link()); - - if (m_watcher) - m_watcher->cancel(); - - m_watcher = std::make_unique<FutureSymbolWatcher>(); - - QObject::connect(m_watcher.get(), &FutureSymbolWatcher::finished, [=, filePath=data.filePath(), - callback=std::move(processLinkCallback)]() mutable { - if (m_watcher->isCanceled() || !isSameInvocationContext(filePath)) - return callback(Utils::Link()); - CppEditor::SymbolInfo result = m_watcher->result(); - // We did not fail but the result is empty - if (result.fileName.isEmpty() || result.isResultOnlyForFallBack) { - const CppEditor::RefactoringEngineInterface &refactoringEngine - = *CppEditor::CppModelManager::instance(); - refactoringEngine.globalFollowSymbol(data, - extendedCallback(std::move(callback), result), - snapshot, - documentFromSemanticInfo, - symbolFinder, - inNextSplit); - } else { - callback(Link(Utils::FilePath::fromString(result.fileName).cleanPath(), - result.startLine, - result.startColumn - 1)); - } - }); - - m_watcher->setFuture(infoFuture); -} - -void ClangFollowSymbol::switchDeclDef(const CppEditor::CursorInEditor &data, - Utils::ProcessLinkCallback &&processLinkCallback, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &documentFromSemanticInfo, - CppEditor::SymbolFinder *symbolFinder) -{ - ClangdClient * const client - = ClangModelManagerSupport::instance()->clientForFile(data.filePath()); - if (client && client->isFullyIndexed()) { - client->switchDeclDef(data.textDocument(), data.cursor(), data.editorWidget(), - std::move(processLinkCallback)); - return; - } - CppEditor::CppModelManager::builtinFollowSymbol().switchDeclDef( - data, std::move(processLinkCallback), snapshot, documentFromSemanticInfo, - symbolFinder); -} - -} // namespace Internal -} // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangfollowsymbol.h b/src/plugins/clangcodemodel/clangfollowsymbol.h deleted file mode 100644 index 0ae10035b4..0000000000 --- a/src/plugins/clangcodemodel/clangfollowsymbol.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include <cppeditor/cpptoolsreuse.h> -#include <cppeditor/followsymbolinterface.h> - -#include <QFutureWatcher> - -namespace ClangCodeModel { -namespace Internal { - -class ClangFollowSymbol : public CppEditor::FollowSymbolInterface -{ -public: - void findLink(const CppEditor::CursorInEditor &data, - ::Utils::ProcessLinkCallback &&processLinkCallback, - bool resolveTarget, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &documentFromSemanticInfo, - CppEditor::SymbolFinder *symbolFinder, - bool inNextSplit) override; - - void switchDeclDef(const CppEditor::CursorInEditor &data, - Utils::ProcessLinkCallback &&processLinkCallback, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &documentFromSemanticInfo, - CppEditor::SymbolFinder *symbolFinder) override; - -private: - using FutureSymbolWatcher = QFutureWatcher<CppEditor::SymbolInfo>; - std::unique_ptr<FutureSymbolWatcher> m_watcher; - -}; - -} // namespace Internal -} // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index afc72cee82..fe7ddcf4cd 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -29,7 +29,6 @@ #include "clangdclient.h" #include "clangdquickfixfactory.h" #include "clangeditordocumentprocessor.h" -#include "clangfollowsymbol.h" #include "clangdlocatorfilters.h" #include "clanghoverhandler.h" #include "clangoverviewmodel.h" @@ -45,11 +44,13 @@ #include <cppeditor/cppcodemodelsettings.h> #include <cppeditor/cppeditorconstants.h> +#include <cppeditor/cppeditorwidget.h> #include <cppeditor/cppfollowsymbolundercursor.h> #include <cppeditor/cppmodelmanager.h> #include <cppeditor/cppprojectfile.h> #include <cppeditor/cpptoolsreuse.h> #include <cppeditor/editordocumenthandle.h> +#include <cppeditor/symbolfinder.h> #include <languageclient/languageclientmanager.h> @@ -106,7 +107,6 @@ static const QList<TextEditor::TextDocument *> allCppDocuments() ClangModelManagerSupport::ClangModelManagerSupport() : m_completionAssistProvider(m_communicator, CompletionType::Other) , m_functionHintAssistProvider(m_communicator, CompletionType::FunctionHint) - , m_followSymbol(new ClangFollowSymbol) , m_refactoringEngine(new RefactoringEngine) { QTC_CHECK(!m_instance); @@ -188,9 +188,37 @@ TextEditor::BaseHoverHandler *ClangModelManagerSupport::createHoverHandler() return new Internal::ClangHoverHandler; } -CppEditor::FollowSymbolInterface &ClangModelManagerSupport::followSymbolInterface() +void ClangModelManagerSupport::followSymbol(const CppEditor::CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback, bool resolveTarget, + bool inNextSplit) { - return *m_followSymbol; + if (ClangdClient * const client = clientForFile(data.filePath()); + client && client->isFullyIndexed()) { + client->followSymbol(data.textDocument(), data.cursor(), data.editorWidget(), + std::move(processLinkCallback), resolveTarget, inNextSplit); + return; + } + + SymbolFinder finder; + CppModelManager::builtinFollowSymbol().findLink(data, std::move(processLinkCallback), + resolveTarget, CppModelManager::instance()->snapshot(), + data.editorWidget()->semanticInfo().doc, &finder, inNextSplit); +} + +void ClangModelManagerSupport::switchDeclDef(const CppEditor::CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback) +{ + if (ClangdClient * const client = clientForFile(data.filePath()); + client && client->isFullyIndexed()) { + client->switchDeclDef(data.textDocument(), data.cursor(), data.editorWidget(), + std::move(processLinkCallback)); + return; + } + + SymbolFinder finder; + CppModelManager::builtinFollowSymbol().switchDeclDef(data, std::move(processLinkCallback), + CppModelManager::instance()->snapshot(), data.editorWidget()->semanticInfo().doc, + &finder); } CppEditor::RefactoringEngineInterface &ClangModelManagerSupport::refactoringEngineInterface() diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.h b/src/plugins/clangcodemodel/clangmodelmanagersupport.h index b957ae69b9..06355f8ab2 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.h +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.h @@ -45,10 +45,7 @@ class QWidget; QT_END_NAMESPACE namespace TextEditor { class TextEditorWidget; } -namespace CppEditor { -class FollowSymbolInterface; -class RefactoringEngineInterface; -} // namespace CppEditor +namespace CppEditor { class RefactoringEngineInterface; } namespace ClangCodeModel { namespace Internal { @@ -71,7 +68,6 @@ public: TextEditor::BaseHoverHandler *createHoverHandler() override; CppEditor::BaseEditorDocumentProcessor *createEditorDocumentProcessor( TextEditor::TextDocument *baseTextDocument) override; - CppEditor::FollowSymbolInterface &followSymbolInterface() override; CppEditor::RefactoringEngineInterface &refactoringEngineInterface() override; std::unique_ptr<CppEditor::AbstractOverviewModel> createOverviewModel() override; bool supportsOutline(const TextEditor::TextDocument *document) const override; @@ -92,6 +88,12 @@ signals: void createdClient(ClangdClient *client); private: + void followSymbol(const CppEditor::CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback, bool resolveTarget, + bool inNextSplit) override; + void switchDeclDef(const CppEditor::CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback) override; + void onEditorOpened(Core::IEditor *editor); void onEditorClosed(const QList<Core::IEditor *> &editors); void onCurrentEditorChanged(Core::IEditor *newCurrent); @@ -142,7 +144,6 @@ private: BackendCommunicator m_communicator; ClangCompletionAssistProvider m_completionAssistProvider; ClangCompletionAssistProvider m_functionHintAssistProvider; - std::unique_ptr<CppEditor::FollowSymbolInterface> m_followSymbol; std::unique_ptr<CppEditor::RefactoringEngineInterface> m_refactoringEngine; QHash<ProjectExplorer::Project *, ClangProjectSettings *> m_projectSettings; diff --git a/src/plugins/clangcodemodel/clangrefactoringengine.cpp b/src/plugins/clangcodemodel/clangrefactoringengine.cpp index fb2a743a84..751700c1b9 100644 --- a/src/plugins/clangcodemodel/clangrefactoringengine.cpp +++ b/src/plugins/clangcodemodel/clangrefactoringengine.cpp @@ -124,25 +124,5 @@ void RefactoringEngine::findUsages(const CppEditor::CursorInEditor &cursor, client->findUsages(cursor.textDocument(), cursor.cursor(), {}); } -void RefactoringEngine::globalFollowSymbol( - const CppEditor::CursorInEditor &cursor, - Utils::ProcessLinkCallback &&callback, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &doc, - CppEditor::SymbolFinder *symbolFinder, - bool inNextSplit) const -{ - ClangdClient * const client - = ClangModelManagerSupport::instance()->clientForFile(cursor.filePath()); - if (!client || !client->isFullyIndexed()) { - CppEditor::CppModelManager::builtinRefactoringEngine() - ->globalFollowSymbol(cursor, std::move(callback), snapshot, doc, symbolFinder, - inNextSplit); - return; - } - client->followSymbol(cursor.textDocument(), cursor.cursor(), cursor.editorWidget(), - std::move(callback), true, inNextSplit); -} - } // namespace Internal } // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangrefactoringengine.h b/src/plugins/clangcodemodel/clangrefactoringengine.h index ea324f9899..407e267b8e 100644 --- a/src/plugins/clangcodemodel/clangrefactoringengine.h +++ b/src/plugins/clangcodemodel/clangrefactoringengine.h @@ -48,12 +48,6 @@ public: const QString &replacement) override; void findUsages(const CppEditor::CursorInEditor &cursor, CppEditor::UsagesCallback &&callback) const override; - void globalFollowSymbol(const CppEditor::CursorInEditor &cursor, - ::Utils::ProcessLinkCallback &&callback, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &doc, - CppEditor::SymbolFinder *symbolFinder, - bool inNextSplit) const override; private: using FutureCursorWatcher = QFutureWatcher<CppEditor::CursorInfo>; diff --git a/src/plugins/cppeditor/CMakeLists.txt b/src/plugins/cppeditor/CMakeLists.txt index 31f28cd13c..a5b0f7ff53 100644 --- a/src/plugins/cppeditor/CMakeLists.txt +++ b/src/plugins/cppeditor/CMakeLists.txt @@ -102,7 +102,6 @@ add_qtc_plugin(CppEditor cursorineditor.h doxygengenerator.cpp doxygengenerator.h editordocumenthandle.cpp editordocumenthandle.h - followsymbolinterface.h functionutils.cpp functionutils.h generatedcodemodelsupport.cpp generatedcodemodelsupport.h headerpathfilter.cpp headerpathfilter.h diff --git a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp index 18dac93753..317a1edf84 100644 --- a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp +++ b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp @@ -27,11 +27,13 @@ #include "builtineditordocumentprocessor.h" #include "cppcompletionassist.h" +#include "cppeditorwidget.h" #include "cppelementevaluator.h" #include "cppfollowsymbolundercursor.h" #include "cppoverviewmodel.h" #include "cpprefactoringengine.h" #include "cpptoolsreuse.h" +#include "symbolfinder.h" #include <app/app_version.h> #include <texteditor/basehoverhandler.h> @@ -127,11 +129,6 @@ TextEditor::BaseHoverHandler *BuiltinModelManagerSupport::createHoverHandler() return new CppHoverHandler; } -FollowSymbolInterface &BuiltinModelManagerSupport::followSymbolInterface() -{ - return *m_followSymbol; -} - RefactoringEngineInterface &BuiltinModelManagerSupport::refactoringEngineInterface() { return *m_refactoringEngine; @@ -142,4 +139,23 @@ std::unique_ptr<AbstractOverviewModel> BuiltinModelManagerSupport::createOvervie return std::make_unique<OverviewModel>(); } +void BuiltinModelManagerSupport::followSymbol(const CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback, + bool resolveTarget, bool inNextSplit) +{ + SymbolFinder finder; + m_followSymbol->findLink(data, std::move(processLinkCallback), + resolveTarget, CppModelManager::instance()->snapshot(), + data.editorWidget()->semanticInfo().doc, &finder, inNextSplit); +} + +void BuiltinModelManagerSupport::switchDeclDef(const CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback) +{ + SymbolFinder finder; + m_followSymbol->switchDeclDef(data, std::move(processLinkCallback), + CppModelManager::instance()->snapshot(), data.editorWidget()->semanticInfo().doc, + &finder); +} + } // namespace CppEditor::Internal diff --git a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h index bf96f227aa..bd4b2cf863 100644 --- a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h +++ b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h @@ -29,6 +29,8 @@ #include <QScopedPointer> +namespace CppEditor { class FollowSymbolUnderCursor; } + namespace CppEditor::Internal { class BuiltinModelManagerSupport: public ModelManagerSupport @@ -44,13 +46,19 @@ public: TextEditor::BaseHoverHandler *createHoverHandler() final; BaseEditorDocumentProcessor *createEditorDocumentProcessor( TextEditor::TextDocument *baseTextDocument) final; - FollowSymbolInterface &followSymbolInterface() final; RefactoringEngineInterface &refactoringEngineInterface() final; std::unique_ptr<AbstractOverviewModel> createOverviewModel() final; + FollowSymbolUnderCursor &followSymbolInterface() { return *m_followSymbol; } + private: + void followSymbol(const CursorInEditor &data, Utils::ProcessLinkCallback &&processLinkCallback, + bool resolveTarget, bool inNextSplit) override; + void switchDeclDef(const CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback) override; + QScopedPointer<CppCompletionAssistProvider> m_completionAssistProvider; - QScopedPointer<FollowSymbolInterface> m_followSymbol; + QScopedPointer<FollowSymbolUnderCursor> m_followSymbol; QScopedPointer<RefactoringEngineInterface> m_refactoringEngine; }; diff --git a/src/plugins/cppeditor/cppeditor.qbs b/src/plugins/cppeditor/cppeditor.qbs index 0e9ed0ae8b..bd93199cd2 100644 --- a/src/plugins/cppeditor/cppeditor.qbs +++ b/src/plugins/cppeditor/cppeditor.qbs @@ -219,7 +219,6 @@ QtcPlugin { "doxygengenerator.h", "editordocumenthandle.cpp", "editordocumenthandle.h", - "followsymbolinterface.h", "functionutils.cpp", "functionutils.h", "generatedcodemodelsupport.cpp", diff --git a/src/plugins/cppeditor/cppeditorwidget.cpp b/src/plugins/cppeditor/cppeditorwidget.cpp index 6604cce834..e77272efe5 100644 --- a/src/plugins/cppeditor/cppeditorwidget.cpp +++ b/src/plugins/cppeditor/cppeditorwidget.cpp @@ -50,7 +50,6 @@ #include "cpptoolssettings.h" #include "cppuseselectionsupdater.h" #include "cppworkingcopy.h" -#include "followsymbolinterface.h" #include "refactoringengineinterface.h" #include "symbolfinder.h" @@ -1045,9 +1044,7 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit) if (self && link.hasValidTarget()) self->openLink(link, split); }; - followSymbolInterface().switchDeclDef(cursor, std::move(callback), - d->m_modelManager->snapshot(), d->m_lastSemanticInfo.doc, - d->m_modelManager->symbolFinder()); + CppModelManager::instance()->switchDeclDef(cursor, std::move(callback)); } void CppEditorWidget::findLinkAt(const QTextCursor &cursor, @@ -1087,13 +1084,10 @@ void CppEditorWidget::findLinkAt(const QTextCursor &cursor, } callback(link); }; - followSymbolInterface().findLink( + CppModelManager::instance()->followSymbol( CursorInEditor{cursor, filePath, this, textDocument()}, std::move(callbackWrapper), resolveTarget, - d->m_modelManager->snapshot(), - d->m_lastSemanticInfo.doc, - d->m_modelManager->symbolFinder(), inNextSplit); } @@ -1102,11 +1096,6 @@ unsigned CppEditorWidget::documentRevision() const return document()->revision(); } -FollowSymbolInterface &CppEditorWidget::followSymbolInterface() const -{ - return d->m_modelManager->followSymbolInterface(); -} - bool CppEditorWidget::isSemanticInfoValidExceptLocalUses() const { return d->m_lastSemanticInfo.doc && d->m_lastSemanticInfo.revision == documentRevision() diff --git a/src/plugins/cppeditor/cppeditorwidget.h b/src/plugins/cppeditor/cppeditorwidget.h index 837954d6c5..0593fbab4d 100644 --- a/src/plugins/cppeditor/cppeditorwidget.h +++ b/src/plugins/cppeditor/cppeditorwidget.h @@ -38,7 +38,6 @@ class IAssistProvider; } namespace CppEditor { -class FollowSymbolInterface; class SemanticInfo; class ProjectPart; @@ -152,8 +151,6 @@ private: QMenu *createRefactorMenu(QWidget *parent) const; - FollowSymbolInterface &followSymbolInterface() const; - const ProjectPart *projectPart() const; private: diff --git a/src/plugins/cppeditor/cppfollowsymbolundercursor.h b/src/plugins/cppeditor/cppfollowsymbolundercursor.h index 08cb72027d..8c2a89e2f8 100644 --- a/src/plugins/cppeditor/cppfollowsymbolundercursor.h +++ b/src/plugins/cppeditor/cppfollowsymbolundercursor.h @@ -25,13 +25,18 @@ #pragma once -#include "followsymbolinterface.h" +#include "cppeditor_global.h" +#include "cursorineditor.h" -namespace CppEditor { +#include <cplusplus/CppDocument.h> + +#include <texteditor/texteditor.h> +namespace CppEditor { +class SymbolFinder; class VirtualFunctionAssistProvider; -class CPPEDITOR_EXPORT FollowSymbolUnderCursor : public FollowSymbolInterface +class CPPEDITOR_EXPORT FollowSymbolUnderCursor { public: FollowSymbolUnderCursor(); @@ -42,13 +47,13 @@ public: const CPlusPlus::Snapshot &snapshot, const CPlusPlus::Document::Ptr &documentFromSemanticInfo, SymbolFinder *symbolFinder, - bool inNextSplit) override; + bool inNextSplit); void switchDeclDef(const CursorInEditor &data, Utils::ProcessLinkCallback &&processLinkCallback, const CPlusPlus::Snapshot &snapshot, const CPlusPlus::Document::Ptr &documentFromSemanticInfo, - SymbolFinder *symbolFinder) override; + SymbolFinder *symbolFinder); QSharedPointer<VirtualFunctionAssistProvider> virtualFunctionAssistProvider(); void setVirtualFunctionAssistProvider( diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index 726b6c4f46..8a94e9bb19 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -48,7 +48,6 @@ #include "stringtable.h" #include "symbolfinder.h" #include "symbolsfindfilter.h" -#include "followsymbolinterface.h" #include <coreplugin/documentmanager.h> #include <coreplugin/editormanager/editormanager.h> @@ -348,20 +347,6 @@ void CppModelManager::findUsages(const CursorInEditor &data, engine->findUsages(data, std::move(showUsagesCallback)); } -void CppModelManager::globalFollowSymbol( - const CursorInEditor &data, - Utils::ProcessLinkCallback &&processLinkCallback, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &documentFromSemanticInfo, - SymbolFinder *symbolFinder, - bool inNextSplit) const -{ - RefactoringEngineInterface *engine = getRefactoringEngine(d->m_refactoringEngines); - QTC_ASSERT(engine, return;); - engine->globalFollowSymbol(data, std::move(processLinkCallback), snapshot, documentFromSemanticInfo, - symbolFinder, inNextSplit); -} - bool CppModelManager::positionRequiresSignal(const QString &filePath, const QByteArray &content, int position) const { @@ -487,9 +472,10 @@ RefactoringEngineInterface *CppModelManager::builtinRefactoringEngine() return instance()->d->m_refactoringEngines.value(RefactoringEngineType::BuiltIn); } -FollowSymbolInterface &CppModelManager::builtinFollowSymbol() +FollowSymbolUnderCursor &CppModelManager::builtinFollowSymbol() { - return instance()->d->m_builtinModelManagerSupport->followSymbolInterface(); + return instance()->d->m_builtinModelManagerSupport.staticCast<BuiltinModelManagerSupport>() + ->followSymbolInterface(); } template<class FilterClass> @@ -560,11 +546,6 @@ Core::ILocatorFilter *CppModelManager::currentDocumentFilter() const return d->m_currentDocumentFilter.get(); } -FollowSymbolInterface &CppModelManager::followSymbolInterface() const -{ - return d->m_activeModelManagerSupport->followSymbolInterface(); -} - std::unique_ptr<AbstractOverviewModel> CppModelManager::createOverviewModel() const { return d->m_activeModelManagerSupport->createOverviewModel(); @@ -1680,6 +1661,20 @@ TextEditor::BaseHoverHandler *CppModelManager::createHoverHandler() const return d->m_activeModelManagerSupport->createHoverHandler(); } +void CppModelManager::followSymbol(const CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback, + bool resolveTarget, bool inNextSplit) +{ + d->m_activeModelManagerSupport->followSymbol(data, std::move(processLinkCallback), + resolveTarget, inNextSplit); +} + +void CppModelManager::switchDeclDef(const CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback) +{ + d->m_activeModelManagerSupport->switchDeclDef(data, std::move(processLinkCallback)); +} + BaseEditorDocumentProcessor *CppModelManager::createEditorDocumentProcessor( TextEditor::TextDocument *baseTextDocument) const { diff --git a/src/plugins/cppeditor/cppmodelmanager.h b/src/plugins/cppeditor/cppmodelmanager.h index fadb00657d..1c499479fd 100644 --- a/src/plugins/cppeditor/cppmodelmanager.h +++ b/src/plugins/cppeditor/cppmodelmanager.h @@ -60,8 +60,8 @@ class CppCompletionAssistProvider; class CppEditorDocumentHandle; class CppIndexingSupport; class CppLocatorData; +class FollowSymbolUnderCursor; class ModelManagerSupportProvider; -class FollowSymbolInterface; class SymbolFinder; class WorkingCopy; @@ -162,12 +162,6 @@ public: const QString &replacement) final; void findUsages(const CursorInEditor &data, UsagesCallback &&showUsagesCallback) const final; - void globalFollowSymbol(const CursorInEditor &data, - Utils::ProcessLinkCallback &&processLinkCallback, - const CPlusPlus::Snapshot &snapshot, - const Document::Ptr &documentFromSemanticInfo, - SymbolFinder *symbolFinder, - bool inNextSplit) const final; bool positionRequiresSignal(const QString &filePath, const QByteArray &content, int position) const; @@ -187,7 +181,12 @@ public: BaseEditorDocumentProcessor *createEditorDocumentProcessor( TextEditor::TextDocument *baseTextDocument) const; TextEditor::BaseHoverHandler *createHoverHandler() const; - FollowSymbolInterface &followSymbolInterface() const; + static FollowSymbolUnderCursor &builtinFollowSymbol(); + void followSymbol(const CursorInEditor &data, Utils::ProcessLinkCallback &&processLinkCallback, + bool resolveTarget, bool inNextSplit); + void switchDeclDef(const CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback); + std::unique_ptr<AbstractOverviewModel> createOverviewModel() const; CppIndexingSupport *indexingSupport(); @@ -217,7 +216,6 @@ public: RefactoringEngineInterface *refactoringEngine); static void removeRefactoringEngine(RefactoringEngineType type); static RefactoringEngineInterface *builtinRefactoringEngine(); - static FollowSymbolInterface &builtinFollowSymbol(); void setLocatorFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); void setClassesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); diff --git a/src/plugins/cppeditor/cppmodelmanagersupport.h b/src/plugins/cppeditor/cppmodelmanagersupport.h index ca287d8baf..29c258a1a0 100644 --- a/src/plugins/cppeditor/cppmodelmanagersupport.h +++ b/src/plugins/cppeditor/cppmodelmanagersupport.h @@ -27,6 +27,8 @@ #include "cppeditor_global.h" +#include <utils/link.h> + #include <QSharedPointer> #include <QString> @@ -42,7 +44,7 @@ namespace CppEditor { class AbstractOverviewModel; class BaseEditorDocumentProcessor; class CppCompletionAssistProvider; -class FollowSymbolInterface; +class CursorInEditor; class RefactoringEngineInterface; class CPPEDITOR_EXPORT ModelManagerSupport @@ -58,11 +60,16 @@ public: virtual TextEditor::BaseHoverHandler *createHoverHandler() = 0; virtual BaseEditorDocumentProcessor *createEditorDocumentProcessor( TextEditor::TextDocument *baseTextDocument) = 0; - virtual FollowSymbolInterface &followSymbolInterface() = 0; virtual RefactoringEngineInterface &refactoringEngineInterface() = 0; virtual std::unique_ptr<AbstractOverviewModel> createOverviewModel() = 0; virtual bool supportsOutline(const TextEditor::TextDocument *) const { return true; } virtual bool supportsLocalUses(const TextEditor::TextDocument *) const { return true; } + + virtual void followSymbol(const CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback, + bool resolveTarget, bool inNextSplit) = 0; + virtual void switchDeclDef(const CursorInEditor &data, + Utils::ProcessLinkCallback &&processLinkCallback) = 0; }; class CPPEDITOR_EXPORT ModelManagerSupportProvider diff --git a/src/plugins/cppeditor/cpprefactoringengine.cpp b/src/plugins/cppeditor/cpprefactoringengine.cpp index 653598143f..4a88f75d3a 100644 --- a/src/plugins/cppeditor/cpprefactoringengine.cpp +++ b/src/plugins/cppeditor/cpprefactoringengine.cpp @@ -103,17 +103,4 @@ void CppRefactoringEngine::findUsages(const CursorInEditor &data, } } -void CppRefactoringEngine::globalFollowSymbol( - const CursorInEditor &data, - Utils::ProcessLinkCallback &&processLinkCallback, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &documentFromSemanticInfo, - SymbolFinder *symbolFinder, - bool inNextSplit) const -{ - FollowSymbolUnderCursor followSymbol; - return followSymbol.findLink(data, std::move(processLinkCallback), true, snapshot, - documentFromSemanticInfo, symbolFinder, inNextSplit); -} - } // namespace CppEditor::Internal diff --git a/src/plugins/cppeditor/cpprefactoringengine.h b/src/plugins/cppeditor/cpprefactoringengine.h index 18b0a2555f..765e8eece6 100644 --- a/src/plugins/cppeditor/cpprefactoringengine.h +++ b/src/plugins/cppeditor/cpprefactoringengine.h @@ -38,12 +38,6 @@ public: void globalRename(const CursorInEditor &data, UsagesCallback &&, const QString &replacement) override; void findUsages(const CursorInEditor &data, UsagesCallback &&) const override; - void globalFollowSymbol(const CursorInEditor &data, - Utils::ProcessLinkCallback &&processLinkCallback, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &documentFromSemanticInfo, - SymbolFinder *symbolFinder, - bool inNextSplit) const override; }; } // namespace CppEditor::Internal diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp index 63f16e9809..cd423e0cec 100644 --- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp +++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp @@ -350,9 +350,7 @@ F2TestCase::F2TestCase(CppEditorAction action, switch (action) { case FollowSymbolUnderCursorAction: { CppEditorWidget *widget = initialTestFile->m_editorWidget; - FollowSymbolInterface &delegate = CppModelManager::instance()->followSymbolInterface(); - auto* builtinFollowSymbol = dynamic_cast<FollowSymbolUnderCursor *>(&delegate); - if (!builtinFollowSymbol) { + if (CppModelManager::instance()->isClangCodeModelActive()) { if (curTestName == "testFollowSymbolQTCREATORBUG7903") QSKIP((curTestName + " is not supported by Clang FollowSymbol").toLatin1()); widget->enableTestMode(); @@ -360,6 +358,7 @@ F2TestCase::F2TestCase(CppEditorAction action, break; } + FollowSymbolUnderCursor *builtinFollowSymbol = &CppModelManager::builtinFollowSymbol(); QSharedPointer<VirtualFunctionAssistProvider> original = builtinFollowSymbol->virtualFunctionAssistProvider(); diff --git a/src/plugins/cppeditor/followsymbolinterface.h b/src/plugins/cppeditor/followsymbolinterface.h deleted file mode 100644 index e31b8703ff..0000000000 --- a/src/plugins/cppeditor/followsymbolinterface.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "cppeditor_global.h" -#include "cursorineditor.h" - -#include <cplusplus/CppDocument.h> - -#include <texteditor/texteditor.h> - -namespace CppEditor { - -class SymbolFinder; - -class CPPEDITOR_EXPORT FollowSymbolInterface -{ -public: - using Link = Utils::Link; - - virtual ~FollowSymbolInterface() = default; - virtual void findLink(const CursorInEditor &data, - Utils::ProcessLinkCallback &&processLinkCallback, - bool resolveTarget, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &documentFromSemanticInfo, - SymbolFinder *symbolFinder, - bool inNextSplit) = 0; - virtual void switchDeclDef(const CursorInEditor &data, - Utils::ProcessLinkCallback &&processLinkCallback, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &documentFromSemanticInfo, - SymbolFinder *symbolFinder) = 0; -}; - -} // namespace CppEditor diff --git a/src/plugins/cppeditor/refactoringengineinterface.h b/src/plugins/cppeditor/refactoringengineinterface.h index b4068fd33b..55299aee26 100644 --- a/src/plugins/cppeditor/refactoringengineinterface.h +++ b/src/plugins/cppeditor/refactoringengineinterface.h @@ -67,12 +67,6 @@ public: const QString &replacement) = 0; virtual void findUsages(const CursorInEditor &data, UsagesCallback &&showUsagesCallback) const = 0; - virtual void globalFollowSymbol(const CursorInEditor &data, - Utils::ProcessLinkCallback &&processLinkCallback, - const CPlusPlus::Snapshot &snapshot, - const CPlusPlus::Document::Ptr &documentFromSemanticInfo, - SymbolFinder *symbolFinder, - bool inNextSplit) const = 0; virtual bool isRefactoringEngineAvailable() const { return true; } }; |