From cd5b281c904025f83ecd3b7390ea64ba9b61fb09 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 17 Dec 2021 21:47:37 +0800 Subject: [PATCH] - enhancement: use the new expression parser to parse info for tips --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 33 +++++++++++++++++++++++++-------- RedPandaIDE/editor.h | 4 ++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index 01f75e26..a818a7aa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ Version 0.11.3 For Dev-C++ 7 Beta - fix: use pixel size for fonts, to fit different dpi in multiple displays + - enhancement: use the new expression parser to parse info for tips Version 0.11.2 For Dev-C++ 7 Beta - fix: button "run all problem cases" not disabled when compiling or debugging diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 789874b8..2a5fbc95 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -972,6 +972,7 @@ bool Editor::event(QEvent *event) bool isIncludeLine = false; BufferCoord pBeginPos,pEndPos; QString s; + QStringList expression; switch (reason) { case TipType::Preprocessor: // When hovering above a preprocessor line, determine if we want to show an include or a identifier hint @@ -985,8 +986,10 @@ bool Editor::event(QEvent *event) s = getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpEvaluation); // debugging else if (//devEditor.ParserHints and !mCompletionPopup->isVisible() - && !mHeaderCompletionPopup->isVisible()) - s = getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); // information during coding + && !mHeaderCompletionPopup->isVisible()) { + expression = getExpressionAtPosition(p); + s = expression.join(""); // information during coding + } break; case TipType::Selection: s = selText(); // when a selection is available, always only use that @@ -1028,7 +1031,7 @@ bool Editor::event(QEvent *event) !mCompletionPopup->isVisible() && !mHeaderCompletionPopup->isVisible()) { if (pSettings->editor().enableIdentifierToolTips()) - hint = getParserHint(s,p.Line); + hint = getParserHint(QStringList(),s,p.Line); } break; case TipType::Identifier: @@ -1039,7 +1042,7 @@ bool Editor::event(QEvent *event) && (pSettings->editor().enableDebugTooltips())) { showDebugHint(s,p.Line); } else if (pSettings->editor().enableIdentifierToolTips()) { //if devEditor.ParserHints { - hint = getParserHint(s, p.Line); + hint = getParserHint(expression, s, p.Line); } } break; @@ -1627,7 +1630,7 @@ QStringList Editor::getOwnerExpressionAndMemberAtPositionForCompletion( QString &memberOperator, QStringList &memberExpression) { - QStringList expression = getExpressionAtPositionForCompletion(pos); + QStringList expression = getExpressionAtPosition(pos); //find position of the last member operator int lastMemberOperatorPos = -1; int currentMatchingLevel = 0; @@ -1675,7 +1678,7 @@ QStringList Editor::getOwnerExpressionAndMemberAtPositionForCompletion( return ownerExpression; } -QStringList Editor::getExpressionAtPositionForCompletion( +QStringList Editor::getExpressionAtPosition( const BufferCoord &pos) { QStringList result; @@ -3092,11 +3095,25 @@ QString Editor::getFileHint(const QString &s) return ""; } -QString Editor::getParserHint(const QString &s, int line) +QString Editor::getParserHint(const QStringList& expression,const QString &s, int line) { // This piece of code changes the parser database, possibly making hints and code completion invalid... QString result; - PStatement statement = mParser->findStatementOf(mFilename, s, line); + PStatement statement; + if (expression.count()>1) { + PEvalStatement evalStatement = mParser->evalExpression( + mFilename,expression, + mParser->findAndScanBlockAt(mFilename,line)); + if (evalStatement) { + if (evalStatement->kind == EvalStatementKind::Type) { + statement = evalStatement->effectiveTypeStatement; + } else { + statement = evalStatement->baseStatement; + } + } + } else { + statement = mParser->findStatementOf(mFilename, s, line); + } if (!statement) return result; if (statement->kind == StatementKind::skFunction diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 9eb41da5..3ccbe2c2 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -249,7 +249,7 @@ private: TipType getTipType(QPoint point, BufferCoord& pos); void cancelHint(); QString getFileHint(const QString& s); - QString getParserHint(const QString& s, int line); + QString getParserHint(const QStringList& expression,const QString& s, int line); void showDebugHint(const QString& s,int line); QString getErrorHint(const PSyntaxIssue& issue); QString getHintForFunction(const PStatement& statement, const PStatement& scope, @@ -260,7 +260,7 @@ private: void popUserCodeInTabStops(); void onExportedFormatToken(PSynHighlighter syntaxHighlighter, int Line, int column, const QString& token, PSynHighlighterAttribute &attr); - QStringList getExpressionAtPositionForCompletion( + QStringList getExpressionAtPosition( const BufferCoord& pos); private: QByteArray mEncodingOption; // the encoding type set by the user