- 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.
This commit is contained in:
Roy Qu 2023-03-16 22:02:32 +08:00
parent f8076dd069
commit 626217f856
5 changed files with 80 additions and 47 deletions

View File

@ -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 evaluation expression in the debug panel is case insensitive.
- fix: The comboxbox to input replace text in the search 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: 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 Red Panda C++ Version 2.17

View File

@ -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->updateForStatusbarModeInfo();
pMainWindow->updateEditorActions(); 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; int y=pos.line-1;
QString s = document()->getLine(y); int x=pos.ch;
int posY = y; if (!syntaxer() || syntaxer()->language()!=QSynedit::ProgrammingLanguage::CPP)
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; return false;
s = document()->getLine(posY); if (y==0)
posX = s.length()-1; syntaxer()->resetState();
else
syntaxer()->setState(document()->getSyntaxState(y-1));
syntaxer()->setLine(document()->getLine(y),y);
// qDebug()<<x<<document()->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()<<syntaxer()->getToken()<<start<<end;
if (end>=x)
break;
state = syntaxer()->getState();
syntaxer()->next();
} }
if (s[posX] == '>' // qDebug()<<state.parenthesisLevel;
|| s[posX] == ']') { return state.parenthesisLevel>0;
bracketLevel++;
} else if (s[posX] == '<'
|| s[posX] == '[') { // bool result = false;
bracketLevel--; // QString s = document()->getLine(y);
} else if (bracketLevel==0) { // int posY = y;
switch (s[posX].unicode()) { // int posX = std::min(x,s.length()-1); // x is started from 1
case '(': // int bracketLevel=0;
return true;
case ';': // while (true) {
case '{': // while (posX < 0) {
return false; // posY--;
} // if (posY < 0)
if (!(isIdentChar(s[posX]) // return false;
|| s[posX] == ' ' // s = document()->getLine(posY);
|| s[posX] == '\t' // posX = s.length()-1;
|| s[posX] == '*' // }
|| s[posX] == '&')) // if (s[posX] == '>'
break;; // || s[posX] == ']') {
} // bracketLevel++;
posX--; // } else if (s[posX] == '<'
} // || s[posX] == '[') {
return result; // 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) void Editor::completionInsert(bool appendFunc)
@ -4188,7 +4214,6 @@ void Editor::updateFunctionTip(bool showTip)
QSynedit::BufferCoord pWordBegin, pWordEnd; QSynedit::BufferCoord pWordBegin, pWordEnd;
QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation); QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation);
int x = pWordBegin.ch-1-1; int x = pWordBegin.ch-1-1;
QString line = document()->getLine(pWordBegin.line-1); QString line = document()->getLine(pWordBegin.line-1);
bool hasPreviousWord=false; bool hasPreviousWord=false;
@ -4206,9 +4231,10 @@ void Editor::updateFunctionTip(bool showTip)
break; break;
} }
//handle class initializer
if (x >= 0 && hasPreviousWord) { if (x >= 0 && hasPreviousWord) {
QSynedit::BufferCoord pos = pWordBegin; QSynedit::BufferCoord pos = pWordBegin;
pos.ch = x+1; pos.ch = pWordBegin.ch;
QString previousWord = getPreviousWordAtPositionForSuggestion(pos); QString previousWord = getPreviousWordAtPositionForSuggestion(pos);
PStatement statement = mParser->findStatementOf( PStatement statement = mParser->findStatementOf(
@ -4779,7 +4805,7 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo
if ((p.line<1) || (p.line>document()->count())) { if ((p.line<1) || (p.line>document()->count())) {
return ""; return "";
} }
bool inFunc = testInFunc(p.ch-1,p.line-1); bool inFunc = testInFunc(p);
QString s = document()->getLine(p.line - 1); QString s = document()->getLine(p.line - 1);
int wordBegin; int wordBegin;
@ -4800,7 +4826,7 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo
else else
return ""; return "";
} else if (bracketLevel==0) { } 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 (s[wordEnd] == ',') {
if (inFunc) // in func, dont skip ',' if (inFunc) // in func, dont skip ','
break; break;

View File

@ -271,7 +271,7 @@ private:
void saveAutoBackup(); void saveAutoBackup();
void cleanAutoBackup(); void cleanAutoBackup();
bool testInFunc(int x,int y); bool testInFunc(const QSynedit::BufferCoord& pos);
void completionInsert(bool appendFunc=false); void completionInsert(bool appendFunc=false);

View File

@ -84,6 +84,7 @@ void StatementModel::clear() {
#endif #endif
} }
#ifdef QT_DEBUG
void StatementModel::dump(const QString &logFile) void StatementModel::dump(const QString &logFile)
{ {
QFile file(logFile); QFile file(logFile);
@ -93,7 +94,6 @@ void StatementModel::dump(const QString &logFile)
} }
} }
#ifdef QT_DEBUG
void StatementModel::dumpAll(const QString &logFile) void StatementModel::dumpAll(const QString &logFile)
{ {
QFile file(logFile); QFile file(logFile);
@ -104,11 +104,16 @@ void StatementModel::dumpAll(const QString &logFile)
.arg(statement->command).arg(int(statement->kind)) .arg(statement->command).arg(int(statement->kind))
.arg(statement->type).arg(statement->fullName) .arg(statement->type).arg(statement->fullName)
.arg((size_t)(statement->parentScope.lock().get())) .arg((size_t)(statement->parentScope.lock().get()))
.arg((int)statement->classScope) .arg((int)statement->accessibility)
.arg(statement->fileName) .arg(statement->fileName)
.arg(statement->line) .arg(statement->line)
.arg(statement->definitionFileName) .arg(statement->definitionFileName)
.arg(statement->definitionLine)<<endl; .arg(statement->definitionLine)<<
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
Qt::endl;
#else
endl;
#endif
} }
} }
} }

View File

@ -36,8 +36,8 @@ public:
const StatementMap& childrenStatements(const PStatement& statement = PStatement()) const; const StatementMap& childrenStatements(const PStatement& statement = PStatement()) const;
const StatementMap& childrenStatements(std::weak_ptr<Statement> statement) const; const StatementMap& childrenStatements(std::weak_ptr<Statement> statement) const;
void clear(); void clear();
void dump(const QString& logFile);
#ifdef QT_DEBUG #ifdef QT_DEBUG
void dump(const QString& logFile);
void dumpAll(const QString& logFile); void dumpAll(const QString& logFile);
#endif #endif
private: private: