feat: 更好的代码填充;

This commit is contained in:
寂静的羽夏 2025-04-16 13:44:40 +08:00
parent f87c0970be
commit ef8bb9aa3a
3 changed files with 238 additions and 1292 deletions

View File

@ -349,11 +349,20 @@ QList<CodeInfoTip> AsCompletion::parseDocument() {
switch (sym.symtype) { switch (sym.symtype) {
case QAsCodeParser::SymbolType::Function: case QAsCodeParser::SymbolType::Function:
case QAsCodeParser::SymbolType::FnDef:
tip.type = CodeInfoTip::Type::Function; tip.type = CodeInfoTip::Type::Function;
tip.addinfo.insert(CodeInfoTip::RetType, tip.addinfo.insert(CodeInfoTip::RetType,
QString::fromUtf8(sym.type)); QString::fromUtf8(sym.type));
tip.addinfo.insert(CodeInfoTip::Args, tip.addinfo.insert(CodeInfoTip::Args,
QString::fromUtf8(sym.additonalInfo)); QString::fromUtf8(sym.additonalInfo));
for (auto &var : sym.children) {
CodeInfoTip va;
va.dontAddGlobal = true;
va.name = var.name;
va.nameSpace = QString::fromUtf8(var.scope.join("::"));
va.type = CodeInfoTip::Type::Variable;
ret.append(va);
}
break; break;
case QAsCodeParser::SymbolType::Enum: case QAsCodeParser::SymbolType::Enum:
tip.type = CodeInfoTip::Type::Enum; tip.type = CodeInfoTip::Type::Enum;
@ -378,7 +387,6 @@ QList<CodeInfoTip> AsCompletion::parseDocument() {
tip.type = CodeInfoTip::Type::Variable; tip.type = CodeInfoTip::Type::Variable;
break; break;
case QAsCodeParser::SymbolType::Class: case QAsCodeParser::SymbolType::Class:
case QAsCodeParser::SymbolType::FnDef:
case QAsCodeParser::SymbolType::Invalid: case QAsCodeParser::SymbolType::Invalid:
continue; continue;
} }

File diff suppressed because it is too large Load Diff

View File

@ -103,6 +103,14 @@ public:
// so, a helper function? // so, a helper function?
QList<Symbol> parseAndIntell(qsizetype offset, const QByteArray &codes); QList<Symbol> parseAndIntell(qsizetype offset, const QByteArray &codes);
public:
// utilities
static bool isConstant(int tokenType);
static bool isOperator(int tokenType);
static bool isPreOperator(int tokenType);
static bool isPostOperator(int tokenType);
static bool isAssignOperator(int tokenType);
private: private:
QList<QAsCodeParser::CodeSegment> parseScript(bool inBlock); QList<QAsCodeParser::CodeSegment> parseScript(bool inBlock);
@ -134,8 +142,6 @@ private:
sToken parseDataType(bool allowVariableType = false, sToken parseDataType(bool allowVariableType = false,
bool allowAuto = false); bool allowAuto = false);
sToken parseOneOf(int *tokens, int count); sToken parseOneOf(int *tokens, int count);
sToken parseType(bool allowConst, bool allowVariableType = false,
bool allowAuto = false);
void parseNamespace(); void parseNamespace();
@ -156,49 +162,29 @@ private:
bool isClassProp = false, bool isClassProp = false,
bool isGlobalVar = false); bool isGlobalVar = false);
QByteArray parseType(bool allowConst, bool allowVariableType = false,
bool allowAuto = false);
Symbol parseFuncDefContent(const QByteArrayList &ns,
const QByteArray &code);
QList<Symbol> parseClassContent(const QByteArrayList &ns,
const QByteArray &code);
QList<Symbol> parseStatementBlock(const QByteArrayList &ns,
const QByteArray &code, qsizetype end);
private: private:
void parseStatementBlock();
void parseStatement(); void parseStatement();
void parseClassContent();
void parseMixinContent(); void parseMixinContent();
void parseInterfaceContent(); void parseInterfaceContent();
Symbol parseFuncDefContent();
void ParseReturn();
void ParseBreak();
void ParseContinue();
void ParseTryCatch();
void ParseIf();
void ParseLambda();
CodeSegment parseFunction(bool isMethod); CodeSegment parseFunction(bool isMethod);
void ParseExpressionStatement();
void ParseListPattern();
void ParseAssignment();
void ParseAssignOperator();
void ParseSwitch();
void ParseCase();
void ParseFor();
void ParseWhile();
void ParseDoWhile();
void ParseCondition();
void ParseExpression();
void ParseExprTerm();
void ParseExprOperator();
void ParseExprPreOp();
void ParseExprPostOp();
void ParseExprValue();
Symbol parseVirtualPropertyDecl(bool isMethod, bool isInterface); Symbol parseVirtualPropertyDecl(bool isMethod, bool isInterface);
QList<Symbol> parseParameterListContent(); QList<Symbol> parseParameterListContent();
// parse but not get symbols // parse but not get symbols
void ParseTypeMod(bool isParam); void parseTypeMod(bool isParam);
void ParseFunctionCall();
void ParseInitList();
void ParseCast();
void ParseVariableAccess();
void ParseConstructCall();
void ParseConstant();
private: private:
void reset(); void reset();
@ -221,21 +207,12 @@ private:
private: private:
bool checkTemplateType(const sToken &t); bool checkTemplateType(const sToken &t);
void parseArgList(bool withParenthesis = true);
private: private:
bool findTokenAfterType(sToken &nextToken); bool findTokenAfterType(sToken &nextToken);
bool findIdentifierAfterScope(sToken &nextToken); bool findIdentifierAfterScope(sToken &nextToken);
bool isConstant(int tokenType);
bool isOperator(int tokenType);
bool isPreOperator(int tokenType);
bool isPostOperator(int tokenType);
bool isAssignOperator(int tokenType);
bool typeExist(const QString &t); bool typeExist(const QString &t);
Symbol parseFunctionDefinition();
Symbol parseInterfaceMethod(); Symbol parseInterfaceMethod();
void ParseStringConstant(); void ParseStringConstant();
@ -248,10 +225,7 @@ private:
asCScriptEngine *engine; asCScriptEngine *engine;
// size_t _curscope = 0;
QByteArray _code; QByteArray _code;
QByteArray tempString; // Used for reduzing amount of dynamic allocations
sToken _lastToken; sToken _lastToken;
size_t _sourcePos; size_t _sourcePos;