- enhancement: Sort header completion infos by suffix-trimmed filename.

This commit is contained in:
Roy Qu 2023-03-11 19:30:56 +08:00
parent d29ec1ee0f
commit b220df600b
6 changed files with 55 additions and 25 deletions

View File

@ -1,6 +1,9 @@
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

View File

@ -1958,6 +1958,8 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
PStatement CppParser::doFindTypeDefinitionOf(const QString &fileName, const QString &aType, const PStatement &currentClass) const
{
if (aType.isEmpty())
return PStatement();
// Remove pointer stuff from type
QString s = aType; // 'Type' is a keyword
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 &currentScope) const
{
if (phrase.isEmpty())
return QString();
// Remove pointer stuff from type
QString s = phrase; // 'Type' is a keyword
int i = s.indexOf('<');
@ -4073,12 +4077,12 @@ PStatement CppParser::findStatementInScope(const QString &name, const QString &n
if (!namespaceStatementsList)
return PStatement();
foreach (const PStatement& namespaceStatement, *namespaceStatementsList) {
PStatement result=findStatementInScope(name,noNameArgs,kind,namespaceStatement);
PStatement result=doFindStatementInScope(name,noNameArgs,kind,namespaceStatement);
if (result)
return result;
}
} else {
return findStatementInScope(name,noNameArgs,kind,scope);
return doFindStatementInScope(name,noNameArgs,kind,scope);
}
return PStatement();
}
@ -4249,9 +4253,11 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName,
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) {
result->definitionString=typeName;
result = doCreateEvalType(fileName,typeStatement);
result->definitionString=typeName;
result->kind = EvalStatementKind::Variable;
} else {
result = PEvalStatement();
}
}
} else {
@ -4262,17 +4268,19 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName,
&& result->baseStatement) {
PStatement parentScope = result->baseStatement->parentScope.lock();
QString typeName;
if (result->definitionString.isEmpty())
if (!previousResult || previousResult->definitionString.isEmpty())
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
else
typeName = doFindFirstTemplateParamOf(fileName,result->definitionString,parentScope);
typeName = doFindFirstTemplateParamOf(fileName,previousResult->definitionString,parentScope);
// qDebug()<<"typeName"<<typeName;
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) {
result->definitionString=typeName;
result = doCreateEvalType(fileName,typeStatement);
result->definitionString=typeName;
result->kind = EvalStatementKind::Variable;
} else {
result = PEvalStatement();
}
}
}
@ -4398,7 +4406,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
} else if (result->kind == EvalStatementKind::Function) {
doSkipInExpression(phraseExpression,pos,"(",")");
// qDebug()<<"????"<<(result->baseStatement!=nullptr)<<(lastResult!=nullptr);
if (result->baseStatement && lastResult && lastResult->baseStatement) {
if (result->baseStatement && lastResult) {
PStatement parentScope = result->baseStatement->parentScope.lock();
if (parentScope
&& STLContainers.contains(parentScope->fullName)
@ -4407,16 +4415,20 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
//stl container methods
PStatement typeStatement = result->effectiveTypeStatement;
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);
else
typeName = doFindFirstTemplateParamOf(fileName,result->definitionString,parentScope);
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
if (!typeName.isEmpty())
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) {
result->definitionString = typeName;
result = doCreateEvalType(fileName,typeStatement);
result->definitionString = typeName;
result->kind = EvalStatementKind::Variable;
lastResult = result;
} else {
return PEvalStatement();
}
}
}
@ -4436,17 +4448,22 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
&& result->baseStatement) {
PStatement parentScope = result->baseStatement->parentScope.lock();
QString typeName;
if (result->definitionString.isEmpty())
if (!lastResult || lastResult->definitionString.isEmpty())
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
else
typeName = doFindFirstTemplateParamOf(fileName,result->definitionString,parentScope);
typeName = doFindFirstTemplateParamOf(fileName,lastResult->definitionString,parentScope);
typeStatement = doFindTypeDefinitionOf(fileName, typeName,
parentScope);
if (typeStatement) {
result->definitionString=typeName;
result = doCreateEvalType(fileName,typeStatement);
result->definitionString=typeName;
result->kind = EvalStatementKind::Variable;
lastResult = result;
} else {
return PEvalStatement();
}
} else {
return PEvalStatement();
}
}
} else if (phraseExpression[pos] == ".") {
@ -4470,16 +4487,18 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
&& result->baseStatement) {
PStatement parentScope = result->baseStatement->parentScope.lock();
QString typeName;
if (result->definitionString.isEmpty())
if (!previousResult || previousResult->definitionString.isEmpty())
typeName = doFindFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope);
else
typeName = doFindFirstTemplateParamOf(fileName,result->definitionString,parentScope);
typeName = doFindFirstTemplateParamOf(fileName,previousResult->definitionString,parentScope);
// qDebug()<<"typeName"<<typeName;
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) {
result->definitionString=typeName;
result = doCreateEvalType(fileName,typeStatement);
result->definitionString=typeName;
result->kind = EvalStatementKind::Variable;
} else {
return PEvalStatement();
}
}
} else {
@ -4864,7 +4883,7 @@ PEvalStatement CppParser::doCreateEvalType(const QString& fileName,const PStatem
return std::make_shared<EvalStatement>(
typeStatement->fullName,
EvalStatementKind::Type,
PStatement(),
typeStatement,
typeStatement,
typeStatement);
}
@ -5092,9 +5111,9 @@ int CppParser::getBracketEnd(const QString &s, int startAt) const
PStatement CppParser::doFindStatementInScope(const QString &name,
const QString &noNameArgs,
StatementKind kind,
const PStatement& scope)
const PStatement& scope) const
{
const StatementMap& statementMap =mStatementList.childrenStatements(scope);
const StatementMap& statementMap = mStatementList.childrenStatements(scope);
foreach (const PStatement& statement, statementMap.values(name)) {
if (statement->kind == kind && statement->noNameArgs == noNameArgs) {

View File

@ -497,7 +497,7 @@ private:
PStatement doFindStatementInScope(const QString& name,
const QString& noNameArgs,
StatementKind kind,
const PStatement& scope);
const PStatement& scope) const;
void internalInvalidateFile(const QString& fileName);
void internalInvalidateFiles(const QSet<QString>& files);
QSet<QString> calculateFilesToBeReparsed(const QString& fileName);

View File

@ -15,12 +15,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "cpppreprocessor.h"
#include "../utils.h"
#include <QFile>
#include <QTextCodec>
#include <QDebug>
#include <QMessageBox>
#include "../utils.h"
CppPreprocessor::CppPreprocessor()
{

View File

@ -20,6 +20,7 @@
#include <QFileInfo>
#include <QVBoxLayout>
#include <QDebug>
#include "systemconsts.h"
#include "../utils.h"
HeaderCompletionPopup::HeaderCompletionPopup(QWidget* parent):QWidget(parent)
@ -144,7 +145,10 @@ static bool sortByUsage(const PHeaderCompletionListItem& item1,const PHeaderComp
if (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;
PHeaderCompletionListItem item = std::make_shared<HeaderCompletionListItem>();
item->filename = fileName;
item->noSuffixFilename = fileInfo.baseName();
item->suffix = fileInfo.suffix();
item->itemType = type;
item->fullpath = cleanPath(dir.absoluteFilePath(fileName));
item->usageCount = mHeaderUsageCounts.value(item->fullpath,0);

View File

@ -31,6 +31,8 @@ enum class HeaderCompletionListItemType {
struct HeaderCompletionListItem {
QString filename;
QString fullpath;
QString suffix;
QString noSuffixFilename;
bool isFolder;
int usageCount;
HeaderCompletionListItemType itemType;