From 6b891a6626225bd72fee5a803ab080745e9542b6 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 4 Mar 2024 18:36:46 +0800 Subject: [PATCH] basicly done --- RedPandaIDE/editor.cpp | 111 ++++++++++--------- libs/qsynedit/qsynedit/document.h | 2 +- libs/qsynedit/qsynedit/painter.cpp | 1 - libs/qsynedit/qsynedit/qsynedit.cpp | 18 +-- libs/qsynedit/qsynedit/qsynedit.h | 4 +- libs/qsynedit/qsynedit/syntaxer/asm.h | 9 +- libs/qsynedit/qsynedit/syntaxer/cpp.h | 19 +--- libs/qsynedit/qsynedit/syntaxer/glsl.cpp | 2 +- libs/qsynedit/qsynedit/syntaxer/glsl.h | 14 +-- libs/qsynedit/qsynedit/syntaxer/lua.h | 26 +---- libs/qsynedit/qsynedit/syntaxer/makefile.h | 13 +-- libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp | 3 +- libs/qsynedit/qsynedit/syntaxer/syntaxer.h | 2 +- 13 files changed, 87 insertions(+), 137 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 6d841f13..e0cfd9b6 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -287,7 +287,6 @@ void Editor::loadFile(QString filename) { checkSyntaxInBack(); } reparseTodo(); - saveAutoBackup(); } @@ -1041,11 +1040,12 @@ void Editor::keyPressEvent(QKeyEvent *event) return; case '(': { if (!selAvail()) { - QChar nextCh = nextNonSpaceChar(caretY()-1,caretX()-1); - if (!isIdentChar(nextCh) && nextCh!='(' - && nextCh!='"' && nextCh!='\'' ){ - handled = handleSymbolCompletion(ch); - } + // QChar nextCh = nextNonSpaceChar(caretY()-1,caretX()-1); + // if (!isIdentChar(nextCh) && nextCh!='(' + // && nextCh!='"' && nextCh!='\'' ){ + // handled = handleSymbolCompletion(ch); + // } + handled = handleSymbolCompletion(ch); } else { handled = handleSymbolCompletion(ch); } @@ -3513,6 +3513,57 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple } } + // Scan the current function body + QSet keywords; + + if (syntaxer()->language() != QSynedit::ProgrammingLanguage::CPP ) { + if (syntaxer()->language()==QSynedit::ProgrammingLanguage::ATTAssembly) { + if (word.startsWith(".")) + keywords = QSynedit::ASMSyntaxer::ATTDirectives; + else if (word.startsWith("%")) + keywords = QSynedit::ASMSyntaxer::ATTRegisters; + else { + keywords = QSynedit::ASMSyntaxer::InstructionNames; + } + } else { + int pos = word.lastIndexOf("."); + if (pos>=0) { + QString scopeWord=word.left(pos); + word = word.mid(pos+1); + QMap > scopedKeywords = syntaxer()->scopedKeywords(); + keywords = scopedKeywords.value(scopeWord, QSet()); + } else + keywords = syntaxer()->keywords(); + } + } else { + switch(calcParserLanguage()) { + case ParserLanguage::CPlusPlus: + foreach (const QString& keyword, CppKeywords.keys()) { + keywords.insert(keyword); + } + break; + case ParserLanguage::C: + keywords = CKeywords; + break; +#ifdef ENABLE_SDCC + case ParserLanguage::SDCC: + keywords = CKeywords; + foreach (const QString& keyword, SDCCKeywords.keys()) { + keywords.insert(keyword); + } + break; +#endif + } + if (pSettings->editor().enableCustomCTypeKeywords()) { + foreach (const QString& keyword, pSettings->editor().customCTypeKeywords()) { + keywords.insert(keyword); + } + } + } + + if (type == CodeCompletionType::KeywordsOnly && keywords.isEmpty()) + return; + mCompletionPopup->setRecordUsage(pSettings->codeCompletion().recordUsage()); mCompletionPopup->setSortByScope(pSettings->codeCompletion().sortByScope()); mCompletionPopup->setShowKeywords(pSettings->codeCompletion().showKeywords()); @@ -3566,54 +3617,6 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple } pMainWindow->functionTip()->hide(); mCompletionPopup->show(); - // Scan the current function body - QSet keywords; - - if (syntaxer()->language() != QSynedit::ProgrammingLanguage::CPP ) { - if (syntaxer()->language()==QSynedit::ProgrammingLanguage::ATTAssembly) { - if (word.startsWith(".")) - keywords = QSynedit::ASMSyntaxer::ATTDirectives; - else if (word.startsWith("%")) - keywords = QSynedit::ASMSyntaxer::ATTRegisters; - else { - keywords = QSynedit::ASMSyntaxer::InstructionNames; - } - } else { - int pos = word.lastIndexOf("."); - if (pos>=0) { - QString scopeWord=word.left(pos); - word = word.mid(pos+1); - QMap > scopedKeywords = syntaxer()->scopedKeywords(); - keywords = scopedKeywords.value(scopeWord, QSet()); - } else - keywords = syntaxer()->keywords(); - } - } else { - switch(calcParserLanguage()) { - case ParserLanguage::CPlusPlus: - foreach (const QString& keyword, CppKeywords.keys()) { - keywords.insert(keyword); - } - break; - case ParserLanguage::C: - keywords = CKeywords; - break; -#ifdef ENABLE_SDCC - case ParserLanguage::SDCC: - keywords = CKeywords; - foreach (const QString& keyword, SDCCKeywords.keys()) { - keywords.insert(keyword); - } - break; -#endif - } - if (pSettings->editor().enableCustomCTypeKeywords()) { - foreach (const QString& keyword, pSettings->editor().customCTypeKeywords()) { - keywords.insert(keyword); - } - } - } - if (word.isEmpty()) { //word=getWordAtPosition(this,caretXY(),pBeginPos,pEndPos, WordPurpose::wpCompletion); diff --git a/libs/qsynedit/qsynedit/document.h b/libs/qsynedit/qsynedit/document.h index ec66b126..b0968689 100644 --- a/libs/qsynedit/qsynedit/document.h +++ b/libs/qsynedit/qsynedit/document.h @@ -566,7 +566,7 @@ signals: void cleared(); void deleted(int startLine, int count); void inserted(int startLine, int count); - void putted(int startLine, int count); + void putted(int line); protected: QString getTextStr() const; void setUpdateState(bool Updating); diff --git a/libs/qsynedit/qsynedit/painter.cpp b/libs/qsynedit/qsynedit/painter.cpp index 62e4e017..f23644c0 100644 --- a/libs/qsynedit/qsynedit/painter.cpp +++ b/libs/qsynedit/qsynedit/painter.cpp @@ -970,7 +970,6 @@ void QSynEditPainter::paintLines() int lineWidth; QList glyphStartCharList = mEdit->mDocument->getGlyphStartCharList(vLine-1,sLine); QList glyphStartPositionsList = mEdit->mDocument->getGlyphStartPositionList(vLine-1,sLine, lineWidth); - { // Initialize highlighter with line text and range info. It is // necessary because we probably did not scan to the end of the last // line - the internal highlighter range might be wrong. diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 70c3f7b2..a3011d3f 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -328,7 +328,7 @@ bool QSynEdit::canRedo() const int QSynEdit::maxScrollWidth() const { int maxWidth = mDocument->longestLineWidth(); - if (mSyntaxer->supportFolding()) + if (useCodeFolding()) maxWidth += stringWidth(syntaxer()->foldString(""),maxWidth); if (mOptions.testFlag(eoScrollPastEol)) return std::max(maxWidth ,1); @@ -3478,7 +3478,7 @@ void QSynEdit::findSubFoldRange(PCodeFoldingRanges topFoldRanges, PCodeFoldingRa PCodeFoldingRange collapsedFold; int line = 0; QString curLine; - if (mSyntaxer->supportFolding()) + if (!useCodeFolding()) return; while (line < mDocument->count()) { // index is valid for LinesToScan and fLines @@ -6596,18 +6596,18 @@ void QSynEdit::onLinesCleared() void QSynEdit::onLinesDeleted(int line, int count) { - if (mUseCodeFolding) + if (useCodeFolding()) foldOnLinesDeleted(line + 1, count); if (mSyntaxer->needsLineState()) { reparseLines(line, mDocument->count()); } invalidateLines(line + 1, INT_MAX); -// invalidateGutterLines(index + 1, INT_MAX); + //invalidateGutterLines(line + 1, INT_MAX); } void QSynEdit::onLinesInserted(int line, int count) { - if (mUseCodeFolding) + if (useCodeFolding()) foldOnLinesInserted(line + 1, count); if (mSyntaxer->needsLineState()) { reparseLines(line, mDocument->count()); @@ -6616,7 +6616,7 @@ void QSynEdit::onLinesInserted(int line, int count) reparseLines(line, line + count); } invalidateLines(line + 1, INT_MAX); -// invalidateGutterLines(index + 1, INT_MAX); + //invalidateGutterLines(line + 1, INT_MAX); } void QSynEdit::onLinesPutted(int line) @@ -6624,9 +6624,11 @@ void QSynEdit::onLinesPutted(int line) if (mSyntaxer->needsLineState()) { reparseLines(line, mDocument->count()); invalidateLines(line + 1, INT_MAX); + //invalidateGutterLines(line +1 , INT_MAX); } else { reparseLines(line, line+1); invalidateLine( line + 1 ); + //invalidateGutterLine(line +1); } } @@ -6711,7 +6713,7 @@ void QSynEdit::setBlockEnd(BufferCoord value) value.ch = 1; } else { int maxLen = mDocument->longestLineWidth(); - if (mSyntaxer->supportFolding()) + if (useCodeFolding()) maxLen += stringWidth(mSyntaxer->foldString(""),maxLen); value.ch = minMax(value.ch, 1, maxLen+1); } @@ -6818,7 +6820,7 @@ void QSynEdit::setBlockBegin(BufferCoord value) value.ch = 1; } else { int maxLen = mDocument->longestLineWidth(); - if (mSyntaxer->supportFolding()) + if (useCodeFolding()) maxLen += stringWidth(mSyntaxer->foldString(""),maxLen); value.ch = minMax(value.ch, 1, maxLen+1); } diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index 7337b9f0..1ad9783f 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -533,7 +533,7 @@ private: QString expandAtWideGlyphs(const QString& S); void updateModifiedStatus(); void reparseLines(int startLine, int endLine); - void reparseLine(int line); + //void reparseLine(int line); void reparseDocument(); void uncollapse(PCodeFoldingRange FoldRange); void collapse(PCodeFoldingRange FoldRange); @@ -657,7 +657,7 @@ private slots: void onLinesCleared(); void onLinesDeleted(int line, int count); void onLinesInserted(int line, int count); - void onLinesPutted(int line, int count); + void onLinesPutted(int line); //void onRedoAdded(); void onScrollTimeout(); void onDraggingScrollTimeout(); diff --git a/libs/qsynedit/qsynedit/syntaxer/asm.h b/libs/qsynedit/qsynedit/syntaxer/asm.h index 31340321..4cd162ef 100644 --- a/libs/qsynedit/qsynedit/syntaxer/asm.h +++ b/libs/qsynedit/qsynedit/syntaxer/asm.h @@ -106,23 +106,18 @@ public: void next() override; void setLine(const QString &newLine, int lineNumber) override; - // SynHighlighter interface -public: bool isCommentNotFinished(int state) const override; bool isStringNotFinished(int state) const override; SyntaxState getState() const override; void setState(const SyntaxState& rangeState) override; void resetState() override; - -public: + bool supportFolding() override; + bool needsLineState() override; QSet keywords() override; bool isATT() const; void setATT(bool newATT); - - // Syntaxer interface -public: QString commentSymbol() override; QString blockCommentBeginSymbol() override; QString blockCommentEndSymbol() override; diff --git a/libs/qsynedit/qsynedit/syntaxer/cpp.h b/libs/qsynedit/qsynedit/syntaxer/cpp.h index ff3620dd..0b4fdf43 100644 --- a/libs/qsynedit/qsynedit/syntaxer/cpp.h +++ b/libs/qsynedit/qsynedit/syntaxer/cpp.h @@ -175,7 +175,7 @@ private: PTokenAttribute mGlobalVarAttribute; PTokenAttribute mLocalVarAttribute; - // SynHighligterBase interface + // Syntaxer interface public: bool isCommentNotFinished(int state) const override; bool isStringNotFinished(int state) const override; @@ -193,34 +193,21 @@ public: QString languageName() override; ProgrammingLanguage language() override; - // SynHighlighter interface -public: SyntaxState getState() const override; - - // SynHighlighter interface -public: bool isIdentChar(const QChar &ch) const override; bool isIdentStartChar(const QChar &ch) const override; - - // SynHighlighter interface -public: QSet keywords() override; - - // SynHighlighter interface -public: QString foldString(QString startLine) override; const QSet &customTypeKeywords() const; void setCustomTypeKeywords(const QSet &newCustomTypeKeywords); - // Highlighter interface -public: bool supportBraceLevel() override; - // Syntaxer interface -public: QString commentSymbol() override; QString blockCommentBeginSymbol() override; QString blockCommentEndSymbol() override; + virtual bool supportFolding() override; + virtual bool needsLineState() override; }; } diff --git a/libs/qsynedit/qsynedit/syntaxer/glsl.cpp b/libs/qsynedit/qsynedit/syntaxer/glsl.cpp index ea7a291c..939f7396 100644 --- a/libs/qsynedit/qsynedit/syntaxer/glsl.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/glsl.cpp @@ -1446,6 +1446,6 @@ bool GLSLSyntaxer::supportFolding() bool GLSLSyntaxer::needsLineState() { - + return true; } } diff --git a/libs/qsynedit/qsynedit/syntaxer/glsl.h b/libs/qsynedit/qsynedit/syntaxer/glsl.h index 66e7f4a5..7299431f 100644 --- a/libs/qsynedit/qsynedit/syntaxer/glsl.h +++ b/libs/qsynedit/qsynedit/syntaxer/glsl.h @@ -175,24 +175,14 @@ public: QString languageName() override; ProgrammingLanguage language() override; - - // SynHighlighter interface -public: SyntaxState getState() const override; - - // SynHighlighter interface -public: QSet keywords() override; - - // Highlighter interface -public: bool supportBraceLevel() override; - - // Syntaxer interface -public: QString commentSymbol() override; QString blockCommentBeginSymbol() override; QString blockCommentEndSymbol() override; + bool supportFolding() override; + bool needsLineState() override; }; } diff --git a/libs/qsynedit/qsynedit/syntaxer/lua.h b/libs/qsynedit/qsynedit/syntaxer/lua.h index fa01621e..4b22b7d0 100644 --- a/libs/qsynedit/qsynedit/syntaxer/lua.h +++ b/libs/qsynedit/qsynedit/syntaxer/lua.h @@ -138,7 +138,7 @@ private: PTokenAttribute mStringEscapeSequenceAttribute; PTokenAttribute mCharAttribute; - // SynHighligterBase interface + public: bool isCommentNotFinished(int state) const override; bool isStringNotFinished(int state) const override; @@ -154,41 +154,23 @@ public: QString languageName() override; ProgrammingLanguage language() override; - - // SynHighlighter interface -public: SyntaxState getState() const override; - - // SynHighlighter interface -public: bool isIdentChar(const QChar &ch) const override; bool isIdentStartChar(const QChar& ch) const override; - - // SynHighlighter interface -public: QSet keywords() override; - - // SynHighlighter interface -public: QString foldString(QString startLine) override; const QSet &customTypeKeywords() const; void setCustomTypeKeywords(const QSet &newCustomTypeKeywords); - - // Highlighter interface -public: bool supportBraceLevel() override; - - // Syntaxer interface -public: QMap > scopedKeywords() override; bool useXMakeLibs() const; void setUseXMakeLibs(bool newUseXMakeLibs); - - // Syntaxer interface -public: QString commentSymbol() override; QString blockCommentBeginSymbol() override; QString blockCommentEndSymbol() override; + bool supportFolding() override; + bool needsLineState() override; + }; } diff --git a/libs/qsynedit/qsynedit/syntaxer/makefile.h b/libs/qsynedit/qsynedit/syntaxer/makefile.h index cfbf797e..015afcf4 100644 --- a/libs/qsynedit/qsynedit/syntaxer/makefile.h +++ b/libs/qsynedit/qsynedit/syntaxer/makefile.h @@ -131,7 +131,6 @@ private: return (ch>='0') && (ch<='9'); } - // SynHighlighter interface public: bool eol() const override; @@ -142,23 +141,17 @@ public: int getTokenPos() override; void next() override; void setLine(const QString &newLine, int lineNumber) override; - - // SynHighlighter interface -public: bool isCommentNotFinished(int state) const override; bool isStringNotFinished(int state) const override; SyntaxState getState() const override; void setState(const SyntaxState& rangeState) override; void resetState() override; - bool isIdentChar(const QChar& ch) const override; -public: QSet keywords() override; - - - // Syntaxer interface -public: QString commentSymbol() override; + bool supportFolding() override; + bool needsLineState() override; + }; } diff --git a/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp b/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp index e48072ab..727f761d 100644 --- a/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp @@ -19,7 +19,6 @@ namespace QSynedit { Syntaxer::Syntaxer() : - mEnabled(true), mWordBreakChars{ WordBreakChars } { mCommentAttribute = std::make_shared(SYNS_AttrComment, @@ -42,7 +41,7 @@ Syntaxer::Syntaxer() : addAttribute(mSymbolAttribute); } -const QMap& Syntaxer::attributes() const +QMap Syntaxer::attributes() const { return mAttributes; } diff --git a/libs/qsynedit/qsynedit/syntaxer/syntaxer.h b/libs/qsynedit/qsynedit/syntaxer/syntaxer.h index 4ad887ef..8f1ef306 100644 --- a/libs/qsynedit/qsynedit/syntaxer/syntaxer.h +++ b/libs/qsynedit/qsynedit/syntaxer/syntaxer.h @@ -122,7 +122,7 @@ public: Syntaxer(const Syntaxer&)=delete; Syntaxer& operator=(const Syntaxer&)=delete; - virtual const QMap& attributes() const; + virtual QMap attributes() const; const QSet& wordBreakChars() const;