- 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
This commit is contained in:
Roy Qu 2022-03-08 22:29:15 +08:00
parent 2a84679f7c
commit 44d5453263
4 changed files with 27 additions and 6 deletions

View File

@ -22,6 +22,8 @@ Red Panda C++ Version 0.14.5
- fix: crash when open a project that contains custom folder - fix: crash when open a project that contains custom folder
- enhancement: symbol completion when editor has selection - enhancement: symbol completion when editor has selection
- fix: save project's layout shouldn't modify the project file - 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 Red Panda C++ Version 0.14.4
- enhancement: git - log - enhancement: git - log

View File

@ -887,17 +887,24 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
if (mParser && highlighter() && (attr == highlighter()->identifierAttribute())) { if (mParser && highlighter() && (attr == highlighter()->identifierAttribute())) {
BufferCoord p{aChar,line}; BufferCoord p{aChar,line};
BufferCoord pBeginPos,pEndPos; // BufferCoord pBeginPos,pEndPos;
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); // QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
// qDebug()<<s; // qDebug()<<s;
PStatement statement = mParser->findStatementOf(mFilename, // PStatement statement = mParser->findStatementOf(mFilename,
s , p.Line); // s , p.Line);
QStringList expression = getExpressionAtPosition(p);
PStatement statement = parser()->findStatementOf(
filename(),
expression,
p.Line);
StatementKind kind = getKindOfStatement(statement); StatementKind kind = getKindOfStatement(statement);
if (kind == StatementKind::skUnknown) { if (kind == StatementKind::skUnknown) {
BufferCoord pBeginPos,pEndPos;
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
if ((pEndPos.Line>=1) if ((pEndPos.Line>=1)
&& (pEndPos.Char>=0) && (pEndPos.Char>=0)
&& (pEndPos.Char < lines()->getString(pEndPos.Line-1).length()) && (pEndPos.Char+1 < lines()->getString(pEndPos.Line-1).length())
&& (lines()->getString(pEndPos.Line-1)[pEndPos.Char] == '(')) { && (lines()->getString(pEndPos.Line-1)[pEndPos.Char+1] == '(')) {
kind = StatementKind::skFunction; kind = StatementKind::skFunction;
} else { } else {
kind = StatementKind::skVariable; kind = StatementKind::skVariable;

View File

@ -26,6 +26,7 @@
QStringList CppDirectives; QStringList CppDirectives;
QStringList JavadocTags; QStringList JavadocTags;
QMap<QString,SkipType> CppKeywords; QMap<QString,SkipType> CppKeywords;
QSet<QString> CppControlKeyWords;
QSet<QString> CppTypeKeywords; QSet<QString> CppTypeKeywords;
QSet<QString> CKeywords; QSet<QString> CKeywords;
QSet<QString> STLPointers; QSet<QString> STLPointers;
@ -239,6 +240,10 @@ void initParser()
CKeywords.insert("volatile"); CKeywords.insert("volatile");
CKeywords.insert("while"); CKeywords.insert("while");
CppControlKeyWords.insert("for");
CppControlKeyWords.insert("if");
CppControlKeyWords.insert("catch");
//STL Containers //STL Containers
STLContainers.insert("std::array"); STLContainers.insert("std::array");
STLContainers.insert("std::vector"); STLContainers.insert("std::vector");
@ -621,3 +626,8 @@ bool isCppFile(const QString &filename)
return true; return true;
return false; return false;
} }
bool isCppControlKeyword(const QString &word)
{
return CppControlKeyWords.contains(word);
}

View File

@ -248,6 +248,7 @@ using PFileIncludes = std::shared_ptr<FileIncludes>;
extern QStringList CppDirectives; extern QStringList CppDirectives;
extern QStringList JavadocTags; extern QStringList JavadocTags;
extern QMap<QString,SkipType> CppKeywords; extern QMap<QString,SkipType> CppKeywords;
extern QSet<QString> CppControlKeyWords;
extern QSet<QString> CKeywords; extern QSet<QString> CKeywords;
extern QSet<QString> CppTypeKeywords; extern QSet<QString> CppTypeKeywords;
extern QSet<QString> STLPointers; extern QSet<QString> STLPointers;
@ -268,6 +269,7 @@ bool isHFile(const QString& filename);
bool isCFile(const QString& filename); bool isCFile(const QString& filename);
bool isCppFile(const QString& filename); bool isCppFile(const QString& filename);
bool isCppKeyword(const QString& word); bool isCppKeyword(const QString& word);
bool isCppControlKeyword(const QString& word);
bool isScopeTypeKind(StatementKind kind); bool isScopeTypeKind(StatementKind kind);
MemberOperatorType getOperatorType(const QString& phrase, int index); MemberOperatorType getOperatorType(const QString& phrase, int index);
QStringList getOwnerExpressionAndMember( QStringList getOwnerExpressionAndMember(