From 354f375f677a9439cda3d20efd00ce4cabd67f52 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 19 Apr 2022 19:17:49 +0800 Subject: [PATCH] - enhancement: improve the matching of function declaration and definitions - fix: research button doesn't show find in files dialog --- NEWS.md | 2 ++ RedPandaIDE/mainwindow.ui | 2 +- RedPandaIDE/parser/cppparser.cpp | 51 +++++++++++++++++++++++----- RedPandaIDE/widgets/searchdialog.cpp | 2 +- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index a5d01c95..6e587564 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ Red Panda C++ Version 1.0.5 - enhancement: add autolink and project template for sqlite3 + - enhancement: improve the matching of function declaration and definitions + - fix: research button doesn't show find in files dialog Red Panda C++ Version 1.0.4 - fix: hide function tips, when move or resize the main window diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 3f86a77c..39279471 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -542,7 +542,7 @@ QTabWidget::South - 6 + 3 diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index e98807e5..f3161725 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -4445,6 +4445,25 @@ QString CppParser::splitPhrase(const QString &phrase, QString &sClazz, return result; } +static bool isIdentChar(const QChar& ch) { + return ch.isLetter() + || ch == '_' + || ch.isDigit(); +} + +static void appendArgWord(QString& args, const QString& word) { + QString s=word.trimmed(); + if (s.isEmpty()) + return; + if (args.isEmpty()) + args.append(s); + else if (isIdentChar(args.back()) && isIdentChar(word.front()) ) { + args+=" "; + args+=s; + } else { + args+=s; + } +} QString CppParser::removeArgNames(const QString &args) { QString result = ""; @@ -4463,10 +4482,10 @@ QString CppParser::removeArgNames(const QString &args) word+=args[i]; } else { if (!typeGetted) { - currentArg += ' ' + word; + appendArgWord(currentArg,word); } else { if (isCppKeyword(word)) { - currentArg += ' ' + word; + appendArgWord(currentArg,word); } } word = ""; @@ -4491,29 +4510,45 @@ QString CppParser::removeArgNames(const QString &args) case '\t': if ((brackLevel >0) && !isSpaceChar(args[i-1])) { word+=args[i]; - } else if (!word.trimmed().isEmpty()) { + } else if (!word.isEmpty()) { if (!typeGetted) { - currentArg += ' ' + word; + appendArgWord(currentArg,word); if (mCppTypeKeywords.contains(word) || !isCppKeyword(word)) typeGetted = true; } else { if (isCppKeyword(word)) - currentArg += ' ' + word; + appendArgWord(currentArg,word); } word = ""; } break; + case '&': + case '*': + if (!word.isEmpty()) { + if (!typeGetted) { + appendArgWord(currentArg,word); + if (mCppTypeKeywords.contains(word) || !isCppKeyword(word)) + typeGetted = true; + } else { + if (isCppKeyword(word)) + appendArgWord(currentArg,word); + } + word = ""; + } + currentArg+=args[i]; + break; default: - if (isWordChar(args[i]) || isDigitChar(args[i])) + if (isIdentChar(args[i])) { word+=args[i]; + } } i++; } if (!typeGetted) { - currentArg += ' ' + word; + appendArgWord(currentArg,word); } else { if (isCppKeyword(word)) { - currentArg += ' ' + word; + appendArgWord(currentArg,word); } } result += currentArg.trimmed(); diff --git a/RedPandaIDE/widgets/searchdialog.cpp b/RedPandaIDE/widgets/searchdialog.cpp index 654fcdeb..21c79446 100644 --- a/RedPandaIDE/widgets/searchdialog.cpp +++ b/RedPandaIDE/widgets/searchdialog.cpp @@ -89,7 +89,7 @@ void SearchDialog::findInFiles(const QString &text) void SearchDialog::findInFiles(const QString &keyword, SearchFileScope scope, SynSearchOptions options) { - mTabBar->setCurrentIndex(1); + mTabBar->setCurrentIndex(2); ui->cbFind->setCurrentText(keyword); ui->cbFind->setFocus();