Skip to content

Commit 872f578

Browse files
authored
Merge pull request #402 from QuangNguyenMinh123/feature/Go_to_definition
Add feature: Go to definition
2 parents e38e5cd + 3ff7d93 commit 872f578

8 files changed

Lines changed: 181 additions & 43 deletions

src/SeerEditorManagerWidget.cpp

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ SeerEditorManagerWidget::SeerEditorManagerWidget (QWidget* parent) : QWidget(par
4040
_showOpcodeColumn = false;
4141
_showSourceLines = false;
4242
_notifyAssemblyTabShown = true;
43+
_idFunctionDefinition = Seer::createID();
44+
_idVariableDefinition = Seer::createID();
45+
_idTypeDefinition = Seer::createID();
4346

4447
// Setup UI
4548
setupUi(this);
@@ -801,8 +804,41 @@ void SeerEditorManagerWidget::handleText (const QString& text) {
801804
i->widget->sourceArea()->eraseColorCurrentLine(line_text.toInt());
802805
}
803806
}
804-
}
805-
else{
807+
808+
}else if ( text.contains(QRegularExpression("^([0-9]+)\\^done,symbols={"))) {
809+
810+
if (text.startsWith(QString::number(_idTypeDefinition) + "^done,symbols={") ||
811+
text.startsWith(QString::number(_idFunctionDefinition) + "^done,symbols={") ||
812+
text.startsWith(QString::number(_idVariableDefinition) + "^done,symbols={")) { // Handle Go to Definition
813+
814+
//^10done,symbols={debug=[{filename=" ",fullname=" ",
815+
// symbols=[{line=" ",name="uwTick",type="volatile uint32_t",description="volatile uint32_t uwTick;"},}]}]
816+
QString debug_text = Seer::parseFirst(text, "debug=", '[', ']', false);
817+
QStringList filenames_list = Seer::parse(debug_text, "", '{', '}', false);
818+
819+
for (const auto& filename_entry : filenames_list) {
820+
821+
QString filename_text = Seer::parseFirst(filename_entry, "filename=", '"', '"', false);
822+
QString fullname_text = Seer::parseFirst(filename_entry, "fullname=", '"', '"', false);
823+
QString symbols_text = Seer::parseFirst(filename_entry, "symbols=", '[', ']', false);
824+
825+
QStringList symbols_list = Seer::parse(symbols_text, "", '{', '}', false);
826+
827+
for (const auto& symbol_entry : symbols_list) {
828+
829+
QString line_text = Seer::parseFirst(symbol_entry, "line=", '"', '"', false);
830+
QString name_text = Seer::parseFirst(symbol_entry, "name=", '"', '"', false);
831+
832+
// name_text may be st like: function_name(params...) , so only extract function_name part
833+
name_text = name_text.section('(', 0, 0).trimmed();
834+
835+
if (name_text == _gotoDefIdentifier) { // you found it! Open file
836+
handleOpenFile(filename_text, fullname_text, line_text.toInt());
837+
}
838+
}
839+
}
840+
}
841+
}else{
806842
// Ignore others.
807843
return;
808844
}
@@ -1060,6 +1096,7 @@ SeerEditorWidgetSource* SeerEditorManagerWidget::createEditorWidgetTab (const QS
10601096
QObject::connect(editorWidget->sourceArea(), &SeerEditorWidgetSourceArea::addStructVisualizer, this, &SeerEditorManagerWidget::handleAddStructVisualizer);
10611097
QObject::connect(editorWidget, &SeerEditorWidgetSource::addAlternateDirectory, this, &SeerEditorManagerWidget::handleAddAlternateDirectory);
10621098
QObject::connect(editorWidget->sourceArea(), &SeerEditorWidgetSourceArea::addToMouseNavigation, this, &SeerEditorManagerWidget::handleAddToMouseNavigation);
1099+
QObject::connect(editorWidget->sourceArea(), &SeerEditorWidgetSourceArea::signalGotoDefinition, this, &SeerEditorManagerWidget::gotoDefinitionForwarder);
10631100

10641101
// Send the Editor widget the command to load the file. ??? Do better than this.
10651102
editorWidget->sourceArea()->handleText(text);
@@ -1124,6 +1161,7 @@ SeerEditorWidgetSource* SeerEditorManagerWidget::createEditorWidgetTab (const QS
11241161
QObject::connect(editorWidget->sourceArea(), &SeerEditorWidgetSourceArea::addStructVisualizer, this, &SeerEditorManagerWidget::handleAddStructVisualizer);
11251162
QObject::connect(editorWidget, &SeerEditorWidgetSource::addAlternateDirectory, this, &SeerEditorManagerWidget::handleAddAlternateDirectory);
11261163
QObject::connect(editorWidget->sourceArea(), &SeerEditorWidgetSourceArea::addToMouseNavigation, this, &SeerEditorManagerWidget::handleAddToMouseNavigation);
1164+
QObject::connect(editorWidget->sourceArea(), &SeerEditorWidgetSourceArea::signalGotoDefinition, this, &SeerEditorManagerWidget::gotoDefinitionForwarder);
11271165

11281166
// Load the file.
11291167
editorWidget->sourceArea()->open(fullname, QFileInfo(file).fileName());
@@ -1547,7 +1585,7 @@ void SeerEditorManagerWidget::handleAddToMouseNavigation(const SeerEditorWidgetS
15471585
return;
15481586
}
15491587
}
1550-
1588+
15511589
// if _forwardFilesIndex is at the end of the list, just append
15521590
if (_forwardFilesIndex >= _listForwardFiles.size() - 1)
15531591
{
@@ -1569,13 +1607,13 @@ void SeerEditorManagerWidget::handleAddToMouseNavigation(const SeerEditorWidgetS
15691607
_listForwardFiles.append(currentFile);
15701608
_forwardFilesIndex = _listForwardFiles.size() -1;
15711609
}
1572-
}
1610+
}
15731611
}
15741612

