@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.
Files changed (252) hide show
  1. package/README.md +79 -205
  2. package/bin/hydranium-cli.js +13 -0
  3. package/heap-analysis/heap/core/load.mjs +2 -2
  4. package/lib/cli-version.js.map +1 -1
  5. package/lib/cli.js +7 -2
  6. package/lib/cli.js.map +1 -1
  7. package/lib/commands/analyze-heap-args.js.map +1 -1
  8. package/lib/commands/analyze-heap.d.ts +3 -0
  9. package/lib/commands/analyze-heap.d.ts.map +1 -1
  10. package/lib/commands/analyze-heap.js +2 -1
  11. package/lib/commands/analyze-heap.js.map +1 -1
  12. package/lib/commands/ast-ground-truth-args.d.ts +3 -2
  13. package/lib/commands/ast-ground-truth-args.d.ts.map +1 -1
  14. package/lib/commands/ast-ground-truth-args.js +11 -9
  15. package/lib/commands/ast-ground-truth-args.js.map +1 -1
  16. package/lib/commands/ast-ground-truth-driver.js +2 -1
  17. package/lib/commands/ast-ground-truth-driver.js.map +1 -1
  18. package/lib/commands/ast-ground-truth.js +1 -1
  19. package/lib/commands/ast-ground-truth.js.map +1 -1
  20. package/lib/commands/client-session.d.ts +17 -0
  21. package/lib/commands/client-session.d.ts.map +1 -0
  22. package/lib/commands/client-session.js +27 -0
  23. package/lib/commands/client-session.js.map +1 -0
  24. package/lib/commands/create-args.d.ts +17 -0
  25. package/lib/commands/create-args.d.ts.map +1 -0
  26. package/lib/commands/create-args.js +53 -0
  27. package/lib/commands/create-args.js.map +1 -0
  28. package/lib/commands/create.d.ts +38 -0
  29. package/lib/commands/create.d.ts.map +1 -0
  30. package/lib/commands/create.js +43 -0
  31. package/lib/commands/create.js.map +1 -0
  32. package/lib/commands/delete-args.d.ts +17 -0
  33. package/lib/commands/delete-args.d.ts.map +1 -0
  34. package/lib/commands/delete-args.js +49 -0
  35. package/lib/commands/delete-args.js.map +1 -0
  36. package/lib/commands/delete.d.ts +30 -0
  37. package/lib/commands/delete.d.ts.map +1 -0
  38. package/lib/commands/delete.js +32 -0
  39. package/lib/commands/delete.js.map +1 -0
  40. package/lib/commands/generate-languages.d.ts +35 -0
  41. package/lib/commands/generate-languages.d.ts.map +1 -0
  42. package/lib/commands/generate-languages.js +105 -0
  43. package/lib/commands/generate-languages.js.map +1 -0
  44. package/lib/commands/generate-transfer-model-args.d.ts.map +1 -1
  45. package/lib/commands/generate-transfer-model-args.js +7 -0
  46. package/lib/commands/generate-transfer-model-args.js.map +1 -1
  47. package/lib/commands/generate-transfer-model-config.d.ts.map +1 -1
  48. package/lib/commands/generate-transfer-model-config.js +6 -3
  49. package/lib/commands/generate-transfer-model-config.js.map +1 -1
  50. package/lib/commands/generate-transfer-model.d.ts +15 -1
  51. package/lib/commands/generate-transfer-model.d.ts.map +1 -1
  52. package/lib/commands/generate-transfer-model.js +46 -8
  53. package/lib/commands/generate-transfer-model.js.map +1 -1
  54. package/lib/commands/harness-args.d.ts +44 -42
  55. package/lib/commands/harness-args.d.ts.map +1 -1
  56. package/lib/commands/harness-args.js +109 -27
  57. package/lib/commands/harness-args.js.map +1 -1
  58. package/lib/commands/headless-harness.d.ts +37 -20
  59. package/lib/commands/headless-harness.d.ts.map +1 -1
  60. package/lib/commands/headless-harness.js +68 -17
  61. package/lib/commands/headless-harness.js.map +1 -1
  62. package/lib/commands/init-args.d.ts.map +1 -1
  63. package/lib/commands/init-args.js +32 -27
  64. package/lib/commands/init-args.js.map +1 -1
  65. package/lib/commands/init-prompt.d.ts +3 -3
  66. package/lib/commands/init-prompt.d.ts.map +1 -1
  67. package/lib/commands/init-prompt.js +4 -5
  68. package/lib/commands/init-prompt.js.map +1 -1
  69. package/lib/commands/init-templates.d.ts +18 -14
  70. package/lib/commands/init-templates.d.ts.map +1 -1
  71. package/lib/commands/init-templates.js +732 -677
  72. package/lib/commands/init-templates.js.map +1 -1
  73. package/lib/commands/init-wizard.d.ts.map +1 -1
  74. package/lib/commands/init-wizard.js +17 -27
  75. package/lib/commands/init-wizard.js.map +1 -1
  76. package/lib/commands/init-workspace.d.ts +13 -11
  77. package/lib/commands/init-workspace.d.ts.map +1 -1
  78. package/lib/commands/init-workspace.js +21 -7
  79. package/lib/commands/init-workspace.js.map +1 -1
  80. package/lib/commands/init.d.ts +45 -19
  81. package/lib/commands/init.d.ts.map +1 -1
  82. package/lib/commands/init.js +80 -43
  83. package/lib/commands/init.js.map +1 -1
  84. package/lib/commands/kebab.d.ts +15 -0
  85. package/lib/commands/kebab.d.ts.map +1 -0
  86. package/lib/commands/kebab.js +17 -0
  87. package/lib/commands/kebab.js.map +1 -0
  88. package/lib/commands/lint-grammar-args.d.ts +3 -2
  89. package/lib/commands/lint-grammar-args.d.ts.map +1 -1
  90. package/lib/commands/lint-grammar-args.js +13 -10
  91. package/lib/commands/lint-grammar-args.js.map +1 -1
  92. package/lib/commands/lint-grammar-driver.js +2 -1
  93. package/lib/commands/lint-grammar-driver.js.map +1 -1
  94. package/lib/commands/lint-grammar-report.js.map +1 -1
  95. package/lib/commands/lint-grammar.js +1 -1
  96. package/lib/commands/lint-grammar.js.map +1 -1
  97. package/lib/commands/measure-memory-args.d.ts +3 -2
  98. package/lib/commands/measure-memory-args.d.ts.map +1 -1
  99. package/lib/commands/measure-memory-args.js +22 -11
  100. package/lib/commands/measure-memory-args.js.map +1 -1
  101. package/lib/commands/measure-memory-driver.js +5 -3
  102. package/lib/commands/measure-memory-driver.js.map +1 -1
  103. package/lib/commands/measure-memory.js +1 -1
  104. package/lib/commands/measure-memory.js.map +1 -1
  105. package/lib/commands/model-docs-args.d.ts +4 -3
  106. package/lib/commands/model-docs-args.d.ts.map +1 -1
  107. package/lib/commands/model-docs-args.js +12 -10
  108. package/lib/commands/model-docs-args.js.map +1 -1
  109. package/lib/commands/model-docs-driver.js +2 -1
  110. package/lib/commands/model-docs-driver.js.map +1 -1
  111. package/lib/commands/model-docs.js +1 -1
  112. package/lib/commands/model-docs.js.map +1 -1
  113. package/lib/commands/projects-args.d.ts.map +1 -1
  114. package/lib/commands/projects-args.js +5 -5
  115. package/lib/commands/projects-args.js.map +1 -1
  116. package/lib/commands/projects.d.ts +3 -4
  117. package/lib/commands/projects.d.ts.map +1 -1
  118. package/lib/commands/projects.js +2 -2
  119. package/lib/commands/projects.js.map +1 -1
  120. package/lib/commands/query-args.d.ts.map +1 -1
  121. package/lib/commands/query-args.js +5 -5
  122. package/lib/commands/query-args.js.map +1 -1
  123. package/lib/commands/query.d.ts +3 -4
  124. package/lib/commands/query.d.ts.map +1 -1
  125. package/lib/commands/query.js +2 -2
  126. package/lib/commands/query.js.map +1 -1
  127. package/lib/commands/reflect-args.d.ts +3 -2
  128. package/lib/commands/reflect-args.d.ts.map +1 -1
  129. package/lib/commands/reflect-args.js +13 -10
  130. package/lib/commands/reflect-args.js.map +1 -1
  131. package/lib/commands/reflect-driver.js +2 -1
  132. package/lib/commands/reflect-driver.js.map +1 -1
  133. package/lib/commands/reflect-report.js.map +1 -1
  134. package/lib/commands/reflect.js +1 -1
  135. package/lib/commands/reflect.js.map +1 -1
  136. package/lib/commands/save-args.d.ts.map +1 -1
  137. package/lib/commands/save-args.js +7 -4
  138. package/lib/commands/save-args.js.map +1 -1
  139. package/lib/commands/save.d.ts +8 -4
  140. package/lib/commands/save.d.ts.map +1 -1
  141. package/lib/commands/save.js +12 -23
  142. package/lib/commands/save.js.map +1 -1
  143. package/lib/commands/validate-args.d.ts +3 -2
  144. package/lib/commands/validate-args.d.ts.map +1 -1
  145. package/lib/commands/validate-args.js +13 -10
  146. package/lib/commands/validate-args.js.map +1 -1
  147. package/lib/commands/validate-driver.js +2 -1
  148. package/lib/commands/validate-driver.js.map +1 -1
  149. package/lib/commands/validate-report.js.map +1 -1
  150. package/lib/commands/validate.js +1 -1
  151. package/lib/commands/validate.js.map +1 -1
  152. package/lib/commands/watch-args.d.ts.map +1 -1
  153. package/lib/commands/watch-args.js +6 -4
  154. package/lib/commands/watch-args.js.map +1 -1
  155. package/lib/commands/watch.d.ts +3 -4
  156. package/lib/commands/watch.d.ts.map +1 -1
  157. package/lib/commands/watch.js +20 -2
  158. package/lib/commands/watch.js.map +1 -1
  159. package/lib/driver-heap.d.ts +52 -0
  160. package/lib/driver-heap.d.ts.map +1 -0
  161. package/lib/driver-heap.js +51 -0
  162. package/lib/driver-heap.js.map +1 -0
  163. package/lib/index.d.ts +2 -0
  164. package/lib/index.d.ts.map +1 -1
  165. package/lib/index.js +2 -0
  166. package/lib/index.js.map +1 -1
  167. package/lib/log-level.d.ts +21 -11
  168. package/lib/log-level.d.ts.map +1 -1
  169. package/lib/log-level.js +25 -14
  170. package/lib/log-level.js.map +1 -1
  171. package/lib/spawn-data-server.d.ts +9 -4
  172. package/lib/spawn-data-server.d.ts.map +1 -1
  173. package/lib/spawn-data-server.js +5 -4
  174. package/lib/spawn-data-server.js.map +1 -1
  175. package/lib/stderr-connection-logger.d.ts +12 -0
  176. package/lib/stderr-connection-logger.d.ts.map +1 -0
  177. package/lib/stderr-connection-logger.js +16 -0
  178. package/lib/stderr-connection-logger.js.map +1 -0
  179. package/lib/testing/echo-server.js +9 -1
  180. package/lib/testing/echo-server.js.map +1 -1
  181. package/package.json +52 -39
  182. package/src/cli.ts +7 -2
  183. package/src/commands/analyze-heap.ts +4 -1
  184. package/src/commands/ast-ground-truth-args.ts +15 -12
  185. package/src/commands/ast-ground-truth-driver.ts +2 -1
  186. package/src/commands/ast-ground-truth.ts +1 -1
  187. package/src/commands/client-session.ts +33 -0
  188. package/src/commands/create-args.ts +68 -0
  189. package/src/commands/create.ts +83 -0
  190. package/src/commands/delete-args.ts +64 -0
  191. package/src/commands/delete.ts +61 -0
  192. package/src/commands/generate-languages.ts +132 -0
  193. package/src/commands/generate-transfer-model-args.ts +7 -0
  194. package/src/commands/generate-transfer-model-config.ts +6 -3
  195. package/src/commands/generate-transfer-model.ts +56 -8
  196. package/src/commands/harness-args.ts +99 -31
  197. package/src/commands/headless-harness.ts +86 -26
  198. package/src/commands/init-args.ts +32 -27
  199. package/src/commands/init-prompt.ts +5 -6
  200. package/src/commands/init-templates.ts +790 -696
  201. package/src/commands/init-wizard.ts +17 -27
  202. package/src/commands/init-workspace.ts +31 -16
  203. package/src/commands/init.ts +126 -58
  204. package/src/commands/kebab.ts +17 -0
  205. package/src/commands/lint-grammar-args.ts +17 -13
  206. package/src/commands/lint-grammar-driver.ts +2 -1
  207. package/src/commands/lint-grammar.ts +1 -1
  208. package/src/commands/measure-memory-args.ts +27 -14
  209. package/src/commands/measure-memory-driver.ts +5 -3
  210. package/src/commands/measure-memory.ts +1 -1
  211. package/src/commands/model-docs-args.ts +16 -13
  212. package/src/commands/model-docs-driver.ts +2 -1
  213. package/src/commands/model-docs.ts +1 -1
  214. package/src/commands/projects-args.ts +5 -4
  215. package/src/commands/projects.ts +4 -6
  216. package/src/commands/query-args.ts +5 -4
  217. package/src/commands/query.ts +4 -6
  218. package/src/commands/reflect-args.ts +17 -13
  219. package/src/commands/reflect-driver.ts +2 -1
  220. package/src/commands/reflect.ts +1 -1
  221. package/src/commands/save-args.ts +7 -3
  222. package/src/commands/save.ts +24 -27
  223. package/src/commands/validate-args.ts +17 -13
  224. package/src/commands/validate-driver.ts +2 -1
  225. package/src/commands/validate.ts +1 -1
  226. package/src/commands/watch-args.ts +6 -3
  227. package/src/commands/watch.ts +28 -7
  228. package/src/driver-heap.ts +65 -0
  229. package/src/index.ts +2 -0
  230. package/src/log-level.ts +42 -14
  231. package/src/spawn-data-server.ts +17 -5
  232. package/src/stderr-connection-logger.ts +18 -0
  233. package/src/testing/echo-server.ts +11 -2
  234. package/templates/gitignore +1 -0
  235. package/templates/protocol/gitignore +3 -0
  236. package/templates/protocol/src/__GRAMMAR_ID__-diagram-types.ts +41 -0
  237. package/templates/server/gitignore +6 -0
  238. package/templates/server/src/glsp/__GRAMMAR_ID__/create-node-operation-handler.ts +62 -0
  239. package/templates/server/src/glsp/__GRAMMAR_ID__/gmodel-factory.ts +60 -0
  240. package/templates/server/src/glsp/__GRAMMAR_ID__/state.ts +18 -0
  241. package/templates/server/src/glsp/__GRAMMAR_ID__/storage.ts +16 -0
  242. package/templates/server/src/glsp/__GRAMMAR_ID__/submission-handler.ts +24 -0
  243. package/templates/server/src/grammar/common.langium +12 -0
  244. package/templates/server/src/language-server/__GRAMMAR_ID__-serializer.ts +53 -0
  245. package/templates/server/src/language-server/ast.ts +23 -0
  246. package/templates/server/src/node/services.ts +16 -0
  247. package/templates/server/test/__GRAMMAR_ID__-diagram.test.ts +112 -0
  248. package/templates/server/test/tsconfig.json +4 -0
  249. package/templates/server/tsconfig.test.json +10 -0
  250. package/templates/server/vitest.config.ts +14 -0
  251. package/templates/workspace/nodes.__EXTENSION__ +5 -0
  252. 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
