- 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 Red Panda C++ Version 2.11
- fix: Can't correctly handle definitions for "operator," - 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 Red Panda C++ Version 2.10

View File

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

View File

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

View File

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