diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 4814166553e..6595c3aa98a 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -832,7 +832,7 @@ void ClangdClient::followSymbol(TextDocument *document, d->followSymbol = nullptr; const QTextCursor adjustedCursor = d->adjustedCursor(cursor, document); - if (!resolveTarget) { + if (followTo == FollowTo::SymbolDef && !resolveTarget) { symbolSupport().findLinkAt(document, adjustedCursor, callback, false); return; } diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index 2bcdd71874a..913f31a3fd9 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -270,6 +270,19 @@ void ClangModelManagerSupport::followSymbol(const CppEditor::CursorInEditor &dat CppModelManager::Backend::Builtin); } +void ClangModelManagerSupport::followSymbolToType(const CppEditor::CursorInEditor &data, + const Utils::LinkHandler &processLinkCallback, + bool inNextSplit) +{ + if (ClangdClient * const client = clientForFile(data.filePath())) { + client->followSymbol(data.textDocument(), data.cursor(), data.editorWidget(), + processLinkCallback, false, FollowTo::SymbolType, inNextSplit); + return; + } + CppModelManager::followSymbolToType(data, processLinkCallback, inNextSplit, + CppModelManager::Backend::Builtin); +} + void ClangModelManagerSupport::switchDeclDef(const CppEditor::CursorInEditor &data, const Utils::LinkHandler &processLinkCallback) { diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.h b/src/plugins/clangcodemodel/clangmodelmanagersupport.h index 8557574805b..3968e9bebab 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.h +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.h @@ -52,6 +52,9 @@ private: void followSymbol(const CppEditor::CursorInEditor &data, const Utils::LinkHandler &processLinkCallback, bool resolveTarget, bool inNextSplit) override; + void followSymbolToType(const CppEditor::CursorInEditor &data, + const Utils::LinkHandler &processLinkCallback, + bool inNextSplit) override; void switchDeclDef(const CppEditor::CursorInEditor &data, const Utils::LinkHandler &processLinkCallback) override; void startLocalRenaming(const CppEditor::CursorInEditor &data, diff --git a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp index eade8005c37..f46d7ea03af 100644 --- a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp +++ b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp @@ -6,14 +6,15 @@ #include "builtineditordocumentprocessor.h" #include "cppcanonicalsymbol.h" #include "cppcompletionassist.h" +#include "cppeditortr.h" #include "cppeditorwidget.h" #include "cppelementevaluator.h" #include "cppfollowsymbolundercursor.h" -#include "cppoutlinemodel.h" #include "cpptoolsreuse.h" #include "symbolfinder.h" #include +#include #include #include #include @@ -105,6 +106,17 @@ void BuiltinModelManagerSupport::followSymbol(const CursorInEditor &data, data.editorWidget()->semanticInfo().doc, &finder, inNextSplit); } +void BuiltinModelManagerSupport::followSymbolToType(const CursorInEditor &data, + const Utils::LinkHandler &processLinkCallback, + bool inNextSplit) +{ + Q_UNUSED(data) + Q_UNUSED(processLinkCallback) + Q_UNUSED(inNextSplit) + MessageManager::writeDisrupting( + Tr::tr("Follow Symbol to Type is only available when using clangd")); +} + void BuiltinModelManagerSupport::switchDeclDef(const CursorInEditor &data, const Utils::LinkHandler &processLinkCallback) { diff --git a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h index 363dbfae0c2..4a6d56429c5 100644 --- a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h +++ b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h @@ -30,6 +30,9 @@ public: private: void followSymbol(const CursorInEditor &data, const Utils::LinkHandler &processLinkCallback, bool resolveTarget, bool inNextSplit) override; + void followSymbolToType(const CursorInEditor &data, + const Utils::LinkHandler &processLinkCallback, + bool inNextSplit) override; void switchDeclDef(const CursorInEditor &data, const Utils::LinkHandler &processLinkCallback) override; void startLocalRenaming(const CursorInEditor &data, diff --git a/src/plugins/cppeditor/cppeditorconstants.h b/src/plugins/cppeditor/cppeditorconstants.h index ab30f790f0f..0c226f6682c 100644 --- a/src/plugins/cppeditor/cppeditorconstants.h +++ b/src/plugins/cppeditor/cppeditorconstants.h @@ -14,6 +14,8 @@ const char CPPEDITOR_ID[] = "CppEditor.C++Editor"; const char CPPEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "C++ Editor"); const char SWITCH_DECLARATION_DEFINITION[] = "CppEditor.SwitchDeclarationDefinition"; const char OPEN_DECLARATION_DEFINITION_IN_NEXT_SPLIT[] = "CppEditor.OpenDeclarationDefinitionInNextSplit"; +const char FOLLOW_SYMBOL_TO_TYPE[] = "TextEditor.FollowSymbolToType"; +const char FOLLOW_SYMBOL_TO_TYPE_IN_NEXT_SPLIT[] = "TextEditor.FollowSymbolToTypeInNextSplit"; const char OPEN_PREPROCESSOR_DIALOG[] = "CppEditor.OpenPreprocessorDialog"; const char MULTIPLE_PARSE_CONTEXTS_AVAILABLE[] = "CppEditor.MultipleParseContextsAvailable"; const char M_REFACTORING_MENU_INSERTION_POINT[] = "CppEditor.RefactorGroup"; diff --git a/src/plugins/cppeditor/cppeditorplugin.cpp b/src/plugins/cppeditor/cppeditorplugin.cpp index 0b4e5ca9033..3ce2884553c 100644 --- a/src/plugins/cppeditor/cppeditorplugin.cpp +++ b/src/plugins/cppeditor/cppeditorplugin.cpp @@ -357,6 +357,30 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err this, &CppEditorPlugin::openDeclarationDefinitionInNextSplit); cppToolsMenu->addAction(cmd); + QAction * const followSymbolToType = new QAction(tr("Follow Symbol Under Cursor to Type"), + this); + cmd = ActionManager::registerAction(followSymbolToType, Constants::FOLLOW_SYMBOL_TO_TYPE, + context, true); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F2"))); + connect(followSymbolToType, &QAction::triggered, this, []{ + if (CppEditorWidget *editorWidget = currentCppEditorWidget()) + editorWidget->followSymbolToType(false); + }); + contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST); + cppToolsMenu->addAction(cmd); + QAction * const followSymbolToTypeInNextSplit = + new QAction(tr("Follow Symbol To Type in Next Split"), this); + cmd = ActionManager::registerAction(followSymbolToTypeInNextSplit, + Constants::FOLLOW_SYMBOL_TO_TYPE_IN_NEXT_SPLIT, context, true); + cmd->setDefaultKeySequence(QKeySequence(HostOsInfo::isMacHost() + ? tr("Meta+E, Ctrl+Shift+F2") + : tr("Ctrl+E, Ctrl+Shift+F2"))); + connect(followSymbolToTypeInNextSplit, &QAction::triggered, this, []{ + if (CppEditorWidget *editorWidget = currentCppEditorWidget()) + editorWidget->followSymbolToType(true); + }); + cppToolsMenu->addAction(cmd); + cmd = ActionManager::command(TextEditor::Constants::FIND_USAGES); contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST); cppToolsMenu->addAction(cmd); diff --git a/src/plugins/cppeditor/cppeditorwidget.cpp b/src/plugins/cppeditor/cppeditorwidget.cpp index 193e0d7735a..94d69382420 100644 --- a/src/plugins/cppeditor/cppeditorwidget.cpp +++ b/src/plugins/cppeditor/cppeditorwidget.cpp @@ -834,6 +834,20 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit) CppModelManager::switchDeclDef(cursor, std::move(callback)); } +void CppEditorWidget::followSymbolToType(bool inNextSplit) +{ + if (!d->m_modelManager) + return; + + const CursorInEditor cursor(textCursor(), textDocument()->filePath(), this, textDocument()); + const auto callback = [self = QPointer(this), + split = inNextSplit != alwaysOpenLinksInNextSplit()](const Link &link) { + if (self && link.hasValidTarget()) + self->openLink(link, split); + }; + CppModelManager::followSymbolToType(cursor, callback, inNextSplit); +} + bool CppEditorWidget::followQrcUrl(const QTextCursor &cursor, const Utils::LinkHandler &processLinkCallback) { diff --git a/src/plugins/cppeditor/cppeditorwidget.h b/src/plugins/cppeditor/cppeditorwidget.h index d3ed526c2c4..93e9691506f 100644 --- a/src/plugins/cppeditor/cppeditorwidget.h +++ b/src/plugins/cppeditor/cppeditorwidget.h @@ -54,6 +54,7 @@ public: void selectAll() override; void switchDeclarationDefinition(bool inNextSplit); + void followSymbolToType(bool inNextSplit); void showPreProcessorWidget(); void findUsages() override; diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index d5c8a28870f..c3de62dc27f 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -1764,6 +1764,14 @@ void CppModelManager::followSymbol(const CursorInEditor &data, resolveTarget, inNextSplit); } +void CppModelManager::followSymbolToType(const CursorInEditor &data, + const Utils::LinkHandler &processLinkCallback, + bool inNextSplit, Backend backend) +{ + instance()->modelManagerSupport(backend)->followSymbolToType(data, processLinkCallback, + inNextSplit); +} + void CppModelManager::switchDeclDef(const CursorInEditor &data, const Utils::LinkHandler &processLinkCallback, Backend backend) diff --git a/src/plugins/cppeditor/cppmodelmanager.h b/src/plugins/cppeditor/cppmodelmanager.h index cbf39c206d2..221672d979a 100644 --- a/src/plugins/cppeditor/cppmodelmanager.h +++ b/src/plugins/cppeditor/cppmodelmanager.h @@ -167,6 +167,9 @@ public: static void followSymbol(const CursorInEditor &data, const Utils::LinkHandler &processLinkCallback, bool resolveTarget, bool inNextSplit, Backend backend = Backend::Best); + static void followSymbolToType(const CursorInEditor &data, + const Utils::LinkHandler &processLinkCallback, bool inNextSplit, + Backend backend = Backend::Best); static void switchDeclDef(const CursorInEditor &data, const Utils::LinkHandler &processLinkCallback, Backend backend = Backend::Best); diff --git a/src/plugins/cppeditor/cppmodelmanagersupport.h b/src/plugins/cppeditor/cppmodelmanagersupport.h index 952b1d2ea7e..0544cb45323 100644 --- a/src/plugins/cppeditor/cppmodelmanagersupport.h +++ b/src/plugins/cppeditor/cppmodelmanagersupport.h @@ -40,6 +40,9 @@ public: virtual void followSymbol(const CursorInEditor &data, const Utils::LinkHandler &processLinkCallback, bool resolveTarget, bool inNextSplit) = 0; + virtual void followSymbolToType(const CursorInEditor &data, + const Utils::LinkHandler &processLinkCallback, + bool inNextSplit) = 0; virtual void switchDeclDef(const CursorInEditor &data, const Utils::LinkHandler &processLinkCallback) = 0; virtual void startLocalRenaming(const CursorInEditor &data,