@hydranium/cli 1.0.0-next.40 → 1.0.0-next.401
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 +102 -204
- package/bin/hydranium-cli.js +13 -0
- package/heap-analysis/heap/core/load.mjs +2 -2
- package/heap-analysis/heap/langium/langium.classifier.mjs +22 -11
- package/lib/cli-version.js.map +1 -1
- package/lib/cli.js +7 -2
- package/lib/cli.js.map +1 -1
- package/lib/commands/analyze-heap-args.d.ts.map +1 -1
- package/lib/commands/analyze-heap-args.js +1 -2
- 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-driver.js +4 -2
- package/lib/commands/ast-ground-truth-driver.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/client-session.d.ts +17 -0
- package/lib/commands/client-session.d.ts.map +1 -0
- package/lib/commands/client-session.js +27 -0
- package/lib/commands/client-session.js.map +1 -0
- package/lib/commands/create-args.d.ts +17 -0
- package/lib/commands/create-args.d.ts.map +1 -0
- package/lib/commands/create-args.js +53 -0
- package/lib/commands/create-args.js.map +1 -0
- package/lib/commands/create.d.ts +38 -0
- package/lib/commands/create.d.ts.map +1 -0
- package/lib/commands/create.js +43 -0
- package/lib/commands/create.js.map +1 -0
- package/lib/commands/delete-args.d.ts +17 -0
- package/lib/commands/delete-args.d.ts.map +1 -0
- package/lib/commands/delete-args.js +49 -0
- package/lib/commands/delete-args.js.map +1 -0
- package/lib/commands/delete.d.ts +30 -0
- package/lib/commands/delete.d.ts.map +1 -0
- package/lib/commands/delete.js +32 -0
- package/lib/commands/delete.js.map +1 -0
- package/lib/commands/generate-ast-builder.d.ts.map +1 -1
- package/lib/commands/generate-ast-builder.js +1 -10
- package/lib/commands/generate-ast-builder.js.map +1 -1
- package/lib/commands/generate-languages.d.ts +35 -0
- package/lib/commands/generate-languages.d.ts.map +1 -0
- package/lib/commands/generate-languages.js +105 -0
- package/lib/commands/generate-languages.js.map +1 -0
- package/lib/commands/generate-transfer-builder.d.ts +33 -0
- package/lib/commands/generate-transfer-builder.d.ts.map +1 -0
- package/lib/commands/generate-transfer-builder.js +86 -0
- package/lib/commands/generate-transfer-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 +20 -5
- 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 +8 -3
- package/lib/commands/generate-transfer-model-config.js.map +1 -1
- package/lib/commands/generate-transfer-model.d.ts +40 -9
- package/lib/commands/generate-transfer-model.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model.js +219 -67
- package/lib/commands/generate-transfer-model.js.map +1 -1
- package/lib/commands/generated-module-path.d.ts +16 -0
- package/lib/commands/generated-module-path.d.ts.map +1 -0
- package/lib/commands/generated-module-path.js +21 -0
- package/lib/commands/generated-module-path.js.map +1 -0
- package/lib/commands/harness-args.d.ts +44 -42
- package/lib/commands/harness-args.d.ts.map +1 -1
- package/lib/commands/harness-args.js +109 -27
- 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 +71 -19
- package/lib/commands/headless-harness.js.map +1 -1
- package/lib/commands/init-args.d.ts +2 -0
- package/lib/commands/init-args.d.ts.map +1 -1
- package/lib/commands/init-args.js +74 -31
- package/lib/commands/init-args.js.map +1 -1
- package/lib/commands/init-hosts.d.ts +24 -0
- package/lib/commands/init-hosts.d.ts.map +1 -0
- package/lib/commands/init-hosts.js +37 -0
- package/lib/commands/init-hosts.js.map +1 -0
- package/lib/commands/init-prompt.d.ts +3 -3
- package/lib/commands/init-prompt.d.ts.map +1 -1
- package/lib/commands/init-prompt.js +4 -5
- package/lib/commands/init-prompt.js.map +1 -1
- package/lib/commands/init-templates.d.ts +20 -14
- package/lib/commands/init-templates.d.ts.map +1 -1
- package/lib/commands/init-templates.js +2983 -752
- package/lib/commands/init-templates.js.map +1 -1
- package/lib/commands/init-wizard.d.ts +3 -0
- package/lib/commands/init-wizard.d.ts.map +1 -1
- package/lib/commands/init-wizard.js +46 -31
- package/lib/commands/init-wizard.js.map +1 -1
- package/lib/commands/init-workspace.d.ts +13 -11
- package/lib/commands/init-workspace.d.ts.map +1 -1
- package/lib/commands/init-workspace.js +21 -7
- package/lib/commands/init-workspace.js.map +1 -1
- package/lib/commands/init.d.ts +58 -22
- package/lib/commands/init.d.ts.map +1 -1
- package/lib/commands/init.js +203 -48
- package/lib/commands/init.js.map +1 -1
- package/lib/commands/kebab.d.ts +15 -0
- package/lib/commands/kebab.d.ts.map +1 -0
- package/lib/commands/kebab.js +17 -0
- package/lib/commands/kebab.js.map +1 -0
- 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-driver.js +2 -1
- package/lib/commands/lint-grammar-driver.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 +22 -11
- package/lib/commands/measure-memory-args.js.map +1 -1
- package/lib/commands/measure-memory-driver.js +5 -3
- 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-driver.js +2 -1
- package/lib/commands/model-docs-driver.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 +6 -5
- package/lib/commands/query-args.js.map +1 -1
- package/lib/commands/query.d.ts +6 -5
- package/lib/commands/query.d.ts.map +1 -1
- package/lib/commands/query.js +5 -4
- 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-driver.js +2 -1
- package/lib/commands/reflect-driver.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 +7 -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 +12 -23
- 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-driver.js +2 -1
- package/lib/commands/validate-driver.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 +5 -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 +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -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 +9 -4
- package/lib/spawn-data-server.d.ts.map +1 -1
- package/lib/spawn-data-server.js +5 -4
- 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 +9 -1
- package/lib/testing/echo-server.js.map +1 -1
- package/package.json +90 -39
- package/src/cli.ts +7 -2
- package/src/commands/analyze-heap-args.ts +1 -2
- package/src/commands/analyze-heap.ts +4 -1
- package/src/commands/ast-ground-truth-args.ts +15 -12
- package/src/commands/ast-ground-truth-driver.ts +4 -2
- package/src/commands/ast-ground-truth.ts +1 -1
- package/src/commands/client-session.ts +33 -0
- package/src/commands/create-args.ts +68 -0
- package/src/commands/create.ts +83 -0
- package/src/commands/delete-args.ts +64 -0
- package/src/commands/delete.ts +61 -0
- package/src/commands/generate-ast-builder.ts +1 -11
- package/src/commands/generate-languages.ts +132 -0
- package/src/commands/generate-transfer-builder.ts +101 -0
- package/src/commands/generate-transfer-model-args.ts +20 -5
- package/src/commands/generate-transfer-model-config.ts +8 -3
- package/src/commands/generate-transfer-model.ts +291 -65
- package/src/commands/generated-module-path.ts +22 -0
- package/src/commands/harness-args.ts +99 -31
- package/src/commands/headless-harness.ts +89 -28
- package/src/commands/init-args.ts +76 -31
- package/src/commands/init-hosts.ts +51 -0
- package/src/commands/init-prompt.ts +5 -6
- package/src/commands/init-templates.ts +3150 -761
- package/src/commands/init-wizard.ts +55 -31
- package/src/commands/init-workspace.ts +31 -16
- package/src/commands/init.ts +261 -63
- package/src/commands/kebab.ts +17 -0
- package/src/commands/lint-grammar-args.ts +17 -13
- package/src/commands/lint-grammar-driver.ts +2 -1
- package/src/commands/lint-grammar.ts +1 -1
- package/src/commands/measure-memory-args.ts +27 -14
- package/src/commands/measure-memory-driver.ts +5 -3
- package/src/commands/measure-memory.ts +1 -1
- package/src/commands/model-docs-args.ts +16 -13
- package/src/commands/model-docs-driver.ts +2 -1
- 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 +6 -4
- package/src/commands/query.ts +9 -9
- package/src/commands/reflect-args.ts +17 -13
- package/src/commands/reflect-driver.ts +2 -1
- package/src/commands/reflect.ts +1 -1
- package/src/commands/save-args.ts +7 -3
- package/src/commands/save.ts +24 -27
- package/src/commands/validate-args.ts +17 -13
- package/src/commands/validate-driver.ts +2 -1
- package/src/commands/validate.ts +1 -1
- package/src/commands/watch-args.ts +6 -3
- package/src/commands/watch.ts +7 -6
- package/src/driver-heap.ts +65 -0
- package/src/index.ts +2 -0
- package/src/log-level.ts +42 -14
- package/src/spawn-data-server.ts +17 -5
- package/src/stderr-connection-logger.ts +18 -0
- package/src/testing/echo-server.ts +11 -2
- package/templates/client/gitignore +3 -0
- package/templates/client/src/__GRAMMAR_ID__-diagram-module.ts +82 -0
- package/templates/editorconfig +15 -0
- package/templates/gitignore +1 -0
- package/templates/host-browser/esbuild.mjs +82 -0
- package/templates/host-browser/gitignore +4 -0
- package/templates/host-browser/hydranium-mark.svg +40 -0
- package/templates/host-browser/index.html +287 -0
- package/templates/host-browser/playwright.config.mts +24 -0
- package/templates/host-browser/src/data-status.ts +15 -0
- package/templates/host-browser/src/diagram-save.ts +60 -0
- package/templates/host-browser/src/diagram.ts +121 -0
- package/templates/host-browser/src/editor.ts +102 -0
- package/templates/host-browser/src/log.ts +14 -0
- package/templates/host-browser/src/monaco-editor-core-worker.d.ts +7 -0
- package/templates/host-browser/src/monaco-editor-worker.ts +10 -0
- package/templates/host-browser/src/posix-path-shim.ts +23 -0
- package/templates/host-browser/src/shown-file.ts +61 -0
- package/templates/host-browser/src/workspace.ts +5 -0
- package/templates/host-browser/tsconfig.e2e.json +16 -0
- package/templates/host-browser/tsconfig.page.json +16 -0
- package/templates/host-browser/tsconfig.worker.json +16 -0
- package/templates/host-theia-browser/esbuild.mjs +24 -0
- package/templates/host-theia-browser/gitignore +9 -0
- package/templates/host-theia-browser/playwright.config.mts +42 -0
- package/templates/host-theia-browser/start.mjs +50 -0
- package/templates/host-theia-browser/tsconfig.e2e.json +16 -0
- package/templates/host-theia-electron/esbuild.mjs +27 -0
- package/templates/host-theia-electron/gitignore +8 -0
- package/templates/host-theia-electron/playwright.config.mts +12 -0
- package/templates/host-theia-electron/start.mjs +47 -0
- package/templates/host-theia-electron/tsconfig.e2e.json +16 -0
- package/templates/host-vscode/esbuild.mjs +38 -0
- package/templates/host-vscode/gitignore +7 -0
- package/templates/host-vscode/playwright.config.mts +14 -0
- package/templates/host-vscode/src/__GRAMMAR_ID__-diagram-editor.ts +19 -0
- package/templates/host-vscode/src/show-model-command.ts +24 -0
- package/templates/host-vscode/src/webview/__GRAMMAR_ID__-diagram.ts +18 -0
- package/templates/host-vscode/src/webview/diagram.css +40 -0
- package/templates/host-vscode/start.mjs +22 -0
- package/templates/host-vscode/test/install-vscode.mts +21 -0
- package/templates/host-vscode/test/vscode-version.mts +10 -0
- package/templates/host-vscode/tsconfig.e2e.json +17 -0
- package/templates/host-vscode/tsconfig.json +19 -0
- package/templates/host-vscode/tsconfig.webview.json +17 -0
- package/templates/oxlintrc.json +4 -0
- package/templates/protocol/gitignore +3 -0
- package/templates/protocol/src/__GRAMMAR_ID__-diagram-types.ts +47 -0
- package/templates/server/gitignore +6 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/create-node-operation-handler.ts +62 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/delete-operation-handler.ts +63 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/gmodel-factory.ts +144 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/state.ts +18 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/storage.ts +16 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/submission-handler.ts +24 -0
- package/templates/server/src/grammar/common.langium +12 -0
- package/templates/server/src/language-server/__GRAMMAR_ID__-serializer.ts +53 -0
- package/templates/server/src/language-server/__GRAMMAR_ID__-validation.ts +30 -0
- package/templates/server/src/language-server/ast.ts +23 -0
- package/templates/server/src/node/services.ts +16 -0
- package/templates/server/test/__GRAMMAR_ID__-diagram.test.ts +403 -0
- package/templates/server/test/tsconfig.json +4 -0
- package/templates/server/tsconfig.test.json +10 -0
- package/templates/server/vitest.config.ts +14 -0
- package/templates/theia/gitignore +3 -0
- package/templates/theia/src/browser/__GRAMMAR_ID__-diagram-frontend-module.ts +65 -0
- package/templates/theia/src/browser/__PROJECT_ID__-connection-preload-module.ts +15 -0
- package/templates/theia/src/browser/__PROJECT_ID__-data-connection.ts +15 -0
- package/templates/theia/src/browser/__PROJECT_ID__-data-port.ts +11 -0
- package/templates/theia/src/browser/__PROJECT_ID__-glsp-client-contribution.ts +13 -0
- package/templates/theia/src/browser/__PROJECT_ID__-show-model-command.ts +51 -0
- package/templates/theia/src/common/__PROJECT_ID__-glsp-contribution.ts +3 -0
- package/templates/theia/src/node/__PROJECT_ID__-connection-backend-module.ts +12 -0
- package/templates/theia/src/node/__PROJECT_ID__-data-backend-module.ts +15 -0
- package/templates/theia/src/node/__PROJECT_ID__-glsp-backend-module.ts +16 -0
- package/templates/theia/style/diagram.css +20 -0
- package/templates/theia/tsconfig.json +24 -0
- package/templates/vscode-servers/gitignore +4 -0
- package/templates/vscode-servers/tsconfig.json +19 -0
- package/templates/workspace/nodes.__EXTENSION__ +5 -0
- package/templates/workspace/references.__EXTENSION__ +2 -0
|
@@ -21,6 +21,12 @@
|
|
|
21
21
|
* `bin` key, the DI module filename, and the data-server port command.
|
|
22
22
|
* - `__CONFIG_ROOT_CONST__` — SCREAMING_SNAKE project id, naming the
|
|
23
23
|
* `lsp.configurationRoot` constant a multi-grammar project binds.
|
|
24
|
+
* - `__PROTOCOL_PACKAGE__` — the protocol member's package name, scope
|
|
25
|
+
* included, which the server and every client import ids and wire types
|
|
26
|
+
* from.
|
|
27
|
+
* - `__SERVER_PACKAGE__` / `__CLIENT_PACKAGE__` — the server and client
|
|
28
|
+
* members' package names, which a host imports the language and the diagram
|
|
29
|
+
* definition from.
|
|
24
30
|
*
|
|
25
31
|
* GRAMMAR tokens, substituted once per grammar:
|
|
26
32
|
*
|
|
@@ -28,6 +34,10 @@
|
|
|
28
34
|
* Drives the PER-LANGUAGE generated symbols (`<grammar>GeneratedModule`,
|
|
29
35
|
* `<grammar>LanguageMetaData`).
|
|
30
36
|
* - `__GRAMMAR_ID__` — kebab grammar id: the `.langium` filename.
|
|
37
|
+
* - `__GRAMMAR_ID_CONST__` — SCREAMING_SNAKE grammar id, prefixing the
|
|
38
|
+
* diagram's type-id constants.
|
|
39
|
+
* - `__GRAMMAR_CAMEL__` — lowerCamelCase grammar name, naming the client's
|
|
40
|
+
* diagram module constant.
|
|
31
41
|
* - `__LANGUAGE_ID__` — kebab routing key: the `langium-config` entry id and
|
|
32
42
|
* its TextMate output.
|
|
33
43
|
* - `__EXTENSION__` — the grammar's FIRST file extension, without the dot.
|
|
@@ -48,10 +58,22 @@
|
|
|
48
58
|
* generator emits `interface <projectName>Element` as the base type every rule
|
|
49
59
|
* extends, which a rule of that name would collide with.
|
|
50
60
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
61
|
+
* The project is its packages and a starter workspace, each in its own
|
|
62
|
+
* directory: `server/` (the grammar, the language and its heads), `protocol/`
|
|
63
|
+
* (what the server and its clients both import, so a client never installs
|
|
64
|
+
* Langium), `client/` with a diagram (its host-neutral client side),
|
|
65
|
+
* `host-<name>/` per host, `vscode-servers/` with the VS Code host (the server
|
|
66
|
+
* launch it shares with a Theia app), and `workspace/` (starter model files
|
|
67
|
+
* every host and the CLI open). A standalone project adds a root manifest
|
|
68
|
+
* naming them as npm workspaces; a workspace member joins the surrounding root
|
|
69
|
+
* instead.
|
|
70
|
+
*
|
|
71
|
+
* A file that is fixed text with tokens lives in the `templates/` tree the
|
|
72
|
+
* package ships beside `lib`, at the path it is emitted at, tokens included
|
|
73
|
+
* (each ignore file without its dot); one computed from the composition is
|
|
74
|
+
* built here. The tree is read synchronously, so `runInit` stays synchronous,
|
|
75
|
+
* and it is neither formatted with the repo's settings nor given a license
|
|
76
|
+
* header, since either would change what `init` emits.
|
|
55
77
|
*
|
|
56
78
|
* Two conventions the templates follow deliberately:
|
|
57
79
|
*
|
|
@@ -70,16 +92,10 @@
|
|
|
70
92
|
* is what the detection cannot fix. A very long `--name` can still push a line
|
|
71
93
|
* over; the adopter's own formatter settles it.
|
|
72
94
|
*/
|
|
95
|
+
import { readFileSync } from 'node:fs';
|
|
73
96
|
import { readCliVersion } from '../cli-version.js';
|
|
74
|
-
|
|
75
|
-
|
|
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';
|
|
97
|
+
import { initMembers } from './init.js';
|
|
98
|
+
import { isTheiaHost } from './init-hosts.js';
|
|
83
99
|
/**
|
|
84
100
|
* The version `init` pins every `@hydranium/*` dependency at: the scaffolding
|
|
85
101
|
* CLI's own.
|
|
@@ -107,12 +123,52 @@ function frameworkPin(composition) {
|
|
|
107
123
|
function screamingSnake(projectId) {
|
|
108
124
|
return projectId.replace(/-/g, '_').toUpperCase();
|
|
109
125
|
}
|
|
126
|
+
const VSCODE_EXTENSION_MEMBERS = ['vscode-servers', 'host-vscode'];
|
|
127
|
+
/**
|
|
128
|
+
* A member's package name: `<id>-<member>`, under the scope when there is one,
|
|
129
|
+
* except for the VS Code extensions, whose scoped name `vsce` refuses to
|
|
130
|
+
* package.
|
|
131
|
+
*
|
|
132
|
+
* Suffixed even for the server, because a project of several packages has no
|
|
133
|
+
* member entitled to the bare id, and a later client or host would otherwise
|
|
134
|
+
* read as a part of the server.
|
|
135
|
+
*/
|
|
136
|
+
export function memberPackageName(composition, member) {
|
|
137
|
+
const { scope } = composition.packaging;
|
|
138
|
+
const name = `${composition.projectId}-${member}`;
|
|
139
|
+
return scope === undefined || VSCODE_EXTENSION_MEMBERS.includes(member) ? name : `${scope}/${name}`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The composition as one member sees it: inside a workspace, its placement
|
|
143
|
+
* sits one directory below the project's, so its `extends` and its lint
|
|
144
|
+
* config path reach one level further up.
|
|
145
|
+
*/
|
|
146
|
+
function forMember(composition, member) {
|
|
147
|
+
const workspace = composition.packaging.workspace;
|
|
148
|
+
if (workspace === undefined) {
|
|
149
|
+
return composition;
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
...composition,
|
|
153
|
+
packaging: {
|
|
154
|
+
...composition.packaging,
|
|
155
|
+
workspace: {
|
|
156
|
+
...workspace,
|
|
157
|
+
targetPath: `${workspace.targetPath}/${member}`,
|
|
158
|
+
baseTsconfig: workspace.baseTsconfig === undefined ? undefined : `../${workspace.baseTsconfig}`
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
110
163
|
/** Substitute the project-tier tokens. */
|
|
111
164
|
function project(text, composition) {
|
|
112
165
|
return text
|
|
113
166
|
.replace(/__NAME__/g, composition.name)
|
|
114
167
|
.replace(/__PROJECT_ID__/g, composition.projectId)
|
|
115
|
-
.replace(/__CONFIG_ROOT_CONST__/g, screamingSnake(composition.projectId))
|
|
168
|
+
.replace(/__CONFIG_ROOT_CONST__/g, screamingSnake(composition.projectId))
|
|
169
|
+
.replace(/__PROTOCOL_PACKAGE__/g, memberPackageName(composition, 'protocol'))
|
|
170
|
+
.replace(/__SERVER_PACKAGE__/g, memberPackageName(composition, 'server'))
|
|
171
|
+
.replace(/__CLIENT_PACKAGE__/g, memberPackageName(composition, 'client'));
|
|
116
172
|
}
|
|
117
173
|
/**
|
|
118
174
|
* Substitute the grammar-tier tokens for ONE grammar.
|
|
@@ -124,7 +180,9 @@ function project(text, composition) {
|
|
|
124
180
|
*/
|
|
125
181
|
function grammarTier(text, grammar) {
|
|
126
182
|
return text
|
|
183
|
+
.replace(/__GRAMMAR_ID_CONST__/g, screamingSnake(grammar.grammarId))
|
|
127
184
|
.replace(/__GRAMMAR_ID__/g, grammar.grammarId)
|
|
185
|
+
.replace(/__GRAMMAR_CAMEL__/g, grammar.grammar.charAt(0).toLowerCase() + grammar.grammar.slice(1))
|
|
128
186
|
.replace(/__GRAMMAR__/g, grammar.grammar)
|
|
129
187
|
.replace(/__LANGUAGE_ID__/g, grammar.languageId)
|
|
130
188
|
.replace(/__EXTENSION__/g, grammar.extensions[0])
|
|
@@ -135,6 +193,25 @@ function grammarTier(text, grammar) {
|
|
|
135
193
|
function render(text, composition, grammar) {
|
|
136
194
|
return grammarTier(project(text, composition), grammar);
|
|
137
195
|
}
|
|
196
|
+
/** The template tree, the same two levels up from `src/commands` and `lib/commands`. */
|
|
197
|
+
const TEMPLATES = new URL('../../templates/', import.meta.url);
|
|
198
|
+
/** One template file's text. */
|
|
199
|
+
function template(path) {
|
|
200
|
+
return readFileSync(new URL(path, TEMPLATES), 'utf-8');
|
|
201
|
+
}
|
|
202
|
+
/** A template emitted once per project at its own path, rendered with the project tokens. */
|
|
203
|
+
function projectTemplate(path, composition) {
|
|
204
|
+
return { path, content: project(template(path), composition) };
|
|
205
|
+
}
|
|
206
|
+
/** A template emitted once per grammar, its path rendered like its content. */
|
|
207
|
+
function grammarTemplate(path, composition, grammar) {
|
|
208
|
+
return { path: render(path, composition, grammar), content: render(template(path), composition, grammar) };
|
|
209
|
+
}
|
|
210
|
+
/** An ignore file, stored without its dot because `npm pack` drops a nested `.gitignore` and applies it as an ignore file. */
|
|
211
|
+
function ignoreFile(directory) {
|
|
212
|
+
const prefix = directory === '' ? '' : `${directory}/`;
|
|
213
|
+
return { path: `${prefix}.gitignore`, content: template(`${prefix}gitignore`) };
|
|
214
|
+
}
|
|
138
215
|
/** A comma-separated list of single-quoted TypeScript/JS string literals. */
|
|
139
216
|
function quotedList(values) {
|
|
140
217
|
return values.map(value => `'${value}'`).join(', ');
|
|
@@ -142,21 +219,22 @@ function quotedList(values) {
|
|
|
142
219
|
/**
|
|
143
220
|
* The column budget the emitted sources wrap at when nothing better is known.
|
|
144
221
|
*
|
|
145
|
-
* **Not "prettier's default"** — that is 80.
|
|
146
|
-
* a default was wrong in a way that mattered: no single width is stable for an
|
|
222
|
+
* **Not "prettier's default"** — that is 80. No single width is stable for an
|
|
147
223
|
* unknown repo, so emitted code only passes a formatter check relative to a
|
|
148
224
|
* config. A workspace scaffold detects the surrounding repo's `printWidth` and
|
|
149
225
|
* uses it (see {@link columnsFor}); a standalone one has no config to read and
|
|
150
|
-
* falls back here.
|
|
226
|
+
* falls back here. It is the framework's own width, so a fixed template, which
|
|
227
|
+
* wraps at no budget, reads the same in a standalone scaffold as in the
|
|
228
|
+
* examples this repo formats.
|
|
151
229
|
*/
|
|
152
|
-
const DEFAULT_COLUMNS =
|
|
230
|
+
const DEFAULT_COLUMNS = 140;
|
|
153
231
|
/** The width THIS composition wraps at: the detected workspace one, else {@link DEFAULT_COLUMNS}. */
|
|
154
232
|
function columnsFor(composition) {
|
|
155
233
|
return composition.packaging.workspace?.printWidth ?? DEFAULT_COLUMNS;
|
|
156
234
|
}
|
|
157
235
|
/**
|
|
158
236
|
* 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
|
|
237
|
+
* per line. Emitted files are supposed to pass a format check as-is, and the
|
|
160
238
|
* generated-module import grows by one symbol per grammar.
|
|
161
239
|
*/
|
|
162
240
|
function importList(symbols, from, columns, typeOnly = false) {
|
|
@@ -175,9 +253,13 @@ function arrayLiteral(elements, indent, columns) {
|
|
|
175
253
|
* The FRAMEWORK packages each head adds, carrying no version: every
|
|
176
254
|
* `@hydranium/*` pin is derived at scaffold time from {@link frameworkPin}, so
|
|
177
255
|
* none of them can name a version its siblings were not published at.
|
|
256
|
+
*
|
|
257
|
+
* `base` is every head set's: the services every head serves from are composed
|
|
258
|
+
* the same with or without an LSP head.
|
|
178
259
|
*/
|
|
179
260
|
const HEAD_FRAMEWORK_DEPENDENCIES = {
|
|
180
|
-
|
|
261
|
+
base: ['@hydranium/core', '@hydranium/langium', '@hydranium/protocol'],
|
|
262
|
+
lsp: [],
|
|
181
263
|
data: ['@hydranium/data-server'],
|
|
182
264
|
glsp: ['@hydranium/glsp-server']
|
|
183
265
|
};
|
|
@@ -197,44 +279,191 @@ const HEAD_FRAMEWORK_DEPENDENCIES = {
|
|
|
197
279
|
* `overrides` block exists to prevent — so a repo gate holds each entry here
|
|
198
280
|
* against the manifest that declares it.
|
|
199
281
|
*
|
|
200
|
-
* `langium` is required
|
|
282
|
+
* `langium` is required even though hand-written code goes through the
|
|
201
283
|
* `@hydranium/langium` chokepoint, because `langium-cli` emits direct imports
|
|
202
|
-
* into the generated files and regenerates them on every build.
|
|
284
|
+
* into the generated files and regenerates them on every build. The `vscode-*`
|
|
285
|
+
* packages are required peers of `@hydranium/core`, so they are `base` too.
|
|
203
286
|
*/
|
|
204
287
|
const HEAD_THIRD_PARTY_DEPENDENCIES = {
|
|
205
|
-
|
|
206
|
-
langium: '4.
|
|
207
|
-
|
|
288
|
+
base: {
|
|
289
|
+
langium: '4.4.0',
|
|
290
|
+
// Exact, as are the protocol and transport it pins, so Langium and the
|
|
291
|
+
// framework share their copies; across copies, an error a handler throws
|
|
292
|
+
// or returns loses its code, and a later patch can pin another protocol.
|
|
293
|
+
'vscode-languageserver': '10.1.2',
|
|
294
|
+
'vscode-jsonrpc': '9.0.3',
|
|
295
|
+
'vscode-languageserver-protocol': '3.18.4',
|
|
296
|
+
// The copy that protocol pins; a root without it takes the one Theia pins.
|
|
297
|
+
'vscode-languageserver-types': '3.18.4'
|
|
208
298
|
},
|
|
299
|
+
lsp: {},
|
|
209
300
|
data: {},
|
|
210
301
|
glsp: {
|
|
211
|
-
'@eclipse-glsp/graph': '2.
|
|
212
|
-
'@eclipse-glsp/server': '2.
|
|
213
|
-
// `^6.1.3` and NOT `^6.0.0`: `@eclipse-glsp/server
|
|
302
|
+
'@eclipse-glsp/graph': '2.8.0',
|
|
303
|
+
'@eclipse-glsp/server': '2.8.0',
|
|
304
|
+
// `^6.1.3` and NOT `^6.0.0`: `@eclipse-glsp/server` requires it, and
|
|
214
305
|
// `^6.0.0` resolved only because the hoisted copy happened to satisfy it.
|
|
215
306
|
inversify: '^6.1.3',
|
|
216
307
|
'reflect-metadata': '~0.2.2'
|
|
217
308
|
}
|
|
218
309
|
};
|
|
219
|
-
/**
|
|
310
|
+
/**
|
|
311
|
+
* What each head adds to the protocol member, which carries only what a
|
|
312
|
+
* client may install. Keyed by head because the `glsp` head implies a diagram,
|
|
313
|
+
* whose element ids extend GLSP's default type names.
|
|
314
|
+
*/
|
|
315
|
+
const PROTOCOL_THIRD_PARTY_DEPENDENCIES = {
|
|
316
|
+
lsp: {},
|
|
317
|
+
data: {},
|
|
318
|
+
glsp: { '@eclipse-glsp/protocol': '2.8.0' }
|
|
319
|
+
};
|
|
320
|
+
/** The client member's packages: the diagram definition and what it registers its elements with. */
|
|
321
|
+
const CLIENT_FRAMEWORK_DEPENDENCIES = ['@hydranium/glsp-client'];
|
|
322
|
+
const CLIENT_THIRD_PARTY_DEPENDENCIES = {
|
|
323
|
+
'@eclipse-glsp/client': '2.8.0',
|
|
324
|
+
inversify: '^6.1.3'
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* What each head adds to the browser host, which bundles the server into its
|
|
328
|
+
* worker and the head's client into its page. `base` is what every page needs.
|
|
329
|
+
*
|
|
330
|
+
* `monaco-editor-core` is exact for the reason `langium` is: Monaco's models
|
|
331
|
+
* live in one copy, and `@hydranium/client-browser` must reach the page's.
|
|
332
|
+
*/
|
|
333
|
+
const HOST_BROWSER_FRAMEWORK_DEPENDENCIES = {
|
|
334
|
+
base: ['@hydranium/client-browser', '@hydranium/core', '@hydranium/protocol'],
|
|
335
|
+
lsp: [],
|
|
336
|
+
data: ['@hydranium/data-server'],
|
|
337
|
+
glsp: ['@hydranium/glsp-client', '@hydranium/glsp-server']
|
|
338
|
+
};
|
|
339
|
+
const HOST_BROWSER_THIRD_PARTY_DEPENDENCIES = {
|
|
340
|
+
base: { 'vscode-jsonrpc': '9.0.3', 'vscode-languageserver-protocol': '3.18.4' },
|
|
341
|
+
lsp: { 'monaco-editor-core': '0.56.0' },
|
|
342
|
+
data: {},
|
|
343
|
+
glsp: { '@eclipse-glsp/server': '2.8.0', 'reflect-metadata': '~0.2.2' }
|
|
344
|
+
};
|
|
345
|
+
/** The browser host's tools: the bundler, the smoke tier and the type check. */
|
|
346
|
+
const HOST_BROWSER_DEV_DEPENDENCIES = {
|
|
347
|
+
'@playwright/test': '^1.55.0',
|
|
348
|
+
'@types/node': '^22.0.0',
|
|
349
|
+
esbuild: '^0.28.0',
|
|
350
|
+
rimraf: '^5.0.0',
|
|
351
|
+
typescript: '^7.0.2'
|
|
352
|
+
};
|
|
353
|
+
/** The language client both VS Code extensions start the server with. */
|
|
354
|
+
const VSCODE_LANGUAGE_CLIENT = { 'vscode-languageclient': '10.1.2' };
|
|
355
|
+
/** The VS Code API's types, at the oldest VS Code both extensions run in, which `engines` names too. */
|
|
356
|
+
const VSCODE_ENGINE = '^1.101.0';
|
|
357
|
+
/**
|
|
358
|
+
* What the GLSP head adds to the VS Code extension: the connector in the
|
|
359
|
+
* extension host and the diagram webview's starter, which bundles the client
|
|
360
|
+
* member.
|
|
361
|
+
*/
|
|
362
|
+
const HOST_VSCODE_GLSP_FRAMEWORK_DEPENDENCIES = [
|
|
363
|
+
'@hydranium/client-vscode',
|
|
364
|
+
'@hydranium/glsp-client',
|
|
365
|
+
'@hydranium/glsp-client-vscode',
|
|
366
|
+
'@hydranium/protocol'
|
|
367
|
+
];
|
|
368
|
+
const HOST_VSCODE_GLSP_THIRD_PARTY_DEPENDENCIES = {
|
|
369
|
+
'@eclipse-glsp/client': '2.8.0',
|
|
370
|
+
'@eclipse-glsp/vscode-integration': '2.8.0',
|
|
371
|
+
'@eclipse-glsp/vscode-integration-webview': '2.8.0',
|
|
372
|
+
inversify: '^6.1.3',
|
|
373
|
+
'vscode-jsonrpc': '9.0.3'
|
|
374
|
+
};
|
|
375
|
+
/** What the data head adds to the VS Code extension: the Show Model command's socket to it. */
|
|
376
|
+
const HOST_VSCODE_DATA_FRAMEWORK_DEPENDENCIES = [
|
|
377
|
+
'@hydranium/client-vscode',
|
|
378
|
+
'@hydranium/data-client-vscode',
|
|
379
|
+
'@hydranium/protocol'
|
|
380
|
+
];
|
|
381
|
+
// Exact, as the server's is: the socket's connection and the framework's must be one copy.
|
|
382
|
+
const HOST_VSCODE_DATA_THIRD_PARTY_DEPENDENCIES = { 'vscode-jsonrpc': '9.0.3' };
|
|
383
|
+
/** The VS Code extension's tools: the smoke tier, the download it runs in, the type check and the watch. */
|
|
384
|
+
const HOST_VSCODE_DEV_DEPENDENCIES = {
|
|
385
|
+
'@playwright/test': '^1.55.0',
|
|
386
|
+
'@types/node': '^22.0.0',
|
|
387
|
+
'@types/vscode': VSCODE_ENGINE,
|
|
388
|
+
'@vscode/test-electron': '^3.1.0',
|
|
389
|
+
concurrently: '^9.0.0',
|
|
390
|
+
rimraf: '^5.0.0',
|
|
391
|
+
typescript: '^7.0.2'
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* The exact pins of every member the composition emits, for a workspace root
|
|
395
|
+
* to declare too. npm installs a root's own dependencies at the top of the
|
|
396
|
+
* tree, so another member's version of one nests beneath that member instead of
|
|
397
|
+
* taking the place of the copy this package shares with the framework.
|
|
398
|
+
*/
|
|
399
|
+
export function workspaceRootPins(composition) {
|
|
400
|
+
const { heads } = composition;
|
|
401
|
+
const members = initMembers(heads, composition.hosts);
|
|
402
|
+
const pins = new Map([
|
|
403
|
+
...Object.entries(HEAD_THIRD_PARTY_DEPENDENCIES.base),
|
|
404
|
+
...heads.flatMap(head => [
|
|
405
|
+
...Object.entries(HEAD_THIRD_PARTY_DEPENDENCIES[head]),
|
|
406
|
+
...Object.entries(PROTOCOL_THIRD_PARTY_DEPENDENCIES[head])
|
|
407
|
+
]),
|
|
408
|
+
...(members.includes('client') ? Object.entries(CLIENT_THIRD_PARTY_DEPENDENCIES) : []),
|
|
409
|
+
...(members.includes('host-browser')
|
|
410
|
+
? ['base', ...heads].flatMap(head => Object.entries(HOST_BROWSER_THIRD_PARTY_DEPENDENCIES[head]))
|
|
411
|
+
: []),
|
|
412
|
+
...(members.includes('vscode-servers') ? Object.entries(VSCODE_LANGUAGE_CLIENT) : []),
|
|
413
|
+
...(members.includes('host-vscode') && heads.includes('glsp') ? Object.entries(HOST_VSCODE_GLSP_THIRD_PARTY_DEPENDENCIES) : []),
|
|
414
|
+
...(members.includes('host-vscode') && heads.includes('data') ? Object.entries(HOST_VSCODE_DATA_THIRD_PARTY_DEPENDENCIES) : []),
|
|
415
|
+
...(members.includes('theia') ? theiaThirdPartyDependencies(heads) : []),
|
|
416
|
+
...(members.includes('host-theia-browser') ? hostTheiaBrowserTheiaDependencies() : []),
|
|
417
|
+
...(members.includes('host-theia-electron') ? hostTheiaElectronPins() : [])
|
|
418
|
+
]);
|
|
419
|
+
return [...pins].filter(([, version]) => /^\d+\.\d+\.\d+$/.test(version)).sort(([left], [right]) => left.localeCompare(right));
|
|
420
|
+
}
|
|
421
|
+
/** 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. */
|
|
422
|
+
function installsVitest41(npmVersion) {
|
|
423
|
+
const [release, prerelease] = (npmVersion ?? '0.0.0').split('-', 2);
|
|
424
|
+
const [major, minor, patch] = release.split('.').map(Number);
|
|
425
|
+
return major > 11 || (major === 11 && (minor > 6 || (minor === 6 && (patch > 0 || prerelease === undefined))));
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Whether the scaffold holds `vitest` below 4.1, whose peer set crashes npm
|
|
429
|
+
* before 11.6 (every npm a Node 22 release bundles) on the first install. Only a
|
|
430
|
+
* workspace root declaring a newer npm lifts it, and only when `init` runs under
|
|
431
|
+
* an npm known to be newer: npm does not enforce `packageManager`.
|
|
432
|
+
*/
|
|
433
|
+
function pinsVitest(composition) {
|
|
434
|
+
const workspace = composition.packaging.workspace;
|
|
435
|
+
return !(installsVitest41(workspace?.packageManagerNpm) && installsVitest41(workspace?.npmVersion));
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* The version a member pins a sibling member at: exact, at the version every
|
|
439
|
+
* member starts with. npm links a sibling only when the range admits its local
|
|
440
|
+
* version, and otherwise looks for it in the registry, where it was never
|
|
441
|
+
* published.
|
|
442
|
+
*/
|
|
443
|
+
const MEMBER_PIN = '0.0.0';
|
|
444
|
+
/** A dependency block, sorted as npm writes it. */
|
|
445
|
+
function sortedBlock(dependencies, indent) {
|
|
446
|
+
return Object.keys(dependencies)
|
|
447
|
+
.sort()
|
|
448
|
+
.map(name => `${indent}"${name}": "${dependencies[name]}"`)
|
|
449
|
+
.join(',\n');
|
|
450
|
+
}
|
|
451
|
+
/** The server's dependency block: the base and head set's packages and the protocol member. */
|
|
220
452
|
function dependencyBlock(composition, indent) {
|
|
221
|
-
const merged = {};
|
|
222
|
-
for (const head of composition.heads) {
|
|
453
|
+
const merged = { [memberPackageName(composition, 'protocol')]: MEMBER_PIN };
|
|
454
|
+
for (const head of ['base', ...composition.heads]) {
|
|
223
455
|
Object.assign(merged, HEAD_THIRD_PARTY_DEPENDENCIES[head]);
|
|
224
456
|
for (const framework of HEAD_FRAMEWORK_DEPENDENCIES[head]) {
|
|
225
457
|
merged[framework] = frameworkPin(composition);
|
|
226
458
|
}
|
|
227
459
|
}
|
|
228
|
-
return
|
|
229
|
-
.sort()
|
|
230
|
-
.map(name => `${indent}"${name}": "${merged[name]}"`)
|
|
231
|
-
.join(',\n');
|
|
460
|
+
return sortedBlock(merged, indent);
|
|
232
461
|
}
|
|
233
462
|
// JSON at two-space indent, not the three the `.ts` templates use: that is the
|
|
234
463
|
// npm convention, and `npm install` rewrites `package.json` at two spaces
|
|
235
464
|
// regardless — so three would not survive the adopter's first install.
|
|
236
465
|
//
|
|
237
|
-
// The KEY ORDER is
|
|
466
|
+
// The KEY ORDER is the one Oxfmt's `sortPackageJson` canonicalises to, `private`
|
|
238
467
|
// before `license` included. Any other order is rewritten by the scaffolded
|
|
239
468
|
// project's own first `format` run — a diff on a file the adopter never touched
|
|
240
469
|
// — and it makes a byte-compare against a formatted copy of this emission
|
|
@@ -254,6 +483,11 @@ function dependencyBlock(composition, indent) {
|
|
|
254
483
|
// from this package's own grammar and can reach a consumer from nowhere else; a
|
|
255
484
|
// listed path that does not exist yet is inert.
|
|
256
485
|
//
|
|
486
|
+
// `exports` puts `createServices`, the one module reading the real filesystem,
|
|
487
|
+
// behind `./node`, so the root loads in a browser worker that has no `node:fs`.
|
|
488
|
+
// `./lib/*` and `./package.json` stay reachable for a host that resolves
|
|
489
|
+
// `<server>/lib/main.js` to spawn the server.
|
|
490
|
+
//
|
|
257
491
|
// `repository` is deliberately NOT emitted while `author` is emitted empty. An
|
|
258
492
|
// empty `author` is the form `npm init` itself writes and asserts nothing, but
|
|
259
493
|
// `repository` is CONSUMED — the registry page, `npm repo` and publish
|
|
@@ -265,16 +499,9 @@ const PACKAGE_JSON = `{
|
|
|
265
499
|
"version": "0.0.0",
|
|
266
500
|
__PRIVATE__ "description": "__NAME__ language server, built with the Hydranium framework.",
|
|
267
501
|
"keywords": [
|
|
268
|
-
|
|
269
|
-
"langium",
|
|
270
|
-
"language-server",
|
|
271
|
-
"__PROJECT_ID__"
|
|
272
|
-
],
|
|
502
|
+
__KEYWORDS__ ],
|
|
273
503
|
"license": "UNLICENSED",
|
|
274
504
|
"author": "",
|
|
275
|
-
"type": "module",
|
|
276
|
-
"main": "lib/index.js",
|
|
277
|
-
"types": "lib/index.d.ts",
|
|
278
505
|
"bin": {
|
|
279
506
|
__BIN__ },
|
|
280
507
|
"files": [
|
|
@@ -282,17 +509,32 @@ __BIN__ },
|
|
|
282
509
|
"src",
|
|
283
510
|
"syntaxes"
|
|
284
511
|
],
|
|
512
|
+
"type": "module",
|
|
513
|
+
"main": "lib/index.js",
|
|
514
|
+
"types": "lib/index.d.ts",
|
|
515
|
+
"exports": {
|
|
516
|
+
".": {
|
|
517
|
+
"types": "./lib/index.d.ts",
|
|
518
|
+
"default": "./lib/index.js"
|
|
519
|
+
},
|
|
520
|
+
"./node": {
|
|
521
|
+
"types": "./lib/node/services.d.ts",
|
|
522
|
+
"default": "./lib/node/services.js"
|
|
523
|
+
},
|
|
524
|
+
"./lib/*": "./lib/*",
|
|
525
|
+
"./package.json": "./package.json"
|
|
526
|
+
},
|
|
285
527
|
"scripts": {
|
|
286
|
-
"build": "npm run generate && tsc",
|
|
287
|
-
"clean": "rimraf lib syntaxes src/language-server/generated src/language-server/generated-hydranium tsconfig.tsbuildinfo",
|
|
528
|
+
"build": "npm run generate && tsc -b",
|
|
529
|
+
"clean": "rimraf lib syntaxes src/language-server/generated src/language-server/generated-hydranium test/generated-hydranium tsconfig.tsbuildinfo",
|
|
288
530
|
"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/
|
|
531
|
+
"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 ../protocol/src/generated-hydranium/transfer-model.ts --ast-builder-file src/language-server/generated-hydranium/ast-builder.ts --transfer-builder-file test/generated-hydranium/transfer-builder.ts --languages-file ../protocol/src/generated-hydranium/languages.ts --element-type-name __NAME__Element --terminals-name __NAME__Terminals --regen-command \\"Run: __NPM_RUN__ generate:transfer-model\\"",
|
|
290
532
|
"langium:generate": "langium generate",
|
|
291
533
|
"langium:watch": "langium generate --watch",
|
|
292
|
-
__LINT__ "start": "node lib/main.
|
|
534
|
+
__LINT__ "start": "node lib/main.js__START_ARGS__",
|
|
293
535
|
"test": "npm run typecheck:test && vitest run",
|
|
294
536
|
"typecheck:test": "tsc --noEmit -p tsconfig.test.json",
|
|
295
|
-
"watch": "tsc --watch"
|
|
537
|
+
"watch": "concurrently --kill-others --names langium,transfer-model,tsc \\"npm run langium:watch\\" \\"npm run generate:transfer-model -- --watch\\" \\"tsc -b --watch\\""
|
|
296
538
|
},
|
|
297
539
|
"dependencies": {
|
|
298
540
|
__DEPENDENCIES__
|
|
@@ -300,10 +542,11 @@ __DEPENDENCIES__
|
|
|
300
542
|
"devDependencies": {
|
|
301
543
|
"@hydranium/cli": "__FRAMEWORK_PIN__",
|
|
302
544
|
"@types/node": "^22.0.0",
|
|
303
|
-
"
|
|
545
|
+
"concurrently": "^9.0.0",
|
|
546
|
+
"langium-cli": "4.4.0",
|
|
304
547
|
"rimraf": "^5.0.0",
|
|
305
|
-
"typescript": "^
|
|
306
|
-
"vitest": "
|
|
548
|
+
"typescript": "^7.0.2",
|
|
549
|
+
"vitest": "__VITEST__"
|
|
307
550
|
},
|
|
308
551
|
"engines": {
|
|
309
552
|
"node": ">=22.13"
|
|
@@ -311,16 +554,17 @@ __DEPENDENCIES__
|
|
|
311
554
|
}
|
|
312
555
|
`;
|
|
313
556
|
/**
|
|
314
|
-
* How the scaffold names `npm run`
|
|
557
|
+
* How the scaffold names `npm run` for one member's script.
|
|
315
558
|
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
559
|
+
* Always with `--prefix`, from the directory commands are run in: the
|
|
560
|
+
* workspace root for a member, the project root for a standalone project. A
|
|
561
|
+
* bare `npm run` there reaches the ROOT manifest and fails, and the regen hint
|
|
562
|
+
* a generated file prints is read in `protocol/` as well, where the script it
|
|
563
|
+
* names does not exist.
|
|
320
564
|
*/
|
|
321
|
-
function npmRun(composition) {
|
|
565
|
+
function npmRun(composition, member) {
|
|
322
566
|
const workspace = composition.packaging.workspace;
|
|
323
|
-
return workspace === undefined ?
|
|
567
|
+
return `npm --prefix ${workspace === undefined ? member : `${workspace.targetPath}/${member}`} run`;
|
|
324
568
|
}
|
|
325
569
|
/**
|
|
326
570
|
* The `bin` targets, one per executable entry the head set emits.
|
|
@@ -331,7 +575,7 @@ function npmRun(composition) {
|
|
|
331
575
|
* name. Without the second key a scaffolded project has no command line that
|
|
332
576
|
* reaches its own data head at all.
|
|
333
577
|
*
|
|
334
|
-
* Alphabetical, because `
|
|
578
|
+
* Alphabetical, because Oxfmt's `sortPackageJson` sorts `bin` and any other
|
|
335
579
|
* order is rewritten by the scaffolded project's first `format` run.
|
|
336
580
|
*/
|
|
337
581
|
function binBlock(composition) {
|
|
@@ -341,21 +585,37 @@ function binBlock(composition) {
|
|
|
341
585
|
}
|
|
342
586
|
return entries.map(([name, target]) => ` "${name}": "${target}"`).join(',\n') + '\n';
|
|
343
587
|
}
|
|
344
|
-
/**
|
|
588
|
+
/**
|
|
589
|
+
* A member's `lint` script line, over `directories`, or nothing.
|
|
590
|
+
*
|
|
591
|
+
* Emitted only where a root lint config says the repo lints. The absence is
|
|
592
|
+
* the dangerous direction: a task runner runs a script only where one is
|
|
593
|
+
* declared, so a package with no `lint` is SKIPPED rather than reported, and
|
|
594
|
+
* that reads as a clean lint. A wrong invocation is one visible line to edit.
|
|
595
|
+
*/
|
|
596
|
+
function lintScript(member, directories) {
|
|
597
|
+
const workspace = member.packaging.workspace;
|
|
598
|
+
if (workspace?.oxlintConfig !== undefined) {
|
|
599
|
+
const config = `${'../'.repeat(workspace.targetPath.split('/').length)}${workspace.oxlintConfig}`;
|
|
600
|
+
return ` "lint": "oxlint --report-unused-disable-directives --format stylish --config ${config} ${directories} --max-warnings 0",\n`;
|
|
601
|
+
}
|
|
602
|
+
return workspace?.eslintConfig !== undefined ? ` "lint": "eslint ${directories} --max-warnings 0",\n` : '';
|
|
603
|
+
}
|
|
604
|
+
/** The server's `package.json`, with the name, the private flag and the dependency block all derived. */
|
|
345
605
|
function packageJson(composition) {
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
// declared, so a package with no `lint` is SKIPPED rather than reported, and
|
|
351
|
-
// that reads as a clean lint. A wrong invocation is one visible line to edit.
|
|
352
|
-
const lint = composition.packaging.workspace?.eslintConfig === undefined ? '' : ' "lint": "eslint src test --max-warnings 0",\n';
|
|
606
|
+
const keywords = ['hydranium', 'langium', 'language-server', composition.projectId]
|
|
607
|
+
.sort()
|
|
608
|
+
.map(keyword => ` ${JSON.stringify(keyword)}`)
|
|
609
|
+
.join(',\n') + '\n';
|
|
353
610
|
return project(PACKAGE_JSON, composition)
|
|
354
|
-
.replace('__PACKAGE_NAME__',
|
|
611
|
+
.replace('__PACKAGE_NAME__', memberPackageName(composition, 'server'))
|
|
612
|
+
.replace('__KEYWORDS__', keywords)
|
|
355
613
|
.replace('__BIN__', binBlock(composition))
|
|
356
|
-
.replace('__LINT__',
|
|
614
|
+
.replace('__LINT__', lintScript(forMember(composition, 'server'), 'src test'))
|
|
615
|
+
.replace('__START_ARGS__', composition.heads.includes('lsp') ? ' --stdio' : ' ../workspace')
|
|
616
|
+
.replace('__VITEST__', pinsVitest(composition) ? '~4.0.18' : '^4.0.0')
|
|
357
617
|
.replace('__PRIVATE__', composition.packaging.private ? ' "private": true,\n' : '')
|
|
358
|
-
.replace('__NPM_RUN__', npmRun(composition))
|
|
618
|
+
.replace('__NPM_RUN__', npmRun(composition, 'server'))
|
|
359
619
|
.replace('__FRAMEWORK_PIN__', frameworkPin(composition))
|
|
360
620
|
.replace('__DEPENDENCIES__', dependencyBlock(composition, ' '));
|
|
361
621
|
}
|
|
@@ -418,6 +678,23 @@ const TSCONFIG_COMPILER_OPTIONS = [
|
|
|
418
678
|
['forceConsistentCasingInFileNames', true],
|
|
419
679
|
['types', ['node']]
|
|
420
680
|
];
|
|
681
|
+
/** The protocol member's compiler options, pruned against a workspace base like the server's. */
|
|
682
|
+
const PROTOCOL_COMPILER_OPTIONS = [
|
|
683
|
+
['target', 'ES2022'],
|
|
684
|
+
['lib', ['ES2022']],
|
|
685
|
+
['module', 'NodeNext'],
|
|
686
|
+
['moduleResolution', 'NodeNext'],
|
|
687
|
+
['rootDir', 'src'],
|
|
688
|
+
['outDir', 'lib'],
|
|
689
|
+
['strict', true],
|
|
690
|
+
['skipLibCheck', true],
|
|
691
|
+
['declaration', true],
|
|
692
|
+
// The server's `tsc -b` builds this project through a reference, which
|
|
693
|
+
// `tsc` refuses unless the referenced project is composite.
|
|
694
|
+
['composite', true],
|
|
695
|
+
// No ambient Node types: a browser client compiles against this package.
|
|
696
|
+
['types', []]
|
|
697
|
+
];
|
|
421
698
|
/**
|
|
422
699
|
* The options that describe where THIS package's own files live. Never pruned,
|
|
423
700
|
* and emitted first in the workspace case: a base config that supplied them
|
|
@@ -425,9 +702,19 @@ const TSCONFIG_COMPILER_OPTIONS = [
|
|
|
425
702
|
* base is wrong rather than that the member is redundant.
|
|
426
703
|
*/
|
|
427
704
|
const PACKAGE_LOCAL_OPTIONS = ['rootDir', 'outDir'];
|
|
428
|
-
/**
|
|
429
|
-
|
|
430
|
-
|
|
705
|
+
/**
|
|
706
|
+
* The enum-valued options of {@link TSCONFIG_COMPILER_OPTIONS}, whose values
|
|
707
|
+
* `tsc` reads case-insensitively, so `nodenext` and `NodeNext` are one value.
|
|
708
|
+
* An enum-valued option added there belongs here too.
|
|
709
|
+
*/
|
|
710
|
+
const CASE_INSENSITIVE_OPTIONS = ['target', 'lib', 'module', 'moduleResolution'];
|
|
711
|
+
/** Compare two option values. Sound here because compiler options are scalars and flat arrays. */
|
|
712
|
+
function optionEquals(key, left, right) {
|
|
713
|
+
const normalise = (value) => {
|
|
714
|
+
const text = JSON.stringify(value);
|
|
715
|
+
return CASE_INSENSITIVE_OPTIONS.includes(key) ? text?.toLowerCase() : text;
|
|
716
|
+
};
|
|
717
|
+
return normalise(left) === normalise(right);
|
|
431
718
|
}
|
|
432
719
|
/**
|
|
433
720
|
* `tsconfig.json`, extending the workspace's base config when there is one.
|
|
@@ -436,104 +723,43 @@ function jsonEquals(left, right) {
|
|
|
436
723
|
* the same key: inheriting `"module": "CommonJS"` where the scaffold needs
|
|
437
724
|
* `NodeNext` would break every emitted import, so a differing base value is a
|
|
438
725
|
* reason to keep the override rather than to trust the parent.
|
|
726
|
+
*
|
|
727
|
+
* `member` is the composition as that member sees it, so `extends` reaches the
|
|
728
|
+
* workspace base from the member's own directory.
|
|
439
729
|
*/
|
|
440
|
-
function tsconfigJson(
|
|
441
|
-
const workspace =
|
|
730
|
+
function tsconfigJson(member, compilerOptions, include, references = '') {
|
|
731
|
+
const workspace = member.packaging.workspace;
|
|
442
732
|
const base = workspace?.baseTsconfig === undefined ? undefined : (workspace.baseCompilerOptions ?? {});
|
|
443
733
|
const options = base === undefined
|
|
444
|
-
?
|
|
734
|
+
? compilerOptions
|
|
445
735
|
: [
|
|
446
|
-
...
|
|
447
|
-
...
|
|
736
|
+
...compilerOptions.filter(([key]) => PACKAGE_LOCAL_OPTIONS.includes(key)),
|
|
737
|
+
...compilerOptions.filter(([key, value]) => !PACKAGE_LOCAL_OPTIONS.includes(key) && !optionEquals(key, base[key], value))
|
|
448
738
|
];
|
|
449
739
|
const extendsLine = workspace?.baseTsconfig === undefined ? '' : ` "extends": "${workspace.baseTsconfig}",\n`;
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
// vitest compiles through esbuild — a per-file transform with no type
|
|
456
|
-
// information, which cannot tell a re-exported TYPE from a re-exported value.
|
|
457
|
-
// Without the flag `tsc` accepts `export { SomeType } from './x'` that esbuild
|
|
458
|
-
// then emits as a real import of a symbol that does not exist at runtime, so
|
|
459
|
-
// the typecheck passes and the suite fails with a confusing missing-export.
|
|
460
|
-
const TSCONFIG_TEST = `{
|
|
461
|
-
"extends": "./tsconfig.json",
|
|
462
|
-
"compilerOptions": {
|
|
463
|
-
"rootDir": ".",
|
|
464
|
-
"noEmit": true,
|
|
465
|
-
"isolatedModules": true,
|
|
466
|
-
"types": ["node"]
|
|
467
|
-
},
|
|
468
|
-
"include": ["src", "test", "src/**/*.json"]
|
|
740
|
+
// An array spaced as a formatter writes it, which `JSON.stringify` does not.
|
|
741
|
+
const json = (value) => (Array.isArray(value) ? `[${value.map(json).join(', ')}]` : JSON.stringify(value));
|
|
742
|
+
const body = options.map(([key, value]) => ` "${key}": ${json(value)}`).join(',\n');
|
|
743
|
+
const referencesLine = references === '' ? '' : `,\n "references": ${references}`;
|
|
744
|
+
return `{\n${extendsLine} "compilerOptions": {\n${body}\n },\n "include": ${include}${referencesLine}\n}\n`;
|
|
469
745
|
}
|
|
470
|
-
`;
|
|
471
|
-
const VITEST_CONFIG = `import { defineConfig } from 'vitest/config';
|
|
472
|
-
|
|
473
|
-
// Vitest transforms TypeScript itself and resolves \`.js\` specifiers to their
|
|
474
|
-
// \`.ts\` source, so tests import from \`../src/\` with the same specifiers the
|
|
475
|
-
// compiled output uses. \`include\` is scoped to \`test/\` so \`lib/\` is never
|
|
476
|
-
// scanned; \`npm test\` runs \`typecheck:test\` first, because the esbuild
|
|
477
|
-
// transform strips types without checking them.
|
|
478
|
-
|
|
479
|
-
export default defineConfig({
|
|
480
|
-
test: {
|
|
481
|
-
environment: 'node',
|
|
482
|
-
include: ['test/**/*.{test,spec}.ts']
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
`;
|
|
486
|
-
const GITIGNORE = `node_modules/
|
|
487
|
-
lib/
|
|
488
|
-
*.tsbuildinfo
|
|
489
|
-
|
|
490
|
-
# Langium-generated TextMate grammar (rewritten by every \`langium generate\`).
|
|
491
|
-
syntaxes/
|
|
492
|
-
`;
|
|
493
746
|
/**
|
|
494
|
-
* The
|
|
495
|
-
*
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
* them: it is a Langium artefact, so a root that has never held a Langium
|
|
501
|
-
* package has no rule for it, and the first `langium generate` then offers
|
|
502
|
-
* generated output up for commit with nothing to warn the adopter. Dropping the
|
|
503
|
-
* whole file rather than this subset is the mistake this template exists to
|
|
504
|
-
* undo.
|
|
505
|
-
*/
|
|
506
|
-
const GITIGNORE_WORKSPACE_MEMBER = `# The workspace root already covers \`node_modules/\`, \`lib/\` and \`*.tsbuildinfo\`.
|
|
507
|
-
# It has no reason to know about this one: the TextMate grammar is a Langium
|
|
508
|
-
# artefact, rewritten by every \`langium generate\`, so a root that has never held
|
|
509
|
-
# a Langium package ignores nothing here and the generated file is offered for
|
|
510
|
-
# commit.
|
|
511
|
-
syntaxes/
|
|
512
|
-
`;
|
|
513
|
-
/** The terminals every grammar needs, shared verbatim by the fragment and the lone-grammar case. */
|
|
514
|
-
const TERMINALS = `hidden terminal WS: /\\s+/;
|
|
515
|
-
terminal ID: /[_a-zA-Z][\\w_]*/;
|
|
516
|
-
hidden terminal SL_COMMENT: /\\/\\/[^\\n\\r]*/;
|
|
517
|
-
hidden terminal ML_COMMENT: /\\/\\*[\\s\\S]*?\\*\\//;
|
|
518
|
-
`;
|
|
747
|
+
* The server's `tsconfig.json`. It references the protocol member, so `tsc -b`
|
|
748
|
+
* compiles protocol first, after `generate` has written its generated modules.
|
|
749
|
+
*/
|
|
750
|
+
function serverTsconfigJson(composition) {
|
|
751
|
+
return tsconfigJson(forMember(composition, 'server'), TSCONFIG_COMPILER_OPTIONS, '["src", "src/**/*.json"]', '[{ "path": "../protocol" }]');
|
|
752
|
+
}
|
|
519
753
|
/**
|
|
520
|
-
* The
|
|
521
|
-
*
|
|
522
|
-
* The alternative — every grammar declaring its own `WS` / `ID` — lets the token
|
|
523
|
-
* sets drift apart.
|
|
754
|
+
* The terminals every grammar needs: the shared fragment's text after its
|
|
755
|
+
* leading comment run, so a lone grammar declares the same set.
|
|
524
756
|
*/
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
//
|
|
529
|
-
// Keeping the tokens here rather than in one of the languages means a grammar
|
|
530
|
-
// imports \`common\` for its TOKENS and another language only when it needs that
|
|
531
|
-
// language's TYPES — separate reasons that are worth keeping separate.
|
|
532
|
-
|
|
533
|
-
${TERMINALS}`;
|
|
757
|
+
function terminals() {
|
|
758
|
+
return template('server/src/grammar/common.langium').replace(/^(\/\/.*\n)*\n/, '');
|
|
759
|
+
}
|
|
534
760
|
/** One starter grammar. `shared` decides whether it imports the fragment or declares its own terminals. */
|
|
535
761
|
function grammarFile(shared) {
|
|
536
|
-
const lexis = shared ? "import './common'\n" : `\n${
|
|
762
|
+
const lexis = shared ? "import './common'\n" : `\n${terminals()}`;
|
|
537
763
|
return `grammar __GRAMMAR__
|
|
538
764
|
${shared ? '\n' + lexis : ''}
|
|
539
765
|
// A minimal starter grammar — replace with your own language. \`__NODE_RULE__\` is
|
|
@@ -593,7 +819,10 @@ export const __CONFIG_ROOT_CONST___CONFIGURATION_ROOT = '__PROJECT_ID__';
|
|
|
593
819
|
};`
|
|
594
820
|
: `const __NAME__SharedModule: Module<__NAME__SharedServices, PartialLangiumSharedServices> = {};`;
|
|
595
821
|
const serializerImports = composition.grammars
|
|
596
|
-
.
|
|
822
|
+
.flatMap(grammar => [
|
|
823
|
+
`import { ${grammar.grammar}Serializer } from './${grammar.grammarId}-serializer.js';`,
|
|
824
|
+
`import { ${grammar.grammar}ValidationContribution } from './${grammar.grammarId}-validation.js';`
|
|
825
|
+
])
|
|
597
826
|
.join('\n');
|
|
598
827
|
// Each language gets its own adopter module because `Serializer` is a
|
|
599
828
|
// per-language slot. `additionalLanguages` defaults its `adopter` to the
|
|
@@ -603,6 +832,11 @@ export const __CONFIG_ROOT_CONST___CONFIGURATION_ROOT = '__PROJECT_ID__';
|
|
|
603
832
|
.map(grammar => `const ${grammar.grammar}LanguageModule: Module<__NAME__Services, PartialLangiumServices & DeepPartial<ServerAddedServices>> = {
|
|
604
833
|
serializer: {
|
|
605
834
|
Serializer: services => new ${grammar.grammar}Serializer(services)
|
|
835
|
+
},
|
|
836
|
+
validation: {
|
|
837
|
+
checks: {
|
|
838
|
+
names: () => new ${grammar.grammar}ValidationContribution()
|
|
839
|
+
}
|
|
606
840
|
}
|
|
607
841
|
};`)
|
|
608
842
|
.join('\n\n');
|
|
@@ -616,11 +850,11 @@ export const __CONFIG_ROOT_CONST___CONFIGURATION_ROOT = '__PROJECT_ID__';
|
|
|
616
850
|
: `${primary.grammar}: language`;
|
|
617
851
|
const text = `// DI bootstrap for __NAME__. Composes the framework defaults with adopter
|
|
618
852
|
// overrides via Langium's \`inject()\` (through the framework's
|
|
619
|
-
// \`createIntegrationServices\`). Each adopter module binds
|
|
620
|
-
//
|
|
621
|
-
//
|
|
622
|
-
// management, build pipeline) boots on the framework defaults;
|
|
623
|
-
// computation
|
|
853
|
+
// \`createIntegrationServices\`). Each adopter module binds its language's
|
|
854
|
+
// \`Serializer\`, which the framework cannot default because a concrete syntax
|
|
855
|
+
// is grammar knowledge, and its validation checks. Everything else (scope,
|
|
856
|
+
// naming, project management, build pipeline) boots on the framework defaults;
|
|
857
|
+
// scope computation and AST extensions go in these same modules.
|
|
624
858
|
//
|
|
625
859
|
// Note which generated symbol comes from which name: the SHARED module is
|
|
626
860
|
// \`__NAME__GeneratedSharedModule\` (from \`projectName\`) and there is one of it,
|
|
@@ -634,7 +868,11 @@ export const __CONFIG_ROOT_CONST___CONFIGURATION_ROOT = '__PROJECT_ID__';
|
|
|
634
868
|
: `
|
|
635
869
|
//
|
|
636
870
|
// A second grammar goes in the \`additionalLanguages\` option of
|
|
637
|
-
// \`createIntegrationServices\`, generated from this same \`langium-config.json
|
|
871
|
+
// \`createIntegrationServices\`, generated from this same \`langium-config.json\`.
|
|
872
|
+
// With several languages, bind \`lsp.configurationRoot\` in
|
|
873
|
+
// \`__NAME__SharedModule\`, or the framework warns and takes the first
|
|
874
|
+
// language's id. Type that module's second \`Module\` argument as
|
|
875
|
+
// \`PartialLangiumSharedServices & { lsp: { configurationRoot: string } }\`.`}
|
|
638
876
|
|
|
639
877
|
${importList(['createLspServerLanguageModule', 'createLspServerSharedModule', 'type LspServerAddedServices', 'type LspServerAddedSharedServices'], '@hydranium/core/lsp', columns)}
|
|
640
878
|
import { createIntegrationServices, type ServerAddedServices, type ServerModuleContext, type ServerSharedServices } from '@hydranium/core';
|
|
@@ -701,179 +939,121 @@ ${returnType}
|
|
|
701
939
|
`;
|
|
702
940
|
return project(text, composition);
|
|
703
941
|
}
|
|
704
|
-
const SERVICES = `// Zero-arg service factory for the headless \`hydranium-cli\` tooling: the
|
|
705
|
-
// \`reflect\` / \`lint-grammar\` / \`validate\` subcommands import this via
|
|
706
|
-
// \`--services ./lib/services.js\`. The head wires its own filesystem here.
|
|
707
|
-
//
|
|
708
|
-
// The contract is language-count-agnostic — a second grammar needs no edit here.
|
|
709
|
-
|
|
710
|
-
import { NodeFileSystem } from '@hydranium/core/node';
|
|
711
|
-
import { create__NAME__Services } from './language-server/__PROJECT_ID__-module.js';
|
|
712
|
-
|
|
713
|
-
export function createServices(): ReturnType<typeof create__NAME__Services> {
|
|
714
|
-
return create__NAME__Services({ ...NodeFileSystem });
|
|
715
|
-
}
|
|
716
|
-
`;
|
|
717
|
-
const AST = `// The language's AST entry point: a re-export of what \`langium generate\`
|
|
718
|
-
// emits, plus anywhere you augment those types.
|
|
719
|
-
//
|
|
720
|
-
// Import the AST from HERE rather than from \`./generated/ast.js\`, so any
|
|
721
|
-
// augmentation below travels with every import. One \`langium-cli\` run over N
|
|
722
|
-
// grammars emits ONE combined AST module sharing one reflection, so a further
|
|
723
|
-
// grammar needs no change here.
|
|
724
|
-
//
|
|
725
|
-
// \`generate:transfer-model\` reads this file as its \`--augmentation-file\`: the
|
|
726
|
-
// generated wire types are derived from the AST *as augmented*, not from the
|
|
727
|
-
// raw generated module. Augment a type here and the transfer model follows.
|
|
728
|
-
//
|
|
729
|
-
// A \`@derived\` property is computed at build time rather than parsed, so it is
|
|
730
|
-
// declared here and populated by an AST-extension contribution:
|
|
731
|
-
//
|
|
732
|
-
// declare module './generated/ast.js' {
|
|
733
|
-
// interface __ENTRY_RULE__ {
|
|
734
|
-
// /** @derived Populated by an \`ast.extensions.computedProperties\` contribution. */
|
|
735
|
-
// readonly _summary?: string;
|
|
736
|
-
// }
|
|
737
|
-
// }
|
|
738
|
-
|
|
739
|
-
export * from './generated/ast.js';
|
|
740
|
-
`;
|
|
741
942
|
/**
|
|
742
|
-
*
|
|
943
|
+
* How a host finds each socket head's port, in emission order: an LSP request
|
|
944
|
+
* when the LSP head publishes the ports, else the environment variable
|
|
945
|
+
* `main.ts` reads a port from.
|
|
743
946
|
*
|
|
744
|
-
*
|
|
745
|
-
* is a per-language slot and a serializer is grammar-shaped by definition. That
|
|
746
|
-
* is also why the framework refuses to default it: its `UnboundSerializer`
|
|
747
|
-
* throws, naming the binding to add, rather than guessing a syntax.
|
|
748
|
-
*/
|
|
749
|
-
const SERIALIZER = `// Concrete-syntax emitter for __GRAMMAR__ — the parser's inverse, turning a
|
|
750
|
-
// model back into text this grammar accepts. Derived from the starter grammar
|
|
751
|
-
// exactly as \`generated/ast.ts\` is, so replacing the grammar replaces this too.
|
|
752
|
-
//
|
|
753
|
-
// Without it every structured write fails: the framework's default binding at
|
|
754
|
-
// \`services.serializer.Serializer\` THROWS, because a concrete syntax is
|
|
755
|
-
// language knowledge no framework can derive. \`ModelService.update\` / \`save\`,
|
|
756
|
-
// the data head's \`saveModelDocument\` and a GLSP \`SaveModelAction\` all reach
|
|
757
|
-
// it.
|
|
758
|
-
//
|
|
759
|
-
// \`AbstractSerializer\`'s generic property walk lays out FORMAT-structured
|
|
760
|
-
// output — its YAML and JSON subclasses are what it exists for — and cannot
|
|
761
|
-
// produce a keyword-delimited syntax like \`node a -> b\`. So \`serializeNode\` is
|
|
762
|
-
// a per-\`$type\` emitter here and the two array hooks are unreachable.
|
|
763
|
-
|
|
764
|
-
import { AbstractSerializer } from '@hydranium/core';
|
|
765
|
-
import type { AstNode } from '@hydranium/langium';
|
|
766
|
-
import { type __ENTRY_RULE__, type __NODE_RULE__, is__ENTRY_RULE__, is__NODE_RULE__ } from './ast.js';
|
|
767
|
-
|
|
768
|
-
export class __GRAMMAR__Serializer extends AbstractSerializer<__ENTRY_RULE__> {
|
|
769
|
-
protected override serializeNode(node: AstNode | Record<string, unknown>): string {
|
|
770
|
-
if (is__ENTRY_RULE__(node)) {
|
|
771
|
-
return node.nodes.map(child => this.emitNode(child)).join('\\n');
|
|
772
|
-
}
|
|
773
|
-
if (is__NODE_RULE__(node)) {
|
|
774
|
-
return this.emitNode(node);
|
|
775
|
-
}
|
|
776
|
-
// Defensive: a rule added to the grammar with no emitter added here.
|
|
777
|
-
throw new Error(\`__GRAMMAR__Serializer: no emitter for $type \${(node as AstNode).$type}\`);
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
/** Unreachable — this grammar's one list is emitted by its \`__ENTRY_RULE__\` parent. */
|
|
781
|
-
protected override serializeArray(): string {
|
|
782
|
-
throw new Error('__GRAMMAR__Serializer: arrays are emitted by the per-$type parent, not the generic dispatch.');
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
/** Unreachable — same reasoning as {@link serializeArray}. */
|
|
786
|
-
protected override serializeReferenceArray(): string {
|
|
787
|
-
throw new Error('__GRAMMAR__Serializer: reference arrays are emitted by the per-$type parent, not the generic dispatch.');
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* \`serializeReferenceText\` rather than \`node.target?.$refText\`: it is the one
|
|
792
|
-
* read that spans BOTH input shapes. A transfer model reaching
|
|
793
|
-
* \`serializeTransfer\` carries \`target\` as a plain string rather than a
|
|
794
|
-
* \`Reference\`, and a serializer that reaches for \`$refText\` directly emits
|
|
795
|
-
* the AST correctly and drops every reference on the transfer path.
|
|
796
|
-
*/
|
|
797
|
-
private emitNode(node: __NODE_RULE__): string {
|
|
798
|
-
const target = this.serializeReferenceText(node.target);
|
|
799
|
-
return target === undefined ? \`node \${node.name}\` : \`node \${node.name} -> \${target}\`;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
`;
|
|
803
|
-
/**
|
|
804
|
-
* The exported constant names for the head set, in emission order. Both are
|
|
805
|
-
* keyed by the PROJECT rather than by a language: one server of each kind per
|
|
947
|
+
* Keyed by the PROJECT rather than by a language: one server of each kind per
|
|
806
948
|
* process serves every registered grammar, so a language-derived name would tie
|
|
807
949
|
* a project-level endpoint to whichever grammar was scaffolded first.
|
|
808
950
|
*/
|
|
809
|
-
function
|
|
951
|
+
function headPortConstants(composition) {
|
|
810
952
|
const upper = screamingSnake(composition.projectId);
|
|
953
|
+
const lsp = composition.heads.includes('lsp');
|
|
954
|
+
return socketHeads(composition).map(head => lsp
|
|
955
|
+
? {
|
|
956
|
+
name: `${upper}_${head.key}_PORT_COMMAND`,
|
|
957
|
+
value: `${composition.projectId}/${head.path}/port`,
|
|
958
|
+
doc: `LSP request the host queries to discover the ${head.label} socket port.`
|
|
959
|
+
}
|
|
960
|
+
: {
|
|
961
|
+
name: `${upper}_${head.key}_PORT_ENV`,
|
|
962
|
+
value: `${upper}_${head.key}_PORT`,
|
|
963
|
+
doc: `Environment variable naming the ${head.label} socket port when no \`--${head.path}-port\` flag does.`
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
/** The socket heads of the composition, as `head-ports.ts` names them. */
|
|
967
|
+
function socketHeads(composition) {
|
|
811
968
|
return [
|
|
812
|
-
...(composition.heads.includes('data')
|
|
813
|
-
|
|
969
|
+
...(composition.heads.includes('data')
|
|
970
|
+
? [{ key: 'DATA_SERVER', path: 'data-server', command: 'dataServer', label: 'data-server' }]
|
|
971
|
+
: []),
|
|
972
|
+
...(composition.heads.includes('glsp') ? [{ key: 'GLSP_SERVER', path: 'glsp-server', command: 'glsp', label: 'GLSP' }] : [])
|
|
814
973
|
];
|
|
815
974
|
}
|
|
975
|
+
/** Whether the composition emits the servers-only extension, which VS Code starts the server through and a Theia app sideloads. */
|
|
976
|
+
function emitsVscodeServers(composition) {
|
|
977
|
+
return initMembers(composition.heads, composition.hosts).includes('vscode-servers');
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* The host commands the servers extension answers each socket head's port
|
|
981
|
+
* under, for a host without a language client of its own.
|
|
982
|
+
*/
|
|
983
|
+
function hostCommandConstants(composition) {
|
|
984
|
+
if (!emitsVscodeServers(composition)) {
|
|
985
|
+
return [];
|
|
986
|
+
}
|
|
987
|
+
const upper = screamingSnake(composition.projectId);
|
|
988
|
+
return socketHeads(composition).map(head => ({
|
|
989
|
+
name: `${upper}_${head.key}_HOST_COMMAND`,
|
|
990
|
+
value: `${composition.projectId}.port.${head.command}`,
|
|
991
|
+
doc: `Host command the servers extension answers with the ${head.label} socket port.`
|
|
992
|
+
}));
|
|
993
|
+
}
|
|
816
994
|
/**
|
|
817
|
-
* The socket heads'
|
|
995
|
+
* The socket heads' port commands or variables, in the protocol member.
|
|
818
996
|
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
*
|
|
824
|
-
* rather than failing.
|
|
997
|
+
* A host shell has to name the same string the server reads, and reaches it
|
|
998
|
+
* here without depending on the server. A host that retypes the literal
|
|
999
|
+
* instead gets no error when it drifts: the framework's port poll defaults to
|
|
1000
|
+
* `findPortAttempts = -1`, so a wrong command retries forever rather than
|
|
1001
|
+
* failing, and a wrong variable is never read.
|
|
825
1002
|
*/
|
|
826
1003
|
function headPortsFile(composition) {
|
|
827
|
-
const
|
|
828
|
-
const
|
|
829
|
-
const
|
|
830
|
-
const
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
1004
|
+
const constants = [...headPortConstants(composition), ...hostCommandConstants(composition)];
|
|
1005
|
+
const blocks = constants.map(constant => `/** ${constant.doc} */\nexport const ${constant.name} = '${constant.value}';`);
|
|
1006
|
+
const socketHeadCount = socketHeads(composition).length;
|
|
1007
|
+
const heads = `socket head${socketHeadCount > 1 ? 's' : ''}`;
|
|
1008
|
+
const opening = composition.heads.includes('lsp')
|
|
1009
|
+
? `// The LSP requests a host queries to discover this server's ${heads}.`
|
|
1010
|
+
: `// The environment variables that name the ports of this server's ${heads}.`;
|
|
1011
|
+
const usage = composition.heads.includes('lsp')
|
|
1012
|
+
? `// The server publishes them and a host shell has to name the same string to
|
|
1013
|
+
// reach the head; both import them from here. A shell that retypes the literal
|
|
1014
|
+
// gets no error when it drifts: the framework's port poll retries indefinitely
|
|
1015
|
+
// by default.`
|
|
1016
|
+
: `// The server reads them and a process that starts it sets them; both import
|
|
1017
|
+
// them from here. A variable retyped with a typo is never read, and the head
|
|
1018
|
+
// then listens on whichever port is free.`;
|
|
1019
|
+
const hostCommands = emitsVscodeServers(composition)
|
|
1020
|
+
? `
|
|
843
1021
|
//
|
|
844
|
-
//
|
|
1022
|
+
// The host commands are the same ports for a host with no language client,
|
|
1023
|
+
// such as a Theia app sideloading the servers extension: it runs the command
|
|
1024
|
+
// and the extension sends the request.`
|
|
1025
|
+
: '';
|
|
1026
|
+
return `${opening}
|
|
1027
|
+
//
|
|
1028
|
+
// ${socketHeadCount > 1 ? 'Both are' : 'It is'} keyed by the PROJECT, not the language: one server of each kind per
|
|
845
1029
|
// process serves every registered grammar, so a language-derived name would tie
|
|
846
1030
|
// a project-level endpoint to whichever grammar was scaffolded first.
|
|
847
1031
|
//
|
|
848
|
-
|
|
849
|
-
// same string to reach the head, and \`main.ts\` is an executable entry — nothing
|
|
850
|
-
// can import from it. A shell that retypes the literal gets no error when it
|
|
851
|
-
// drifts: the framework's port poll retries indefinitely by default. Import
|
|
852
|
-
// these instead, and assert any host-side copy against them.
|
|
1032
|
+
${usage}${hostCommands}
|
|
853
1033
|
|
|
854
1034
|
${blocks.join('\n\n')}
|
|
855
1035
|
`;
|
|
856
1036
|
}
|
|
857
|
-
|
|
858
|
-
|
|
1037
|
+
/**
|
|
1038
|
+
* The server's root entry: the DI factory, the generated AST and each diagram
|
|
1039
|
+
* module, all loadable in a browser worker.
|
|
1040
|
+
*/
|
|
1041
|
+
function indexFile(composition) {
|
|
1042
|
+
const diagrams = composition.grammars.filter(grammar => grammar.diagram);
|
|
1043
|
+
const diagramPhrase = diagrams.length === 0 ? '' : diagrams.length === 1 ? ', plus the diagram module' : ', plus the diagram modules';
|
|
1044
|
+
const text = `// Public surface of the __NAME__ language server: the DI factory and the
|
|
1045
|
+
// generated AST${diagramPhrase}.
|
|
859
1046
|
//
|
|
860
|
-
//
|
|
861
|
-
//
|
|
862
|
-
//
|
|
1047
|
+
// Everything here loads in a browser worker as well as in Node, so a host can
|
|
1048
|
+
// compose the language wherever it runs it. \`createServices\`, which reads the
|
|
1049
|
+
// real filesystem, is the package's \`./node\` entry instead. The entry points
|
|
1050
|
+
// under \`src/\` are not re-exported either: each opens a transport at module
|
|
1051
|
+
// scope, so importing one starts a server, which is why they are \`bin\` targets.
|
|
863
1052
|
|
|
864
1053
|
export * from './language-server/__PROJECT_ID__-module.js';
|
|
865
1054
|
export * from './language-server/ast.js';
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
/**
|
|
869
|
-
* The public surface, plus the head-port commands when there is a socket head.
|
|
870
|
-
*
|
|
871
|
-
* The commands belong here rather than only in `head-ports.ts` so a host shell
|
|
872
|
-
* reaches them from the package root, the same way it reaches `createServices`.
|
|
873
|
-
*/
|
|
874
|
-
function indexFile(composition) {
|
|
875
|
-
const base = project(INDEX, composition);
|
|
876
|
-
return portCommandNames(composition).length ? `${base}export * from './head-ports.js';\n` : base;
|
|
1055
|
+
${diagrams.map(grammar => `export * from './glsp/${grammar.grammarId}/diagram-module.js';\n`).join('')}`;
|
|
1056
|
+
return project(text, composition);
|
|
877
1057
|
}
|
|
878
1058
|
/**
|
|
879
1059
|
* The `#!` line every emitted `bin` target carries.
|
|
@@ -899,12 +1079,14 @@ const SHEBANG = '#!/usr/bin/env node\n';
|
|
|
899
1079
|
*/
|
|
900
1080
|
function mainFile(composition) {
|
|
901
1081
|
const columns = columnsFor(composition);
|
|
902
|
-
const roots =
|
|
1082
|
+
const roots = composition.grammars.map(grammar => grammar.entryRule).sort();
|
|
903
1083
|
const upper = screamingSnake(composition.projectId);
|
|
1084
|
+
const lsp = composition.heads.includes('lsp');
|
|
904
1085
|
const data = composition.heads.includes('data');
|
|
905
1086
|
const glsp = composition.heads.includes('glsp');
|
|
906
1087
|
const diagrams = composition.grammars.filter(grammar => grammar.diagram);
|
|
907
1088
|
const plural = roots.length > 1 ? 's' : '';
|
|
1089
|
+
const portFlags = [...(data ? ['--data-server-port'] : []), ...(glsp ? ['--glsp-server-port'] : [])];
|
|
908
1090
|
const headNames = composition.heads.map(head => head === 'lsp' ? 'the Langium LSP head' : head === 'data' ? 'a socket data-server (model server) head' : 'a GLSP head');
|
|
909
1091
|
// Comma-joined but for the last, which takes `and`: a bare `, ` join reads as
|
|
910
1092
|
// a truncated list, and the emitted comment is the first thing an adopter
|
|
@@ -913,7 +1095,7 @@ function mainFile(composition) {
|
|
|
913
1095
|
// `reflect-metadata` must be imported before anything that reads a
|
|
914
1096
|
// decorator's emitted metadata, which inversify does at module scope.
|
|
915
1097
|
const reflectImport = glsp ? "import 'reflect-metadata';\n" : '';
|
|
916
|
-
const coreNodeSymbols = ['NodeFileSystem', ...(data ? ['publishPortOnLspConnection', 'startSocketServer'] : [])];
|
|
1098
|
+
const coreNodeSymbols = ['NodeFileSystem', ...(data ? [...(lsp ? ['publishPortOnLspConnection'] : []), 'startSocketServer'] : [])];
|
|
917
1099
|
const glspImports = glsp
|
|
918
1100
|
? `import { ServerModule } from '@eclipse-glsp/server/node.js';
|
|
919
1101
|
import { GlspClientLogger, HydraniumGlspAppModule } from '@hydranium/glsp-server';
|
|
@@ -930,44 +1112,57 @@ import { startGlspServer } from '@hydranium/glsp-server/node';
|
|
|
930
1112
|
// \`TransferElement\` structurally, so naming the AST type here compiles fine and
|
|
931
1113
|
// silently tells every typed client that a reference is a resolvable object
|
|
932
1114
|
// rather than a name.
|
|
933
|
-
${importList(roots, '
|
|
1115
|
+
${importList(roots, memberPackageName(composition, 'protocol'), columns, true)}
|
|
934
1116
|
`
|
|
935
1117
|
: '';
|
|
936
|
-
// The
|
|
937
|
-
// the same string to reach the head, and this file is an executable entry,
|
|
938
|
-
// nothing can import from it.
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
1118
|
+
// The names live in the protocol member, not here: a host shell has to name
|
|
1119
|
+
// the same string to reach the head, and this file is an executable entry,
|
|
1120
|
+
// so nothing can import from it.
|
|
1121
|
+
const portNames = headPortConstants(composition).map(constant => constant.name);
|
|
1122
|
+
const portImports = portNames.length ? importList(portNames, memberPackageName(composition, 'protocol'), columns) + '\n' : '';
|
|
1123
|
+
const dataBlock = !data
|
|
1124
|
+
? ''
|
|
1125
|
+
: !lsp
|
|
1126
|
+
? `
|
|
1127
|
+
// Data-server head: each accepted client gets its own DataServer.
|
|
1128
|
+
const dataServer = startSocketServer(
|
|
1129
|
+
{ shared, workspace, port: portFrom('data-server-port', ${upper}_DATA_SERVER_PORT_ENV), logTag: 'ModelServer', logger: shared.Logger },
|
|
1130
|
+
dataConnection => {
|
|
1131
|
+
new DataServer<${roots.join(' | ')}>(dataConnection, shared);
|
|
1132
|
+
return { dispose: () => undefined };
|
|
1133
|
+
}
|
|
1134
|
+
);
|
|
1135
|
+
`
|
|
1136
|
+
: `
|
|
944
1137
|
// Data-server head alongside LSP: binds an ephemeral port, published over the LSP
|
|
945
1138
|
// connection for the host to discover. Each accepted client gets its own DataServer.
|
|
946
1139
|
//
|
|
947
1140
|
// Neither the bind nor the publish may be swallowed: either failure leaves the LSP
|
|
948
1141
|
// head serving text edits while every data client waits on a port command that was
|
|
949
1142
|
// never registered, and the launcher reports a bind failure only if given a logger.
|
|
950
|
-
const dataServer = startSocketServer({ port: 0, logTag: 'ModelServer', logger: shared.Logger }, dataConnection => {
|
|
1143
|
+
const dataServer = startSocketServer({ shared, port: 0, logTag: 'ModelServer', logger: shared.Logger }, dataConnection => {
|
|
951
1144
|
new DataServer<${roots.join(' | ')}>(dataConnection, shared);
|
|
952
1145
|
return { dispose: () => undefined };
|
|
953
1146
|
});
|
|
954
1147
|
dataServer.started
|
|
955
|
-
.then(
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1148
|
+
.then(
|
|
1149
|
+
() => {
|
|
1150
|
+
const { port } = dataServer;
|
|
1151
|
+
if (port === undefined) {
|
|
1152
|
+
// \`started\` resolves only once the address is resolved, so this is
|
|
1153
|
+
// unreachable; a non-null assertion in its place would publish
|
|
1154
|
+
// \`undefined\`, which the host cannot tell from an unreachable port.
|
|
1155
|
+
throw new Error('the data head started without a resolved port');
|
|
1156
|
+
}
|
|
1157
|
+
publishPortOnLspConnection(shared.lsp.Connection, ${upper}_DATA_SERVER_PORT_COMMAND, port);
|
|
1158
|
+
},
|
|
1159
|
+
// The launcher logged its own bind failure; the rejection is control flow.
|
|
1160
|
+
() => undefined
|
|
1161
|
+
)
|
|
965
1162
|
.catch((error: unknown) => {
|
|
966
|
-
|
|
967
|
-
shared.Logger.error(\`[ModelServer] Could not publish the data-server port: \${reason}\`);
|
|
1163
|
+
shared.Logger.error(\`[ModelServer] Could not publish the data-server port: \${describeErrorWithStack(error)}\`);
|
|
968
1164
|
});
|
|
969
|
-
|
|
970
|
-
: '';
|
|
1165
|
+
`;
|
|
971
1166
|
const glspBlock = glsp
|
|
972
1167
|
? `
|
|
973
1168
|
// GLSP head on the same shared workspace. \`HydraniumGlspAppModule\` is used
|
|
@@ -975,89 +1170,146 @@ dataServer.started
|
|
|
975
1170
|
// grammar a request concerns, so nothing per-language belongs there — each
|
|
976
1171
|
// diagram module declares its own language instead.
|
|
977
1172
|
//
|
|
978
|
-
|
|
979
|
-
|
|
1173
|
+
${lsp
|
|
1174
|
+
? `// GLSP framework logs route through the LSP connection rather than stdout, which
|
|
1175
|
+
// IS the LSP transport in stdio mode; writing there corrupts the protocol stream.`
|
|
1176
|
+
: `// GLSP framework logs route through the framework's logger to stderr. GLSP's
|
|
1177
|
+
// own startup line goes to stdout, beside the ports line below.`}
|
|
980
1178
|
const glspServer = startGlspServer({
|
|
981
1179
|
// The GLSP log threshold lives on the logger, not beside it: the framework
|
|
982
1180
|
// replaces GLSP's own \`Logger\` binding, so a launcher-level \`logLevel\` would
|
|
983
1181
|
// be discarded. The logger tracks the framework's process-wide threshold, so
|
|
984
|
-
// \`HYDRANIUM_LOG_LEVEL\` and the LSP log-level setting govern GLSP output too;
|
|
1182
|
+
// \`HYDRANIUM_LOG_LEVEL\` ${lsp ? 'and the LSP log-level setting govern' : 'governs'} GLSP output too;
|
|
985
1183
|
// pass \`logLevel\` only to make GLSP quieter than the rest of the server.
|
|
986
1184
|
createLogger: caller => new GlspClientLogger(shared, { component: caller }),
|
|
987
1185
|
serverModule: new ServerModule()${diagrams.map(grammar => `.configureDiagramModule(new ${grammar.grammar}DiagramModule())`).join('')},
|
|
988
1186
|
appModules: [new HydraniumGlspAppModule({ shared })],
|
|
989
|
-
|
|
990
|
-
|
|
1187
|
+
${lsp
|
|
1188
|
+
? ` lspConnection: shared.lsp.Connection,
|
|
1189
|
+
portCommand: ${upper}_GLSP_SERVER_PORT_COMMAND`
|
|
1190
|
+
: ` workspace,
|
|
1191
|
+
port: portFrom('glsp-server-port', ${upper}_GLSP_SERVER_PORT_ENV),
|
|
1192
|
+
logger: shared.Logger`}
|
|
991
1193
|
});
|
|
992
|
-
void glspServer
|
|
993
|
-
`
|
|
1194
|
+
${lsp ? 'void glspServer;\n' : ''}`
|
|
994
1195
|
: '';
|
|
995
|
-
const
|
|
996
|
-
// process, so every head shares one model store.
|
|
997
|
-
// Invocation: \`node lib/main.js --stdio\`, or the package's \`__PROJECT_ID__\` bin
|
|
998
|
-
// script.${data
|
|
999
|
-
? `
|
|
1000
|
-
//
|
|
1001
|
-
// NOT the entry \`hydranium-cli query\` / \`save\` / \`projects\` / \`watch\` speak to:
|
|
1002
|
-
// stdio here carries LSP, and the data head is a socket whose port is published
|
|
1003
|
-
// over the LSP connection. Those subcommands spawn \`data-server-main.js\`.`
|
|
1004
|
-
: ''}
|
|
1005
|
-
//
|
|
1006
|
-
// Everything here runs at module scope, so this file is an executable rather
|
|
1007
|
-
// than a library entry — import \`./index.js\` instead to compose the language.
|
|
1008
|
-
|
|
1009
|
-
${reflectImport}${glspImports}${importList(coreNodeSymbols, '@hydranium/core/node', columns)}
|
|
1010
|
-
${data ? "import { DataServer } from '@hydranium/data-server';\n" : ''}// The framework's entry point, NOT Langium's \`@hydranium/langium/lsp\` one. It is
|
|
1196
|
+
const lspImports = `// The framework's entry point, NOT Langium's \`@hydranium/langium/lsp\` one. It is
|
|
1011
1197
|
// signature-compatible and delegates straight through; what it adds first is
|
|
1012
1198
|
// \`assertLspHeadComposed\`, which fails the start if the LSP head's SHARED module
|
|
1013
1199
|
// was never composed. Reaching for Langium's is the natural mistake and it is
|
|
1014
1200
|
// silent: the server boots, links and completes, while echo suppression, the
|
|
1015
1201
|
// didChangeContent debounce and the last-client-close rebuild are all inert.
|
|
1016
|
-
import { startLanguageServer } from '@hydranium/core/lsp';
|
|
1202
|
+
import { startLanguageServer, withHydraniumLspFeatures } from '@hydranium/core/lsp';
|
|
1017
1203
|
import { ProposedFeatures, createConnection } from 'vscode-languageserver/node';
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
const connection = createConnection(ProposedFeatures.all);
|
|
1204
|
+
`;
|
|
1205
|
+
const lspStart = `
|
|
1206
|
+
const connection = createConnection(withHydraniumLspFeatures(ProposedFeatures.all));
|
|
1021
1207
|
const { shared } = create__NAME__Services({ connection, ...NodeFileSystem });
|
|
1022
1208
|
startLanguageServer(shared);
|
|
1023
|
-
|
|
1209
|
+
`;
|
|
1210
|
+
// No LSP client names the workspace or asks for the ports here, so the
|
|
1211
|
+
// command line does, and the ports go to stdout once every head listens.
|
|
1212
|
+
const servers = [...(data ? ['dataServer'] : []), ...(glsp ? ['glspServer'] : [])];
|
|
1213
|
+
const socketStart = `
|
|
1214
|
+
const { values, positionals } = parseArgs({
|
|
1215
|
+
options: { ${portFlags.map(flag => `'${flag.slice(2)}': { type: 'string' }`).join(', ')} },
|
|
1216
|
+
allowPositionals: true
|
|
1217
|
+
});
|
|
1218
|
+
// The workspace root: the first argument, else the process cwd.
|
|
1219
|
+
const workspace = positionals[0] ?? process.cwd();
|
|
1220
|
+
|
|
1221
|
+
/** A head's port: its flag, else its environment variable, else 0 for any free port. */
|
|
1222
|
+
function portFrom(flag: keyof typeof values, variable: string): number {
|
|
1223
|
+
const text = values[flag] ?? process.env[variable] ?? '0';
|
|
1224
|
+
const port = Number(text);
|
|
1225
|
+
// Decimal digits only: \`Number\` also reads '' as 0 and takes '1e3' or '0x10'.
|
|
1226
|
+
if (!/^\\d+$/.test(text) || port > 65_535) {
|
|
1227
|
+
throw new Error(\`--\${flag} or \${variable} is '\${text}', not a port\`);
|
|
1228
|
+
}
|
|
1229
|
+
return port;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
const { shared } = create__NAME__Services({ ...NodeFileSystem });
|
|
1233
|
+
`;
|
|
1234
|
+
const portsLine = `
|
|
1235
|
+
// One JSON line on stdout once every head listens, for the process that started
|
|
1236
|
+
// this one to read the ports from: the one line that starts with \`{\`. Each
|
|
1237
|
+
// head brings the workspace up before it listens; a head that fails to start
|
|
1238
|
+
// has logged why and ends the process, which would otherwise serve without it.
|
|
1239
|
+
${servers.length === 1 ? `${servers[0]}.started` : `Promise.all([${servers.map(server => `${server}.started`).join(', ')}])`}.then(
|
|
1240
|
+
() => process.stdout.write(\`\${JSON.stringify({ ${servers.map(server => `${server}: ${server}.port`).join(', ')} })}\\n\`),
|
|
1241
|
+
() => process.exit(1)
|
|
1242
|
+
);
|
|
1243
|
+
`;
|
|
1244
|
+
const invocation = lsp
|
|
1245
|
+
? `// Invocation: \`node lib/main.js --stdio\`, or the package's \`__PROJECT_ID__\` bin
|
|
1246
|
+
// script.`
|
|
1247
|
+
: `// Invocation: \`node lib/main.js [<workspace-path>] ${portFlags.map(flag => `[${flag} <port>]`).join(' ')}\`,
|
|
1248
|
+
// or the package's \`__PROJECT_ID__\` bin script. Each port falls back to its
|
|
1249
|
+
// environment variable, then to any free port.`;
|
|
1250
|
+
const dataNote = !data
|
|
1251
|
+
? ''
|
|
1252
|
+
: lsp
|
|
1253
|
+
? `
|
|
1254
|
+
//
|
|
1255
|
+
// NOT the entry the data-server subcommands of \`hydranium-cli\` speak to: stdio
|
|
1256
|
+
// here carries LSP, and the data head is a socket whose port is published over
|
|
1257
|
+
// the LSP connection. Those subcommands spawn \`data-server-main.js\`.`
|
|
1258
|
+
: `
|
|
1259
|
+
//
|
|
1260
|
+
// NOT the entry the data-server subcommands of \`hydranium-cli\` speak to: they
|
|
1261
|
+
// drive the data protocol over a child's stdio, and the data head here is a
|
|
1262
|
+
// socket. Those subcommands spawn \`data-server-main.js\`.`;
|
|
1263
|
+
const text = `${SHEBANG}// Standalone entry point: starts ${headSummary} in the same
|
|
1264
|
+
// process, so every head shares one model store.
|
|
1265
|
+
${invocation}${dataNote}
|
|
1266
|
+
//
|
|
1267
|
+
// Everything here runs at module scope, so this file is an executable rather
|
|
1268
|
+
// than a library entry — import \`./index.js\` instead to compose the language.
|
|
1269
|
+
|
|
1270
|
+
${reflectImport}${glspImports}${importList(coreNodeSymbols, '@hydranium/core/node', columns)}
|
|
1271
|
+
${data ? "import { DataServer } from '@hydranium/data-server';\n" : ''}${data && lsp ? "import { describeErrorWithStack } from '@hydranium/protocol';\n" : ''}${lsp ? lspImports : "import { parseArgs } from 'node:util';\n"}${diagramImports}${transferImports}import { create__NAME__Services } from './language-server/__PROJECT_ID__-module.js';
|
|
1272
|
+
${portImports === '' ? '' : '\n' + portImports}${lsp ? lspStart : socketStart}${dataBlock}${glspBlock}${lsp ? '' : portsLine}`;
|
|
1024
1273
|
return project(text, composition);
|
|
1025
1274
|
}
|
|
1026
1275
|
/**
|
|
1027
1276
|
* The second executable entry: the data head alone, on stdio.
|
|
1028
1277
|
*
|
|
1029
1278
|
* Emitted with the `data` head because it is the ONLY command line that reaches
|
|
1030
|
-
* that head from outside the editor. `main.ts`
|
|
1031
|
-
*
|
|
1032
|
-
*
|
|
1033
|
-
* `
|
|
1034
|
-
*
|
|
1035
|
-
*
|
|
1036
|
-
* unrecognised method rather than as a missing head.
|
|
1279
|
+
* that head from outside the editor. `main.ts` serves the data head on a
|
|
1280
|
+
* socket, so a client driving the data protocol over a spawned child's
|
|
1281
|
+
* stdin/stdout cannot reach it — which is every data-server subcommand of
|
|
1282
|
+
* `hydranium-cli`. Without this file a scaffolded project has no `--server`
|
|
1283
|
+
* value, and the closest guess, `main.ts`, fails as an unrecognised method or
|
|
1284
|
+
* an unknown flag rather than as a missing head.
|
|
1037
1285
|
*
|
|
1038
1286
|
* A separate process rather than a flag on `main.ts`: only one protocol can own
|
|
1039
1287
|
* stdio, so the two entries are mutually exclusive by construction.
|
|
1040
1288
|
*/
|
|
1041
1289
|
function dataServerMainFile(composition) {
|
|
1042
1290
|
const columns = columnsFor(composition);
|
|
1043
|
-
const roots =
|
|
1291
|
+
const roots = composition.grammars.map(grammar => grammar.entryRule).sort();
|
|
1044
1292
|
const plural = roots.length > 1 ? 's' : '';
|
|
1045
1293
|
const text = `${SHEBANG}// Standalone entry point: a data-server head on **stdio**, with no LSP head in
|
|
1046
|
-
// the process. This is the transport \`hydranium-cli\` speaks —
|
|
1047
|
-
//
|
|
1048
|
-
//
|
|
1049
|
-
// language.
|
|
1294
|
+
// the process. This is the transport \`hydranium-cli\` speaks — its data-server
|
|
1295
|
+
// subcommands spawn a server command and drive JSON-RPC over its stdin/stdout —
|
|
1296
|
+
// so it is what makes those subcommands usable against this language.
|
|
1050
1297
|
//
|
|
1051
1298
|
// Invocation: \`node lib/data-server-main.js [<workspace-path>]\`, or the
|
|
1052
1299
|
// package's \`__PROJECT_ID__-data-server\` bin script. The workspace path defaults to
|
|
1053
1300
|
// the process cwd, which is what the CLI's \`--cwd\` sets on the child.
|
|
1054
1301
|
//
|
|
1055
|
-
|
|
1302
|
+
${composition.heads.includes('lsp')
|
|
1303
|
+
? `// Contrast with \`main.ts\`, the editor entry: there the LSP head owns stdio and
|
|
1056
1304
|
// the data head is a socket published over the LSP connection. Here there is no
|
|
1057
1305
|
// LSP connection at all, so the workspace initialization an
|
|
1058
1306
|
// \`initialize\`/\`initialized\` pair would otherwise drive has to happen here —
|
|
1059
1307
|
// which is why this entry uses \`startStdioServer\` rather than wiring a
|
|
1060
|
-
// connection directly
|
|
1308
|
+
// connection directly.`
|
|
1309
|
+
: `// Contrast with \`main.ts\`, where the data head is a socket whose port it
|
|
1310
|
+
// prints. Here it owns stdio, and as there, no LSP connection drives the
|
|
1311
|
+
// workspace initialization, so \`startStdioServer\` brings the workspace up
|
|
1312
|
+
// before it listens.`}
|
|
1061
1313
|
//
|
|
1062
1314
|
// Everything here runs at module scope, so this file is an executable rather
|
|
1063
1315
|
// than a library entry — import \`./index.js\` instead to compose the language.
|
|
@@ -1065,7 +1317,7 @@ function dataServerMainFile(composition) {
|
|
|
1065
1317
|
${importList(['NodeFileSystem', 'startStdioServer'], '@hydranium/core/node', columns)}
|
|
1066
1318
|
import { DataServer } from '@hydranium/data-server';
|
|
1067
1319
|
// The TRANSFER root${plural}, not the AST one${plural} — same reasoning as \`main.ts\`.
|
|
1068
|
-
${importList(roots, '
|
|
1320
|
+
${importList(roots, memberPackageName(composition, 'protocol'), columns, true)}
|
|
1069
1321
|
import { create__NAME__Services } from './language-server/__PROJECT_ID__-module.js';
|
|
1070
1322
|
|
|
1071
1323
|
const { shared } = create__NAME__Services({ ...NodeFileSystem });
|
|
@@ -1113,7 +1365,7 @@ function servicesTest(composition) {
|
|
|
1113
1365
|
// is missing from the composition.
|
|
1114
1366
|
|
|
1115
1367
|
import { describe, expect, it } from 'vitest';
|
|
1116
|
-
import { createServices } from '../src/services.js';
|
|
1368
|
+
import { createServices } from '../src/node/services.js';
|
|
1117
1369
|
|
|
1118
1370
|
describe('__NAME__ services', () => {
|
|
1119
1371
|
it('composes the DI tree and registers ${title}', () => {
|
|
@@ -1154,13 +1406,9 @@ const SERIALIZATION_SUITE = `describe('__GRAMMAR__ serialization', () => {
|
|
|
1154
1406
|
|
|
1155
1407
|
it('emits the same text from a transfer model, whose references are plain strings', async () => {
|
|
1156
1408
|
const { __GRAMMAR__ } = createServices();
|
|
1157
|
-
const model
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
{ $type: '__NODE_RULE__', name: 'first', target: 'second' },
|
|
1161
|
-
{ $type: '__NODE_RULE__', name: 'second' }
|
|
1162
|
-
]
|
|
1163
|
-
};
|
|
1409
|
+
const model = transferNode(Transfer__ENTRY_RULE__, {
|
|
1410
|
+
nodes: __TRANSFER_NODES__
|
|
1411
|
+
});
|
|
1164
1412
|
|
|
1165
1413
|
expect(await __GRAMMAR__.serializer.Serializer.serializeTransfer(model)).toBe(source);
|
|
1166
1414
|
});
|
|
@@ -1178,11 +1426,23 @@ const SERIALIZATION_SUITE = `describe('__GRAMMAR__ serialization', () => {
|
|
|
1178
1426
|
function serializationTest(composition) {
|
|
1179
1427
|
const columns = columnsFor(composition);
|
|
1180
1428
|
const astTypes = composition.grammars.map(grammar => grammar.entryRule);
|
|
1181
|
-
const
|
|
1429
|
+
const transferConstants = composition.grammars.flatMap(grammar => [
|
|
1430
|
+
`${grammar.entryRule} as Transfer${grammar.entryRule}`,
|
|
1431
|
+
grammar.nodeRule
|
|
1432
|
+
]);
|
|
1433
|
+
const suite = (grammar) => {
|
|
1434
|
+
const nodes = [
|
|
1435
|
+
`transferNode(${grammar.nodeRule}, { name: 'first', target: 'second' })`,
|
|
1436
|
+
`transferNode(${grammar.nodeRule}, { name: 'second' })`
|
|
1437
|
+
];
|
|
1438
|
+
const single = `[${nodes.join(', ')}]`;
|
|
1439
|
+
const literal = ` nodes: ${single}`.length <= columns ? single : `[\n${nodes.map(node => ` ${node}`).join(',\n')}\n ]`;
|
|
1440
|
+
return render(SERIALIZATION_SUITE, composition, grammar).replace('__TRANSFER_NODES__', literal);
|
|
1441
|
+
};
|
|
1182
1442
|
const text = `// Round-trips each grammar through its serializer: parse the source, serialize
|
|
1183
1443
|
// the model, compare the text. The serializer is the parser's inverse, so this
|
|
1184
|
-
// is the assertion that keeps \`
|
|
1185
|
-
// language server can read back.
|
|
1444
|
+
// is the assertion that keeps a client session's \`update\` / \`save\` writing
|
|
1445
|
+
// files the language server can read back.
|
|
1186
1446
|
//
|
|
1187
1447
|
// The transfer case is the one that catches the mistake worth catching.
|
|
1188
1448
|
// \`ModelService.modelToText\` short-circuits only a RAW STRING, so a typed model
|
|
@@ -1192,10 +1452,11 @@ function serializationTest(composition) {
|
|
|
1192
1452
|
import { parseHelper } from '@hydranium/core/testing';
|
|
1193
1453
|
import { describe, expect, it } from 'vitest';
|
|
1194
1454
|
${importList(astTypes, '../src/language-server/ast.js', columns, true)}
|
|
1195
|
-
${importList(
|
|
1196
|
-
import { createServices } from '../src/services.js';
|
|
1455
|
+
${importList(transferConstants, memberPackageName(composition, 'protocol'), columns)}
|
|
1456
|
+
import { createServices } from '../src/node/services.js';
|
|
1457
|
+
import { transferNode } from './generated-hydranium/transfer-builder.js';
|
|
1197
1458
|
|
|
1198
|
-
${composition.grammars.map(
|
|
1459
|
+
${composition.grammars.map(suite).join('\n\n')}
|
|
1199
1460
|
`;
|
|
1200
1461
|
return text;
|
|
1201
1462
|
}
|
|
@@ -1272,14 +1533,9 @@ const LINKING_SUITE = `describe('__GRAMMAR__ linking', () => {
|
|
|
1272
1533
|
});
|
|
1273
1534
|
});`;
|
|
1274
1535
|
/**
|
|
1275
|
-
* The validation tier
|
|
1276
|
-
* adopter
|
|
1277
|
-
*
|
|
1278
|
-
* The scaffold binds no `validation.checks`, so a test over an adopter check
|
|
1279
|
-
* would have to invent one and would then assert the test's own fixture rather
|
|
1280
|
-
* than the language. What a scaffolded project really guarantees on day one is
|
|
1281
|
-
* that a dangling reference is reported, which is a linker diagnostic — and
|
|
1282
|
-
* that is the tier a new adopter breaks third.
|
|
1536
|
+
* The validation tier: the linker's diagnostic for a dangling reference, the
|
|
1537
|
+
* tier a new adopter breaks third, and the scaffold's one check, a warning on
|
|
1538
|
+
* a repeated name.
|
|
1283
1539
|
*/
|
|
1284
1540
|
const VALIDATING_SUITE = `describe('__GRAMMAR__ validation', () => {
|
|
1285
1541
|
it('reports nothing for a well-formed document', async () => {
|
|
@@ -1306,6 +1562,21 @@ const VALIDATING_SUITE = `describe('__GRAMMAR__ validation', () => {
|
|
|
1306
1562
|
expect(diagnostics[0].severity).toBe(DiagnosticSeverity.Error);
|
|
1307
1563
|
expect(diagnostics[0].message).toContain('absent');
|
|
1308
1564
|
});
|
|
1565
|
+
|
|
1566
|
+
it('warns on each node named like one before it', async () => {
|
|
1567
|
+
const { shared, __GRAMMAR__ } = createServices();
|
|
1568
|
+
|
|
1569
|
+
const document = await parseHelper<__ENTRY_RULE__>(__GRAMMAR__)('node first\\nnode second\\nnode first', {
|
|
1570
|
+
documentUri: 'file:///duplicate.__EXTENSION__'
|
|
1571
|
+
});
|
|
1572
|
+
await shared.workspace.DocumentBuilder.build([document], { validation: true });
|
|
1573
|
+
|
|
1574
|
+
const diagnostics = document.diagnostics ?? [];
|
|
1575
|
+
expect(diagnostics).toHaveLength(1);
|
|
1576
|
+
expect(diagnostics[0].severity).toBe(DiagnosticSeverity.Warning);
|
|
1577
|
+
expect(diagnostics[0].message).toBe("A node named 'first' is already declared.");
|
|
1578
|
+
expect(diagnostics[0].range.start.line).toBe(2);
|
|
1579
|
+
});
|
|
1309
1580
|
});`;
|
|
1310
1581
|
/** Assemble one grammar-derived test file: a fixed preamble plus one suite per grammar. */
|
|
1311
1582
|
function grammarTest(composition, header, imports, suite) {
|
|
@@ -1316,7 +1587,7 @@ function grammarTest(composition, header, imports, suite) {
|
|
|
1316
1587
|
import { parseHelper } from '@hydranium/core/testing';
|
|
1317
1588
|
import { describe, expect, it } from 'vitest';
|
|
1318
1589
|
${imports.join('\n')}${imports.length ? '\n' : ''}${importList(astTypes, '../src/language-server/ast.js', columns, true)}
|
|
1319
|
-
import { createServices } from '../src/services.js';
|
|
1590
|
+
import { createServices } from '../src/node/services.js';
|
|
1320
1591
|
|
|
1321
1592
|
${composition.grammars.map(grammar => render(suite, composition, grammar)).join('\n\n')}
|
|
1322
1593
|
`;
|
|
@@ -1334,15 +1605,15 @@ const LINKING_HEADER = `// Tier two: does my cross-reference resolve.
|
|
|
1334
1605
|
// multi-file workspace depends on and what a single-document test cannot see.`;
|
|
1335
1606
|
const VALIDATING_HEADER = `// Tier three: does a broken model get reported.
|
|
1336
1607
|
//
|
|
1337
|
-
//
|
|
1338
|
-
//
|
|
1339
|
-
//
|
|
1340
|
-
// language module and assert it here alongside these.`;
|
|
1608
|
+
// A dangling reference is the FRAMEWORK's own linker diagnostic; a repeated
|
|
1609
|
+
// name is reported by the scaffold's own validation check. Bind a further
|
|
1610
|
+
// check in your language module and assert it here alongside these.`;
|
|
1341
1611
|
/** The README, assembled from lines to avoid escaping the Markdown code fences. */
|
|
1342
1612
|
function readme(composition) {
|
|
1343
1613
|
const multi = composition.grammars.length > 1;
|
|
1344
1614
|
const data = composition.heads.includes('data');
|
|
1345
1615
|
const primaryExtension = composition.grammars[0].extensions[0];
|
|
1616
|
+
const diagramCount = composition.grammars.filter(grammar => grammar.diagram).length;
|
|
1346
1617
|
const grammarBullets = composition.grammars.map(grammar => `- \`src/grammar/${grammar.grammarId}.langium\` — the \`${grammar.grammar}\` grammar (.${grammar.extensions.join(', .')})`);
|
|
1347
1618
|
const lines = [
|
|
1348
1619
|
'# __NAME__',
|
|
@@ -1351,24 +1622,11 @@ function readme(composition) {
|
|
|
1351
1622
|
'',
|
|
1352
1623
|
'## Getting started',
|
|
1353
1624
|
'',
|
|
1354
|
-
// Conditional on the pin this scaffold actually carries — see
|
|
1355
|
-
// `UNPUBLISHED_FRAMEWORK_VERSION`.
|
|
1356
|
-
...(composition.frameworkVersion === UNPUBLISHED_FRAMEWORK_VERSION
|
|
1357
|
-
? [
|
|
1358
|
-
'> **Pre-publish note.** `@hydranium/*` is not on npm yet, so the `0.0.0`',
|
|
1359
|
-
'> pins below are placeholders and `npm install` will fail with a 404 until',
|
|
1360
|
-
'> the framework is released. Until then, supply the packages from a local',
|
|
1361
|
-
'> framework checkout with [yalc](https://github.com/wclr/yalc) — a plain',
|
|
1362
|
-
'> `file:` path or `npm link` is not enough, because the framework packages',
|
|
1363
|
-
'> depend on each other by version and npm would try to fetch those from the',
|
|
1364
|
-
'> registry too.',
|
|
1365
|
-
''
|
|
1366
|
-
]
|
|
1367
|
-
: []),
|
|
1368
1625
|
'```bash',
|
|
1369
1626
|
'npm install',
|
|
1370
1627
|
'npm run langium:generate # generate the AST from the grammar',
|
|
1371
1628
|
'npm run build # generate + compile to lib/',
|
|
1629
|
+
'npm run watch # regenerate and recompile on every grammar or source change',
|
|
1372
1630
|
'npm test # typecheck the tests, then run them',
|
|
1373
1631
|
'```',
|
|
1374
1632
|
'',
|
|
@@ -1379,25 +1637,26 @@ function readme(composition) {
|
|
|
1379
1637
|
// nowhere else.
|
|
1380
1638
|
'```bash',
|
|
1381
1639
|
'# Grammar / AST reflection',
|
|
1382
|
-
'npx hydranium-cli reflect --services ./lib/services.js',
|
|
1640
|
+
'npx hydranium-cli reflect --services ./lib/node/services.js',
|
|
1383
1641
|
'',
|
|
1384
1642
|
'# Grammar-convention lint (CI gate)',
|
|
1385
|
-
'npx hydranium-cli lint-grammar --services ./lib/services.js',
|
|
1643
|
+
'npx hydranium-cli lint-grammar --services ./lib/node/services.js',
|
|
1386
1644
|
'',
|
|
1387
1645
|
'# Validate a workspace of model files (non-zero exit on errors)',
|
|
1388
|
-
'npx hydranium-cli validate --services ./lib/services.js
|
|
1646
|
+
'npx hydranium-cli validate --services ./lib/node/services.js ../workspace',
|
|
1389
1647
|
...(data
|
|
1390
1648
|
? [
|
|
1391
1649
|
'',
|
|
1392
1650
|
'# Data-head operations. `--server` is a command line the CLI spawns and then',
|
|
1393
1651
|
"# drives the data protocol over the child's stdin/stdout, so it has to name",
|
|
1394
|
-
|
|
1395
|
-
|
|
1652
|
+
...(composition.heads.includes('lsp')
|
|
1653
|
+
? ['# `data-server-main.js` — `main.js` gives stdio to LSP and answers these', '# methods with "Unhandled method".']
|
|
1654
|
+
: ['# `data-server-main.js` — `main.js` serves the data head on a socket.']),
|
|
1396
1655
|
'#',
|
|
1397
1656
|
'# The workspace goes to the ENTRY, not to `--cwd`: `--cwd` re-roots the child,',
|
|
1398
1657
|
'# so a relative entry path is refused by name (an absolute one is fine).',
|
|
1399
|
-
'npx hydranium-cli projects --server "node ./lib/data-server-main.js
|
|
1400
|
-
`npx hydranium-cli query --server "node ./lib/data-server-main.js
|
|
1658
|
+
'npx hydranium-cli projects --server "node ./lib/data-server-main.js ../workspace"',
|
|
1659
|
+
`npx hydranium-cli query --server "node ./lib/data-server-main.js ../workspace" --uri <file:// URI of ../workspace/nodes.${primaryExtension}>`
|
|
1401
1660
|
]
|
|
1402
1661
|
: []),
|
|
1403
1662
|
'```',
|
|
@@ -1407,9 +1666,12 @@ function readme(composition) {
|
|
|
1407
1666
|
...grammarBullets,
|
|
1408
1667
|
...(multi ? ['- `src/grammar/common.langium` — shared terminals, imported by each grammar (not a language)'] : []),
|
|
1409
1668
|
'- `src/language-server/__PROJECT_ID__-module.ts` — `create__NAME__Services` DI wiring',
|
|
1410
|
-
...composition.grammars.
|
|
1411
|
-
|
|
1412
|
-
|
|
1669
|
+
...composition.grammars.flatMap(grammar => [
|
|
1670
|
+
`- \`src/language-server/${grammar.grammarId}-serializer.ts\` — emits \`${grammar.grammar}\` back to text (the framework defaults this to a throw)`,
|
|
1671
|
+
`- \`src/language-server/${grammar.grammarId}-validation.ts\` — the \`${grammar.grammar}\` checks: a warning on a repeated name`
|
|
1672
|
+
]),
|
|
1673
|
+
"- `src/node/services.ts` — zero-arg `createServices()` for the headless CLI, the package's `./node` entry",
|
|
1674
|
+
`- \`src/index.ts\` — the package root, loadable in a browser worker: DI factory + generated AST${diagramCount === 0 ? '' : diagramCount === 1 ? ' + diagram module' : ' + diagram modules'}`,
|
|
1413
1675
|
`- \`src/main.ts\` — starts ${composition.heads.join(' + ')}, the \`__PROJECT_ID__\` bin entry`,
|
|
1414
1676
|
...(data
|
|
1415
1677
|
? [
|
|
@@ -1419,7 +1681,8 @@ function readme(composition) {
|
|
|
1419
1681
|
: []),
|
|
1420
1682
|
...composition.grammars
|
|
1421
1683
|
.filter(grammar => grammar.diagram)
|
|
1422
|
-
.map(grammar => `- \`src/glsp/${grammar.grammarId}/\` — the \`${grammar.grammar}\` diagram:
|
|
1684
|
+
.map(grammar => `- \`src/glsp/${grammar.grammarId}/\` — the \`${grammar.grammar}\` diagram: state, storage, submission handler, GModel factory, configuration, create-node handler, DI module`),
|
|
1685
|
+
`- \`../protocol/\` — the \`${memberPackageName(composition, 'protocol')}\` package: what this server and its clients both import (language ids, ${headPortConstants(composition).length === 0 ? '' : composition.heads.includes('lsp') ? 'port commands, ' : 'port variables, '}${composition.grammars.some(grammar => grammar.diagram) ? 'diagram ids, ' : ''}the transfer model), written partly by \`npm run generate\``,
|
|
1423
1686
|
'- `test/services.test.ts` — the DI tree composes; grows as your language does',
|
|
1424
1687
|
'- `test/parsing.test.ts` / `linking.test.ts` / `validating.test.ts` — the three tiers a new language breaks first',
|
|
1425
1688
|
'- `test/serialization.test.ts` — each grammar round-trips through its serializer',
|
|
@@ -1472,6 +1735,21 @@ function readme(composition) {
|
|
|
1472
1735
|
'atomic set and depends on a single physical copy, so a floating range can',
|
|
1473
1736
|
'silently resolve a second one.',
|
|
1474
1737
|
'',
|
|
1738
|
+
'`vscode-languageserver` is pinned to `10.1.2`, and',
|
|
1739
|
+
'`vscode-languageserver-protocol` and `vscode-jsonrpc` to the `3.18.4` and',
|
|
1740
|
+
'`9.0.3` it pins, so Langium, the LSP connection and the framework share one',
|
|
1741
|
+
'copy of each. With two, an error a Langium handler returns, such as a request',
|
|
1742
|
+
'for a document the server does not have, reaches the client as a result, and a',
|
|
1743
|
+
'framework error your own LSP handler throws loses its code.',
|
|
1744
|
+
'',
|
|
1745
|
+
...(pinsVitest(composition)
|
|
1746
|
+
? [
|
|
1747
|
+
'`vitest` is held below 4.1, whose peer set crashes the npm every Node 22',
|
|
1748
|
+
'release bundles. Raise it once every npm that installs this project is',
|
|
1749
|
+
'11.6 or later.',
|
|
1750
|
+
''
|
|
1751
|
+
]
|
|
1752
|
+
: []),
|
|
1475
1753
|
'## If your repo gates license headers',
|
|
1476
1754
|
'',
|
|
1477
1755
|
'The emitted `.ts` files carry no copyright header — the scaffold cannot know',
|
|
@@ -1490,201 +1768,68 @@ function readme(composition) {
|
|
|
1490
1768
|
/**
|
|
1491
1769
|
* The GLSP files for ONE grammar's diagram.
|
|
1492
1770
|
*
|
|
1493
|
-
* Per grammar rather than per project because
|
|
1494
|
-
* grammar
|
|
1495
|
-
*
|
|
1496
|
-
* grammar with no diagram can sit on the same server.
|
|
1771
|
+
* Per grammar rather than per project because the state, storage and GModel
|
|
1772
|
+
* factory are typed over that grammar's model, and a grammar with no diagram
|
|
1773
|
+
* can sit on the same server.
|
|
1497
1774
|
*
|
|
1498
1775
|
* The index and the computed-bounds handler are framework classes used
|
|
1499
1776
|
* unmodified; storage and the submission handler are thin typed subclasses,
|
|
1500
1777
|
* which is where an adopter's own load/save and log formatting land.
|
|
1501
1778
|
*
|
|
1502
|
-
* The set is EDITABLE rather than read-only:
|
|
1503
|
-
* on the module. GLSP's own `DiagramModule` binds no handler that
|
|
1504
|
-
* source model, so without
|
|
1505
|
-
* client it may change nothing — which reads as a broken diagram
|
|
1506
|
-
* deliberate viewer.
|
|
1779
|
+
* The set is EDITABLE rather than read-only: a create-node and a delete handler,
|
|
1780
|
+
* registered on the module. GLSP's own `DiagramModule` binds no handler that
|
|
1781
|
+
* mutates a source model, so without them the head renders and answers while
|
|
1782
|
+
* telling the client it may change nothing — which reads as a broken diagram
|
|
1783
|
+
* rather than as a deliberate viewer.
|
|
1507
1784
|
*/
|
|
1508
1785
|
function glspFiles(composition, grammar) {
|
|
1509
1786
|
const columns = columnsFor(composition);
|
|
1510
|
-
const
|
|
1511
|
-
const
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
// registered on the client too: sprotty's registries are exact-key maps with no
|
|
1517
|
-
// prefix fallback, so an id the client does not know yields an element with none
|
|
1518
|
-
// of a node's features, rendered by \`MissingView\` with only a
|
|
1519
|
-
// \`no registered view for type '…'\` console warning. Nothing fails server-side.
|
|
1520
|
-
//
|
|
1521
|
-
// The ids stay namespaced under the GLSP defaults (\`node:\` / \`edge:\`) so a
|
|
1522
|
-
// reader can tell a node id from an edge id at a glance.
|
|
1523
|
-
|
|
1524
|
-
import { DefaultTypes } from '@eclipse-glsp/server';
|
|
1525
|
-
|
|
1526
|
-
/**
|
|
1527
|
-
* The GLSP diagram type — the string GLSP routes every per-diagram-type request
|
|
1528
|
-
* by. Mirrored by the client; a mismatch silently DROPS the request rather than
|
|
1529
|
-
* reporting an unknown diagram type. Same value as the language id, so the two
|
|
1530
|
-
* cannot drift apart as a diagram gains element types.
|
|
1531
|
-
*/
|
|
1532
|
-
export const ${upper}_DIAGRAM_TYPE = '__LANGUAGE_ID__';
|
|
1533
|
-
|
|
1534
|
-
/** A \`__NODE_RULE__\` — the starter grammar's one named, referenceable node. */
|
|
1535
|
-
export const ${upper}_NODE_TYPE = \`\${DefaultTypes.NODE}:__GRAMMAR_ID__-node\`;
|
|
1536
|
-
|
|
1537
|
-
/** A resolved \`target\` reference, drawn as a connection between two nodes. */
|
|
1538
|
-
export const ${upper}_EDGE_TYPE = \`\${DefaultTypes.EDGE}:__GRAMMAR_ID__-target\`;
|
|
1539
|
-
`;
|
|
1540
|
-
const state = `// GLSP state for the __GRAMMAR__ diagram.
|
|
1787
|
+
const fixed = (file) => grammarTemplate(`server/src/glsp/__GRAMMAR_ID__/${file}`, composition, grammar);
|
|
1788
|
+
const computed = (file, text) => ({
|
|
1789
|
+
path: `server/src/glsp/${grammar.grammarId}/${file}`,
|
|
1790
|
+
content: render(text, composition, grammar)
|
|
1791
|
+
});
|
|
1792
|
+
const configuration = `// Diagram configuration for the __GRAMMAR__ diagram.
|
|
1541
1793
|
//
|
|
1542
|
-
// \`
|
|
1543
|
-
//
|
|
1544
|
-
//
|
|
1545
|
-
//
|
|
1546
|
-
//
|
|
1794
|
+
// **A hint is \`true\` only where a handler backs it.** The starter
|
|
1795
|
+
// __GRAMMAR__CreateNodeOperationHandler offers creation through the tool palette,
|
|
1796
|
+
// which GLSP assembles from the create handlers' trigger actions — there is no
|
|
1797
|
+
// \`creatable\` hint. __GRAMMAR__DeleteOperationHandler backs \`deletable\` on a
|
|
1798
|
+
// node and an edge; a node of another document stays undeletable, since this
|
|
1799
|
+
// diagram does not own it. Nothing backs reparent / reposition / resize, so
|
|
1800
|
+
// declaring one would offer a gesture whose operation the server rejects: a worse
|
|
1801
|
+
// failure than the tool being absent. Turn a hint on in the same change that adds
|
|
1802
|
+
// its handler.
|
|
1547
1803
|
//
|
|
1548
|
-
//
|
|
1549
|
-
//
|
|
1550
|
-
// \`
|
|
1804
|
+
// \`needsClientLayout\` is \`true\` and \`layoutKind\` is \`NONE\`: the starter grammar
|
|
1805
|
+
// persists no bounds, so the client measures and places everything. That is also
|
|
1806
|
+
// why \`ChangeBoundsOperation\` is a poor second handler to add — with nowhere in
|
|
1807
|
+
// the grammar to write a position, a move never reaches the text and is lost on
|
|
1808
|
+
// the next reload.
|
|
1551
1809
|
|
|
1552
|
-
import {
|
|
1810
|
+
import { type GModelElementConstructor } from '@eclipse-glsp/graph';
|
|
1811
|
+
${importList(['type DiagramConfiguration', 'type EdgeTypeHint', 'ServerLayoutKind', 'type ShapeTypeHint', 'getDefaultMapping'], '@eclipse-glsp/server', columns)}
|
|
1553
1812
|
import { injectable } from 'inversify';
|
|
1554
|
-
import
|
|
1813
|
+
import { __GRAMMAR_ID_CONST___EDGE_TYPE, __GRAMMAR_ID_CONST___EXTERNAL_NODE_TYPE, __GRAMMAR_ID_CONST___NODE_TYPE } from '__PROTOCOL_PACKAGE__';
|
|
1555
1814
|
|
|
1556
1815
|
@injectable()
|
|
1557
|
-
export class
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
// \`saveSourceModel\` (through \`ModelService.save\` → the per-URI \`Serializer\` →
|
|
1562
|
-
// the multi-client text store → \`WritableFileSystemProvider\`).
|
|
1563
|
-
//
|
|
1564
|
-
// The subclass exists so a bespoke load or save has a stable place to land.
|
|
1565
|
-
|
|
1566
|
-
import { type FullTextSourceModel, HydraniumGlspStorage } from '@hydranium/glsp-server';
|
|
1567
|
-
import { injectable } from 'inversify';
|
|
1568
|
-
import type { __ENTRY_RULE__ } from '../../language-server/ast.js';
|
|
1569
|
-
|
|
1570
|
-
@injectable()
|
|
1571
|
-
export class __GRAMMAR__GlspStorage extends HydraniumGlspStorage<__ENTRY_RULE__, FullTextSourceModel> {}
|
|
1572
|
-
`;
|
|
1573
|
-
const submission = `// Submission handler for the __GRAMMAR__ diagram.
|
|
1574
|
-
//
|
|
1575
|
-
// Inherits the framework's \`readyEvent = IntegrityService.SettledState\`, which
|
|
1576
|
-
// is load-bearing rather than incidental: the GModel factory resolves
|
|
1577
|
-
// \`target.ref\`, so it needs a fully-linked AST. Without the gate those reads
|
|
1578
|
-
// fire mid-build and warn about resolution before scopes are computed.
|
|
1579
|
-
//
|
|
1580
|
-
// Only \`formatSourceRoot\` is overridden, so the submit log names the model and
|
|
1581
|
-
// its node count instead of a bare \`$type\`.
|
|
1582
|
-
|
|
1583
|
-
import { ModelState } from '@eclipse-glsp/server';
|
|
1584
|
-
import { type FullTextSourceModel, HydraniumGlspSubmissionHandler } from '@hydranium/glsp-server';
|
|
1585
|
-
import { inject, injectable } from 'inversify';
|
|
1586
|
-
import type { __ENTRY_RULE__ } from '../../language-server/ast.js';
|
|
1587
|
-
import type { __GRAMMAR__GlspState } from './state.js';
|
|
1588
|
-
|
|
1589
|
-
@injectable()
|
|
1590
|
-
export class __GRAMMAR__SubmissionHandler extends HydraniumGlspSubmissionHandler<__ENTRY_RULE__, FullTextSourceModel> {
|
|
1591
|
-
@inject(ModelState) declare protected modelState: __GRAMMAR__GlspState;
|
|
1592
|
-
|
|
1593
|
-
protected override formatSourceRoot(root: __ENTRY_RULE__ | undefined): string {
|
|
1594
|
-
return root ? \`__ENTRY_RULE__ nodes=\${root.nodes.length}\` : 'none';
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
`;
|
|
1598
|
-
const factory = `// AST → GModel for the __GRAMMAR__ diagram: one node per \`__NODE_RULE__\`, one
|
|
1599
|
-
// edge per resolved \`target\` reference.
|
|
1600
|
-
//
|
|
1601
|
-
// Ids come from the index rather than being composed here, so the id strategy
|
|
1602
|
-
// stays in one place. Nodes are emitted before edges, because a GLSP edge
|
|
1603
|
-
// pointing at an id that does not exist fails client-side with a far less
|
|
1604
|
-
// obvious error than a missing edge. An unresolved reference is SKIPPED rather
|
|
1605
|
-
// than treated as an error: a dangling reference is ordinary editing state, and
|
|
1606
|
-
// the LSP head already reports it as a diagnostic.
|
|
1607
|
-
|
|
1608
|
-
import { DefaultTypes, GEdge, GGraph, GLabel, type GModelFactory, GNode, ModelState } from '@eclipse-glsp/server';
|
|
1609
|
-
import { inject, injectable } from 'inversify';
|
|
1610
|
-
import type { __ENTRY_RULE__ } from '../../language-server/ast.js';
|
|
1611
|
-
import { ${upper}_EDGE_TYPE, ${upper}_NODE_TYPE } from './types.js';
|
|
1612
|
-
import type { __GRAMMAR__GlspState } from './state.js';
|
|
1613
|
-
|
|
1614
|
-
@injectable()
|
|
1615
|
-
export class __GRAMMAR__GModelFactory implements GModelFactory {
|
|
1616
|
-
@inject(ModelState) protected readonly modelState!: __GRAMMAR__GlspState;
|
|
1617
|
-
|
|
1618
|
-
createModel(): void {
|
|
1619
|
-
const root = this.modelState.sourceRoot;
|
|
1620
|
-
const graph = GGraph.builder().id(this.modelState.sourceUri).build();
|
|
1621
|
-
if (root) {
|
|
1622
|
-
this.buildGraph(root, graph);
|
|
1623
|
-
}
|
|
1624
|
-
this.modelState.updateRoot(graph);
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
protected buildGraph(root: __ENTRY_RULE__, graph: GGraph): void {
|
|
1628
|
-
for (const node of root.nodes) {
|
|
1629
|
-
const id = this.modelState.index.createId(node);
|
|
1630
|
-
graph.children.push(
|
|
1631
|
-
GNode.builder()
|
|
1632
|
-
.id(id)
|
|
1633
|
-
.type(${upper}_NODE_TYPE)
|
|
1634
|
-
.add(GLabel.builder().id(\`\${id}_name\`).text(node.name).type(DefaultTypes.LABEL).build())
|
|
1635
|
-
.build()
|
|
1636
|
-
);
|
|
1637
|
-
}
|
|
1638
|
-
for (const node of root.nodes) {
|
|
1639
|
-
const target = node.target?.ref;
|
|
1640
|
-
if (!target) {
|
|
1641
|
-
continue;
|
|
1642
|
-
}
|
|
1643
|
-
const sourceId = this.modelState.index.createId(node);
|
|
1644
|
-
graph.children.push(
|
|
1645
|
-
GEdge.builder()
|
|
1646
|
-
.id(\`\${sourceId}_target\`)
|
|
1647
|
-
.type(${upper}_EDGE_TYPE)
|
|
1648
|
-
.sourceId(sourceId)
|
|
1649
|
-
.targetId(this.modelState.index.createId(target))
|
|
1650
|
-
.build()
|
|
1651
|
-
);
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
`;
|
|
1656
|
-
const configuration = `// Diagram configuration for the __GRAMMAR__ diagram.
|
|
1657
|
-
//
|
|
1658
|
-
// **Every hint is \`false\`, and that is not the same as read-only.** The starter
|
|
1659
|
-
// __GRAMMAR__CreateNodeOperationHandler makes this diagram editable through the
|
|
1660
|
-
// tool palette, which GLSP assembles from the create handlers' trigger actions —
|
|
1661
|
-
// there is no \`creatable\` hint. What the hints govern is delete / reparent /
|
|
1662
|
-
// reposition / resize, and nothing backs those, so declaring one would offer a
|
|
1663
|
-
// gesture whose operation the server rejects: a worse failure than the tool being
|
|
1664
|
-
// absent. Turn a hint on in the same change that adds its handler.
|
|
1665
|
-
//
|
|
1666
|
-
// \`needsClientLayout\` is \`true\` and \`layoutKind\` is \`NONE\`: the starter grammar
|
|
1667
|
-
// persists no bounds, so the client measures and places everything. That is also
|
|
1668
|
-
// why \`ChangeBoundsOperation\` is a poor second handler to add — with nowhere in
|
|
1669
|
-
// the grammar to write a position, a move never reaches the text and is lost on
|
|
1670
|
-
// the next reload.
|
|
1671
|
-
|
|
1672
|
-
import { type GModelElementConstructor } from '@eclipse-glsp/graph';
|
|
1673
|
-
${importList(['type DiagramConfiguration', 'type EdgeTypeHint', 'ServerLayoutKind', 'type ShapeTypeHint', 'getDefaultMapping'], '@eclipse-glsp/server', columns)}
|
|
1674
|
-
import { injectable } from 'inversify';
|
|
1675
|
-
import { ${upper}_EDGE_TYPE, ${upper}_NODE_TYPE } from './types.js';
|
|
1676
|
-
|
|
1677
|
-
@injectable()
|
|
1678
|
-
export class __GRAMMAR__DiagramConfiguration implements DiagramConfiguration {
|
|
1679
|
-
readonly layoutKind: ServerLayoutKind = ServerLayoutKind.NONE;
|
|
1680
|
-
readonly needsClientLayout: boolean = true;
|
|
1681
|
-
readonly animatedUpdate: boolean = false;
|
|
1816
|
+
export class __GRAMMAR__DiagramConfiguration implements DiagramConfiguration {
|
|
1817
|
+
readonly layoutKind: ServerLayoutKind = ServerLayoutKind.NONE;
|
|
1818
|
+
readonly needsClientLayout: boolean = true;
|
|
1819
|
+
readonly animatedUpdate: boolean = false;
|
|
1682
1820
|
|
|
1683
1821
|
readonly typeMapping: Map<string, GModelElementConstructor> = getDefaultMapping();
|
|
1684
1822
|
|
|
1685
1823
|
readonly shapeTypeHints: ShapeTypeHint[] = [
|
|
1686
1824
|
{
|
|
1687
|
-
elementTypeId:
|
|
1825
|
+
elementTypeId: __GRAMMAR_ID_CONST___NODE_TYPE,
|
|
1826
|
+
deletable: true,
|
|
1827
|
+
reparentable: false,
|
|
1828
|
+
repositionable: false,
|
|
1829
|
+
resizable: false
|
|
1830
|
+
},
|
|
1831
|
+
{
|
|
1832
|
+
elementTypeId: __GRAMMAR_ID_CONST___EXTERNAL_NODE_TYPE,
|
|
1688
1833
|
deletable: false,
|
|
1689
1834
|
reparentable: false,
|
|
1690
1835
|
repositionable: false,
|
|
@@ -1694,143 +1839,69 @@ export class __GRAMMAR__DiagramConfiguration implements DiagramConfiguration {
|
|
|
1694
1839
|
|
|
1695
1840
|
readonly edgeTypeHints: EdgeTypeHint[] = [
|
|
1696
1841
|
{
|
|
1697
|
-
elementTypeId:
|
|
1698
|
-
deletable:
|
|
1842
|
+
elementTypeId: __GRAMMAR_ID_CONST___EDGE_TYPE,
|
|
1843
|
+
deletable: true,
|
|
1699
1844
|
repositionable: false,
|
|
1700
1845
|
routable: false,
|
|
1701
|
-
sourceElementTypeIds: [
|
|
1702
|
-
targetElementTypeIds: [
|
|
1846
|
+
sourceElementTypeIds: [__GRAMMAR_ID_CONST___NODE_TYPE],
|
|
1847
|
+
targetElementTypeIds: [__GRAMMAR_ID_CONST___NODE_TYPE, __GRAMMAR_ID_CONST___EXTERNAL_NODE_TYPE]
|
|
1703
1848
|
}
|
|
1704
1849
|
];
|
|
1705
1850
|
}
|
|
1706
|
-
`;
|
|
1707
|
-
const createHandler = `// The starter operation handler for the __GRAMMAR__ diagram: the tool-palette
|
|
1708
|
-
// entry that creates a \`__NODE_RULE__\`.
|
|
1709
|
-
//
|
|
1710
|
-
// **Deleting this file and its \`configureOperationHandlers\` registration in
|
|
1711
|
-
// \`diagram-module.ts\` gives a read-only viewer**, and nothing else has to change
|
|
1712
|
-
// — creation is offered through the palette rather than through a type hint, so
|
|
1713
|
-
// every hint in \`diagram-configuration.ts\` is already \`false\`. The scaffold emits
|
|
1714
|
-
// the editable direction because that asymmetry runs one way: editable →
|
|
1715
|
-
// read-only is a deletion the compiler checks, while read-only → editable is
|
|
1716
|
-
// authoring against a seam you have not used yet.
|
|
1717
|
-
//
|
|
1718
|
-
// **It composes TEXT rather than mutating the AST.** The source model of
|
|
1719
|
-
// \`FullTextHydraniumGlspState\` is the document text, and reading it back through
|
|
1720
|
-
// \`state.sourceModel\` serialises the AST through the per-URI \`Serializer\`, which
|
|
1721
|
-
// this scaffold does not bind — so that getter throws until you do. Appending a
|
|
1722
|
-
// declaration to the text the parser last read needs no serializer, which is what
|
|
1723
|
-
// makes a scaffolded diagram editable on day one. Bind a \`Serializer\` at
|
|
1724
|
-
// \`services.serializer.Serializer\` and this becomes a
|
|
1725
|
-
// \`HydraniumGlspRecordingCommand\` over \`state.sourceModel\` instead — the same
|
|
1726
|
-
// binding the diagram's own save action needs.
|
|
1727
|
-
//
|
|
1728
|
-
// **The drop location is discarded.** \`needsClientLayout\` is \`true\` and the
|
|
1729
|
-
// starter grammar persists no bounds, so there is nowhere to put a coordinate: the
|
|
1730
|
-
// node is appended at the end of the document and the client places it.
|
|
1731
|
-
//
|
|
1732
|
-
// Like \`types.ts\`, \`gmodel-factory.ts\` and \`diagram-configuration.ts\`, this file
|
|
1733
|
-
// knows the starter grammar's concrete syntax — the \`node\` keyword below is that
|
|
1734
|
-
// grammar's. Replacing the grammar means replacing these four together.
|
|
1735
|
-
|
|
1736
|
-
import { type Command, type CreateNodeOperation, JsonCreateNodeOperationHandler, type MaybePromise } from '@eclipse-glsp/server';
|
|
1737
|
-
import { findNextUnique } from '@hydranium/protocol';
|
|
1738
|
-
import { injectable } from 'inversify';
|
|
1739
|
-
import { ${upper}_NODE_TYPE } from './types.js';
|
|
1740
|
-
import type { __GRAMMAR__GlspState } from './state.js';
|
|
1741
|
-
|
|
1742
|
-
/** Proposed name for a new node, uniquified against the ones the document already has. */
|
|
1743
|
-
const NODE_NAME_STEM = 'Node';
|
|
1744
|
-
|
|
1745
|
-
@injectable()
|
|
1746
|
-
export class __GRAMMAR__CreateNodeOperationHandler extends JsonCreateNodeOperationHandler {
|
|
1747
|
-
declare protected modelState: __GRAMMAR__GlspState;
|
|
1748
|
-
|
|
1749
|
-
/** The palette's word for the thing it creates, so a noun rather than an action. */
|
|
1750
|
-
override readonly label = '__NODE_RULE__';
|
|
1751
|
-
elementTypeIds = [${upper}_NODE_TYPE];
|
|
1752
|
-
|
|
1753
|
-
override createCommand(operation: CreateNodeOperation): MaybePromise<Command | undefined> {
|
|
1754
|
-
if (!this.elementTypeIds.includes(operation.elementTypeId)) {
|
|
1755
|
-
return undefined;
|
|
1756
|
-
}
|
|
1757
|
-
const state = this.modelState;
|
|
1758
|
-
const before = this.documentText();
|
|
1759
|
-
const after = this.withNode(
|
|
1760
|
-
before,
|
|
1761
|
-
findNextUnique(
|
|
1762
|
-
NODE_NAME_STEM,
|
|
1763
|
-
state.sourceRoot.nodes.map(node => node.name)
|
|
1764
|
-
)
|
|
1765
|
-
);
|
|
1766
|
-
// Whole-document undo, which is all a full-text source model can offer: it
|
|
1767
|
-
// has exactly one field, so there is nothing to merge a concurrent edit into.
|
|
1768
|
-
return {
|
|
1769
|
-
execute: () => state.updateSourceModel({ text: after }),
|
|
1770
|
-
undo: () => state.updateSourceModel({ text: before }),
|
|
1771
|
-
redo: () => state.updateSourceModel({ text: after })
|
|
1772
|
-
};
|
|
1773
|
-
}
|
|
1774
|
-
|
|
1775
|
-
/** The text the captured source root was parsed from — the baseline an edit appends to. */
|
|
1776
|
-
protected documentText(): string {
|
|
1777
|
-
return this.modelState.sourceRoot.$document?.textDocument.getText() ?? '';
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
/** \`text\` with one more node declaration, under exactly one trailing newline. */
|
|
1781
|
-
protected withNode(text: string, name: string): string {
|
|
1782
|
-
const body = text.trimEnd();
|
|
1783
|
-
const declaration = \`node \${name}\`;
|
|
1784
|
-
return body.length === 0 ? \`\${declaration}\\n\` : \`\${body}\\n\${declaration}\\n\`;
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
1851
|
`;
|
|
1788
1852
|
const module = `// GLSP diagram module for __GRAMMAR__ — the DI wiring of one diagram type.
|
|
1789
1853
|
//
|
|
1790
|
-
// \`declareLanguage\` is the multi-grammar seam: it binds the grammar this diagram
|
|
1791
|
-
// edits on the SESSION container, so \`modelState.diagramLanguage\` and the
|
|
1792
|
-
// per-language lookups resolve to __LANGUAGE_ID__. That is what stops one
|
|
1793
|
-
// diagram type from fighting over a process-wide binding when a project holds
|
|
1794
|
-
// several grammars — a grammar with no diagram is registered on the same server.
|
|
1795
|
-
//
|
|
1796
1854
|
// \`configureActionHandlers\` REBINDS rather than adds: GLSP's own
|
|
1797
1855
|
// \`DiagramModule\` already registers \`ComputedBoundsActionHandler\`, and two
|
|
1798
1856
|
// handlers for one action would both run.
|
|
1799
1857
|
//
|
|
1800
1858
|
// \`configureOperationHandlers\` ADDS: GLSP's default pair
|
|
1801
1859
|
// (\`CompoundOperationHandler\` and \`LayoutOperationHandler\`) mutates no source
|
|
1802
|
-
// model, so the starter create
|
|
1860
|
+
// model, so the starter create and delete handlers are what make this diagram
|
|
1861
|
+
// editable at all.
|
|
1803
1862
|
|
|
1804
1863
|
${importList([
|
|
1805
1864
|
'ActionHandlerConstructor',
|
|
1806
1865
|
'BindingTarget',
|
|
1866
|
+
'ComputedBoundsAction',
|
|
1807
1867
|
'DiagramConfiguration',
|
|
1808
1868
|
'GModelFactory',
|
|
1809
1869
|
'GModelIndex',
|
|
1870
|
+
'GModelRoot',
|
|
1810
1871
|
'InstanceMultiBinding',
|
|
1811
1872
|
'ModelState',
|
|
1812
1873
|
'ModelSubmissionHandler',
|
|
1874
|
+
'ModelValidator',
|
|
1813
1875
|
'OperationHandlerConstructor',
|
|
1814
1876
|
'SourceModelStorage'
|
|
1815
1877
|
], '@eclipse-glsp/server', columns, true)}
|
|
1816
1878
|
import { ComputedBoundsActionHandler } from '@eclipse-glsp/server';
|
|
1817
|
-
|
|
1818
|
-
${importList(['HydraniumGlspComputedBoundsActionHandler', 'AbstractHydraniumGlspDiagramModule', 'HydraniumGlspIndex'], '@hydranium/glsp-server', columns)}
|
|
1819
|
-
import { __GRAMMAR__LanguageMetaData } from '../../language-server/generated/module.js';
|
|
1879
|
+
${importList(['HydraniumGlspComputedBoundsActionHandler', 'AbstractHydraniumGlspDiagramModule', 'HydraniumGlspIndex', 'HydraniumGlspModelValidator'], '@hydranium/glsp-server', columns)}
|
|
1820
1880
|
import { __GRAMMAR__CreateNodeOperationHandler } from './create-node-operation-handler.js';
|
|
1881
|
+
import { __GRAMMAR__DeleteOperationHandler } from './delete-operation-handler.js';
|
|
1821
1882
|
import { __GRAMMAR__DiagramConfiguration } from './diagram-configuration.js';
|
|
1822
1883
|
import { __GRAMMAR__GModelFactory } from './gmodel-factory.js';
|
|
1823
1884
|
import { __GRAMMAR__GlspState } from './state.js';
|
|
1824
1885
|
import { __GRAMMAR__GlspStorage } from './storage.js';
|
|
1825
1886
|
import { __GRAMMAR__SubmissionHandler } from './submission-handler.js';
|
|
1826
|
-
import {
|
|
1827
|
-
|
|
1828
|
-
export class __GRAMMAR__DiagramModule extends AbstractHydraniumGlspDiagramModule {
|
|
1829
|
-
readonly diagramType = ${upper}_DIAGRAM_TYPE;
|
|
1887
|
+
import { __GRAMMAR_ID_CONST___DIAGRAM_TYPE } from '__PROTOCOL_PACKAGE__';
|
|
1888
|
+
import { injectable } from 'inversify';
|
|
1830
1889
|
|
|
1831
|
-
|
|
1832
|
-
|
|
1890
|
+
/**
|
|
1891
|
+
* The framework handler, keeping none of the edge routes the client reports:
|
|
1892
|
+
* it routes an edge before it sizes the nodes, so a self-reference's loop would
|
|
1893
|
+
* stay drawn inside its node. The starter's edges have no routing points, and
|
|
1894
|
+
* the client routes them afresh from the sized nodes.
|
|
1895
|
+
*/
|
|
1896
|
+
@injectable()
|
|
1897
|
+
export class __GRAMMAR__ComputedBoundsActionHandler extends HydraniumGlspComputedBoundsActionHandler {
|
|
1898
|
+
protected override applyBounds(root: GModelRoot, action: ComputedBoundsAction): void {
|
|
1899
|
+
super.applyBounds(root, { ...action, routes: undefined });
|
|
1833
1900
|
}
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
export class __GRAMMAR__DiagramModule extends AbstractHydraniumGlspDiagramModule {
|
|
1904
|
+
readonly diagramType = __GRAMMAR_ID_CONST___DIAGRAM_TYPE;
|
|
1834
1905
|
|
|
1835
1906
|
protected override bindModelState(): BindingTarget<ModelState> {
|
|
1836
1907
|
return { service: __GRAMMAR__GlspState };
|
|
@@ -1857,80 +1928,2240 @@ export class __GRAMMAR__DiagramModule extends AbstractHydraniumGlspDiagramModule
|
|
|
1857
1928
|
return { service: HydraniumGlspIndex };
|
|
1858
1929
|
}
|
|
1859
1930
|
|
|
1931
|
+
/**
|
|
1932
|
+
* The language's diagnostics as diagram markers, following each edit. GLSP
|
|
1933
|
+
* binds no validator by default, and without one no marker ever shows.
|
|
1934
|
+
*/
|
|
1935
|
+
protected override bindModelValidator(): BindingTarget<ModelValidator> {
|
|
1936
|
+
return HydraniumGlspModelValidator;
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1860
1939
|
protected override configureActionHandlers(binding: InstanceMultiBinding<ActionHandlerConstructor>): void {
|
|
1861
1940
|
super.configureActionHandlers(binding);
|
|
1862
|
-
binding.rebind(ComputedBoundsActionHandler,
|
|
1941
|
+
binding.rebind(ComputedBoundsActionHandler, __GRAMMAR__ComputedBoundsActionHandler);
|
|
1863
1942
|
}
|
|
1864
1943
|
|
|
1865
1944
|
protected override configureOperationHandlers(binding: InstanceMultiBinding<OperationHandlerConstructor>): void {
|
|
1866
1945
|
super.configureOperationHandlers(binding);
|
|
1867
1946
|
binding.add(__GRAMMAR__CreateNodeOperationHandler);
|
|
1947
|
+
binding.add(__GRAMMAR__DeleteOperationHandler);
|
|
1868
1948
|
}
|
|
1869
1949
|
}
|
|
1870
1950
|
`;
|
|
1871
1951
|
return [
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1952
|
+
fixed('state.ts'),
|
|
1953
|
+
fixed('storage.ts'),
|
|
1954
|
+
fixed('submission-handler.ts'),
|
|
1955
|
+
fixed('gmodel-factory.ts'),
|
|
1956
|
+
computed('diagram-configuration.ts', configuration),
|
|
1957
|
+
fixed('create-node-operation-handler.ts'),
|
|
1958
|
+
fixed('delete-operation-handler.ts'),
|
|
1959
|
+
computed('diagram-module.ts', module),
|
|
1960
|
+
grammarTemplate('server/test/__GRAMMAR_ID__-diagram.test.ts', composition, grammar)
|
|
1880
1961
|
];
|
|
1881
1962
|
}
|
|
1882
1963
|
/**
|
|
1883
|
-
*
|
|
1964
|
+
* The server member: the grammar, the language and its heads.
|
|
1884
1965
|
*
|
|
1885
1966
|
* Grammar-count-dependent emissions live here rather than in a template string:
|
|
1886
1967
|
* one `.langium` file per grammar, and the shared `common.langium` fragment only
|
|
1887
1968
|
* when there is more than one grammar to share it.
|
|
1888
1969
|
*/
|
|
1889
|
-
|
|
1970
|
+
function serverFiles(composition) {
|
|
1890
1971
|
const multi = composition.grammars.length > 1;
|
|
1891
1972
|
const grammarFiles = composition.grammars.map(grammar => ({
|
|
1892
|
-
path: `src/grammar/${grammar.grammarId}.langium`,
|
|
1973
|
+
path: `server/src/grammar/${grammar.grammarId}.langium`,
|
|
1893
1974
|
content: render(grammarFile(multi), composition, grammar)
|
|
1894
1975
|
}));
|
|
1976
|
+
// The shared lexical fragment, only for several grammars: each declaring its
|
|
1977
|
+
// own `WS` / `ID` lets the token sets drift apart.
|
|
1895
1978
|
if (multi) {
|
|
1896
|
-
grammarFiles.unshift(
|
|
1979
|
+
grammarFiles.unshift(projectTemplate('server/src/grammar/common.langium', composition));
|
|
1897
1980
|
}
|
|
1898
1981
|
const diagramFiles = composition.grammars.filter(grammar => grammar.diagram).flatMap(grammar => glspFiles(composition, grammar));
|
|
1899
1982
|
return [
|
|
1900
|
-
{ path: 'package.json', content: packageJson(composition) },
|
|
1901
|
-
{ path: 'langium-config.json', content: langiumConfig(composition) },
|
|
1902
|
-
{ path: 'tsconfig.json', content:
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1983
|
+
{ path: 'server/package.json', content: packageJson(composition) },
|
|
1984
|
+
{ path: 'server/langium-config.json', content: langiumConfig(composition) },
|
|
1985
|
+
{ path: 'server/tsconfig.json', content: serverTsconfigJson(composition) },
|
|
1986
|
+
// `isolatedModules` is what makes this check agree with the transform that
|
|
1987
|
+
// actually runs the tests. `npm test` is `typecheck:test && vitest run`, and
|
|
1988
|
+
// vitest compiles each file on its own — a transform with no type
|
|
1989
|
+
// information, which cannot tell a re-exported TYPE from a re-exported value.
|
|
1990
|
+
// Without the flag `tsc` accepts `export { SomeType } from './x'` that the
|
|
1991
|
+
// transform then emits as a real import of a symbol that does not exist at
|
|
1992
|
+
// runtime, so the typecheck passes and the suite fails with a confusing
|
|
1993
|
+
// missing-export.
|
|
1994
|
+
projectTemplate('server/tsconfig.test.json', composition),
|
|
1995
|
+
// Found by name, unlike `tsconfig.test.json`. Under vite 8, vitest's transform
|
|
1996
|
+
// applies a tsconfig only to the files its own `include` lists, so without this
|
|
1997
|
+
// a test declaring a decorated class fails to load.
|
|
1998
|
+
projectTemplate('server/test/tsconfig.json', composition),
|
|
1999
|
+
projectTemplate('server/vitest.config.ts', composition),
|
|
2000
|
+
// Written for a workspace member too: its root may not ignore `lib/` (a `yo
|
|
2001
|
+
// langium` root ignores `out/`), and a rule the root repeats costs nothing.
|
|
2002
|
+
ignoreFile('server'),
|
|
2003
|
+
{ path: 'server/README.md', content: readme(composition) },
|
|
1910
2004
|
...grammarFiles,
|
|
1911
|
-
{ path: `src/language-server/${composition.projectId}-module.ts`, content: moduleFile(composition) },
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
2005
|
+
{ path: `server/src/language-server/${composition.projectId}-module.ts`, content: moduleFile(composition) },
|
|
2006
|
+
grammarTemplate('server/src/language-server/ast.ts', composition, composition.grammars[0]),
|
|
2007
|
+
// Per grammar, because `services.serializer.Serializer` is a per-language slot
|
|
2008
|
+
// and a serializer is grammar-shaped by definition. That is also why the
|
|
2009
|
+
// framework refuses to default it: its `UnboundSerializer` throws, naming the
|
|
2010
|
+
// binding to add, rather than guessing a syntax.
|
|
2011
|
+
...composition.grammars.flatMap(grammar => [
|
|
2012
|
+
grammarTemplate('server/src/language-server/__GRAMMAR_ID__-serializer.ts', composition, grammar),
|
|
2013
|
+
grammarTemplate('server/src/language-server/__GRAMMAR_ID__-validation.ts', composition, grammar)
|
|
2014
|
+
]),
|
|
2015
|
+
{ path: 'server/src/index.ts', content: indexFile(composition) },
|
|
2016
|
+
projectTemplate('server/src/node/services.ts', composition),
|
|
2017
|
+
{ path: 'server/src/main.ts', content: mainFile(composition) },
|
|
2018
|
+
...(composition.heads.includes('data') ? [{ path: 'server/src/data-server-main.ts', content: dataServerMainFile(composition) }] : []),
|
|
1922
2019
|
...diagramFiles,
|
|
1923
|
-
{ path: 'test/services.test.ts', content: servicesTest(composition) },
|
|
1924
|
-
{ path: 'test/parsing.test.ts', content: grammarTest(composition, PARSING_HEADER, [], PARSING_SUITE) },
|
|
2020
|
+
{ path: 'server/test/services.test.ts', content: servicesTest(composition) },
|
|
2021
|
+
{ path: 'server/test/parsing.test.ts', content: grammarTest(composition, PARSING_HEADER, [], PARSING_SUITE) },
|
|
1925
2022
|
{
|
|
1926
|
-
path: 'test/linking.test.ts',
|
|
2023
|
+
path: 'server/test/linking.test.ts',
|
|
1927
2024
|
content: grammarTest(composition, LINKING_HEADER, ["import { AstUtils } from '@hydranium/langium';"], LINKING_SUITE)
|
|
1928
2025
|
},
|
|
1929
2026
|
{
|
|
1930
|
-
path: 'test/validating.test.ts',
|
|
2027
|
+
path: 'server/test/validating.test.ts',
|
|
1931
2028
|
content: grammarTest(composition, VALIDATING_HEADER, ["import { DiagnosticSeverity } from 'vscode-languageserver';"], VALIDATING_SUITE)
|
|
1932
2029
|
},
|
|
1933
|
-
{ path: 'test/serialization.test.ts', content: serializationTest(composition) }
|
|
2030
|
+
{ path: 'server/test/serialization.test.ts', content: serializationTest(composition) }
|
|
2031
|
+
];
|
|
2032
|
+
}
|
|
2033
|
+
/**
|
|
2034
|
+
* The protocol member's `package.json`.
|
|
2035
|
+
*
|
|
2036
|
+
* Its `build` runs the server's `generate` first, because the server writes
|
|
2037
|
+
* this package's `generated-hydranium/` modules from the grammar: a runner that
|
|
2038
|
+
* builds in dependency order reaches this package before the server, and would
|
|
2039
|
+
* otherwise compile modules that do not exist yet. A full build therefore
|
|
2040
|
+
* generates twice; the second pass rewrites nothing.
|
|
2041
|
+
*/
|
|
2042
|
+
function protocolPackageJson(composition) {
|
|
2043
|
+
const member = forMember(composition, 'protocol');
|
|
2044
|
+
const dependencies = {};
|
|
2045
|
+
for (const head of composition.heads) {
|
|
2046
|
+
Object.assign(dependencies, PROTOCOL_THIRD_PARTY_DEPENDENCIES[head]);
|
|
2047
|
+
}
|
|
2048
|
+
const dependencyLines = Object.keys(dependencies).length === 0 ? '' : ` "dependencies": {\n${sortedBlock(dependencies, ' ')}\n },\n`;
|
|
2049
|
+
return `{
|
|
2050
|
+
"name": "${memberPackageName(composition, 'protocol')}",
|
|
2051
|
+
"version": "0.0.0",
|
|
2052
|
+
${composition.packaging.private ? ' "private": true,\n' : ''} "description": "What the ${composition.name} language server and its clients share: language ids, wire types and diagram ids.",
|
|
2053
|
+
"license": "UNLICENSED",
|
|
2054
|
+
"author": "",
|
|
2055
|
+
"files": [
|
|
2056
|
+
"lib",
|
|
2057
|
+
"src"
|
|
2058
|
+
],
|
|
2059
|
+
"type": "module",
|
|
2060
|
+
"main": "lib/index.js",
|
|
2061
|
+
"types": "lib/index.d.ts",
|
|
2062
|
+
"scripts": {
|
|
2063
|
+
"build": "npm --prefix ../server run generate && tsc -b",
|
|
2064
|
+
"clean": "rimraf lib tsconfig.tsbuildinfo",
|
|
2065
|
+
${lintScript(member, 'src')} "watch": "tsc -b --watch"
|
|
2066
|
+
},
|
|
2067
|
+
${dependencyLines} "devDependencies": {
|
|
2068
|
+
"rimraf": "^5.0.0",
|
|
2069
|
+
"typescript": "^7.0.2"
|
|
2070
|
+
},
|
|
2071
|
+
"engines": {
|
|
2072
|
+
"node": ">=22.13"
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
`;
|
|
2076
|
+
}
|
|
2077
|
+
/** The protocol member's root entry, one re-export per module. */
|
|
2078
|
+
function protocolIndexFile(composition) {
|
|
2079
|
+
const modules = [
|
|
2080
|
+
'./generated-hydranium/languages.js',
|
|
2081
|
+
'./generated-hydranium/transfer-model.js',
|
|
2082
|
+
...(headPortConstants(composition).length ? ['./head-ports.js'] : []),
|
|
2083
|
+
...composition.grammars.filter(grammar => grammar.diagram).map(grammar => `./${grammar.grammarId}-diagram-types.js`)
|
|
2084
|
+
];
|
|
2085
|
+
const text = `// What the __NAME__ server and its clients both import. A client depends on
|
|
2086
|
+
// this package instead of the server, so it never installs Langium to reach a
|
|
2087
|
+
// constant or a wire type.
|
|
2088
|
+
//
|
|
2089
|
+
// The server's \`generate\` writes \`generated-hydranium/\` from the grammar;
|
|
2090
|
+
// commit those modules with the grammar change that produced them. An interface
|
|
2091
|
+
// narrowed here hides the generated constant of the same name; re-export that
|
|
2092
|
+
// constant beside it, and declare the type map under its own name with the
|
|
2093
|
+
// narrowed entry, or the builder and the GLSP state keep the generated one.
|
|
2094
|
+
|
|
2095
|
+
${modules.map(module => `export * from '${module}';`).join('\n')}
|
|
2096
|
+
`;
|
|
2097
|
+
return project(text, composition);
|
|
2098
|
+
}
|
|
2099
|
+
/** The protocol member's README. */
|
|
2100
|
+
function protocolReadme(composition) {
|
|
2101
|
+
const lines = [
|
|
2102
|
+
`# ${memberPackageName(composition, 'protocol')}`,
|
|
2103
|
+
'',
|
|
2104
|
+
'What the __NAME__ language server and its clients both import, so a client',
|
|
2105
|
+
'never depends on the server or installs Langium.',
|
|
2106
|
+
'',
|
|
2107
|
+
'- `src/generated-hydranium/languages.ts` — each language id and its file extensions',
|
|
2108
|
+
'- `src/generated-hydranium/transfer-model.ts` — the wire types of the model, references as plain strings',
|
|
2109
|
+
...(headPortConstants(composition).length === 0
|
|
2110
|
+
? []
|
|
2111
|
+
: composition.heads.includes('lsp')
|
|
2112
|
+
? ['- `src/head-ports.ts` — the LSP requests a host sends to find the socket heads']
|
|
2113
|
+
: ["- `src/head-ports.ts` — the environment variables naming the socket heads' ports"]),
|
|
2114
|
+
...composition.grammars
|
|
2115
|
+
.filter(grammar => grammar.diagram)
|
|
2116
|
+
.map(grammar => `- \`src/${grammar.grammarId}-diagram-types.ts\` — the \`${grammar.grammar}\` diagram's type ids`),
|
|
2117
|
+
'',
|
|
2118
|
+
"The server's `npm run generate` writes `src/generated-hydranium/` from the",
|
|
2119
|
+
'grammar, and `npm run build` here runs it first. Commit the generated',
|
|
2120
|
+
'modules with the grammar change that produced them.',
|
|
2121
|
+
''
|
|
2122
|
+
];
|
|
2123
|
+
return project(lines.join('\n'), composition);
|
|
2124
|
+
}
|
|
2125
|
+
/** The protocol member: everything the server and its clients both import. */
|
|
2126
|
+
function protocolFiles(composition) {
|
|
2127
|
+
return [
|
|
2128
|
+
{ path: 'protocol/package.json', content: protocolPackageJson(composition) },
|
|
2129
|
+
{ path: 'protocol/tsconfig.json', content: tsconfigJson(forMember(composition, 'protocol'), PROTOCOL_COMPILER_OPTIONS, '["src"]') },
|
|
2130
|
+
ignoreFile('protocol'),
|
|
2131
|
+
{ path: 'protocol/README.md', content: protocolReadme(composition) },
|
|
2132
|
+
{ path: 'protocol/src/index.ts', content: protocolIndexFile(composition) },
|
|
2133
|
+
...(headPortConstants(composition).length ? [{ path: 'protocol/src/head-ports.ts', content: headPortsFile(composition) }] : []),
|
|
2134
|
+
...composition.grammars
|
|
2135
|
+
.filter(grammar => grammar.diagram)
|
|
2136
|
+
.map(grammar => grammarTemplate('protocol/src/__GRAMMAR_ID__-diagram-types.ts', composition, grammar))
|
|
2137
|
+
];
|
|
2138
|
+
}
|
|
2139
|
+
/**
|
|
2140
|
+
* The starter model files every host and the CLI open, two per language: one
|
|
2141
|
+
* declaring nodes, one referencing a node in the other file.
|
|
2142
|
+
*
|
|
2143
|
+
* Named by extension alone, since `init` refuses two grammars sharing one.
|
|
2144
|
+
*/
|
|
2145
|
+
function workspaceFiles(composition) {
|
|
2146
|
+
return composition.grammars.flatMap(grammar => [
|
|
2147
|
+
grammarTemplate('workspace/nodes.__EXTENSION__', composition, grammar),
|
|
2148
|
+
grammarTemplate('workspace/references.__EXTENSION__', composition, grammar)
|
|
2149
|
+
]);
|
|
2150
|
+
}
|
|
2151
|
+
/** The client member's compiler options: the protocol's, with the DOM its diagram renders into. */
|
|
2152
|
+
const CLIENT_COMPILER_OPTIONS = [
|
|
2153
|
+
['target', 'ES2022'],
|
|
2154
|
+
['lib', ['ES2022', 'DOM']],
|
|
2155
|
+
['module', 'NodeNext'],
|
|
2156
|
+
['moduleResolution', 'NodeNext'],
|
|
2157
|
+
['rootDir', 'src'],
|
|
2158
|
+
['outDir', 'lib'],
|
|
2159
|
+
['strict', true],
|
|
2160
|
+
['skipLibCheck', true],
|
|
2161
|
+
['declaration', true],
|
|
2162
|
+
// For inversify's `@injectable`, which a GLSP view needs to be bound.
|
|
2163
|
+
['experimentalDecorators', true],
|
|
2164
|
+
['types', []],
|
|
2165
|
+
// A base that sets it fails every `import` in this CommonJS member.
|
|
2166
|
+
['verbatimModuleSyntax', false]
|
|
2167
|
+
];
|
|
2168
|
+
/**
|
|
2169
|
+
* The client member's `package.json`.
|
|
2170
|
+
*
|
|
2171
|
+
* CommonJS, unlike its siblings, as GLSP's client is: inversify ships an ES
|
|
2172
|
+
* build and a CommonJS one, so an ES module here would load the first while
|
|
2173
|
+
* GLSP's client loads the second, giving a page two containers' worth of
|
|
2174
|
+
* classes. Node from 22.12 and `tsc` under `nodenext` both let it require the
|
|
2175
|
+
* ES protocol member.
|
|
2176
|
+
*/
|
|
2177
|
+
function clientPackageJson(composition) {
|
|
2178
|
+
const dependencies = {
|
|
2179
|
+
[memberPackageName(composition, 'protocol')]: MEMBER_PIN,
|
|
2180
|
+
...CLIENT_THIRD_PARTY_DEPENDENCIES
|
|
2181
|
+
};
|
|
2182
|
+
for (const framework of CLIENT_FRAMEWORK_DEPENDENCIES) {
|
|
2183
|
+
dependencies[framework] = frameworkPin(composition);
|
|
2184
|
+
}
|
|
2185
|
+
return `{
|
|
2186
|
+
"name": "${memberPackageName(composition, 'client')}",
|
|
2187
|
+
"version": "0.0.0",
|
|
2188
|
+
${composition.packaging.private ? ' "private": true,\n' : ''} "description": "The host-neutral client side of the ${composition.name} language: what every host of it mounts.",
|
|
2189
|
+
"license": "UNLICENSED",
|
|
2190
|
+
"author": "",
|
|
2191
|
+
"files": [
|
|
2192
|
+
"lib",
|
|
2193
|
+
"src"
|
|
2194
|
+
],
|
|
2195
|
+
"main": "lib/index.js",
|
|
2196
|
+
"types": "lib/index.d.ts",
|
|
2197
|
+
"scripts": {
|
|
2198
|
+
"build": "tsc -b",
|
|
2199
|
+
"clean": "rimraf lib tsconfig.tsbuildinfo",
|
|
2200
|
+
${lintScript(forMember(composition, 'client'), 'src')} "watch": "tsc --watch"
|
|
2201
|
+
},
|
|
2202
|
+
"dependencies": {
|
|
2203
|
+
${sortedBlock(dependencies, ' ')}
|
|
2204
|
+
},
|
|
2205
|
+
"devDependencies": {
|
|
2206
|
+
"rimraf": "^5.0.0",
|
|
2207
|
+
"typescript": "^7.0.2"
|
|
2208
|
+
},
|
|
2209
|
+
"engines": {
|
|
2210
|
+
"node": ">=22.13"
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
`;
|
|
2214
|
+
}
|
|
2215
|
+
/** The client member's README. */
|
|
2216
|
+
function clientReadme(composition) {
|
|
2217
|
+
const diagrams = composition.grammars.filter(grammar => grammar.diagram);
|
|
2218
|
+
const lines = [
|
|
2219
|
+
`# ${memberPackageName(composition, 'client')}`,
|
|
2220
|
+
'',
|
|
2221
|
+
'The host-neutral client side of the __NAME__ language: what every host of it',
|
|
2222
|
+
'mounts, whatever that host is. It reads the element ids from the protocol',
|
|
2223
|
+
'package and never depends on the server.',
|
|
2224
|
+
'',
|
|
2225
|
+
...diagrams.map(grammar => `- \`src/${grammar.grammarId}-diagram-module.ts\` — the \`${grammar.grammar}\` diagram: a registration per element type, its container module, and \`initialize${grammar.grammar}DiagramContainer\``),
|
|
2226
|
+
'- `src/index.ts` — the package root, re-exporting each module',
|
|
2227
|
+
'',
|
|
2228
|
+
'A host builds a diagram container with the initializer, passing its own',
|
|
2229
|
+
'modules: they go first and the diagram definition last, since GLSP gives an',
|
|
2230
|
+
'element type to whichever module registered it last.',
|
|
2231
|
+
''
|
|
2232
|
+
];
|
|
2233
|
+
return project(lines.join('\n'), composition);
|
|
2234
|
+
}
|
|
2235
|
+
/** The client member's root entry, one re-export per diagram module. */
|
|
2236
|
+
function clientIndexFile(composition) {
|
|
2237
|
+
const modules = composition.grammars.filter(grammar => grammar.diagram).map(grammar => `./${grammar.grammarId}-diagram-module.js`);
|
|
2238
|
+
return `// What every host of the ${composition.name} language mounts.
|
|
2239
|
+
|
|
2240
|
+
${modules.map(module => `export * from '${module}';`).join('\n')}
|
|
2241
|
+
`;
|
|
2242
|
+
}
|
|
2243
|
+
/**
|
|
2244
|
+
* The client member: the host-neutral client side of the language, emitted
|
|
2245
|
+
* when there is a diagram to define. Each host mounts it rather than defining
|
|
2246
|
+
* the diagram again.
|
|
2247
|
+
*/
|
|
2248
|
+
function clientFiles(composition) {
|
|
2249
|
+
return [
|
|
2250
|
+
{ path: 'client/package.json', content: clientPackageJson(composition) },
|
|
2251
|
+
{
|
|
2252
|
+
path: 'client/tsconfig.json',
|
|
2253
|
+
content: tsconfigJson(forMember(composition, 'client'), CLIENT_COMPILER_OPTIONS, '["src"]', '[{ "path": "../protocol" }]')
|
|
2254
|
+
},
|
|
2255
|
+
ignoreFile('client'),
|
|
2256
|
+
{ path: 'client/README.md', content: clientReadme(composition) },
|
|
2257
|
+
{ path: 'client/src/index.ts', content: clientIndexFile(composition) },
|
|
2258
|
+
...composition.grammars
|
|
2259
|
+
.filter(grammar => grammar.diagram)
|
|
2260
|
+
.map(grammar => grammarTemplate('client/src/__GRAMMAR_ID__-diagram-module.ts', composition, grammar))
|
|
2261
|
+
];
|
|
2262
|
+
}
|
|
2263
|
+
/**
|
|
2264
|
+
* The browser host's `package.json`. Always private: it is an application,
|
|
2265
|
+
* which nothing installs as a dependency.
|
|
2266
|
+
*/
|
|
2267
|
+
function hostBrowserPackageJson(composition) {
|
|
2268
|
+
const dependencies = {
|
|
2269
|
+
[memberPackageName(composition, 'protocol')]: MEMBER_PIN,
|
|
2270
|
+
[memberPackageName(composition, 'server')]: MEMBER_PIN,
|
|
2271
|
+
...(composition.heads.includes('glsp') ? { [memberPackageName(composition, 'client')]: MEMBER_PIN } : {}),
|
|
2272
|
+
// A page with no editor saves through the diagram's own action dispatcher.
|
|
2273
|
+
...(composition.heads.includes('lsp') ? {} : { '@eclipse-glsp/client': CLIENT_THIRD_PARTY_DEPENDENCIES['@eclipse-glsp/client'] })
|
|
2274
|
+
};
|
|
2275
|
+
for (const head of ['base', ...composition.heads]) {
|
|
2276
|
+
Object.assign(dependencies, HOST_BROWSER_THIRD_PARTY_DEPENDENCIES[head]);
|
|
2277
|
+
for (const framework of HOST_BROWSER_FRAMEWORK_DEPENDENCIES[head]) {
|
|
2278
|
+
dependencies[framework] = frameworkPin(composition);
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
return `{
|
|
2282
|
+
"name": "${memberPackageName(composition, 'host-browser')}",
|
|
2283
|
+
"version": "0.0.0",
|
|
2284
|
+
"private": true,
|
|
2285
|
+
"description": "${composition.name} in a browser page, with every head in a web worker and no backend.",
|
|
2286
|
+
"license": "UNLICENSED",
|
|
2287
|
+
"author": "",
|
|
2288
|
+
"type": "module",
|
|
2289
|
+
"scripts": {
|
|
2290
|
+
"build": "npm run typecheck && node esbuild.mjs",
|
|
2291
|
+
"clean": "rimraf out test-results playwright-report",
|
|
2292
|
+
${lintScript(forMember(composition, 'host-browser'), 'src test')} "start": "node esbuild.mjs --serve",
|
|
2293
|
+
"test:e2e": "playwright test --tsconfig tsconfig.e2e.json",
|
|
2294
|
+
"test:e2e:install": "playwright install chromium",
|
|
2295
|
+
"typecheck": "tsc --noEmit -p tsconfig.worker.json && tsc --noEmit -p tsconfig.page.json && tsc --noEmit -p tsconfig.e2e.json"
|
|
2296
|
+
},
|
|
2297
|
+
"dependencies": {
|
|
2298
|
+
${sortedBlock(dependencies, ' ')}
|
|
2299
|
+
},
|
|
2300
|
+
"devDependencies": {
|
|
2301
|
+
${sortedBlock(HOST_BROWSER_DEV_DEPENDENCIES, ' ')}
|
|
2302
|
+
},
|
|
2303
|
+
"engines": {
|
|
2304
|
+
"node": ">=22.13"
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
`;
|
|
2308
|
+
}
|
|
2309
|
+
/** The workspace URI of a grammar's first starter file, as a template literal over `WORKSPACE_ROOT_URI`. */
|
|
2310
|
+
function starterUri(grammar) {
|
|
2311
|
+
return `\`\${WORKSPACE_ROOT_URI}/nodes.${grammar.extensions[0]}\``;
|
|
2312
|
+
}
|
|
2313
|
+
/**
|
|
2314
|
+
* The worker hosting the heads: every head over the one store, with the
|
|
2315
|
+
* workspace seeded from `../workspace` and saved files kept in IndexedDB.
|
|
2316
|
+
*/
|
|
2317
|
+
function hostWorkerFile(composition) {
|
|
2318
|
+
const columns = columnsFor(composition);
|
|
2319
|
+
const lsp = composition.heads.includes('lsp');
|
|
2320
|
+
const data = composition.heads.includes('data');
|
|
2321
|
+
const glsp = composition.heads.includes('glsp');
|
|
2322
|
+
const diagrams = composition.grammars.filter(grammar => grammar.diagram);
|
|
2323
|
+
const roots = composition.grammars.map(grammar => grammar.entryRule).sort();
|
|
2324
|
+
const serverSymbols = [`create${composition.name}Services`, ...diagrams.map(grammar => `${grammar.grammar}DiagramModule`)].sort((left, right) => left.localeCompare(right));
|
|
2325
|
+
const imports = [
|
|
2326
|
+
...(glsp
|
|
2327
|
+
? [
|
|
2328
|
+
'// First, before any class carrying a decorator loads: GLSP reads the metadata',
|
|
2329
|
+
'// its decorators emit as each class is defined.',
|
|
2330
|
+
"import 'reflect-metadata';",
|
|
2331
|
+
"import { ServerModule } from '@eclipse-glsp/server/browser.js';"
|
|
2332
|
+
]
|
|
2333
|
+
: []),
|
|
2334
|
+
"import { persistentFileSystem } from '@hydranium/core';",
|
|
2335
|
+
importList(['hostHeadsInWorker', 'IndexedDbFileSystemStore', ...(lsp ? ['startLanguageServerInWorker'] : [])], '@hydranium/core/browser', columns),
|
|
2336
|
+
...(data
|
|
2337
|
+
? [
|
|
2338
|
+
"import { DataServer } from '@hydranium/data-server';",
|
|
2339
|
+
"import { startDataServerInWorker } from '@hydranium/data-server/browser';"
|
|
2340
|
+
]
|
|
2341
|
+
: []),
|
|
2342
|
+
...(glsp
|
|
2343
|
+
? [
|
|
2344
|
+
"import { GlspClientLogger, HydraniumGlspAppModule } from '@hydranium/glsp-server';",
|
|
2345
|
+
"import { startGlspServerInWorker } from '@hydranium/glsp-server/browser';"
|
|
2346
|
+
]
|
|
2347
|
+
: []),
|
|
2348
|
+
...(data ? [importList(roots, memberPackageName(composition, 'protocol'), columns, true)] : []),
|
|
2349
|
+
importList(serverSymbols, memberPackageName(composition, 'server'), columns),
|
|
2350
|
+
"import { WORKSPACE_ROOT_URI } from './workspace.js';"
|
|
2351
|
+
];
|
|
2352
|
+
const services = `const shared = create${composition.name}Services({ ...fileSystem }).shared;`;
|
|
2353
|
+
const lspCall = `startLanguageServerInWorker(ports.lsp, connection => create${composition.name}Services({ connection, ...fileSystem }).shared);`;
|
|
2354
|
+
const startServices = !lsp
|
|
2355
|
+
? services
|
|
2356
|
+
: ` const shared = ${lspCall}`.length <= columns
|
|
2357
|
+
? `const shared = ${lspCall}`
|
|
2358
|
+
: `const shared = startLanguageServerInWorker(
|
|
2359
|
+
ports.lsp,
|
|
2360
|
+
connection => create${composition.name}Services({ connection, ...fileSystem }).shared
|
|
2361
|
+
);`;
|
|
2362
|
+
const dataServer = `connection => new DataServer<${roots.join(' | ')}>(connection, shared)`;
|
|
2363
|
+
const dataCall = `startDataServerInWorker(ports.data, shared, ${dataServer});`;
|
|
2364
|
+
const dataHead = data
|
|
2365
|
+
? `
|
|
2366
|
+
// The data head serves from the ${lsp ? "LSP head's" : "services'"} store, on its own port.
|
|
2367
|
+
${` ${dataCall}`.length <= columns
|
|
2368
|
+
? dataCall
|
|
2369
|
+
: `startDataServerInWorker(
|
|
2370
|
+
ports.data,
|
|
2371
|
+
shared,
|
|
2372
|
+
${dataServer}
|
|
2373
|
+
);`}`
|
|
2374
|
+
: '';
|
|
2375
|
+
const glspHead = glsp
|
|
2376
|
+
? `
|
|
2377
|
+
const glsp = startGlspServerInWorker({
|
|
2378
|
+
context: ports.glsp,
|
|
2379
|
+
createLogger: caller => new GlspClientLogger(shared, { component: caller }),
|
|
2380
|
+
serverModule: new ServerModule()${diagrams.map(grammar => `.configureDiagramModule(new ${grammar.grammar}DiagramModule())`).join('')},
|
|
2381
|
+
appModules: [new HydraniumGlspAppModule({ shared })]
|
|
2382
|
+
});
|
|
2383
|
+
// The GLSP head reports a failed start through \`started\`, which the
|
|
2384
|
+
// ready message waits for.
|
|
2385
|
+
return { shared, started: [glsp.started] };`
|
|
2386
|
+
: `
|
|
2387
|
+
return shared;`;
|
|
2388
|
+
const text = `// The worker hosting the heads: every head over one store, in the browser and
|
|
2389
|
+
// with no backend. The page reaches each head over a \`MessagePort\` of its own.
|
|
2390
|
+
|
|
2391
|
+
${imports.join('\n')}
|
|
2392
|
+
|
|
2393
|
+
/** The files of \`../workspace\`, read by \`esbuild.mjs\` and keyed by their path below the root. */
|
|
2394
|
+
declare const __WORKSPACE_SEED__: Record<string, string>;
|
|
2395
|
+
/** This project's directory, hashed by \`esbuild.mjs\`, so that no other project on the origin opens its store. */
|
|
2396
|
+
declare const __DIRECTORY_KEY__: string;
|
|
2397
|
+
|
|
2398
|
+
// A saved file is kept in IndexedDB and laid over the seed on the next load;
|
|
2399
|
+
// the heads start once the stored files are restored.
|
|
2400
|
+
const store = new IndexedDbFileSystemStore(\`__PROJECT_ID__-workspace-\${__DIRECTORY_KEY__}\`);
|
|
2401
|
+
|
|
2402
|
+
hostHeadsInWorker(
|
|
2403
|
+
persistentFileSystem({ store, seed: __WORKSPACE_SEED__, rootUri: WORKSPACE_ROOT_URI }),
|
|
2404
|
+
(ports, fileSystem) => {
|
|
2405
|
+
${lsp ? '// The LSP head composes the services, as the Node entry does around stdio.\n ' : ''}${startServices}${dataHead}${glspHead}
|
|
2406
|
+
},
|
|
2407
|
+
${lsp
|
|
2408
|
+
? '// The ready message then carries the workspace files the page opens.'
|
|
2409
|
+
: '// With no LSP head the workspace comes up from this root, and the ready\n // message then carries its files.'}
|
|
2410
|
+
{ rootUri: WORKSPACE_ROOT_URI }
|
|
2411
|
+
);
|
|
2412
|
+
`;
|
|
2413
|
+
return project(text, composition);
|
|
2414
|
+
}
|
|
2415
|
+
/**
|
|
2416
|
+
* The page, and the one place deciding which head's part of it runs: each
|
|
2417
|
+
* part is a module of its own, and this calls the ones the heads serve.
|
|
2418
|
+
*/
|
|
2419
|
+
function hostPageFile(composition) {
|
|
2420
|
+
const lsp = composition.heads.includes('lsp');
|
|
2421
|
+
const data = composition.heads.includes('data');
|
|
2422
|
+
const diagram = composition.grammars.find(grammar => grammar.diagram);
|
|
2423
|
+
// A host takes lsp or glsp, and glsp marks a diagram grammar, so without lsp there is one.
|
|
2424
|
+
const diagramLanguage = lsp || diagram === undefined ? undefined : `${screamingSnake(diagram.grammarId)}_LANGUAGE`;
|
|
2425
|
+
const shownLanguage = diagramLanguage ?? 'ALL_LANGUAGES';
|
|
2426
|
+
const parts = [
|
|
2427
|
+
// Every part follows the file the page shows, so the switch comes first. With
|
|
2428
|
+
// no editor it lists only the diagram's files, the only ones the page shows.
|
|
2429
|
+
{
|
|
2430
|
+
module: './shown-file.js',
|
|
2431
|
+
imports: 'startShownFile',
|
|
2432
|
+
call: `const shownFile = await startShownFile(heads, ${diagramLanguage === undefined ? shownLanguage : `[${diagramLanguage}]`});`
|
|
2433
|
+
},
|
|
2434
|
+
// Save is armed with the editor, so it works before the other panes load;
|
|
2435
|
+
// with a diagram it waits for the edits of the one shown, once mounted.
|
|
2436
|
+
...(lsp
|
|
2437
|
+
? [
|
|
2438
|
+
{
|
|
2439
|
+
module: './editor.js',
|
|
2440
|
+
imports: 'armEditorSave, startEditor',
|
|
2441
|
+
call: [
|
|
2442
|
+
'const editor = await startEditor(heads, shownFile);',
|
|
2443
|
+
...(diagram === undefined
|
|
2444
|
+
? ['armEditorSave(editor);']
|
|
2445
|
+
: [
|
|
2446
|
+
'let shownDiagram: Awaited<ReturnType<typeof mountDiagram>> | undefined = undefined;',
|
|
2447
|
+
'armEditorSave(editor, () => settleDiagramEdits(shownDiagram?.()));'
|
|
2448
|
+
])
|
|
2449
|
+
].join('\n ')
|
|
2450
|
+
}
|
|
2451
|
+
]
|
|
2452
|
+
: []),
|
|
2453
|
+
...(data
|
|
2454
|
+
? [
|
|
2455
|
+
{
|
|
2456
|
+
module: './data-status.js',
|
|
2457
|
+
imports: 'showDataStatus',
|
|
2458
|
+
call: `await showDataStatus(heads.data, ${starterUri(composition.grammars[0])});`
|
|
2459
|
+
}
|
|
2460
|
+
]
|
|
2461
|
+
: []),
|
|
2462
|
+
...(diagram === undefined
|
|
2463
|
+
? []
|
|
2464
|
+
: [
|
|
2465
|
+
{
|
|
2466
|
+
module: './diagram.js',
|
|
2467
|
+
imports: lsp ? 'mountDiagram, settleDiagramEdits' : 'mountDiagram',
|
|
2468
|
+
call: `${lsp ? 'shownDiagram' : 'const shownDiagram'} = await mountDiagram(heads.glsp, shownFile, logger, ${lsp ? 'settleDiagramEdits' : 'saveBeforeLeaving'});`
|
|
2469
|
+
}
|
|
2470
|
+
]),
|
|
2471
|
+
// Without the editor, the diagram is what the page saves through.
|
|
2472
|
+
...(lsp ? [] : [{ module: './diagram-save.js', imports: 'armDiagramSave, saveBeforeLeaving', call: 'armDiagramSave(shownDiagram);' }])
|
|
2473
|
+
];
|
|
2474
|
+
const imports = [
|
|
2475
|
+
...parts.map(part => `import { ${part.imports} } from '${part.module}';`),
|
|
2476
|
+
"import { appendLog, setStatus } from './log.js';",
|
|
2477
|
+
...(data ? ["import { WORKSPACE_ROOT_URI } from './workspace.js';"] : [])
|
|
2478
|
+
].sort((left, right) => left.slice(left.indexOf("'")).localeCompare(right.slice(right.indexOf("'"))));
|
|
2479
|
+
return `// The page: it starts the worker, hands each head a channel of its own, and
|
|
2480
|
+
// fills the pane of each head the server runs, one after the other.
|
|
2481
|
+
|
|
2482
|
+
import { connectWorkerHeads } from '@hydranium/client-browser';
|
|
2483
|
+
import { ConsoleLogger, describeError } from '@hydranium/protocol';
|
|
2484
|
+
import { ${shownLanguage} } from '${memberPackageName(composition, 'protocol')}';
|
|
2485
|
+
${imports.join('\n')}
|
|
2486
|
+
|
|
2487
|
+
/** Where the worker bundle is served, substituted by \`esbuild.mjs\`. */
|
|
2488
|
+
declare const __WORKER_BUNDLE_URL__: string;
|
|
2489
|
+
|
|
2490
|
+
async function main(): Promise<void> {
|
|
2491
|
+
// The page's end of each head's connection logs to the browser console.
|
|
2492
|
+
const logger = new ConsoleLogger();
|
|
2493
|
+
const heads = connectWorkerHeads(new Worker(__WORKER_BUNDLE_URL__), { logger });
|
|
2494
|
+
heads.onWorkerError(report => appendLog(\`worker error during \${report.phase}: \${report.message}\`));
|
|
2495
|
+
setStatus('starting…');
|
|
2496
|
+
${parts.map(part => ` ${part.call}`).join('\n')}
|
|
2497
|
+
setStatus('ready');
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2500
|
+
main().catch((error: unknown) => setStatus(\`failed: \${describeError(error)}\`));
|
|
2501
|
+
`;
|
|
2502
|
+
}
|
|
2503
|
+
/**
|
|
2504
|
+
* The smoke test: what each head shows on the page, and an edit that survives
|
|
2505
|
+
* a reload, typed in the editor or, with no LSP head, made in the diagram. With
|
|
2506
|
+
* a diagram, also a diagram edit the reload guard and Save catch before the
|
|
2507
|
+
* server has answered it.
|
|
2508
|
+
*/
|
|
2509
|
+
function hostSmokeSpec(composition) {
|
|
2510
|
+
const lsp = composition.heads.includes('lsp');
|
|
2511
|
+
const data = composition.heads.includes('data');
|
|
2512
|
+
const diagram = composition.grammars.find(grammar => grammar.diagram);
|
|
2513
|
+
const primary = composition.grammars[0];
|
|
2514
|
+
const checks = [
|
|
2515
|
+
...(lsp ? [" await expect(editor).toContainText('node First');"] : []),
|
|
2516
|
+
...(data
|
|
2517
|
+
? [
|
|
2518
|
+
' // The data head reads the document out of the same store.',
|
|
2519
|
+
` await expect(page.locator('#data-status')).toHaveText('data head: nodes.${primary.extensions[0]} holds a ${primary.entryRule}');`
|
|
2520
|
+
]
|
|
2521
|
+
: []),
|
|
2522
|
+
...(diagram === undefined
|
|
2523
|
+
? []
|
|
2524
|
+
: [
|
|
2525
|
+
' // The diagram follows the switch: two nodes in one file, and in the other its',
|
|
2526
|
+
' // node and the target it references there, drawn as external.',
|
|
2527
|
+
" const first = await page.locator('#file').inputValue();",
|
|
2528
|
+
` await page.locator('#file').selectOption('nodes.${diagram.extensions[0]}');`,
|
|
2529
|
+
" await expect(page.locator('#diagram .sprotty-node')).toHaveCount(2);",
|
|
2530
|
+
` await page.locator('#file').selectOption('references.${diagram.extensions[0]}');`,
|
|
2531
|
+
` await expect(page.locator('#diagram .external')).toHaveText('Second (nodes.${diagram.extensions[0]})');`,
|
|
2532
|
+
" await page.locator('#file').selectOption(first);"
|
|
2533
|
+
])
|
|
2534
|
+
];
|
|
2535
|
+
const edit = lsp
|
|
2536
|
+
? ` await editor.click();
|
|
2537
|
+
await page.keyboard.press('ControlOrMeta+End');
|
|
2538
|
+
await page.keyboard.type('\\nnode Added');
|
|
2539
|
+
await page.locator('#save').click();
|
|
2540
|
+
await expect(page.locator('#status')).toHaveText('saved 1 file(s)');
|
|
2541
|
+
|
|
2542
|
+
await page.reload();
|
|
2543
|
+
await expect(page.locator('#status')).toHaveText('ready');
|
|
2544
|
+
await expect(editor).toContainText('node Added');`
|
|
2545
|
+
: ` // A node from the palette, dropped low and left of centre: the starter nodes
|
|
2546
|
+
// sit in the upper band and the palette in the upper right.
|
|
2547
|
+
const canvas = page.locator('#diagram');
|
|
2548
|
+
const create = async (): Promise<void> => {
|
|
2549
|
+
await page.locator('#diagram .tool-button', { hasText: '${diagram?.nodeRule}' }).click();
|
|
2550
|
+
const size = await canvas.evaluate(element => ({ width: element.clientWidth, height: element.clientHeight }));
|
|
2551
|
+
await canvas.click({ position: { x: size.width * 0.4, y: size.height * 0.85 } });
|
|
2552
|
+
};
|
|
2553
|
+
await create();
|
|
2554
|
+
await expect(nodes).toHaveCount(3);
|
|
2555
|
+
await page.locator('#save').click();
|
|
2556
|
+
await expect(page.locator('#status')).toHaveText('saved the diagram');
|
|
2557
|
+
// A second, left unsaved: the switch saves the diagram it leaves.
|
|
2558
|
+
await create();
|
|
2559
|
+
await expect(nodes).toHaveCount(4);
|
|
2560
|
+
await page.locator('#file').selectOption('references.${diagram?.extensions[0]}');
|
|
2561
|
+
await expect(page.locator('#diagram .external')).toBeVisible();
|
|
2562
|
+
|
|
2563
|
+
await page.reload();
|
|
2564
|
+
await expect(page.locator('#status')).toHaveText('ready');
|
|
2565
|
+
await expect(nodes).toHaveCount(4);`;
|
|
2566
|
+
const guardTest = diagram === undefined
|
|
2567
|
+
? ''
|
|
2568
|
+
: `
|
|
2569
|
+
test('asks before a reload drops a diagram edit the server has not answered, and saves it with Save at once', async ({ page }) => {
|
|
2570
|
+
const nodes = page.locator('#diagram .sprotty-node');
|
|
2571
|
+
const askGuard = (): Promise<boolean> =>
|
|
2572
|
+
page.evaluate(() => {
|
|
2573
|
+
const event = new Event('beforeunload', { cancelable: true });
|
|
2574
|
+
window.dispatchEvent(event);
|
|
2575
|
+
return event.defaultPrevented;
|
|
2576
|
+
});
|
|
2577
|
+
await page.goto('/');
|
|
2578
|
+
await expect(page.locator('#status')).toHaveText('ready');
|
|
2579
|
+
await page.locator('#file').selectOption('nodes.${diagram.extensions[0]}');
|
|
2580
|
+
await expect(nodes).toHaveCount(2);
|
|
2581
|
+
|
|
2582
|
+
const canvas = page.locator('#diagram');
|
|
2583
|
+
await page.locator('#diagram .tool-button', { hasText: '${diagram.nodeRule}' }).click();
|
|
2584
|
+
const size = await canvas.evaluate(element => ({ width: element.clientWidth, height: element.clientHeight }));
|
|
2585
|
+
// Asked and clicked right after the click's own handlers, in the same turn
|
|
2586
|
+
// of the page, so the server's answer cannot have marked anything unsaved.
|
|
2587
|
+
await page.evaluate(() => {
|
|
2588
|
+
window.addEventListener(
|
|
2589
|
+
'mouseup',
|
|
2590
|
+
() =>
|
|
2591
|
+
queueMicrotask(() => {
|
|
2592
|
+
const event = new Event('beforeunload', { cancelable: true });
|
|
2593
|
+
window.dispatchEvent(event);
|
|
2594
|
+
document.getElementById('save')?.click();
|
|
2595
|
+
Reflect.set(window, 'guardedOnCreate', event.defaultPrevented);
|
|
2596
|
+
}),
|
|
2597
|
+
{ once: true }
|
|
2598
|
+
);
|
|
2599
|
+
});
|
|
2600
|
+
await canvas.click({ position: { x: size.width * 0.4, y: size.height * 0.85 } });
|
|
2601
|
+
expect(await page.evaluate(() => Reflect.get(window, 'guardedOnCreate'))).toBe(true);
|
|
2602
|
+
await expect(page.locator('#status')).toHaveText('${lsp ? 'saved 1 file(s)' : 'saved the diagram'}');
|
|
2603
|
+
expect(await askGuard()).toBe(false);
|
|
2604
|
+
|
|
2605
|
+
await page.reload();
|
|
2606
|
+
await expect(page.locator('#status')).toHaveText('ready');
|
|
2607
|
+
await page.locator('#file').selectOption('nodes.${diagram.extensions[0]}');
|
|
2608
|
+
await expect(nodes).toHaveCount(3);
|
|
2609
|
+
});
|
|
2610
|
+
`;
|
|
2611
|
+
const locators = [
|
|
2612
|
+
...(lsp ? [" const editor = page.locator('#editor .view-lines');"] : []),
|
|
2613
|
+
...(lsp ? [] : [" const nodes = page.locator('#diagram .sprotty-node');"])
|
|
2614
|
+
];
|
|
2615
|
+
return `// The page loads with every head answering, and an edit saved through the
|
|
2616
|
+
// ${lsp ? 'LSP head' : 'GLSP head'} is still there after a reload; any console error fails that
|
|
2617
|
+
// test. The other asks before a reload drops a diagram edit the server has not
|
|
2618
|
+
// answered yet, and keeps it when Save is clicked at once.
|
|
2619
|
+
|
|
2620
|
+
import { expect, test } from '@playwright/test';
|
|
2621
|
+
|
|
2622
|
+
test('loads every head and keeps a saved ${lsp ? 'edit' : 'diagram edit'} across a reload', async ({ page }) => {
|
|
2623
|
+
const errors: string[] = [];
|
|
2624
|
+
page.on('pageerror', error => errors.push(error.message));
|
|
2625
|
+
page.on('console', message => {
|
|
2626
|
+
if (message.type() === 'error') {
|
|
2627
|
+
errors.push(message.text());
|
|
2628
|
+
}
|
|
2629
|
+
});
|
|
2630
|
+
${locators.join('\n')}
|
|
2631
|
+
|
|
2632
|
+
await page.goto('/');
|
|
2633
|
+
await expect(page.locator('#status')).toHaveText('ready');
|
|
2634
|
+
${checks.join('\n')}
|
|
2635
|
+
|
|
2636
|
+
${edit}
|
|
2637
|
+
expect(errors).toEqual([]);
|
|
2638
|
+
});
|
|
2639
|
+
${guardTest}`;
|
|
2640
|
+
}
|
|
2641
|
+
/** The browser host's README. */
|
|
2642
|
+
function hostBrowserReadme(composition) {
|
|
2643
|
+
const lsp = composition.heads.includes('lsp');
|
|
2644
|
+
const data = composition.heads.includes('data');
|
|
2645
|
+
const diagram = composition.grammars.find(grammar => grammar.diagram);
|
|
2646
|
+
const lines = [
|
|
2647
|
+
`# ${memberPackageName(composition, 'host-browser')}`,
|
|
2648
|
+
'',
|
|
2649
|
+
'__NAME__ in a browser page: every head runs in a web worker, with no backend',
|
|
2650
|
+
`and no Node runtime. The page saves through the ${lsp ? 'LSP head' : 'GLSP head'}, and the worker`,
|
|
2651
|
+
'keeps each saved file in IndexedDB, laid over `../workspace` on the next',
|
|
2652
|
+
'load.',
|
|
2653
|
+
'',
|
|
2654
|
+
'```bash',
|
|
2655
|
+
'npm run build # type-check and bundle into out/',
|
|
2656
|
+
'npm start # serve the page at the URL it prints, rebundled on every source change',
|
|
2657
|
+
'npm run test:e2e:install # download the Chromium the smoke test drives, once',
|
|
2658
|
+
'npm run test:e2e # the smoke test, which serves the page itself',
|
|
2659
|
+
'```',
|
|
2660
|
+
'',
|
|
2661
|
+
'`PORT` moves the page to another port, for `npm start` and the smoke test alike;',
|
|
2662
|
+
'stop `npm start` before the smoke test, or give one of them another port.',
|
|
2663
|
+
'`npm start` reads `../workspace` once, so restart it after editing a file',
|
|
2664
|
+
'there.',
|
|
2665
|
+
'',
|
|
2666
|
+
'## Layout',
|
|
2667
|
+
'',
|
|
2668
|
+
'- `index.html` — the page, with a pane for each head that stays hidden until its part fills it',
|
|
2669
|
+
'- `hydranium-mark.svg` — the tab icon',
|
|
2670
|
+
`- \`esbuild.mjs\` — bundles the page${lsp ? ', the worker and Monaco’s worker' : ' and the worker'}, reading \`../workspace\` in as the seed`,
|
|
2671
|
+
'- `src/worker.ts` — the worker: the heads over one store, seeded and persisted',
|
|
2672
|
+
'- `src/page.ts` — starts the worker and runs the part of the page each head serves',
|
|
2673
|
+
'- `src/shown-file.ts` — the file switch above the panes, which every part follows',
|
|
2674
|
+
...(lsp ? ['- `src/editor.ts` — the LSP part: a Monaco editor and Save'] : []),
|
|
2675
|
+
...(data ? ['- `src/data-status.ts` — the data part: one document read through the data head'] : []),
|
|
2676
|
+
...(diagram === undefined
|
|
2677
|
+
? []
|
|
2678
|
+
: [
|
|
2679
|
+
`- \`src/diagram.ts\` — the GLSP part: the \`${diagram.grammar}\` diagram of the file the page shows, defined in the client package`
|
|
2680
|
+
]),
|
|
2681
|
+
...(lsp ? [] : ['- `src/diagram-save.ts` — Save with no editor: the diagram saved through the GLSP head']),
|
|
2682
|
+
'- `src/log.ts` — the status line and the log area',
|
|
2683
|
+
'- `src/workspace.ts` — the workspace root URI both ends name',
|
|
2684
|
+
...(lsp ? ['- `src/monaco-editor-worker.ts` — Monaco’s own worker, which hosts no head'] : []),
|
|
2685
|
+
'- `src/posix-path-shim.ts` — the `path` function the framework imports, for the bundle',
|
|
2686
|
+
'- `test/smoke.spec.mts` — the page loads, each head answers, and a saved edit survives a reload',
|
|
2687
|
+
''
|
|
2688
|
+
];
|
|
2689
|
+
return project(lines.join('\n'), composition);
|
|
2690
|
+
}
|
|
2691
|
+
/** The page with the line under its log view saying what shows there, which the LSP head decides. */
|
|
2692
|
+
function withLogHint(page, lsp) {
|
|
2693
|
+
const hint = lsp
|
|
2694
|
+
? 'What the server logs over the LSP head, and the errors the page reports.'
|
|
2695
|
+
: "The errors the page reports. The server logs to the worker's console, in the browser's developer tools.";
|
|
2696
|
+
return { ...page, content: page.content.replace('__LOG_HINT__', hint) };
|
|
2697
|
+
}
|
|
2698
|
+
/** The browser host: a page and a worker, bundled by esbuild and served as static files. */
|
|
2699
|
+
function hostBrowserFiles(composition) {
|
|
2700
|
+
const fixed = (file) => projectTemplate(`host-browser/${file}`, composition);
|
|
2701
|
+
const lsp = composition.heads.includes('lsp');
|
|
2702
|
+
const diagram = composition.grammars.find(grammar => grammar.diagram);
|
|
2703
|
+
return [
|
|
2704
|
+
{ path: 'host-browser/package.json', content: hostBrowserPackageJson(composition) },
|
|
2705
|
+
ignoreFile('host-browser'),
|
|
2706
|
+
{ path: 'host-browser/README.md', content: hostBrowserReadme(composition) },
|
|
2707
|
+
withLogHint(fixed('index.html'), lsp),
|
|
2708
|
+
fixed('hydranium-mark.svg'),
|
|
2709
|
+
fixed('esbuild.mjs'),
|
|
2710
|
+
fixed('playwright.config.mts'),
|
|
2711
|
+
fixed('tsconfig.worker.json'),
|
|
2712
|
+
fixed('tsconfig.page.json'),
|
|
2713
|
+
fixed('tsconfig.e2e.json'),
|
|
2714
|
+
{ path: 'host-browser/src/worker.ts', content: hostWorkerFile(composition) },
|
|
2715
|
+
{ path: 'host-browser/src/page.ts', content: hostPageFile(composition) },
|
|
2716
|
+
fixed('src/shown-file.ts'),
|
|
2717
|
+
...(lsp ? [fixed('src/editor.ts')] : []),
|
|
2718
|
+
...(composition.heads.includes('data') ? [fixed('src/data-status.ts')] : []),
|
|
2719
|
+
...(diagram === undefined ? [] : [grammarTemplate('host-browser/src/diagram.ts', composition, diagram)]),
|
|
2720
|
+
...(lsp ? [] : [fixed('src/diagram-save.ts')]),
|
|
2721
|
+
fixed('src/log.ts'),
|
|
2722
|
+
fixed('src/workspace.ts'),
|
|
2723
|
+
...(lsp ? [fixed('src/monaco-editor-worker.ts'), fixed('src/monaco-editor-core-worker.d.ts')] : []),
|
|
2724
|
+
fixed('src/posix-path-shim.ts'),
|
|
2725
|
+
{ path: 'host-browser/test/smoke.spec.mts', content: hostSmokeSpec(composition) }
|
|
2726
|
+
];
|
|
2727
|
+
}
|
|
2728
|
+
/** A JSON value as it sits at `indent` in a manifest npm writes. */
|
|
2729
|
+
function jsonAt(value, indent) {
|
|
2730
|
+
return JSON.stringify(value, null, 2).replace(/\n/g, `\n${indent}`);
|
|
2731
|
+
}
|
|
2732
|
+
/**
|
|
2733
|
+
* The languages and grammars a VS Code extension contributes. Each extension
|
|
2734
|
+
* declares its own, since either may be installed without the other; the
|
|
2735
|
+
* grammars are the server's, copied in by `copy:syntaxes`.
|
|
2736
|
+
*/
|
|
2737
|
+
function vscodeLanguageContributions(composition) {
|
|
2738
|
+
return {
|
|
2739
|
+
grammars: composition.grammars.map(grammar => ({
|
|
2740
|
+
language: grammar.languageId,
|
|
2741
|
+
scopeName: `source.${grammar.languageId}`,
|
|
2742
|
+
path: `./syntaxes/${grammar.languageId}.tmLanguage.json`
|
|
2743
|
+
})),
|
|
2744
|
+
languages: composition.grammars.map(grammar => ({
|
|
2745
|
+
id: grammar.languageId,
|
|
2746
|
+
aliases: [grammar.grammar],
|
|
2747
|
+
extensions: grammar.extensions.map(extension => `.${extension}`)
|
|
2748
|
+
}))
|
|
2749
|
+
};
|
|
2750
|
+
}
|
|
2751
|
+
/** VS Code finds the grammars only inside the extension, so the build copies the server's. */
|
|
2752
|
+
const COPY_SYNTAXES_SCRIPT = "require('node:fs').cpSync('../server/syntaxes', 'syntaxes', { recursive: true })";
|
|
2753
|
+
const COPY_SYNTAXES = `node -e \\"${COPY_SYNTAXES_SCRIPT}\\"`;
|
|
2754
|
+
/** `copy:syntaxes`, then again each time the server's `langium:watch` rewrites a grammar. */
|
|
2755
|
+
const WATCH_SYNTAXES = `node -e \\"const copy = () => ${COPY_SYNTAXES_SCRIPT}; copy(); require('node:fs').watch('../server/syntaxes', copy)\\"`;
|
|
2756
|
+
/**
|
|
2757
|
+
* The servers-only extension's `package.json`. Always private, like a host:
|
|
2758
|
+
* it is installed into an application, never as a dependency.
|
|
2759
|
+
*
|
|
2760
|
+
* `onStartupFinished` rather than `onLanguage`, since a Theia backend asks for
|
|
2761
|
+
* a port before any document is open.
|
|
2762
|
+
*/
|
|
2763
|
+
function vscodeServersPackageJson(composition) {
|
|
2764
|
+
const dependencies = {
|
|
2765
|
+
[memberPackageName(composition, 'protocol')]: MEMBER_PIN,
|
|
2766
|
+
[memberPackageName(composition, 'server')]: MEMBER_PIN,
|
|
2767
|
+
...VSCODE_LANGUAGE_CLIENT,
|
|
2768
|
+
'@hydranium/client-vscode': frameworkPin(composition)
|
|
2769
|
+
};
|
|
2770
|
+
return `{
|
|
2771
|
+
"name": "${memberPackageName(composition, 'vscode-servers')}",
|
|
2772
|
+
"displayName": "${composition.name} Servers",
|
|
2773
|
+
"version": "0.0.0",
|
|
2774
|
+
"private": true,
|
|
2775
|
+
"description": "Starts the ${composition.name} server${socketHeads(composition).length > 0 ? " and publishes its socket heads' ports as host commands" : ''}, with no editor of its own.",
|
|
2776
|
+
"license": "UNLICENSED",
|
|
2777
|
+
"author": "",
|
|
2778
|
+
"publisher": "${composition.projectId}",
|
|
2779
|
+
"main": "./out/extension.js",
|
|
2780
|
+
"scripts": {
|
|
2781
|
+
"build": "npm run copy:syntaxes && tsc",
|
|
2782
|
+
"clean": "rimraf out syntaxes tsconfig.tsbuildinfo",
|
|
2783
|
+
"copy:syntaxes": "${COPY_SYNTAXES}",
|
|
2784
|
+
${lintScript(forMember(composition, 'vscode-servers'), 'src')} "watch": "concurrently --kill-others --names syntaxes,tsc \\"npm run watch:syntaxes\\" \\"tsc --watch\\"",
|
|
2785
|
+
"watch:syntaxes": "${WATCH_SYNTAXES}"
|
|
2786
|
+
},
|
|
2787
|
+
"dependencies": {
|
|
2788
|
+
${sortedBlock(dependencies, ' ')}
|
|
2789
|
+
},
|
|
2790
|
+
"devDependencies": {
|
|
2791
|
+
${sortedBlock({ '@types/node': '^22.0.0', '@types/vscode': VSCODE_ENGINE, concurrently: '^9.0.0', rimraf: '^5.0.0', typescript: '^7.0.2' }, ' ')}
|
|
2792
|
+
},
|
|
2793
|
+
"contributes": ${jsonAt(vscodeLanguageContributions(composition), ' ')},
|
|
2794
|
+
"activationEvents": [
|
|
2795
|
+
"onStartupFinished"
|
|
2796
|
+
],
|
|
2797
|
+
"engines": {
|
|
2798
|
+
"vscode": "${VSCODE_ENGINE}"
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
`;
|
|
2802
|
+
}
|
|
2803
|
+
/**
|
|
2804
|
+
* The servers-only extension's activation: the shared launch, and with a socket
|
|
2805
|
+
* head the port commands, which only this extension registers.
|
|
2806
|
+
*/
|
|
2807
|
+
function vscodeServersExtensionFile(composition) {
|
|
2808
|
+
const upper = screamingSnake(composition.projectId);
|
|
2809
|
+
const heads = socketHeads(composition).map(head => head.key);
|
|
2810
|
+
const protocolSymbols = heads.flatMap(head => [`${upper}_${head}_HOST_COMMAND`, `${upper}_${head}_PORT_COMMAND`]);
|
|
2811
|
+
const imports = heads.length === 0
|
|
2812
|
+
? ''
|
|
2813
|
+
: `import { registerPortCommands } from '@hydranium/client-vscode/node';
|
|
2814
|
+
${importList(protocolSymbols, memberPackageName(composition, 'protocol'), columnsFor(composition))}
|
|
2815
|
+
`;
|
|
2816
|
+
const portCommands = heads.length === 0
|
|
2817
|
+
? ''
|
|
2818
|
+
: `
|
|
2819
|
+
|
|
2820
|
+
// Each socket head's port as a host command, for a host with no language
|
|
2821
|
+
// client of its own. Not in the shared launch: VS Code throws on a second
|
|
2822
|
+
// registration of one id, so the VS Code extension beside this one would fail
|
|
2823
|
+
// to activate. A pass-through: awaiting anything else in it would hang a
|
|
2824
|
+
// Theia backend on a user dismissing a notification.
|
|
2825
|
+
registerPortCommands(context, client, {
|
|
2826
|
+
${heads.map(head => ` [${upper}_${head}_HOST_COMMAND]: ${upper}_${head}_PORT_COMMAND`).join(',\n')}
|
|
2827
|
+
});`;
|
|
2828
|
+
return `// The servers-only extension: it starts the ${composition.name} server and contributes no
|
|
2829
|
+
// editor, view or command. A Theia app sideloads this one rather than the VS
|
|
2830
|
+
// Code extension, whose diagram editors would give its files a second editor.
|
|
2831
|
+
|
|
2832
|
+
${imports}import type { ExtensionContext } from 'vscode';
|
|
2833
|
+
import type { LanguageClient } from 'vscode-languageclient/node';
|
|
2834
|
+
import { start${composition.name}LanguageClient } from './language-client.js';
|
|
2835
|
+
|
|
2836
|
+
let client: LanguageClient | undefined;
|
|
2837
|
+
|
|
2838
|
+
export async function activate(context: ExtensionContext): Promise<void> {
|
|
2839
|
+
client = await start${composition.name}LanguageClient(context);${portCommands}
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2842
|
+
export async function deactivate(): Promise<void> {
|
|
2843
|
+
await client?.stop();
|
|
2844
|
+
client = undefined;
|
|
2845
|
+
}
|
|
2846
|
+
`;
|
|
2847
|
+
}
|
|
2848
|
+
/**
|
|
2849
|
+
* The server launch both extensions share: one launch, so VS Code and a Theia
|
|
2850
|
+
* app sideloading the servers extension hand the server the same documents.
|
|
2851
|
+
*/
|
|
2852
|
+
function vscodeLanguageClientFile(composition) {
|
|
2853
|
+
return `// Starts the ${composition.name} server for VS Code, and for a Theia app that sideloads
|
|
2854
|
+
// this extension: one launch, so both hand the server the same documents.
|
|
2855
|
+
|
|
2856
|
+
import { textDocumentContentMiddleware } from '@hydranium/client-vscode/node';
|
|
2857
|
+
import { ALL_LANGUAGES } from '${memberPackageName(composition, 'protocol')}';
|
|
2858
|
+
import { type ExtensionContext, workspace } from 'vscode';
|
|
2859
|
+
import { LanguageClient, TransportKind } from 'vscode-languageclient/node';
|
|
2860
|
+
|
|
2861
|
+
/** Fork the server, start its language client and return it once started. */
|
|
2862
|
+
export async function start${composition.name}LanguageClient(context: ExtensionContext): Promise<LanguageClient> {
|
|
2863
|
+
// Resolved through the package, so it works from the workspace and from an
|
|
2864
|
+
// installed extension alike. Over IPC, which keeps the server's stdout free.
|
|
2865
|
+
const serverModule = require.resolve('${memberPackageName(composition, 'server')}/lib/main.js');
|
|
2866
|
+
const extensions = ALL_LANGUAGES.flatMap(language => language.fileExtensions).join(',');
|
|
2867
|
+
const client: LanguageClient = new LanguageClient(
|
|
2868
|
+
'${composition.projectId}',
|
|
2869
|
+
'${composition.name}',
|
|
2870
|
+
{ module: serverModule, transport: TransportKind.ipc },
|
|
2871
|
+
{
|
|
2872
|
+
documentSelector: ALL_LANGUAGES.map(({ languageId }) => ({ scheme: 'file', language: languageId })),
|
|
2873
|
+
// Changes on disk the editor does not hold, such as a file another tool writes.
|
|
2874
|
+
synchronize: { fileEvents: workspace.createFileSystemWatcher(\`**/*{\${extensions}}\`) },
|
|
2875
|
+
// The text of a document only the server holds, such as a built-in library.
|
|
2876
|
+
middleware: textDocumentContentMiddleware(() => client)
|
|
2877
|
+
}
|
|
2878
|
+
);
|
|
2879
|
+
context.subscriptions.push(client);
|
|
2880
|
+
await client.start();
|
|
2881
|
+
|
|
2882
|
+
return client;
|
|
2883
|
+
}
|
|
2884
|
+
`;
|
|
2885
|
+
}
|
|
2886
|
+
/** The folders of the Theia applications the composition emits, as code spans. */
|
|
2887
|
+
function theiaApplicationPaths(composition) {
|
|
2888
|
+
return composition.hosts.filter(isTheiaHost).map(host => `\`../host-${host}\``);
|
|
2889
|
+
}
|
|
2890
|
+
/** The servers-only extension's README. */
|
|
2891
|
+
function vscodeServersReadme(composition) {
|
|
2892
|
+
const vscode = composition.hosts.includes('vscode');
|
|
2893
|
+
const theiaApps = theiaApplicationPaths(composition);
|
|
2894
|
+
const intro = [
|
|
2895
|
+
'A VS Code extension that starts the __NAME__ server and contributes no editor, view or command: the languages, their grammars and the server.',
|
|
2896
|
+
`With a socket head, it also answers each head’s port under a host command, which a host without a language client of its own runs${theiaApps.length > 0
|
|
2897
|
+
? theiaApps.length === 1
|
|
2898
|
+
? `: the Theia application in ${theiaApps[0]}, which sideloads this extension.`
|
|
2899
|
+
: `: the Theia applications in ${listPhrase(theiaApps)}, which sideload this extension.`
|
|
2900
|
+
: ', such as a Theia app sideloading this extension.'}`,
|
|
2901
|
+
...(vscode
|
|
2902
|
+
? [
|
|
2903
|
+
'The VS Code extension in `../host-vscode` starts the server through the same function.',
|
|
2904
|
+
'Both work side by side, but each starts its own server and language client, so diagnostics may show twice: install one.'
|
|
2905
|
+
]
|
|
2906
|
+
: [])
|
|
2907
|
+
];
|
|
2908
|
+
const lines = [
|
|
2909
|
+
`# ${memberPackageName(composition, 'vscode-servers')}`,
|
|
2910
|
+
'',
|
|
2911
|
+
...wrapProse(intro.join(' ')),
|
|
2912
|
+
'',
|
|
2913
|
+
'```bash',
|
|
2914
|
+
'npm run build # copy the server’s grammars and compile into out/; build the server first',
|
|
2915
|
+
'npm run watch # the same on every change',
|
|
2916
|
+
'```',
|
|
2917
|
+
'',
|
|
2918
|
+
'- `src/extension.ts` — activation, which starts the server and, with a socket head, registers its port commands',
|
|
2919
|
+
`- \`src/language-client.ts\` — the server launch${vscode ? ', shared with `../host-vscode`' : ''}`,
|
|
2920
|
+
''
|
|
2921
|
+
];
|
|
2922
|
+
return project(lines.join('\n'), composition);
|
|
2923
|
+
}
|
|
2924
|
+
/** The servers-only extension: the server's launch, without an editor. */
|
|
2925
|
+
function vscodeServersFiles(composition) {
|
|
2926
|
+
return [
|
|
2927
|
+
{ path: 'vscode-servers/package.json', content: vscodeServersPackageJson(composition) },
|
|
2928
|
+
ignoreFile('vscode-servers'),
|
|
2929
|
+
{ path: 'vscode-servers/README.md', content: vscodeServersReadme(composition) },
|
|
2930
|
+
projectTemplate('vscode-servers/tsconfig.json', composition),
|
|
2931
|
+
{ path: 'vscode-servers/src/extension.ts', content: vscodeServersExtensionFile(composition) },
|
|
2932
|
+
{ path: 'vscode-servers/src/language-client.ts', content: vscodeLanguageClientFile(composition) }
|
|
2933
|
+
];
|
|
2934
|
+
}
|
|
2935
|
+
/**
|
|
2936
|
+
* The custom-editor view type of a grammar's diagram, as the editor module
|
|
2937
|
+
* declares it. VS Code keys custom editors by view type alone, across every
|
|
2938
|
+
* installed extension, so it carries the language id, which `init` qualifies
|
|
2939
|
+
* by the project wherever the grammar is named apart from it.
|
|
2940
|
+
*/
|
|
2941
|
+
function diagramViewType(grammar) {
|
|
2942
|
+
return `${grammar.languageId}.diagram`;
|
|
2943
|
+
}
|
|
2944
|
+
/**
|
|
2945
|
+
* The VS Code extension's `package.json`. Always private, as every host is.
|
|
2946
|
+
*
|
|
2947
|
+
* A diagram file opens in its diagram by default; `Reopen Editor With` reaches
|
|
2948
|
+
* the text.
|
|
2949
|
+
*/
|
|
2950
|
+
function hostVscodePackageJson(composition) {
|
|
2951
|
+
const diagrams = composition.grammars.filter(grammar => grammar.diagram);
|
|
2952
|
+
const dependencies = {
|
|
2953
|
+
[memberPackageName(composition, 'vscode-servers')]: MEMBER_PIN,
|
|
2954
|
+
...VSCODE_LANGUAGE_CLIENT
|
|
2955
|
+
};
|
|
2956
|
+
if (diagrams.length > 0) {
|
|
2957
|
+
dependencies[memberPackageName(composition, 'client')] = MEMBER_PIN;
|
|
2958
|
+
dependencies[memberPackageName(composition, 'protocol')] = MEMBER_PIN;
|
|
2959
|
+
Object.assign(dependencies, HOST_VSCODE_GLSP_THIRD_PARTY_DEPENDENCIES);
|
|
2960
|
+
for (const framework of HOST_VSCODE_GLSP_FRAMEWORK_DEPENDENCIES) {
|
|
2961
|
+
dependencies[framework] = frameworkPin(composition);
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
if (composition.heads.includes('data')) {
|
|
2965
|
+
dependencies[memberPackageName(composition, 'protocol')] = MEMBER_PIN;
|
|
2966
|
+
Object.assign(dependencies, HOST_VSCODE_DATA_THIRD_PARTY_DEPENDENCIES);
|
|
2967
|
+
for (const framework of HOST_VSCODE_DATA_FRAMEWORK_DEPENDENCIES) {
|
|
2968
|
+
dependencies[framework] = frameworkPin(composition);
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
const devDependencies = { ...HOST_VSCODE_DEV_DEPENDENCIES, ...(diagrams.length > 0 ? { esbuild: '^0.28.0' } : {}) };
|
|
2972
|
+
const watches = {
|
|
2973
|
+
syntaxes: 'npm run watch:syntaxes',
|
|
2974
|
+
tsc: 'tsc --watch',
|
|
2975
|
+
...(diagrams.length > 0 ? { webview: 'node esbuild.mjs --watch' } : {})
|
|
2976
|
+
};
|
|
2977
|
+
const watchNames = Object.keys(watches).join(',');
|
|
2978
|
+
const watchCommands = Object.values(watches)
|
|
2979
|
+
.map(command => `\\"${command}\\"`)
|
|
2980
|
+
.join(' ');
|
|
2981
|
+
const contributes = {
|
|
2982
|
+
...(composition.heads.includes('data')
|
|
2983
|
+
? { commands: [{ command: `${composition.projectId}.showModel`, title: 'Show Model', category: composition.name }] }
|
|
2984
|
+
: {}),
|
|
2985
|
+
...(diagrams.length > 0
|
|
2986
|
+
? {
|
|
2987
|
+
customEditors: diagrams.map(grammar => ({
|
|
2988
|
+
viewType: diagramViewType(grammar),
|
|
2989
|
+
displayName: `${grammar.grammar} Diagram`,
|
|
2990
|
+
selector: grammar.extensions.map(extension => ({ filenamePattern: `*.${extension}` })),
|
|
2991
|
+
priority: 'default'
|
|
2992
|
+
}))
|
|
2993
|
+
}
|
|
2994
|
+
: {}),
|
|
2995
|
+
...vscodeLanguageContributions(composition)
|
|
2996
|
+
};
|
|
2997
|
+
const typecheck = [...(diagrams.length > 0 ? ['tsconfig.webview.json'] : []), 'tsconfig.e2e.json']
|
|
2998
|
+
.map(project => `tsc --noEmit -p ${project}`)
|
|
2999
|
+
.join(' && ');
|
|
3000
|
+
return `{
|
|
3001
|
+
"name": "${memberPackageName(composition, 'host-vscode')}",
|
|
3002
|
+
"displayName": "${composition.name}",
|
|
3003
|
+
"version": "0.0.0",
|
|
3004
|
+
"private": true,
|
|
3005
|
+
"description": "${composition.name} in VS Code: ${hostVscodeParts(composition)}.",
|
|
3006
|
+
"license": "UNLICENSED",
|
|
3007
|
+
"author": "",
|
|
3008
|
+
"publisher": "${composition.projectId}",
|
|
3009
|
+
"main": "./out/extension.js",
|
|
3010
|
+
"scripts": {
|
|
3011
|
+
"build": "npm run copy:syntaxes && npm run typecheck && tsc${diagrams.length > 0 ? ' && node esbuild.mjs' : ''}",
|
|
3012
|
+
"clean": "rimraf out syntaxes tsconfig.tsbuildinfo test-results playwright-report",
|
|
3013
|
+
"copy:syntaxes": "${COPY_SYNTAXES}",
|
|
3014
|
+
${lintScript(forMember(composition, 'host-vscode'), 'src test')} "start": "node start.mjs",
|
|
3015
|
+
"test:e2e": "playwright test --tsconfig tsconfig.e2e.json",
|
|
3016
|
+
"test:e2e:install": "node --experimental-strip-types test/install-vscode.mts",
|
|
3017
|
+
"typecheck": "${typecheck}",
|
|
3018
|
+
"watch": "concurrently --kill-others --names ${watchNames} ${watchCommands}",
|
|
3019
|
+
"watch:syntaxes": "${WATCH_SYNTAXES}"
|
|
3020
|
+
},
|
|
3021
|
+
"dependencies": {
|
|
3022
|
+
${sortedBlock(dependencies, ' ')}
|
|
3023
|
+
},
|
|
3024
|
+
"devDependencies": {
|
|
3025
|
+
${sortedBlock(devDependencies, ' ')}
|
|
3026
|
+
},
|
|
3027
|
+
"contributes": ${jsonAt(contributes, ' ')},
|
|
3028
|
+
"activationEvents": ${jsonAt(composition.grammars.map(grammar => `onLanguage:${grammar.languageId}`), ' ')},
|
|
3029
|
+
"engines": {
|
|
3030
|
+
"vscode": "${VSCODE_ENGINE}"
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
`;
|
|
3034
|
+
}
|
|
3035
|
+
/** What the VS Code extension brings, as one phrase; `started` follows the language client. */
|
|
3036
|
+
function hostVscodeParts(composition, started = '') {
|
|
3037
|
+
const parts = [
|
|
3038
|
+
`the language client${started}`,
|
|
3039
|
+
...(composition.heads.includes('data') ? ['a Show Model command reading a file through the data head'] : []),
|
|
3040
|
+
...(composition.grammars.some(grammar => grammar.diagram) ? ['a custom editor for each diagram'] : [])
|
|
3041
|
+
];
|
|
3042
|
+
return listPhrase(parts);
|
|
3043
|
+
}
|
|
3044
|
+
/** `parts` as one English list: `a`, `a and b`, `a, b, and c`. */
|
|
3045
|
+
function listPhrase(parts) {
|
|
3046
|
+
return parts.length === 1 ? parts[0] : `${parts.slice(0, -1).join(', ')}${parts.length > 2 ? ',' : ''} and ${parts.at(-1)}`;
|
|
3047
|
+
}
|
|
3048
|
+
/**
|
|
3049
|
+
* The VS Code extension's entry: the shared server launch, then the Show Model
|
|
3050
|
+
* command over the data head and a diagram editor per diagram grammar.
|
|
3051
|
+
*/
|
|
3052
|
+
function hostVscodeExtensionFile(composition) {
|
|
3053
|
+
const columns = columnsFor(composition);
|
|
3054
|
+
const diagrams = composition.grammars.filter(grammar => grammar.diagram);
|
|
3055
|
+
const data = composition.heads.includes('data');
|
|
3056
|
+
const start = `start${composition.name}LanguageClient`;
|
|
3057
|
+
const servers = `${memberPackageName(composition, 'vscode-servers')}/out/language-client.js`;
|
|
3058
|
+
const upper = screamingSnake(composition.projectId);
|
|
3059
|
+
const editors = diagrams.map(grammar => ({
|
|
3060
|
+
module: `./${grammar.grammarId}-diagram-editor.js`,
|
|
3061
|
+
viewType: `${screamingSnake(grammar.grammarId)}_DIAGRAM_VIEW_TYPE`,
|
|
3062
|
+
provider: `${grammar.grammar}DiagramEditorProvider`,
|
|
3063
|
+
local: `${grammar.grammar.charAt(0).toLowerCase()}${grammar.grammar.slice(1)}Editor`
|
|
3064
|
+
}));
|
|
3065
|
+
const registrations = editors.map(editor => ` const ${editor.local} = new ${editor.provider}(glspConnector, context.extensionUri);
|
|
3066
|
+
context.subscriptions.push(
|
|
3067
|
+
window.registerCustomEditorProvider(${editor.viewType}, ${editor.local}, {
|
|
3068
|
+
// A hidden tab keeps its diagram session rather than repeating the handshake.
|
|
3069
|
+
webviewOptions: { retainContextWhenHidden: true },
|
|
3070
|
+
// Two views of one document would be two GLSP clients racing on one model.
|
|
3071
|
+
supportsMultipleEditorsPerDocument: false
|
|
3072
|
+
})
|
|
3073
|
+
);`);
|
|
3074
|
+
const sockets = data || diagrams.length > 0;
|
|
3075
|
+
const protocolSymbols = [
|
|
3076
|
+
...(data ? [`${upper}_DATA_SERVER_PORT_COMMAND`] : []),
|
|
3077
|
+
...(diagrams.length > 0 ? [`${upper}_GLSP_SERVER_PORT_COMMAND`] : []),
|
|
3078
|
+
...(data ? [`type ${composition.name}Element`] : [])
|
|
3079
|
+
];
|
|
3080
|
+
const imports = [
|
|
3081
|
+
...(sockets ? ["import { findPort } from '@hydranium/client-vscode/node';"] : []),
|
|
3082
|
+
...(data ? ["import { SocketDataPort } from '@hydranium/data-client-vscode/node';"] : []),
|
|
3083
|
+
...(diagrams.length > 0
|
|
3084
|
+
? ["import { HydraniumGlspVscodeConnector, HydraniumGlspVscodeServer } from '@hydranium/glsp-client-vscode/node';"]
|
|
3085
|
+
: []),
|
|
3086
|
+
...(sockets
|
|
3087
|
+
? [
|
|
3088
|
+
importList([
|
|
3089
|
+
'ConsoleLogger',
|
|
3090
|
+
...(data ? ['DataConnectionWithEvents'] : []),
|
|
3091
|
+
...(diagrams.length > 0 ? ['describeError'] : []),
|
|
3092
|
+
...(data ? ['renderFrameworkMessage'] : [])
|
|
3093
|
+
], '@hydranium/protocol', columns)
|
|
3094
|
+
]
|
|
3095
|
+
: []),
|
|
3096
|
+
...(sockets ? [importList(protocolSymbols, memberPackageName(composition, 'protocol'), columns)] : []),
|
|
3097
|
+
...(sockets
|
|
3098
|
+
? [`import { ${[...(data ? ['commands'] : []), 'type ExtensionContext', 'window'].join(', ')} } from 'vscode';`]
|
|
3099
|
+
: ["import type { ExtensionContext } from 'vscode';"]),
|
|
3100
|
+
"import type { LanguageClient } from 'vscode-languageclient/node';",
|
|
3101
|
+
`import { ${start} } from '${servers}';`,
|
|
3102
|
+
...editors.map(editor => importList([editor.viewType, editor.provider], editor.module, columns)),
|
|
3103
|
+
...(data ? ["import { showModelCommand } from './show-model-command.js';"] : [])
|
|
3104
|
+
];
|
|
3105
|
+
const dataBlock = data
|
|
3106
|
+
? `
|
|
3107
|
+
|
|
3108
|
+
// The data head, read by the Show Model command. Nothing connects until it runs.
|
|
3109
|
+
const dataPort = new SocketDataPort({
|
|
3110
|
+
findPort: () => findPort(running, ${upper}_DATA_SERVER_PORT_COMMAND),
|
|
3111
|
+
logger: new ConsoleLogger().with('data head'),
|
|
3112
|
+
// A failed read shown to the user, not only logged; the message carries the detail.
|
|
3113
|
+
reportError: (_error, reported) => void window.showErrorMessage(renderFrameworkMessage(reported))
|
|
3114
|
+
});
|
|
3115
|
+
const dataConnection = new DataConnectionWithEvents<${composition.name}Element>(dataPort);
|
|
3116
|
+
context.subscriptions.push(dataConnection, dataPort, commands.registerCommand('${composition.projectId}.showModel', showModelCommand(dataConnection)));`
|
|
3117
|
+
: '';
|
|
3118
|
+
const glspBlock = diagrams.length > 0
|
|
3119
|
+
? `
|
|
3120
|
+
|
|
3121
|
+
// The GLSP head, and the connector bridging it to every diagram webview. No
|
|
3122
|
+
// \`messenger\` option: the connector's own keeps messages flowing to a hidden tab.
|
|
3123
|
+
const glspServer = new HydraniumGlspVscodeServer({
|
|
3124
|
+
clientId: '${composition.projectId}-glsp',
|
|
3125
|
+
clientName: '${composition.name}',
|
|
3126
|
+
findPort: () => findPort(running, ${upper}_GLSP_SERVER_PORT_COMMAND),
|
|
3127
|
+
logger: new ConsoleLogger().with('GLSP head')
|
|
3128
|
+
});
|
|
3129
|
+
const glspConnector = new HydraniumGlspVscodeConnector({ server: glspServer, logging: false });
|
|
3130
|
+
context.subscriptions.push(glspServer, glspConnector);
|
|
3131
|
+
// Not awaited, so a session that opens no diagram does not wait on the port.
|
|
3132
|
+
// \`start()\` resolves either way; a failure is reported off \`onReady\`.
|
|
3133
|
+
void glspServer.start();
|
|
3134
|
+
void glspServer.onReady.catch((error: unknown) => {
|
|
3135
|
+
void window.showErrorMessage(\`${composition.name} diagram unavailable: \${describeError(error)}\`);
|
|
3136
|
+
});
|
|
3137
|
+
${registrations.join('\n')}`
|
|
3138
|
+
: '';
|
|
3139
|
+
const opening = wrapComment(`The ${composition.name} VS Code extension: ${hostVscodeParts(composition, ', started the way the servers extension starts it')}.${sockets ? ' Node extension host only: the server is forked and its socket heads reached over TCP.' : ''}`);
|
|
3140
|
+
const activation = sockets
|
|
3141
|
+
? ` const running = await ${start}(context);
|
|
3142
|
+
client = running;${dataBlock}${glspBlock}`
|
|
3143
|
+
: ` client = await ${start}(context);`;
|
|
3144
|
+
return `${opening}
|
|
3145
|
+
|
|
3146
|
+
${imports.join('\n')}
|
|
3147
|
+
|
|
3148
|
+
let client: LanguageClient | undefined;
|
|
3149
|
+
|
|
3150
|
+
export async function activate(context: ExtensionContext): Promise<void> {
|
|
3151
|
+
${activation}
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
export async function deactivate(): Promise<void> {
|
|
3155
|
+
await client?.stop();
|
|
3156
|
+
client = undefined;
|
|
3157
|
+
}
|
|
3158
|
+
`;
|
|
3159
|
+
}
|
|
3160
|
+
/** A smoke test's title: what it checks of each head the composition has. */
|
|
3161
|
+
function hostVscodeSmokeTitle(composition) {
|
|
3162
|
+
return listPhrase([
|
|
3163
|
+
...(composition.heads.includes('data') ? ['reads the model'] : []),
|
|
3164
|
+
...(composition.grammars.some(grammar => grammar.diagram) ? ['draws the diagram'] : []),
|
|
3165
|
+
'reports a broken reference'
|
|
3166
|
+
]);
|
|
3167
|
+
}
|
|
3168
|
+
/**
|
|
3169
|
+
* The smoke test: VS Code opens the starter workspace with the extension
|
|
3170
|
+
* loaded, Show Model names the model with the data head, each diagram file
|
|
3171
|
+
* draws, and the server reports a broken reference.
|
|
3172
|
+
*/
|
|
3173
|
+
function hostVscodeSmokeSpec(composition) {
|
|
3174
|
+
const diagram = composition.grammars.find(grammar => grammar.diagram);
|
|
3175
|
+
const file = `nodes.${(diagram ?? composition.grammars[0]).extensions[0]}`;
|
|
3176
|
+
const diagramSteps = diagram
|
|
3177
|
+
? `
|
|
3178
|
+
// The diagram file opens in its diagram, which draws the two starter nodes.
|
|
3179
|
+
const webview = page.frameLocator('iframe.webview.ready').frameLocator('#active-frame');
|
|
3180
|
+
// In the editor's container: sprotty measures shapes in a hidden copy beside it.
|
|
3181
|
+
await expect(webview.locator('.hydranium-diagram-container .sprotty-node')).toHaveCount(2);
|
|
3182
|
+
// Then as text. The row is clicked, since Enter runs the best fuzzy match,
|
|
3183
|
+
// and its name ends in its keybinding, if it has one.
|
|
3184
|
+
await page.keyboard.press('ControlOrMeta+Shift+P');
|
|
3185
|
+
await page.locator('.quick-input-widget input').fill('>View: Reopen Editor with Text Editor');
|
|
3186
|
+
await page
|
|
3187
|
+
.locator('.quick-input-list')
|
|
3188
|
+
.getByRole('option', { name: /^View: Reopen Editor with Text Editor(,|$)/ })
|
|
3189
|
+
.click();
|
|
3190
|
+
`
|
|
3191
|
+
: '';
|
|
3192
|
+
const primary = diagram ?? composition.grammars[0];
|
|
3193
|
+
const showModelSteps = composition.heads.includes('data')
|
|
3194
|
+
? ` // The data head reads the open file.
|
|
3195
|
+
await page.keyboard.press('ControlOrMeta+Shift+P');
|
|
3196
|
+
await page.locator('.quick-input-widget input').fill('>${composition.name}: Show Model');
|
|
3197
|
+
await page
|
|
3198
|
+
.locator('.quick-input-list')
|
|
3199
|
+
.getByRole('option', { name: /^${composition.name}: Show Model(,|$)/ })
|
|
3200
|
+
.click();
|
|
3201
|
+
await expect(page.locator('.notification-toast').filter({ hasText: '${file} holds a ${primary.entryRule}' })).toBeVisible();
|
|
3202
|
+
`
|
|
3203
|
+
: '';
|
|
3204
|
+
const opening = wrapComment(`VS Code opens a copy of the starter workspace with this extension loaded, ${listPhrase([
|
|
3205
|
+
...(composition.heads.includes('data') ? ['the data head reads the file'] : []),
|
|
3206
|
+
...(diagram ? ['the diagram file draws in its diagram editor'] : []),
|
|
3207
|
+
'the server reports a reference that resolves to nothing'
|
|
3208
|
+
])}.`);
|
|
3209
|
+
return `${opening}
|
|
3210
|
+
|
|
3211
|
+
import { _electron, expect, test, type ElectronApplication, type Page } from '@playwright/test';
|
|
3212
|
+
import { downloadAndUnzipVSCode } from '@vscode/test-electron';
|
|
3213
|
+
import { cpSync, mkdtempSync, rmSync } from 'node:fs';
|
|
3214
|
+
import { tmpdir } from 'node:os';
|
|
3215
|
+
import { join } from 'node:path';
|
|
3216
|
+
import { fileURLToPath } from 'node:url';
|
|
3217
|
+
import { VSCODE_CACHE, VSCODE_VERSION } from './vscode-version.mts';
|
|
3218
|
+
|
|
3219
|
+
const extensionRoot = fileURLToPath(new URL('..', import.meta.url));
|
|
3220
|
+
|
|
3221
|
+
test('${hostVscodeSmokeTitle(composition)}', async () => {
|
|
3222
|
+
// A copy, since the server writes its repairs to the folder it opens, and a
|
|
3223
|
+
// fresh profile, since a reused one restores the last run's editors.
|
|
3224
|
+
const scratch = mkdtempSync(join(tmpdir(), '${composition.projectId}-vscode-'));
|
|
3225
|
+
const workspace = join(scratch, 'workspace');
|
|
3226
|
+
cpSync(fileURLToPath(new URL('../../workspace', import.meta.url)), workspace, { recursive: true });
|
|
3227
|
+
let app: ElectronApplication | undefined;
|
|
3228
|
+
try {
|
|
3229
|
+
app = await _electron.launch({
|
|
3230
|
+
executablePath: await downloadAndUnzipVSCode({ version: VSCODE_VERSION, cachePath: VSCODE_CACHE }),
|
|
3231
|
+
args: [
|
|
3232
|
+
'--no-sandbox',
|
|
3233
|
+
'--disable-gpu-sandbox',
|
|
3234
|
+
'--disable-updates',
|
|
3235
|
+
'--skip-welcome',
|
|
3236
|
+
'--skip-release-notes',
|
|
3237
|
+
'--disable-workspace-trust',
|
|
3238
|
+
'--disable-extensions',
|
|
3239
|
+
\`--extensionDevelopmentPath=\${extensionRoot}\`,
|
|
3240
|
+
\`--user-data-dir=\${join(scratch, 'user-data')}\`,
|
|
3241
|
+
\`--extensions-dir=\${join(scratch, 'extensions')}\`,
|
|
3242
|
+
workspace
|
|
3243
|
+
]
|
|
3244
|
+
});
|
|
3245
|
+
const page = await app.firstWindow();
|
|
3246
|
+
await expect(page.locator('.monaco-workbench')).toBeVisible();
|
|
3247
|
+
await quickOpen(page, '${file}');
|
|
3248
|
+
${showModelSteps}${diagramSteps}
|
|
3249
|
+
const editor = page.locator('.monaco-editor .view-lines').first();
|
|
3250
|
+
await expect(editor).toContainText('node First');
|
|
3251
|
+
await editor.click();
|
|
3252
|
+
await page.keyboard.press('ControlOrMeta+End');
|
|
3253
|
+
// In one edit: typed key by key, the half-typed reference is reported on the way.
|
|
3254
|
+
await page.keyboard.insertText('\\nnode Broken -> Missing');
|
|
3255
|
+
await expect(page.locator('.monaco-editor .squiggly-error').first()).toBeVisible();
|
|
3256
|
+
} finally {
|
|
3257
|
+
await app?.close();
|
|
3258
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
3259
|
+
}
|
|
3260
|
+
});
|
|
3261
|
+
|
|
3262
|
+
/** Open \`file\` through Quick Open, so it gets the editor a user would. */
|
|
3263
|
+
async function quickOpen(page: Page, file: string): Promise<void> {
|
|
3264
|
+
await page.keyboard.press('ControlOrMeta+P');
|
|
3265
|
+
const input = page.locator('.quick-input-widget input');
|
|
3266
|
+
await input.fill(file);
|
|
3267
|
+
await expect(page.locator('.quick-input-list .monaco-list-row').first()).toContainText(file);
|
|
3268
|
+
await input.press('Enter');
|
|
3269
|
+
await expect(page.locator('.quick-input-widget')).toBeHidden();
|
|
3270
|
+
}
|
|
3271
|
+
`;
|
|
3272
|
+
}
|
|
3273
|
+
/**
|
|
3274
|
+
* `text` broken at spaces into lines of at most 80 columns, the width
|
|
3275
|
+
* `check:docs` holds Markdown to. A link or code span stays whole, and runs
|
|
3276
|
+
* long on a line of its own.
|
|
3277
|
+
*/
|
|
3278
|
+
function wrapProse(text, width = 80) {
|
|
3279
|
+
const lines = [];
|
|
3280
|
+
for (const piece of text.match(/!?\[[^\]]*\]\([^)]*\)\S*|`+[^`]*`+\S*|\S+/g) ?? []) {
|
|
3281
|
+
const last = lines.at(-1);
|
|
3282
|
+
if (last !== undefined && last.length + 1 + piece.length <= width) {
|
|
3283
|
+
lines[lines.length - 1] = `${last} ${piece}`;
|
|
3284
|
+
}
|
|
3285
|
+
else {
|
|
3286
|
+
lines.push(piece);
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
return lines;
|
|
3290
|
+
}
|
|
3291
|
+
/** `text` as a `//` comment of lines at most 80 columns wide. */
|
|
3292
|
+
function wrapComment(text) {
|
|
3293
|
+
return wrapProse(text, 77)
|
|
3294
|
+
.map(line => `// ${line}`)
|
|
3295
|
+
.join('\n');
|
|
3296
|
+
}
|
|
3297
|
+
/** The VS Code extension's README. */
|
|
3298
|
+
function hostVscodeReadme(composition) {
|
|
3299
|
+
const diagrams = composition.grammars.filter(grammar => grammar.diagram);
|
|
3300
|
+
const data = composition.heads.includes('data');
|
|
3301
|
+
const intro = [
|
|
3302
|
+
diagrams.length > 0
|
|
3303
|
+
? `${composition.name} in VS Code: the language client, and a custom editor drawing each diagram file.`
|
|
3304
|
+
: `${composition.name} in VS Code: the language client.`,
|
|
3305
|
+
'The server is started by `../vscode-servers`, whose launch this extension calls, so the two never hand the server different documents.',
|
|
3306
|
+
socketHeads(composition).length > 0
|
|
3307
|
+
? 'It needs a Node extension host: the server is forked, and its socket heads are reached over TCP.'
|
|
3308
|
+
: 'It needs a Node extension host, since the server is forked.'
|
|
3309
|
+
];
|
|
3310
|
+
const dataNote = `\`${composition.name}: Show Model\`, in the Command Palette, reads the active file through the data head over a socket from the extension host, and names its root type. A webview reaches the data head too: see the Host in VS Code guide.`;
|
|
3311
|
+
const lines = [
|
|
3312
|
+
`# ${memberPackageName(composition, 'host-vscode')}`,
|
|
3313
|
+
'',
|
|
3314
|
+
...wrapProse(intro.join(' ')),
|
|
3315
|
+
...(data ? ['', ...wrapProse(dataNote)] : []),
|
|
3316
|
+
'',
|
|
3317
|
+
'```bash',
|
|
3318
|
+
`npm run build # copy the server’s grammars, type-check and compile${diagrams.length > 0 ? ', then bundle' : ''}`,
|
|
3319
|
+
`npm run watch # copy the grammars and recompile${diagrams.length > 0 ? ' and rebundle' : ''} on every change; Developer: Reload Window picks it up`,
|
|
3320
|
+
'npm start # VS Code with this extension, on ../workspace; needs `code` on the PATH',
|
|
3321
|
+
'npm run test:e2e:install # download the VS Code the smoke test drives, once',
|
|
3322
|
+
'npm run test:e2e # the smoke test; under `xvfb-run -a` on Linux without a display',
|
|
3323
|
+
'```',
|
|
3324
|
+
'',
|
|
3325
|
+
'## Layout',
|
|
3326
|
+
'',
|
|
3327
|
+
`- \`src/extension.ts\` — activation: ${listPhrase([
|
|
3328
|
+
'the server, through `../vscode-servers`',
|
|
3329
|
+
...(data ? ['the Show Model command'] : []),
|
|
3330
|
+
...(diagrams.length > 0 ? ['the diagram editors'] : [])
|
|
3331
|
+
])}`,
|
|
3332
|
+
...(data ? ['- `src/show-model-command.ts` — Show Model: the active file, read through the data head'] : []),
|
|
3333
|
+
...diagrams.flatMap(grammar => [
|
|
3334
|
+
`- \`src/${grammar.grammarId}-diagram-editor.ts\` — the \`${grammar.grammar}\` diagram’s custom editor; its view type is the one \`package.json\` declares`,
|
|
3335
|
+
`- \`src/webview/${grammar.grammarId}-diagram.ts\` — the webview it loads, over the client package’s diagram`
|
|
3336
|
+
]),
|
|
3337
|
+
...(diagrams.length > 0
|
|
3338
|
+
? ['- `src/webview/diagram.css` — the webview’s size and colours', '- `esbuild.mjs` — bundles each webview into `out/webview/`']
|
|
3339
|
+
: []),
|
|
3340
|
+
'- `start.mjs` — `npm start`: VS Code with this extension, on `../workspace`',
|
|
3341
|
+
'- `test/smoke.spec.mts` — VS Code opens the workspace, ' +
|
|
3342
|
+
(composition.heads.includes('data') ? 'Show Model names the model, ' : '') +
|
|
3343
|
+
(diagrams.length > 0 ? 'the diagram draws, ' : '') +
|
|
3344
|
+
'and the server reports a broken reference',
|
|
3345
|
+
'- `test/vscode-version.mts` — the VS Code release the smoke test runs',
|
|
3346
|
+
''
|
|
3347
|
+
];
|
|
3348
|
+
return project(lines.join('\n'), composition);
|
|
3349
|
+
}
|
|
3350
|
+
/** The VS Code extension: the language client and a diagram editor per diagram grammar. */
|
|
3351
|
+
function hostVscodeFiles(composition) {
|
|
3352
|
+
const fixed = (file) => projectTemplate(`host-vscode/${file}`, composition);
|
|
3353
|
+
const diagrams = composition.grammars.filter(grammar => grammar.diagram);
|
|
3354
|
+
return [
|
|
3355
|
+
{ path: 'host-vscode/package.json', content: hostVscodePackageJson(composition) },
|
|
3356
|
+
ignoreFile('host-vscode'),
|
|
3357
|
+
{ path: 'host-vscode/README.md', content: hostVscodeReadme(composition) },
|
|
3358
|
+
fixed('tsconfig.json'),
|
|
3359
|
+
fixed('tsconfig.e2e.json'),
|
|
3360
|
+
fixed('playwright.config.mts'),
|
|
3361
|
+
fixed('start.mjs'),
|
|
3362
|
+
{ path: 'host-vscode/src/extension.ts', content: hostVscodeExtensionFile(composition) },
|
|
3363
|
+
...(composition.heads.includes('data') ? [fixed('src/show-model-command.ts')] : []),
|
|
3364
|
+
...(diagrams.length > 0 ? [fixed('tsconfig.webview.json'), fixed('esbuild.mjs'), fixed('src/webview/diagram.css')] : []),
|
|
3365
|
+
...diagrams.flatMap(grammar => [
|
|
3366
|
+
grammarTemplate('host-vscode/src/__GRAMMAR_ID__-diagram-editor.ts', composition, grammar),
|
|
3367
|
+
grammarTemplate('host-vscode/src/webview/__GRAMMAR_ID__-diagram.ts', composition, grammar)
|
|
3368
|
+
]),
|
|
3369
|
+
{ path: 'host-vscode/test/smoke.spec.mts', content: hostVscodeSmokeSpec(composition) },
|
|
3370
|
+
fixed('test/vscode-version.mts'),
|
|
3371
|
+
fixed('test/install-vscode.mts')
|
|
3372
|
+
];
|
|
3373
|
+
}
|
|
3374
|
+
/**
|
|
3375
|
+
* The Theia release of every Theia member, the one the framework's own
|
|
3376
|
+
* Theia examples take, so a scaffold builds against what the repo tests: the
|
|
3377
|
+
* Theia community release. Exact, as Theia's members pin each other, so a
|
|
3378
|
+
* workspace root declares it too and GLSP's open Theia peer resolves to it.
|
|
3379
|
+
*/
|
|
3380
|
+
const THEIA_VERSION = '1.74.3';
|
|
3381
|
+
/**
|
|
3382
|
+
* What each head adds to the Theia extension; `base` is the connection hardening
|
|
3383
|
+
* and editor sync every one gets. With the third-party entries below, they name
|
|
3384
|
+
* the peers of the framework's Theia packages, so an installer that adds no peers
|
|
3385
|
+
* still finds them.
|
|
3386
|
+
*/
|
|
3387
|
+
const THEIA_FRAMEWORK_DEPENDENCIES = {
|
|
3388
|
+
base: ['@hydranium/client-theia', '@hydranium/protocol'],
|
|
3389
|
+
lsp: [],
|
|
3390
|
+
data: ['@hydranium/data-client-theia'],
|
|
3391
|
+
glsp: ['@hydranium/glsp-client', '@hydranium/glsp-client-theia']
|
|
3392
|
+
};
|
|
3393
|
+
const THEIA_THIRD_PARTY_DEPENDENCIES = {
|
|
3394
|
+
base: {
|
|
3395
|
+
'@theia/core': THEIA_VERSION,
|
|
3396
|
+
'@theia/editor': THEIA_VERSION,
|
|
3397
|
+
'@theia/filesystem': THEIA_VERSION,
|
|
3398
|
+
'@theia/output': THEIA_VERSION,
|
|
3399
|
+
inversify: '^6.1.3',
|
|
3400
|
+
'vscode-jsonrpc': '9.0.3'
|
|
3401
|
+
},
|
|
3402
|
+
lsp: {},
|
|
3403
|
+
data: { '@theia/workspace': THEIA_VERSION },
|
|
3404
|
+
glsp: {
|
|
3405
|
+
'@eclipse-glsp/client': '2.8.0',
|
|
3406
|
+
'@eclipse-glsp/theia-integration': '2.8.0',
|
|
3407
|
+
'@theia/process': THEIA_VERSION,
|
|
3408
|
+
'@theia/workspace': THEIA_VERSION
|
|
3409
|
+
}
|
|
3410
|
+
};
|
|
3411
|
+
/** The Theia extension's third-party pins for `heads`, for its manifest and a workspace root's. */
|
|
3412
|
+
function theiaThirdPartyDependencies(heads) {
|
|
3413
|
+
return ['base', ...heads].flatMap(head => Object.entries(THEIA_THIRD_PARTY_DEPENDENCIES[head]));
|
|
3414
|
+
}
|
|
3415
|
+
/**
|
|
3416
|
+
* The Theia packages the application assembles: the workbench a user expects,
|
|
3417
|
+
* and `plugin-ext` with its VS Code API to sideload the servers extension.
|
|
3418
|
+
*/
|
|
3419
|
+
const HOST_THEIA_BROWSER_DEPENDENCIES = [
|
|
3420
|
+
'@theia/core',
|
|
3421
|
+
'@theia/editor',
|
|
3422
|
+
'@theia/filesystem',
|
|
3423
|
+
'@theia/markers',
|
|
3424
|
+
'@theia/messages',
|
|
3425
|
+
'@theia/monaco',
|
|
3426
|
+
'@theia/navigator',
|
|
3427
|
+
'@theia/output',
|
|
3428
|
+
'@theia/plugin-ext',
|
|
3429
|
+
'@theia/plugin-ext-vscode',
|
|
3430
|
+
'@theia/preferences',
|
|
3431
|
+
'@theia/process',
|
|
3432
|
+
'@theia/workspace'
|
|
3433
|
+
];
|
|
3434
|
+
/** The Theia tooling the application builds with. */
|
|
3435
|
+
const HOST_THEIA_BROWSER_DEV_DEPENDENCIES = ['@theia/cli'];
|
|
3436
|
+
/** Every Theia package the application declares, for a workspace root's pins. */
|
|
3437
|
+
function hostTheiaBrowserTheiaDependencies() {
|
|
3438
|
+
return [...HOST_THEIA_BROWSER_DEPENDENCIES, ...HOST_THEIA_BROWSER_DEV_DEPENDENCIES].map(name => [name, THEIA_VERSION]);
|
|
3439
|
+
}
|
|
3440
|
+
/** The Electron application's Theia packages: the browser application's, and Theia's Electron integration. */
|
|
3441
|
+
const HOST_THEIA_ELECTRON_DEPENDENCIES = [...HOST_THEIA_BROWSER_DEPENDENCIES, '@theia/electron'].sort();
|
|
3442
|
+
/** The Electron release `@theia/electron` peers on, exactly. */
|
|
3443
|
+
const ELECTRON_VERSION = '42.11.16';
|
|
3444
|
+
/** Every package the Electron application pins, for a workspace root's pins. */
|
|
3445
|
+
function hostTheiaElectronPins() {
|
|
3446
|
+
return [
|
|
3447
|
+
...[...HOST_THEIA_ELECTRON_DEPENDENCIES, ...HOST_THEIA_BROWSER_DEV_DEPENDENCIES].map((name) => [
|
|
3448
|
+
name,
|
|
3449
|
+
THEIA_VERSION
|
|
3450
|
+
]),
|
|
3451
|
+
['electron', ELECTRON_VERSION]
|
|
3452
|
+
];
|
|
3453
|
+
}
|
|
3454
|
+
/** The Theia extension's `theiaExtensions` entries: one per head it forwards, and one per diagram. */
|
|
3455
|
+
function theiaExtensionEntries(composition) {
|
|
3456
|
+
const id = composition.projectId;
|
|
3457
|
+
return [
|
|
3458
|
+
{
|
|
3459
|
+
frontendPreload: `lib/browser/${id}-connection-preload-module`,
|
|
3460
|
+
frontend: `lib/browser/${id}-frontend-module`,
|
|
3461
|
+
backend: `lib/node/${id}-connection-backend-module`
|
|
3462
|
+
},
|
|
3463
|
+
...(composition.heads.includes('data') ? [{ backend: `lib/node/${id}-data-backend-module` }] : []),
|
|
3464
|
+
...(composition.heads.includes('glsp') ? [{ backend: `lib/node/${id}-glsp-backend-module` }] : []),
|
|
3465
|
+
...composition.grammars
|
|
3466
|
+
.filter(grammar => grammar.diagram)
|
|
3467
|
+
.map(grammar => ({ frontend: `lib/browser/${grammar.grammarId}-diagram-frontend-module` }))
|
|
3468
|
+
];
|
|
3469
|
+
}
|
|
3470
|
+
/** The Theia extension's `package.json`. Private unless `--public`, as the client member is. */
|
|
3471
|
+
function theiaPackageJson(composition) {
|
|
3472
|
+
const dependencies = {
|
|
3473
|
+
// The socket heads' host commands, and the data head's model type.
|
|
3474
|
+
...(socketHeads(composition).length > 0 ? { [memberPackageName(composition, 'protocol')]: MEMBER_PIN } : {}),
|
|
3475
|
+
...(composition.heads.includes('glsp') ? { [memberPackageName(composition, 'client')]: MEMBER_PIN } : {}),
|
|
3476
|
+
...Object.fromEntries(theiaThirdPartyDependencies(composition.heads))
|
|
3477
|
+
};
|
|
3478
|
+
for (const head of ['base', ...composition.heads]) {
|
|
3479
|
+
for (const framework of THEIA_FRAMEWORK_DEPENDENCIES[head]) {
|
|
3480
|
+
dependencies[framework] = frameworkPin(composition);
|
|
3481
|
+
}
|
|
3482
|
+
}
|
|
3483
|
+
return `{
|
|
3484
|
+
"name": "${memberPackageName(composition, 'theia')}",
|
|
3485
|
+
"version": "0.0.0",
|
|
3486
|
+
${composition.packaging.private ? ' "private": true,\n' : ''} "description": "The ${composition.name} Theia extension: ${theiaParts(composition)}.",
|
|
3487
|
+
"license": "UNLICENSED",
|
|
3488
|
+
"author": "",
|
|
3489
|
+
"files": [
|
|
3490
|
+
"lib",
|
|
3491
|
+
"src",
|
|
3492
|
+
"style"
|
|
3493
|
+
],
|
|
3494
|
+
"scripts": {
|
|
3495
|
+
"build": "tsc",
|
|
3496
|
+
"clean": "rimraf lib tsconfig.tsbuildinfo",
|
|
3497
|
+
${lintScript(forMember(composition, 'theia'), 'src')} "watch": "tsc --watch"
|
|
3498
|
+
},
|
|
3499
|
+
"dependencies": {
|
|
3500
|
+
${sortedBlock(dependencies, ' ')}
|
|
3501
|
+
},
|
|
3502
|
+
"devDependencies": {
|
|
3503
|
+
${sortedBlock({ '@types/node': '^22.0.0', rimraf: '^5.0.0', typescript: '^7.0.2' }, ' ')}
|
|
3504
|
+
},
|
|
3505
|
+
"engines": {
|
|
3506
|
+
"node": ">=22.13"
|
|
3507
|
+
},
|
|
3508
|
+
"theiaExtensions": ${jsonAt(theiaExtensionEntries(composition), ' ')}
|
|
3509
|
+
}
|
|
3510
|
+
`;
|
|
3511
|
+
}
|
|
3512
|
+
/** What the Theia extension brings, as one phrase. */
|
|
3513
|
+
function theiaParts(composition) {
|
|
3514
|
+
return listPhrase([
|
|
3515
|
+
'reconnect hardening',
|
|
3516
|
+
...(composition.heads.includes('data') ? ['a Show Model command reading a file through the data head'] : []),
|
|
3517
|
+
...(composition.grammars.some(grammar => grammar.diagram) ? ['a diagram editor for each diagram'] : [])
|
|
3518
|
+
]);
|
|
3519
|
+
}
|
|
3520
|
+
/** The extension's one frontend module: the logger, the connection diagnostics and editor sync, and each head's client. */
|
|
3521
|
+
function theiaFrontendModuleFile(composition) {
|
|
3522
|
+
const id = composition.projectId;
|
|
3523
|
+
const name = composition.name;
|
|
3524
|
+
const data = composition.heads.includes('data');
|
|
3525
|
+
const glsp = composition.heads.includes('glsp');
|
|
3526
|
+
const imports = [
|
|
3527
|
+
...(glsp ? ["import { GLSPClientContribution } from '@eclipse-glsp/theia-integration';"] : []),
|
|
3528
|
+
"import { bindChannelLogger, bindConnectionDiagnostics, bindEditorDiskSync } from '@hydranium/client-theia/browser';",
|
|
3529
|
+
...(data
|
|
3530
|
+
? [
|
|
3531
|
+
"import { bindDataConnection } from '@hydranium/data-client-theia/browser';",
|
|
3532
|
+
"import { CommandContribution } from '@theia/core';"
|
|
3533
|
+
]
|
|
3534
|
+
: []),
|
|
3535
|
+
"import { ContainerModule } from '@theia/core/shared/inversify';",
|
|
3536
|
+
...(data
|
|
3537
|
+
? [
|
|
3538
|
+
`import { ${name}DataConnection } from './${id}-data-connection.js';`,
|
|
3539
|
+
`import { ${name}DataPort } from './${id}-data-port.js';`
|
|
3540
|
+
]
|
|
3541
|
+
: []),
|
|
3542
|
+
...(glsp ? [`import { ${name}GlspClientContribution } from './${id}-glsp-client-contribution.js';`] : []),
|
|
3543
|
+
...(data ? [`import { ${name}ShowModelCommand } from './${id}-show-model-command.js';`] : [])
|
|
3544
|
+
];
|
|
3545
|
+
const dataBlock = data
|
|
3546
|
+
? `
|
|
3547
|
+
|
|
3548
|
+
// The data head: one connection, opened when the command first runs.
|
|
3549
|
+
bind(${name}DataPort).toSelf().inSingletonScope();
|
|
3550
|
+
bindDataConnection(bind, isBound, ${name}DataConnection);
|
|
3551
|
+
bind(${name}ShowModelCommand).toSelf().inSingletonScope();
|
|
3552
|
+
bind(CommandContribution).toService(${name}ShowModelCommand);`
|
|
3553
|
+
: '';
|
|
3554
|
+
const glspBlock = glsp
|
|
3555
|
+
? `
|
|
3556
|
+
|
|
3557
|
+
// One GLSP client for every diagram, so each diagram module skips binding its own.
|
|
3558
|
+
bind(${name}GlspClientContribution).toSelf().inSingletonScope();
|
|
3559
|
+
bind(GLSPClientContribution).toService(${name}GlspClientContribution);`
|
|
3560
|
+
: '';
|
|
3561
|
+
return `${wrapComment(`The ${name} Theia extension's frontend: ${listPhrase([
|
|
3562
|
+
'the connection’s lifecycle in an Output channel',
|
|
3563
|
+
'a warning when an outage outlasts the offline buffer',
|
|
3564
|
+
'editor disk sync',
|
|
3565
|
+
...(data ? ['the data head’s connection and the Show Model command'] : []),
|
|
3566
|
+
...(glsp ? ['the GLSP client the diagrams share'] : [])
|
|
3567
|
+
])}.`)}
|
|
3568
|
+
|
|
3569
|
+
${imports.join('\n')}
|
|
3570
|
+
|
|
3571
|
+
export default new ContainerModule((bind, _unbind, isBound, rebind) => {
|
|
3572
|
+
bindChannelLogger(bind, { channelName: '${name} Connection' });
|
|
3573
|
+
bindConnectionDiagnostics(bind);
|
|
3574
|
+
// Keeps an editor from writing over a file a head saved while it held the same text unsaved.
|
|
3575
|
+
bindEditorDiskSync(bind, isBound, rebind);${dataBlock}${glspBlock}
|
|
3576
|
+
});
|
|
3577
|
+
`;
|
|
3578
|
+
}
|
|
3579
|
+
/** The Theia extension's README. */
|
|
3580
|
+
function theiaReadme(composition) {
|
|
3581
|
+
const id = composition.projectId;
|
|
3582
|
+
const data = composition.heads.includes('data');
|
|
3583
|
+
const glsp = composition.heads.includes('glsp');
|
|
3584
|
+
const diagrams = composition.grammars.filter(grammar => grammar.diagram);
|
|
3585
|
+
const theiaApps = theiaApplicationPaths(composition);
|
|
3586
|
+
const intro = [
|
|
3587
|
+
`The ${composition.name} Theia extension: ${theiaParts(composition)}.`,
|
|
3588
|
+
socketHeads(composition).length > 0
|
|
3589
|
+
? 'The language client is not here: the application sideloads `../vscode-servers`, which starts the server and answers each socket head’s port under a host command, and the backend modules forward the page’s channels to those ports.'
|
|
3590
|
+
: 'The language client is not here: the application sideloads `../vscode-servers`, which starts the server.',
|
|
3591
|
+
theiaApps.length === 1 ? `The application in ${theiaApps[0]} runs it.` : `The applications in ${listPhrase(theiaApps)} run it.`
|
|
3592
|
+
];
|
|
3593
|
+
const before = [...(socketHeads(composition).length > 0 ? ['protocol'] : []), ...(glsp ? ['client'] : [])];
|
|
3594
|
+
const lines = [
|
|
3595
|
+
`# ${memberPackageName(composition, 'theia')}`,
|
|
3596
|
+
'',
|
|
3597
|
+
...wrapProse(intro.join(' ')),
|
|
3598
|
+
'',
|
|
3599
|
+
'```bash',
|
|
3600
|
+
'npm run build # compile into lib/' +
|
|
3601
|
+
(before.length > 0 ? `; build the ${before.join(' and ')} package${before.length > 1 ? 's' : ''} first` : ''),
|
|
3602
|
+
'```',
|
|
3603
|
+
'',
|
|
3604
|
+
'## Layout',
|
|
3605
|
+
'',
|
|
3606
|
+
`- \`src/browser/${id}-connection-preload-module.ts\` and \`src/node/${id}-connection-backend-module.ts\` — reconnect hardening, sized by the application’s \`connectionBufferBytes\``,
|
|
3607
|
+
`- \`src/browser/${id}-frontend-module.ts\` — the frontend bindings`,
|
|
3608
|
+
...(data
|
|
3609
|
+
? [
|
|
3610
|
+
`- \`src/browser/${id}-data-port.ts\` and \`${id}-data-connection.ts\` — the data head’s connection`,
|
|
3611
|
+
`- \`src/browser/${id}-show-model-command.ts\` — \`${composition.name}: Show Model\`, reading the current file through the data head`,
|
|
3612
|
+
`- \`src/node/${id}-data-backend-module.ts\` — forwards the data channel to the data head’s port`
|
|
3613
|
+
]
|
|
3614
|
+
: []),
|
|
3615
|
+
...(glsp
|
|
3616
|
+
? [
|
|
3617
|
+
`- \`src/common/${id}-glsp-contribution.ts\` — the id the GLSP client and its forwarder share`,
|
|
3618
|
+
`- \`src/browser/${id}-glsp-client-contribution.ts\` — the GLSP client every diagram shares`,
|
|
3619
|
+
`- \`src/node/${id}-glsp-backend-module.ts\` — forwards the GLSP channel to the GLSP head’s port`
|
|
3620
|
+
]
|
|
3621
|
+
: []),
|
|
3622
|
+
...diagrams.map(grammar => `- \`src/browser/${grammar.grammarId}-diagram-frontend-module.ts\` — the \`${grammar.grammar}\` diagram editor, over the client package’s diagram`),
|
|
3623
|
+
...(diagrams.length > 0 ? ['- `style/diagram.css` — the diagrams’ colours, from the Theia theme'] : []),
|
|
3624
|
+
''
|
|
3625
|
+
];
|
|
3626
|
+
return project(lines.join('\n'), composition);
|
|
3627
|
+
}
|
|
3628
|
+
/** The Theia extension: what a Theia application runs of the language, beside the sideloaded servers extension. */
|
|
3629
|
+
function theiaFiles(composition) {
|
|
3630
|
+
const fixed = (file) => ({
|
|
3631
|
+
path: project(`theia/${file}`, composition),
|
|
3632
|
+
content: project(template(`theia/${file}`), composition)
|
|
3633
|
+
});
|
|
3634
|
+
const id = composition.projectId;
|
|
3635
|
+
const data = composition.heads.includes('data');
|
|
3636
|
+
const glsp = composition.heads.includes('glsp');
|
|
3637
|
+
const diagrams = composition.grammars.filter(grammar => grammar.diagram);
|
|
3638
|
+
return [
|
|
3639
|
+
{ path: 'theia/package.json', content: theiaPackageJson(composition) },
|
|
3640
|
+
ignoreFile('theia'),
|
|
3641
|
+
{ path: 'theia/README.md', content: theiaReadme(composition) },
|
|
3642
|
+
fixed('tsconfig.json'),
|
|
3643
|
+
fixed('src/browser/__PROJECT_ID__-connection-preload-module.ts'),
|
|
3644
|
+
{ path: `theia/src/browser/${id}-frontend-module.ts`, content: theiaFrontendModuleFile(composition) },
|
|
3645
|
+
fixed('src/node/__PROJECT_ID__-connection-backend-module.ts'),
|
|
3646
|
+
...(data
|
|
3647
|
+
? [
|
|
3648
|
+
fixed('src/browser/__PROJECT_ID__-data-port.ts'),
|
|
3649
|
+
fixed('src/browser/__PROJECT_ID__-data-connection.ts'),
|
|
3650
|
+
fixed('src/browser/__PROJECT_ID__-show-model-command.ts'),
|
|
3651
|
+
fixed('src/node/__PROJECT_ID__-data-backend-module.ts')
|
|
3652
|
+
]
|
|
3653
|
+
: []),
|
|
3654
|
+
...(glsp
|
|
3655
|
+
? [
|
|
3656
|
+
fixed('src/common/__PROJECT_ID__-glsp-contribution.ts'),
|
|
3657
|
+
fixed('src/browser/__PROJECT_ID__-glsp-client-contribution.ts'),
|
|
3658
|
+
fixed('src/node/__PROJECT_ID__-glsp-backend-module.ts')
|
|
3659
|
+
]
|
|
3660
|
+
: []),
|
|
3661
|
+
...diagrams.map(grammar => grammarTemplate('theia/src/browser/__GRAMMAR_ID__-diagram-frontend-module.ts', composition, grammar)),
|
|
3662
|
+
...(diagrams.length > 0 ? [fixed('style/diagram.css')] : [])
|
|
3663
|
+
];
|
|
3664
|
+
}
|
|
3665
|
+
/**
|
|
3666
|
+
* The Theia application's `package.json`. Always private, as every host is.
|
|
3667
|
+
*
|
|
3668
|
+
* Theia's default `frontendConnectionTimeout` of 0 ends the session on any
|
|
3669
|
+
* dropped socket, and the page reloads; a minute lets the reconnect hardening
|
|
3670
|
+
* resume it.
|
|
3671
|
+
*/
|
|
3672
|
+
function hostTheiaBrowserPackageJson(composition) {
|
|
3673
|
+
const dependencies = {
|
|
3674
|
+
[memberPackageName(composition, 'theia')]: MEMBER_PIN,
|
|
3675
|
+
...Object.fromEntries(HOST_THEIA_BROWSER_DEPENDENCIES.map(name => [name, THEIA_VERSION]))
|
|
3676
|
+
};
|
|
3677
|
+
const devDependencies = {
|
|
3678
|
+
// Built before this application, whose start links it into plugins/.
|
|
3679
|
+
[memberPackageName(composition, 'vscode-servers')]: MEMBER_PIN,
|
|
3680
|
+
'@playwright/test': '^1.55.0',
|
|
3681
|
+
...Object.fromEntries(HOST_THEIA_BROWSER_DEV_DEPENDENCIES.map(name => [name, THEIA_VERSION])),
|
|
3682
|
+
'@types/node': '^22.0.0',
|
|
3683
|
+
rimraf: '^5.0.0',
|
|
3684
|
+
typescript: '^7.0.2'
|
|
3685
|
+
};
|
|
3686
|
+
const theia = {
|
|
3687
|
+
target: 'browser',
|
|
3688
|
+
frontend: {
|
|
3689
|
+
config: {
|
|
3690
|
+
applicationName: composition.name,
|
|
3691
|
+
connectionBufferBytes: 102400,
|
|
3692
|
+
preferences: { 'security.workspace.trust.enabled': false }
|
|
3693
|
+
}
|
|
3694
|
+
},
|
|
3695
|
+
backend: { config: { connectionBufferBytes: 102400, frontendConnectionTimeout: 60000 } }
|
|
3696
|
+
};
|
|
3697
|
+
return `{
|
|
3698
|
+
"name": "${memberPackageName(composition, 'host-theia-browser')}",
|
|
3699
|
+
"version": "0.0.0",
|
|
3700
|
+
"private": true,
|
|
3701
|
+
"description": "${composition.name} in a Theia browser application: the Theia extension, and the servers extension sideloaded for the language client.",
|
|
3702
|
+
"license": "UNLICENSED",
|
|
3703
|
+
"author": "",
|
|
3704
|
+
"scripts": {
|
|
3705
|
+
"build": "theia build --mode development && npm run typecheck",
|
|
3706
|
+
"clean": "rimraf lib src-gen plugins gen-esbuild.browser.mjs gen-esbuild.node.mjs smoke-workspace test-results playwright-report",
|
|
3707
|
+
${lintScript(forMember(composition, 'host-theia-browser'), 'test')} "start": "node start.mjs",
|
|
3708
|
+
"test:e2e": "playwright test --tsconfig tsconfig.e2e.json",
|
|
3709
|
+
"test:e2e:install": "playwright install chromium",
|
|
3710
|
+
"typecheck": "tsc --noEmit -p tsconfig.e2e.json",
|
|
3711
|
+
"watch": "theia build --watch --mode development"
|
|
3712
|
+
},
|
|
3713
|
+
"dependencies": {
|
|
3714
|
+
${sortedBlock(dependencies, ' ')}
|
|
3715
|
+
},
|
|
3716
|
+
"devDependencies": {
|
|
3717
|
+
${sortedBlock(devDependencies, ' ')}
|
|
3718
|
+
},
|
|
3719
|
+
"engines": {
|
|
3720
|
+
"node": ">=22.13"
|
|
3721
|
+
},
|
|
3722
|
+
"theia": ${jsonAt(theia, ' ')}
|
|
3723
|
+
}
|
|
3724
|
+
`;
|
|
3725
|
+
}
|
|
3726
|
+
/**
|
|
3727
|
+
* The Theia smoke test: the application opens a copy of the starter
|
|
3728
|
+
* workspace, and each head answers. The steps are the same in both
|
|
3729
|
+
* applications; the browser one's page is Chromium on the server the
|
|
3730
|
+
* configuration starts, the Electron one's the window the test launches.
|
|
3731
|
+
*/
|
|
3732
|
+
function theiaSmokeSpec(composition, target) {
|
|
3733
|
+
const data = composition.heads.includes('data');
|
|
3734
|
+
const diagram = composition.grammars.find(grammar => grammar.diagram);
|
|
3735
|
+
const primary = diagram ?? composition.grammars[0];
|
|
3736
|
+
const file = `nodes.${primary.extensions[0]}`;
|
|
3737
|
+
const showModelSteps = data
|
|
3738
|
+
? `
|
|
3739
|
+
// The data head reads the open file, with focus in the Explorer beside it.
|
|
3740
|
+
await page.locator('.theia-FileTree .theia-TreeNode', { hasText: '${file}' }).click();
|
|
3741
|
+
await expect(page.locator('.theia-FileTree:focus-within')).toHaveCount(1);
|
|
3742
|
+
await runCommand(page, '${composition.name}: Show Model');
|
|
3743
|
+
// \`first()\`: Theia lists a notification in its toast and in the notification centre.
|
|
3744
|
+
await expect(
|
|
3745
|
+
page.locator('.theia-notification-message').filter({ hasText: '${file} holds a ${primary.entryRule}' }).first()
|
|
3746
|
+
).toBeVisible();
|
|
3747
|
+
`
|
|
3748
|
+
: '';
|
|
3749
|
+
const diagramSteps = diagram
|
|
3750
|
+
? `
|
|
3751
|
+
// The diagram file opens in its diagram, which draws the two starter nodes.
|
|
3752
|
+
// In the editor's copy: sprotty measures shapes in a hidden one on the page.
|
|
3753
|
+
await expect(page.locator('.sprotty:not(.sprotty-hidden) .sprotty-node')).toHaveCount(2);
|
|
3754
|
+
`
|
|
3755
|
+
: '';
|
|
3756
|
+
const textSteps = diagram
|
|
3757
|
+
? ` // Then as text, through the Explorer's Open With.
|
|
3758
|
+
await page.locator('.theia-FileTree .theia-TreeNode', { hasText: '${file}' }).click({ button: 'right' });
|
|
3759
|
+
await page.locator('.lm-Menu-item', { hasText: 'Open With...' }).click();
|
|
3760
|
+
await page.locator('.quick-input-list .monaco-list-row', { hasText: 'Text Editor' }).click();
|
|
3761
|
+
`
|
|
3762
|
+
: '';
|
|
3763
|
+
return `${wrapComment(`Theia opens a copy of the starter workspace with this application's extensions, ${listPhrase([
|
|
3764
|
+
...(diagram ? ['the diagram file draws in its diagram editor'] : []),
|
|
3765
|
+
...(data ? ['the data head reads the file'] : []),
|
|
3766
|
+
'the server reports a reference that resolves to nothing'
|
|
3767
|
+
])}.`)}
|
|
3768
|
+
|
|
3769
|
+
${target === 'browser' ? "import { expect, test, type Page } from '@playwright/test';\n" : theiaElectronSmokeFixture(composition)}
|
|
3770
|
+
test('${listPhrase([...(diagram ? ['draws the diagram'] : []), ...(data ? ['reads the model'] : []), 'reports a broken reference'])}', async ({ page }) => {
|
|
3771
|
+
${target === 'browser' ? " await page.goto('/');\n" : ''} // Up once the loading screen is gone; a key pressed before then is lost.
|
|
3772
|
+
await expect(page.locator('.theia-preload')).toHaveCount(0);
|
|
3773
|
+
await page.keyboard.press('ControlOrMeta+Shift+E');
|
|
3774
|
+
await expect(page.locator('.theia-FileTree .theia-TreeNode', { hasText: '${file}' })).toBeVisible();
|
|
3775
|
+
await quickOpen(page, '${file}');
|
|
3776
|
+
${diagramSteps}${showModelSteps}
|
|
3777
|
+
${textSteps} const editor = page.locator('.monaco-editor .view-lines').first();
|
|
3778
|
+
await expect(editor).toContainText('node First');
|
|
3779
|
+
await editor.click();
|
|
3780
|
+
await page.keyboard.press('ControlOrMeta+End');
|
|
3781
|
+
// In one edit: typed key by key, the half-typed reference is reported on the way.
|
|
3782
|
+
await page.keyboard.insertText('\\nnode Broken -> Missing');
|
|
3783
|
+
await expect(page.locator('.monaco-editor .squiggly-error').first()).toBeVisible();
|
|
3784
|
+
});
|
|
3785
|
+
|
|
3786
|
+
/** Open \`file\` through Quick Open, so it gets the editor a user would. */
|
|
3787
|
+
async function quickOpen(page: Page, file: string): Promise<void> {
|
|
3788
|
+
await page.keyboard.press('ControlOrMeta+P');
|
|
3789
|
+
const input = page.locator('.quick-input-widget input');
|
|
3790
|
+
await input.fill(file);
|
|
3791
|
+
await expect(page.locator('.quick-input-list .monaco-list-row').first()).toContainText(file);
|
|
3792
|
+
await input.press('Enter');
|
|
3793
|
+
await expect(page.locator('.quick-input-widget')).toBeHidden();
|
|
3794
|
+
}
|
|
3795
|
+
${data
|
|
3796
|
+
? `
|
|
3797
|
+
/** Run the command whose palette entry reads \`label\`, checked before Enter, since the match is fuzzy. */
|
|
3798
|
+
async function runCommand(page: Page, label: string): Promise<void> {
|
|
3799
|
+
await page.keyboard.press('F1');
|
|
3800
|
+
const input = page.locator('.quick-input-widget input');
|
|
3801
|
+
await input.fill(\`>\${label}\`);
|
|
3802
|
+
await expect(page.locator('.quick-input-list .monaco-list-row.focused')).toContainText(label);
|
|
3803
|
+
await input.press('Enter');
|
|
3804
|
+
await expect(page.locator('.quick-input-widget')).toBeHidden();
|
|
3805
|
+
}
|
|
3806
|
+
`
|
|
3807
|
+
: ''}`;
|
|
3808
|
+
}
|
|
3809
|
+
/** The Theia application's README. */
|
|
3810
|
+
function hostTheiaBrowserReadme(composition) {
|
|
3811
|
+
const intro = [
|
|
3812
|
+
`${composition.name} in a Theia browser application: the Theia extension in \`../theia\`, and \`../vscode-servers\` sideloaded through \`@theia/plugin-ext\`, which starts the server and its language client.`,
|
|
3813
|
+
'The backend runs the server, so this is a Node application; Theia serves the page.',
|
|
3814
|
+
...(composition.grammars.some(grammar => grammar.diagram)
|
|
3815
|
+
? ['The servers extension contributes no editor, so a diagram file opens in the Theia diagram editor alone.']
|
|
3816
|
+
: [])
|
|
3817
|
+
];
|
|
3818
|
+
const lines = [
|
|
3819
|
+
`# ${memberPackageName(composition, 'host-theia-browser')}`,
|
|
3820
|
+
'',
|
|
3821
|
+
...wrapProse(intro.join(' ')),
|
|
3822
|
+
'',
|
|
3823
|
+
'```bash',
|
|
3824
|
+
'npm run build # bundle and type-check; build the members first',
|
|
3825
|
+
'npm run watch # rebundle whenever the members’ builds change; reload the page to pick it up',
|
|
3826
|
+
'npm start # Theia at http://localhost:3000 on ../workspace; THEIA_PORT picks another port',
|
|
3827
|
+
'npm run test:e2e:install # download the Chromium the smoke test drives, once',
|
|
3828
|
+
'npm run test:e2e # the smoke test, which starts the application itself',
|
|
3829
|
+
'```',
|
|
3830
|
+
'',
|
|
3831
|
+
...wrapProse('The `theia` block of `package.json` sets `frontendConnectionTimeout`, without which Theia ends the session on any dropped socket and the page reloads, and `connectionBufferBytes`, the messages kept while the socket is down; the Theia extension’s connection modules read both.'),
|
|
3832
|
+
'',
|
|
3833
|
+
'## Layout',
|
|
3834
|
+
'',
|
|
3835
|
+
'- `esbuild.mjs` — the bundling `theia build` runs. It keeps this file, so it is the place to adjust the bundle',
|
|
3836
|
+
'- `start.mjs` — `npm start`: links `../vscode-servers` into `plugins/`, then starts the backend on `THEIA_PORT`, on a folder given as its argument or `../workspace`',
|
|
3837
|
+
'- `playwright.config.mts` — the smoke tier, on port 4938 or `THEIA_PORT`, on a copy of `../workspace` in `smoke-workspace/`',
|
|
3838
|
+
'- `test/smoke.spec.mts` — Theia opens the workspace and each head answers',
|
|
3839
|
+
''
|
|
3840
|
+
];
|
|
3841
|
+
return project(lines.join('\n'), composition);
|
|
3842
|
+
}
|
|
3843
|
+
/** The Theia browser application: the Theia extension and the sideloaded servers extension. */
|
|
3844
|
+
function hostTheiaBrowserFiles(composition) {
|
|
3845
|
+
const fixed = (file) => projectTemplate(`host-theia-browser/${file}`, composition);
|
|
3846
|
+
return [
|
|
3847
|
+
{ path: 'host-theia-browser/package.json', content: hostTheiaBrowserPackageJson(composition) },
|
|
3848
|
+
ignoreFile('host-theia-browser'),
|
|
3849
|
+
{ path: 'host-theia-browser/README.md', content: hostTheiaBrowserReadme(composition) },
|
|
3850
|
+
fixed('esbuild.mjs'),
|
|
3851
|
+
fixed('start.mjs'),
|
|
3852
|
+
fixed('playwright.config.mts'),
|
|
3853
|
+
fixed('tsconfig.e2e.json'),
|
|
3854
|
+
{ path: 'host-theia-browser/test/smoke.spec.mts', content: theiaSmokeSpec(composition, 'browser') }
|
|
3855
|
+
];
|
|
3856
|
+
}
|
|
3857
|
+
/**
|
|
3858
|
+
* The Electron smoke test's imports and its `page`: the application's window,
|
|
3859
|
+
* launched by the test on a scratch copy of the workspace.
|
|
3860
|
+
*/
|
|
3861
|
+
function theiaElectronSmokeFixture(composition) {
|
|
3862
|
+
return `import { expect, test as base, type ElectronApplication, type Page } from '@playwright/test';
|
|
3863
|
+
import { once } from 'node:events';
|
|
3864
|
+
import { cpSync, mkdirSync, mkdtempSync, rmSync, symlinkSync } from 'node:fs';
|
|
3865
|
+
import { tmpdir } from 'node:os';
|
|
3866
|
+
import { join } from 'node:path';
|
|
3867
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3868
|
+
|
|
3869
|
+
/**
|
|
3870
|
+
* The application in Electron, on a copy of the starter workspace, since the
|
|
3871
|
+
* server writes its repairs to the folder it opens, with a profile of its own:
|
|
3872
|
+
* Theia quits at once while another window holds one. Its settings are its own
|
|
3873
|
+
* too, so a run never writes \`~/.theia/settings.json\`.
|
|
3874
|
+
*/
|
|
3875
|
+
const test = base.extend<{ page: Page }>({
|
|
3876
|
+
page: async ({ playwright }, use) => {
|
|
3877
|
+
const scratch = mkdtempSync(join(tmpdir(), '${composition.projectId}-theia-electron-'));
|
|
3878
|
+
const workspace = join(scratch, 'workspace');
|
|
3879
|
+
// The servers extension, sideloaded from a plugins folder as \`npm start\` does.
|
|
3880
|
+
const plugins = join(scratch, 'plugins');
|
|
3881
|
+
const link = join(plugins, '${composition.projectId}-vscode-servers');
|
|
3882
|
+
let app: ElectronApplication | undefined;
|
|
3883
|
+
try {
|
|
3884
|
+
cpSync(fileURLToPath(new URL('../../workspace', import.meta.url)), workspace, { recursive: true });
|
|
3885
|
+
mkdirSync(plugins);
|
|
3886
|
+
symlinkSync(fileURLToPath(new URL('../../vscode-servers', import.meta.url)), link, 'junction');
|
|
3887
|
+
// Playwright resolves Electron itself; given its path, Theia opens this
|
|
3888
|
+
// folder instead of the workspace.
|
|
3889
|
+
app = await playwright._electron.launch({
|
|
3890
|
+
args: [
|
|
3891
|
+
fileURLToPath(new URL('..', import.meta.url)),
|
|
3892
|
+
'--no-sandbox',
|
|
3893
|
+
\`--user-data-dir=\${join(scratch, 'user-data')}\`,
|
|
3894
|
+
// In URI form, since Theia reads the argument as a URI.
|
|
3895
|
+
\`--plugins=local-dir:\${pathToFileURL(plugins).pathname}\`,
|
|
3896
|
+
workspace
|
|
3897
|
+
],
|
|
3898
|
+
env: {
|
|
3899
|
+
...process.env,
|
|
3900
|
+
THEIA_CONFIG_DIR: join(scratch, 'config'),
|
|
3901
|
+
// Menus drawn in the page, where the test can click them.
|
|
3902
|
+
THEIA_ELECTRON_DISABLE_NATIVE_ELEMENTS: '1'
|
|
3903
|
+
}
|
|
3904
|
+
});
|
|
3905
|
+
await use(await app.firstWindow());
|
|
3906
|
+
} finally {
|
|
3907
|
+
try {
|
|
3908
|
+
// Exited, not closed: closing asks whether to save the edited file. An
|
|
3909
|
+
// app that is already gone is left alone, so the test's own error stands.
|
|
3910
|
+
const child = app?.process();
|
|
3911
|
+
if (app && child?.exitCode === null && child.signalCode === null) {
|
|
3912
|
+
const exited = once(child, 'exit');
|
|
3913
|
+
await app.evaluate(({ app: electron }) => electron.exit(0));
|
|
3914
|
+
await exited;
|
|
3915
|
+
}
|
|
3916
|
+
} finally {
|
|
3917
|
+
// Unlinked first, so the remove never reaches \`../vscode-servers\` through it.
|
|
3918
|
+
rmSync(link, { force: true });
|
|
3919
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
}
|
|
3923
|
+
});
|
|
3924
|
+
`;
|
|
3925
|
+
}
|
|
3926
|
+
/**
|
|
3927
|
+
* The Theia Electron application's `package.json`: the browser application's
|
|
3928
|
+
* `theia` block with the Electron target. Always private, as every host is.
|
|
3929
|
+
*/
|
|
3930
|
+
function hostTheiaElectronPackageJson(composition) {
|
|
3931
|
+
const dependencies = {
|
|
3932
|
+
[memberPackageName(composition, 'theia')]: MEMBER_PIN,
|
|
3933
|
+
...Object.fromEntries(HOST_THEIA_ELECTRON_DEPENDENCIES.map(name => [name, THEIA_VERSION]))
|
|
3934
|
+
};
|
|
3935
|
+
const devDependencies = {
|
|
3936
|
+
// Built before this application, whose start links it into plugins/.
|
|
3937
|
+
[memberPackageName(composition, 'vscode-servers')]: MEMBER_PIN,
|
|
3938
|
+
'@playwright/test': '^1.55.0',
|
|
3939
|
+
...Object.fromEntries(HOST_THEIA_BROWSER_DEV_DEPENDENCIES.map(name => [name, THEIA_VERSION])),
|
|
3940
|
+
'@types/node': '^22.0.0',
|
|
3941
|
+
electron: ELECTRON_VERSION,
|
|
3942
|
+
rimraf: '^5.0.0',
|
|
3943
|
+
typescript: '^7.0.2'
|
|
3944
|
+
};
|
|
3945
|
+
const theia = {
|
|
3946
|
+
target: 'electron',
|
|
3947
|
+
frontend: {
|
|
3948
|
+
config: {
|
|
3949
|
+
applicationName: composition.name,
|
|
3950
|
+
connectionBufferBytes: 102400,
|
|
3951
|
+
preferences: { 'security.workspace.trust.enabled': false }
|
|
3952
|
+
}
|
|
3953
|
+
},
|
|
3954
|
+
backend: { config: { connectionBufferBytes: 102400, frontendConnectionTimeout: 60000 } }
|
|
3955
|
+
};
|
|
3956
|
+
return `{
|
|
3957
|
+
"name": "${memberPackageName(composition, 'host-theia-electron')}",
|
|
3958
|
+
"version": "0.0.0",
|
|
3959
|
+
"private": true,
|
|
3960
|
+
"description": "${composition.name} in a Theia Electron application: the Theia extension, and the servers extension sideloaded for the language client.",
|
|
3961
|
+
"license": "UNLICENSED",
|
|
3962
|
+
"author": "",
|
|
3963
|
+
"main": "lib/backend/electron-main.js",
|
|
3964
|
+
"scripts": {
|
|
3965
|
+
"build": "theia build --mode development && npm run typecheck",
|
|
3966
|
+
"clean": "rimraf lib src-gen plugins gen-esbuild.browser.mjs gen-esbuild.electron.mjs gen-esbuild.node.mjs test-results playwright-report",
|
|
3967
|
+
${lintScript(forMember(composition, 'host-theia-electron'), 'test')} "start": "node start.mjs",
|
|
3968
|
+
"test:e2e": "playwright test --tsconfig tsconfig.e2e.json",
|
|
3969
|
+
"typecheck": "tsc --noEmit -p tsconfig.e2e.json",
|
|
3970
|
+
"watch": "theia build --watch --mode development"
|
|
3971
|
+
},
|
|
3972
|
+
"dependencies": {
|
|
3973
|
+
${sortedBlock(dependencies, ' ')}
|
|
3974
|
+
},
|
|
3975
|
+
"devDependencies": {
|
|
3976
|
+
${sortedBlock(devDependencies, ' ')}
|
|
3977
|
+
},
|
|
3978
|
+
"engines": {
|
|
3979
|
+
"node": ">=22.13"
|
|
3980
|
+
},
|
|
3981
|
+
"theia": ${jsonAt(theia, ' ')}
|
|
3982
|
+
}
|
|
3983
|
+
`;
|
|
3984
|
+
}
|
|
3985
|
+
/** The Theia Electron application's README. */
|
|
3986
|
+
function hostTheiaElectronReadme(composition) {
|
|
3987
|
+
const intro = [
|
|
3988
|
+
`${composition.name} in a Theia Electron application: the Theia extension in \`../theia\`, and \`../vscode-servers\` sideloaded through \`@theia/plugin-ext\`, which starts the server and its language client.`,
|
|
3989
|
+
'Electron runs the window, and a backend process it starts runs the server.',
|
|
3990
|
+
...(composition.grammars.some(grammar => grammar.diagram)
|
|
3991
|
+
? ['The servers extension contributes no editor, so a diagram file opens in the Theia diagram editor alone.']
|
|
3992
|
+
: [])
|
|
3993
|
+
];
|
|
3994
|
+
const lines = [
|
|
3995
|
+
`# ${memberPackageName(composition, 'host-theia-electron')}`,
|
|
3996
|
+
'',
|
|
3997
|
+
...wrapProse(intro.join(' ')),
|
|
3998
|
+
'',
|
|
3999
|
+
'```bash',
|
|
4000
|
+
'npm run build # bundle and type-check, and download Electron; build the members first',
|
|
4001
|
+
'npm run watch # rebundle whenever the members’ builds change; reload the window to pick it up',
|
|
4002
|
+
'npm start # the application on ../workspace',
|
|
4003
|
+
'npm run test:e2e # the smoke test, which launches the application itself',
|
|
4004
|
+
'```',
|
|
4005
|
+
'',
|
|
4006
|
+
...wrapProse('There is no `theia rebuild:electron` step: Theia’s native modules are N-API builds, which load in Electron as `npm install` built them for Node.'),
|
|
4007
|
+
'',
|
|
4008
|
+
...wrapProse('`npm run watch` reports a `theia-source-map-paths` JSON error as it starts: `esbuild.mjs` starts the browser and electron builds together, and they share `lib/frontend`. Later rebuilds are clean.'),
|
|
4009
|
+
'',
|
|
4010
|
+
'## Layout',
|
|
4011
|
+
'',
|
|
4012
|
+
'- `esbuild.mjs` — the bundling `theia build` runs. It keeps this file, so it is the place to adjust the bundle',
|
|
4013
|
+
'- `start.mjs` — `npm start`: links `../vscode-servers` into `plugins/`, then starts the application on a folder given as its argument or `../workspace`',
|
|
4014
|
+
'- `playwright.config.mts` — the smoke tier',
|
|
4015
|
+
'- `test/smoke.spec.mts` — Electron opens a copy of the workspace with a profile of its own, and each head answers',
|
|
4016
|
+
''
|
|
4017
|
+
];
|
|
4018
|
+
return project(lines.join('\n'), composition);
|
|
4019
|
+
}
|
|
4020
|
+
/** The Theia Electron application: the browser application's extensions in a desktop window. */
|
|
4021
|
+
function hostTheiaElectronFiles(composition) {
|
|
4022
|
+
const fixed = (file) => projectTemplate(`host-theia-electron/${file}`, composition);
|
|
4023
|
+
return [
|
|
4024
|
+
{ path: 'host-theia-electron/package.json', content: hostTheiaElectronPackageJson(composition) },
|
|
4025
|
+
ignoreFile('host-theia-electron'),
|
|
4026
|
+
{ path: 'host-theia-electron/README.md', content: hostTheiaElectronReadme(composition) },
|
|
4027
|
+
fixed('esbuild.mjs'),
|
|
4028
|
+
fixed('start.mjs'),
|
|
4029
|
+
fixed('playwright.config.mts'),
|
|
4030
|
+
fixed('tsconfig.e2e.json'),
|
|
4031
|
+
{ path: 'host-theia-electron/test/smoke.spec.mts', content: theiaSmokeSpec(composition, 'electron') }
|
|
4032
|
+
];
|
|
4033
|
+
}
|
|
4034
|
+
/**
|
|
4035
|
+
* The formatter and linter a standalone root runs. Exact, because a formatter
|
|
4036
|
+
* release that changes its output would fail the project's `format:check`.
|
|
4037
|
+
*/
|
|
4038
|
+
const ROOT_STYLE_DEV_DEPENDENCIES = { oxfmt: '0.71.0', oxlint: '1.82.0' };
|
|
4039
|
+
/**
|
|
4040
|
+
* The standalone root's formatter config: the style every template is written
|
|
4041
|
+
* in, at the width the emitted sources wrap at. Generated code is ignored
|
|
4042
|
+
* because each run of its generator rewrites it in that generator's style.
|
|
4043
|
+
*/
|
|
4044
|
+
function oxfmtConfig(composition) {
|
|
4045
|
+
return `{
|
|
4046
|
+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
|
4047
|
+
"arrowParens": "avoid",
|
|
4048
|
+
"endOfLine": "lf",
|
|
4049
|
+
"ignorePatterns": ["**/generated", "**/generated-hydranium", "**/syntaxes", "**/*.md"],
|
|
4050
|
+
"jsxSingleQuote": true,
|
|
4051
|
+
"printWidth": ${columnsFor(composition)},
|
|
4052
|
+
"singleQuote": true,
|
|
4053
|
+
"sortPackageJson": true,
|
|
4054
|
+
"tabWidth": 3,
|
|
4055
|
+
"trailingComma": "none",
|
|
4056
|
+
"overrides": [
|
|
4057
|
+
{
|
|
4058
|
+
"files": ["*.json", "*.yml", "*.yaml"],
|
|
4059
|
+
"options": {
|
|
4060
|
+
"printWidth": 100,
|
|
4061
|
+
"tabWidth": 2
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
]
|
|
4065
|
+
}
|
|
4066
|
+
`;
|
|
4067
|
+
}
|
|
4068
|
+
/**
|
|
4069
|
+
* A standalone project's root: the members as npm workspaces.
|
|
4070
|
+
*
|
|
4071
|
+
* Always private: it is never published, whatever `--public` makes of the
|
|
4072
|
+
* members. npm runs a script across the members in the order listed here, not
|
|
4073
|
+
* by their dependencies; listing protocol first is safe because its `build`
|
|
4074
|
+
* runs the server's `generate` before compiling.
|
|
4075
|
+
*
|
|
4076
|
+
* It declares the exact pins `--monorepo` prints for a workspace root, for the
|
|
4077
|
+
* same reason: a package ranging over one, such as a framework package's peer,
|
|
4078
|
+
* otherwise takes the top of the tree with the newest match, and each member's
|
|
4079
|
+
* exact copy nests beneath it.
|
|
4080
|
+
*
|
|
4081
|
+
* `watch` keeps every non-host member built; `watch:<host>` adds one host, so
|
|
4082
|
+
* only the bundler of the host being worked on runs.
|
|
4083
|
+
*
|
|
4084
|
+
* `format` and `lint` run at the root over every member, which is why the
|
|
4085
|
+
* members get no `lint` of their own here.
|
|
4086
|
+
*/
|
|
4087
|
+
function rootFiles(composition) {
|
|
4088
|
+
const devDependencies = {
|
|
4089
|
+
...Object.fromEntries(workspaceRootPins(composition)),
|
|
4090
|
+
concurrently: '^9.0.0',
|
|
4091
|
+
...ROOT_STYLE_DEV_DEPENDENCIES
|
|
4092
|
+
};
|
|
4093
|
+
const members = initMembers(composition.heads, composition.hosts);
|
|
4094
|
+
// Only the server's watch is `tsc -b`, so protocol is built by one process
|
|
4095
|
+
// rather than two writing the same `lib/`; a host's watch joins only in its
|
|
4096
|
+
// own `watch:<host>`.
|
|
4097
|
+
const watched = members.filter(member => member !== 'protocol' && !member.startsWith('host-'));
|
|
4098
|
+
const parallel = (commands) => `concurrently --kill-others --names ${Object.keys(commands).join(',')} ${Object.values(commands)
|
|
4099
|
+
.map(command => `\\"${command}\\"`)
|
|
4100
|
+
.join(' ')}`;
|
|
4101
|
+
const scripts = {
|
|
4102
|
+
build: 'npm run build --workspaces',
|
|
4103
|
+
clean: 'npm run clean --workspaces --if-present',
|
|
4104
|
+
format: 'oxfmt',
|
|
4105
|
+
'format:check': 'oxfmt --check',
|
|
4106
|
+
lint: 'oxlint --report-unused-disable-directives --max-warnings 0',
|
|
4107
|
+
...Object.fromEntries(composition.hosts.map(host => [`start:${host}`, `npm --prefix host-${host} start`])),
|
|
4108
|
+
test: 'npm test --workspaces --if-present',
|
|
4109
|
+
watch: parallel(Object.fromEntries(watched.map(member => [member, `npm --prefix ${member} run watch`]))),
|
|
4110
|
+
// The browser host's `start` is its watch: it rebundles the page as it serves it.
|
|
4111
|
+
...Object.fromEntries(composition.hosts.map(host => [
|
|
4112
|
+
`watch:${host}`,
|
|
4113
|
+
parallel({
|
|
4114
|
+
watch: 'npm run watch',
|
|
4115
|
+
[`host-${host}`]: `npm --prefix host-${host} ${host === 'browser' ? 'start' : 'run watch'}`
|
|
4116
|
+
})
|
|
4117
|
+
]))
|
|
4118
|
+
};
|
|
4119
|
+
const content = `{
|
|
4120
|
+
"name": "${composition.projectId}-root",
|
|
4121
|
+
"version": "0.0.0",
|
|
4122
|
+
"private": true,
|
|
4123
|
+
"workspaces": [
|
|
4124
|
+
${members.map(member => ` "${member}"`).join(',\n')}
|
|
4125
|
+
],
|
|
4126
|
+
"scripts": {
|
|
4127
|
+
${Object.entries(scripts)
|
|
4128
|
+
.map(([name, command]) => ` "${name}": "${command}"`)
|
|
4129
|
+
.join(',\n')}
|
|
4130
|
+
},
|
|
4131
|
+
"devDependencies": {
|
|
4132
|
+
${sortedBlock(devDependencies, ' ')}
|
|
4133
|
+
},
|
|
4134
|
+
"engines": {
|
|
4135
|
+
"node": ">=22.13"
|
|
4136
|
+
}
|
|
4137
|
+
}
|
|
4138
|
+
`;
|
|
4139
|
+
return [
|
|
4140
|
+
{ path: 'package.json', content },
|
|
4141
|
+
ignoreFile(''),
|
|
4142
|
+
{ path: '.editorconfig', content: template('editorconfig') },
|
|
4143
|
+
{ path: '.oxfmtrc.json', content: oxfmtConfig(composition) },
|
|
4144
|
+
{ path: '.oxlintrc.json', content: template('oxlintrc.json') }
|
|
4145
|
+
];
|
|
4146
|
+
}
|
|
4147
|
+
/**
|
|
4148
|
+
* Every file the scaffold emits, fully rendered, at its path in the project
|
|
4149
|
+
* directory. A workspace member's project gets no root of its own: it joins the
|
|
4150
|
+
* surrounding workspace, whose manifest `init` prints the changes for.
|
|
4151
|
+
*/
|
|
4152
|
+
export function buildInitTemplates(composition) {
|
|
4153
|
+
return [
|
|
4154
|
+
...(composition.packaging.workspace === undefined ? rootFiles(composition) : []),
|
|
4155
|
+
...protocolFiles(composition),
|
|
4156
|
+
...serverFiles(composition),
|
|
4157
|
+
...(composition.heads.includes('glsp') ? clientFiles(composition) : []),
|
|
4158
|
+
...(emitsVscodeServers(composition) ? vscodeServersFiles(composition) : []),
|
|
4159
|
+
...(composition.hosts.some(isTheiaHost) ? theiaFiles(composition) : []),
|
|
4160
|
+
...(composition.hosts.includes('browser') ? hostBrowserFiles(composition) : []),
|
|
4161
|
+
...(composition.hosts.includes('vscode') ? hostVscodeFiles(composition) : []),
|
|
4162
|
+
...(composition.hosts.includes('theia-browser') ? hostTheiaBrowserFiles(composition) : []),
|
|
4163
|
+
...(composition.hosts.includes('theia-electron') ? hostTheiaElectronFiles(composition) : []),
|
|
4164
|
+
...workspaceFiles(composition)
|
|
1934
4165
|
];
|
|
1935
4166
|
}
|
|
1936
4167
|
//# sourceMappingURL=init-templates.js.map
|