refactor code
This commit is contained in:
parent
6a13d6462a
commit
ae7e914788
|
@ -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<QString> keywords;
|
||||
|
|
|
@ -159,7 +159,7 @@ QList<PStatement> 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)
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
QList<PStatement> 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,
|
||||
|
|
|
@ -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<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > >& CodeCompletionPopup::colors() const
|
||||
|
@ -881,16 +864,6 @@ const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > >&
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -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<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > >& colors() const;
|
||||
void setColors(const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue