📦 更新lsp对tree-sitter的依赖
🚀 优化部分无关代码 🐛 修复`ast`的测试代码
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "debug_printer.hpp"
|
||||
#include <sstream>
|
||||
|
||||
namespace lsp::language::ast
|
||||
namespace lsp::language::ast::debug
|
||||
{
|
||||
// ===== 辅助函数实现 =====
|
||||
|
||||
@@ -249,9 +249,7 @@ namespace lsp::language::ast
|
||||
is_last_child_stack_.pop_back();
|
||||
|
||||
if (!label.empty())
|
||||
{
|
||||
DecreaseIndent();
|
||||
}
|
||||
}
|
||||
|
||||
void DebugPrinter::PrintParameter(const Parameter& param, bool is_last)
|
||||
@@ -266,14 +264,22 @@ namespace lsp::language::ast
|
||||
PrintColored(param.type->name, Color::BrightYellow);
|
||||
}
|
||||
|
||||
if (param.is_var)
|
||||
{
|
||||
os_ << " " << GetColor(Color::Magenta) << "(var)" << GetColor(Color::Reset);
|
||||
}
|
||||
|
||||
if (param.is_out)
|
||||
switch (param.mode)
|
||||
{
|
||||
case ast::ParameterMode::kNone:
|
||||
break;
|
||||
case ast::ParameterMode::kConst:
|
||||
os_ << " " << GetColor(Color::Magenta) << "(const)" << GetColor(Color::Reset);
|
||||
break;
|
||||
case ast::ParameterMode::kIn:
|
||||
os_ << " " << GetColor(Color::Magenta) << "(in)" << GetColor(Color::Reset);
|
||||
break;
|
||||
case ast::ParameterMode::kOut:
|
||||
os_ << " " << GetColor(Color::Magenta) << "(out)" << GetColor(Color::Reset);
|
||||
break;
|
||||
case ast::ParameterMode::kVar:
|
||||
os_ << " " << GetColor(Color::Magenta) << "(var)" << GetColor(Color::Reset);
|
||||
break;
|
||||
}
|
||||
|
||||
if (param.default_value)
|
||||
@@ -431,21 +437,21 @@ namespace lsp::language::ast
|
||||
PrintColored(mod_str, Color::BrightYellow);
|
||||
}
|
||||
|
||||
void DebugPrinter::PrintMethodType(MethodType type)
|
||||
void DebugPrinter::PrintMethodType(MethodKind kind)
|
||||
{
|
||||
const char* type_str = "";
|
||||
switch (type)
|
||||
switch (kind)
|
||||
{
|
||||
case MethodType::kNormal:
|
||||
type_str = "normal";
|
||||
case MethodKind::kOrdinary:
|
||||
type_str = "ordinary";
|
||||
break;
|
||||
case MethodType::kConstructor:
|
||||
case MethodKind::kConstructor:
|
||||
type_str = "constructor";
|
||||
break;
|
||||
case MethodType::kDestructor:
|
||||
case MethodKind::kDestructor:
|
||||
type_str = "destructor";
|
||||
break;
|
||||
case MethodType::kOperatorOverload:
|
||||
case MethodKind::kOperator:
|
||||
type_str = "operator";
|
||||
break;
|
||||
}
|
||||
@@ -573,16 +579,14 @@ namespace lsp::language::ast
|
||||
{
|
||||
if (!source_code_)
|
||||
return "";
|
||||
if (loc.start_byte >= source_code_->length())
|
||||
if (loc.start_offset >= source_code_->length())
|
||||
return "";
|
||||
|
||||
size_t length = loc.end_byte - loc.start_byte;
|
||||
if (loc.start_byte + length > source_code_->length())
|
||||
{
|
||||
length = source_code_->length() - loc.start_byte;
|
||||
}
|
||||
size_t length = loc.end_offset - loc.start_offset;
|
||||
if (loc.start_offset + length > source_code_->length())
|
||||
length = source_code_->length() - loc.start_offset;
|
||||
|
||||
return source_code_->substr(loc.start_byte, length);
|
||||
return source_code_->substr(loc.start_offset, length);
|
||||
}
|
||||
|
||||
std::string DebugPrinter::GetNodeKindName(NodeKind kind) const
|
||||
@@ -912,18 +916,16 @@ namespace lsp::language::ast
|
||||
os_ << "\n";
|
||||
}
|
||||
|
||||
if (node.method_type != MethodType::kNormal)
|
||||
if (node.method_kind != MethodKind::kOrdinary)
|
||||
{
|
||||
PrintIndent();
|
||||
PrintColored("Type: ", Color::Yellow);
|
||||
PrintMethodType(node.method_type);
|
||||
PrintMethodType(node.method_kind);
|
||||
os_ << "\n";
|
||||
}
|
||||
|
||||
if (node.is_class_method)
|
||||
{
|
||||
if (node.is_static)
|
||||
PrintKeyValue("ClassMethod", true);
|
||||
}
|
||||
|
||||
if (!node.parameters.empty())
|
||||
{
|
||||
@@ -1033,11 +1035,11 @@ namespace lsp::language::ast
|
||||
os_ << "\n";
|
||||
}
|
||||
|
||||
if (node.method_type != MethodType::kNormal)
|
||||
if (node.method_kind != MethodKind::kOrdinary)
|
||||
{
|
||||
PrintIndent();
|
||||
PrintColored("Type: ", Color::Yellow);
|
||||
PrintMethodType(node.method_type);
|
||||
PrintMethodType(node.method_kind);
|
||||
os_ << "\n";
|
||||
}
|
||||
|
||||
@@ -1090,7 +1092,7 @@ namespace lsp::language::ast
|
||||
{
|
||||
PrintIndent();
|
||||
PrintColored("Literal: ", Color::BrightCyan);
|
||||
PrintColored("\"" + node.name + "\"", Color::Green);
|
||||
PrintColored("\"" + node.value + "\"", Color::Green);
|
||||
os_ << " (";
|
||||
PrintLiteralKind(node.literal_kind);
|
||||
os_ << ")";
|
||||
@@ -1160,7 +1162,7 @@ namespace lsp::language::ast
|
||||
const auto& elem = node.elements[i];
|
||||
bool is_last = (i == node.elements.size() - 1);
|
||||
|
||||
if (elem.key.has_value())
|
||||
if (elem.key)
|
||||
{
|
||||
PrintIndent();
|
||||
PrintColored("Element (key-value):", Color::Yellow);
|
||||
@@ -1194,7 +1196,7 @@ namespace lsp::language::ast
|
||||
|
||||
IncreaseIndent();
|
||||
|
||||
PrintExpression(node.function.get(), "Function", node.arguments.empty());
|
||||
PrintExpression(node.callee.get(), "Function", node.arguments.empty());
|
||||
|
||||
if (!node.arguments.empty())
|
||||
{
|
||||
@@ -1212,7 +1214,7 @@ namespace lsp::language::ast
|
||||
{
|
||||
label += " (" + arg.name.value() + ")";
|
||||
}
|
||||
if (arg.is_const)
|
||||
if (arg.mode == ast::ParameterMode::kConst)
|
||||
{
|
||||
label += " [const]";
|
||||
}
|
||||
@@ -1638,10 +1640,10 @@ namespace lsp::language::ast
|
||||
}
|
||||
os_ << "\n";
|
||||
|
||||
if (node.class_expr)
|
||||
if (node.target)
|
||||
{
|
||||
IncreaseIndent();
|
||||
PrintExpression(node.class_expr.get(), "Class", true);
|
||||
PrintExpression(node.target.get(), "Class", true);
|
||||
DecreaseIndent();
|
||||
}
|
||||
}
|
||||
@@ -1701,7 +1703,7 @@ namespace lsp::language::ast
|
||||
if (node.call)
|
||||
{
|
||||
IncreaseIndent();
|
||||
PrintExpression(node.call.get(), "Call", true);
|
||||
PrintExpression(node.call.value().get(), "Call", true);
|
||||
DecreaseIndent();
|
||||
}
|
||||
}
|
||||
@@ -1771,14 +1773,22 @@ namespace lsp::language::ast
|
||||
PrintColored(node.type->name, Color::BrightYellow);
|
||||
}
|
||||
|
||||
if (node.is_var)
|
||||
{
|
||||
os_ << " " << GetColor(Color::Magenta) << "(var)" << GetColor(Color::Reset);
|
||||
}
|
||||
|
||||
if (node.is_out)
|
||||
switch (node.mode)
|
||||
{
|
||||
case ast::ParameterMode::kNone:
|
||||
break;
|
||||
case ast::ParameterMode::kConst:
|
||||
os_ << " " << GetColor(Color::Magenta) << "(const)" << GetColor(Color::Reset);
|
||||
break;
|
||||
case ast::ParameterMode::kIn:
|
||||
os_ << " " << GetColor(Color::Magenta) << "(in)" << GetColor(Color::Reset);
|
||||
break;
|
||||
case ast::ParameterMode::kOut:
|
||||
os_ << " " << GetColor(Color::Magenta) << "(out)" << GetColor(Color::Reset);
|
||||
break;
|
||||
case ast::ParameterMode::kVar:
|
||||
os_ << " " << GetColor(Color::Magenta) << "(var)" << GetColor(Color::Reset);
|
||||
break;
|
||||
}
|
||||
|
||||
if (options_.show_location)
|
||||
@@ -1792,7 +1802,7 @@ namespace lsp::language::ast
|
||||
if (node.default_value)
|
||||
{
|
||||
IncreaseIndent();
|
||||
PrintExpression(node.default_value.get(), "DefaultValue", true);
|
||||
PrintExpression(node.default_value->get(), "DefaultValue", true);
|
||||
DecreaseIndent();
|
||||
}
|
||||
}
|
||||
@@ -1894,7 +1904,7 @@ namespace lsp::language::ast
|
||||
PrintColored("Else Branch:", Color::Yellow);
|
||||
os_ << "\n";
|
||||
IncreaseIndent();
|
||||
PrintStatement(node.else_body.get(), "Body", true);
|
||||
PrintStatement(node.else_body->get(), "Body", true);
|
||||
DecreaseIndent();
|
||||
}
|
||||
|
||||
@@ -2043,9 +2053,7 @@ namespace lsp::language::ast
|
||||
}
|
||||
|
||||
if (node.else_body)
|
||||
{
|
||||
PrintStatement(node.else_body.get(), "Else", true);
|
||||
}
|
||||
PrintStatement(node.else_body->get(), "Else", true);
|
||||
|
||||
DecreaseIndent();
|
||||
}
|
||||
@@ -2118,7 +2126,7 @@ namespace lsp::language::ast
|
||||
if (node.value)
|
||||
{
|
||||
IncreaseIndent();
|
||||
PrintExpression(node.value.get(), "", true);
|
||||
PrintExpression(node.value->get(), "", true);
|
||||
DecreaseIndent();
|
||||
}
|
||||
}
|
||||
@@ -2275,9 +2283,9 @@ namespace lsp::language::ast
|
||||
PrintKeyValue("Type", node.type->name);
|
||||
}
|
||||
|
||||
if (node.initial_value)
|
||||
if (node.initializer)
|
||||
{
|
||||
PrintExpression(node.initial_value.get(), "InitialValue", true);
|
||||
PrintExpression(node.initializer->get(), "InitialValue", true);
|
||||
}
|
||||
|
||||
DecreaseIndent();
|
||||
@@ -2303,10 +2311,8 @@ namespace lsp::language::ast
|
||||
PrintKeyValue("Type", node.type->name);
|
||||
}
|
||||
|
||||
if (node.initial_value)
|
||||
{
|
||||
PrintExpression(node.initial_value.get(), "Initializer", true);
|
||||
}
|
||||
if (node.initializer)
|
||||
PrintExpression(node.initializer->get(), "Initializer", true);
|
||||
|
||||
DecreaseIndent();
|
||||
}
|
||||
@@ -2327,14 +2333,10 @@ namespace lsp::language::ast
|
||||
IncreaseIndent();
|
||||
|
||||
if (node.type)
|
||||
{
|
||||
PrintKeyValue("Type", node.type->name);
|
||||
}
|
||||
|
||||
if (node.initial_value)
|
||||
{
|
||||
PrintExpression(node.initial_value.get(), "Initializer", true);
|
||||
}
|
||||
if (node.initializer)
|
||||
PrintExpression(node.initializer->get(), "Initializer", true);
|
||||
|
||||
DecreaseIndent();
|
||||
}
|
||||
@@ -2383,14 +2385,10 @@ namespace lsp::language::ast
|
||||
IncreaseIndent();
|
||||
|
||||
if (node.type)
|
||||
{
|
||||
PrintKeyValue("Type", node.type->name);
|
||||
}
|
||||
|
||||
if (node.initial_value)
|
||||
{
|
||||
PrintExpression(node.initial_value.get(), "Initializer", true);
|
||||
}
|
||||
if (node.initializer)
|
||||
PrintExpression(node.initializer->get(), "Initializer", true);
|
||||
|
||||
DecreaseIndent();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "../../src/language/ast/types.hpp"
|
||||
#include "../../src/language/ast/deserializer.hpp"
|
||||
|
||||
namespace lsp::language::ast
|
||||
namespace lsp::language::ast::debug
|
||||
{
|
||||
// ===== 打印配置 =====
|
||||
struct PrintOptions
|
||||
@@ -214,7 +214,7 @@ namespace lsp::language::ast
|
||||
void PrintLiteralKind(LiteralKind kind);
|
||||
void PrintAccessModifier(AccessModifier modifier);
|
||||
void PrintMethodModifier(MethodModifier modifier);
|
||||
void PrintMethodType(MethodType type);
|
||||
void PrintMethodType(MethodKind kind);
|
||||
void PrintReferenceModifier(ReferenceModifier modifier);
|
||||
void PrintConditionalCompilationType(ConditionalCompilationType type);
|
||||
void PrintTSSQLExpressionType(TSSQLExpressionType type);
|
||||
|
||||
@@ -136,7 +136,7 @@ int main(int argc, char* argv[])
|
||||
bool test_incremental = false;
|
||||
|
||||
// 默认打印选项
|
||||
PrintOptions opts = PrintOptions::Default();
|
||||
debug::PrintOptions opts = debug::PrintOptions::Default();
|
||||
|
||||
// 解析命令行参数
|
||||
for (int i = 1; i < argc; ++i)
|
||||
@@ -149,11 +149,11 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else if (arg == "-v" || arg == "--verbose")
|
||||
{
|
||||
opts = PrintOptions::Verbose();
|
||||
opts = debug::PrintOptions::Verbose();
|
||||
}
|
||||
else if (arg == "-c" || arg == "--compact")
|
||||
{
|
||||
opts = PrintOptions::Compact();
|
||||
opts = debug::PrintOptions::Compact();
|
||||
}
|
||||
else if (arg == "-s" || arg == "--show-source")
|
||||
{
|
||||
@@ -228,10 +228,10 @@ int main(int argc, char* argv[])
|
||||
|
||||
// 打印摘要
|
||||
std::cout << "\n";
|
||||
std::cout << Color::BrightBlue << "========================================\n"
|
||||
<< Color::Reset;
|
||||
std::cout << Color::BrightCyan << "Summary:\n"
|
||||
<< Color::Reset;
|
||||
std::cout << debug::Color::BrightBlue << "========================================\n"
|
||||
<< debug::Color::Reset;
|
||||
std::cout << debug::Color::BrightCyan << "Summary:\n"
|
||||
<< debug::Color::Reset;
|
||||
std::cout << " File: " << filepath << "\n";
|
||||
std::cout << " Size: " << source.length() << " bytes\n";
|
||||
|
||||
@@ -243,20 +243,20 @@ int main(int argc, char* argv[])
|
||||
std::cout << " Errors: ";
|
||||
if (result.HasErrors())
|
||||
{
|
||||
std::cout << Color::BrightRed << result.errors.size() << " ✗" << Color::Reset << "\n";
|
||||
std::cout << " Status: " << Color::BrightRed << "FAILED" << Color::Reset << "\n";
|
||||
std::cout << debug::Color::BrightRed << result.errors.size() << " ✗" << debug::Color::Reset << "\n";
|
||||
std::cout << " Status: " << debug::Color::BrightRed << "FAILED" << debug::Color::Reset << "\n";
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << Color::BrightGreen << "0 ✓" << Color::Reset << "\n";
|
||||
std::cout << " Status: " << Color::BrightGreen << "SUCCESS" << Color::Reset << "\n";
|
||||
std::cout << debug::Color::BrightGreen << "0 ✓" << debug::Color::Reset << "\n";
|
||||
std::cout << " Status: " << debug::Color::BrightGreen << "SUCCESS" << debug::Color::Reset << "\n";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cerr << Color::BrightRed << "Error: " << e.what() << Color::Reset << "\n";
|
||||
std::cerr << debug::Color::BrightRed << "Error: " << e.what() << debug::Color::Reset << "\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user