From 626217f8565bbd612535ecb6c0a3bccc2926e105 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 16 Mar 2023 22:02:32 +0800 Subject: [PATCH] - fix: Don't show completion info when input parameters for function definitions. - fix: Don't show function info tips when typing class variable definitions. - fix: Compare error in debug mode. --- NEWS.md | 2 + RedPandaIDE/editor.cpp | 110 ++++++++++++++++---------- RedPandaIDE/editor.h | 2 +- RedPandaIDE/parser/statementmodel.cpp | 11 ++- RedPandaIDE/parser/statementmodel.h | 2 +- 5 files changed, 80 insertions(+), 47 deletions(-) diff --git a/NEWS.md b/NEWS.md index 63b4635f..afc51503 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,6 +18,8 @@ Red Panda C++ Version 2.18 - fix: The comboxbox to input evaluation expression in the debug panel is case insensitive. - fix: The comboxbox to input replace text in the search panel is case insensitive. - fix: None initialized std::vector is not correctly displayed in the gdb of the gcc distributed with redpanda-c++ (Windows 64bit). + - fix: Don't show completion info when input parameters for function definitions. + - fix: Don't show function info tips when typing class variable definitions. Red Panda C++ Version 2.17 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 65f9c0db..2f6a9e11 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1780,7 +1780,7 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes) } } - if (changes.testFlag(QSynedit::scInsertMode) | changes.testFlag(QSynedit::scReadOnly)) + if (changes.testFlag(QSynedit::scInsertMode) || changes.testFlag(QSynedit::scReadOnly)) pMainWindow->updateForStatusbarModeInfo(); pMainWindow->updateEditorActions(); @@ -3573,45 +3573,71 @@ void Editor::cleanAutoBackup() } } -bool Editor::testInFunc(int x, int y) +bool Editor::testInFunc(const QSynedit::BufferCoord& pos) { - bool result = false; - QString s = document()->getLine(y); - int posY = y; - int posX = std::min(x,s.length()-1); // x is started from 1 - int bracketLevel=0; - while (true) { - while (posX < 0) { - posY--; - if (posY < 0) - return false; - s = document()->getLine(posY); - posX = s.length()-1; - } - if (s[posX] == '>' - || s[posX] == ']') { - bracketLevel++; - } else if (s[posX] == '<' - || s[posX] == '[') { - bracketLevel--; - } else if (bracketLevel==0) { - switch (s[posX].unicode()) { - case '(': - return true; - case ';': - case '{': - return false; - } - if (!(isIdentChar(s[posX]) - || s[posX] == ' ' - || s[posX] == '\t' - || s[posX] == '*' - || s[posX] == '&')) - break;; - } - posX--; + int y=pos.line-1; + int x=pos.ch; + if (!syntaxer() || syntaxer()->language()!=QSynedit::ProgrammingLanguage::CPP) + return false; + if (y==0) + syntaxer()->resetState(); + else + syntaxer()->setState(document()->getSyntaxState(y-1)); + syntaxer()->setLine(document()->getLine(y),y); +// qDebug()<getLine(y).length(); + QSynedit::SyntaxState state = syntaxer()->getState(); + while(!syntaxer()->eol()) { + int start = syntaxer()->getTokenPos(); + QString token = syntaxer()->getToken(); + int end = start + token.length(); +// qDebug()<getToken()<=x) + break; + state = syntaxer()->getState(); + syntaxer()->next(); } - return result; +// qDebug()<0; + + +// bool result = false; +// QString s = document()->getLine(y); +// int posY = y; +// int posX = std::min(x,s.length()-1); // x is started from 1 +// int bracketLevel=0; + +// while (true) { +// while (posX < 0) { +// posY--; +// if (posY < 0) +// return false; +// s = document()->getLine(posY); +// posX = s.length()-1; +// } +// if (s[posX] == '>' +// || s[posX] == ']') { +// bracketLevel++; +// } else if (s[posX] == '<' +// || s[posX] == '[') { +// bracketLevel--; +// } else if (bracketLevel==0) { +// switch (s[posX].unicode()) { +// case '(': +// return true; +// case ';': +// case '{': +// return false; +// } +// if (!(isIdentChar(s[posX]) +// || s[posX] == ' ' +// || s[posX] == '\t' +// || s[posX] == '*' +// || s[posX] == '&')) +// break;; +// } +// posX--; +// } +// return result; } void Editor::completionInsert(bool appendFunc) @@ -4188,7 +4214,6 @@ void Editor::updateFunctionTip(bool showTip) QSynedit::BufferCoord pWordBegin, pWordEnd; QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation); - int x = pWordBegin.ch-1-1; QString line = document()->getLine(pWordBegin.line-1); bool hasPreviousWord=false; @@ -4206,9 +4231,10 @@ void Editor::updateFunctionTip(bool showTip) break; } + //handle class initializer if (x >= 0 && hasPreviousWord) { QSynedit::BufferCoord pos = pWordBegin; - pos.ch = x+1; + pos.ch = pWordBegin.ch; QString previousWord = getPreviousWordAtPositionForSuggestion(pos); PStatement statement = mParser->findStatementOf( @@ -4779,7 +4805,7 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo if ((p.line<1) || (p.line>document()->count())) { return ""; } - bool inFunc = testInFunc(p.ch-1,p.line-1); + bool inFunc = testInFunc(p); QString s = document()->getLine(p.line - 1); int wordBegin; @@ -4800,7 +4826,7 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo else return ""; } else if (bracketLevel==0) { - //we can't differentiate multiple definition and function parameter define here , so we don't handle ',' + //Differentiate multiple definition and function parameter define here if (s[wordEnd] == ',') { if (inFunc) // in func, dont skip ',' break; diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 487b78a3..ce8037ab 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -271,7 +271,7 @@ private: void saveAutoBackup(); void cleanAutoBackup(); - bool testInFunc(int x,int y); + bool testInFunc(const QSynedit::BufferCoord& pos); void completionInsert(bool appendFunc=false); diff --git a/RedPandaIDE/parser/statementmodel.cpp b/RedPandaIDE/parser/statementmodel.cpp index dc1e195a..c564c1cb 100644 --- a/RedPandaIDE/parser/statementmodel.cpp +++ b/RedPandaIDE/parser/statementmodel.cpp @@ -84,6 +84,7 @@ void StatementModel::clear() { #endif } +#ifdef QT_DEBUG void StatementModel::dump(const QString &logFile) { QFile file(logFile); @@ -93,7 +94,6 @@ void StatementModel::dump(const QString &logFile) } } -#ifdef QT_DEBUG void StatementModel::dumpAll(const QString &logFile) { QFile file(logFile); @@ -104,11 +104,16 @@ void StatementModel::dumpAll(const QString &logFile) .arg(statement->command).arg(int(statement->kind)) .arg(statement->type).arg(statement->fullName) .arg((size_t)(statement->parentScope.lock().get())) - .arg((int)statement->classScope) + .arg((int)statement->accessibility) .arg(statement->fileName) .arg(statement->line) .arg(statement->definitionFileName) - .arg(statement->definitionLine)<definitionLine)<< +#if QT_VERSION >= QT_VERSION_CHECK(5,15,0) + Qt::endl; +#else + endl; +#endif } } } diff --git a/RedPandaIDE/parser/statementmodel.h b/RedPandaIDE/parser/statementmodel.h index 48bca5c1..2709c244 100644 --- a/RedPandaIDE/parser/statementmodel.h +++ b/RedPandaIDE/parser/statementmodel.h @@ -36,8 +36,8 @@ public: const StatementMap& childrenStatements(const PStatement& statement = PStatement()) const; const StatementMap& childrenStatements(std::weak_ptr statement) const; void clear(); - void dump(const QString& logFile); #ifdef QT_DEBUG + void dump(const QString& logFile); void dumpAll(const QString& logFile); #endif private: