📦 更新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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user