15751613
void SeerEditorManagerWidget::handleOpenForwardBackward(const SeerEditorWidgetSourceArea::SeerCurrentFile& fileInfo) {
15761614
// Get the EditorWidget for the file. Create one if needed.
15771615
SeerEditorWidgetSource* editorWidget = editorWidgetTab(fileInfo.fullname);
1578-
1616+
15791617
if (editorWidget == 0) {
15801618
editorWidget = createEditorWidgetTab(fileInfo.fullname, fileInfo.file);
15811619
}
@@ -1629,8 +1667,29 @@ void SeerEditorManagerWidget::mousePressEvent(QMouseEvent *event)
16291667
const SeerEditorWidgetSourceArea::SeerCurrentFile &info = _listForwardFiles.at(_forwardFilesIndex);
16301668
handleOpenForwardBackward(info);
16311669
}
1632-
else
1670+
else
16331671
{
16341672
QWidget::mousePressEvent(event);
16351673
}
1636-
}
1674+
}
1675+
1676+
/***********************************************************************************************************************
1677+
* Functions for handling tracing identifier *
1678+
**********************************************************************************************************************/
1679+
void SeerEditorManagerWidget::gotoDefinitionForwarder(const QString& identifier) {
1680+
1681+
_gotoDefIdentifier = identifier;
1682+
1683+
// Ask for identifier matches for Functions, Variables, and Types.
1684+
//
1685+
// Sometimes symbols have or don't have arguments.
1686+
// Searching for: "^functionName(.*)$" "^functionName$".
1687+
// Searching for: "^functionName$".
1688+
//
1689+
1690+
emit refreshFunctionList(_idFunctionDefinition, "^" + _gotoDefIdentifier + "$");
1691+
emit refreshFunctionList(_idFunctionDefinition, "^" + _gotoDefIdentifier + "\\(.*\\)$");
1692+
emit refreshVariableList(_idVariableDefinition, _gotoDefIdentifier, "");
1693+
emit refreshTypeList(_idTypeDefinition, _gotoDefIdentifier);
1694+
}
1695+

src/SeerEditorManagerWidget.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class SeerEditorManagerWidget : public QWidget, protected Ui::SeerEditorManagerW
117117
void handleTextSearchToolButtonClicked ();
118118
void handleHelpToolButtonClicked ();
119119
void handleAddAlternateDirectory (QString path);
120+
void gotoDefinitionForwarder (const QString& identifier);
120121

