@tabnas/lsp 0.1.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/LICENSE +21 -0
- package/README.md +51 -0
- package/bin/tabnas-lsp-gen.js +98 -0
- package/bin/tabnas-lsp.js +7 -0
- package/data/diagnostic-fixtures.json +2888 -0
- package/data/registry.json +424 -0
- package/package.json +52 -0
- package/src/core.js +299 -0
- package/src/documents.js +97 -0
- package/src/generate.js +962 -0
- package/src/instances.js +141 -0
- package/src/loaders.js +515 -0
- package/src/registry.js +194 -0
- package/src/server.js +371 -0
- package/tools/gen-fixtures.js +90 -0
- package/tools/gen-registry.js +153 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tabnas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @tabnas/lsp
|
|
2
|
+
|
|
3
|
+
The tabnas language server and language-server generator.
|
|
4
|
+
|
|
5
|
+
One LSP server serves **every** tabnas grammar — fleet plugins,
|
|
6
|
+
serialized `GrammarSpec` data, or BNF-dialect text added dynamically
|
|
7
|
+
through workspace configuration — and the same machinery **generates**
|
|
8
|
+
standalone single-language servers (Node packages or Go binaries) plus
|
|
9
|
+
the editor plugins to use them, from one parser module or grammar.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# the unified server, over stdio
|
|
13
|
+
npx --package=@tabnas/lsp tabnas-lsp --stdio
|
|
14
|
+
|
|
15
|
+
# a branded single-language server + editor plugins
|
|
16
|
+
npx --package=@tabnas/lsp tabnas-lsp-gen \
|
|
17
|
+
--spec my-grammar.json --language-id mydsl --out mydsl-tools
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`--package` is required either way: this package ships two binaries and
|
|
21
|
+
neither is named `@tabnas/lsp`, so the package-name form of `npx` cannot
|
|
22
|
+
pick one, and a bare `npx tabnas-lsp-gen` would fetch an unrelated
|
|
23
|
+
registry package.
|
|
24
|
+
|
|
25
|
+
## What it provides
|
|
26
|
+
|
|
27
|
+
Diagnostics, semantic tokens, document symbols (outline) and completion,
|
|
28
|
+
over incremental `didChange` sync, for any grammar the registry can
|
|
29
|
+
reach. Grammars can be added without rebuilding the server: an installed
|
|
30
|
+
plugin module, a serialized `GrammarSpec`, or a BNF dialect compiled at
|
|
31
|
+
load time, declared per workspace folder and reloaded when the file
|
|
32
|
+
changes.
|
|
33
|
+
|
|
34
|
+
## Engine
|
|
35
|
+
|
|
36
|
+
Requires a `@tabnas/parser` providing the LSP engine contract —
|
|
37
|
+
recovery, `ruleDone` and `continuations`. The peer range is open by fleet
|
|
38
|
+
convention, but the contract is newer than the current published engine;
|
|
39
|
+
see `AGENTS.md` in the repository for the release constraint that
|
|
40
|
+
applies before this package is published.
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
Full design, the dynamism ladder, the generator matrix and the security
|
|
45
|
+
model are in [`doc/design.md`](https://github.com/tabnas/lsp/blob/main/doc/design.md).
|
|
46
|
+
Contributor and agent guidance is in
|
|
47
|
+
[`AGENTS.md`](https://github.com/tabnas/lsp/blob/main/AGENTS.md).
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* Copyright (c) 2026 Richard Rodger, MIT License */
|
|
3
|
+
'use strict'
|
|
4
|
+
|
|
5
|
+
// tabnas-lsp-gen: generate a standalone single-language LSP server —
|
|
6
|
+
// Node package or Go module — plus editor plugins, from one grammar
|
|
7
|
+
// (design §7). A deliberately separate bin from tabnas-lsp: a
|
|
8
|
+
// generator argument bug must never break editor launches.
|
|
9
|
+
|
|
10
|
+
const { generate, ALL_EDITORS } = require('../src/generate')
|
|
11
|
+
|
|
12
|
+
const USAGE = `usage: tabnas-lsp-gen --out <dir> <input> [options]
|
|
13
|
+
|
|
14
|
+
input (exactly one):
|
|
15
|
+
--entry <languageId> a bundled fleet registry entry
|
|
16
|
+
--module <npm-name> a tabnas plugin module (Node runtime only)
|
|
17
|
+
--spec <file.json> a serialized GrammarSpec (pure data)
|
|
18
|
+
--grammar <file> BNF-dialect text (.abnf | .ebnf | .gbnf)
|
|
19
|
+
|
|
20
|
+
options:
|
|
21
|
+
--out <dir> target directory (required)
|
|
22
|
+
--language-id <id> served language id (derived when omitted)
|
|
23
|
+
--extensions <.a,.b> file extensions (default: .<language-id>)
|
|
24
|
+
--runtime <node|go> server runtime (default: node)
|
|
25
|
+
--editors <list|none> ${ALL_EDITORS.join(',')} (default: all)
|
|
26
|
+
--unified editor plugins for the whole bundled
|
|
27
|
+
registry over tabnas-lsp itself (no server)
|
|
28
|
+
|
|
29
|
+
go runtime:
|
|
30
|
+
--go-module <path> generated module path
|
|
31
|
+
--go-plugin <import> Go plugin package (closure/imperative grammars)
|
|
32
|
+
--go-plugin-func <Name> plugin function (default: id CamelCased with
|
|
33
|
+
non-identifier characters removed)
|
|
34
|
+
--go-plugin-version <vX.Y.Z> pin the plugin require (otherwise
|
|
35
|
+
\`go mod tidy\` resolves it from the import)
|
|
36
|
+
--go-lsp-version <vX.Y.Z> pin the github.com/tabnas/lsp/go require
|
|
37
|
+
--go-parser-version <vX.Y.Z> pin the github.com/tabnas/parser/go require
|
|
38
|
+
--go-replace <mod=dir> replace directive for local dev (repeatable)
|
|
39
|
+
`
|
|
40
|
+
|
|
41
|
+
function parseArgs(argv) {
|
|
42
|
+
const opts = { input: {}, goReplace: [] }
|
|
43
|
+
for (let i = 0; i < argv.length; i++) {
|
|
44
|
+
const a = argv[i]
|
|
45
|
+
const next = () => {
|
|
46
|
+
if (i + 1 >= argv.length) throw new Error(a + ' needs a value')
|
|
47
|
+
return argv[++i]
|
|
48
|
+
}
|
|
49
|
+
switch (a) {
|
|
50
|
+
case '--out': opts.out = next(); break
|
|
51
|
+
case '--entry': opts.input.entry = next(); break
|
|
52
|
+
case '--module': opts.input.module = next(); break
|
|
53
|
+
case '--spec': opts.input.spec = next(); break
|
|
54
|
+
case '--grammar': opts.input.grammar = next(); break
|
|
55
|
+
case '--language-id': opts.languageId = next(); break
|
|
56
|
+
case '--extensions':
|
|
57
|
+
opts.extensions = next().split(',').map((x) =>
|
|
58
|
+
x.startsWith('.') ? x : '.' + x)
|
|
59
|
+
break
|
|
60
|
+
case '--runtime': opts.runtime = next(); break
|
|
61
|
+
case '--editors': {
|
|
62
|
+
const v = next()
|
|
63
|
+
opts.editors = 'none' === v ? [] : v.split(',')
|
|
64
|
+
break
|
|
65
|
+
}
|
|
66
|
+
case '--unified': opts.unified = true; break
|
|
67
|
+
case '--go-module': opts.goModule = next(); break
|
|
68
|
+
case '--go-plugin': opts.goPlugin = next(); break
|
|
69
|
+
case '--go-plugin-func': opts.goPluginFunc = next(); break
|
|
70
|
+
case '--go-plugin-version': opts.goPluginVersion = next(); break
|
|
71
|
+
case '--go-lsp-version': opts.goLspVersion = next(); break
|
|
72
|
+
case '--go-parser-version': opts.goParserVersion = next(); break
|
|
73
|
+
case '--go-replace': opts.goReplace.push(next()); break
|
|
74
|
+
case '--help': case '-h':
|
|
75
|
+
console.log(USAGE)
|
|
76
|
+
process.exit(0)
|
|
77
|
+
break
|
|
78
|
+
default:
|
|
79
|
+
throw new Error('unknown option: ' + a + '\n\n' + USAGE)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return opts
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const opts = parseArgs(process.argv.slice(2))
|
|
87
|
+
if (!opts.out) throw new Error('--out is required\n\n' + USAGE)
|
|
88
|
+
const inputs = Object.keys(opts.input).length
|
|
89
|
+
if (!opts.unified && 1 !== inputs) {
|
|
90
|
+
throw new Error('exactly one input is required\n\n' + USAGE)
|
|
91
|
+
}
|
|
92
|
+
const { files, out } = generate(opts)
|
|
93
|
+
console.log('generated ' + files.length + ' files under ' + out + ':')
|
|
94
|
+
for (const f of files) console.log(' ' + f)
|
|
95
|
+
} catch (e) {
|
|
96
|
+
console.error('tabnas-lsp-gen: ' + e.message)
|
|
97
|
+
process.exitCode = 1
|
|
98
|
+
}
|