- enhancement: Code completion for '->' operator on std iterators.
This commit is contained in:
parent
36cb8b7867
commit
4746d1b63c
1
NEWS.md
1
NEWS.md
|
@ -1,6 +1,7 @@
|
||||||
Red Panda C++ Version 2.23
|
Red Panda C++ Version 2.23
|
||||||
|
|
||||||
- fix: When selection is availalbe, Ctrl+Click shouldn't jump to declaration/definition.
|
- fix: When selection is availalbe, Ctrl+Click shouldn't jump to declaration/definition.
|
||||||
|
- enhancement: Code completion for '->' operator on std iterators.
|
||||||
|
|
||||||
Red Panda C++ Version 2.22
|
Red Panda C++ Version 2.22
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,14 @@ QString CppParser::findFirstTemplateParamOf(const QString &fileName, const QStri
|
||||||
return doFindFirstTemplateParamOf(fileName,phrase,currentScope);
|
return doFindFirstTemplateParamOf(fileName,phrase,currentScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CppParser::findTemplateParamOf(const QString &fileName, const QString &phrase, int index, const PStatement ¤tScope)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&mMutex);
|
||||||
|
if (mParsing)
|
||||||
|
return "";
|
||||||
|
return doFindTemplateParamOf(fileName,phrase,index,currentScope);
|
||||||
|
}
|
||||||
|
|
||||||
PStatement CppParser::findFunctionAt(const QString &fileName, int line)
|
PStatement CppParser::findFunctionAt(const QString &fileName, int line)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mMutex);
|
QMutexLocker locker(&mMutex);
|
||||||
|
@ -4632,27 +4640,57 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
|
||||||
false);
|
false);
|
||||||
} else if (phraseExpression[pos] == "->") {
|
} else if (phraseExpression[pos] == "->") {
|
||||||
pos++;
|
pos++;
|
||||||
// qDebug()<<"pointer level"<<result->pointerLevel;
|
|
||||||
if (result->pointerLevel==0) {
|
if (result->pointerLevel==0) {
|
||||||
PStatement typeStatement = result->effectiveTypeStatement;
|
// iterator
|
||||||
if ((typeStatement)
|
if (result->typeStatement
|
||||||
&& STLPointers.contains(typeStatement->fullName)
|
&& STLIterators.contains(result->typeStatement->command)
|
||||||
&& result->kind == EvalStatementKind::Variable
|
) {
|
||||||
&& result->baseStatement) {
|
PStatement parentScope = result->typeStatement->parentScope.lock();
|
||||||
PStatement parentScope = result->baseStatement->parentScope.lock();
|
if (STLContainers.contains(parentScope->fullName)) {
|
||||||
QString typeName;
|
QString typeName=doFindFirstTemplateParamOf(fileName,result->templateParams, parentScope);
|
||||||
if (!previousResult || previousResult->definitionString.isEmpty())
|
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
|
PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
|
||||||
else
|
if (typeStatement) {
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,previousResult->definitionString,parentScope);
|
result = doCreateEvalType(fileName,typeStatement);
|
||||||
// qDebug()<<"typeName"<<typeName;
|
result->definitionString=typeName;
|
||||||
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
|
result->kind = EvalStatementKind::Variable;
|
||||||
if (typeStatement) {
|
} else {
|
||||||
result = doCreateEvalType(fileName,typeStatement);
|
result = PEvalStatement();
|
||||||
result->definitionString=typeName;
|
}
|
||||||
result->kind = EvalStatementKind::Variable;
|
} else if (STLMaps.contains(parentScope->fullName)) {
|
||||||
} else {
|
QString typeName=doFindTemplateParamOf(fileName,result->templateParams,1,parentScope);
|
||||||
return PEvalStatement();
|
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
|
||||||
|
PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
|
||||||
|
if (typeStatement) {
|
||||||
|
result = doCreateEvalType(fileName,typeStatement);
|
||||||
|
result->definitionString=typeName;
|
||||||
|
result->kind = EvalStatementKind::Variable;
|
||||||
|
} else {
|
||||||
|
result = PEvalStatement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//smart pointer
|
||||||
|
PStatement typeStatement = result->effectiveTypeStatement;
|
||||||
|
if ((typeStatement)
|
||||||
|
&& STLPointers.contains(typeStatement->fullName)
|
||||||
|
&& result->kind == EvalStatementKind::Variable
|
||||||
|
&& result->baseStatement) {
|
||||||
|
PStatement parentScope = result->baseStatement->parentScope.lock();
|
||||||
|
QString typeName;
|
||||||
|
if (!previousResult || previousResult->definitionString.isEmpty())
|
||||||
|
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
|
||||||
|
else
|
||||||
|
typeName = doFindFirstTemplateParamOf(fileName,previousResult->definitionString,parentScope);
|
||||||
|
// qDebug()<<"typeName"<<typeName;
|
||||||
|
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
|
||||||
|
if (typeStatement) {
|
||||||
|
result = doCreateEvalType(fileName,typeStatement);
|
||||||
|
result->definitionString=typeName;
|
||||||
|
result->kind = EvalStatementKind::Variable;
|
||||||
|
} else {
|
||||||
|
return PEvalStatement();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -52,6 +52,10 @@ public:
|
||||||
QString findFirstTemplateParamOf(const QString& fileName,
|
QString findFirstTemplateParamOf(const QString& fileName,
|
||||||
const QString& phrase,
|
const QString& phrase,
|
||||||
const PStatement& currentScope);
|
const PStatement& currentScope);
|
||||||
|
QString findTemplateParamOf(const QString& fileName,
|
||||||
|
const QString& phrase,
|
||||||
|
int index,
|
||||||
|
const PStatement& currentScope);
|
||||||
PStatement findFunctionAt(const QString& fileName,
|
PStatement findFunctionAt(const QString& fileName,
|
||||||
int line);
|
int line);
|
||||||
int findLastOperator(const QString& phrase) const;
|
int findLastOperator(const QString& phrase) const;
|
||||||
|
|
|
@ -303,8 +303,10 @@ void initParser()
|
||||||
STLPointers.insert("std::shared_ptr");
|
STLPointers.insert("std::shared_ptr");
|
||||||
STLPointers.insert("std::weak_ptr");
|
STLPointers.insert("std::weak_ptr");
|
||||||
//STLPointers.insert("__gnu_cxx::__normal_iterator");
|
//STLPointers.insert("__gnu_cxx::__normal_iterator");
|
||||||
//STLPointers.insert("std::reverse_iterator");
|
// STLPointers.insert("std::reverse_iterator");
|
||||||
//STLPointers.insert("std::iterator");
|
// STLPointers.insert("std::iterator");
|
||||||
|
// STLPointers.insert("std::const_iterator");
|
||||||
|
// STLPointers.insert("std::const_reverse_iterator");
|
||||||
|
|
||||||
AutoTypes.insert("auto");
|
AutoTypes.insert("auto");
|
||||||
AutoTypes.insert("auto &");
|
AutoTypes.insert("auto &");
|
||||||
|
|
|
@ -752,6 +752,28 @@ void CodeCompletionPopup::getCompletionFor(
|
||||||
|
|
||||||
if (!classTypeStatement)
|
if (!classTypeStatement)
|
||||||
return;
|
return;
|
||||||
|
// It's a iterator
|
||||||
|
if (ownerStatement
|
||||||
|
&& ownerStatement->typeStatement
|
||||||
|
&& STLIterators.contains(ownerStatement->typeStatement->command)
|
||||||
|
&& (memberOperator == "->"
|
||||||
|
|| memberOperator == "->*")
|
||||||
|
) {
|
||||||
|
PStatement parentScope = ownerStatement->typeStatement->parentScope.lock();
|
||||||
|
if (STLContainers.contains(parentScope->fullName)) {
|
||||||
|
QString typeName=mParser->findFirstTemplateParamOf(fileName,ownerStatement->templateParams, parentScope);
|
||||||
|
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
|
||||||
|
classTypeStatement=mParser->findTypeDefinitionOf(fileName, typeName,parentScope);
|
||||||
|
if (!classTypeStatement)
|
||||||
|
return;
|
||||||
|
} else if (STLMaps.contains(parentScope->fullName)) {
|
||||||
|
QString typeName=mParser->findTemplateParamOf(fileName,ownerStatement->templateParams,1,parentScope);
|
||||||
|
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
|
||||||
|
classTypeStatement=mParser->findTypeDefinitionOf(fileName, typeName,parentScope);
|
||||||
|
if (!classTypeStatement)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
//is a smart pointer
|
//is a smart pointer
|
||||||
if (STLPointers.contains(classTypeStatement->fullName)
|
if (STLPointers.contains(classTypeStatement->fullName)
|
||||||
&& (memberOperator == "->"
|
&& (memberOperator == "->"
|
||||||
|
|
Loading…
Reference in New Issue