basicly done

This commit is contained in:
Roy Qu 2024-03-04 18:36:46 +08:00
parent 2a18f3f47a
commit 6b891a6626
13 changed files with 87 additions and 137 deletions

View File

@ -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!='\'' ){
// 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<QString> 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<QString, QSet<QString> > scopedKeywords = syntaxer()->scopedKeywords();
keywords = scopedKeywords.value(scopeWord, QSet<QString>());
} 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<QString> 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<QString, QSet<QString> > scopedKeywords = syntaxer()->scopedKeywords();
keywords = scopedKeywords.value(scopeWord, QSet<QString>());
} 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);

View File

@ -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);

View File

@ -970,7 +970,6 @@ void QSynEditPainter::paintLines()
int lineWidth;
QList<int> glyphStartCharList = mEdit->mDocument->getGlyphStartCharList(vLine-1,sLine);
QList<int> 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.

View File

@ -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);
}

View File

@ -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();

View File

@ -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<QString> keywords() override;
bool isATT() const;
void setATT(bool newATT);
// Syntaxer interface
public:
QString commentSymbol() override;
QString blockCommentBeginSymbol() override;
QString blockCommentEndSymbol() override;

View File

@ -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<QString> keywords() override;
// SynHighlighter interface
public:
QString foldString(QString startLine) override;
const QSet<QString> &customTypeKeywords() const;
void setCustomTypeKeywords(const QSet<QString> &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;
};
}

View File

@ -1446,6 +1446,6 @@ bool GLSLSyntaxer::supportFolding()
bool GLSLSyntaxer::needsLineState()
{
return true;
}
}

View File

@ -175,24 +175,14 @@ public:
QString languageName() override;
ProgrammingLanguage language() override;
// SynHighlighter interface
public:
SyntaxState getState() const override;
// SynHighlighter interface
public:
QSet<QString> 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;
};
}

View File

@ -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<QString> keywords() override;
// SynHighlighter interface
public:
QString foldString(QString startLine) override;
const QSet<QString> &customTypeKeywords() const;
void setCustomTypeKeywords(const QSet<QString> &newCustomTypeKeywords);
// Highlighter interface
public:
bool supportBraceLevel() override;
// Syntaxer interface
public:
QMap<QString, QSet<QString> > 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;
};
}

View File

@ -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<QString> keywords() override;
// Syntaxer interface
public:
QString commentSymbol() override;
bool supportFolding() override;
bool needsLineState() override;
};
}

View File

@ -19,7 +19,6 @@
namespace QSynedit {
Syntaxer::Syntaxer() :
mEnabled(true),
mWordBreakChars{ WordBreakChars }
{
mCommentAttribute = std::make_shared<TokenAttribute>(SYNS_AttrComment,
@ -42,7 +41,7 @@ Syntaxer::Syntaxer() :
addAttribute(mSymbolAttribute);
}
const QMap<QString, PTokenAttribute>& Syntaxer::attributes() const
QMap<QString, PTokenAttribute> Syntaxer::attributes() const
{
return mAttributes;
}

View File

@ -122,7 +122,7 @@ public:
Syntaxer(const Syntaxer&)=delete;
Syntaxer& operator=(const Syntaxer&)=delete;
virtual const QMap<QString, PTokenAttribute>& attributes() const;
virtual QMap<QString, PTokenAttribute> attributes() const;
const QSet<QChar>& wordBreakChars() const;