feat: IDE支持 — workspace拆分、LSP服务器、VS Code扩展

**Workspace 拆分**
- aster-core: 纯库,zero-dependency,包含 lexer/parser/ast/interpreter/error/analysis
- aster: REPL 二进制,薄封装 aster-core
- aster-lsp: LSP 语言服务器

**VS Code 扩展 (vscode-ext/)**
- TextMate 语法高亮 (.ast 文件)
- 语言配置 (注释切换、括号配对、自动缩进)
- LSP 客户端 (extension.js)

**LSP 服务端功能**
- Diagnostics: 实时显示 lex/parse 错误红色波浪线
- Completion: 关键字 + 内置函数 + 用户定义符号补全
- Hover: 悬停显示变量/函数信息
- Signature Help: 函数参数提示
- Goto Definition: Ctrl+Click 跳转到声明处
- Find References: 查找所有引用位置
- Rename: F2 重命名符号

**新增 analysis 模块**
- collect_symbols: AST 遍历收集符号
- find_declaration/find_all_references: Token 扫描定位声明和引用
This commit is contained in:
2026-06-25 00:28:13 +08:00
parent 99c9e9c9bd
commit bdffe9e3c5
65 changed files with 1709 additions and 47 deletions
+141
View File
@@ -0,0 +1,141 @@
use crate::ast::stmt::Stmt;
#[derive(Debug, Clone)]
pub enum Expr {
/// 字面量:number / string / bool / nil
Literal(Literal),
/// 变量引用
Variable(String),
/// 赋值表达式:a = b
Assign {
name: String,
op: AssignOp,
value: Box<Expr>,
},
/// 属性访问表达式:object.name
Get {
object: Box<Expr>,
name: String,
},
/// 属性赋值表达式:object.name = value
Set {
object: Box<Expr>,
name: String,
op: AssignOp,
value: Box<Expr>,
},
/// 对象字面量:{ key: value, ... }
ObjectLiteral {
properties: Vec<(String, Expr)>,
},
/// 数组字面量:[ expr, expr, ... ]
ArrayLiteral {
elements: Vec<Expr>,
},
/// 索引访问:expr[index]
IndexGet {
array: Box<Expr>,
index: Box<Expr>,
},
/// 索引赋值:expr[index] = value
IndexSet {
array: Box<Expr>,
index: Box<Expr>,
op: AssignOp,
value: Box<Expr>,
},
/// 一元运算:!expr / -expr
Unary {
op: UnaryOp,
right: Box<Expr>,
},
/// 二元运算:a + b
Binary {
left: Box<Expr>,
op: BinaryOp,
right: Box<Expr>,
},
/// 逻辑运算:&& ||
Logical {
left: Box<Expr>,
op: LogicalOp,
right: Box<Expr>,
},
/// 三元运算:condition ? then_branch : else_branch
Ternary {
condition: Box<Expr>,
then_branch: Box<Expr>,
else_branch: Box<Expr>,
},
/// 函数调用
Call {
callee: Box<Expr>,
arguments: Vec<Expr>,
},
/// 匿名函数(为闭包预留)
Lambda {
params: Vec<String>,
body: Vec<Stmt>,
},
}
#[derive(Debug, Clone)]
pub enum Literal {
Number(f64),
String(String),
Bool(bool),
Nil,
}
#[derive(Debug, Clone, Copy)]
pub enum UnaryOp {
Negate, // -
Not, // !
}
#[derive(Debug, Clone, Copy)]
pub enum BinaryOp {
Add,
Sub,
Mul,
Div,
Mod,
Greater,
GreaterEqual,
Less,
LessEqual,
Equal,
NotEqual,
}
#[derive(Debug, Clone, Copy)]
pub enum LogicalOp {
And,
Or,
}
#[derive(Debug, Clone, Copy)]
pub enum AssignOp {
Equal, // =
PlusEqual, // +=
MinusEqual, // -=
StarEqual, // *=
SlashEqual, // /=
PercentEqual, // %=
}