- fix: editor folder process error

- add: function tooltip
This commit is contained in:
royqh1979@gmail.com 2021-09-23 12:06:26 +08:00
parent 6065c2d24f
commit 842e1f6cbd
15 changed files with 132 additions and 229 deletions

View File

@ -79,11 +79,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
editor.highlighter()->resetState(); editor.highlighter()->resetState();
} else { } else {
editor.highlighter()->setState( editor.highlighter()->setState(
editor.lines()->ranges(posY-1), editor.lines()->ranges(posY-1));
editor.lines()->braceLevels(posY-1),
editor.lines()->bracketLevels(posY-1),
editor.lines()->parenthesisLevels(posY-1)
);
} }
editor.highlighter()->setLine(line,posY); editor.highlighter()->setLine(line,posY);
while (!editor.highlighter()->eol()) { while (!editor.highlighter()->eol()) {

View File

@ -343,10 +343,7 @@ bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &XY, QString &Token,
if (PosY == 0) { if (PosY == 0) {
mHighlighter->resetState(); mHighlighter->resetState();
} else { } else {
mHighlighter->setState(mLines->ranges(PosY-1), mHighlighter->setState(mLines->ranges(PosY-1));
mLines->braceLevels(PosY-1),
mLines->bracketLevels(PosY-1),
mLines->parenthesisLevels(PosY-1));
} }
mHighlighter->setLine(Line, PosY); mHighlighter->setLine(Line, PosY);
PosX = XY.Char; PosX = XY.Char;
@ -384,10 +381,7 @@ bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &XY, QString &Toke
if (PosY == 0) { if (PosY == 0) {
mHighlighter->resetState(); mHighlighter->resetState();
} else { } else {
mHighlighter->setState(mLines->ranges(PosY-1), mHighlighter->setState(mLines->ranges(PosY-1));
mLines->braceLevels(PosY-1),
mLines->bracketLevels(PosY-1),
mLines->parenthesisLevels(PosY-1));
} }
mHighlighter->setLine(Line, PosY); mHighlighter->setLine(Line, PosY);
PosX = XY.Char; PosX = XY.Char;
@ -2858,7 +2852,7 @@ void SynEdit::updateModifiedStatus()
setModified(!mUndoList->initialState()); setModified(!mUndoList->initialState());
} }
int SynEdit::scanFrom(int Index) int SynEdit::scanFrom(int Index, int canStopIndex)
{ {
SynRangeState iRange; SynRangeState iRange;
int Result = Index; int Result = Index;
@ -2868,27 +2862,18 @@ int SynEdit::scanFrom(int Index)
if (Result == 0) { if (Result == 0) {
mHighlighter->resetState(); mHighlighter->resetState();
} else { } else {
mHighlighter->setState(mLines->ranges(Result-1), mHighlighter->setState(mLines->ranges(Result-1));
mLines->braceLevels(Result-1),
mLines->bracketLevels(Result-1),
mLines->parenthesisLevels(Result-1));
} }
do { do {
mHighlighter->setLine(mLines->getString(Result), Result); mHighlighter->setLine(mLines->getString(Result), Result);
mHighlighter->nextToEol(); mHighlighter->nextToEol();
iRange = mHighlighter->getRangeState(); iRange = mHighlighter->getRangeState();
{ if (Result > canStopIndex){
if (mLines->ranges(Result).state == iRange.state if (mLines->ranges(Result).state == iRange.state
&& mLines->braceLevels(Result) == mHighlighter->getBraceLevel()
&& mLines->bracketLevels(Result) == mHighlighter->getBracketLevel()
&& mLines->parenthesisLevels(Result) == mHighlighter->getParenthesisLevel()
) )
return Result;// avoid the final Decrement return Result;// avoid the final Decrement
} }
mLines->setRange(Result,iRange); mLines->setRange(Result,iRange);
mLines->setParenthesisLevel(Result,mHighlighter->getParenthesisLevel());
mLines->setBraceLevel(Result,mHighlighter->getBraceLevel());
mLines->setBracketLevel(Result,mHighlighter->getBracketLevel());
Result ++ ; Result ++ ;
} while (Result < mLines->count()); } while (Result < mLines->count());
Result--; Result--;
@ -2903,9 +2888,6 @@ void SynEdit::scanRanges()
mHighlighter->setLine(mLines->getString(i), i); mHighlighter->setLine(mLines->getString(i), i);
mHighlighter->nextToEol(); mHighlighter->nextToEol();
mLines->setRange(i, mHighlighter->getRangeState()); mLines->setRange(i, mHighlighter->getRangeState());
mLines->setParenthesisLevel(i, mHighlighter->getParenthesisLevel());
mLines->setBracketLevel(i, mHighlighter->getBracketLevel());
mLines->setBraceLevel(i, mHighlighter->getBraceLevel());
} }
} }
} }
@ -3067,7 +3049,6 @@ void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,P
QString CurLine; QString CurLine;
bool useBraces = ( mCodeFolding.foldRegions.get(FoldIndex)->openSymbol == "{" bool useBraces = ( mCodeFolding.foldRegions.get(FoldIndex)->openSymbol == "{"
&& mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol == "}"); && mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol == "}");
int lastBraceLevel = 0;
if (!mHighlighter) if (!mHighlighter)
return; return;
@ -3083,21 +3064,8 @@ void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,P
if (useBraces) { if (useBraces) {
// Find an opening character on this line // Find an opening character on this line
CurLine = mLines->getString(Line); CurLine = mLines->getString(Line);
if (mLines->rightBraces(Line)>0) {
int curBraceLevel = mLines->braceLevels(Line); for (int i=0; i<mLines->rightBraces(Line);i++) {
if (curBraceLevel > lastBraceLevel) {
for (int i=0; i<curBraceLevel-lastBraceLevel;i++) {
// Add it to the top list of folds
Parent = parentFoldRanges->addByParts(
Parent,
TopFoldRanges,
Line + 1,
mCodeFolding.foldRegions.get(FoldIndex),
Line + 1);
parentFoldRanges = Parent->subFoldRanges;
}
} else if (curBraceLevel < lastBraceLevel) {
for (int i=0; i<lastBraceLevel-curBraceLevel;i++) {
// Stop the recursion if we find a closing char, and return to our parent // Stop the recursion if we find a closing char, and return to our parent
if (Parent) { if (Parent) {
Parent->toLine = Line + 1; Parent->toLine = Line + 1;
@ -3110,16 +3078,24 @@ void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,P
} }
} }
} }
lastBraceLevel = curBraceLevel; if (mLines->leftBraces(Line)>0) {
for (int i=0; i<mLines->leftBraces(Line);i++) {
// Add it to the top list of folds
Parent = parentFoldRanges->addByParts(
Parent,
TopFoldRanges,
Line + 1,
mCodeFolding.foldRegions.get(FoldIndex),
Line + 1);
parentFoldRanges = Parent->subFoldRanges;
}
}
} else { } else {
// Find an opening character on this line // Find an opening character on this line
CurLine = mLines->getString(Line); CurLine = mLines->getString(Line);
mHighlighter->setState(mLines->ranges(Line), mHighlighter->setState(mLines->ranges(Line));
mLines->braceLevels(Line),
mLines->bracketLevels(Line),
mLines->parenthesisLevels(Line));
mHighlighter->setLine(CurLine,Line); mHighlighter->setLine(CurLine,Line);
QString token; QString token;
@ -5793,7 +5769,7 @@ void SynEdit::onLinesDeleted(int index, int count)
if (mUseCodeFolding) if (mUseCodeFolding)
foldOnListDeleted(index + 1, count); foldOnListDeleted(index + 1, count);
if (mHighlighter && mLines->count() > 0) if (mHighlighter && mLines->count() > 0)
scanFrom(index); scanFrom(index, index);
invalidateLines(index + 1, INT_MAX); invalidateLines(index + 1, INT_MAX);
invalidateGutterLines(index + 1, INT_MAX); invalidateGutterLines(index + 1, INT_MAX);
} }
@ -5803,21 +5779,21 @@ void SynEdit::onLinesInserted(int index, int count)
if (mUseCodeFolding) if (mUseCodeFolding)
foldOnListInserted(index + 1, count); foldOnListInserted(index + 1, count);
if (mHighlighter && mLines->count() > 0) { if (mHighlighter && mLines->count() > 0) {
int vLastScan = index; // int vLastScan = index;
do { // do {
vLastScan = scanFrom(vLastScan); scanFrom(index, index+count);
vLastScan++; // vLastScan++;
} while (vLastScan < index + count) ; // } while (vLastScan < index + count) ;
} }
invalidateLines(index + 1, INT_MAX); invalidateLines(index + 1, INT_MAX);
invalidateGutterLines(index + 1, INT_MAX); invalidateGutterLines(index + 1, INT_MAX);
} }
void SynEdit::onLinesPutted(int index, int) void SynEdit::onLinesPutted(int index, int count)
{ {
int vEndLine = index + 1; int vEndLine = index + 1;
if (mHighlighter) { if (mHighlighter) {
vEndLine = std::max(vEndLine, scanFrom(index) + 1); vEndLine = std::max(vEndLine, scanFrom(index, index+count) + 1);
// If this editor is chained then the real owner of text buffer will probably // If this editor is chained then the real owner of text buffer will probably
// have already parsed the changes, so ScanFrom will return immediately. // have already parsed the changes, so ScanFrom will return immediately.
if (mLines != mOrigLines) if (mLines != mOrigLines)

View File

@ -446,7 +446,7 @@ private:
void recalcCharExtent(); void recalcCharExtent();
QString expandAtWideGlyphs(const QString& S); QString expandAtWideGlyphs(const QString& S);
void updateModifiedStatus(); void updateModifiedStatus();
int scanFrom(int Index); int scanFrom(int Index, int canStopIndex);
void scanRanges(); void scanRanges();
void uncollapse(PSynEditFoldRange FoldRange); void uncollapse(PSynEditFoldRange FoldRange);
void collapse(PSynEditFoldRange FoldRange); void collapse(PSynEditFoldRange FoldRange);

View File

@ -27,7 +27,7 @@ static void ListIndexOutOfBounds(int index) {
int SynEditStringList::parenthesisLevels(int Index) int SynEditStringList::parenthesisLevels(int Index)
{ {
if (Index>=0 && Index < mList.size()) { if (Index>=0 && Index < mList.size()) {
return mList[Index]->fParenthesisLevel; return mList[Index]->fRange.parenthesisLevel;
} else } else
return 0; return 0;
} }
@ -35,7 +35,7 @@ int SynEditStringList::parenthesisLevels(int Index)
int SynEditStringList::bracketLevels(int Index) int SynEditStringList::bracketLevels(int Index)
{ {
if (Index>=0 && Index < mList.size()) { if (Index>=0 && Index < mList.size()) {
return mList[Index]->fBracketLevel; return mList[Index]->fRange.bracketLevel;
} else } else
return 0; return 0;
} }
@ -43,7 +43,7 @@ int SynEditStringList::bracketLevels(int Index)
int SynEditStringList::braceLevels(int Index) int SynEditStringList::braceLevels(int Index)
{ {
if (Index>=0 && Index < mList.size()) { if (Index>=0 && Index < mList.size()) {
return mList[Index]->fBraceLevel; return mList[Index]->fRange.braceLevel;
} else } else
return 0; return 0;
} }
@ -70,6 +70,22 @@ int SynEditStringList::lineColumns(int Index)
return 0; return 0;
} }
int SynEditStringList::leftBraces(int Index)
{
if (Index>=0 && Index < mList.size()) {
return mList[Index]->fRange.leftBraces;
} else
return 0;
}
int SynEditStringList::rightBraces(int Index)
{
if (Index>=0 && Index < mList.size()) {
return mList[Index]->fRange.rightBraces;
} else
return 0;
}
int SynEditStringList::lengthOfLongestLine() int SynEditStringList::lengthOfLongestLine()
{ {
if (mIndexOfLongestLine < 0) { if (mIndexOfLongestLine < 0) {
@ -104,12 +120,14 @@ QString SynEditStringList::lineBreak()
return "\n"; return "\n";
} }
SynRangeState SynEditStringList::ranges(int Index) const SynRangeState& SynEditStringList::ranges(int Index)
{ {
if (Index>=0 && Index < mList.size()) { if (Index>=0 && Index < mList.size()) {
return mList[Index]->fRange; return mList[Index]->fRange;
} else } else {
return {0,0}; ListIndexOutOfBounds(Index);
}
return {0};
} }
void SynEditStringList::InsertItem(int Index, const QString &s) void SynEditStringList::InsertItem(int Index, const QString &s)
@ -147,7 +165,7 @@ void SynEditStringList::setAppendNewLineAtEOF(bool appendNewLineAtEOF)
mAppendNewLineAtEOF = appendNewLineAtEOF; mAppendNewLineAtEOF = appendNewLineAtEOF;
} }
void SynEditStringList::setRange(int Index, SynRangeState ARange) void SynEditStringList::setRange(int Index, const SynRangeState& ARange)
{ {
if (Index<0 || Index>=mList.count()) { if (Index<0 || Index>=mList.count()) {
ListIndexOutOfBounds(Index); ListIndexOutOfBounds(Index);
@ -157,36 +175,6 @@ void SynEditStringList::setRange(int Index, SynRangeState ARange)
endUpdate(); endUpdate();
} }
void SynEditStringList::setParenthesisLevel(int Index, int level)
{
if (Index<0 || Index>=mList.count()) {
ListIndexOutOfBounds(Index);
}
beginUpdate();
mList[Index]->fParenthesisLevel = level;
endUpdate();
}
void SynEditStringList::setBracketLevel(int Index, int level)
{
if (Index<0 || Index>=mList.count()) {
ListIndexOutOfBounds(Index);
}
beginUpdate();
mList[Index]->fBracketLevel = level;
endUpdate();
}
void SynEditStringList::setBraceLevel(int Index, int level)
{
if (Index<0 || Index>=mList.count()) {
ListIndexOutOfBounds(Index);
}
beginUpdate();
mList[Index]->fBraceLevel = level;
endUpdate();
}
QString SynEditStringList::getString(int Index) QString SynEditStringList::getString(int Index)
{ {
if (Index<0 || Index>=mList.count()) { if (Index<0 || Index>=mList.count()) {
@ -687,11 +675,8 @@ void SynEditStringList::invalidAllLineColumns()
SynEditStringRec::SynEditStringRec(): SynEditStringRec::SynEditStringRec():
fString(), fString(),
fObject(nullptr), fObject(nullptr),
fRange{0,0}, fRange{0,0,0,0,0,0,0},
fColumns(-1), fColumns(-1)
fParenthesisLevel(0),
fBracketLevel(0),
fBraceLevel(0)
{ {
} }

View File

@ -22,9 +22,6 @@ struct SynEditStringRec {
void * fObject; void * fObject;
SynRangeState fRange; SynRangeState fRange;
int fColumns; // int fColumns; //
int fParenthesisLevel;
int fBracketLevel;
int fBraceLevel;
public: public:
explicit SynEditStringRec(); explicit SynEditStringRec();
@ -55,13 +52,12 @@ public:
int bracketLevels(int Index); int bracketLevels(int Index);
int braceLevels(int Index); int braceLevels(int Index);
int lineColumns(int Index); int lineColumns(int Index);
int leftBraces(int Index);
int rightBraces(int Index);
int lengthOfLongestLine(); int lengthOfLongestLine();
QString lineBreak(); QString lineBreak();
SynRangeState ranges(int Index); const SynRangeState& ranges(int Index);
void setRange(int Index, SynRangeState ARange); void setRange(int Index, const SynRangeState& ARange);
void setParenthesisLevel(int Index, int level);
void setBracketLevel(int Index, int level);
void setBraceLevel(int Index, int level);
QString getString(int Index); QString getString(int Index);
int count(); int count();
void* getObject(int Index); void* getObject(int Index);

View File

@ -821,11 +821,7 @@ void SynEditTextPainter::PaintLines()
edit->mHighlighter->resetState(); edit->mHighlighter->resetState();
} else { } else {
edit->mHighlighter->setState( edit->mHighlighter->setState(
edit->mLines->ranges(vLine-2), edit->mLines->ranges(vLine-2));
edit->mLines->braceLevels(vLine-2),
edit->mLines->bracketLevels(vLine-2),
edit->mLines->parenthesisLevels(vLine-2)
);
} }
edit->mHighlighter->setLine(sLine, vLine - 1); edit->mHighlighter->setLine(sLine, vLine - 1);
// Try to concatenate as many tokens as possible to minimize the count // Try to concatenate as many tokens as possible to minimize the count
@ -860,17 +856,17 @@ void SynEditTextPainter::PaintLines()
// It's at least partially visible. Get the token attributes now. // It's at least partially visible. Get the token attributes now.
attr = edit->mHighlighter->getTokenAttribute(); attr = edit->mHighlighter->getTokenAttribute();
if (sToken == "[") { if (sToken == "[") {
GetBraceColorAttr(edit->mHighlighter->getBracketLevel(),attr); GetBraceColorAttr(edit->mHighlighter->getRangeState().bracketLevel,attr);
} else if (sToken == "]") { } else if (sToken == "]") {
GetBraceColorAttr(edit->mHighlighter->getBracketLevel()+1,attr); GetBraceColorAttr(edit->mHighlighter->getRangeState().bracketLevel+1,attr);
} else if (sToken == "(") { } else if (sToken == "(") {
GetBraceColorAttr(edit->mHighlighter->getParenthesisLevel(),attr); GetBraceColorAttr(edit->mHighlighter->getRangeState().parenthesisLevel,attr);
} else if (sToken == ")") { } else if (sToken == ")") {
GetBraceColorAttr(edit->mHighlighter->getParenthesisLevel()+1,attr); GetBraceColorAttr(edit->mHighlighter->getRangeState().parenthesisLevel+1,attr);
} else if (sToken == "{") { } else if (sToken == "{") {
GetBraceColorAttr(edit->mHighlighter->getBraceLevel(),attr); GetBraceColorAttr(edit->mHighlighter->getRangeState().braceLevel,attr);
} else if (sToken == "}") { } else if (sToken == "}") {
GetBraceColorAttr(edit->mHighlighter->getBraceLevel()+1,attr); GetBraceColorAttr(edit->mHighlighter->getRangeState().braceLevel+1,attr);
} }
AddHighlightToken(sToken, nTokenColumnsBefore - (vFirstChar - FirstCol), AddHighlightToken(sToken, nTokenColumnsBefore - (vFirstChar - FirstCol),
nTokenColumnLen, vLine,attr); nTokenColumnLen, vLine,attr);
@ -908,7 +904,7 @@ void SynEditTextPainter::PaintLines()
sFold = " ... } "; sFold = " ... } ";
nFold = edit->stringColumns(sFold,edit->mLines->lineColumns(vLine-1)); nFold = edit->stringColumns(sFold,edit->mLines->lineColumns(vLine-1));
attr = edit->mHighlighter->symbolAttribute(); attr = edit->mHighlighter->symbolAttribute();
GetBraceColorAttr(edit->mHighlighter->getBraceLevel(),attr); GetBraceColorAttr(edit->mHighlighter->getRangeState().braceLevel,attr);
AddHighlightToken(sFold,edit->mLines->lineColumns(vLine-1)+1 - (vFirstChar - FirstCol) AddHighlightToken(sFold,edit->mLines->lineColumns(vLine-1)+1 - (vFirstChar - FirstCol)
, nFold, vLine, attr); , nFold, vLine, attr);
} }

View File

@ -63,10 +63,7 @@ void SynExporter::ExportRange(PSynEditStringList ALines, BufferCoord Start, Buff
if (Start.Line == 1) if (Start.Line == 1)
mHighlighter->resetState(); mHighlighter->resetState();
else else
mHighlighter->setState(ALines->ranges(Start.Line-2), mHighlighter->setState(ALines->ranges(Start.Line-2));
ALines->braceLevels(Start.Line-2),
ALines->bracketLevels(Start.Line-2),
ALines->parenthesisLevels(Start.Line-2));
for (int i = Start.Line; i<=Stop.Line; i++) { for (int i = Start.Line; i<=Stop.Line; i++) {
QString Line = ALines->getString(i-1); QString Line = ALines->getString(i-1);
// order is important, since Start.Y might be equal to Stop.Y // order is important, since Start.Y might be equal to Stop.Y

View File

@ -373,10 +373,10 @@ bool SynEditASMHighlighter::isLastLineStringNotFinished(int state) const
SynRangeState SynEditASMHighlighter::getRangeState() const SynRangeState SynEditASMHighlighter::getRangeState() const
{ {
return {0,0}; return {0,0,0,0,0,0,0};
} }
void SynEditASMHighlighter::setState(SynRangeState , int , int , int) void SynEditASMHighlighter::setState(const SynRangeState&)
{ {
} }

View File

@ -75,7 +75,7 @@ public:
bool isLastLineCommentNotFinished(int state) const override; bool isLastLineCommentNotFinished(int state) const override;
bool isLastLineStringNotFinished(int state) const override; bool isLastLineStringNotFinished(int state) const override;
SynRangeState getRangeState() const override; SynRangeState getRangeState() const override;
void setState(SynRangeState rangeState, int braceLevel, int bracketLevel, int parenthesisLevel) override; void setState(const SynRangeState& rangeState) override;
void resetState() override; void resetState() override;
}; };

View File

@ -48,21 +48,6 @@ PSynHighlighterAttribute SynHighlighter::symbolAttribute() const
return mSymbolAttribute; return mSymbolAttribute;
} }
int SynHighlighter::getBraceLevel() const
{
return 0;
}
int SynHighlighter::getBracketLevel() const
{
return 0;
}
int SynHighlighter::getParenthesisLevel() const
{
return 0;
}
SynHighlighterTokenType SynHighlighter::getTokenType() SynHighlighterTokenType SynHighlighter::getTokenType()
{ {
return SynHighlighterTokenType::Default; return SynHighlighterTokenType::Default;
@ -223,3 +208,14 @@ SynHighlighterAttribute::SynHighlighterAttribute(const QString &name):
{ {
} }
bool SynRangeState::operator==(const SynRangeState &s2)
{
return (state == s2.state)
&& (spaceState == s2.spaceState)
&& (braceLevel == s2.braceLevel)
&& (bracketLevel == s2.bracketLevel)
&& (parenthesisLevel == s2.parenthesisLevel)
&& (leftBraces == s2.leftBraces)
&& (rightBraces == s2.rightBraces);
}

View File

@ -10,10 +10,16 @@
#include <QVector> #include <QVector>
#include "../Types.h" #include "../Types.h"
typedef struct { struct SynRangeState {
int state; int state;
int spaceState; int spaceState;
} SynRangeState; int braceLevel;
int bracketLevel;
int parenthesisLevel;
int leftBraces;
int rightBraces;
bool operator==(const SynRangeState& s2);
};
typedef int SynTokenKind; typedef int SynTokenKind;
@ -92,9 +98,6 @@ public:
virtual bool isLastLineStringNotFinished(int state) const = 0; virtual bool isLastLineStringNotFinished(int state) const = 0;
virtual bool eol() const = 0; virtual bool eol() const = 0;
virtual SynRangeState getRangeState() const = 0; virtual SynRangeState getRangeState() const = 0;
virtual int getBraceLevel() const;
virtual int getBracketLevel() const;
virtual int getParenthesisLevel() const;
virtual QString getToken() const=0; virtual QString getToken() const=0;
virtual PSynHighlighterAttribute getTokenAttribute() const=0; virtual PSynHighlighterAttribute getTokenAttribute() const=0;
virtual SynHighlighterTokenType getTokenType(); virtual SynHighlighterTokenType getTokenType();
@ -103,7 +106,7 @@ public:
virtual bool isKeyword(const QString& word); virtual bool isKeyword(const QString& word);
virtual void next() = 0; virtual void next() = 0;
virtual void nextToEol(); virtual void nextToEol();
virtual void setState(SynRangeState rangeState, int braceLevel, int bracketLevel, int parenthesisLevel) = 0; virtual void setState(const SynRangeState& rangeState) = 0;
virtual void setLine(const QString& newLine, int lineNumber) = 0; virtual void setLine(const QString& newLine, int lineNumber) = 0;
virtual void resetState() = 0; virtual void resetState() = 0;

View File

@ -155,9 +155,11 @@ SynEditCppHighlighter::SynEditCppHighlighter(): SynHighlighter()
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
mRange.spaceState = RangeState::rsUnknown; mRange.spaceState = RangeState::rsUnknown;
mParenthesisLevel = 0; mRange.braceLevel = 0;
mBracketLevel = 0; mRange.bracketLevel = 0;
mBraceLevel = 0; mRange.parenthesisLevel = 0;
mRange.leftBraces = 0;
mRange.rightBraces = 0;
mAsmStart = false; mAsmStart = false;
} }
@ -364,7 +366,13 @@ void SynEditCppHighlighter::braceCloseProc()
if (mRange.state == RangeState::rsAsmBlock) { if (mRange.state == RangeState::rsAsmBlock) {
mRange.state = rsUnknown; mRange.state = rsUnknown;
} }
mBraceLevel -= 1;
mRange.braceLevel -= 1;
if (mRange.leftBraces<=mRange.rightBraces) {
mRange.rightBraces++ ;
} else {
mRange.leftBraces--;
}
} }
void SynEditCppHighlighter::braceOpenProc() void SynEditCppHighlighter::braceOpenProc()
@ -376,7 +384,8 @@ void SynEditCppHighlighter::braceOpenProc()
mRange.state = RangeState::rsAsmBlock; mRange.state = RangeState::rsAsmBlock;
mAsmStart = true; mAsmStart = true;
} }
mBraceLevel += 1; mRange.braceLevel += 1;
mRange.leftBraces++;
} }
void SynEditCppHighlighter::colonProc() void SynEditCppHighlighter::colonProc()
@ -876,7 +885,7 @@ void SynEditCppHighlighter::roundCloseProc()
mRun += 1; mRun += 1;
mTokenId = TokenKind::Symbol; mTokenId = TokenKind::Symbol;
mExtTokenId = ExtTokenKind::RoundClose; mExtTokenId = ExtTokenKind::RoundClose;
mParenthesisLevel -= 1; mRange.parenthesisLevel--;
} }
void SynEditCppHighlighter::roundOpenProc() void SynEditCppHighlighter::roundOpenProc()
@ -884,7 +893,7 @@ void SynEditCppHighlighter::roundOpenProc()
mRun += 1; mRun += 1;
mTokenId = TokenKind::Symbol; mTokenId = TokenKind::Symbol;
mExtTokenId = ExtTokenKind::RoundOpen; mExtTokenId = ExtTokenKind::RoundOpen;
mParenthesisLevel += 1; mRange.parenthesisLevel++;
} }
void SynEditCppHighlighter::semiColonProc() void SynEditCppHighlighter::semiColonProc()
@ -946,7 +955,7 @@ void SynEditCppHighlighter::squareCloseProc()
mRun+=1; mRun+=1;
mTokenId = TokenKind::Symbol; mTokenId = TokenKind::Symbol;
mExtTokenId = ExtTokenKind::SquareClose; mExtTokenId = ExtTokenKind::SquareClose;
mBracketLevel+=1; mRange.bracketLevel--;
} }
void SynEditCppHighlighter::squareOpenProc() void SynEditCppHighlighter::squareOpenProc()
@ -954,7 +963,7 @@ void SynEditCppHighlighter::squareOpenProc()
mRun+=1; mRun+=1;
mTokenId = TokenKind::Symbol; mTokenId = TokenKind::Symbol;
mExtTokenId = ExtTokenKind::SquareOpen; mExtTokenId = ExtTokenKind::SquareOpen;
mBracketLevel +=1; mRange.bracketLevel++;
} }
void SynEditCppHighlighter::starProc() void SynEditCppHighlighter::starProc()
@ -1470,24 +1479,11 @@ void SynEditCppHighlighter::setLine(const QString &newLine, int lineNumber)
mLine = mLineString.data(); mLine = mLineString.data();
mLineNumber = lineNumber; mLineNumber = lineNumber;
mRun = 0; mRun = 0;
mRange.leftBraces = 0;
mRange.rightBraces = 0;
next(); next();
} }
int SynEditCppHighlighter::getBraceLevel() const
{
return mBraceLevel;
}
int SynEditCppHighlighter::getBracketLevel() const
{
return mBracketLevel;
}
int SynEditCppHighlighter::getParenthesisLevel() const
{
return mParenthesisLevel;
}
bool SynEditCppHighlighter::isKeyword(const QString &word) bool SynEditCppHighlighter::isKeyword(const QString &word)
{ {
return Keywords.contains(word); return Keywords.contains(word);
@ -1545,21 +1541,22 @@ SynHighlighterTokenType SynEditCppHighlighter::getTokenType()
} }
} }
void SynEditCppHighlighter::setState(SynRangeState rangeState, int braceLevel, int bracketLevel, int parenthesisLevel) void SynEditCppHighlighter::setState(const SynRangeState& rangeState)
{ {
mRange = rangeState; mRange = rangeState;
mBraceLevel = braceLevel; mRange.leftBraces = 0;
mBracketLevel = bracketLevel; mRange.rightBraces = 0;
mParenthesisLevel = parenthesisLevel;
} }
void SynEditCppHighlighter::resetState() void SynEditCppHighlighter::resetState()
{ {
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
mRange.spaceState = RangeState::rsUnknown; mRange.spaceState = RangeState::rsUnknown;
mBracketLevel = 0; mRange.braceLevel = 0;
mBraceLevel = 0; mRange.bracketLevel = 0;
mParenthesisLevel = 0; mRange.parenthesisLevel = 0;
mRange.leftBraces = 0;
mRange.rightBraces = 0;
} }
SynHighlighterClass SynEditCppHighlighter::getClass() const SynHighlighterClass SynEditCppHighlighter::getClass() const

