diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 4a3acdf8..8cd512f4 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -3044,13 +3044,12 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete) return onCompletionKeyPressed(event); }); mCompletionPopup->setParser(mParser); - mCompletionPopup->setUseCppKeyword(mUseCppSyntax); pMainWindow->functionTip()->hide(); mCompletionPopup->show(); // Scan the current function body - mCompletionPopup->setCurrentStatement( - mParser->findAndScanBlockAt(mFilename, caretY()) + mCompletionPopup->setCurrentScope( + mParser->findScopeStatement(mFilename, caretY()) ); QSet keywords; diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 0ee61fdc..6e1c7386 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -159,7 +159,7 @@ QList CppParser::getListOfFunctions(const QString &fileName, const Q return result; } -PStatement CppParser::findAndScanBlockAt(const QString &filename, int line) +PStatement CppParser::findScopeStatement(const QString &filename, int line) { QMutexLocker locker(&mMutex); if (mParsing) { @@ -282,7 +282,7 @@ PStatement CppParser::findStatementOf(const QString &fileName, const QString &ph QMutexLocker locker(&mMutex); if (mParsing) return PStatement(); - return findStatementOf(fileName,phrase,findAndScanBlockAt(fileName,line)); + return findStatementOf(fileName,phrase,findScopeStatement(fileName,line)); } PStatement CppParser::findStatementOf(const QString &fileName, @@ -500,7 +500,7 @@ PStatement CppParser::findStatementOf(const QString &fileName, const QStringList QMutexLocker locker(&mMutex); if (mParsing) return PStatement(); - return findStatementOf(fileName,expression,findAndScanBlockAt(fileName,line)); + return findStatementOf(fileName,expression,findScopeStatement(fileName,line)); } PStatement CppParser::findAliasedStatement(const PStatement &statement) diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index 742a9d69..0c7a9a0e 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -44,7 +44,7 @@ public: QList getListOfFunctions(const QString& fileName, const QString& phrase, int line); - PStatement findAndScanBlockAt(const QString& filename, int line); + PStatement findScopeStatement(const QString& filename, int line); PFileIncludes findFileIncludes(const QString &filename, bool deleteIt = false); QString findFirstTemplateParamOf(const QString& fileName, const QString& phrase, diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index 8c69cc6b..8b140a3f 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -46,7 +46,6 @@ CodeCompletionPopup::CodeCompletionPopup(QWidget *parent) : layout()->setMargin(0); mShowKeywords=true; - mUseCppKeyword=true; mRecordUsage = false; mSortByScope = true; @@ -507,14 +506,6 @@ void CodeCompletionPopup::getCompletionFor( foreach (const QString& keyword,customKeywords) { addKeyword(keyword); } - } else if (mUseCppKeyword) { - foreach (const QString& keyword,CppKeywords.keys()) { - addKeyword(keyword); - } - } else { - foreach (const QString& keyword,CKeywords) { - addKeyword(keyword); - } } } return; @@ -574,18 +565,10 @@ void CodeCompletionPopup::getCompletionFor( foreach (const QString& keyword,customKeywords) { addKeyword(keyword); } - } else if (mUseCppKeyword) { - foreach (const QString& keyword,CppKeywords.keys()) { - addKeyword(keyword); - } - } else { - foreach (const QString& keyword,CKeywords) { - addKeyword(keyword); - } } } - PStatement scopeStatement = mCurrentStatement; + PStatement scopeStatement = mCurrentScope; // repeat until reach global while (scopeStatement) { //add members of current scope that not added before @@ -636,7 +619,7 @@ void CodeCompletionPopup::getCompletionFor( if (memberExpression.length()>2) return; - PStatement scope = mCurrentStatement;//the scope the expression in + PStatement scope = mCurrentScope;//the scope the expression in PStatement parentTypeStatement; // QString scopeName = ownerExpression.join(""); // PStatement ownerStatement = mParser->findStatementOf( @@ -670,7 +653,7 @@ void CodeCompletionPopup::getCompletionFor( } // find the most inner scope statement that has a name (not a block) - PStatement scopeTypeStatement = mCurrentStatement; + PStatement scopeTypeStatement = mCurrentScope; while (scopeTypeStatement && !isScopeTypeKind(scopeTypeStatement->kind)) { scopeTypeStatement = scopeTypeStatement->parentScope.lock(); } @@ -866,14 +849,14 @@ void CodeCompletionPopup::showEvent(QShowEvent *) mListView->setFocus(); } -const PStatement &CodeCompletionPopup::currentStatement() const +const PStatement &CodeCompletionPopup::currentScope() const { - return mCurrentStatement; + return mCurrentScope; } -void CodeCompletionPopup::setCurrentStatement(const PStatement &newCurrentStatement) +void CodeCompletionPopup::setCurrentScope(const PStatement &newCurrentStatement) { - mCurrentStatement = newCurrentStatement; + mCurrentScope = newCurrentStatement; } const std::shared_ptr > >& CodeCompletionPopup::colors() const @@ -881,16 +864,6 @@ const std::shared_ptr > >& return mColors; } -bool CodeCompletionPopup::useCppKeyword() const -{ - return mUseCppKeyword; -} - -void CodeCompletionPopup::setUseCppKeyword(bool newUseCppKeyword) -{ - mUseCppKeyword = newUseCppKeyword; -} - bool CodeCompletionPopup::sortByScope() const { return mSortByScope; @@ -973,7 +946,7 @@ void CodeCompletionPopup::hideEvent(QHideEvent *event) mIncludedFiles.clear(); mUsings.clear(); mAddedStatements.clear(); - mCurrentStatement = nullptr; + mCurrentScope = nullptr; mParser = nullptr; QWidget::hideEvent(event); } diff --git a/RedPandaIDE/widgets/codecompletionpopup.h b/RedPandaIDE/widgets/codecompletionpopup.h index a2851d49..11abafce 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.h +++ b/RedPandaIDE/widgets/codecompletionpopup.h @@ -106,16 +106,13 @@ public: bool sortByScope() const; void setSortByScope(bool newSortByScope); - bool useCppKeyword() const; - void setUseCppKeyword(bool newUseCppKeyword); - bool hideSymbolsStartWithUnderline() const; void setHideSymbolsStartWithUnderline(bool newHideSymbolsStartWithUnderline); bool hideSymbolsStartWithTwoUnderline() const; void setHideSymbolsStartWithTwoUnderline(bool newHideSymbolsStartWithTwoUnderline); - const PStatement ¤tStatement() const; - void setCurrentStatement(const PStatement &newCurrentStatement); + const PStatement ¤tScope() const; + void setCurrentScope(const PStatement &newCurrentStatement); const std::shared_ptr > >& colors() const; void setColors(const std::shared_ptr > > &newColors); const QString &memberPhrase() const; @@ -153,14 +150,13 @@ private: CodeCompletionListItemDelegate* mDelegate; PCppParser mParser; - PStatement mCurrentStatement; + PStatement mCurrentScope; int mShowCount; bool mRecordUsage; bool mShowKeywords; bool mShowCodeSnippets; bool mIgnoreCase; bool mSortByScope; - bool mUseCppKeyword; bool mHideSymbolsStartWithUnderline; bool mHideSymbolsStartWithTwoUnderline;