@hydranium/cli 1.0.0-next.39 → 1.0.0-next.391
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 +26 -14
- package/lib/commands/init-templates.d.ts.map +1 -1
- package/lib/commands/init-templates.js +2989 -746
- 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 +206 -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 +3161 -759
- package/src/commands/init-wizard.ts +55 -31
- package/src/commands/init-workspace.ts +31 -16
- package/src/commands/init.ts +266 -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
|
@@ -9,34 +9,36 @@
|
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
11
|
exitWithUsage,
|
|
12
|
+
HARNESS_VALUE_FLAGS,
|
|
12
13
|
helpRequested,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
importHelpLines,
|
|
15
|
+
LOG_VALUE_FLAGS,
|
|
16
|
+
logHelpLines,
|
|
17
|
+
logOptions,
|
|
16
18
|
parseHarnessArgs,
|
|
17
19
|
printHelp,
|
|
18
|
-
SERVICES_FLAG,
|
|
19
20
|
type UsageError
|
|
20
21
|
} from './harness-args.js';
|
|
21
22
|
import { OUT_FILE_FLAG } from './headless-harness.js';
|
|
22
23
|
import { runValidate, type ValidateCommandOptions } from './validate.js';
|
|
23
24
|
|
|
24
|
-
const VALUE_FLAGS = [OUT_FILE_FLAG,
|
|
25
|
+
const VALUE_FLAGS = [OUT_FILE_FLAG, ...LOG_VALUE_FLAGS] as const;
|
|
25
26
|
const BOOL_FLAGS = ['--strict', '--json'] as const;
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Every flag `validate` accepts, derived from the sets the parser is handed so
|
|
29
|
-
* the list cannot claim a flag the parser would reject.
|
|
30
|
-
* by the shared harness parser itself,
|
|
30
|
+
* the list cannot claim a flag the parser would reject.
|
|
31
|
+
* {@link HARNESS_VALUE_FLAGS} are consumed by the shared harness parser itself,
|
|
32
|
+
* so they are in neither set.
|
|
31
33
|
*/
|
|
32
|
-
export const VALIDATE_FLAGS: readonly string[] = [
|
|
34
|
+
export const VALIDATE_FLAGS: readonly string[] = [...HARNESS_VALUE_FLAGS, ...VALUE_FLAGS, ...BOOL_FLAGS];
|
|
33
35
|
|
|
34
36
|
/** The subset that takes a value, so `--help` in a value position reads as data. */
|
|
35
|
-
export const VALIDATE_VALUE_FLAGS: readonly string[] = [
|
|
37
|
+
export const VALIDATE_VALUE_FLAGS: readonly string[] = [...HARNESS_VALUE_FLAGS, ...VALUE_FLAGS];
|
|
36
38
|
|
|
37
39
|
/** The `--help` text, as data, held to {@link VALIDATE_FLAGS} by a test. */
|
|
38
40
|
export const VALIDATE_HELP: readonly string[] = [
|
|
39
|
-
'Usage: hydranium-cli validate --services <module> <workspace> [--strict] [--json] [--out-file <file>] [--log-level <lvl>]',
|
|
41
|
+
'Usage: hydranium-cli validate --services <module> [--import <specifier>]... <workspace> [--strict] [--json] [--out-file <file>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
|
|
40
42
|
'',
|
|
41
43
|
'Build a workspace headlessly and report its validation diagnostics — a CI gate:',
|
|
42
44
|
'the process exits non-zero when any error is found. `<module>` is an ESM module',
|
|
@@ -45,6 +47,7 @@ export const VALIDATE_HELP: readonly string[] = [
|
|
|
45
47
|
'',
|
|
46
48
|
'Options:',
|
|
47
49
|
' --services <module> ESM module exporting `createServices(): { shared }` (required).',
|
|
50
|
+
...importHelpLines(22),
|
|
48
51
|
' <workspace> Workspace root (path or file URI) to validate (required).',
|
|
49
52
|
' --strict Also fail (non-zero exit) on warnings, not only errors.',
|
|
50
53
|
' --json Emit the raw JSON result instead of the human report.',
|
|
@@ -52,18 +55,19 @@ export const VALIDATE_HELP: readonly string[] = [
|
|
|
52
55
|
' still decides the exit code, and the file is written only',
|
|
53
56
|
' once the report exists, unlike a shell redirection, which',
|
|
54
57
|
' truncates the file before the workspace is even built.',
|
|
55
|
-
|
|
58
|
+
...logHelpLines(22)
|
|
56
59
|
];
|
|
57
60
|
|
|
58
61
|
export function parseValidateArgs(args: string[], onError: UsageError = exitWithUsage): ValidateCommandOptions {
|
|
59
|
-
const { servicesModule, workspace, options } = parseHarnessArgs(args, 'validate', VALUE_FLAGS, BOOL_FLAGS, { onError });
|
|
62
|
+
const { servicesModule, imports, workspace, options } = parseHarnessArgs(args, 'validate', VALUE_FLAGS, BOOL_FLAGS, { onError });
|
|
60
63
|
return {
|
|
61
64
|
servicesModule,
|
|
65
|
+
imports,
|
|
62
66
|
workspace,
|
|
63
67
|
strict: options['--strict'] === 'true',
|
|
64
68
|
json: options['--json'] === 'true',
|
|
65
69
|
outFile: options[OUT_FILE_FLAG],
|
|
66
|
-
|
|
70
|
+
...logOptions(options)
|
|
67
71
|
};
|
|
68
72
|
}
|
|
69
73
|
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* `--strict` also fails on warnings). Never imported — only spawned.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
import { describeError } from '@hydranium/protocol';
|
|
19
20
|
import { emitReport, loadHeadlessContext, OUT_FILE_FLAG } from './headless-harness.js';
|
|
20
21
|
import { formatValidationReport, validationExitCode } from './validate-report.js';
|
|
21
22
|
|
|
@@ -79,6 +80,6 @@ async function main(argv: string[]): Promise<number> {
|
|
|
79
80
|
main(process.argv.slice(2))
|
|
80
81
|
.then(code => process.exit(code))
|
|
81
82
|
.catch((error: unknown) => {
|
|
82
|
-
console.error(
|
|
83
|
+
console.error(describeError(error));
|
|
83
84
|
process.exit(1);
|
|
84
85
|
});
|
package/src/commands/validate.ts
CHANGED
|
@@ -54,5 +54,5 @@ export function buildValidateDriverArgs(options: ValidateCommandOptions): string
|
|
|
54
54
|
* The child's exit code propagates to this process so shells and CI see the gate.
|
|
55
55
|
*/
|
|
56
56
|
export function runValidate(options: ValidateCommandOptions): Promise<void> {
|
|
57
|
-
return runDriverChild([
|
|
57
|
+
return runDriverChild([DRIVER, ...buildValidateDriverArgs(options)], options);
|
|
58
58
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
assertRequired,
|
|
12
12
|
exitWithUsage,
|
|
13
13
|
helpRequested,
|
|
14
|
+
logHelpLines,
|
|
14
15
|
parseFlagOptions,
|
|
15
16
|
parseServerSpawnOptions,
|
|
16
17
|
printHelp,
|
|
@@ -35,7 +36,7 @@ export const WATCH_VALUE_FLAGS: readonly string[] = WATCH_FLAGS;
|
|
|
35
36
|
|
|
36
37
|
/** The `--help` text, as data, held to {@link WATCH_FLAGS} by a test. */
|
|
37
38
|
export const WATCH_HELP: readonly string[] = [
|
|
38
|
-
'Usage: hydranium-cli watch --server "<cmd>..." --uri <uri> [--client-id <id>] [--cwd <dir>] [--log-level <level>]',
|
|
39
|
+
'Usage: hydranium-cli watch --server "<cmd>..." --uri <uri> [--client-id <id>] [--cwd <dir>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
|
|
39
40
|
'',
|
|
40
41
|
'Subscribe to document updates at `<uri>` and print events as newline-delimited',
|
|
41
42
|
'JSON. Long-running — exits cleanly on SIGINT (Ctrl-C).',
|
|
@@ -45,18 +46,20 @@ export const WATCH_HELP: readonly string[] = [
|
|
|
45
46
|
' --uri <uri> Document URI (required).',
|
|
46
47
|
' --client-id <id> Subscriber identity. Default: hydranium-cli.',
|
|
47
48
|
' --cwd <dir> Working directory for the spawned child. Default: cwd.',
|
|
48
|
-
'
|
|
49
|
+
...logHelpLines(22, 'the spawned server')
|
|
49
50
|
];
|
|
50
51
|
|
|
51
52
|
/** Parse the argv; the abort signal is the entry point's to supply, not the command line's. */
|
|
52
53
|
export function parseWatchArgs(args: string[], onError: UsageError = exitWithUsage): WatchCommandOptions {
|
|
53
|
-
const { serverCommand, serverArgs, cwd, logLevel, extra } = parseServerSpawnOptions(args, 'watch', onError);
|
|
54
|
+
const { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel, extra } = parseServerSpawnOptions(args, 'watch', onError);
|
|
54
55
|
const { uri, clientId } = parseFlagOptions(extra, 'watch', OWN_FLAGS, onError);
|
|
55
56
|
return {
|
|
56
57
|
serverCommand,
|
|
57
58
|
serverArgs,
|
|
58
59
|
cwd,
|
|
59
60
|
logLevel,
|
|
61
|
+
logFile,
|
|
62
|
+
logFileLevel,
|
|
60
63
|
uri: assertRequired(uri, '--uri', 'watch', onError),
|
|
61
64
|
clientId
|
|
62
65
|
};
|
package/src/commands/watch.ts
CHANGED
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import type {
|
|
10
|
+
import type { TransferElement } from '@hydranium/protocol';
|
|
11
11
|
import type {
|
|
12
12
|
DataClientProtocol,
|
|
13
13
|
DataServerProtocol,
|
|
14
14
|
TransferDocumentDeletedEvent,
|
|
15
15
|
TransferDocumentUpdatedEvent
|
|
16
16
|
} from '@hydranium/protocol/data';
|
|
17
|
-
import {
|
|
17
|
+
import { logEnv, type LogOptions } from '../log-level.js';
|
|
18
18
|
import { spawnDataServer } from '../spawn-data-server.js';
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -27,12 +27,10 @@ import { spawnDataServer } from '../spawn-data-server.js';
|
|
|
27
27
|
* — production CLI wires SIGINT directly. `__handleForTest` bypasses
|
|
28
28
|
* the spawn step for unit tests.
|
|
29
29
|
*/
|
|
30
|
-
export interface WatchCommandOptions {
|
|
30
|
+
export interface WatchCommandOptions extends LogOptions {
|
|
31
31
|
readonly serverCommand: string;
|
|
32
32
|
readonly serverArgs?: readonly string[];
|
|
33
33
|
readonly cwd?: string;
|
|
34
|
-
/** Log threshold for the spawned server, set on its `HYDRANIUM_LOG_LEVEL` env. */
|
|
35
|
-
readonly logLevel?: LogThreshold;
|
|
36
34
|
readonly uri: string;
|
|
37
35
|
readonly clientId?: string;
|
|
38
36
|
readonly write?: (line: string) => void;
|
|
@@ -137,6 +135,9 @@ export async function runWatch(options: WatchCommandOptions): Promise<void> {
|
|
|
137
135
|
onDocumentSaved(): void {
|
|
138
136
|
// Persistence is out of band for the per-URI update view.
|
|
139
137
|
},
|
|
138
|
+
onDocumentDirtyChanged(): void {
|
|
139
|
+
// Out of band for the per-URI update view, as persistence is.
|
|
140
|
+
},
|
|
140
141
|
onDocumentDeleted(event: TransferDocumentDeletedEvent): void {
|
|
141
142
|
// In band, unlike the two neighbours: this is the end of the stream
|
|
142
143
|
// the view exists to show, and a consumer that never hears it waits
|
|
@@ -166,7 +167,7 @@ export async function runWatch(options: WatchCommandOptions): Promise<void> {
|
|
|
166
167
|
command: options.serverCommand,
|
|
167
168
|
args: options.serverArgs,
|
|
168
169
|
cwd: options.cwd,
|
|
169
|
-
env:
|
|
170
|
+
env: logEnv(options)
|
|
170
171
|
},
|
|
171
172
|
localClient
|
|
172
173
|
);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import { heapCeilingArgs } from '@hydranium/core/node';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Heap ceiling in MiB for a driver child on a machine with no cgroup limit.
|
|
14
|
+
*
|
|
15
|
+
* The subcommands that spawn one build a whole workspace in that child —
|
|
16
|
+
* `measure-memory` deliberately so, `analyze-heap` loads an entire heap
|
|
17
|
+
* snapshot — so the default Node would pick from physical RAM is too low for
|
|
18
|
+
* the workspaces these are pointed at.
|
|
19
|
+
*/
|
|
20
|
+
export const DRIVER_HEAP_MB = 8192;
|
|
21
|
+
|
|
22
|
+
/** Environment variable an operator raises or lowers {@link driverHeapArgs} with. */
|
|
23
|
+
export const DRIVER_HEAP_ENV = 'HYDRANIUM_CLI_MAX_OLD_SPACE_MB';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Smallest ceiling {@link DRIVER_HEAP_ENV} may state. A driver child builds a
|
|
27
|
+
* whole workspace, so a value this far below the default is a unit mistake
|
|
28
|
+
* rather than a deliberate squeeze.
|
|
29
|
+
*/
|
|
30
|
+
export const MIN_DRIVER_HEAP_MB = 256;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A cgroup reading, so a caller — in practice a test — can decide the ceiling
|
|
34
|
+
* instead of inheriting the machine's. Omitted fields fall back to this
|
|
35
|
+
* process's own reading.
|
|
36
|
+
*/
|
|
37
|
+
export interface HeapReading {
|
|
38
|
+
readonly constrained?: number;
|
|
39
|
+
readonly total?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The `execArgv` prefix every driver child is spawned under.
|
|
44
|
+
*
|
|
45
|
+
* Inside a container this is EMPTY on purpose. {@link DRIVER_HEAP_MB} is sized
|
|
46
|
+
* for a workstation, and handing it to a process under a smaller cgroup limit
|
|
47
|
+
* is worse than handing it nothing: V8 has no reason to collect hard below a
|
|
48
|
+
* ceiling it will never reach, so the kernel OOM-kills the container first and
|
|
49
|
+
* the failure arrives as a signal against the whole cgroup rather than as a
|
|
50
|
+
* heap error the parent can attribute. Left to itself, Node sizes the heap from
|
|
51
|
+
* the limit instead.
|
|
52
|
+
*
|
|
53
|
+
* That trades away the ability to use a LARGE container's memory, since Node's
|
|
54
|
+
* derived default is a fraction of the limit — which is what {@link DRIVER_HEAP_ENV}
|
|
55
|
+
* is for. An operator who states a number has decided, so it wins in a
|
|
56
|
+
* container too.
|
|
57
|
+
*/
|
|
58
|
+
export function driverHeapArgs(reading: HeapReading = {}): string[] {
|
|
59
|
+
return heapCeilingArgs({
|
|
60
|
+
desktopDefaultMb: DRIVER_HEAP_MB,
|
|
61
|
+
envValue: process.env[DRIVER_HEAP_ENV],
|
|
62
|
+
minMb: MIN_DRIVER_HEAP_MB,
|
|
63
|
+
...reading
|
|
64
|
+
});
|
|
65
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
+
export * from './commands/create.js';
|
|
11
|
+
export * from './commands/delete.js';
|
|
10
12
|
export * from './commands/generate-ast-builder.js';
|
|
11
13
|
export * from './commands/generate-transfer-model.js';
|
|
12
14
|
export * from './commands/projects.js';
|
package/src/log-level.ts
CHANGED
|
@@ -7,29 +7,47 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_LOG_FILE_ENV,
|
|
12
|
+
DEFAULT_LOG_FILE_LEVEL_ENV,
|
|
13
|
+
DEFAULT_LOG_LEVEL_ENV,
|
|
14
|
+
LEVEL_ORDER,
|
|
15
|
+
parseLogLevel,
|
|
16
|
+
type LogThreshold
|
|
17
|
+
} from '@hydranium/protocol';
|
|
18
|
+
|
|
19
|
+
/** The log flags every subcommand takes, as the env {@link logEnv} hands its child. */
|
|
20
|
+
export interface LogOptions {
|
|
21
|
+
/** Threshold for the client sink; the server's log-level setting replaces it. */
|
|
22
|
+
readonly logLevel?: LogThreshold;
|
|
23
|
+
/** File the server tees its log to; `{workspace}` expands once it is known, `{pid}` from the start. */
|
|
24
|
+
readonly logFile?: string;
|
|
25
|
+
/** The file's own threshold, which the log-level setting does not change. */
|
|
26
|
+
readonly logFileLevel?: LogThreshold;
|
|
27
|
+
}
|
|
11
28
|
|
|
12
29
|
/**
|
|
13
|
-
* Validate a raw `--log-level` argument into a
|
|
14
|
-
* an unrecognised value so the CLI's top-level
|
|
15
|
-
* and exits non-zero (mirroring how the other
|
|
16
|
-
* for the argv-supplied value; the resolved
|
|
17
|
-
* {@link
|
|
30
|
+
* Validate a raw `--log-level` / `--log-file-level` argument into a
|
|
31
|
+
* {@link LogThreshold}. Throws on an unrecognised value so the CLI's top-level
|
|
32
|
+
* `catch` surfaces a clean error and exits non-zero (mirroring how the other
|
|
33
|
+
* option parsers fail fast). Use for the argv-supplied value; the resolved
|
|
34
|
+
* threshold is handed to {@link logEnv} to target the spawned server.
|
|
18
35
|
*/
|
|
19
|
-
export function parseLogLevelOption(raw: string): LogThreshold {
|
|
36
|
+
export function parseLogLevelOption(raw: string, flag = '--log-level'): LogThreshold {
|
|
20
37
|
const level = parseLogLevel(raw);
|
|
21
38
|
if (!level) {
|
|
22
|
-
throw new Error(`Invalid
|
|
39
|
+
throw new Error(`Invalid ${flag}: ${raw} (expected one of: ${Object.keys(LEVEL_ORDER).join(', ')})`);
|
|
23
40
|
}
|
|
24
41
|
return level;
|
|
25
42
|
}
|
|
26
43
|
|
|
27
44
|
/**
|
|
28
45
|
* Build the environment override that targets *only the spawned server's* log
|
|
29
|
-
*
|
|
30
|
-
* `
|
|
31
|
-
*
|
|
32
|
-
*
|
|
46
|
+
* configuration, or `undefined` when no log flag was given. Passed to
|
|
47
|
+
* `spawnDataServer` as `env`, it sets the same `HYDRANIUM_LOG_LEVEL` /
|
|
48
|
+
* `HYDRANIUM_LOG_FILE` / `HYDRANIUM_LOG_FILE_LEVEL` variables the server reads
|
|
49
|
+
* at startup — the CLI's own logging is unaffected, unlike ambient variables
|
|
50
|
+
* that the child would inherit alongside the parent. The server owns *how* log level
|
|
33
51
|
* works; this only routes the CLI's request onto the channel it already reads.
|
|
34
52
|
*
|
|
35
53
|
* **The variable is read by `LspLogger`'s constructor**, which is bound on the
|
|
@@ -44,6 +62,16 @@ export function parseLogLevelOption(raw: string): LogThreshold {
|
|
|
44
62
|
* not go to stdout: that is the JSON-RPC channel, so a log line there would
|
|
45
63
|
* corrupt the very request this flag was set to diagnose.
|
|
46
64
|
*/
|
|
47
|
-
export function
|
|
48
|
-
|
|
65
|
+
export function logEnv(options: LogOptions): Record<string, string> | undefined {
|
|
66
|
+
const env: Record<string, string> = {};
|
|
67
|
+
if (options.logLevel !== undefined) {
|
|
68
|
+
env[DEFAULT_LOG_LEVEL_ENV] = options.logLevel;
|
|
69
|
+
}
|
|
70
|
+
if (options.logFile !== undefined) {
|
|
71
|
+
env[DEFAULT_LOG_FILE_ENV] = options.logFile;
|
|
72
|
+
}
|
|
73
|
+
if (options.logFileLevel !== undefined) {
|
|
74
|
+
env[DEFAULT_LOG_FILE_LEVEL_ENV] = options.logFileLevel;
|
|
75
|
+
}
|
|
76
|
+
return Object.keys(env).length > 0 ? env : undefined;
|
|
49
77
|
}
|
package/src/spawn-data-server.ts
CHANGED
|
@@ -15,7 +15,14 @@ import {
|
|
|
15
15
|
type DataServerProtocol
|
|
16
16
|
} from '@hydranium/protocol/data';
|
|
17
17
|
import { type ChildProcess, spawn } from 'node:child_process';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
StreamMessageReader,
|
|
20
|
+
StreamMessageWriter,
|
|
21
|
+
createMessageConnection,
|
|
22
|
+
type Logger as ConnectionLogger,
|
|
23
|
+
type MessageConnection
|
|
24
|
+
} from 'vscode-jsonrpc/node';
|
|
25
|
+
import { STDERR_CONNECTION_LOGGER } from './stderr-connection-logger.js';
|
|
19
26
|
|
|
20
27
|
/**
|
|
21
28
|
* Options for {@link spawnDataServer}. `command` is the binary or script
|
|
@@ -49,6 +56,11 @@ export interface SpawnDataServerOptions {
|
|
|
49
56
|
* scripted use; set to `'pipe'` to capture for assertion in tests.
|
|
50
57
|
*/
|
|
51
58
|
readonly stderr?: 'inherit' | 'ignore' | 'pipe';
|
|
59
|
+
/**
|
|
60
|
+
* Where the connection to the child logs its protocol faults, such as a
|
|
61
|
+
* response that matches no request. Default: this process's stderr.
|
|
62
|
+
*/
|
|
63
|
+
readonly logger?: ConnectionLogger;
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
/**
|
|
@@ -143,7 +155,7 @@ export function spawnDataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
143
155
|
|
|
144
156
|
const reader = new StreamMessageReader(child.stdout);
|
|
145
157
|
const writer = new StreamMessageWriter(child.stdin);
|
|
146
|
-
const connection = createMessageConnection(reader, writer);
|
|
158
|
+
const connection = createMessageConnection(reader, writer, options.logger ?? STDERR_CONNECTION_LOGGER);
|
|
147
159
|
// Consume transport error / close so a child that dies mid-stream (its stdout
|
|
148
160
|
// closing, a write landing on a torn-down stdin) is observed here rather than
|
|
149
161
|
// escaping as an unhandled error — the death is reported via `whenTerminated`.
|
|
@@ -224,9 +236,9 @@ export function spawnDataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
224
236
|
* child down afterwards. The `use` call is raced against
|
|
225
237
|
* {@link DataServerHandle.whenTerminated}, so a spawn failure or a premature child
|
|
226
238
|
* exit rejects with a clear message instead of hanging on an RPC that can never be
|
|
227
|
-
* answered. This is the one-shot counterpart the
|
|
228
|
-
*
|
|
229
|
-
*
|
|
239
|
+
* answered. This is the one-shot counterpart the data-server subcommands
|
|
240
|
+
* compose; `watch` races its own long-running loop against `whenTerminated`
|
|
241
|
+
* directly.
|
|
230
242
|
*/
|
|
231
243
|
export async function withDataServer<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic, R>(
|
|
232
244
|
options: SpawnDataServerOptions,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import type { Logger as ConnectionLogger } from 'vscode-jsonrpc/node';
|
|
11
|
+
|
|
12
|
+
/** Every connection line goes to stderr: stdout carries the command's output or the protocol stream. */
|
|
13
|
+
export const STDERR_CONNECTION_LOGGER: ConnectionLogger = {
|
|
14
|
+
error: message => console.error(message),
|
|
15
|
+
warn: message => console.error(message),
|
|
16
|
+
info: message => console.error(message),
|
|
17
|
+
log: message => console.error(message)
|
|
18
|
+
};
|
|
@@ -20,8 +20,10 @@
|
|
|
20
20
|
|
|
21
21
|
import { DataServer } from '@hydranium/data-server';
|
|
22
22
|
import { makeTestServices } from '@hydranium/core/testing';
|
|
23
|
+
import { describeErrorWithStack } from '@hydranium/protocol';
|
|
23
24
|
import type { AstNode, URI } from '@hydranium/langium';
|
|
24
|
-
import { StreamMessageReader, StreamMessageWriter, createMessageConnection } from 'vscode-jsonrpc/node';
|
|
25
|
+
import { StreamMessageReader, StreamMessageWriter, createMessageConnection, type ResponseMessage } from 'vscode-jsonrpc/node';
|
|
26
|
+
import { STDERR_CONNECTION_LOGGER } from '../stderr-connection-logger.js';
|
|
25
27
|
|
|
26
28
|
interface FakeRoot extends AstNode {
|
|
27
29
|
readonly $type: 'FakeRoot';
|
|
@@ -72,7 +74,14 @@ function main(): void {
|
|
|
72
74
|
}
|
|
73
75
|
};
|
|
74
76
|
|
|
75
|
-
const
|
|
77
|
+
const writer = new StreamMessageWriter(process.stdout);
|
|
78
|
+
const connection = createMessageConnection(new StreamMessageReader(process.stdin), writer, STDERR_CONNECTION_LOGGER);
|
|
79
|
+
|
|
80
|
+
if (process.argv.includes('--send-response-without-id')) {
|
|
81
|
+
// A response the parent cannot match to a request, for its connection to log.
|
|
82
|
+
const response: ResponseMessage = { jsonrpc: '2.0', id: null, result: null };
|
|
83
|
+
writer.write(response).catch((error: unknown) => STDERR_CONNECTION_LOGGER.error(describeErrorWithStack(error)));
|
|
84
|
+
}
|
|
76
85
|
|
|
77
86
|
if (process.argv.includes('--exit-on-request')) {
|
|
78
87
|
// Fail-fast fixture mode: read a full request (the reader parses the whole
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// The client side of the __GRAMMAR__ diagram: how each element type the server
|
|
2
|
+
// stamps is drawn. It binds nothing a host owns, so every host mounts this one
|
|
3
|
+
// module and adds its own beside it.
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
angleOfPoint,
|
|
7
|
+
configureModelElement,
|
|
8
|
+
type ContainerConfiguration,
|
|
9
|
+
type GEdge,
|
|
10
|
+
GEdgeView,
|
|
11
|
+
GNode,
|
|
12
|
+
initializeDiagramContainer,
|
|
13
|
+
Point,
|
|
14
|
+
type RenderingContext,
|
|
15
|
+
RoundedCornerNodeView,
|
|
16
|
+
svg,
|
|
17
|
+
toDegrees
|
|
18
|
+
} from '@eclipse-glsp/client';
|
|
19
|
+
import { configureHydraniumModelElements, HydraniumGEdge } from '@hydranium/glsp-client';
|
|
20
|
+
import { type Container, ContainerModule, injectable } from 'inversify';
|
|
21
|
+
import {
|
|
22
|
+
__GRAMMAR_ID_CONST___EDGE_TYPE,
|
|
23
|
+
__GRAMMAR_ID_CONST___EXTERNAL_NODE_TYPE,
|
|
24
|
+
__GRAMMAR_ID_CONST___NODE_TYPE,
|
|
25
|
+
type __GRAMMAR__ElementType
|
|
26
|
+
} from '__PROTOCOL_PACKAGE__';
|
|
27
|
+
|
|
28
|
+
/** GLSP's edge view plus an arrowhead at the target, so an edge reads in the direction of its reference. */
|
|
29
|
+
@injectable()
|
|
30
|
+
export class __GRAMMAR__EdgeView extends GEdgeView {
|
|
31
|
+
protected override renderAdditionals(edge: GEdge, segments: Point[], context: RenderingContext) {
|
|
32
|
+
const end = segments[segments.length - 1];
|
|
33
|
+
const degrees = toDegrees(angleOfPoint(Point.subtract(segments[segments.length - 2], end)));
|
|
34
|
+
const arrow = svg('path', {
|
|
35
|
+
'class-sprotty-edge-arrow': true,
|
|
36
|
+
d: 'M 0,0 L 10,-4 L 10,4 Z',
|
|
37
|
+
transform: `rotate(${degrees} ${end.x} ${end.y}) translate(${end.x} ${end.y})`
|
|
38
|
+
});
|
|
39
|
+
return [...super.renderAdditionals(edge, segments, context), arrow];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The model class and view one element type renders through, as `configureModelElement` takes them. */
|
|
44
|
+
export interface __GRAMMAR__ElementRegistration {
|
|
45
|
+
readonly model: Parameters<typeof configureModelElement>[2];
|
|
46
|
+
readonly view: Parameters<typeof configureModelElement>[3];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* One registration per element type the server stamps.
|
|
51
|
+
*
|
|
52
|
+
* Keyed by the protocol's union of ids, so an id added there does not compile
|
|
53
|
+
* until it is drawn here: sprotty renders a type with no registration as
|
|
54
|
+
* nothing, with only a console warning.
|
|
55
|
+
*/
|
|
56
|
+
export const __GRAMMAR_ID_CONST___ELEMENT_REGISTRATIONS: Readonly<Record<__GRAMMAR__ElementType, __GRAMMAR__ElementRegistration>> = {
|
|
57
|
+
[__GRAMMAR_ID_CONST___NODE_TYPE]: { model: GNode, view: RoundedCornerNodeView },
|
|
58
|
+
// Drawn like a node of the document; the server marks it with the `external` CSS class.
|
|
59
|
+
[__GRAMMAR_ID_CONST___EXTERNAL_NODE_TYPE]: { model: GNode, view: RoundedCornerNodeView },
|
|
60
|
+
// The framework's edge rather than `GEdge`: GLSP's gives the labels of an
|
|
61
|
+
// edge without bendpoints no finite bounds, and fitting the diagram to its
|
|
62
|
+
// pane then blanks the canvas.
|
|
63
|
+
[__GRAMMAR_ID_CONST___EDGE_TYPE]: { model: HydraniumGEdge, view: __GRAMMAR__EdgeView }
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** GLSP's default model elements, plus the registrations above. */
|
|
67
|
+
export const __GRAMMAR_CAMEL__DiagramModule = new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
68
|
+
const context = { bind, unbind, isBound, rebind };
|
|
69
|
+
configureHydraniumModelElements(context);
|
|
70
|
+
for (const [elementTypeId, registration] of Object.entries(__GRAMMAR_ID_CONST___ELEMENT_REGISTRATIONS)) {
|
|
71
|
+
configureModelElement(context, elementTypeId, registration.model, registration.view);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Build a __GRAMMAR__ diagram container: the host's modules first and this
|
|
77
|
+
* diagram's definition last, since GLSP gives an element type to whichever
|
|
78
|
+
* module registered it last.
|
|
79
|
+
*/
|
|
80
|
+
export function initialize__GRAMMAR__DiagramContainer(container: Container, ...modules: ContainerConfiguration) {
|
|
81
|
+
return initializeDiagramContainer(container, ...modules, __GRAMMAR_CAMEL__DiagramModule);
|
|
82
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
charset = utf-8
|
|
5
|
+
end_of_line = lf
|
|
6
|
+
insert_final_newline = true
|
|
7
|
+
trim_trailing_whitespace = true
|
|
8
|
+
indent_style = space
|
|
9
|
+
indent_size = 3
|
|
10
|
+
|
|
11
|
+
[*.{json,yml,yaml}]
|
|
12
|
+
indent_size = 2
|
|
13
|
+
|
|
14
|
+
[*.md]
|
|
15
|
+
trim_trailing_whitespace = false
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node_modules/
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Bundles the page, the worker hosting the heads and, with an editor, Monaco's
|
|
2
|
+
// own worker into `out/`: once with `npm run build`, and on every change,
|
|
3
|
+
// served, with `npm start`.
|
|
4
|
+
//
|
|
5
|
+
// At `platform: 'browser'` esbuild refuses a `node:*` import rather than
|
|
6
|
+
// shimming it, so a Node import anywhere the worker reaches fails here rather
|
|
7
|
+
// than inside a worker with no console attached.
|
|
8
|
+
|
|
9
|
+
import { context } from 'esbuild';
|
|
10
|
+
import { createHash } from 'node:crypto';
|
|
11
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
|
|
15
|
+
const root = fileURLToPath(new URL('.', import.meta.url));
|
|
16
|
+
const workspace = fileURLToPath(new URL('../workspace/', import.meta.url));
|
|
17
|
+
|
|
18
|
+
// The worker's filesystem seed: each file of `../workspace`, keyed by its path
|
|
19
|
+
// below the workspace root. A file saved in the page is kept in IndexedDB and
|
|
20
|
+
// laid over this seed on the next load.
|
|
21
|
+
const seed = Object.fromEntries(
|
|
22
|
+
readdirSync(workspace, { recursive: true, encoding: 'utf8' })
|
|
23
|
+
.filter(path => statSync(join(workspace, path)).isFile())
|
|
24
|
+
.map(path => [path.split('\\').join('/'), readFileSync(join(workspace, path), 'utf8')])
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// Names the worker's IndexedDB database after this directory. Every project
|
|
28
|
+
// served on one port shares an origin, and with it the databases, so a name
|
|
29
|
+
// from the project alone lays one project's saved files over another's seed.
|
|
30
|
+
// Moving the directory starts again from the seed.
|
|
31
|
+
const directoryKey = createHash('sha256').update(root).digest('hex').slice(0, 12);
|
|
32
|
+
|
|
33
|
+
const common = {
|
|
34
|
+
absWorkingDir: root,
|
|
35
|
+
outdir: 'out',
|
|
36
|
+
bundle: true,
|
|
37
|
+
platform: 'browser',
|
|
38
|
+
// Classic scripts: the page loads its bundle with a plain `<script>`, and
|
|
39
|
+
// both workers are classic workers.
|
|
40
|
+
format: 'iife',
|
|
41
|
+
target: 'es2022',
|
|
42
|
+
sourcemap: true,
|
|
43
|
+
// The framework imports bare `path` so that a browser bundle can point it
|
|
44
|
+
// at a shim. Relative to `absWorkingDir`.
|
|
45
|
+
alias: { path: './src/posix-path-shim.ts' },
|
|
46
|
+
define: {
|
|
47
|
+
__WORKSPACE_SEED__: JSON.stringify(seed),
|
|
48
|
+
__DIRECTORY_KEY__: JSON.stringify(directoryKey),
|
|
49
|
+
__WORKER_BUNDLE_URL__: JSON.stringify('./out/worker.js'),
|
|
50
|
+
__MONACO_WORKER_BUNDLE_URL__: JSON.stringify('./out/monaco-editor-worker.js')
|
|
51
|
+
},
|
|
52
|
+
logLevel: 'info'
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Monaco's own worker, on a page with an editor: `init` emits its source only
|
|
56
|
+
// with the LSP head.
|
|
57
|
+
const monacoEntry = 'src/monaco-editor-worker.ts';
|
|
58
|
+
const monacoWorker = existsSync(join(root, monacoEntry)) ? { 'monaco-editor-worker': monacoEntry } : {};
|
|
59
|
+
|
|
60
|
+
const builds = await Promise.all([
|
|
61
|
+
context({
|
|
62
|
+
...common,
|
|
63
|
+
entryPoints: { page: 'src/page.ts' },
|
|
64
|
+
// The icon font Monaco and GLSP import, inlined: a `file` loader would
|
|
65
|
+
// rewrite its URL relative to `out/`, which the page one directory up does
|
|
66
|
+
// not resolve. The page's alone, so a diagram client import that reaches
|
|
67
|
+
// the worker fails its bundle.
|
|
68
|
+
loader: { '.ttf': 'dataurl' }
|
|
69
|
+
}),
|
|
70
|
+
context({ ...common, entryPoints: { worker: 'src/worker.ts', ...monacoWorker } })
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
if (process.argv.includes('--serve')) {
|
|
74
|
+
await Promise.all(builds.map(build => build.watch()));
|
|
75
|
+
// On this machine only: the directory served holds the sources and `node_modules`.
|
|
76
|
+
const requested = Number(process.env.PORT || 4937);
|
|
77
|
+
const { port } = await builds[0].serve({ host: 'localhost', servedir: root, port: requested });
|
|
78
|
+
console.log(`Serving http://localhost:${port}`);
|
|
79
|
+
} else {
|
|
80
|
+
await Promise.all(builds.map(build => build.rebuild()));
|
|
81
|
+
await Promise.all(builds.map(build => build.dispose()));
|
|
82
|
+
}
|