- 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,8 +4640,37 @@ 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) {
|
||||||
|
// iterator
|
||||||
|
if (result->typeStatement
|
||||||
|
&& STLIterators.contains(result->typeStatement->command)
|
||||||
|
) {
|
||||||
|
PStatement parentScope = result->typeStatement->parentScope.lock();
|
||||||
|
if (STLContainers.contains(parentScope->fullName)) {
|
||||||
|
QString typeName=doFindFirstTemplateParamOf(fileName,result->templateParams, parentScope);
|
||||||
|
// 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 if (STLMaps.contains(parentScope->fullName)) {
|
||||||
|
QString typeName=doFindTemplateParamOf(fileName,result->templateParams,1,parentScope);
|
||||||
|
// 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;
|
PStatement typeStatement = result->effectiveTypeStatement;
|
||||||
if ((typeStatement)
|
if ((typeStatement)
|
||||||
&& STLPointers.contains(typeStatement->fullName)
|
&& STLPointers.contains(typeStatement->fullName)
|
||||||
|
@ -4645,7 +4682,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
|
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
|
||||||
else
|
else
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,previousResult->definitionString,parentScope);
|
typeName = doFindFirstTemplateParamOf(fileName,previousResult->definitionString,parentScope);
|
||||||
// qDebug()<<"typeName"<<typeName;
|
// qDebug()<<"typeName"<<typeName;
|
||||||
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
|
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
|
||||||
if (typeStatement) {
|
if (typeStatement) {
|
||||||
result = doCreateEvalType(fileName,typeStatement);
|
result = doCreateEvalType(fileName,typeStatement);
|
||||||
|
@ -4655,6 +4692,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
|
||||||
return PEvalStatement();
|
return PEvalStatement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result->pointerLevel--;
|
result->pointerLevel--;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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