@treelsp/cli 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +167 -0
- package/bin/treelsp.js +2 -0
- package/dist/index.js +771 -249
- package/package.json +9 -3
package/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# @treelsp/cli
|
|
2
|
+
|
|
3
|
+
CLI tool for [treelsp](https://github.com/dhrubomoy/treelsp) — generate parsers and language servers from TypeScript grammar definitions. Supports Tree-sitter and Lezer backends.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D @treelsp/cli
|
|
9
|
+
# or
|
|
10
|
+
pnpm add -D @treelsp/cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Commands
|
|
14
|
+
|
|
15
|
+
### `treelsp init`
|
|
16
|
+
|
|
17
|
+
Scaffold a new language project interactively.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
treelsp init
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Prompts for a language name, file extension, and parser backend (Tree-sitter or Lezer), then creates a pnpm monorepo with two packages:
|
|
24
|
+
- `packages/language/` — grammar definition (`grammar.ts`) and generated files
|
|
25
|
+
- `packages/extension/` — VS Code extension that launches the language server
|
|
26
|
+
|
|
27
|
+
Also generates root config files (`treelsp-config.json`, `pnpm-workspace.yaml`, `.vscode/launch.json`).
|
|
28
|
+
|
|
29
|
+
### `treelsp generate`
|
|
30
|
+
|
|
31
|
+
Generate grammar files, AST types, manifest, and syntax highlighting queries from a language definition.
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Usage: treelsp generate [options]
|
|
35
|
+
|
|
36
|
+
Options:
|
|
37
|
+
-f, --file <file> path to treelsp-config.json or package.json with treelsp field
|
|
38
|
+
-w, --watch watch for changes
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Output files** depend on the backend:
|
|
42
|
+
|
|
43
|
+
**Tree-sitter** (default, written to `generated/`):
|
|
44
|
+
- `grammar.js` — Tree-sitter grammar (CommonJS)
|
|
45
|
+
- `ast.ts` — typed AST interfaces
|
|
46
|
+
- `treelsp.json` — manifest for VS Code extension discovery
|
|
47
|
+
- `syntax.tmLanguage.json` — TextMate grammar
|
|
48
|
+
- `queries/highlights.scm` — Tree-sitter syntax highlighting
|
|
49
|
+
- `queries/locals.scm` — Tree-sitter scope/locals
|
|
50
|
+
|
|
51
|
+
**Lezer** (written to `generated-lezer/` or custom `out` path):
|
|
52
|
+
- `grammar.lezer` — Lezer grammar specification
|
|
53
|
+
- `parser-meta.json` — field/node metadata
|
|
54
|
+
- `ast.ts` — typed AST interfaces
|
|
55
|
+
- `treelsp.json` — manifest for VS Code extension discovery
|
|
56
|
+
- `syntax.tmLanguage.json` — TextMate grammar
|
|
57
|
+
|
|
58
|
+
### `treelsp build`
|
|
59
|
+
|
|
60
|
+
Compile the generated grammar and bundle the language server.
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
Usage: treelsp build [options]
|
|
64
|
+
|
|
65
|
+
Options:
|
|
66
|
+
-f, --file <file> path to treelsp-config.json or package.json with treelsp field
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Tree-sitter backend** requires the [tree-sitter CLI](https://github.com/tree-sitter/tree-sitter/blob/master/cli/README.md) (`npm install -g tree-sitter-cli` or `cargo install tree-sitter-cli`).
|
|
70
|
+
|
|
71
|
+
**Lezer backend** requires no external tools (pure JavaScript compilation).
|
|
72
|
+
|
|
73
|
+
**Output files:**
|
|
74
|
+
|
|
75
|
+
Tree-sitter:
|
|
76
|
+
- `grammar.wasm` — compiled WebAssembly parser
|
|
77
|
+
- `server.bundle.cjs` — self-contained language server bundle
|
|
78
|
+
- `tree-sitter.wasm` — web-tree-sitter runtime
|
|
79
|
+
|
|
80
|
+
Lezer:
|
|
81
|
+
- `parser.js` — compiled Lezer parser
|
|
82
|
+
- `parser.bundle.js` — self-contained parser bundle (includes @lezer/lr)
|
|
83
|
+
- `server.bundle.cjs` — self-contained language server bundle
|
|
84
|
+
|
|
85
|
+
### `treelsp watch`
|
|
86
|
+
|
|
87
|
+
Watch mode — re-runs `generate` + `build` automatically when grammar files change.
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
Usage: treelsp watch [options]
|
|
91
|
+
|
|
92
|
+
Options:
|
|
93
|
+
-f, --file <file> path to treelsp-config.json or package.json with treelsp field
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Configuration
|
|
97
|
+
|
|
98
|
+
By default, treelsp looks for `grammar.ts` in the current directory and outputs to `generated/` using the Tree-sitter backend. For multi-language or multi-backend projects, create a config file.
|
|
99
|
+
|
|
100
|
+
### Config discovery order
|
|
101
|
+
|
|
102
|
+
When `-f` is not provided, the CLI searches from the current directory upward for:
|
|
103
|
+
|
|
104
|
+
1. `treelsp-config.json`
|
|
105
|
+
2. A `"treelsp"` field in `package.json`
|
|
106
|
+
3. Falls back to legacy mode (`grammar.ts` in cwd)
|
|
107
|
+
|
|
108
|
+
### `treelsp-config.json`
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"languages": [
|
|
113
|
+
{ "grammar": "packages/language/grammar.ts" },
|
|
114
|
+
{ "grammar": "packages/language/grammar.ts", "backend": "lezer", "out": "packages/language/generated-lezer" }
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### `package.json`
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"treelsp": {
|
|
124
|
+
"languages": [
|
|
125
|
+
{ "grammar": "src/grammar.ts", "out": "src/generated" }
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Schema
|
|
132
|
+
|
|
133
|
+
| Field | Type | Required | Description |
|
|
134
|
+
|-------|------|----------|-------------|
|
|
135
|
+
| `languages` | array | yes | List of language projects |
|
|
136
|
+
| `languages[].grammar` | string | yes | Path to `grammar.ts`, relative to the config file |
|
|
137
|
+
| `languages[].out` | string | no | Output directory (default: `<grammar dir>/generated`) |
|
|
138
|
+
| `languages[].backend` | string | no | Parser backend: `"tree-sitter"` (default) or `"lezer"` |
|
|
139
|
+
|
|
140
|
+
## Typical Workflow
|
|
141
|
+
|
|
142
|
+
**New project:**
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
treelsp init # scaffold project with language + extension packages
|
|
146
|
+
cd my-lang
|
|
147
|
+
pnpm install
|
|
148
|
+
pnpm build # generate + compile + bundle
|
|
149
|
+
# Press F5 in VS Code to launch the extension
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Generate for both backends:**
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"languages": [
|
|
157
|
+
{ "grammar": "packages/language/grammar.ts" },
|
|
158
|
+
{ "grammar": "packages/language/grammar.ts", "backend": "lezer", "out": "packages/language/generated-lezer" }
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
treelsp generate # generates for all configured backends
|
|
165
|
+
treelsp build # builds all configured backends
|
|
166
|
+
treelsp watch # watches all grammar files
|
|
167
|
+
```
|
package/bin/treelsp.js
ADDED