@hydranium/cli 1.0.0-next.22 → 1.0.0-next.220
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 +25 -5
- package/bin/hydranium-cli.js +13 -0
- package/lib/cli-version.js.map +1 -1
- package/lib/cli.js +0 -0
- package/lib/commands/analyze-heap-args.js.map +1 -1
- package/lib/commands/analyze-heap.d.ts +3 -0
- package/lib/commands/analyze-heap.d.ts.map +1 -1
- package/lib/commands/analyze-heap.js +2 -1
- package/lib/commands/analyze-heap.js.map +1 -1
- package/lib/commands/ast-ground-truth-args.d.ts +3 -2
- package/lib/commands/ast-ground-truth-args.d.ts.map +1 -1
- package/lib/commands/ast-ground-truth-args.js +11 -9
- package/lib/commands/ast-ground-truth-args.js.map +1 -1
- package/lib/commands/ast-ground-truth.js +1 -1
- package/lib/commands/ast-ground-truth.js.map +1 -1
- package/lib/commands/generate-ast-builder.d.ts +49 -0
- package/lib/commands/generate-ast-builder.d.ts.map +1 -0
- package/lib/commands/generate-ast-builder.js +200 -0
- package/lib/commands/generate-ast-builder.js.map +1 -0
- package/lib/commands/generate-transfer-model-args.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model-args.js +11 -1
- package/lib/commands/generate-transfer-model-args.js.map +1 -1
- package/lib/commands/generate-transfer-model-config.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model-config.js +3 -1
- package/lib/commands/generate-transfer-model-config.js.map +1 -1
- package/lib/commands/generate-transfer-model.d.ts +9 -0
- package/lib/commands/generate-transfer-model.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model.js +16 -3
- package/lib/commands/generate-transfer-model.js.map +1 -1
- package/lib/commands/harness-args.d.ts +37 -42
- package/lib/commands/harness-args.d.ts.map +1 -1
- package/lib/commands/harness-args.js +65 -25
- package/lib/commands/harness-args.js.map +1 -1
- package/lib/commands/headless-harness.d.ts +37 -20
- package/lib/commands/headless-harness.d.ts.map +1 -1
- package/lib/commands/headless-harness.js +68 -17
- package/lib/commands/headless-harness.js.map +1 -1
- package/lib/commands/init-args.js.map +1 -1
- package/lib/commands/init-prompt.d.ts.map +1 -1
- package/lib/commands/init-templates.d.ts +0 -9
- package/lib/commands/init-templates.d.ts.map +1 -1
- package/lib/commands/init-templates.js +210 -96
- package/lib/commands/init-templates.js.map +1 -1
- package/lib/commands/init-wizard.js.map +1 -1
- package/lib/commands/init-workspace.d.ts +13 -3
- package/lib/commands/init-workspace.d.ts.map +1 -1
- package/lib/commands/init-workspace.js +21 -6
- package/lib/commands/init-workspace.js.map +1 -1
- package/lib/commands/init.d.ts +10 -2
- package/lib/commands/init.d.ts.map +1 -1
- package/lib/commands/init.js +10 -11
- package/lib/commands/init.js.map +1 -1
- package/lib/commands/lint-grammar-args.d.ts +3 -2
- package/lib/commands/lint-grammar-args.d.ts.map +1 -1
- package/lib/commands/lint-grammar-args.js +13 -10
- package/lib/commands/lint-grammar-args.js.map +1 -1
- package/lib/commands/lint-grammar-report.js.map +1 -1
- package/lib/commands/lint-grammar.js +1 -1
- package/lib/commands/lint-grammar.js.map +1 -1
- package/lib/commands/measure-memory-args.d.ts +3 -2
- package/lib/commands/measure-memory-args.d.ts.map +1 -1
- package/lib/commands/measure-memory-args.js +20 -10
- package/lib/commands/measure-memory-args.js.map +1 -1
- package/lib/commands/measure-memory-driver.js +3 -2
- package/lib/commands/measure-memory-driver.js.map +1 -1
- package/lib/commands/measure-memory.js +1 -1
- package/lib/commands/measure-memory.js.map +1 -1
- package/lib/commands/model-docs-args.d.ts +4 -3
- package/lib/commands/model-docs-args.d.ts.map +1 -1
- package/lib/commands/model-docs-args.js +12 -10
- package/lib/commands/model-docs-args.js.map +1 -1
- package/lib/commands/model-docs.js +1 -1
- package/lib/commands/model-docs.js.map +1 -1
- package/lib/commands/projects-args.d.ts.map +1 -1
- package/lib/commands/projects-args.js +5 -5
- package/lib/commands/projects-args.js.map +1 -1
- package/lib/commands/projects.d.ts +3 -4
- package/lib/commands/projects.d.ts.map +1 -1
- package/lib/commands/projects.js +2 -2
- package/lib/commands/projects.js.map +1 -1
- package/lib/commands/query-args.d.ts.map +1 -1
- package/lib/commands/query-args.js +5 -5
- package/lib/commands/query-args.js.map +1 -1
- package/lib/commands/query.d.ts +3 -4
- package/lib/commands/query.d.ts.map +1 -1
- package/lib/commands/query.js +2 -2
- package/lib/commands/query.js.map +1 -1
- package/lib/commands/reflect-args.d.ts +3 -2
- package/lib/commands/reflect-args.d.ts.map +1 -1
- package/lib/commands/reflect-args.js +13 -10
- package/lib/commands/reflect-args.js.map +1 -1
- package/lib/commands/reflect-report.js.map +1 -1
- package/lib/commands/reflect.js +1 -1
- package/lib/commands/reflect.js.map +1 -1
- package/lib/commands/save-args.d.ts.map +1 -1
- package/lib/commands/save-args.js +6 -4
- package/lib/commands/save-args.js.map +1 -1
- package/lib/commands/save.d.ts +8 -4
- package/lib/commands/save.d.ts.map +1 -1
- package/lib/commands/save.js +31 -6
- package/lib/commands/save.js.map +1 -1
- package/lib/commands/validate-args.d.ts +3 -2
- package/lib/commands/validate-args.d.ts.map +1 -1
- package/lib/commands/validate-args.js +13 -10
- package/lib/commands/validate-args.js.map +1 -1
- package/lib/commands/validate-report.js.map +1 -1
- package/lib/commands/validate.js +1 -1
- package/lib/commands/validate.js.map +1 -1
- package/lib/commands/watch-args.d.ts.map +1 -1
- package/lib/commands/watch-args.js +6 -4
- package/lib/commands/watch-args.js.map +1 -1
- package/lib/commands/watch.d.ts +3 -4
- package/lib/commands/watch.d.ts.map +1 -1
- package/lib/commands/watch.js +20 -2
- package/lib/commands/watch.js.map +1 -1
- package/lib/driver-heap.d.ts +52 -0
- package/lib/driver-heap.d.ts.map +1 -0
- package/lib/driver-heap.js +51 -0
- package/lib/driver-heap.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/log-level.d.ts +21 -11
- package/lib/log-level.d.ts.map +1 -1
- package/lib/log-level.js +25 -14
- package/lib/log-level.js.map +1 -1
- package/lib/spawn-data-server.d.ts +6 -1
- package/lib/spawn-data-server.d.ts.map +1 -1
- package/lib/spawn-data-server.js +2 -1
- package/lib/spawn-data-server.js.map +1 -1
- package/lib/stderr-connection-logger.d.ts +12 -0
- package/lib/stderr-connection-logger.d.ts.map +1 -0
- package/lib/stderr-connection-logger.js +16 -0
- package/lib/stderr-connection-logger.js.map +1 -0
- package/lib/testing/echo-server.js +8 -1
- package/lib/testing/echo-server.js.map +1 -1
- package/package.json +39 -39
- package/src/commands/analyze-heap.ts +4 -1
- package/src/commands/ast-ground-truth-args.ts +15 -12
- package/src/commands/ast-ground-truth.ts +1 -1
- package/src/commands/generate-ast-builder.ts +246 -0
- package/src/commands/generate-transfer-model-args.ts +11 -1
- package/src/commands/generate-transfer-model-config.ts +3 -1
- package/src/commands/generate-transfer-model.ts +25 -3
- package/src/commands/harness-args.ts +73 -28
- package/src/commands/headless-harness.ts +86 -26
- package/src/commands/init-templates.ts +216 -97
- package/src/commands/init-workspace.ts +31 -7
- package/src/commands/init.ts +21 -14
- package/src/commands/lint-grammar-args.ts +17 -13
- package/src/commands/lint-grammar.ts +1 -1
- package/src/commands/measure-memory-args.ts +25 -13
- package/src/commands/measure-memory-driver.ts +3 -2
- package/src/commands/measure-memory.ts +1 -1
- package/src/commands/model-docs-args.ts +16 -13
- package/src/commands/model-docs.ts +1 -1
- package/src/commands/projects-args.ts +5 -4
- package/src/commands/projects.ts +4 -6
- package/src/commands/query-args.ts +5 -4
- package/src/commands/query.ts +4 -6
- package/src/commands/reflect-args.ts +17 -13
- package/src/commands/reflect.ts +1 -1
- package/src/commands/save-args.ts +6 -3
- package/src/commands/save.ts +49 -10
- package/src/commands/validate-args.ts +17 -13
- package/src/commands/validate.ts +1 -1
- package/src/commands/watch-args.ts +6 -3
- package/src/commands/watch.ts +28 -7
- package/src/driver-heap.ts +65 -0
- package/src/index.ts +1 -0
- package/src/log-level.ts +42 -14
- package/src/spawn-data-server.ts +14 -2
- package/src/stderr-connection-logger.ts +18 -0
- package/src/testing/echo-server.ts +10 -2
|
@@ -71,15 +71,6 @@
|
|
|
71
71
|
* over; the adopter's own formatter settles it.
|
|
72
72
|
*/
|
|
73
73
|
import { readCliVersion } from '../cli-version.js';
|
|
74
|
-
/**
|
|
75
|
-
* The version every framework package carries before the first release.
|
|
76
|
-
*
|
|
77
|
-
* A scaffold made by a CLI still at this version pins a range the registry
|
|
78
|
-
* cannot serve, so the emitted README keeps its yalc note and `init` keeps its
|
|
79
|
-
* install warning while — and only while — it holds: from a published CLI the
|
|
80
|
-
* derived pins resolve and either note would be false as printed.
|
|
81
|
-
*/
|
|
82
|
-
export const UNPUBLISHED_FRAMEWORK_VERSION = '0.0.0';
|
|
83
74
|
/**
|
|
84
75
|
* The version `init` pins every `@hydranium/*` dependency at: the scaffolding
|
|
85
76
|
* CLI's own.
|
|
@@ -156,7 +147,7 @@ function columnsFor(composition) {
|
|
|
156
147
|
}
|
|
157
148
|
/**
|
|
158
149
|
* A named import on one line while it fits the column budget, else one symbol
|
|
159
|
-
* per line. Emitted files are supposed to pass a
|
|
150
|
+
* per line. Emitted files are supposed to pass a format check as-is, and the
|
|
160
151
|
* generated-module import grows by one symbol per grammar.
|
|
161
152
|
*/
|
|
162
153
|
function importList(symbols, from, columns, typeOnly = false) {
|
|
@@ -204,7 +195,12 @@ const HEAD_FRAMEWORK_DEPENDENCIES = {
|
|
|
204
195
|
const HEAD_THIRD_PARTY_DEPENDENCIES = {
|
|
205
196
|
lsp: {
|
|
206
197
|
langium: '4.3.1',
|
|
207
|
-
|
|
198
|
+
// Exact, as are the protocol and transport it pins, so Langium and the
|
|
199
|
+
// framework share their copies; across copies, an error a handler throws
|
|
200
|
+
// or returns loses its code, and a later patch can pin another protocol.
|
|
201
|
+
'vscode-languageserver': '10.0.1',
|
|
202
|
+
'vscode-jsonrpc': '9.0.0',
|
|
203
|
+
'vscode-languageserver-protocol': '3.18.1'
|
|
208
204
|
},
|
|
209
205
|
data: {},
|
|
210
206
|
glsp: {
|
|
@@ -216,6 +212,22 @@ const HEAD_THIRD_PARTY_DEPENDENCIES = {
|
|
|
216
212
|
'reflect-metadata': '~0.2.2'
|
|
217
213
|
}
|
|
218
214
|
};
|
|
215
|
+
/** Whether an npm version is 11.6.0 or later, the first that installs `vitest` 4.1's peer set; `11.6.0-rc.1` is earlier. */
|
|
216
|
+
function installsVitest41(npmVersion) {
|
|
217
|
+
const [release, prerelease] = (npmVersion ?? '0.0.0').split('-', 2);
|
|
218
|
+
const [major, minor, patch] = release.split('.').map(Number);
|
|
219
|
+
return major > 11 || (major === 11 && (minor > 6 || (minor === 6 && (patch > 0 || prerelease === undefined))));
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Whether the scaffold holds `vitest` below 4.1, whose peer set crashes npm
|
|
223
|
+
* before 11.6 (every npm a Node 22 release bundles) on the first install. Only a
|
|
224
|
+
* workspace root declaring a newer npm lifts it, and only when `init` runs under
|
|
225
|
+
* an npm known to be newer: npm does not enforce `packageManager`.
|
|
226
|
+
*/
|
|
227
|
+
function pinsVitest(composition) {
|
|
228
|
+
const workspace = composition.packaging.workspace;
|
|
229
|
+
return !(installsVitest41(workspace?.packageManagerNpm) && installsVitest41(workspace?.npmVersion));
|
|
230
|
+
}
|
|
219
231
|
/** The dependency block for a head set, merged and sorted as npm writes it. */
|
|
220
232
|
function dependencyBlock(composition, indent) {
|
|
221
233
|
const merged = {};
|
|
@@ -234,7 +246,7 @@ function dependencyBlock(composition, indent) {
|
|
|
234
246
|
// npm convention, and `npm install` rewrites `package.json` at two spaces
|
|
235
247
|
// regardless — so three would not survive the adopter's first install.
|
|
236
248
|
//
|
|
237
|
-
// The KEY ORDER is
|
|
249
|
+
// The KEY ORDER is the one Oxfmt's `sortPackageJson` canonicalises to, `private`
|
|
238
250
|
// before `license` included. Any other order is rewritten by the scaffolded
|
|
239
251
|
// project's own first `format` run — a diff on a file the adopter never touched
|
|
240
252
|
// — and it makes a byte-compare against a formatted copy of this emission
|
|
@@ -265,16 +277,9 @@ const PACKAGE_JSON = `{
|
|
|
265
277
|
"version": "0.0.0",
|
|
266
278
|
__PRIVATE__ "description": "__NAME__ language server, built with the Hydranium framework.",
|
|
267
279
|
"keywords": [
|
|
268
|
-
|
|
269
|
-
"langium",
|
|
270
|
-
"language-server",
|
|
271
|
-
"__PROJECT_ID__"
|
|
272
|
-
],
|
|
280
|
+
__KEYWORDS__ ],
|
|
273
281
|
"license": "UNLICENSED",
|
|
274
282
|
"author": "",
|
|
275
|
-
"type": "module",
|
|
276
|
-
"main": "lib/index.js",
|
|
277
|
-
"types": "lib/index.d.ts",
|
|
278
283
|
"bin": {
|
|
279
284
|
__BIN__ },
|
|
280
285
|
"files": [
|
|
@@ -282,11 +287,14 @@ __BIN__ },
|
|
|
282
287
|
"src",
|
|
283
288
|
"syntaxes"
|
|
284
289
|
],
|
|
290
|
+
"type": "module",
|
|
291
|
+
"main": "lib/index.js",
|
|
292
|
+
"types": "lib/index.d.ts",
|
|
285
293
|
"scripts": {
|
|
286
294
|
"build": "npm run generate && tsc",
|
|
287
|
-
"clean": "rimraf lib syntaxes src/language-server/generated src/language-server/generated-
|
|
295
|
+
"clean": "rimraf lib syntaxes src/language-server/generated src/language-server/generated-hydranium tsconfig.tsbuildinfo",
|
|
288
296
|
"generate": "npm run langium:generate && npm run generate:transfer-model",
|
|
289
|
-
"generate:transfer-model": "hydranium-cli generate-transfer-model --ast-file src/language-server/generated/ast.ts --augmentation-file src/language-server/ast.ts --out-file src/language-server/generated-
|
|
297
|
+
"generate:transfer-model": "hydranium-cli generate-transfer-model --ast-file src/language-server/generated/ast.ts --augmentation-file src/language-server/ast.ts --out-file src/language-server/generated-hydranium/transfer-model.ts --ast-builder-file src/language-server/generated-hydranium/ast-builder.ts --element-type-name __NAME__Element --terminals-name __NAME__Terminals --regen-command \\"Run: __NPM_RUN__ generate:transfer-model\\"",
|
|
290
298
|
"langium:generate": "langium generate",
|
|
291
299
|
"langium:watch": "langium generate --watch",
|
|
292
300
|
__LINT__ "start": "node lib/main.js --stdio",
|
|
@@ -302,8 +310,8 @@ __DEPENDENCIES__
|
|
|
302
310
|
"@types/node": "^22.0.0",
|
|
303
311
|
"langium-cli": "4.3.0",
|
|
304
312
|
"rimraf": "^5.0.0",
|
|
305
|
-
"typescript": "^
|
|
306
|
-
"vitest": "
|
|
313
|
+
"typescript": "^7.0.2",
|
|
314
|
+
"vitest": "__VITEST__"
|
|
307
315
|
},
|
|
308
316
|
"engines": {
|
|
309
317
|
"node": ">=22.13"
|
|
@@ -331,7 +339,7 @@ function npmRun(composition) {
|
|
|
331
339
|
* name. Without the second key a scaffolded project has no command line that
|
|
332
340
|
* reaches its own data head at all.
|
|
333
341
|
*
|
|
334
|
-
* Alphabetical, because `
|
|
342
|
+
* Alphabetical, because Oxfmt's `sortPackageJson` sorts `bin` and any other
|
|
335
343
|
* order is rewritten by the scaffolded project's first `format` run.
|
|
336
344
|
*/
|
|
337
345
|
function binBlock(composition) {
|
|
@@ -345,15 +353,29 @@ function binBlock(composition) {
|
|
|
345
353
|
function packageJson(composition) {
|
|
346
354
|
const { scope } = composition.packaging;
|
|
347
355
|
const packageName = scope === undefined ? composition.projectId : `${scope}/${composition.projectId}`;
|
|
348
|
-
|
|
356
|
+
const keywords = ['hydranium', 'langium', 'language-server', composition.projectId]
|
|
357
|
+
.sort()
|
|
358
|
+
.map(keyword => ` ${JSON.stringify(keyword)}`)
|
|
359
|
+
.join(',\n') + '\n';
|
|
360
|
+
// Emitted only where a root lint config says the repo lints. The absence is
|
|
349
361
|
// the dangerous direction: a task runner runs a script only where one is
|
|
350
362
|
// declared, so a package with no `lint` is SKIPPED rather than reported, and
|
|
351
363
|
// that reads as a clean lint. A wrong invocation is one visible line to edit.
|
|
352
|
-
const
|
|
364
|
+
const workspace = composition.packaging.workspace;
|
|
365
|
+
const oxlintConfig = workspace?.oxlintConfig === undefined
|
|
366
|
+
? undefined
|
|
367
|
+
: `${'../'.repeat(workspace.targetPath.split('/').length)}${workspace.oxlintConfig}`;
|
|
368
|
+
const lint = workspace?.oxlintConfig !== undefined
|
|
369
|
+
? ` "lint": "oxlint --report-unused-disable-directives --format stylish --config ${oxlintConfig} src test --max-warnings 0",\n`
|
|
370
|
+
: workspace?.eslintConfig !== undefined
|
|
371
|
+
? ' "lint": "eslint src test --max-warnings 0",\n'
|
|
372
|
+
: '';
|
|
353
373
|
return project(PACKAGE_JSON, composition)
|
|
354
374
|
.replace('__PACKAGE_NAME__', packageName)
|
|
375
|
+
.replace('__KEYWORDS__', keywords)
|
|
355
376
|
.replace('__BIN__', binBlock(composition))
|
|
356
377
|
.replace('__LINT__', lint)
|
|
378
|
+
.replace('__VITEST__', pinsVitest(composition) ? '~4.0.18' : '^4.0.0')
|
|
357
379
|
.replace('__PRIVATE__', composition.packaging.private ? ' "private": true,\n' : '')
|
|
358
380
|
.replace('__NPM_RUN__', npmRun(composition))
|
|
359
381
|
.replace('__FRAMEWORK_PIN__', frameworkPin(composition))
|
|
@@ -406,6 +428,11 @@ const TSCONFIG_COMPILER_OPTIONS = [
|
|
|
406
428
|
['outDir', 'lib'],
|
|
407
429
|
['strict', true],
|
|
408
430
|
['esModuleInterop', true],
|
|
431
|
+
// A server that renders its own user-facing messages loads a catalogue, and
|
|
432
|
+
// a catalogue is JSON. Without this the import does not resolve at all, and
|
|
433
|
+
// without the `include` glob below a composite project rejects it with
|
|
434
|
+
// TS6307 naming neither cause.
|
|
435
|
+
['resolveJsonModule', true],
|
|
409
436
|
['skipLibCheck', true],
|
|
410
437
|
['declaration', true],
|
|
411
438
|
['experimentalDecorators', true],
|
|
@@ -443,7 +470,7 @@ function tsconfigJson(composition) {
|
|
|
443
470
|
];
|
|
444
471
|
const extendsLine = workspace?.baseTsconfig === undefined ? '' : ` "extends": "${workspace.baseTsconfig}",\n`;
|
|
445
472
|
const body = options.map(([key, value]) => ` "${key}": ${JSON.stringify(value)}`).join(',\n');
|
|
446
|
-
return `{\n${extendsLine} "compilerOptions": {\n${body}\n },\n "include": ["src"]\n}\n`;
|
|
473
|
+
return `{\n${extendsLine} "compilerOptions": {\n${body}\n },\n "include": ["src", "src/**/*.json"]\n}\n`;
|
|
447
474
|
}
|
|
448
475
|
// `isolatedModules` is what makes this check agree with the transform that
|
|
449
476
|
// actually runs the tests. `npm test` is `typecheck:test && vitest run`, and
|
|
@@ -460,7 +487,7 @@ const TSCONFIG_TEST = `{
|
|
|
460
487
|
"isolatedModules": true,
|
|
461
488
|
"types": ["node"]
|
|
462
489
|
},
|
|
463
|
-
"include": ["src", "test"]
|
|
490
|
+
"include": ["src", "test", "src/**/*.json"]
|
|
464
491
|
}
|
|
465
492
|
`;
|
|
466
493
|
const VITEST_CONFIG = `import { defineConfig } from 'vitest/config';
|
|
@@ -644,13 +671,35 @@ export type __NAME__Services = LangiumServices &
|
|
|
644
671
|
LspServerAddedServices & {
|
|
645
672
|
shared: __NAME__SharedServices;
|
|
646
673
|
};
|
|
674
|
+
|
|
675
|
+
/** What a host or a test may vary about this composition. */
|
|
676
|
+
export interface __NAME__Options {
|
|
677
|
+
/**
|
|
678
|
+
* Shared modules layered in after the framework's own bindings.
|
|
679
|
+
*
|
|
680
|
+
* The framework constructs most shared services with no options —
|
|
681
|
+
* \`DocumentBuilder: services => new HydraniumDocumentBuilder(services)\` — so
|
|
682
|
+
* rebinding the slot is the only way to boot one configured differently, and
|
|
683
|
+
* a factory that hard-codes its composition leaves a test nowhere to do it.
|
|
684
|
+
* That is what this is for: pass a module binding \`workspace.DocumentBuilder\`
|
|
685
|
+
* to exercise a builder option, or to substitute a subclass.
|
|
686
|
+
*
|
|
687
|
+
* Composed LAST, after \`__NAME__SharedModule\`, so it wins over every other
|
|
688
|
+
* tier including this file's own bindings — which is what makes it usable for
|
|
689
|
+
* a slot the adopter overrides. Production code should not reach for it.
|
|
690
|
+
*/
|
|
691
|
+
readonly extraSharedModules?: ReadonlyArray<Module<__NAME__SharedServices, DeepPartial<__NAME__SharedServices>>>;
|
|
692
|
+
}
|
|
647
693
|
${configurationRoot}
|
|
648
694
|
${sharedModule}
|
|
649
695
|
|
|
650
696
|
${languageModules}
|
|
651
697
|
|
|
652
698
|
/** Compose the Langium DI tree for __NAME__ — returns the shared + language services. */
|
|
653
|
-
export function create__NAME__Services(
|
|
699
|
+
export function create__NAME__Services(
|
|
700
|
+
context: Partial<ServerModuleContext> = EmptyFileSystem,
|
|
701
|
+
options: __NAME__Options = {}
|
|
702
|
+
): {
|
|
654
703
|
shared: __NAME__SharedServices;
|
|
655
704
|
${returnType}
|
|
656
705
|
} {
|
|
@@ -660,7 +709,8 @@ ${returnType}
|
|
|
660
709
|
sharedModules: {
|
|
661
710
|
generated: __NAME__GeneratedSharedModule,
|
|
662
711
|
adopter: __NAME__SharedModule,
|
|
663
|
-
extra: [createLspServerSharedModule(fullContext)]
|
|
712
|
+
extra: [createLspServerSharedModule(fullContext)],
|
|
713
|
+
overrides: options.extraSharedModules
|
|
664
714
|
},
|
|
665
715
|
languageModules: {
|
|
666
716
|
generated: ${primary.grammar}GeneratedModule,
|
|
@@ -724,9 +774,9 @@ const SERIALIZER = `// Concrete-syntax emitter for __GRAMMAR__ — the parser's
|
|
|
724
774
|
//
|
|
725
775
|
// Without it every structured write fails: the framework's default binding at
|
|
726
776
|
// \`services.serializer.Serializer\` THROWS, because a concrete syntax is
|
|
727
|
-
// language knowledge no framework can derive. \`
|
|
728
|
-
// the data head's \`saveModelDocument\` and a GLSP \`SaveModelAction\`
|
|
729
|
-
// it.
|
|
777
|
+
// language knowledge no framework can derive. A client session's \`update\` /
|
|
778
|
+
// \`save\`, the data head's \`saveModelDocument\` and a GLSP \`SaveModelAction\`
|
|
779
|
+
// all reach it.
|
|
730
780
|
//
|
|
731
781
|
// \`AbstractSerializer\`'s generic property walk lays out FORMAT-structured
|
|
732
782
|
// output — its YAML and JSON subclasses are what it exists for — and cannot
|
|
@@ -902,7 +952,7 @@ import { startGlspServer } from '@hydranium/glsp-server/node';
|
|
|
902
952
|
// \`TransferElement\` structurally, so naming the AST type here compiles fine and
|
|
903
953
|
// silently tells every typed client that a reference is a resolvable object
|
|
904
954
|
// rather than a name.
|
|
905
|
-
${importList(roots, './language-server/generated-
|
|
955
|
+
${importList(roots, './language-server/generated-hydranium/transfer-model.js', columns, true)}
|
|
906
956
|
`
|
|
907
957
|
: '';
|
|
908
958
|
// The commands live in `head-ports.ts`, not here: a host shell has to name
|
|
@@ -979,11 +1029,17 @@ void glspServer;
|
|
|
979
1029
|
// than a library entry — import \`./index.js\` instead to compose the language.
|
|
980
1030
|
|
|
981
1031
|
${reflectImport}${glspImports}${importList(coreNodeSymbols, '@hydranium/core/node', columns)}
|
|
982
|
-
${data ? "import { DataServer } from '@hydranium/data-server';\n" : ''}
|
|
1032
|
+
${data ? "import { DataServer } from '@hydranium/data-server';\n" : ''}// The framework's entry point, NOT Langium's \`@hydranium/langium/lsp\` one. It is
|
|
1033
|
+
// signature-compatible and delegates straight through; what it adds first is
|
|
1034
|
+
// \`assertLspHeadComposed\`, which fails the start if the LSP head's SHARED module
|
|
1035
|
+
// was never composed. Reaching for Langium's is the natural mistake and it is
|
|
1036
|
+
// silent: the server boots, links and completes, while echo suppression, the
|
|
1037
|
+
// didChangeContent debounce and the last-client-close rebuild are all inert.
|
|
1038
|
+
import { startLanguageServer, withHydraniumLspFeatures } from '@hydranium/core/lsp';
|
|
983
1039
|
import { ProposedFeatures, createConnection } from 'vscode-languageserver/node';
|
|
984
1040
|
${diagramImports}${transferImports}import { create__NAME__Services } from './language-server/__PROJECT_ID__-module.js';
|
|
985
1041
|
${portCommands === '' ? '' : '\n' + portCommands}
|
|
986
|
-
const connection = createConnection(ProposedFeatures.all);
|
|
1042
|
+
const connection = createConnection(withHydraniumLspFeatures(ProposedFeatures.all));
|
|
987
1043
|
const { shared } = create__NAME__Services({ connection, ...NodeFileSystem });
|
|
988
1044
|
startLanguageServer(shared);
|
|
989
1045
|
${dataBlock}${glspBlock}`;
|
|
@@ -1031,7 +1087,7 @@ function dataServerMainFile(composition) {
|
|
|
1031
1087
|
${importList(['NodeFileSystem', 'startStdioServer'], '@hydranium/core/node', columns)}
|
|
1032
1088
|
import { DataServer } from '@hydranium/data-server';
|
|
1033
1089
|
// The TRANSFER root${plural}, not the AST one${plural} — same reasoning as \`main.ts\`.
|
|
1034
|
-
${importList(roots, './language-server/generated-
|
|
1090
|
+
${importList(roots, './language-server/generated-hydranium/transfer-model.js', columns, true)}
|
|
1035
1091
|
import { create__NAME__Services } from './language-server/__PROJECT_ID__-module.js';
|
|
1036
1092
|
|
|
1037
1093
|
const { shared } = create__NAME__Services({ ...NodeFileSystem });
|
|
@@ -1147,8 +1203,8 @@ function serializationTest(composition) {
|
|
|
1147
1203
|
const transferTypes = composition.grammars.map(grammar => `${grammar.entryRule} as Transfer${grammar.entryRule}`);
|
|
1148
1204
|
const text = `// Round-trips each grammar through its serializer: parse the source, serialize
|
|
1149
1205
|
// the model, compare the text. The serializer is the parser's inverse, so this
|
|
1150
|
-
// is the assertion that keeps \`
|
|
1151
|
-
// language server can read back.
|
|
1206
|
+
// is the assertion that keeps a client session's \`update\` / \`save\` writing
|
|
1207
|
+
// files the language server can read back.
|
|
1152
1208
|
//
|
|
1153
1209
|
// The transfer case is the one that catches the mistake worth catching.
|
|
1154
1210
|
// \`ModelService.modelToText\` short-circuits only a RAW STRING, so a typed model
|
|
@@ -1158,7 +1214,7 @@ function serializationTest(composition) {
|
|
|
1158
1214
|
import { parseHelper } from '@hydranium/core/testing';
|
|
1159
1215
|
import { describe, expect, it } from 'vitest';
|
|
1160
1216
|
${importList(astTypes, '../src/language-server/ast.js', columns, true)}
|
|
1161
|
-
${importList(transferTypes, '../src/language-server/generated-
|
|
1217
|
+
${importList(transferTypes, '../src/language-server/generated-hydranium/transfer-model.js', columns, true)}
|
|
1162
1218
|
import { createServices } from '../src/services.js';
|
|
1163
1219
|
|
|
1164
1220
|
${composition.grammars.map(grammar => render(SERIALIZATION_SUITE, composition, grammar)).join('\n\n')}
|
|
@@ -1317,20 +1373,6 @@ function readme(composition) {
|
|
|
1317
1373
|
'',
|
|
1318
1374
|
'## Getting started',
|
|
1319
1375
|
'',
|
|
1320
|
-
// Conditional on the pin this scaffold actually carries — see
|
|
1321
|
-
// `UNPUBLISHED_FRAMEWORK_VERSION`.
|
|
1322
|
-
...(composition.frameworkVersion === UNPUBLISHED_FRAMEWORK_VERSION
|
|
1323
|
-
? [
|
|
1324
|
-
'> **Pre-publish note.** `@hydranium/*` is not on npm yet, so the `0.0.0`',
|
|
1325
|
-
'> pins below are placeholders and `npm install` will fail with a 404 until',
|
|
1326
|
-
'> the framework is released. Until then, supply the packages from a local',
|
|
1327
|
-
'> framework checkout with [yalc](https://github.com/wclr/yalc) — a plain',
|
|
1328
|
-
'> `file:` path or `npm link` is not enough, because the framework packages',
|
|
1329
|
-
'> depend on each other by version and npm would try to fetch those from the',
|
|
1330
|
-
'> registry too.',
|
|
1331
|
-
''
|
|
1332
|
-
]
|
|
1333
|
-
: []),
|
|
1334
1376
|
'```bash',
|
|
1335
1377
|
'npm install',
|
|
1336
1378
|
'npm run langium:generate # generate the AST from the grammar',
|
|
@@ -1438,6 +1480,24 @@ function readme(composition) {
|
|
|
1438
1480
|
'atomic set and depends on a single physical copy, so a floating range can',
|
|
1439
1481
|
'silently resolve a second one.',
|
|
1440
1482
|
'',
|
|
1483
|
+
'`vscode-languageserver` is pinned to `10.0.1`, and',
|
|
1484
|
+
'`vscode-languageserver-protocol` and `vscode-jsonrpc` to the `3.18.1` and',
|
|
1485
|
+
'`9.0.0` it pins, so Langium, the LSP connection and the framework share one',
|
|
1486
|
+
'copy of each. With two, an error a Langium handler returns, such as a request',
|
|
1487
|
+
'for a document the server does not have, reaches the client as a result, and a',
|
|
1488
|
+
'framework error your own LSP handler throws loses its code. The Langium 4.4',
|
|
1489
|
+
'upgrade',
|
|
1490
|
+
'([eclipse-emfcloud/hydranium#142](https://github.com/eclipse-emfcloud/hydranium/issues/142))',
|
|
1491
|
+
'replaces these pins.',
|
|
1492
|
+
'',
|
|
1493
|
+
...(pinsVitest(composition)
|
|
1494
|
+
? [
|
|
1495
|
+
'`vitest` is held below 4.1, whose peer set crashes the npm every Node 22',
|
|
1496
|
+
'release bundles. Raise it once every npm that installs this project is',
|
|
1497
|
+
'11.6 or later.',
|
|
1498
|
+
''
|
|
1499
|
+
]
|
|
1500
|
+
: []),
|
|
1441
1501
|
'## If your repo gates license headers',
|
|
1442
1502
|
'',
|
|
1443
1503
|
'The emitted `.ts` files carry no copyright header — the scaffold cannot know',
|
|
@@ -1524,8 +1584,11 @@ export class __GRAMMAR__GlspState extends FullTextHydraniumGlspState<__ENTRY_RUL
|
|
|
1524
1584
|
`;
|
|
1525
1585
|
const storage = `// Source-model storage for the __GRAMMAR__ diagram, inheriting both framework
|
|
1526
1586
|
// defaults: \`loadSourceModel\` (open + settle + \`setSourceRoot\`) and
|
|
1527
|
-
// \`saveSourceModel\` (
|
|
1528
|
-
//
|
|
1587
|
+
// \`saveSourceModel\` (flush the store's text for the primary and every tracked
|
|
1588
|
+
// secondary through the diagram's client session).
|
|
1589
|
+
//
|
|
1590
|
+
// No serializer runs on the save path — a save persists what the diagram's
|
|
1591
|
+
// operations already wrote to the store.
|
|
1529
1592
|
//
|
|
1530
1593
|
// The subclass exists so a bespoke load or save has a stable place to land.
|
|
1531
1594
|
|
|
@@ -1681,27 +1744,28 @@ export class __GRAMMAR__DiagramConfiguration implements DiagramConfiguration {
|
|
|
1681
1744
|
// read-only is a deletion the compiler checks, while read-only → editable is
|
|
1682
1745
|
// authoring against a seam you have not used yet.
|
|
1683
1746
|
//
|
|
1684
|
-
// **It
|
|
1685
|
-
// \`
|
|
1686
|
-
//
|
|
1687
|
-
//
|
|
1688
|
-
//
|
|
1689
|
-
//
|
|
1690
|
-
//
|
|
1691
|
-
// \`HydraniumGlspRecordingCommand\` over \`state.sourceModel\` instead — the same
|
|
1692
|
-
// binding the diagram's own save action needs.
|
|
1747
|
+
// **It edits the operation's working copy.** A handler runs inside an operation,
|
|
1748
|
+
// where \`sourceRoot\` is a copy of the built root: the recording command's
|
|
1749
|
+
// runnable appends to the copy, and the operation writes the copy's text through
|
|
1750
|
+
// the grammar's \`Serializer\` once, gated on the version the copy was made at,
|
|
1751
|
+
// with undo and redo applying that one change. A command that writes the
|
|
1752
|
+
// document itself instead reads no text off the copy, which has no \`$document\`,
|
|
1753
|
+
// and the operation's own write then overwrites it.
|
|
1693
1754
|
//
|
|
1694
1755
|
// **The drop location is discarded.** \`needsClientLayout\` is \`true\` and the
|
|
1695
1756
|
// starter grammar persists no bounds, so there is nowhere to put a coordinate: the
|
|
1696
1757
|
// node is appended at the end of the document and the client places it.
|
|
1697
1758
|
//
|
|
1698
1759
|
// Like \`types.ts\`, \`gmodel-factory.ts\` and \`diagram-configuration.ts\`, this file
|
|
1699
|
-
// knows the starter grammar's
|
|
1700
|
-
//
|
|
1760
|
+
// knows the starter grammar's shape — the \`nodes\` list and the \`__NODE_RULE__\`
|
|
1761
|
+
// it holds. Replacing the grammar means replacing these four together.
|
|
1701
1762
|
|
|
1702
1763
|
import { type Command, type CreateNodeOperation, JsonCreateNodeOperationHandler, type MaybePromise } from '@eclipse-glsp/server';
|
|
1764
|
+
import { appendChild } from '@hydranium/core';
|
|
1765
|
+
import { HydraniumGlspRecordingCommand } from '@hydranium/glsp-server';
|
|
1703
1766
|
import { findNextUnique } from '@hydranium/protocol';
|
|
1704
1767
|
import { injectable } from 'inversify';
|
|
1768
|
+
import type { __NODE_RULE__ } from '../../language-server/ast.js';
|
|
1705
1769
|
import { ${upper}_NODE_TYPE } from './types.js';
|
|
1706
1770
|
import type { __GRAMMAR__GlspState } from './state.js';
|
|
1707
1771
|
|
|
@@ -1720,34 +1784,14 @@ export class __GRAMMAR__CreateNodeOperationHandler extends JsonCreateNodeOperati
|
|
|
1720
1784
|
if (!this.elementTypeIds.includes(operation.elementTypeId)) {
|
|
1721
1785
|
return undefined;
|
|
1722
1786
|
}
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
before,
|
|
1727
|
-
findNextUnique(
|
|
1787
|
+
return new HydraniumGlspRecordingCommand(this.modelState, this.label, () => {
|
|
1788
|
+
const root = this.modelState.sourceRoot;
|
|
1789
|
+
const name = findNextUnique(
|
|
1728
1790
|
NODE_NAME_STEM,
|
|
1729
|
-
|
|
1730
|
-
)
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
// has exactly one field, so there is nothing to merge a concurrent edit into.
|
|
1734
|
-
return {
|
|
1735
|
-
execute: () => state.updateSourceModel({ text: after }),
|
|
1736
|
-
undo: () => state.updateSourceModel({ text: before }),
|
|
1737
|
-
redo: () => state.updateSourceModel({ text: after })
|
|
1738
|
-
};
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1741
|
-
/** The text the captured source root was parsed from — the baseline an edit appends to. */
|
|
1742
|
-
protected documentText(): string {
|
|
1743
|
-
return this.modelState.sourceRoot.$document?.textDocument.getText() ?? '';
|
|
1744
|
-
}
|
|
1745
|
-
|
|
1746
|
-
/** \`text\` with one more node declaration, under exactly one trailing newline. */
|
|
1747
|
-
protected withNode(text: string, name: string): string {
|
|
1748
|
-
const body = text.trimEnd();
|
|
1749
|
-
const declaration = \`node \${name}\`;
|
|
1750
|
-
return body.length === 0 ? \`\${declaration}\\n\` : \`\${body}\\n\${declaration}\\n\`;
|
|
1791
|
+
root.nodes.map(node => node.name)
|
|
1792
|
+
);
|
|
1793
|
+
appendChild(root, 'nodes', root.nodes, { $type: '__NODE_RULE__', name } as __NODE_RULE__);
|
|
1794
|
+
});
|
|
1751
1795
|
}
|
|
1752
1796
|
}
|
|
1753
1797
|
`;
|
|
@@ -1833,6 +1877,75 @@ export class __GRAMMAR__DiagramModule extends AbstractHydraniumGlspDiagramModule
|
|
|
1833
1877
|
binding.add(__GRAMMAR__CreateNodeOperationHandler);
|
|
1834
1878
|
}
|
|
1835
1879
|
}
|
|
1880
|
+
`;
|
|
1881
|
+
const diagramTest = `// The starter create-node handler, run the way a client runs it: an in-process
|
|
1882
|
+
// GLSP server opens a document, a create-node operation adds a node, and an undo
|
|
1883
|
+
// and a redo take it out and put it back. Every step must keep the nodes the
|
|
1884
|
+
// document already had, and its comments: the diagram writes the document from
|
|
1885
|
+
// its AST, which carries none.
|
|
1886
|
+
|
|
1887
|
+
import 'reflect-metadata';
|
|
1888
|
+
import { type Action, CreateNodeOperation, RedoAction, ServerModule, SetDirtyStateAction, UndoAction } from '@eclipse-glsp/server';
|
|
1889
|
+
import { initializeWorkspaceProgrammatically } from '@hydranium/core';
|
|
1890
|
+
import { makeScratchWorkspace, type ScratchWorkspace } from '@hydranium/core/testing/node';
|
|
1891
|
+
import { HydraniumGlspAppModule } from '@hydranium/glsp-server';
|
|
1892
|
+
import { type GlspHarness, makeGlspHarness } from '@hydranium/glsp-server/testing';
|
|
1893
|
+
import { waitFor } from '@hydranium/protocol/testing';
|
|
1894
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
1895
|
+
import { __GRAMMAR__DiagramModule } from '../src/glsp/__GRAMMAR_ID__/diagram-module.js';
|
|
1896
|
+
import type { __GRAMMAR__GlspState } from '../src/glsp/__GRAMMAR_ID__/state.js';
|
|
1897
|
+
import { ${upper}_DIAGRAM_TYPE, ${upper}_NODE_TYPE } from '../src/glsp/__GRAMMAR_ID__/types.js';
|
|
1898
|
+
import { createServices } from '../src/services.js';
|
|
1899
|
+
|
|
1900
|
+
let workspace: ScratchWorkspace | undefined;
|
|
1901
|
+
let diagram: GlspHarness<__GRAMMAR__GlspState> | undefined;
|
|
1902
|
+
|
|
1903
|
+
afterEach(() => {
|
|
1904
|
+
diagram?.dispose();
|
|
1905
|
+
workspace?.dispose();
|
|
1906
|
+
diagram = undefined;
|
|
1907
|
+
workspace = undefined;
|
|
1908
|
+
});
|
|
1909
|
+
|
|
1910
|
+
/** Send \`action\` and wait for the dirty state the server answers it with, which it sends once the edit is written. */
|
|
1911
|
+
async function send(harness: GlspHarness<__GRAMMAR__GlspState>, action: Action, reason: string): Promise<void> {
|
|
1912
|
+
const before = harness.actions.length;
|
|
1913
|
+
harness.dispatch(action);
|
|
1914
|
+
await waitFor(() => harness.actions.slice(before).some(sent => SetDirtyStateAction.is(sent) && sent.reason === reason), {
|
|
1915
|
+
message: \`no '\${reason}' dirty state\`
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
describe('__GRAMMAR__ diagram', () => {
|
|
1920
|
+
it('creates a node after the existing ones, keeping their comments, and undoes and redoes it', async () => {
|
|
1921
|
+
workspace = makeScratchWorkspace({ prefix: '__GRAMMAR_ID__-diagram-' });
|
|
1922
|
+
const original = '// keep this comment\\nnode first -> second\\n// about second\\nnode second';
|
|
1923
|
+
const file = workspace.write('model.__EXTENSION__', original);
|
|
1924
|
+
const { shared } = createServices();
|
|
1925
|
+
await initializeWorkspaceProgrammatically(shared, workspace.root);
|
|
1926
|
+
diagram = makeGlspHarness<__GRAMMAR__GlspState>({
|
|
1927
|
+
serverModule: new ServerModule().configureDiagramModule(new __GRAMMAR__DiagramModule()),
|
|
1928
|
+
diagramType: ${upper}_DIAGRAM_TYPE,
|
|
1929
|
+
appModules: [new HydraniumGlspAppModule({ shared })]
|
|
1930
|
+
});
|
|
1931
|
+
await diagram.start();
|
|
1932
|
+
await diagram.openDocument(file);
|
|
1933
|
+
const uri = workspace.uri('model.__EXTENSION__');
|
|
1934
|
+
const text = (): string | undefined => shared.workspace.TextDocuments.get(uri)?.getText();
|
|
1935
|
+
|
|
1936
|
+
await send(diagram, CreateNodeOperation.create(${upper}_NODE_TYPE), 'operation');
|
|
1937
|
+
const created = text();
|
|
1938
|
+
await send(diagram, UndoAction.create(), 'undo');
|
|
1939
|
+
const undone = text();
|
|
1940
|
+
await send(diagram, RedoAction.create(), 'redo');
|
|
1941
|
+
|
|
1942
|
+
expect({ created, undone, redone: text() }).toEqual({
|
|
1943
|
+
created: \`\${original}\\nnode Node\`,
|
|
1944
|
+
undone: original,
|
|
1945
|
+
redone: \`\${original}\\nnode Node\`
|
|
1946
|
+
});
|
|
1947
|
+
});
|
|
1948
|
+
});
|
|
1836
1949
|
`;
|
|
1837
1950
|
return [
|
|
1838
1951
|
{ path: `${dir}/types.ts`, content: render(types) },
|
|
@@ -1842,7 +1955,8 @@ export class __GRAMMAR__DiagramModule extends AbstractHydraniumGlspDiagramModule
|
|
|
1842
1955
|
{ path: `${dir}/gmodel-factory.ts`, content: render(factory) },
|
|
1843
1956
|
{ path: `${dir}/diagram-configuration.ts`, content: render(configuration) },
|
|
1844
1957
|
{ path: `${dir}/create-node-operation-handler.ts`, content: render(createHandler) },
|
|
1845
|
-
{ path: `${dir}/diagram-module.ts`, content: render(module) }
|
|
1958
|
+
{ path: `${dir}/diagram-module.ts`, content: render(module) },
|
|
1959
|
+
{ path: `test/${grammar.grammarId}-diagram.test.ts`, content: render(diagramTest) }
|
|
1846
1960
|
];
|
|
1847
1961
|
}
|
|
1848
1962
|
/**
|