Commit 40be6cc3 authored by Alain Laporte's avatar Alain Laporte Committed by Christoph Cullmann
Browse files

Ruby parser: add ability to differentiate methods and functions

And code cleaning
parent 88ead581
......@@ -18,28 +18,25 @@ void KatePluginSymbolViewerView::parseRubySymbols(void)
return;
}
m_macro->setText(i18n("Show Globals"));
m_macro->setText(i18n("Show Functions"));
m_struct->setText(i18n("Show Methods"));
m_func->setText(i18n("Show Classes"));
QString cl; // Current Line
int i;
QString name;
QTreeWidgetItem *node = nullptr;
QTreeWidgetItem *mtdNode = nullptr, *clsNode = nullptr;
QTreeWidgetItem *mtdNode = nullptr, *clsNode = nullptr, *functionNode = nullptr;
QTreeWidgetItem *lastMtdNode = nullptr, *lastClsNode = nullptr;
KTextEditor::Document *kv = m_mainWindow->activeView()->document();
// kdDebug(13000)<<"Lines counted :"<<kv->numLines()<<endl;
if (m_treeOn->isChecked()) {
clsNode = new QTreeWidgetItem(m_symbols);
clsNode->setText(0, i18n("Classes"));
clsNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Classes")));
functionNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Functions")));
clsNode->setIcon(0, m_icon_class);
functionNode->setIcon(0, m_icon_function);
if (m_expandOn->isChecked()) {
m_symbols->expandItem(clsNode);
m_symbols->expandItem(functionNode);
}
lastClsNode = clsNode;
mtdNode = clsNode;
......@@ -49,11 +46,15 @@ void KatePluginSymbolViewerView::parseRubySymbols(void)
m_symbols->setRootIsDecorated(0);
}
for (i = 0; i < kv->lines(); i++) {
cl = kv->line(i);
cl = cl.trimmed();
static const QRegularExpression function_regexp(QLatin1String("^(\\s*)def\\s+([a-zA-Z0-9_]+)\\s*(\\(.*\\))"));
static const QRegularExpression class_regexp(QLatin1String("^class\\s+([a-zA-Z0-9]+)"));
QRegularExpressionMatch match;
if (cl.indexOf(QRegularExpression(QLatin1String("^class [a-zA-Z0-9]+[^#]"))) >= 0) {
for (int i = 0; i < kv->lines(); i++) {
QString cl = kv->line(i);
match = class_regexp.match(cl);
if (match.hasMatch()) {
if (m_func->isChecked()) {
if (m_treeOn->isChecked()) {
node = new QTreeWidgetItem(clsNode, lastClsNode);
......@@ -66,29 +67,38 @@ void KatePluginSymbolViewerView::parseRubySymbols(void)
} else {
node = new QTreeWidgetItem(m_symbols);
}
node->setText(0, cl.mid(6));
node->setText(0, match.captured(1));
node->setIcon(0, m_icon_class);
node->setText(1, QString::number(i, 10));
}
continue;
}
if (cl.indexOf(QRegularExpression(QLatin1String("^def [a-zA-Z_]+[^#]"))) >= 0) {
if (m_struct->isChecked()) {
match = function_regexp.match(cl);
if (match.hasMatch()) {
if (m_struct->isChecked() && match.captured(1).isEmpty()) {
if (m_treeOn->isChecked()) {
node = new QTreeWidgetItem(functionNode);
} else {
node = new QTreeWidgetItem(m_symbols);
}
} else if (m_macro->isChecked()) {
if (m_treeOn->isChecked()) {
node = new QTreeWidgetItem(mtdNode, lastMtdNode);
lastMtdNode = node;
} else {
node = new QTreeWidgetItem(m_symbols);
}
}
name = cl.mid(4);
node->setToolTip(0, name);
if (!m_typesOn->isChecked()) {
name = name.left(name.indexOf(QLatin1Char('(')));
}
node->setText(0, name);
node->setIcon(0, m_icon_function);
node->setText(1, QString::number(i, 10));
node->setToolTip(0, match.captured(2));
if (m_typesOn->isChecked()) {
node->setText(0, match.captured(2) + match.captured(3));
} else {
node->setText(0, match.captured(2));
}
node->setIcon(0, m_icon_function);
node->setText(1, QString::number(i, 10));
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment