From c742a8bb29cbaddac2621ff8ef7cd82c0811cb26 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 7 Mar 2024 21:35:53 +0800 Subject: [PATCH] - enhancement: Issue #196 Support C++ using alias in syntax highlighting/code completion/function tips. --- NEWS.md | 2 ++ RedPandaIDE/editor.cpp | 8 +++++++- RedPandaIDE/parser/cppparser.cpp | 19 +++++++++++-------- RedPandaIDE/widgets/codecompletionpopup.cpp | 3 ++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8b8462b8..a0c1084f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -36,6 +36,8 @@ Red Panda C++ Version 2.27 - enhancement: Optimization for string/raw string/char literal status check while completing symbols in c/c++ files. - enhancement: Windows installer Hi-DPI support. - fix: Delete/Insert in column editing mode. + - enhancement: Issue #196 Support using alias in C++ syntax highlighting/code completion/function tips. + Red Panda C++ Version 2.26 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index a6d71b9e..9fd5f034 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1253,6 +1253,8 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to filename(), expression, p.line); + while (statement && statement->kind == StatementKind::skAlias) + statement = mParser->findAliasedStatement(statement); kind = getKindOfStatement(statement); mIdentCache.insert(QString("%1 %2").arg(aChar).arg(token),kind); } @@ -3766,6 +3768,9 @@ void Editor::completionInsert(bool appendFunc) if (appendFunc) { if (statement->kind == StatementKind::skAlias) { PStatement newStatement = mParser->findAliasedStatement(statement); + while (newStatement && newStatement->kind==StatementKind::skAlias) { + newStatement = mParser->findAliasedStatement(newStatement); + } if (newStatement) statement = newStatement; } @@ -4416,6 +4421,8 @@ void Editor::onExportedFormatToken(QSynedit::PSyntaxer syntaxer, int Line, int c // qDebug()<findStatementOf(mFilename, s , p.line); + while (statement && statement->kind == StatementKind::skAlias) + statement = mParser->findAliasedStatement(statement); StatementKind kind = getKindOfStatement(statement); if (kind == StatementKind::skUnknown) { if ((pEndPos.line>=1) @@ -4436,7 +4443,6 @@ void Editor::onExportedFormatToken(QSynedit::PSyntaxer syntaxer, int Line, int c break; case StatementKind::skClass: case StatementKind::skTypedef: - case StatementKind::skAlias: attr = cppSyntaxer->classAttribute(); break; case StatementKind::skEnumClassType: diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index b536d66f..e962a2f1 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -4525,8 +4525,8 @@ void CppParser::internalParse(const QString &fileName) handleInheritances(); // qDebug()<<"parse"<kind == StatementKind::skConstructor) { statement = statement->parentScope.lock(); } + while (statement && statement->kind == StatementKind::skAlias) { + statement = doFindAliasedStatement(statement); + } if (statement) { switch (statement->kind) { case StatementKind::skNamespace: @@ -5368,12 +5371,12 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName, case StatementKind::skNamespaceAlias: result = doFindAliasedNamespace(statement); break; - case StatementKind::skAlias: { - statement = doFindAliasedStatement(statement); - if (statement) - result = doCreateEvalType(fileName,statement); - } - break; + // case StatementKind::skAlias: { + // statement = + // if (statement) + // result = doCreateEvalType(fileName,statement); + // } + // break; case StatementKind::skVariable: case StatementKind::skParameter: result = doCreateEvalVariable(fileName,statement, previousResult?previousResult->templateParams:"",scope); diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index 1d4ea023..84df87f8 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -1254,10 +1254,11 @@ QVariant CodeCompletionListModel::data(const QModelIndex &index, int role) const PStatement statement = mStatements->at(index.row()); return statement->command; } - case Qt::DecorationRole: + case Qt::DecorationRole:{ PStatement statement = mStatements->at(index.row()); return pIconsManager->getPixmapForStatement(statement); } + } return QVariant(); }