- enhancement: Issue #196 Support C++ using alias in syntax highlighting/code completion/function tips.

This commit is contained in:
Roy Qu 2024-03-07 21:35:53 +08:00
parent 1283609c41
commit c742a8bb29
4 changed files with 22 additions and 10 deletions

View File

@ -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: Optimization for string/raw string/char literal status check while completing symbols in c/c++ files.
- enhancement: Windows installer Hi-DPI support. - enhancement: Windows installer Hi-DPI support.
- fix: Delete/Insert in column editing mode. - 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 Red Panda C++ Version 2.26

View File

@ -1253,6 +1253,8 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
filename(), filename(),
expression, expression,
p.line); p.line);
while (statement && statement->kind == StatementKind::skAlias)
statement = mParser->findAliasedStatement(statement);
kind = getKindOfStatement(statement); kind = getKindOfStatement(statement);
mIdentCache.insert(QString("%1 %2").arg(aChar).arg(token),kind); mIdentCache.insert(QString("%1 %2").arg(aChar).arg(token),kind);
} }
@ -3766,6 +3768,9 @@ void Editor::completionInsert(bool appendFunc)
if (appendFunc) { if (appendFunc) {
if (statement->kind == StatementKind::skAlias) { if (statement->kind == StatementKind::skAlias) {
PStatement newStatement = mParser->findAliasedStatement(statement); PStatement newStatement = mParser->findAliasedStatement(statement);
while (newStatement && newStatement->kind==StatementKind::skAlias) {
newStatement = mParser->findAliasedStatement(newStatement);
}
if (newStatement) if (newStatement)
statement = newStatement; statement = newStatement;
} }
@ -4416,6 +4421,8 @@ void Editor::onExportedFormatToken(QSynedit::PSyntaxer syntaxer, int Line, int c
// qDebug()<<s; // qDebug()<<s;
PStatement statement = mParser->findStatementOf(mFilename, PStatement statement = mParser->findStatementOf(mFilename,
s , p.line); s , p.line);
while (statement && statement->kind == StatementKind::skAlias)
statement = mParser->findAliasedStatement(statement);
StatementKind kind = getKindOfStatement(statement); StatementKind kind = getKindOfStatement(statement);
if (kind == StatementKind::skUnknown) { if (kind == StatementKind::skUnknown) {
if ((pEndPos.line>=1) if ((pEndPos.line>=1)
@ -4436,7 +4443,6 @@ void Editor::onExportedFormatToken(QSynedit::PSyntaxer syntaxer, int Line, int c
break; break;
case StatementKind::skClass: case StatementKind::skClass:
case StatementKind::skTypedef: case StatementKind::skTypedef:
case StatementKind::skAlias:
attr = cppSyntaxer->classAttribute(); attr = cppSyntaxer->classAttribute();
break; break;
case StatementKind::skEnumClassType: case StatementKind::skEnumClassType:

View File

@ -4525,8 +4525,8 @@ void CppParser::internalParse(const QString &fileName)
handleInheritances(); handleInheritances();
// qDebug()<<"parse"<<timer.elapsed(); // qDebug()<<"parse"<<timer.elapsed();
#ifdef QT_DEBUG #ifdef QT_DEBUG
mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName))); // mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName)));
mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName))); // mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName)));
#endif #endif
//reduce memory usage //reduce memory usage
internalClear(); internalClear();
@ -5360,6 +5360,9 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName,
if (statement && statement->kind == StatementKind::skConstructor) { if (statement && statement->kind == StatementKind::skConstructor) {
statement = statement->parentScope.lock(); statement = statement->parentScope.lock();
} }
while (statement && statement->kind == StatementKind::skAlias) {
statement = doFindAliasedStatement(statement);
}
if (statement) { if (statement) {
switch (statement->kind) { switch (statement->kind) {
case StatementKind::skNamespace: case StatementKind::skNamespace:
@ -5368,12 +5371,12 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName,
case StatementKind::skNamespaceAlias: case StatementKind::skNamespaceAlias:
result = doFindAliasedNamespace(statement); result = doFindAliasedNamespace(statement);
break; break;
case StatementKind::skAlias: { // case StatementKind::skAlias: {
statement = doFindAliasedStatement(statement); // statement =
if (statement) // if (statement)
result = doCreateEvalType(fileName,statement); // result = doCreateEvalType(fileName,statement);
} // }
break; // break;
case StatementKind::skVariable: case StatementKind::skVariable:
case StatementKind::skParameter: case StatementKind::skParameter:
result = doCreateEvalVariable(fileName,statement, previousResult?previousResult->templateParams:"",scope); result = doCreateEvalVariable(fileName,statement, previousResult?previousResult->templateParams:"",scope);

View File

@ -1254,10 +1254,11 @@ QVariant CodeCompletionListModel::data(const QModelIndex &index, int role) const
PStatement statement = mStatements->at(index.row()); PStatement statement = mStatements->at(index.row());
return statement->command; return statement->command;
} }
case Qt::DecorationRole: case Qt::DecorationRole:{
PStatement statement = mStatements->at(index.row()); PStatement statement = mStatements->at(index.row());
return pIconsManager->getPixmapForStatement(statement); return pIconsManager->getPixmapForStatement(statement);
} }
}
return QVariant(); return QVariant();
} }