WarpLabs Zed 扩展
WarpLabs DSL 的 Zed 编辑器扩展 —— 基于 tree-sitter 的语法高亮、括号匹配、代码折叠、自动缩进和代码片段。
支持的语言
| 语言 | 后缀 | 说明 |
|---|---|---|
| WFL | .wfl |
WarpFusion 语言 —— 融合规则、模式检测、评分 |
| WFS | .wfs |
窗口字段 Schema —— 事件流窗口与字段定义 |
| WPL | .wpl |
WarpLabs 解析语言 —— 带转换管道的日志解析 |
| OML | .oml |
输出映射语言 —— 输出映射与转换 |
| WFG | .wfg |
WarpFusion 场景生成器 —— 测试场景生成与故障注入 |
| MoJu | .mju |
MoJu 设计语言 —— 结构、生命周期、流程、架构与验证 |
功能特性
语法高亮
所有支持的语言均基于 tree-sitter 高亮,覆盖关键字、类型、字符串、数字、注释、运算符和内建函数。
其他
- 括号匹配与自动闭合
- 自动缩进
- 代码折叠
- 代码片段(OML)
安装
1. 安装 Zed 扩展
从 Zed 扩展市场安装(发布后):
Cmd+Shift+X → 搜索 "WarpLabs" → 安装
作为开发扩展安装(开发模式):
先克隆本项目:
git clone https://github.com/wp-labs/zed-warplabs.git
cd zed-warplabs然后在 Zed 中:
Cmd+Shift+P → "zed: install dev extension" → 选择克隆下来的 zed-warplabs/ 目录
2. 验证
打开任意 .wfl、.wfs、.wpl、.oml、.wfg、.gxl 或 .mju 文件,应该能看到:
- 立即生效的语法高亮
语言参考
WFL —— 关键字与内建函数
关键字: use, rule, meta, events, match, keys, duration, on, event, close, score, entity, yield, contract, given, expect, derive, stage, and, or, not, in, true, false, if, then, else, join, conv
聚合函数: count, sum, avg, min, max, distinct
函数: fmt, has, Now::time, Now::date, Now::hour
类型: chars, digit, float, bool, time, ip, hex
WFS —— 关键字与类型
关键字: window, stream, time, over, fields, array
类型: chars, digit, float, bool, time, ip, hex
WPL —— 关键字与类型
关键字: package, rule, field, metadata, length, format, pipe, separator, target, type, tag, copy_raw, alt, opt, some_of, seq, not
类型: chars, digit, float, bool, time, ip, hex, json, kvarr, http/request, http/status, http/agent
OML —— 关键字与管道函数
关键字: name, rule, read, take, pipe, fmt, object, collect, match, select, from, where, and, or, not, in, auto, ip, chars, digit, float, time, bool, obj, array
管道函数: to_json, base64_decode, base64_encode, url, nth, get, path, json_escape, json_unescape, html_unescape, html_escape, str_escape, to_str, skip_empty, ip4_to_int, Time::to_ts_ms
WFG —— 关键字与生成器函数
关键字: use, scenario, seed, time, duration, total, stream, inject, for, on, faults, oracle, hit, near_miss, non_hit, true, false, out_of_order, late, duplicate, drop
生成器函数: ipv4, pattern, uniform, choice, counter, normal, zipf
MoJu —— 关键字
关键字: struct, state, variant, event, failure, failure_policy, message, command, actor, lifecycle, cap, op, flow, verify, usecase, scenario, subsystem, layer, dependency_rule, module, decision, interface, storage, config, dataflow, target, region, node, resource, network, assembly, profile, depends, implements, require, step, ensure, mock, expect
故障排查
Grammar 变更未生效
修改 tree-sitter grammar 之后:
- 在 grammar 仓库执行
tree-sitter generate git commit提交改动- 将
extension.toml中的rev更新为新 commit 哈希 - 在 Zed 中重新安装开发扩展
校验 grammar 与语言查询的兼容性
推送 grammar/高亮改动之前,先运行:
bash scripts/check-grammar-highlights.sh该检查会针对 extension.toml 中的每种语言:
- 克隆固定的 grammar 仓库/版本,
- 解析
languages/<lang>/config.toml声明的所有examples/<lang>/*.<suffix>示例文件, - 编译并运行所有
languages/<lang>/*.scm查询文件,并与这些示例进行匹配。
项目结构
tools/
├── zed-warplabs/ # 本 Zed 扩展
│ ├── extension.toml # 扩展清单(manifest)
│ ├── Cargo.toml # 最小的 Rust WASM 扩展入口
│ ├── src/lib.rs # Extension trait 实现
│ ├── languages/ # 每种语言的 Zed 配置
│ │ ├── wfl/ # config.toml + highlights/brackets/indents/folds/outline .scm
│ │ ├── wfs/
│ │ ├── wpl/
│ │ ├── oml/
│ │ └── wfg/
│ ├── grammars/ # 预构建的 WASM 解析器
│ ├── snippets/ # 代码片段
│ └── examples/ # 测试用示例文件
│
├── tree-sitter-wfl/ # Tree-sitter grammars
├── tree-sitter-wfs/
├── tree-sitter-wpl/
├── tree-sitter-oml/
├── tree-sitter-wfg/
└── tree-sitter-moju/许可证
Apache-2.0