From 24a4f0e127d71cc110590774e8f32307052e5270 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 30 Jun 2022 14:39:12 +0800 Subject: [PATCH] - change: just show one function hint for overloaded functions --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 71 ++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1c6d0ee0..0ed85353 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ Red Panda C++ Version 1.1.3 - enhancement: copy the whole folded code block - enhancement: delete the whole folded code block - fix: correctly update the folding state of code block, when deleted + - change: just show one function hint for overloaded functions Red Panda C++ Version 1.1.2 - enhancement: use different color to differenciate folder and headers in completion popup window diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 0b2a9b63..10c25566 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -3418,6 +3418,7 @@ QString Editor::getParserHint(const QStringList& expression,const QString &/*s*/ { // This piece of code changes the parser database, possibly making hints and code completion invalid... QString result; + // Exit early, don't bother creating a stream (which is slow) PStatement statement = mParser->findStatementOf( mFilename,expression, line); @@ -3427,21 +3428,27 @@ QString Editor::getParserHint(const QStringList& expression,const QString &/*s*/ || statement->kind == StatementKind::skConstructor || statement->kind == StatementKind::skDestructor) { PStatement parentScope = statement->parentScope.lock(); - if (parentScope && parentScope->kind == StatementKind::skNamespace) { - PStatementList namespaceStatementsList = - mParser->findNamespace(parentScope->command); - if (namespaceStatementsList) { - foreach (const PStatement& namespaceStatement, *namespaceStatementsList) { - QString hint = getHintForFunction(statement,namespaceStatement, - mFilename,line); - if (!hint.isEmpty()) { - if (!result.isEmpty()) - result += "
"; - result += hint; - } - } - } - } else +// if (parentScope && parentScope->kind == StatementKind::skNamespace) { +// PStatementList namespaceStatementsList = +// mParser->findNamespace(parentScope->command); +// if (namespaceStatementsList) { +// int counts=0; +// foreach (const PStatement& namespaceStatement, *namespaceStatementsList) { +// QString hint = getHintForFunction(statement,namespaceStatement, +// mFilename,line); +// if (!hint.isEmpty()) { +// counts++; +// if (!result.isEmpty()) +// result += "\n"; +// if (counts>4) { +// result += "..."; +// break; +// } +// result += hint; +// } +// } +// } +// } else result = getHintForFunction(statement, parentScope, mFilename,line); } else if (statement->line>0) { @@ -3489,22 +3496,26 @@ QString Editor::getErrorHint(const PSyntaxIssue& issue) QString Editor::getHintForFunction(const PStatement &statement, const PStatement &scopeStatement, const QString& filename, int line) { + QFileInfo fileInfo(statement->fileName); QString result; - const StatementMap& children = mParser->statementList().childrenStatements(scopeStatement); - foreach (const PStatement& childStatement, children){ - if (statement->command == childStatement->command - && statement->kind == childStatement->kind) { - if ((line < childStatement->line) && - childStatement->fileName == filename) - continue; - if (!result.isEmpty()) - result += "
"; - QFileInfo fileInfo(childStatement->fileName); - result = mParser->prettyPrintStatement(childStatement,filename,line) + " - " - + QString("%1(%2) ").arg(fileInfo.fileName()).arg(childStatement->line) - + tr("Ctrl+click for more info"); - } - } + result = mParser->prettyPrintStatement(statement,filename,line) + " - " + + QString("%1(%2) ").arg(fileInfo.fileName()).arg(statement->line) + + tr("Ctrl+click for more info"); +// const StatementMap& children = mParser->statementList().childrenStatements(scopeStatement); +// foreach (const PStatement& childStatement, children){ +// if (statement->command == childStatement->command +// && statement->kind == childStatement->kind) { +// if ((line < childStatement->line) && +// childStatement->fileName == filename) +// continue; +// if (!result.isEmpty()) +// result += "\n"; +// QFileInfo fileInfo(childStatement->fileName); +// result = mParser->prettyPrintStatement(childStatement,filename,line) + " - " +// + QString("%1(%2) ").arg(fileInfo.fileName()).arg(childStatement->line) +// + tr("Ctrl+click for more info"); +// } +// } return result; }