luaut-language-server 1.0.0
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 +100 -0
- package/dist/chunk-RHII344O.js +733 -0
- package/dist/chunk-RHII344O.js.map +1 -0
- package/dist/cli.cjs +691 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +8 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +774 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +183 -0
- package/dist/index.d.ts +183 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# luaut-language-server
|
|
2
|
+
|
|
3
|
+
Language server (LSP) for **luaut** — the TypeScript-flavoured language that
|
|
4
|
+
compiles to Luau. It is a thin layer over [`luaut-parser`][parser]: the parser
|
|
5
|
+
does the parsing, scope analysis and flow-sensitive type analysis, and this
|
|
6
|
+
package answers editor questions from the tables it produces.
|
|
7
|
+
|
|
8
|
+
[parser]: https://www.npmjs.com/package/luaut-parser
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install luaut-language-server
|
|
12
|
+
luaut-language-server --stdio
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## What it does
|
|
16
|
+
|
|
17
|
+
| request | notes |
|
|
18
|
+
|---|---|
|
|
19
|
+
| `publishDiagnostics` | syntax, scope (redeclare, assign-to-`const`) and type errors, on open and on every keystroke |
|
|
20
|
+
| `hover` | the type as luaut writes it — the **narrowed** type at a reference, so a guarded `v` reads `string`, not `string \| nil` |
|
|
21
|
+
| `definition` | the binding's declaration |
|
|
22
|
+
| `references`, `documentHighlight` | every use of the binding |
|
|
23
|
+
| `rename`, `prepareRename` | refuses names that are not identifiers, and builtins from the definitions files |
|
|
24
|
+
| `completion` | members after `.` / `:`, names in scope, type names in a type position |
|
|
25
|
+
| `signatureHelp` | every overload, with the active parameter — `:` calls count `self` for you |
|
|
26
|
+
| `documentSymbol` | functions, type aliases, top-level bindings |
|
|
27
|
+
|
|
28
|
+
Single file, for now: `import` resolves to `any`, so cross-file navigation is
|
|
29
|
+
not there yet. See [Not yet](#not-yet).
|
|
30
|
+
|
|
31
|
+
## How it is put together
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
src/
|
|
35
|
+
server.ts LSP wiring, and nothing else
|
|
36
|
+
analysis.ts parse -> scopes -> types, cached per document version
|
|
37
|
+
ast-utils.ts 1-based spans <-> 0-based LSP positions, position -> node
|
|
38
|
+
features/ one file per feature; plain functions, no LSP plumbing
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
A feature is `(analysis, position) -> answer`. Nothing in `features/` opens a
|
|
42
|
+
connection or knows about documents, which is why `scripts/test.ts` can drive
|
|
43
|
+
all of them in-process without spawning a server, and why an editor extension
|
|
44
|
+
can call them directly:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { Analyzer, hover, diagnostics } from "luaut-language-server"
|
|
48
|
+
|
|
49
|
+
const analyzer = new Analyzer() // or { libs: [...] } for your own definitions
|
|
50
|
+
const analysis = analyzer.get(document) // a vscode-languageserver TextDocument
|
|
51
|
+
hover(analysis, { line: 3, character: 12 })
|
|
52
|
+
diagnostics(analysis)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Speculative parsing
|
|
56
|
+
|
|
57
|
+
`x.` and `add(1, ` are syntax errors — the text you are in the middle of
|
|
58
|
+
typing usually is. Completion and signature help therefore analyze a
|
|
59
|
+
*repaired copy* of the document: a placeholder identifier at the cursor for
|
|
60
|
+
completion, and the shortest of `nil`, `nil)`, `)` that parses for signature
|
|
61
|
+
help. The user's document is never touched and the repaired copy is never
|
|
62
|
+
cached.
|
|
63
|
+
|
|
64
|
+
### Globals
|
|
65
|
+
|
|
66
|
+
The names a file may use undeclared are not hard-coded: they are read out of
|
|
67
|
+
the `declare` statements in the definitions passed to `Analyzer`. Adding a
|
|
68
|
+
global to a `.d.luaut` is all it takes for the editor to stop calling it
|
|
69
|
+
undefined.
|
|
70
|
+
|
|
71
|
+
## Not yet
|
|
72
|
+
|
|
73
|
+
- **One file at a time.** No workspace indexing, so no cross-file
|
|
74
|
+
go-to-definition, `workspace/symbol`, or diagnostics for files you have not
|
|
75
|
+
opened.
|
|
76
|
+
- **No formatting** — there is no luaut printer yet (the compiler owns
|
|
77
|
+
emitting Luau, and it emits *Luau*, not luaut).
|
|
78
|
+
- No code actions, inlay hints, semantic tokens, or folding ranges.
|
|
79
|
+
- Everything `luaut-parser` does not check is invisible here too: unknown
|
|
80
|
+
properties, writes to `readonly`, generic constraints at call sites,
|
|
81
|
+
metatables.
|
|
82
|
+
|
|
83
|
+
## Editors
|
|
84
|
+
|
|
85
|
+
VS Code: [`luaut-vscode`](../luaut-vscode) — a separate project next door. It
|
|
86
|
+
bundles this server into the extension, so its `.vsix` is self-contained.
|
|
87
|
+
|
|
88
|
+
Anything else that speaks LSP: launch `luaut-language-server --stdio` (or
|
|
89
|
+
`--node-ipc`) and attach it to the `luaut` language / `.luaut` files.
|
|
90
|
+
|
|
91
|
+
## Development
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npm run typecheck
|
|
95
|
+
npm test # features in-process, then the built binary over stdio
|
|
96
|
+
npm run build
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`scripts/test.ts` marks the cursor with `‸` in each fixture (not `|` — that is
|
|
100
|
+
the union operator). `scripts/e2e.ts` speaks real LSP to `dist/cli.js`.
|