diff --git a/NEWS.md b/NEWS.md index 4353f954..27e9b863 100644 --- a/NEWS.md +++ b/NEWS.md @@ -22,6 +22,8 @@ Red Panda C++ Version 0.14.5 - fix: crash when open a project that contains custom folder - enhancement: symbol completion when editor has selection - fix: save project's layout shouldn't modify the project file + - enhancement: use expression processing in syntax highlighting for identifiers + - fix: if a function's declaration can't be found, it will be wrongly highlighted as variable Red Panda C++ Version 0.14.4 - enhancement: git - log diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 9d2fb65b..07449cd5 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -887,17 +887,24 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to if (mParser && highlighter() && (attr == highlighter()->identifierAttribute())) { BufferCoord p{aChar,line}; - BufferCoord pBeginPos,pEndPos; - QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); +// BufferCoord pBeginPos,pEndPos; +// QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); // qDebug()<findStatementOf(mFilename, - s , p.Line); +// PStatement statement = mParser->findStatementOf(mFilename, +// s , p.Line); + QStringList expression = getExpressionAtPosition(p); + PStatement statement = parser()->findStatementOf( + filename(), + expression, + p.Line); StatementKind kind = getKindOfStatement(statement); if (kind == StatementKind::skUnknown) { + BufferCoord pBeginPos,pEndPos; + QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); if ((pEndPos.Line>=1) && (pEndPos.Char>=0) - && (pEndPos.Char < lines()->getString(pEndPos.Line-1).length()) - && (lines()->getString(pEndPos.Line-1)[pEndPos.Char] == '(')) { + && (pEndPos.Char+1 < lines()->getString(pEndPos.Line-1).length()) + && (lines()->getString(pEndPos.Line-1)[pEndPos.Char+1] == '(')) { kind = StatementKind::skFunction; } else { kind = StatementKind::skVariable; diff --git a/RedPandaIDE/parser/parserutils.cpp b/RedPandaIDE/parser/parserutils.cpp index ba4d66d4..9b6e78e4 100644 --- a/RedPandaIDE/parser/parserutils.cpp +++ b/RedPandaIDE/parser/parserutils.cpp @@ -26,6 +26,7 @@ QStringList CppDirectives; QStringList JavadocTags; QMap CppKeywords; +QSet CppControlKeyWords; QSet CppTypeKeywords; QSet CKeywords; QSet STLPointers; @@ -239,6 +240,10 @@ void initParser() CKeywords.insert("volatile"); CKeywords.insert("while"); + CppControlKeyWords.insert("for"); + CppControlKeyWords.insert("if"); + CppControlKeyWords.insert("catch"); + //STL Containers STLContainers.insert("std::array"); STLContainers.insert("std::vector"); @@ -621,3 +626,8 @@ bool isCppFile(const QString &filename) return true; return false; } + +bool isCppControlKeyword(const QString &word) +{ + return CppControlKeyWords.contains(word); +} diff --git a/RedPandaIDE/parser/parserutils.h b/RedPandaIDE/parser/parserutils.h index 5e7d2b4d..83519c02 100644 --- a/RedPandaIDE/parser/parserutils.h +++ b/RedPandaIDE/parser/parserutils.h @@ -248,6 +248,7 @@ using PFileIncludes = std::shared_ptr; extern QStringList CppDirectives; extern QStringList JavadocTags; extern QMap CppKeywords; +extern QSet CppControlKeyWords; extern QSet CKeywords; extern QSet CppTypeKeywords; extern QSet STLPointers; @@ -268,6 +269,7 @@ bool isHFile(const QString& filename); bool isCFile(const QString& filename); bool isCppFile(const QString& filename); bool isCppKeyword(const QString& word); +bool isCppControlKeyword(const QString& word); bool isScopeTypeKind(StatementKind kind); MemberOperatorType getOperatorType(const QString& phrase, int index); QStringList getOwnerExpressionAndMember(