121122
signals:
122123
void refreshBreakpointsList ();
@@ -141,6 +142,10 @@ class SeerEditorManagerWidget : public QWidget, protected Ui::SeerEditorManagerW
141142
void requestSourceAndAssembly (QString address);
142143
void showMessage (QString message, int time);
143144
void assemblyTabShown (bool shown);
145+
void gotoDefinitionForward (const QString& identifier, bool ignoreErrors = false);
146+
void refreshFunctionList (int id, const QString& functionRegex);
147+
void refreshVariableList (int id, const QString& staticNameRegex, const QString& staticTypeRegex);
148+
void refreshTypeList (int id, const QString& typeRegex);
144149

145150
private:
146151
SeerEditorWidgetSource* currentEditorWidgetTab ();
@@ -179,5 +184,11 @@ class SeerEditorManagerWidget : public QWidget, protected Ui::SeerEditorManagerW
179184
// list of cursor positions for mouse navigation (back/forward)
180185
QList<SeerEditorWidgetSourceArea::SeerCurrentFile> _listForwardFiles;
181186
int _forwardFilesIndex = -1;
187+
188+
// _id of identifier for Go to definition
189+
int _idFunctionDefinition;
190+
int _idVariableDefinition;
191+
int _idTypeDefinition;
192+
QString _gotoDefIdentifier;
182193
};
183194

