- enhancement: Sort header completion infos by suffix-trimmed filename.
This commit is contained in:
parent
d29ec1ee0f
commit
b220df600b
5
NEWS.md
5
NEWS.md
|
@ -1,6 +1,9 @@
|
||||||
Red Panda C++ Version 2.18
|
Red Panda C++ Version 2.18
|
||||||
|
|
||||||
- fix: macos icon size overgrown
|
- fix: macos icon size overgrown (by RigoLigo).
|
||||||
|
- enhancement: Code completion for embedded stl containers.
|
||||||
|
- enhancement: Slightly speed up code parsing.
|
||||||
|
- enhancement: Sort header completion infos by suffix-trimmed filename.
|
||||||
|
|
||||||
Red Panda C++ Version 2.17
|
Red Panda C++ Version 2.17
|
||||||
|
|
||||||
|
|
|
@ -1958,6 +1958,8 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
|
||||||
|
|
||||||
PStatement CppParser::doFindTypeDefinitionOf(const QString &fileName, const QString &aType, const PStatement ¤tClass) const
|
PStatement CppParser::doFindTypeDefinitionOf(const QString &fileName, const QString &aType, const PStatement ¤tClass) const
|
||||||
{
|
{
|
||||||
|
if (aType.isEmpty())
|
||||||
|
return PStatement();
|
||||||
// Remove pointer stuff from type
|
// Remove pointer stuff from type
|
||||||
QString s = aType; // 'Type' is a keyword
|
QString s = aType; // 'Type' is a keyword
|
||||||
int position = s.length()-1;
|
int position = s.length()-1;
|
||||||
|
@ -1993,6 +1995,8 @@ QString CppParser::doFindFirstTemplateParamOf(const QString &fileName, const QSt
|
||||||
|
|
||||||
QString CppParser::doFindTemplateParamOf(const QString &fileName, const QString &phrase, int index, const PStatement ¤tScope) const
|
QString CppParser::doFindTemplateParamOf(const QString &fileName, const QString &phrase, int index, const PStatement ¤tScope) const
|
||||||
{
|
{
|
||||||
|
if (phrase.isEmpty())
|
||||||
|
return QString();
|
||||||
// Remove pointer stuff from type
|
// Remove pointer stuff from type
|
||||||
QString s = phrase; // 'Type' is a keyword
|
QString s = phrase; // 'Type' is a keyword
|
||||||
int i = s.indexOf('<');
|
int i = s.indexOf('<');
|
||||||
|
@ -4073,12 +4077,12 @@ PStatement CppParser::findStatementInScope(const QString &name, const QString &n
|
||||||
if (!namespaceStatementsList)
|
if (!namespaceStatementsList)
|
||||||
return PStatement();
|
return PStatement();
|
||||||
foreach (const PStatement& namespaceStatement, *namespaceStatementsList) {
|
foreach (const PStatement& namespaceStatement, *namespaceStatementsList) {
|
||||||
PStatement result=findStatementInScope(name,noNameArgs,kind,namespaceStatement);
|
PStatement result=doFindStatementInScope(name,noNameArgs,kind,namespaceStatement);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return findStatementInScope(name,noNameArgs,kind,scope);
|
return doFindStatementInScope(name,noNameArgs,kind,scope);
|
||||||
}
|
}
|
||||||
return PStatement();
|
return PStatement();
|
||||||
}
|
}
|
||||||
|
@ -4249,9 +4253,11 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName,
|
||||||
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
|
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
|
||||||
PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
|
PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
|
||||||
if (typeStatement) {
|
if (typeStatement) {
|
||||||
result->definitionString=typeName;
|
|
||||||
result = doCreateEvalType(fileName,typeStatement);
|
result = doCreateEvalType(fileName,typeStatement);
|
||||||
|
result->definitionString=typeName;
|
||||||
result->kind = EvalStatementKind::Variable;
|
result->kind = EvalStatementKind::Variable;
|
||||||
|
} else {
|
||||||
|
result = PEvalStatement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -4262,17 +4268,19 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName,
|
||||||
&& result->baseStatement) {
|
&& result->baseStatement) {
|
||||||
PStatement parentScope = result->baseStatement->parentScope.lock();
|
PStatement parentScope = result->baseStatement->parentScope.lock();
|
||||||
QString typeName;
|
QString typeName;
|
||||||
if (result->definitionString.isEmpty())
|
if (!previousResult || previousResult->definitionString.isEmpty())
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
|
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
|
||||||
else
|
else
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,result->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->definitionString=typeName;
|
|
||||||
result = doCreateEvalType(fileName,typeStatement);
|
result = doCreateEvalType(fileName,typeStatement);
|
||||||
|
result->definitionString=typeName;
|
||||||
result->kind = EvalStatementKind::Variable;
|
result->kind = EvalStatementKind::Variable;
|
||||||
|
} else {
|
||||||
|
result = PEvalStatement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4398,7 +4406,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
|
||||||
} else if (result->kind == EvalStatementKind::Function) {
|
} else if (result->kind == EvalStatementKind::Function) {
|
||||||
doSkipInExpression(phraseExpression,pos,"(",")");
|
doSkipInExpression(phraseExpression,pos,"(",")");
|
||||||
// qDebug()<<"????"<<(result->baseStatement!=nullptr)<<(lastResult!=nullptr);
|
// qDebug()<<"????"<<(result->baseStatement!=nullptr)<<(lastResult!=nullptr);
|
||||||
if (result->baseStatement && lastResult && lastResult->baseStatement) {
|
if (result->baseStatement && lastResult) {
|
||||||
PStatement parentScope = result->baseStatement->parentScope.lock();
|
PStatement parentScope = result->baseStatement->parentScope.lock();
|
||||||
if (parentScope
|
if (parentScope
|
||||||
&& STLContainers.contains(parentScope->fullName)
|
&& STLContainers.contains(parentScope->fullName)
|
||||||
|
@ -4407,16 +4415,20 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
|
||||||
//stl container methods
|
//stl container methods
|
||||||
PStatement typeStatement = result->effectiveTypeStatement;
|
PStatement typeStatement = result->effectiveTypeStatement;
|
||||||
QString typeName;
|
QString typeName;
|
||||||
if (result->definitionString.isEmpty())
|
if (!lastResult->definitionString.isEmpty())
|
||||||
|
typeName = doFindFirstTemplateParamOf(fileName,lastResult->definitionString,parentScope);
|
||||||
|
else if (lastResult->baseStatement)
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,lastResult->baseStatement->type, parentScope);
|
typeName = doFindFirstTemplateParamOf(fileName,lastResult->baseStatement->type, parentScope);
|
||||||
else
|
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,result->definitionString,parentScope);
|
|
||||||
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
|
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
|
||||||
|
if (!typeName.isEmpty())
|
||||||
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
|
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
|
||||||
if (typeStatement) {
|
if (typeStatement) {
|
||||||
result->definitionString = typeName;
|
|
||||||
result = doCreateEvalType(fileName,typeStatement);
|
result = doCreateEvalType(fileName,typeStatement);
|
||||||
|
result->definitionString = typeName;
|
||||||
result->kind = EvalStatementKind::Variable;
|
result->kind = EvalStatementKind::Variable;
|
||||||
|
lastResult = result;
|
||||||
|
} else {
|
||||||
|
return PEvalStatement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4436,17 +4448,22 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
|
||||||
&& result->baseStatement) {
|
&& result->baseStatement) {
|
||||||
PStatement parentScope = result->baseStatement->parentScope.lock();
|
PStatement parentScope = result->baseStatement->parentScope.lock();
|
||||||
QString typeName;
|
QString typeName;
|
||||||
if (result->definitionString.isEmpty())
|
if (!lastResult || lastResult->definitionString.isEmpty())
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
|
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
|
||||||
else
|
else
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,result->definitionString,parentScope);
|
typeName = doFindFirstTemplateParamOf(fileName,lastResult->definitionString,parentScope);
|
||||||
typeStatement = doFindTypeDefinitionOf(fileName, typeName,
|
typeStatement = doFindTypeDefinitionOf(fileName, typeName,
|
||||||
parentScope);
|
parentScope);
|
||||||
if (typeStatement) {
|
if (typeStatement) {
|
||||||
result->definitionString=typeName;
|
|
||||||
result = doCreateEvalType(fileName,typeStatement);
|
result = doCreateEvalType(fileName,typeStatement);
|
||||||
|
result->definitionString=typeName;
|
||||||
result->kind = EvalStatementKind::Variable;
|
result->kind = EvalStatementKind::Variable;
|
||||||
|
lastResult = result;
|
||||||
|
} else {
|
||||||
|
return PEvalStatement();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return PEvalStatement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (phraseExpression[pos] == ".") {
|
} else if (phraseExpression[pos] == ".") {
|
||||||
|
@ -4470,16 +4487,18 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
|
||||||
&& result->baseStatement) {
|
&& result->baseStatement) {
|
||||||
PStatement parentScope = result->baseStatement->parentScope.lock();
|
PStatement parentScope = result->baseStatement->parentScope.lock();
|
||||||
QString typeName;
|
QString typeName;
|
||||||
if (result->definitionString.isEmpty())
|
if (!previousResult || previousResult->definitionString.isEmpty())
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
|
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
|
||||||
else
|
else
|
||||||
typeName = doFindFirstTemplateParamOf(fileName,result->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->definitionString=typeName;
|
|
||||||
result = doCreateEvalType(fileName,typeStatement);
|
result = doCreateEvalType(fileName,typeStatement);
|
||||||
|
result->definitionString=typeName;
|
||||||
result->kind = EvalStatementKind::Variable;
|
result->kind = EvalStatementKind::Variable;
|
||||||
|
} else {
|
||||||
|
return PEvalStatement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -4864,7 +4883,7 @@ PEvalStatement CppParser::doCreateEvalType(const QString& fileName,const PStatem
|
||||||
return std::make_shared<EvalStatement>(
|
return std::make_shared<EvalStatement>(
|
||||||
typeStatement->fullName,
|
typeStatement->fullName,
|
||||||
EvalStatementKind::Type,
|
EvalStatementKind::Type,
|
||||||
PStatement(),
|
typeStatement,
|
||||||
typeStatement,
|
typeStatement,
|
||||||
typeStatement);
|
typeStatement);
|
||||||
}
|
}
|
||||||
|
@ -5092,7 +5111,7 @@ int CppParser::getBracketEnd(const QString &s, int startAt) const
|
||||||
PStatement CppParser::doFindStatementInScope(const QString &name,
|
PStatement CppParser::doFindStatementInScope(const QString &name,
|
||||||
const QString &noNameArgs,
|
const QString &noNameArgs,
|
||||||
StatementKind kind,
|
StatementKind kind,
|
||||||
const PStatement& scope)
|
const PStatement& scope) const
|
||||||
{
|
{
|
||||||
const StatementMap& statementMap = mStatementList.childrenStatements(scope);
|
const StatementMap& statementMap = mStatementList.childrenStatements(scope);
|
||||||
|
|
||||||
|
|
|
@ -497,7 +497,7 @@ private:
|
||||||
PStatement doFindStatementInScope(const QString& name,
|
PStatement doFindStatementInScope(const QString& name,
|
||||||
const QString& noNameArgs,
|
const QString& noNameArgs,
|
||||||
StatementKind kind,
|
StatementKind kind,
|
||||||
const PStatement& scope);
|
const PStatement& scope) const;
|
||||||
void internalInvalidateFile(const QString& fileName);
|
void internalInvalidateFile(const QString& fileName);
|
||||||
void internalInvalidateFiles(const QSet<QString>& files);
|
void internalInvalidateFiles(const QSet<QString>& files);
|
||||||
QSet<QString> calculateFilesToBeReparsed(const QString& fileName);
|
QSet<QString> calculateFilesToBeReparsed(const QString& fileName);
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "cpppreprocessor.h"
|
#include "cpppreprocessor.h"
|
||||||
#include "../utils.h"
|
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include "../utils.h"
|
||||||
|
|
||||||
CppPreprocessor::CppPreprocessor()
|
CppPreprocessor::CppPreprocessor()
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include "systemconsts.h"
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
|
|
||||||
HeaderCompletionPopup::HeaderCompletionPopup(QWidget* parent):QWidget(parent)
|
HeaderCompletionPopup::HeaderCompletionPopup(QWidget* parent):QWidget(parent)
|
||||||
|
@ -144,7 +145,10 @@ static bool sortByUsage(const PHeaderCompletionListItem& item1,const PHeaderComp
|
||||||
if (item1->itemType != item2->itemType)
|
if (item1->itemType != item2->itemType)
|
||||||
return item1->itemType<item2->itemType;
|
return item1->itemType<item2->itemType;
|
||||||
|
|
||||||
return item1->filename < item2->filename;
|
int code = QString::compare(item1->noSuffixFilename, item2->noSuffixFilename, PATH_SENSITIVITY);
|
||||||
|
if (code!=0)
|
||||||
|
return code<0;
|
||||||
|
return item1->suffix < item2->suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -231,6 +235,8 @@ void HeaderCompletionPopup::addFile(const QDir& dir, const QFileInfo& fileInfo,
|
||||||
return;
|
return;
|
||||||
PHeaderCompletionListItem item = std::make_shared<HeaderCompletionListItem>();
|
PHeaderCompletionListItem item = std::make_shared<HeaderCompletionListItem>();
|
||||||
item->filename = fileName;
|
item->filename = fileName;
|
||||||
|
item->noSuffixFilename = fileInfo.baseName();
|
||||||
|
item->suffix = fileInfo.suffix();
|
||||||
item->itemType = type;
|
item->itemType = type;
|
||||||
item->fullpath = cleanPath(dir.absoluteFilePath(fileName));
|
item->fullpath = cleanPath(dir.absoluteFilePath(fileName));
|
||||||
item->usageCount = mHeaderUsageCounts.value(item->fullpath,0);
|
item->usageCount = mHeaderUsageCounts.value(item->fullpath,0);
|
||||||
|
|
|
@ -31,6 +31,8 @@ enum class HeaderCompletionListItemType {
|
||||||
struct HeaderCompletionListItem {
|
struct HeaderCompletionListItem {
|
||||||
QString filename;
|
QString filename;
|
||||||
QString fullpath;
|
QString fullpath;
|
||||||
|
QString suffix;
|
||||||
|
QString noSuffixFilename;
|
||||||
bool isFolder;
|
bool isFolder;
|
||||||
int usageCount;
|
int usageCount;
|
||||||
HeaderCompletionListItemType itemType;
|
HeaderCompletionListItemType itemType;
|
||||||
|
|
Loading…
Reference in New Issue