- enhancement: use the new expression parser to parse info for tips

This commit is contained in:
Roy Qu 2021-12-17 21:47:37 +08:00
parent 8a4842efb4
commit cd5b281c90
3 changed files with 28 additions and 10 deletions

View File

@ -1,5 +1,6 @@
Version 0.11.3 For Dev-C++ 7 Beta Version 0.11.3 For Dev-C++ 7 Beta
- fix: use pixel size for fonts, to fit different dpi in multiple displays - 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 Version 0.11.2 For Dev-C++ 7 Beta
- fix: button "run all problem cases" not disabled when compiling or debugging - fix: button "run all problem cases" not disabled when compiling or debugging

View File

@ -972,6 +972,7 @@ bool Editor::event(QEvent *event)
bool isIncludeLine = false; bool isIncludeLine = false;
BufferCoord pBeginPos,pEndPos; BufferCoord pBeginPos,pEndPos;
QString s; QString s;
QStringList expression;
switch (reason) { switch (reason) {
case TipType::Preprocessor: case TipType::Preprocessor:
// When hovering above a preprocessor line, determine if we want to show an include or a identifier hint // 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 s = getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpEvaluation); // debugging
else if (//devEditor.ParserHints and else if (//devEditor.ParserHints and
!mCompletionPopup->isVisible() !mCompletionPopup->isVisible()
&& !mHeaderCompletionPopup->isVisible()) && !mHeaderCompletionPopup->isVisible()) {
s = getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); // information during coding expression = getExpressionAtPosition(p);
s = expression.join(""); // information during coding
}
break; break;
case TipType::Selection: case TipType::Selection:
s = selText(); // when a selection is available, always only use that s = selText(); // when a selection is available, always only use that
@ -1028,7 +1031,7 @@ bool Editor::event(QEvent *event)
!mCompletionPopup->isVisible() !mCompletionPopup->isVisible()
&& !mHeaderCompletionPopup->isVisible()) { && !mHeaderCompletionPopup->isVisible()) {
if (pSettings->editor().enableIdentifierToolTips()) if (pSettings->editor().enableIdentifierToolTips())
hint = getParserHint(s,p.Line); hint = getParserHint(QStringList(),s,p.Line);
} }
break; break;
case TipType::Identifier: case TipType::Identifier:
@ -1039,7 +1042,7 @@ bool Editor::event(QEvent *event)
&& (pSettings->editor().enableDebugTooltips())) { && (pSettings->editor().enableDebugTooltips())) {
showDebugHint(s,p.Line); showDebugHint(s,p.Line);
} else if (pSettings->editor().enableIdentifierToolTips()) { //if devEditor.ParserHints { } else if (pSettings->editor().enableIdentifierToolTips()) { //if devEditor.ParserHints {
hint = getParserHint(s, p.Line); hint = getParserHint(expression, s, p.Line);
} }
} }
break; break;
@ -1627,7 +1630,7 @@ QStringList Editor::getOwnerExpressionAndMemberAtPositionForCompletion(
QString &memberOperator, QString &memberOperator,
QStringList &memberExpression) QStringList &memberExpression)
{ {
QStringList expression = getExpressionAtPositionForCompletion(pos); QStringList expression = getExpressionAtPosition(pos);
//find position of the last member operator //find position of the last member operator
int lastMemberOperatorPos = -1; int lastMemberOperatorPos = -1;
int currentMatchingLevel = 0; int currentMatchingLevel = 0;
@ -1675,7 +1678,7 @@ QStringList Editor::getOwnerExpressionAndMemberAtPositionForCompletion(
return ownerExpression; return ownerExpression;
} }
QStringList Editor::getExpressionAtPositionForCompletion( QStringList Editor::getExpressionAtPosition(
const BufferCoord &pos) const BufferCoord &pos)
{ {
QStringList result; QStringList result;
@ -3092,11 +3095,25 @@ QString Editor::getFileHint(const QString &s)
return ""; 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... // This piece of code changes the parser database, possibly making hints and code completion invalid...
QString result; 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) if (!statement)
return result; return result;
if (statement->kind == StatementKind::skFunction if (statement->kind == StatementKind::skFunction

View File

@ -249,7 +249,7 @@ private:
TipType getTipType(QPoint point, BufferCoord& pos); TipType getTipType(QPoint point, BufferCoord& pos);
void cancelHint(); void cancelHint();
QString getFileHint(const QString& s); 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); void showDebugHint(const QString& s,int line);
QString getErrorHint(const PSyntaxIssue& issue); QString getErrorHint(const PSyntaxIssue& issue);
QString getHintForFunction(const PStatement& statement, const PStatement& scope, QString getHintForFunction(const PStatement& statement, const PStatement& scope,
@ -260,7 +260,7 @@ private:
void popUserCodeInTabStops(); void popUserCodeInTabStops();
void onExportedFormatToken(PSynHighlighter syntaxHighlighter, int Line, int column, const QString& token, void onExportedFormatToken(PSynHighlighter syntaxHighlighter, int Line, int column, const QString& token,
PSynHighlighterAttribute &attr); PSynHighlighterAttribute &attr);
QStringList getExpressionAtPositionForCompletion( QStringList getExpressionAtPosition(
const BufferCoord& pos); const BufferCoord& pos);
private: private:
QByteArray mEncodingOption; // the encoding type set by the user QByteArray mEncodingOption; // the encoding type set by the user