- LOG_LEVEL_FLAG,
14
- logLevelHelpLine,
15
- logLevelOption,
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, LOG_LEVEL_FLAG] as const;
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. `--services` is consumed
30
- * by the shared harness parser itself, so it is in neither set.
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[] = [SERVICES_FLAG, ...VALUE_FLAGS, ...BOOL_FLAGS];
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[] = [SERVICES_FLAG, ...VALUE_FLAGS];
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
- logLevelHelpLine(22)
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
- logLevel: logLevelOption(options[LOG_LEVEL_FLAG])
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(error instanceof Error ? error.message : String(error));
83
+ console.error(describeError(error));
83
84
  process.exit(1);
84
85
  });
@@ -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(['--max-old-space-size=8192', DRIVER, ...buildValidateDriverArgs(options)], options);
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
- ' --log-level <lvl> Log threshold for the spawned server (off|error|warn|info|debug|trace).'
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
  };
@@ -7,9 +7,14 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
- import type { LogThreshold, TransferElement } from '@hydranium/protocol';
11
- import type { DataClientProtocol, DataServerProtocol, TransferDocumentUpdatedEvent } from '@hydranium/protocol/data';
12
- import { logLevelEnv } from '../log-level.js';
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: options.logLevel ? logLevelEnv(options.logLevel) : undefined
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 { DEFAULT_LOG_LEVEL_ENV, LEVEL_ORDER, parseLogLevel, type LogThreshold } from '@hydranium/protocol';
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 {@link LogThreshold}. Throws on
14
- * an unrecognised value so the CLI's top-level `catch` surfaces a clean error
15
- * and exits non-zero (mirroring how the other option parsers fail fast). Use
16
- * for the argv-supplied value; the resolved threshold is handed to
17
- * {@link logLevelEnv} to target the spawned server.
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 --log-level: ${raw} (expected one of: ${Object.keys(LEVEL_ORDER).join(', ')})`);
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
- * threshold. Passed to `spawnDataServer` as `env`, it sets the same
30
- * `HYDRANIUM_LOG_LEVEL` variable the server reads at startup — the CLI's own
31
- * logging is unaffected, unlike an ambient `HYDRANIUM_LOG_LEVEL=…` that the
32
- * child would inherit alongside the parent. The server owns *how* log level
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 logLevelEnv(level: LogThreshold): Record<string, string> {
48
- return { [DEFAULT_LOG_LEVEL_ENV]: level };
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
  }
@@ -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 { StreamMessageReader, StreamMessageWriter, createMessageConnection, type MessageConnection } from 'vscode-jsonrpc/node';
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 `projects` / `query` / `save`
228
- * subcommands compose; `watch` races its own long-running loop against
229
- * `whenTerminated` directly.
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 connection = createMessageConnection(new StreamMessageReader(process.stdin), new StreamMessageWriter(process.stdout));
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,3 @@
1
+ node_modules/
2
+ lib/
3
+ *.tsbuildinfo
@@ -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,6 @@
1
+ node_modules/
2
+ lib/
3
+ *.tsbuildinfo
4
+
5
+ # Langium-generated TextMate grammar (rewritten by every `langium generate`).
6
+ syntaxes/
@@ -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
+ }