diff --git a/NEWS.md b/NEWS.md index 326d6127..0771323d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 7169cc7e..9c5af808 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -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); diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 4e6e9f04..6c8ff4d3 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -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,13 +3454,16 @@ void CppParser::handleStructs(bool isTypedef) "", "", "", - startLine, + mTokenizer[mIndex]->line, StatementKind::skBlock, getScope(), mClassScope, StatementProperty::spHasDefinition); } - addSoloScopeLevel(firstSynonym,startLine); + if (mIndex < mTokenizer.tokenCount()) + addSoloScopeLevel(firstSynonym,mTokenizer[mIndex]->line); + else + addSoloScopeLevel(firstSynonym,startLine); // Step over { if ((mIndex < mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text.front() == '{')) diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index 489e5881..70962f40 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -829,17 +829,24 @@ 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) { - //namespace; - PStatementList namespaceStatementsList = - mParser->findNamespace(scopeStatement->fullName); - if (namespaceStatementsList) { - foreach (const PStatement& namespaceStatement, *namespaceStatementsList) { - addFunctionWithoutDefinitionChildren(namespaceStatement, fileName, line); + if (scopeStatement->kind == StatementKind::skNamespace) { + //namespace; + PStatementList namespaceStatementsList = + mParser->findNamespace(scopeStatement->fullName); + if (namespaceStatementsList) { + foreach (const PStatement& namespaceStatement, *namespaceStatementsList) { + addFunctionWithoutDefinitionChildren(namespaceStatement, fileName, line); + } } + } else { + //class + addKeyword("operator"); + addFunctionWithoutDefinitionChildren(scopeStatement, fileName, line); } } else { //global @@ -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); } }