forked from qt-creator/qt-creator
CppEditor: Add actions for following a symbol to its type
Change-Id: I0b3913993b09b006e2d0431a68e98e21e8865898 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -832,7 +832,7 @@ void ClangdClient::followSymbol(TextDocument *document,
|
|||||||
d->followSymbol = nullptr;
|
d->followSymbol = nullptr;
|
||||||
|
|
||||||
const QTextCursor adjustedCursor = d->adjustedCursor(cursor, document);
|
const QTextCursor adjustedCursor = d->adjustedCursor(cursor, document);
|
||||||
if (!resolveTarget) {
|
if (followTo == FollowTo::SymbolDef && !resolveTarget) {
|
||||||
symbolSupport().findLinkAt(document, adjustedCursor, callback, false);
|
symbolSupport().findLinkAt(document, adjustedCursor, callback, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -270,6 +270,19 @@ void ClangModelManagerSupport::followSymbol(const CppEditor::CursorInEditor &dat
|
|||||||
CppModelManager::Backend::Builtin);
|
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,
|
void ClangModelManagerSupport::switchDeclDef(const CppEditor::CursorInEditor &data,
|
||||||
const Utils::LinkHandler &processLinkCallback)
|
const Utils::LinkHandler &processLinkCallback)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ private:
|
|||||||
void followSymbol(const CppEditor::CursorInEditor &data,
|
void followSymbol(const CppEditor::CursorInEditor &data,
|
||||||
const Utils::LinkHandler &processLinkCallback, bool resolveTarget,
|
const Utils::LinkHandler &processLinkCallback, bool resolveTarget,
|
||||||
bool inNextSplit) override;
|
bool inNextSplit) override;
|
||||||
|
void followSymbolToType(const CppEditor::CursorInEditor &data,
|
||||||
|
const Utils::LinkHandler &processLinkCallback,
|
||||||
|
bool inNextSplit) override;
|
||||||
void switchDeclDef(const CppEditor::CursorInEditor &data,
|
void switchDeclDef(const CppEditor::CursorInEditor &data,
|
||||||
const Utils::LinkHandler &processLinkCallback) override;
|
const Utils::LinkHandler &processLinkCallback) override;
|
||||||
void startLocalRenaming(const CppEditor::CursorInEditor &data,
|
void startLocalRenaming(const CppEditor::CursorInEditor &data,
|
||||||
|
|||||||
@@ -6,14 +6,15 @@
|
|||||||
#include "builtineditordocumentprocessor.h"
|
#include "builtineditordocumentprocessor.h"
|
||||||
#include "cppcanonicalsymbol.h"
|
#include "cppcanonicalsymbol.h"
|
||||||
#include "cppcompletionassist.h"
|
#include "cppcompletionassist.h"
|
||||||
|
#include "cppeditortr.h"
|
||||||
#include "cppeditorwidget.h"
|
#include "cppeditorwidget.h"
|
||||||
#include "cppelementevaluator.h"
|
#include "cppelementevaluator.h"
|
||||||
#include "cppfollowsymbolundercursor.h"
|
#include "cppfollowsymbolundercursor.h"
|
||||||
#include "cppoutlinemodel.h"
|
|
||||||
#include "cpptoolsreuse.h"
|
#include "cpptoolsreuse.h"
|
||||||
#include "symbolfinder.h"
|
#include "symbolfinder.h"
|
||||||
|
|
||||||
#include <app/app_version.h>
|
#include <app/app_version.h>
|
||||||
|
#include <coreplugin/messagemanager.h>
|
||||||
#include <texteditor/basehoverhandler.h>
|
#include <texteditor/basehoverhandler.h>
|
||||||
#include <utils/executeondestruction.h>
|
#include <utils/executeondestruction.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -105,6 +106,17 @@ void BuiltinModelManagerSupport::followSymbol(const CursorInEditor &data,
|
|||||||
data.editorWidget()->semanticInfo().doc, &finder, inNextSplit);
|
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,
|
void BuiltinModelManagerSupport::switchDeclDef(const CursorInEditor &data,
|
||||||
const Utils::LinkHandler &processLinkCallback)
|
const Utils::LinkHandler &processLinkCallback)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
void followSymbol(const CursorInEditor &data, const Utils::LinkHandler &processLinkCallback,
|
void followSymbol(const CursorInEditor &data, const Utils::LinkHandler &processLinkCallback,
|
||||||
bool resolveTarget, bool inNextSplit) override;
|
bool resolveTarget, bool inNextSplit) override;
|
||||||
|
void followSymbolToType(const CursorInEditor &data,
|
||||||
|
const Utils::LinkHandler &processLinkCallback,
|
||||||
|
bool inNextSplit) override;
|
||||||
void switchDeclDef(const CursorInEditor &data,
|
void switchDeclDef(const CursorInEditor &data,
|
||||||
const Utils::LinkHandler &processLinkCallback) override;
|
const Utils::LinkHandler &processLinkCallback) override;
|
||||||
void startLocalRenaming(const CursorInEditor &data,
|
void startLocalRenaming(const CursorInEditor &data,
|
||||||
|
|||||||
@@ -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 CPPEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "C++ Editor");
|
||||||
const char SWITCH_DECLARATION_DEFINITION[] = "CppEditor.SwitchDeclarationDefinition";
|
const char SWITCH_DECLARATION_DEFINITION[] = "CppEditor.SwitchDeclarationDefinition";
|
||||||
const char OPEN_DECLARATION_DEFINITION_IN_NEXT_SPLIT[] = "CppEditor.OpenDeclarationDefinitionInNextSplit";
|
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 OPEN_PREPROCESSOR_DIALOG[] = "CppEditor.OpenPreprocessorDialog";
|
||||||
const char MULTIPLE_PARSE_CONTEXTS_AVAILABLE[] = "CppEditor.MultipleParseContextsAvailable";
|
const char MULTIPLE_PARSE_CONTEXTS_AVAILABLE[] = "CppEditor.MultipleParseContextsAvailable";
|
||||||
const char M_REFACTORING_MENU_INSERTION_POINT[] = "CppEditor.RefactorGroup";
|
const char M_REFACTORING_MENU_INSERTION_POINT[] = "CppEditor.RefactorGroup";
|
||||||
|
|||||||
@@ -357,6 +357,30 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
|
|||||||
this, &CppEditorPlugin::openDeclarationDefinitionInNextSplit);
|
this, &CppEditorPlugin::openDeclarationDefinitionInNextSplit);
|
||||||
cppToolsMenu->addAction(cmd);
|
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);
|
cmd = ActionManager::command(TextEditor::Constants::FIND_USAGES);
|
||||||
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
cppToolsMenu->addAction(cmd);
|
cppToolsMenu->addAction(cmd);
|
||||||
|
|||||||
@@ -834,6 +834,20 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
|||||||
CppModelManager::switchDeclDef(cursor, std::move(callback));
|
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,
|
bool CppEditorWidget::followQrcUrl(const QTextCursor &cursor,
|
||||||
const Utils::LinkHandler &processLinkCallback)
|
const Utils::LinkHandler &processLinkCallback)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public:
|
|||||||
void selectAll() override;
|
void selectAll() override;
|
||||||
|
|
||||||
void switchDeclarationDefinition(bool inNextSplit);
|
void switchDeclarationDefinition(bool inNextSplit);
|
||||||
|
void followSymbolToType(bool inNextSplit);
|
||||||
void showPreProcessorWidget();
|
void showPreProcessorWidget();
|
||||||
|
|
||||||
void findUsages() override;
|
void findUsages() override;
|
||||||
|
|||||||
@@ -1764,6 +1764,14 @@ void CppModelManager::followSymbol(const CursorInEditor &data,
|
|||||||
resolveTarget, inNextSplit);
|
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,
|
void CppModelManager::switchDeclDef(const CursorInEditor &data,
|
||||||
const Utils::LinkHandler &processLinkCallback,
|
const Utils::LinkHandler &processLinkCallback,
|
||||||
Backend backend)
|
Backend backend)
|
||||||
|
|||||||
@@ -167,6 +167,9 @@ public:
|
|||||||
static void followSymbol(const CursorInEditor &data,
|
static void followSymbol(const CursorInEditor &data,
|
||||||
const Utils::LinkHandler &processLinkCallback,
|
const Utils::LinkHandler &processLinkCallback,
|
||||||
bool resolveTarget, bool inNextSplit, Backend backend = Backend::Best);
|
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,
|
static void switchDeclDef(const CursorInEditor &data,
|
||||||
const Utils::LinkHandler &processLinkCallback,
|
const Utils::LinkHandler &processLinkCallback,
|
||||||
Backend backend = Backend::Best);
|
Backend backend = Backend::Best);
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ public:
|
|||||||
virtual void followSymbol(const CursorInEditor &data,
|
virtual void followSymbol(const CursorInEditor &data,
|
||||||
const Utils::LinkHandler &processLinkCallback,
|
const Utils::LinkHandler &processLinkCallback,
|
||||||
bool resolveTarget, bool inNextSplit) = 0;
|
bool resolveTarget, bool inNextSplit) = 0;
|
||||||
|
virtual void followSymbolToType(const CursorInEditor &data,
|
||||||
|
const Utils::LinkHandler &processLinkCallback,
|
||||||
|
bool inNextSplit) = 0;
|
||||||
virtual void switchDeclDef(const CursorInEditor &data,
|
virtual void switchDeclDef(const CursorInEditor &data,
|
||||||
const Utils::LinkHandler &processLinkCallback) = 0;
|
const Utils::LinkHandler &processLinkCallback) = 0;
|
||||||
virtual void startLocalRenaming(const CursorInEditor &data,
|
virtual void startLocalRenaming(const CursorInEditor &data,
|
||||||
|
|||||||
Reference in New Issue
Block a user