@hydranium/cli 1.0.0-next.31 → 1.0.0-next.312
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 +79 -205
- package/bin/hydranium-cli.js +13 -0
- package/heap-analysis/heap/core/load.mjs +2 -2
- 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.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 +2 -1
- 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-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-model-args.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model-args.js +7 -0
- 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 +6 -3
- package/lib/commands/generate-transfer-model-config.js.map +1 -1
- package/lib/commands/generate-transfer-model.d.ts +15 -1
- package/lib/commands/generate-transfer-model.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model.js +46 -8
- package/lib/commands/generate-transfer-model.js.map +1 -1
- 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 +68 -17
- package/lib/commands/headless-harness.js.map +1 -1
- package/lib/commands/init-args.d.ts.map +1 -1
- package/lib/commands/init-args.js +32 -27
- package/lib/commands/init-args.js.map +1 -1
- 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 +18 -14
- package/lib/commands/init-templates.d.ts.map +1 -1
- package/lib/commands/init-templates.js +732 -677
- package/lib/commands/init-templates.js.map +1 -1
- package/lib/commands/init-wizard.d.ts.map +1 -1
- package/lib/commands/init-wizard.js +17 -27
- 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 +45 -19
- package/lib/commands/init.d.ts.map +1 -1
- package/lib/commands/init.js +80 -43
- 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 +5 -5
- package/lib/commands/query-args.js.map +1 -1
- package/lib/commands/query.d.ts +3 -4
- package/lib/commands/query.d.ts.map +1 -1
- package/lib/commands/query.js +2 -2
- package/lib/commands/query.js.map +1 -1
- package/lib/commands/reflect-args.d.ts +3 -2
- package/lib/commands/reflect-args.d.ts.map +1 -1
- package/lib/commands/reflect-args.js +13 -10
- package/lib/commands/reflect-args.js.map +1 -1
- package/lib/commands/reflect-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 +20 -2
- package/lib/commands/watch.js.map +1 -1
- package/lib/driver-heap.d.ts +52 -0
- package/lib/driver-heap.d.ts.map +1 -0
- package/lib/driver-heap.js +51 -0
- package/lib/driver-heap.js.map +1 -0
- package/lib/index.d.ts +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 +52 -39
- package/src/cli.ts +7 -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 +2 -1
- 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-languages.ts +132 -0
- package/src/commands/generate-transfer-model-args.ts +7 -0
- package/src/commands/generate-transfer-model-config.ts +6 -3
- package/src/commands/generate-transfer-model.ts +56 -8
- package/src/commands/harness-args.ts +99 -31
- package/src/commands/headless-harness.ts +86 -26
- package/src/commands/init-args.ts +32 -27
- package/src/commands/init-prompt.ts +5 -6
- package/src/commands/init-templates.ts +790 -696
- package/src/commands/init-wizard.ts +17 -27
- package/src/commands/init-workspace.ts +31 -16
- package/src/commands/init.ts +126 -58
- 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 +5 -4
- package/src/commands/query.ts +4 -6
- 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 +28 -7
- 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/gitignore +1 -0
- package/templates/protocol/gitignore +3 -0
- package/templates/protocol/src/__GRAMMAR_ID__-diagram-types.ts +41 -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__/gmodel-factory.ts +60 -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/ast.ts +23 -0
- package/templates/server/src/node/services.ts +16 -0
- package/templates/server/test/__GRAMMAR_ID__-diagram.test.ts +112 -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/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,9 +7,14 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
12
|
-
|
|
10
|
+
import type { TransferElement } from '@hydranium/protocol';
|
|
11
|
+
import type {
|
|
12
|
+
DataClientProtocol,
|
|
13
|
+
DataServerProtocol,
|
|
14
|
+
TransferDocumentDeletedEvent,
|
|
15
|
+
TransferDocumentUpdatedEvent
|
|
16
|
+
} from '@hydranium/protocol/data';
|
|
17
|
+
import { logEnv, type LogOptions } from '../log-level.js';
|
|
13
18
|
import { spawnDataServer } from '../spawn-data-server.js';
|
|
14
19
|
|
|
15
20
|
/**
|
|
@@ -22,12 +27,10 @@ import { spawnDataServer } from '../spawn-data-server.js';
|
|
|
22
27
|
* — production CLI wires SIGINT directly. `__handleForTest` bypasses
|
|
23
28
|
* the spawn step for unit tests.
|
|
24
29
|
*/
|
|
25
|
-
export interface WatchCommandOptions {
|
|
30
|
+
export interface WatchCommandOptions extends LogOptions {
|
|
26
31
|
readonly serverCommand: string;
|
|
27
32
|
readonly serverArgs?: readonly string[];
|
|
28
33
|
readonly cwd?: string;
|
|
29
|
-
/** Log threshold for the spawned server, set on its `HYDRANIUM_LOG_LEVEL` env. */
|
|
30
|
-
readonly logLevel?: LogThreshold;
|
|
31
34
|
readonly uri: string;
|
|
32
35
|
readonly clientId?: string;
|
|
33
36
|
readonly write?: (line: string) => void;
|
|
@@ -132,6 +135,24 @@ export async function runWatch(options: WatchCommandOptions): Promise<void> {
|
|
|
132
135
|
onDocumentSaved(): void {
|
|
133
136
|
// Persistence is out of band for the per-URI update view.
|
|
134
137
|
},
|
|
138
|
+
onDocumentDirtyChanged(): void {
|
|
139
|
+
// Out of band for the per-URI update view, as persistence is.
|
|
140
|
+
},
|
|
141
|
+
onDocumentDeleted(event: TransferDocumentDeletedEvent): void {
|
|
142
|
+
// In band, unlike the two neighbours: this is the end of the stream
|
|
143
|
+
// the view exists to show, and a consumer that never hears it waits
|
|
144
|
+
// forever for an update that cannot come. The line carries no
|
|
145
|
+
// `document`, so a reader must switch on shape rather than assume one.
|
|
146
|
+
if (event.uri !== options.uri) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
write(`${JSON.stringify(event)}\n`);
|
|
150
|
+
},
|
|
151
|
+
onDocumentsBuilt(): void {
|
|
152
|
+
// Out of band for a per-URI view by construction: this notification
|
|
153
|
+
// carries only documents nobody watches, and this command watches the
|
|
154
|
+
// one URI it was given.
|
|
155
|
+
},
|
|
135
156
|
onProjectsChanged(): void {
|
|
136
157
|
// Project lifecycle is out of band for the per-URI update view.
|
|
137
158
|
}
|
|
@@ -146,7 +167,7 @@ export async function runWatch(options: WatchCommandOptions): Promise<void> {
|
|
|
146
167
|
command: options.serverCommand,
|
|
147
168
|
args: options.serverArgs,
|
|
148
169
|
cwd: options.cwd,
|
|
149
|
-
env:
|
|
170
|
+
env: logEnv(options)
|
|
150
171
|
},
|
|
151
172
|
localClient
|
|
152
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 @@
|
|
|
1
|
+
node_modules/
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// GLSP diagram-type and element-type ids for the __GRAMMAR__ diagram, which the
|
|
2
|
+
// server stamps onto the graph and every client registers.
|
|
3
|
+
//
|
|
4
|
+
// Declared once, here, for both ends. A drift between them fails silently:
|
|
5
|
+
// sprotty's registries are exact-key maps with no prefix fallback, so an id the
|
|
6
|
+
// client does not know yields an element with none of a node's features,
|
|
7
|
+
// rendered by `MissingView` with only a `no registered view for type '…'`
|
|
8
|
+
// console warning. Nothing fails server-side.
|
|
9
|
+
//
|
|
10
|
+
// The ids stay namespaced under the GLSP defaults (`node:` / `edge:`) so a
|
|
11
|
+
// reader can tell a node id from an edge id at a glance.
|
|
12
|
+
|
|
13
|
+
import { DefaultTypes } from '@eclipse-glsp/protocol';
|
|
14
|
+
import { __GRAMMAR_ID_CONST___LANGUAGE } from './generated-hydranium/languages.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The GLSP diagram type — the string GLSP routes every per-diagram-type request
|
|
18
|
+
* by. A mismatch silently DROPS the request rather than reporting an unknown
|
|
19
|
+
* diagram type. Read from the language id, so renaming the language renames
|
|
20
|
+
* the diagram type at the next `generate`.
|
|
21
|
+
*/
|
|
22
|
+
export const __GRAMMAR_ID_CONST___DIAGRAM_TYPE = __GRAMMAR_ID_CONST___LANGUAGE.languageId;
|
|
23
|
+
|
|
24
|
+
/** A `__NODE_RULE__` — the starter grammar's one named, referenceable node. */
|
|
25
|
+
export const __GRAMMAR_ID_CONST___NODE_TYPE = `${DefaultTypes.NODE}:__GRAMMAR_ID__-node`;
|
|
26
|
+
|
|
27
|
+
/** A resolved `target` reference, drawn as a connection between two nodes. */
|
|
28
|
+
export const __GRAMMAR_ID_CONST___EDGE_TYPE = `${DefaultTypes.EDGE}:__GRAMMAR_ID__-target`;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Every element type id the server stamps.
|
|
32
|
+
*
|
|
33
|
+
* A tuple, so {@link __GRAMMAR__ElementType} is a union of the ids rather than
|
|
34
|
+
* `string`: a client table keyed by that union does not compile while an id
|
|
35
|
+
* lacks its registration. Nothing holds the tuple to the constants above, so
|
|
36
|
+
* an id declared without joining it escapes that check.
|
|
37
|
+
*/
|
|
38
|
+
export const __GRAMMAR_ID_CONST___ELEMENT_TYPES = [__GRAMMAR_ID_CONST___NODE_TYPE, __GRAMMAR_ID_CONST___EDGE_TYPE] as const;
|
|
39
|
+
|
|
40
|
+
/** One of the element type ids in {@link __GRAMMAR_ID_CONST___ELEMENT_TYPES}. */
|
|
41
|
+
export type __GRAMMAR__ElementType = (typeof __GRAMMAR_ID_CONST___ELEMENT_TYPES)[number];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// The starter operation handler for the __GRAMMAR__ diagram: the tool-palette
|
|
2
|
+
// entry that creates a `__NODE_RULE__`.
|
|
3
|
+
//
|
|
4
|
+
// **Deleting this file and its `configureOperationHandlers` registration in
|
|
5
|
+
// `diagram-module.ts` gives a read-only viewer**, and nothing else has to change
|
|
6
|
+
// — creation is offered through the palette rather than through a type hint, so
|
|
7
|
+
// every hint in `diagram-configuration.ts` is already `false`. The scaffold emits
|
|
8
|
+
// the editable direction because that asymmetry runs one way: editable →
|
|
9
|
+
// read-only is a deletion the compiler checks, while read-only → editable is
|
|
10
|
+
// authoring against a seam you have not used yet.
|
|
11
|
+
//
|
|
12
|
+
// **It edits the operation's working copy.** A handler runs inside an operation,
|
|
13
|
+
// where `sourceRoot` is a copy of the built root: the recording command's
|
|
14
|
+
// runnable appends to the copy, and the operation writes the copy's text through
|
|
15
|
+
// the grammar's `Serializer` once, gated on the version the copy was made at,
|
|
16
|
+
// with undo and redo applying that one change. A command that writes the
|
|
17
|
+
// document itself instead reads no text off the copy, which has no `$document`,
|
|
18
|
+
// and the operation's own write then overwrites it.
|
|
19
|
+
//
|
|
20
|
+
// **The drop location is discarded.** `needsClientLayout` is `true` and the
|
|
21
|
+
// starter grammar persists no bounds, so there is nowhere to put a coordinate: the
|
|
22
|
+
// node is appended at the end of the document and the client places it.
|
|
23
|
+
//
|
|
24
|
+
// Like protocol's `__GRAMMAR_ID__-diagram-types.ts`, `gmodel-factory.ts` and
|
|
25
|
+
// `diagram-configuration.ts`, this file knows the starter grammar's shape — the
|
|
26
|
+
// `nodes` list and the `__NODE_RULE__` it holds. Replacing the grammar means
|
|
27
|
+
// replacing these four together.
|
|
28
|
+
|
|
29
|
+
import { type Command, type CreateNodeOperation, JsonCreateNodeOperationHandler, type MaybePromise } from '@eclipse-glsp/server';
|
|
30
|
+
import { appendChild } from '@hydranium/core';
|
|
31
|
+
import { HydraniumGlspRecordingCommand } from '@hydranium/glsp-server';
|
|
32
|
+
import { findNextUnique } from '@hydranium/protocol';
|
|
33
|
+
import { __GRAMMAR_ID_CONST___NODE_TYPE } from '__PROTOCOL_PACKAGE__';
|
|
34
|
+
import { injectable } from 'inversify';
|
|
35
|
+
import type { __NODE_RULE__ } from '../../language-server/ast.js';
|
|
36
|
+
import type { __GRAMMAR__GlspState } from './state.js';
|
|
37
|
+
|
|
38
|
+
/** Proposed name for a new node, uniquified against the ones the document already has. */
|
|
39
|
+
const NODE_NAME_STEM = 'Node';
|
|
40
|
+
|
|
41
|
+
@injectable()
|
|
42
|
+
export class __GRAMMAR__CreateNodeOperationHandler extends JsonCreateNodeOperationHandler {
|
|
43
|
+
declare protected modelState: __GRAMMAR__GlspState;
|
|
44
|
+
|
|
45
|
+
/** The palette's word for the thing it creates, so a noun rather than an action. */
|
|
46
|
+
override readonly label = '__NODE_RULE__';
|
|
47
|
+
elementTypeIds = [__GRAMMAR_ID_CONST___NODE_TYPE];
|
|
48
|
+
|
|
49
|
+
override createCommand(operation: CreateNodeOperation): MaybePromise<Command | undefined> {
|
|
50
|
+
if (!this.elementTypeIds.includes(operation.elementTypeId)) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
return new HydraniumGlspRecordingCommand(this.modelState, this.label, () => {
|
|
54
|
+
const root = this.modelState.sourceRoot;
|
|
55
|
+
const name = findNextUnique(
|
|
56
|
+
NODE_NAME_STEM,
|
|
57
|
+
root.nodes.map(node => node.name)
|
|
58
|
+
);
|
|
59
|
+
appendChild(root, 'nodes', root.nodes, { $type: '__NODE_RULE__', name } as __NODE_RULE__);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// AST → GModel for the __GRAMMAR__ diagram: one node per `__NODE_RULE__`, one
|
|
2
|
+
// edge per resolved `target` reference.
|
|
3
|
+
//
|
|
4
|
+
// Ids come from the index rather than being composed here, so the id strategy
|
|
5
|
+
// stays in one place. Nodes are emitted before edges, because a GLSP edge
|
|
6
|
+
// pointing at an id that does not exist fails client-side with a far less
|
|
7
|
+
// obvious error than a missing edge. An unresolved reference is SKIPPED rather
|
|
8
|
+
// than treated as an error: a dangling reference is ordinary editing state, and
|
|
9
|
+
// the language already reports it as a diagnostic. A reference into another
|
|
10
|
+
// document is skipped for the same reason: the graph holds only this
|
|
11
|
+
// document's nodes, so its target has no id here.
|
|
12
|
+
|
|
13
|
+
import { DefaultTypes, GEdge, GGraph, GLabel, type GModelFactory, GNode, ModelState } from '@eclipse-glsp/server';
|
|
14
|
+
import { AstUtils } from '@hydranium/langium';
|
|
15
|
+
import { __GRAMMAR_ID_CONST___EDGE_TYPE, __GRAMMAR_ID_CONST___NODE_TYPE } from '__PROTOCOL_PACKAGE__';
|
|
16
|
+
import { inject, injectable } from 'inversify';
|
|
17
|
+
import type { __ENTRY_RULE__ } from '../../language-server/ast.js';
|
|
18
|
+
import type { __GRAMMAR__GlspState } from './state.js';
|
|
19
|
+
|
|
20
|
+
@injectable()
|
|
21
|
+
export class __GRAMMAR__GModelFactory implements GModelFactory {
|
|
22
|
+
@inject(ModelState) protected readonly modelState!: __GRAMMAR__GlspState;
|
|
23
|
+
|
|
24
|
+
createModel(): void {
|
|
25
|
+
const root = this.modelState.sourceRoot;
|
|
26
|
+
const graph = GGraph.builder().id(this.modelState.sourceUri).build();
|
|
27
|
+
if (root) {
|
|
28
|
+
this.buildGraph(root, graph);
|
|
29
|
+
}
|
|
30
|
+
this.modelState.updateRoot(graph);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
protected buildGraph(root: __ENTRY_RULE__, graph: GGraph): void {
|
|
34
|
+
for (const node of root.nodes) {
|
|
35
|
+
const id = this.modelState.index.createId(node);
|
|
36
|
+
graph.children.push(
|
|
37
|
+
GNode.builder()
|
|
38
|
+
.id(id)
|
|
39
|
+
.type(__GRAMMAR_ID_CONST___NODE_TYPE)
|
|
40
|
+
.add(GLabel.builder().id(`${id}_name`).text(node.name).type(DefaultTypes.LABEL).build())
|
|
41
|
+
.build()
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
for (const node of root.nodes) {
|
|
45
|
+
const target = node.target?.ref;
|
|
46
|
+
if (!target || AstUtils.findRootNode(target) !== root) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const sourceId = this.modelState.index.createId(node);
|
|
50
|
+
graph.children.push(
|
|
51
|
+
GEdge.builder()
|
|
52
|
+
.id(`${sourceId}_target`)
|
|
53
|
+
.type(__GRAMMAR_ID_CONST___EDGE_TYPE)
|
|
54
|
+
.sourceId(sourceId)
|
|
55
|
+
.targetId(this.modelState.index.createId(target))
|
|
56
|
+
.build()
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|