- enhancement: Auto suggest keyword "operator" when define functions.

- fix: Differentiate class and constructors.
This commit is contained in:
Roy Qu 2023-02-05 21:55:23 +08:00
parent ca5916a4b1
commit 7085318197
4 changed files with 42 additions and 15 deletions

View File

@ -1,6 +1,8 @@
Red Panda C++ Version 2.11
- fix: Can't correctly handle definitions for "operator,"
- enhancement: Auto suggest keyword "operator" when define functions.
- fix: Differentiate class and constructors.
Red Panda C++ Version 2.10

View File

@ -869,7 +869,8 @@ void Editor::keyPressEvent(QKeyEvent *event)
while(currentScope && currentScope->kind==StatementKind::skBlock) {
currentScope = currentScope->parentScope.lock();
}
if (!currentScope || currentScope->kind == StatementKind::skNamespace) {
if (!currentScope || currentScope->kind == StatementKind::skNamespace
|| currentScope->kind == StatementKind::skClass) {
//may define a function
processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion(lastWord,false,CodeCompletionType::FunctionWithoutDefinition);

View File

@ -485,7 +485,16 @@ PStatement CppParser::findStatementOf(const QString &fileName, const QStringList
QMutexLocker locker(&mMutex);
if (mParsing)
return PStatement();
return findStatementOf(fileName,expression,findScopeStatement(fileName,line));
PStatement statement = findStatementOf(fileName,expression,findScopeStatement(fileName,line));
if (statement && statement->line != line
&& statement->definitionLine != line) {
PStatement parentStatement = statement->parentScope.lock();
if (parentStatement &&
(parentStatement->line == line && parentStatement->fileName == fileName)) {
return parentStatement;
}
}
return statement;
}
PStatement CppParser::findAliasedStatement(const PStatement &statement)
@ -3230,7 +3239,7 @@ void CppParser::handleStructs(bool isTypedef)
"", // args
"", // noname args
"", // values
startLine,
mTokenizer[mIndex]->line,
StatementKind::skTypedef,
getScope(),
mClassScope,
@ -3289,7 +3298,8 @@ void CppParser::handleStructs(bool isTypedef)
"", // args
"", // no name args,
"", // values
startLine,
mTokenizer[mIndex]->line,
//startLine,
StatementKind::skClass,
getScope(),
mClassScope,
@ -3313,7 +3323,8 @@ void CppParser::handleStructs(bool isTypedef)
"", // args
"", // no name args
"", // values
startLine,
mTokenizer[mIndex]->line,
//startLine,
StatementKind::skClass,
getScope(),
mClassScope,
@ -3381,7 +3392,8 @@ void CppParser::handleStructs(bool isTypedef)
"",
"",
"",
startLine,
mTokenizer[i]->line,
//startLine,
StatementKind::skClass,
getScope(),
mClassScope,
@ -3442,12 +3454,15 @@ void CppParser::handleStructs(bool isTypedef)
"",
"",
"",
startLine,
mTokenizer[mIndex]->line,
StatementKind::skBlock,
getScope(),
mClassScope,
StatementProperty::spHasDefinition);
}
if (mIndex < mTokenizer.tokenCount())
addSoloScopeLevel(firstSynonym,mTokenizer[mIndex]->line);
else
addSoloScopeLevel(firstSynonym,startLine);
// Step over {

View File

@ -829,10 +829,12 @@ void CodeCompletionPopup::getCompletionForFunctionWithoutDefinition(const QStrin
getCompletionListForTypeKeywordComplex(preWord);
PStatement scopeStatement = mCurrentScope;
//add members of current scope that not added before
while (scopeStatement && scopeStatement->kind!=StatementKind::skNamespace) {
while (scopeStatement && scopeStatement->kind!=StatementKind::skNamespace
&& scopeStatement->kind!=StatementKind::skClass) {
scopeStatement = scopeStatement->parentScope.lock();
}
if (scopeStatement) {
if (scopeStatement->kind == StatementKind::skNamespace) {
//namespace;
PStatementList namespaceStatementsList =
mParser->findNamespace(scopeStatement->fullName);
@ -841,6 +843,11 @@ void CodeCompletionPopup::getCompletionForFunctionWithoutDefinition(const QStrin
addFunctionWithoutDefinitionChildren(namespaceStatement, fileName, line);
}
}
} else {
//class
addKeyword("operator");
addFunctionWithoutDefinitionChildren(scopeStatement, fileName, line);
}
} else {
//global
addFunctionWithoutDefinitionChildren(scopeStatement, fileName, line);
@ -849,6 +856,7 @@ void CodeCompletionPopup::getCompletionForFunctionWithoutDefinition(const QStrin
if (memberOperator != "::")
return;
//the identifier to be completed is a member of variable/class
if (ownerExpression.isEmpty()) {
// start with '::', we only find in global
// add all global members and not added before
@ -879,6 +887,7 @@ void CodeCompletionPopup::getCompletionForFunctionWithoutDefinition(const QStrin
}
return;
} else if (ownerStatement->effectiveTypeStatement->kind == StatementKind::skClass) {
addKeyword("operator");
addFunctionWithoutDefinitionChildren(ownerStatement->effectiveTypeStatement, fileName, line);
}
}