View File

@ -130,9 +130,6 @@ private:
bool mAsmStart; bool mAsmStart;
SynRangeState mRange; SynRangeState mRange;
// SynRangeState mSpaceRange; // SynRangeState mSpaceRange;
int mParenthesisLevel;
int mBracketLevel;
int mBraceLevel;
QString mLineString; QString mLineString;
QChar* mLine; QChar* mLine;
int mLineSize; int mLineSize;
@ -173,12 +170,9 @@ public:
int getTokenPos() override; int getTokenPos() override;
void next() override; void next() override;
void setLine(const QString &newLine, int lineNumber) override; void setLine(const QString &newLine, int lineNumber) override;
int getBraceLevel() const override;
int getBracketLevel() const override;
int getParenthesisLevel() const override;
bool isKeyword(const QString &word) override; bool isKeyword(const QString &word) override;
SynHighlighterTokenType getTokenType() override; SynHighlighterTokenType getTokenType() override;
void setState(SynRangeState rangeState, int braceLevel, int bracketLevel, int parenthesisLevel) override; void setState(const SynRangeState& rangeState) override;
void resetState() override; void resetState() override;
SynHighlighterClass getClass() const override; SynHighlighterClass getClass() const override;
QString getName() const override; QString getName() const override;

View File

@ -66,10 +66,10 @@ void FunctionTooltipWidget::setIndex(int newIndex)
mIndex = newIndex; mIndex = newIndex;
} }
QStringList FunctionTooltipWidget::splitArgs(const QString &argStr) QStringList FunctionTooltipWidget::splitArgs(QString argStr)
{ {
int i = 0;
// Split up argument string by , // Split up argument string by ,
int i;
if (argStr.startsWith('(')) { if (argStr.startsWith('(')) {
i = 1; // assume it starts with ( and ends with ) i = 1; // assume it starts with ( and ends with )
} else { } else {
@ -79,51 +79,18 @@ QStringList FunctionTooltipWidget::splitArgs(const QString &argStr)
QStringList result; QStringList result;
while (i < argStr.length()) { while (i < argStr.length()) {
if ((argStr[i] == ',') || if ((argStr[i] == ',')) {
((i == argStr.length()-1) && (argStr[i] == ')'))) {
// We've found "int* a" for example // We've found "int* a" for example
QString s = argStr.mid(paramStart,i-paramStart); QString s = argStr.mid(paramStart,i-paramStart);
result.append(s);
//remove default value
int assignPos = s.indexOf('=');
if (assignPos >= 0) {
s.truncate(assignPos);
s = s.trimmed();
}
// we don't support function pointer parameters now, till we can tokenize function parameters
// {
// // Can be a function pointer. If so, scan after last )
// BracePos := LastPos(')', S);
// if (BracePos > 0) then // it's a function pointer... begin
// SpacePos := LastPos(' ', Copy(S, BracePos, MaxInt)) // start search at brace
// end else begin
// }
int spacePos = s.lastIndexOf(' '); // Cut up at last space
if (spacePos >= 0) {
args = "";
int bracketPos = s.indexOf('[');
if (bracketPos >= 0) {
args = s.mid(bracketPos);
s.truncate(bracketPos);
}
addStatement(
functionStatement,
mCurrentFile,
"", // do not override hint
s.mid(0,spacePos), // 'int*'
s.mid(spacePos+1), // a
args,
"",
functionStatement->definitionLine,
StatementKind::skParameter,
StatementScope::ssLocal,
StatementClassScope::scsNone,
true,
false);
}
paramStart = i + 1; // step over , paramStart = i + 1; // step over ,
} }
i++; i++;
} }
QString s = argStr.mid(paramStart,i-paramStart);
s=s.trimmed();
if (!s.isEmpty()) {
result.append(s);
}
return result; return result;
} }

View File

@ -30,7 +30,7 @@ public:
void setIndex(int newIndex); void setIndex(int newIndex);
signals: signals:
private: private:
QStringList splitArgs(const QString& args); QStringList splitArgs(QString args);
private: private:
QLabel* mInfoLabel; QLabel* mInfoLabel;
QLabel* mTotalLabel; QLabel* mTotalLabel;