- enhancement: show parameter tips for class constructors

- enhancement: when there are tips showing, don't show mouse tips
This commit is contained in:
Roy Qu 2022-01-26 12:17:15 +08:00
parent 922a870724
commit 894e587f7d
7 changed files with 64 additions and 12 deletions

View File

@ -5,6 +5,8 @@ Red Panda C++ Version 0.13.4
- fix: can't show private & protected members of 'this' - fix: can't show private & protected members of 'this'
- fix: function name like 'A::B' is not correctly parsed - fix: function name like 'A::B' is not correctly parsed
- fix: static members are not correct shown after Classname + '::' - fix: static members are not correct shown after Classname + '::'
- enhancement: show parameter tips for class constructors
- enhancement: when there are tips showing, don't show mouse tips
Red Panda C++ Version 0.13.3 Red Panda C++ Version 0.13.3
- enhancement: restore editor position after rename symbol - enhancement: restore editor position after rename symbol

View File

@ -957,7 +957,9 @@ bool Editor::event(QEvent *event)
{ {
if ((event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove) if ((event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove)
&& pSettings->editor().enableTooltips() && pSettings->editor().enableTooltips()
) { && !pMainWindow->completionPopup()->isVisible()
&& !pMainWindow->functionTip()->isVisible()
&& !pMainWindow->headerCompletionPopup()->isVisible()) {
QHoverEvent *helpEvent = static_cast<QHoverEvent *>(event); QHoverEvent *helpEvent = static_cast<QHoverEvent *>(event);
BufferCoord p; BufferCoord p;
TipType reason = getTipType(helpEvent->pos(),p); TipType reason = getTipType(helpEvent->pos(),p);
@ -3366,6 +3368,39 @@ void Editor::updateFunctionTip()
QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation); QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation);
int x = pWordBegin.Char-1-1;
QString line = lines()->getString(pWordBegin.Line-1);
bool hasPreviousWord=false;
while (x>=0) {
QChar ch=line[x];
if (ch == ' ' || ch == '\t')
continue;
if (isIdentChar(ch)) {
hasPreviousWord = true;
break;
}
hasPreviousWord = false;
break;
}
if (x >= 0 && hasPreviousWord) {
BufferCoord pos = pWordBegin;
pos.Char = x+1;
QString previousWord = getPreviousWordAtPositionForSuggestion(pos);
PStatement statement = mParser->findStatementOf(
mFilename,
previousWord,
pos.Line);
if (statement) {
PStatement typeStatement = mParser->findTypeDef(statement,mFilename);
if (typeStatement && typeStatement->kind == StatementKind::skClass) {
s = previousWord;
functionNamePos = pos;
}
}
}
// qDebug()<<QString("find word at %1:%2 - '%3'") // qDebug()<<QString("find word at %1:%2 - '%3'")
// .arg(FuncStartXY.Line) // .arg(FuncStartXY.Line)
// .arg(FuncStartXY.Char) // .arg(FuncStartXY.Char)

View File

@ -5406,7 +5406,7 @@ void MainWindow::on_actionRename_Symbol_triggered()
// return; // return;
// } // }
if (isKeyword(word)) { if (isCppKeyword(word)) {
return; return;
} }

View File

@ -125,7 +125,11 @@ QList<PStatement> CppParser::getListOfFunctions(const QString &fileName, const Q
PStatement statement = findStatementOf(fileName,phrase, line); PStatement statement = findStatementOf(fileName,phrase, line);
if (!statement) if (!statement)
return result; return result;
PStatement parentScope = statement->parentScope.lock(); PStatement parentScope;
if (statement->kind == StatementKind::skClass) {
parentScope = statement;
} else
parentScope = statement->parentScope.lock();
if (parentScope && parentScope->kind == StatementKind::skNamespace) { if (parentScope && parentScope->kind == StatementKind::skNamespace) {
PStatementList namespaceStatementsList = findNamespace(parentScope->command); PStatementList namespaceStatementsList = findNamespace(parentScope->command);
if (namespaceStatementsList) { if (namespaceStatementsList) {
@ -545,6 +549,15 @@ PStatement CppParser::findTypeDefinitionOf(const QString &fileName, const QStrin
return getTypeDef(statement,fileName,aType); return getTypeDef(statement,fileName,aType);
} }
PStatement CppParser::findTypeDef(const PStatement &statement, const QString &fileName)
{
QMutexLocker locker(&mMutex);
if (mParsing)
return PStatement();
return getTypeDef(statement, fileName, "");
}
bool CppParser::freeze() bool CppParser::freeze()
{ {
QMutexLocker locker(&mMutex); QMutexLocker locker(&mMutex);
@ -3323,12 +3336,12 @@ QList<PStatement> CppParser::getListOfFunctions(const QString &fileName, int lin
QList<PStatement> result; QList<PStatement> result;
StatementMap children = mStatementList.childrenStatements(scopeStatement); StatementMap children = mStatementList.childrenStatements(scopeStatement);
for (const PStatement& child:children) { for (const PStatement& child:children) {
if ((statement->command == child->command) if (( (statement->command == child->command)
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
|| (statement->command +'A' == child->command) || (statement->command +'A' == child->command)
|| (statement->command +'W' == child->command) || (statement->command +'W' == child->command)
#endif #endif
) { ) ) {
if (line < child->line && (child->fileName == fileName)) if (line < child->line && (child->fileName == fileName))
continue; continue;
result.append(child); result.append(child);
@ -4473,7 +4486,7 @@ QString CppParser::removeArgNames(const QString &args)
if (!typeGetted) { if (!typeGetted) {
currentArg += ' ' + word; currentArg += ' ' + word;
} else { } else {
if (isKeyword(word)) { if (isCppKeyword(word)) {
currentArg += ' ' + word; currentArg += ' ' + word;
} }
} }
@ -4502,10 +4515,10 @@ QString CppParser::removeArgNames(const QString &args)
} else if (!word.trimmed().isEmpty()) { } else if (!word.trimmed().isEmpty()) {
if (!typeGetted) { if (!typeGetted) {
currentArg += ' ' + word; currentArg += ' ' + word;
if (mCppTypeKeywords.contains(word) || !isKeyword(word)) if (mCppTypeKeywords.contains(word) || !isCppKeyword(word))
typeGetted = true; typeGetted = true;
} else { } else {
if (isKeyword(word)) if (isCppKeyword(word))
currentArg += ' ' + word; currentArg += ' ' + word;
} }
word = ""; word = "";
@ -4520,7 +4533,7 @@ QString CppParser::removeArgNames(const QString &args)
if (!typeGetted) { if (!typeGetted) {
currentArg += ' ' + word; currentArg += ' ' + word;
} else { } else {
if (isKeyword(word)) { if (isCppKeyword(word)) {
currentArg += ' ' + word; currentArg += ' ' + word;
} }
} }
@ -4650,7 +4663,7 @@ bool CppParser::isNotFuncArgs(const QString &args)
return false; return false;
} }
if (isKeyword(word)) { if (isCppKeyword(word)) {
return word == "true" || word == "false" || word == "nullptr"; return word == "true" || word == "false" || word == "nullptr";
} }
PStatement statement =findStatementOf(mCurrentFile,word,getCurrentScope(),true); PStatement statement =findStatementOf(mCurrentFile,word,getCurrentScope(),true);

View File

@ -87,6 +87,8 @@ public:
PStatement findTypeDefinitionOf(const QString& fileName, PStatement findTypeDefinitionOf(const QString& fileName,
const QString& aType, const QString& aType,
const PStatement& currentClass); const PStatement& currentClass);
PStatement findTypeDef(const PStatement& statement,
const QString& fileName);
bool freeze(); // Freeze/Lock (stop reparse while searching) bool freeze(); // Freeze/Lock (stop reparse while searching)
bool freeze(const QString& serialId); // Freeze/Lock (stop reparse while searching) bool freeze(const QString& serialId); // Freeze/Lock (stop reparse while searching)
QStringList getClassesList(); QStringList getClassesList();

View File

@ -413,7 +413,7 @@ bool isSystemHeaderFile(const QString &fileName, const QSet<QString> &includePat
return false; return false;
} }
bool isKeyword(const QString &word) bool isCppKeyword(const QString &word)
{ {
return CppKeywords.contains(word); return CppKeywords.contains(word);
} }

View File

@ -255,7 +255,7 @@ QString getSystemHeaderFilename(const QString& fileName, const QStringList& incl
bool isSystemHeaderFile(const QString& fileName, const QSet<QString>& includePaths); bool isSystemHeaderFile(const QString& fileName, const QSet<QString>& includePaths);
bool isHfile(const QString& filename); bool isHfile(const QString& filename);
bool isCfile(const QString& filename); bool isCfile(const QString& filename);
bool isKeyword(const QString& word); bool isCppKeyword(const QString& word);
bool isScopeTypeKind(StatementKind kind); bool isScopeTypeKind(StatementKind kind);
MemberOperatorType getOperatorType(const QString& phrase, int index); MemberOperatorType getOperatorType(const QString& phrase, int index);
QStringList getOwnerExpressionAndMember( QStringList getOwnerExpressionAndMember(