From 842e1f6cbd7eacf6f1c3621d5e836b0ebead3118 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Thu, 23 Sep 2021 12:06:26 +0800 Subject: [PATCH] - fix: editor folder process error - add: function tooltip --- RedPandaIDE/cpprefacter.cpp | 6 +- RedPandaIDE/qsynedit/SynEdit.cpp | 80 +++++++------------ RedPandaIDE/qsynedit/SynEdit.h | 2 +- RedPandaIDE/qsynedit/TextBuffer.cpp | 69 +++++++--------- RedPandaIDE/qsynedit/TextBuffer.h | 12 +-- RedPandaIDE/qsynedit/TextPainter.cpp | 20 ++--- RedPandaIDE/qsynedit/exporter/synexporter.cpp | 5 +- RedPandaIDE/qsynedit/highlighter/asm.cpp | 4 +- RedPandaIDE/qsynedit/highlighter/asm.h | 2 +- RedPandaIDE/qsynedit/highlighter/base.cpp | 26 +++--- RedPandaIDE/qsynedit/highlighter/base.h | 15 ++-- RedPandaIDE/qsynedit/highlighter/cpp.cpp | 59 +++++++------- RedPandaIDE/qsynedit/highlighter/cpp.h | 8 +- RedPandaIDE/widgets/functiontooltipwidget.cpp | 51 +++--------- RedPandaIDE/widgets/functiontooltipwidget.h | 2 +- 15 files changed, 132 insertions(+), 229 deletions(-) diff --git a/RedPandaIDE/cpprefacter.cpp b/RedPandaIDE/cpprefacter.cpp index e93a90cb..a1361177 100644 --- a/RedPandaIDE/cpprefacter.cpp +++ b/RedPandaIDE/cpprefacter.cpp @@ -79,11 +79,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile( editor.highlighter()->resetState(); } else { editor.highlighter()->setState( - editor.lines()->ranges(posY-1), - editor.lines()->braceLevels(posY-1), - editor.lines()->bracketLevels(posY-1), - editor.lines()->parenthesisLevels(posY-1) - ); + editor.lines()->ranges(posY-1)); } editor.highlighter()->setLine(line,posY); while (!editor.highlighter()->eol()) { diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 4e8da1ab..453a88f5 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -343,10 +343,7 @@ bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &XY, QString &Token, if (PosY == 0) { mHighlighter->resetState(); } else { - mHighlighter->setState(mLines->ranges(PosY-1), - mLines->braceLevels(PosY-1), - mLines->bracketLevels(PosY-1), - mLines->parenthesisLevels(PosY-1)); + mHighlighter->setState(mLines->ranges(PosY-1)); } mHighlighter->setLine(Line, PosY); PosX = XY.Char; @@ -384,10 +381,7 @@ bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &XY, QString &Toke if (PosY == 0) { mHighlighter->resetState(); } else { - mHighlighter->setState(mLines->ranges(PosY-1), - mLines->braceLevels(PosY-1), - mLines->bracketLevels(PosY-1), - mLines->parenthesisLevels(PosY-1)); + mHighlighter->setState(mLines->ranges(PosY-1)); } mHighlighter->setLine(Line, PosY); PosX = XY.Char; @@ -2858,7 +2852,7 @@ void SynEdit::updateModifiedStatus() setModified(!mUndoList->initialState()); } -int SynEdit::scanFrom(int Index) +int SynEdit::scanFrom(int Index, int canStopIndex) { SynRangeState iRange; int Result = Index; @@ -2868,27 +2862,18 @@ int SynEdit::scanFrom(int Index) if (Result == 0) { mHighlighter->resetState(); } else { - mHighlighter->setState(mLines->ranges(Result-1), - mLines->braceLevels(Result-1), - mLines->bracketLevels(Result-1), - mLines->parenthesisLevels(Result-1)); + mHighlighter->setState(mLines->ranges(Result-1)); } do { mHighlighter->setLine(mLines->getString(Result), Result); mHighlighter->nextToEol(); iRange = mHighlighter->getRangeState(); - { + if (Result > canStopIndex){ 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 } mLines->setRange(Result,iRange); - mLines->setParenthesisLevel(Result,mHighlighter->getParenthesisLevel()); - mLines->setBraceLevel(Result,mHighlighter->getBraceLevel()); - mLines->setBracketLevel(Result,mHighlighter->getBracketLevel()); Result ++ ; } while (Result < mLines->count()); Result--; @@ -2903,9 +2888,6 @@ void SynEdit::scanRanges() mHighlighter->setLine(mLines->getString(i), i); mHighlighter->nextToEol(); 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; bool useBraces = ( mCodeFolding.foldRegions.get(FoldIndex)->openSymbol == "{" && mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol == "}"); - int lastBraceLevel = 0; if (!mHighlighter) return; @@ -3083,21 +3064,8 @@ void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,P if (useBraces) { // Find an opening character on this line CurLine = mLines->getString(Line); - - int curBraceLevel = mLines->braceLevels(Line); - if (curBraceLevel > lastBraceLevel) { - for (int i=0; iaddByParts( - Parent, - TopFoldRanges, - Line + 1, - mCodeFolding.foldRegions.get(FoldIndex), - Line + 1); - parentFoldRanges = Parent->subFoldRanges; - } - } else if (curBraceLevel < lastBraceLevel) { - for (int i=0; irightBraces(Line)>0) { + for (int i=0; irightBraces(Line);i++) { // Stop the recursion if we find a closing char, and return to our parent if (Parent) { 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; ileftBraces(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 { // Find an opening character on this line CurLine = mLines->getString(Line); - mHighlighter->setState(mLines->ranges(Line), - mLines->braceLevels(Line), - mLines->bracketLevels(Line), - mLines->parenthesisLevels(Line)); + mHighlighter->setState(mLines->ranges(Line)); mHighlighter->setLine(CurLine,Line); QString token; @@ -5793,7 +5769,7 @@ void SynEdit::onLinesDeleted(int index, int count) if (mUseCodeFolding) foldOnListDeleted(index + 1, count); if (mHighlighter && mLines->count() > 0) - scanFrom(index); + scanFrom(index, index); invalidateLines(index + 1, INT_MAX); invalidateGutterLines(index + 1, INT_MAX); } @@ -5803,21 +5779,21 @@ void SynEdit::onLinesInserted(int index, int count) if (mUseCodeFolding) foldOnListInserted(index + 1, count); if (mHighlighter && mLines->count() > 0) { - int vLastScan = index; - do { - vLastScan = scanFrom(vLastScan); - vLastScan++; - } while (vLastScan < index + count) ; +// int vLastScan = index; +// do { + scanFrom(index, index+count); +// vLastScan++; +// } while (vLastScan < index + count) ; } invalidateLines(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; 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 // have already parsed the changes, so ScanFrom will return immediately. if (mLines != mOrigLines) diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 3a3b3f11..fd0ee461 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -446,7 +446,7 @@ private: void recalcCharExtent(); QString expandAtWideGlyphs(const QString& S); void updateModifiedStatus(); - int scanFrom(int Index); + int scanFrom(int Index, int canStopIndex); void scanRanges(); void uncollapse(PSynEditFoldRange FoldRange); void collapse(PSynEditFoldRange FoldRange); diff --git a/RedPandaIDE/qsynedit/TextBuffer.cpp b/RedPandaIDE/qsynedit/TextBuffer.cpp index d5acb980..f05f9ca7 100644 --- a/RedPandaIDE/qsynedit/TextBuffer.cpp +++ b/RedPandaIDE/qsynedit/TextBuffer.cpp @@ -27,7 +27,7 @@ static void ListIndexOutOfBounds(int index) { int SynEditStringList::parenthesisLevels(int Index) { if (Index>=0 && Index < mList.size()) { - return mList[Index]->fParenthesisLevel; + return mList[Index]->fRange.parenthesisLevel; } else return 0; } @@ -35,7 +35,7 @@ int SynEditStringList::parenthesisLevels(int Index) int SynEditStringList::bracketLevels(int Index) { if (Index>=0 && Index < mList.size()) { - return mList[Index]->fBracketLevel; + return mList[Index]->fRange.bracketLevel; } else return 0; } @@ -43,7 +43,7 @@ int SynEditStringList::bracketLevels(int Index) int SynEditStringList::braceLevels(int Index) { if (Index>=0 && Index < mList.size()) { - return mList[Index]->fBraceLevel; + return mList[Index]->fRange.braceLevel; } else return 0; } @@ -70,6 +70,22 @@ int SynEditStringList::lineColumns(int Index) 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() { if (mIndexOfLongestLine < 0) { @@ -104,12 +120,14 @@ QString SynEditStringList::lineBreak() return "\n"; } -SynRangeState SynEditStringList::ranges(int Index) +const SynRangeState& SynEditStringList::ranges(int Index) { if (Index>=0 && Index < mList.size()) { return mList[Index]->fRange; - } else - return {0,0}; + } else { + ListIndexOutOfBounds(Index); + } + return {0}; } void SynEditStringList::InsertItem(int Index, const QString &s) @@ -147,7 +165,7 @@ void SynEditStringList::setAppendNewLineAtEOF(bool appendNewLineAtEOF) mAppendNewLineAtEOF = appendNewLineAtEOF; } -void SynEditStringList::setRange(int Index, SynRangeState ARange) +void SynEditStringList::setRange(int Index, const SynRangeState& ARange) { if (Index<0 || Index>=mList.count()) { ListIndexOutOfBounds(Index); @@ -157,36 +175,6 @@ void SynEditStringList::setRange(int Index, SynRangeState ARange) 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) { if (Index<0 || Index>=mList.count()) { @@ -687,11 +675,8 @@ void SynEditStringList::invalidAllLineColumns() SynEditStringRec::SynEditStringRec(): fString(), fObject(nullptr), - fRange{0,0}, - fColumns(-1), - fParenthesisLevel(0), - fBracketLevel(0), - fBraceLevel(0) + fRange{0,0,0,0,0,0,0}, + fColumns(-1) { } diff --git a/RedPandaIDE/qsynedit/TextBuffer.h b/RedPandaIDE/qsynedit/TextBuffer.h index 46410b91..90ef0f61 100644 --- a/RedPandaIDE/qsynedit/TextBuffer.h +++ b/RedPandaIDE/qsynedit/TextBuffer.h @@ -22,9 +22,6 @@ struct SynEditStringRec { void * fObject; SynRangeState fRange; int fColumns; // - int fParenthesisLevel; - int fBracketLevel; - int fBraceLevel; public: explicit SynEditStringRec(); @@ -55,13 +52,12 @@ public: int bracketLevels(int Index); int braceLevels(int Index); int lineColumns(int Index); + int leftBraces(int Index); + int rightBraces(int Index); int lengthOfLongestLine(); QString lineBreak(); - SynRangeState ranges(int Index); - void setRange(int Index, SynRangeState ARange); - void setParenthesisLevel(int Index, int level); - void setBracketLevel(int Index, int level); - void setBraceLevel(int Index, int level); + const SynRangeState& ranges(int Index); + void setRange(int Index, const SynRangeState& ARange); QString getString(int Index); int count(); void* getObject(int Index); diff --git a/RedPandaIDE/qsynedit/TextPainter.cpp b/RedPandaIDE/qsynedit/TextPainter.cpp index ad8bb45f..5310b1f6 100644 --- a/RedPandaIDE/qsynedit/TextPainter.cpp +++ b/RedPandaIDE/qsynedit/TextPainter.cpp @@ -821,11 +821,7 @@ void SynEditTextPainter::PaintLines() edit->mHighlighter->resetState(); } else { edit->mHighlighter->setState( - edit->mLines->ranges(vLine-2), - edit->mLines->braceLevels(vLine-2), - edit->mLines->bracketLevels(vLine-2), - edit->mLines->parenthesisLevels(vLine-2) - ); + edit->mLines->ranges(vLine-2)); } edit->mHighlighter->setLine(sLine, vLine - 1); // 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. attr = edit->mHighlighter->getTokenAttribute(); if (sToken == "[") { - GetBraceColorAttr(edit->mHighlighter->getBracketLevel(),attr); + GetBraceColorAttr(edit->mHighlighter->getRangeState().bracketLevel,attr); } else if (sToken == "]") { - GetBraceColorAttr(edit->mHighlighter->getBracketLevel()+1,attr); + GetBraceColorAttr(edit->mHighlighter->getRangeState().bracketLevel+1,attr); } else if (sToken == "(") { - GetBraceColorAttr(edit->mHighlighter->getParenthesisLevel(),attr); + GetBraceColorAttr(edit->mHighlighter->getRangeState().parenthesisLevel,attr); } else if (sToken == ")") { - GetBraceColorAttr(edit->mHighlighter->getParenthesisLevel()+1,attr); + GetBraceColorAttr(edit->mHighlighter->getRangeState().parenthesisLevel+1,attr); } else if (sToken == "{") { - GetBraceColorAttr(edit->mHighlighter->getBraceLevel(),attr); + GetBraceColorAttr(edit->mHighlighter->getRangeState().braceLevel,attr); } else if (sToken == "}") { - GetBraceColorAttr(edit->mHighlighter->getBraceLevel()+1,attr); + GetBraceColorAttr(edit->mHighlighter->getRangeState().braceLevel+1,attr); } AddHighlightToken(sToken, nTokenColumnsBefore - (vFirstChar - FirstCol), nTokenColumnLen, vLine,attr); @@ -908,7 +904,7 @@ void SynEditTextPainter::PaintLines() sFold = " ... } "; nFold = edit->stringColumns(sFold,edit->mLines->lineColumns(vLine-1)); 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) , nFold, vLine, attr); } diff --git a/RedPandaIDE/qsynedit/exporter/synexporter.cpp b/RedPandaIDE/qsynedit/exporter/synexporter.cpp index cfcbc67f..1062081d 100644 --- a/RedPandaIDE/qsynedit/exporter/synexporter.cpp +++ b/RedPandaIDE/qsynedit/exporter/synexporter.cpp @@ -63,10 +63,7 @@ void SynExporter::ExportRange(PSynEditStringList ALines, BufferCoord Start, Buff if (Start.Line == 1) mHighlighter->resetState(); else - mHighlighter->setState(ALines->ranges(Start.Line-2), - ALines->braceLevels(Start.Line-2), - ALines->bracketLevels(Start.Line-2), - ALines->parenthesisLevels(Start.Line-2)); + mHighlighter->setState(ALines->ranges(Start.Line-2)); for (int i = Start.Line; i<=Stop.Line; i++) { QString Line = ALines->getString(i-1); // order is important, since Start.Y might be equal to Stop.Y diff --git a/RedPandaIDE/qsynedit/highlighter/asm.cpp b/RedPandaIDE/qsynedit/highlighter/asm.cpp index 694aac12..8b8d58cc 100644 --- a/RedPandaIDE/qsynedit/highlighter/asm.cpp +++ b/RedPandaIDE/qsynedit/highlighter/asm.cpp @@ -373,10 +373,10 @@ bool SynEditASMHighlighter::isLastLineStringNotFinished(int state) 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&) { } diff --git a/RedPandaIDE/qsynedit/highlighter/asm.h b/RedPandaIDE/qsynedit/highlighter/asm.h index d9f1e9b4..2c3925af 100644 --- a/RedPandaIDE/qsynedit/highlighter/asm.h +++ b/RedPandaIDE/qsynedit/highlighter/asm.h @@ -75,7 +75,7 @@ public: bool isLastLineCommentNotFinished(int state) const override; bool isLastLineStringNotFinished(int state) 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; }; diff --git a/RedPandaIDE/qsynedit/highlighter/base.cpp b/RedPandaIDE/qsynedit/highlighter/base.cpp index f25ceb31..aadb56e7 100644 --- a/RedPandaIDE/qsynedit/highlighter/base.cpp +++ b/RedPandaIDE/qsynedit/highlighter/base.cpp @@ -48,21 +48,6 @@ PSynHighlighterAttribute SynHighlighter::symbolAttribute() const return mSymbolAttribute; } -int SynHighlighter::getBraceLevel() const -{ - return 0; -} - -int SynHighlighter::getBracketLevel() const -{ - return 0; -} - -int SynHighlighter::getParenthesisLevel() const -{ - return 0; -} - SynHighlighterTokenType SynHighlighter::getTokenType() { 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); +} diff --git a/RedPandaIDE/qsynedit/highlighter/base.h b/RedPandaIDE/qsynedit/highlighter/base.h index 3f191a11..540e3779 100644 --- a/RedPandaIDE/qsynedit/highlighter/base.h +++ b/RedPandaIDE/qsynedit/highlighter/base.h @@ -10,10 +10,16 @@ #include #include "../Types.h" -typedef struct { +struct SynRangeState { int state; int spaceState; -} SynRangeState; + int braceLevel; + int bracketLevel; + int parenthesisLevel; + int leftBraces; + int rightBraces; + bool operator==(const SynRangeState& s2); +}; typedef int SynTokenKind; @@ -92,9 +98,6 @@ public: virtual bool isLastLineStringNotFinished(int state) const = 0; virtual bool eol() 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 PSynHighlighterAttribute getTokenAttribute() const=0; virtual SynHighlighterTokenType getTokenType(); @@ -103,7 +106,7 @@ public: virtual bool isKeyword(const QString& word); virtual void next() = 0; 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 resetState() = 0; diff --git a/RedPandaIDE/qsynedit/highlighter/cpp.cpp b/RedPandaIDE/qsynedit/highlighter/cpp.cpp index 2a24e9ab..972af96e 100644 --- a/RedPandaIDE/qsynedit/highlighter/cpp.cpp +++ b/RedPandaIDE/qsynedit/highlighter/cpp.cpp @@ -155,9 +155,11 @@ SynEditCppHighlighter::SynEditCppHighlighter(): SynHighlighter() mRange.state = RangeState::rsUnknown; mRange.spaceState = RangeState::rsUnknown; - mParenthesisLevel = 0; - mBracketLevel = 0; - mBraceLevel = 0; + mRange.braceLevel = 0; + mRange.bracketLevel = 0; + mRange.parenthesisLevel = 0; + mRange.leftBraces = 0; + mRange.rightBraces = 0; mAsmStart = false; } @@ -364,7 +366,13 @@ void SynEditCppHighlighter::braceCloseProc() if (mRange.state == RangeState::rsAsmBlock) { mRange.state = rsUnknown; } - mBraceLevel -= 1; + + mRange.braceLevel -= 1; + if (mRange.leftBraces<=mRange.rightBraces) { + mRange.rightBraces++ ; + } else { + mRange.leftBraces--; + } } void SynEditCppHighlighter::braceOpenProc() @@ -376,7 +384,8 @@ void SynEditCppHighlighter::braceOpenProc() mRange.state = RangeState::rsAsmBlock; mAsmStart = true; } - mBraceLevel += 1; + mRange.braceLevel += 1; + mRange.leftBraces++; } void SynEditCppHighlighter::colonProc() @@ -876,7 +885,7 @@ void SynEditCppHighlighter::roundCloseProc() mRun += 1; mTokenId = TokenKind::Symbol; mExtTokenId = ExtTokenKind::RoundClose; - mParenthesisLevel -= 1; + mRange.parenthesisLevel--; } void SynEditCppHighlighter::roundOpenProc() @@ -884,7 +893,7 @@ void SynEditCppHighlighter::roundOpenProc() mRun += 1; mTokenId = TokenKind::Symbol; mExtTokenId = ExtTokenKind::RoundOpen; - mParenthesisLevel += 1; + mRange.parenthesisLevel++; } void SynEditCppHighlighter::semiColonProc() @@ -946,7 +955,7 @@ void SynEditCppHighlighter::squareCloseProc() mRun+=1; mTokenId = TokenKind::Symbol; mExtTokenId = ExtTokenKind::SquareClose; - mBracketLevel+=1; + mRange.bracketLevel--; } void SynEditCppHighlighter::squareOpenProc() @@ -954,7 +963,7 @@ void SynEditCppHighlighter::squareOpenProc() mRun+=1; mTokenId = TokenKind::Symbol; mExtTokenId = ExtTokenKind::SquareOpen; - mBracketLevel +=1; + mRange.bracketLevel++; } void SynEditCppHighlighter::starProc() @@ -1470,24 +1479,11 @@ void SynEditCppHighlighter::setLine(const QString &newLine, int lineNumber) mLine = mLineString.data(); mLineNumber = lineNumber; mRun = 0; + mRange.leftBraces = 0; + mRange.rightBraces = 0; 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) { 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; - mBraceLevel = braceLevel; - mBracketLevel = bracketLevel; - mParenthesisLevel = parenthesisLevel; + mRange.leftBraces = 0; + mRange.rightBraces = 0; } void SynEditCppHighlighter::resetState() { mRange.state = RangeState::rsUnknown; mRange.spaceState = RangeState::rsUnknown; - mBracketLevel = 0; - mBraceLevel = 0; - mParenthesisLevel = 0; + mRange.braceLevel = 0; + mRange.bracketLevel = 0; + mRange.parenthesisLevel = 0; + mRange.leftBraces = 0; + mRange.rightBraces = 0; } SynHighlighterClass SynEditCppHighlighter::getClass() const diff --git a/RedPandaIDE/qsynedit/highlighter/cpp.h b/RedPandaIDE/qsynedit/highlighter/cpp.h index 2da3ed34..706b26b5 100644 --- a/RedPandaIDE/qsynedit/highlighter/cpp.h +++ b/RedPandaIDE/qsynedit/highlighter/cpp.h @@ -130,9 +130,6 @@ private: bool mAsmStart; SynRangeState mRange; // SynRangeState mSpaceRange; - int mParenthesisLevel; - int mBracketLevel; - int mBraceLevel; QString mLineString; QChar* mLine; int mLineSize; @@ -173,12 +170,9 @@ public: int getTokenPos() override; void next() 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; SynHighlighterTokenType getTokenType() override; - void setState(SynRangeState rangeState, int braceLevel, int bracketLevel, int parenthesisLevel) override; + void setState(const SynRangeState& rangeState) override; void resetState() override; SynHighlighterClass getClass() const override; QString getName() const override; diff --git a/RedPandaIDE/widgets/functiontooltipwidget.cpp b/RedPandaIDE/widgets/functiontooltipwidget.cpp index 1ee37a51..dd67dd41 100644 --- a/RedPandaIDE/widgets/functiontooltipwidget.cpp +++ b/RedPandaIDE/widgets/functiontooltipwidget.cpp @@ -66,10 +66,10 @@ void FunctionTooltipWidget::setIndex(int newIndex) mIndex = newIndex; } -QStringList FunctionTooltipWidget::splitArgs(const QString &argStr) +QStringList FunctionTooltipWidget::splitArgs(QString argStr) { + int i = 0; // Split up argument string by , - int i; if (argStr.startsWith('(')) { i = 1; // assume it starts with ( and ends with ) } else { @@ -79,51 +79,18 @@ QStringList FunctionTooltipWidget::splitArgs(const QString &argStr) QStringList result; while (i < argStr.length()) { - if ((argStr[i] == ',') || - ((i == argStr.length()-1) && (argStr[i] == ')'))) { + if ((argStr[i] == ',')) { // We've found "int* a" for example QString s = argStr.mid(paramStart,i-paramStart); - - //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); - } + result.append(s); paramStart = i + 1; // step over , } i++; } + QString s = argStr.mid(paramStart,i-paramStart); + s=s.trimmed(); + if (!s.isEmpty()) { + result.append(s); + } return result; } diff --git a/RedPandaIDE/widgets/functiontooltipwidget.h b/RedPandaIDE/widgets/functiontooltipwidget.h index 7a1fdf7b..015bc512 100644 --- a/RedPandaIDE/widgets/functiontooltipwidget.h +++ b/RedPandaIDE/widgets/functiontooltipwidget.h @@ -30,7 +30,7 @@ public: void setIndex(int newIndex); signals: private: - QStringList splitArgs(const QString& args); + QStringList splitArgs(QString args); private: QLabel* mInfoLabel; QLabel* mTotalLabel;