src/SeerEditorWidgetSource.cpp

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,39 +44,41 @@ SeerEditorWidgetSource::SeerEditorWidgetSource(QWidget* parent) : QWidget(parent
4444
_lineSearchShortcut = new QShortcut(QKeySequence(tr("Ctrl+L")), this);
4545
_alternateDirShortcut = new QShortcut(QKeySequence(tr("Ctrl+O")), this);
4646
_toggleBreakpointShortcut = new QShortcut(QKeySequence(tr("Ctrl+B")), this);
47+
_gotoDefinitionShortcut = new QShortcut(QKeySequence(tr("F12")), this);
4748

4849
setKeySettings(SeerKeySettings::populate());
4950

5051
// Connect things.
51-
QObject::connect(searchTextLineEdit, &QHistoryLineEdit::returnPressed, this, &SeerEditorWidgetSource::handleSearchTextLineEdit);
52-
QObject::connect(searchTextLineEdit, &QHistoryLineEdit::escapePressed, this, &SeerEditorWidgetSource::handleEscapePressed);
52+
QObject::connect(searchTextLineEdit, &QHistoryLineEdit::returnPressed, this, &SeerEditorWidgetSource::handleSearchTextLineEdit);
53+
QObject::connect(searchTextLineEdit, &QHistoryLineEdit::escapePressed, this, &SeerEditorWidgetSource::handleEscapePressed);
5354
#if QT_VERSION >= 0x060900
54-
QObject::connect(matchCaseCheckBox, &QCheckBox::checkStateChanged, this, &SeerEditorWidgetSource::handleSearchTextLineEdit);
55+
QObject::connect(matchCaseCheckBox, &QCheckBox::checkStateChanged, this, &SeerEditorWidgetSource::handleSearchTextLineEdit);
5556
#else
56-
QObject::connect(matchCaseCheckBox, &QCheckBox::stateChanged, this, &SeerEditorWidgetSource::handleSearchTextLineEdit);
57+
QObject::connect(matchCaseCheckBox, &QCheckBox::stateChanged, this, &SeerEditorWidgetSource::handleSearchTextLineEdit);
5758
#endif
58-
QObject::connect(searchDownToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleSearchDownToolButton);
59-
QObject::connect(searchUpToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleSearchUpToolButton);
60-
QObject::connect(searchLineNumberLineEdit, &QHistoryLineEdit::returnPressed, this, &SeerEditorWidgetSource::handleSearchLineNumberLineEdit);
61-
QObject::connect(searchLineNumberLineEdit, &QHistoryLineEdit::escapePressed, this, &SeerEditorWidgetSource::handleEscapePressed);
62-
QObject::connect(searchReloadToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleReloadToolButton);
63-
QObject::connect(searchCloseToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleSearchCloseToolButton);
64-
QObject::connect(alternateCloseToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleAlternateCloseToolButton);
65-
QObject::connect(alternateFileOpenToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleAlternateFileOpenToolButton);
66-
QObject::connect(alternateLineEdit, &QHistoryLineEdit::returnPressed, this, &SeerEditorWidgetSource::handleAlternateLineEdit);
67-
QObject::connect(reloadToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleReloadToolButton);
68-
QObject::connect(reloadCloseToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleReloadCloseToolButton);
69-
QObject::connect(sourceWidget, &SeerEditorWidgetSourceArea::showSearchBar, this, qOverload<bool>(&SeerEditorWidgetSource::showSearchBar));
70-
QObject::connect(sourceWidget, &SeerEditorWidgetSourceArea::showAlternateBar, this, &SeerEditorWidgetSource::showAlternateBar);
71-
QObject::connect(sourceWidget, &SeerEditorWidgetSourceArea::showReloadBar, this, &SeerEditorWidgetSource::showReloadBar);
72-
73-
QObject::connect(_textSearchShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleTextSearchShortcut);
74-
QObject::connect(_textSearchNextShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleSearchDownToolButton);
75-
QObject::connect(_textSearchPrevShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleSearchUpToolButton);
76-
QObject::connect(_textSearchReloadShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleReloadToolButton);
77-
QObject::connect(_lineSearchShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleLineSearchShortcut);
78-
QObject::connect(_alternateDirShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleAlternateDirectoryShortcut);
79-
QObject::connect(_toggleBreakpointShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleToggleBreakpointShortcut);
59+
QObject::connect(searchDownToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleSearchDownToolButton);
60+
QObject::connect(searchUpToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleSearchUpToolButton);
61+
QObject::connect(searchLineNumberLineEdit, &QHistoryLineEdit::returnPressed, this, &SeerEditorWidgetSource::handleSearchLineNumberLineEdit);
62+
QObject::connect(searchLineNumberLineEdit, &QHistoryLineEdit::escapePressed, this, &SeerEditorWidgetSource::handleEscapePressed);
63+
QObject::connect(searchReloadToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleReloadToolButton);
64+
QObject::connect(searchCloseToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleSearchCloseToolButton);
65+
QObject::connect(alternateCloseToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleAlternateCloseToolButton);
66+
QObject::connect(alternateFileOpenToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleAlternateFileOpenToolButton);
67+
QObject::connect(alternateLineEdit, &QHistoryLineEdit::returnPressed, this, &SeerEditorWidgetSource::handleAlternateLineEdit);
68+
QObject::connect(reloadToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleReloadToolButton);
69+
QObject::connect(reloadCloseToolButton, &QToolButton::clicked, this, &SeerEditorWidgetSource::handleReloadCloseToolButton);
70+
QObject::connect(sourceWidget, &SeerEditorWidgetSourceArea::showSearchBar, this, qOverload<bool>(&SeerEditorWidgetSource::showSearchBar));
71+
QObject::connect(sourceWidget, &SeerEditorWidgetSourceArea::showAlternateBar, this, &SeerEditorWidgetSource::showAlternateBar);
72+
QObject::connect(sourceWidget, &SeerEditorWidgetSourceArea::showReloadBar, this, &SeerEditorWidgetSource::showReloadBar);
73+
74+
QObject::connect(_textSearchShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleTextSearchShortcut);
75+
QObject::connect(_textSearchNextShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleSearchDownToolButton);
76+
QObject::connect(_textSearchPrevShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleSearchUpToolButton);
77+
QObject::connect(_textSearchReloadShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleReloadToolButton);
78+
QObject::connect(_lineSearchShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleLineSearchShortcut);
79+
QObject::connect(_alternateDirShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleAlternateDirectoryShortcut);
80+
QObject::connect(_toggleBreakpointShortcut, &QShortcut::activated, this, &SeerEditorWidgetSource::handleToggleBreakpointShortcut);
81+
QObject::connect(_gotoDefinitionShortcut, &QShortcut::activated, sourceArea(), &SeerEditorWidgetSourceArea::handleGotoDefinition);
8082
}
8183

8284
SeerEditorWidgetSource::~SeerEditorWidgetSource () {
@@ -125,6 +127,10 @@ void SeerEditorWidgetSource::setKeySettings (const SeerKeySettings& settings) {
125127
if (_keySettings.has("ToggleBreakpoint") == true) {
126128
_toggleBreakpointShortcut->setKey(_keySettings.get("ToggleBreakpoint")._sequence);
127129
}
130+
131+
if (_keySettings.has("GoToDefinition") == true) {
132+
_gotoDefinitionShortcut->setKey(_keySettings.get("GoToDefinition")._sequence);
133+
}
128134
}
129135

130136
const SeerKeySettings& SeerEditorWidgetSource::keySettings () const {

0 commit comments

Comments
 (0)