@hydranium/core 1.0.0-next.12 → 1.0.0-next.127

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 (482) hide show
  1. package/README.md +5 -1
  2. package/lib/documents/ast-document-manager.d.ts +92 -19
  3. package/lib/documents/ast-document-manager.d.ts.map +1 -1
  4. package/lib/documents/ast-document-manager.js +114 -26
  5. package/lib/documents/ast-document-manager.js.map +1 -1
  6. package/lib/documents/client-ids.d.ts +5 -19
  7. package/lib/documents/client-ids.d.ts.map +1 -1
  8. package/lib/documents/client-ids.js +5 -19
  9. package/lib/documents/client-ids.js.map +1 -1
  10. package/lib/documents/client-session-errors.d.ts +15 -0
  11. package/lib/documents/client-session-errors.d.ts.map +1 -0
  12. package/lib/documents/client-session-errors.js +15 -0
  13. package/lib/documents/client-session-errors.js.map +1 -0
  14. package/lib/documents/client-session-registry.d.ts +138 -0
  15. package/lib/documents/client-session-registry.d.ts.map +1 -0
  16. package/lib/documents/client-session-registry.js +184 -0
  17. package/lib/documents/client-session-registry.js.map +1 -0
  18. package/lib/documents/file-system-task-queue.d.ts +49 -0
  19. package/lib/documents/file-system-task-queue.d.ts.map +1 -0
  20. package/lib/documents/file-system-task-queue.js +34 -0
  21. package/lib/documents/file-system-task-queue.js.map +1 -0
  22. package/lib/documents/hydranium-text-documents.d.ts +386 -57
  23. package/lib/documents/hydranium-text-documents.d.ts.map +1 -1
  24. package/lib/documents/hydranium-text-documents.js +701 -114
  25. package/lib/documents/hydranium-text-documents.js.map +1 -1
  26. package/lib/documents/index.d.ts +3 -0
  27. package/lib/documents/index.d.ts.map +1 -1
  28. package/lib/documents/index.js +3 -0
  29. package/lib/documents/index.js.map +1 -1
  30. package/lib/documents/language-client-text-shadow.d.ts +41 -9
  31. package/lib/documents/language-client-text-shadow.d.ts.map +1 -1
  32. package/lib/documents/language-client-text-shadow.js +56 -11
  33. package/lib/documents/language-client-text-shadow.js.map +1 -1
  34. package/lib/documents/self-save-registry.d.ts +37 -6
  35. package/lib/documents/self-save-registry.d.ts.map +1 -1
  36. package/lib/documents/self-save-registry.js +28 -15
  37. package/lib/documents/self-save-registry.js.map +1 -1
  38. package/lib/index.d.ts +3 -0
  39. package/lib/index.d.ts.map +1 -1
  40. package/lib/index.js +6 -0
  41. package/lib/index.js.map +1 -1
  42. package/lib/langium/ast-extension/ast-node-builder.d.ts +32 -9
  43. package/lib/langium/ast-extension/ast-node-builder.d.ts.map +1 -1
  44. package/lib/langium/ast-extension/ast-node-builder.js +60 -22
  45. package/lib/langium/ast-extension/ast-node-builder.js.map +1 -1
  46. package/lib/langium/bootstrap.d.ts.map +1 -1
  47. package/lib/langium/bootstrap.js +16 -9
  48. package/lib/langium/bootstrap.js.map +1 -1
  49. package/lib/langium/config/configuration-provider.d.ts +81 -0
  50. package/lib/langium/config/configuration-provider.d.ts.map +1 -0
  51. package/lib/langium/config/configuration-provider.js +112 -0
  52. package/lib/langium/config/configuration-provider.js.map +1 -0
  53. package/lib/langium/config/index.d.ts +1 -0
  54. package/lib/langium/config/index.d.ts.map +1 -1
  55. package/lib/langium/config/index.js +1 -0
  56. package/lib/langium/config/index.js.map +1 -1
  57. package/lib/langium/diagnostics/lsp-logger.d.ts +17 -0
  58. package/lib/langium/diagnostics/lsp-logger.d.ts.map +1 -1
  59. package/lib/langium/diagnostics/lsp-logger.js +40 -6
  60. package/lib/langium/diagnostics/lsp-logger.js.map +1 -1
  61. package/lib/langium/document-builder/build-pipeline-integration.d.ts +21 -1
  62. package/lib/langium/document-builder/build-pipeline-integration.d.ts.map +1 -1
  63. package/lib/langium/document-builder/build-pipeline-integration.js +32 -5
  64. package/lib/langium/document-builder/build-pipeline-integration.js.map +1 -1
  65. package/lib/langium/document-builder/build-session.d.ts +93 -0
  66. package/lib/langium/document-builder/build-session.d.ts.map +1 -0
  67. package/lib/langium/document-builder/build-session.js +72 -0
  68. package/lib/langium/document-builder/build-session.js.map +1 -0
  69. package/lib/langium/document-builder/document-builder.d.ts +165 -9
  70. package/lib/langium/document-builder/document-builder.d.ts.map +1 -1
  71. package/lib/langium/document-builder/document-builder.js +313 -13
  72. package/lib/langium/document-builder/document-builder.js.map +1 -1
  73. package/lib/langium/document-builder/index.d.ts +1 -0
  74. package/lib/langium/document-builder/index.d.ts.map +1 -1
  75. package/lib/langium/document-builder/index.js +1 -0
  76. package/lib/langium/document-builder/index.js.map +1 -1
  77. package/lib/langium/integration-services.d.ts +45 -1
  78. package/lib/langium/integration-services.d.ts.map +1 -1
  79. package/lib/langium/integration-services.js +10 -5
  80. package/lib/langium/integration-services.js.map +1 -1
  81. package/lib/langium/integrity/integrity-rule.d.ts +13 -5
  82. package/lib/langium/integrity/integrity-rule.d.ts.map +1 -1
  83. package/lib/langium/integrity/integrity-rule.js.map +1 -1
  84. package/lib/langium/integrity/integrity-service.d.ts +50 -6
  85. package/lib/langium/integrity/integrity-service.d.ts.map +1 -1
  86. package/lib/langium/integrity/integrity-service.js +193 -17
  87. package/lib/langium/integrity/integrity-service.js.map +1 -1
  88. package/lib/langium/keys/containment.d.ts +64 -0
  89. package/lib/langium/keys/containment.d.ts.map +1 -0
  90. package/lib/langium/keys/containment.js +53 -0
  91. package/lib/langium/keys/containment.js.map +1 -0
  92. package/lib/langium/keys/index.d.ts +1 -0
  93. package/lib/langium/keys/index.d.ts.map +1 -1
  94. package/lib/langium/keys/index.js +1 -0
  95. package/lib/langium/keys/index.js.map +1 -1
  96. package/lib/langium/keys/name-based-key-provider.d.ts +4 -0
  97. package/lib/langium/keys/name-based-key-provider.d.ts.map +1 -1
  98. package/lib/langium/keys/name-based-key-provider.js +4 -0
  99. package/lib/langium/keys/name-based-key-provider.js.map +1 -1
  100. package/lib/langium/language-module.d.ts +27 -2
  101. package/lib/langium/language-module.d.ts.map +1 -1
  102. package/lib/langium/language-module.js +16 -2
  103. package/lib/langium/language-module.js.map +1 -1
  104. package/lib/langium/model-service/client-session.d.ts +299 -0
  105. package/lib/langium/model-service/client-session.d.ts.map +1 -0
  106. package/lib/langium/model-service/client-session.js +379 -0
  107. package/lib/langium/model-service/client-session.js.map +1 -0
  108. package/lib/langium/model-service/index.d.ts +1 -0
  109. package/lib/langium/model-service/index.d.ts.map +1 -1
  110. package/lib/langium/model-service/index.js +1 -0
  111. package/lib/langium/model-service/index.js.map +1 -1
  112. package/lib/langium/model-service/model-service.d.ts +226 -162
  113. package/lib/langium/model-service/model-service.d.ts.map +1 -1
  114. package/lib/langium/model-service/model-service.js +203 -309
  115. package/lib/langium/model-service/model-service.js.map +1 -1
  116. package/lib/langium/module.d.ts +95 -16
  117. package/lib/langium/module.d.ts.map +1 -1
  118. package/lib/langium/module.js +30 -12
  119. package/lib/langium/module.js.map +1 -1
  120. package/lib/langium/naming/name-provider.d.ts +25 -4
  121. package/lib/langium/naming/name-provider.d.ts.map +1 -1
  122. package/lib/langium/naming/name-provider.js +2 -1
  123. package/lib/langium/naming/name-provider.js.map +1 -1
  124. package/lib/langium/naming/name-separator-validation.d.ts +23 -0
  125. package/lib/langium/naming/name-separator-validation.d.ts.map +1 -1
  126. package/lib/langium/naming/name-separator-validation.js +30 -1
  127. package/lib/langium/naming/name-separator-validation.js.map +1 -1
  128. package/lib/langium/residency/cst-residency-service.d.ts +31 -11
  129. package/lib/langium/residency/cst-residency-service.d.ts.map +1 -1
  130. package/lib/langium/residency/cst-residency-service.js +13 -56
  131. package/lib/langium/residency/cst-residency-service.js.map +1 -1
  132. package/lib/langium/scope/hydranium-scope-provider.d.ts +48 -13
  133. package/lib/langium/scope/hydranium-scope-provider.d.ts.map +1 -1
  134. package/lib/langium/scope/hydranium-scope-provider.js +56 -20
  135. package/lib/langium/scope/hydranium-scope-provider.js.map +1 -1
  136. package/lib/langium/serialization/abstract-serializer.d.ts +11 -20
  137. package/lib/langium/serialization/abstract-serializer.d.ts.map +1 -1
  138. package/lib/langium/serialization/abstract-serializer.js +12 -21
  139. package/lib/langium/serialization/abstract-serializer.js.map +1 -1
  140. package/lib/langium/service-registry.d.ts +15 -1
  141. package/lib/langium/service-registry.d.ts.map +1 -1
  142. package/lib/langium/service-registry.js +16 -0
  143. package/lib/langium/service-registry.js.map +1 -1
  144. package/lib/langium/shared-services.d.ts +15 -2
  145. package/lib/langium/shared-services.d.ts.map +1 -1
  146. package/lib/langium/shared-services.js.map +1 -1
  147. package/lib/langium/transfer/transfer-encoder.d.ts +60 -17
  148. package/lib/langium/transfer/transfer-encoder.d.ts.map +1 -1
  149. package/lib/langium/transfer/transfer-encoder.js +38 -16
  150. package/lib/langium/transfer/transfer-encoder.js.map +1 -1
  151. package/lib/langium/trivia/comment-preserver.d.ts +423 -0
  152. package/lib/langium/trivia/comment-preserver.d.ts.map +1 -0
  153. package/lib/langium/trivia/comment-preserver.js +906 -0
  154. package/lib/langium/trivia/comment-preserver.js.map +1 -0
  155. package/lib/langium/trivia/document-ending-preserver.d.ts +43 -0
  156. package/lib/langium/trivia/document-ending-preserver.d.ts.map +1 -0
  157. package/lib/langium/trivia/document-ending-preserver.js +48 -0
  158. package/lib/langium/trivia/document-ending-preserver.js.map +1 -0
  159. package/lib/langium/trivia/index.d.ts +14 -0
  160. package/lib/langium/trivia/index.d.ts.map +1 -0
  161. package/lib/langium/trivia/index.js +14 -0
  162. package/lib/langium/trivia/index.js.map +1 -0
  163. package/lib/langium/trivia/trivia-contribution.d.ts +37 -0
  164. package/lib/langium/trivia/trivia-contribution.d.ts.map +1 -0
  165. package/lib/langium/trivia/trivia-contribution.js +10 -0
  166. package/lib/langium/trivia/trivia-contribution.js.map +1 -0
  167. package/lib/langium/trivia/trivia-preserver.d.ts +50 -0
  168. package/lib/langium/trivia/trivia-preserver.d.ts.map +1 -0
  169. package/lib/langium/trivia/trivia-preserver.js +10 -0
  170. package/lib/langium/trivia/trivia-preserver.js.map +1 -0
  171. package/lib/langium/trivia/trivia-service.d.ts +70 -0
  172. package/lib/langium/trivia/trivia-service.d.ts.map +1 -0
  173. package/lib/langium/trivia/trivia-service.js +56 -0
  174. package/lib/langium/trivia/trivia-service.js.map +1 -0
  175. package/lib/langium/update-rewrite/update-rewrite.d.ts +1 -1
  176. package/lib/langium/validation/document-validator.d.ts +294 -10
  177. package/lib/langium/validation/document-validator.d.ts.map +1 -1
  178. package/lib/langium/validation/document-validator.js +448 -5
  179. package/lib/langium/validation/document-validator.js.map +1 -1
  180. package/lib/langium/workspace/document-uri-policy.d.ts +3 -4
  181. package/lib/langium/workspace/document-uri-policy.d.ts.map +1 -1
  182. package/lib/langium/workspace/document-uri-policy.js +3 -4
  183. package/lib/langium/workspace/document-uri-policy.js.map +1 -1
  184. package/lib/langium/workspace/file-system-provider.d.ts +9 -1
  185. package/lib/langium/workspace/file-system-provider.d.ts.map +1 -1
  186. package/lib/langium/workspace/file-system-provider.js +40 -7
  187. package/lib/langium/workspace/file-system-provider.js.map +1 -1
  188. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts +25 -0
  189. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts.map +1 -1
  190. package/lib/langium/workspace/hydranium-langium-document-factory.js +25 -0
  191. package/lib/langium/workspace/hydranium-langium-document-factory.js.map +1 -1
  192. package/lib/langium/workspace/hydranium-workspace-manager.d.ts +21 -1
  193. package/lib/langium/workspace/hydranium-workspace-manager.d.ts.map +1 -1
  194. package/lib/langium/workspace/hydranium-workspace-manager.js +28 -0
  195. package/lib/langium/workspace/hydranium-workspace-manager.js.map +1 -1
  196. package/lib/langium/workspace/in-memory-file-system-provider.d.ts +23 -0
  197. package/lib/langium/workspace/in-memory-file-system-provider.d.ts.map +1 -1
  198. package/lib/langium/workspace/in-memory-file-system-provider.js +55 -9
  199. package/lib/langium/workspace/in-memory-file-system-provider.js.map +1 -1
  200. package/lib/langium/workspace/initialize-workspace.d.ts +31 -2
  201. package/lib/langium/workspace/initialize-workspace.d.ts.map +1 -1
  202. package/lib/langium/workspace/initialize-workspace.js +13 -5
  203. package/lib/langium/workspace/initialize-workspace.js.map +1 -1
  204. package/lib/langium/workspace/langium-documents.d.ts +79 -17
  205. package/lib/langium/workspace/langium-documents.d.ts.map +1 -1
  206. package/lib/langium/workspace/langium-documents.js +83 -28
  207. package/lib/langium/workspace/langium-documents.js.map +1 -1
  208. package/lib/langium/workspace/virtual-document.d.ts +18 -3
  209. package/lib/langium/workspace/virtual-document.d.ts.map +1 -1
  210. package/lib/langium/workspace/virtual-document.js +19 -2
  211. package/lib/langium/workspace/virtual-document.js.map +1 -1
  212. package/lib/langium/workspace/write-lock-scope.d.ts +1 -1
  213. package/lib/langium/workspace/write-lock-scope.js +1 -1
  214. package/lib/locale/index.d.ts +10 -0
  215. package/lib/locale/index.d.ts.map +1 -0
  216. package/lib/locale/index.js +10 -0
  217. package/lib/locale/index.js.map +1 -0
  218. package/lib/locale/server-locale.d.ts +73 -0
  219. package/lib/locale/server-locale.d.ts.map +1 -0
  220. package/lib/locale/server-locale.js +61 -0
  221. package/lib/locale/server-locale.js.map +1 -0
  222. package/lib/lsp/completion/hydranium-completion-provider.d.ts +44 -2
  223. package/lib/lsp/completion/hydranium-completion-provider.d.ts.map +1 -1
  224. package/lib/lsp/completion/hydranium-completion-provider.js +68 -0
  225. package/lib/lsp/completion/hydranium-completion-provider.js.map +1 -1
  226. package/lib/lsp/connection-features.d.ts +23 -0
  227. package/lib/lsp/connection-features.d.ts.map +1 -0
  228. package/lib/lsp/connection-features.js +60 -0
  229. package/lib/lsp/connection-features.js.map +1 -0
  230. package/lib/lsp/diagnostics-connection.d.ts +27 -0
  231. package/lib/lsp/diagnostics-connection.d.ts.map +1 -0
  232. package/lib/lsp/diagnostics-connection.js +53 -0
  233. package/lib/lsp/diagnostics-connection.js.map +1 -0
  234. package/lib/lsp/hydranium-document-update-handler.d.ts +70 -62
  235. package/lib/lsp/hydranium-document-update-handler.d.ts.map +1 -1
  236. package/lib/lsp/hydranium-document-update-handler.js +130 -75
  237. package/lib/lsp/hydranium-document-update-handler.js.map +1 -1
  238. package/lib/lsp/index.d.ts +3 -1
  239. package/lib/lsp/index.d.ts.map +1 -1
  240. package/lib/lsp/index.js +3 -1
  241. package/lib/lsp/index.js.map +1 -1
  242. package/lib/lsp/lsp-latency.d.ts +39 -0
  243. package/lib/lsp/lsp-latency.d.ts.map +1 -0
  244. package/lib/lsp/lsp-latency.js +58 -0
  245. package/lib/lsp/lsp-latency.js.map +1 -0
  246. package/lib/lsp/semantic-token-provider.d.ts +34 -1
  247. package/lib/lsp/semantic-token-provider.d.ts.map +1 -1
  248. package/lib/lsp/semantic-token-provider.js +55 -8
  249. package/lib/lsp/semantic-token-provider.js.map +1 -1
  250. package/lib/lsp/shared-module.d.ts +4 -8
  251. package/lib/lsp/shared-module.d.ts.map +1 -1
  252. package/lib/lsp/shared-module.js.map +1 -1
  253. package/lib/lsp/start-language-server.d.ts +8 -7
  254. package/lib/lsp/start-language-server.d.ts.map +1 -1
  255. package/lib/lsp/start-language-server.js +13 -7
  256. package/lib/lsp/start-language-server.js.map +1 -1
  257. package/lib/messages/carriers.d.ts +54 -0
  258. package/lib/messages/carriers.d.ts.map +1 -0
  259. package/lib/messages/carriers.js +62 -0
  260. package/lib/messages/carriers.js.map +1 -0
  261. package/lib/messages/index.d.ts +25 -0
  262. package/lib/messages/index.d.ts.map +1 -0
  263. package/lib/messages/index.js +25 -0
  264. package/lib/messages/index.js.map +1 -0
  265. package/lib/messages/renderer.d.ts +142 -0
  266. package/lib/messages/renderer.d.ts.map +1 -0
  267. package/lib/messages/renderer.js +165 -0
  268. package/lib/messages/renderer.js.map +1 -0
  269. package/lib/node/heap-ceiling.d.ts +61 -0
  270. package/lib/node/heap-ceiling.d.ts.map +1 -0
  271. package/lib/node/heap-ceiling.js +72 -0
  272. package/lib/node/heap-ceiling.js.map +1 -0
  273. package/lib/node/index.d.ts +1 -0
  274. package/lib/node/index.d.ts.map +1 -1
  275. package/lib/node/index.js +1 -0
  276. package/lib/node/index.js.map +1 -1
  277. package/lib/node/latency-from-env.d.ts +1 -1
  278. package/lib/node/latency-from-env.js +1 -1
  279. package/lib/node/measure-memory.d.ts.map +1 -1
  280. package/lib/node/measure-memory.js +1 -0
  281. package/lib/node/measure-memory.js.map +1 -1
  282. package/lib/node/node-file-system-provider.d.ts +35 -1
  283. package/lib/node/node-file-system-provider.d.ts.map +1 -1
  284. package/lib/node/node-file-system-provider.js +140 -45
  285. package/lib/node/node-file-system-provider.js.map +1 -1
  286. package/lib/node/profile-capture.d.ts +8 -2
  287. package/lib/node/profile-capture.d.ts.map +1 -1
  288. package/lib/node/profile-capture.js.map +1 -1
  289. package/lib/node/profiling-run.d.ts +2 -2
  290. package/lib/node/profiling-run.js +1 -1
  291. package/lib/node/profiling-run.js.map +1 -1
  292. package/lib/node/rename-over-open-readers.d.ts +52 -0
  293. package/lib/node/rename-over-open-readers.d.ts.map +1 -0
  294. package/lib/node/rename-over-open-readers.js +66 -0
  295. package/lib/node/rename-over-open-readers.js.map +1 -0
  296. package/lib/node/socket-launcher.d.ts +16 -1
  297. package/lib/node/socket-launcher.d.ts.map +1 -1
  298. package/lib/node/socket-launcher.js +4 -3
  299. package/lib/node/socket-launcher.js.map +1 -1
  300. package/lib/node/stdio-launcher.d.ts +1 -1
  301. package/lib/node/stdio-launcher.d.ts.map +1 -1
  302. package/lib/node/stdio-launcher.js +1 -1
  303. package/lib/node/stdio-launcher.js.map +1 -1
  304. package/lib/testing/fake-document.d.ts +16 -4
  305. package/lib/testing/fake-document.d.ts.map +1 -1
  306. package/lib/testing/fake-document.js +18 -3
  307. package/lib/testing/fake-document.js.map +1 -1
  308. package/lib/testing/make-noop-shared-services.d.ts +14 -0
  309. package/lib/testing/make-noop-shared-services.d.ts.map +1 -1
  310. package/lib/testing/make-noop-shared-services.js +28 -2
  311. package/lib/testing/make-noop-shared-services.js.map +1 -1
  312. package/lib/testing/make-test-services.d.ts +61 -13
  313. package/lib/testing/make-test-services.d.ts.map +1 -1
  314. package/lib/testing/make-test-services.js +25 -5
  315. package/lib/testing/make-test-services.js.map +1 -1
  316. package/lib/testing/node/index.d.ts +1 -0
  317. package/lib/testing/node/index.d.ts.map +1 -1
  318. package/lib/testing/node/index.js +1 -0
  319. package/lib/testing/node/index.js.map +1 -1
  320. package/lib/testing/node/lsp-harness.d.ts.map +1 -1
  321. package/lib/testing/node/lsp-harness.js +2 -0
  322. package/lib/testing/node/lsp-harness.js.map +1 -1
  323. package/lib/testing/node/lsp-server-connection.d.ts +11 -3
  324. package/lib/testing/node/lsp-server-connection.d.ts.map +1 -1
  325. package/lib/testing/node/lsp-server-connection.js +42 -9
  326. package/lib/testing/node/lsp-server-connection.js.map +1 -1
  327. package/lib/testing/node/scratch-workspace.d.ts.map +1 -1
  328. package/lib/testing/node/scratch-workspace.js +10 -5
  329. package/lib/testing/node/scratch-workspace.js.map +1 -1
  330. package/lib/testing/node/spawned-server.d.ts +14 -0
  331. package/lib/testing/node/spawned-server.d.ts.map +1 -1
  332. package/lib/testing/node/spawned-server.js +33 -1
  333. package/lib/testing/node/spawned-server.js.map +1 -1
  334. package/lib/testing/node/unhandled-rejections.d.ts +20 -0
  335. package/lib/testing/node/unhandled-rejections.d.ts.map +1 -0
  336. package/lib/testing/node/unhandled-rejections.js +32 -0
  337. package/lib/testing/node/unhandled-rejections.js.map +1 -0
  338. package/lib/testing/playwright/flaky-network-proxy.d.ts +76 -0
  339. package/lib/testing/playwright/flaky-network-proxy.d.ts.map +1 -0
  340. package/lib/testing/playwright/flaky-network-proxy.js +164 -0
  341. package/lib/testing/playwright/flaky-network-proxy.js.map +1 -0
  342. package/lib/testing/playwright/index.d.ts +1 -0
  343. package/lib/testing/playwright/index.d.ts.map +1 -1
  344. package/lib/testing/playwright/index.js +1 -0
  345. package/lib/testing/playwright/index.js.map +1 -1
  346. package/lib/testing/playwright/server-log-capture.d.ts +14 -4
  347. package/lib/testing/playwright/server-log-capture.d.ts.map +1 -1
  348. package/lib/testing/playwright/server-log-capture.js +21 -4
  349. package/lib/testing/playwright/server-log-capture.js.map +1 -1
  350. package/lib/testing/playwright/server-log-rename-reporter.d.ts.map +1 -1
  351. package/lib/testing/playwright/server-log-rename-reporter.js +10 -1
  352. package/lib/testing/playwright/server-log-rename-reporter.js.map +1 -1
  353. package/lib/testing/run-update-pipeline.d.ts +4 -4
  354. package/lib/testing/run-update-pipeline.d.ts.map +1 -1
  355. package/lib/testing/stub-ast-document-manager.d.ts +10 -9
  356. package/lib/testing/stub-ast-document-manager.d.ts.map +1 -1
  357. package/lib/testing/stub-ast-document-manager.js +8 -9
  358. package/lib/testing/stub-ast-document-manager.js.map +1 -1
  359. package/lib/testing/stub-document-builder.d.ts +8 -0
  360. package/lib/testing/stub-document-builder.d.ts.map +1 -1
  361. package/lib/testing/stub-document-builder.js +22 -3
  362. package/lib/testing/stub-document-builder.js.map +1 -1
  363. package/lib/testing/stub-hydranium-text-documents.d.ts +22 -7
  364. package/lib/testing/stub-hydranium-text-documents.d.ts.map +1 -1
  365. package/lib/testing/stub-hydranium-text-documents.js +92 -15
  366. package/lib/testing/stub-hydranium-text-documents.js.map +1 -1
  367. package/lib/testing/stub-langium-documents.d.ts +3 -2
  368. package/lib/testing/stub-langium-documents.d.ts.map +1 -1
  369. package/lib/testing/stub-langium-documents.js.map +1 -1
  370. package/lib/testing/stub-model-service.d.ts +7 -6
  371. package/lib/testing/stub-model-service.d.ts.map +1 -1
  372. package/lib/testing/stub-model-service.js +4 -4
  373. package/lib/testing/stub-model-service.js.map +1 -1
  374. package/lib/util/connection-liveness.d.ts +7 -6
  375. package/lib/util/connection-liveness.d.ts.map +1 -1
  376. package/lib/util/connection-liveness.js +35 -14
  377. package/lib/util/connection-liveness.js.map +1 -1
  378. package/package.json +17 -8
  379. package/src/documents/ast-document-manager.ts +195 -45
  380. package/src/documents/client-ids.ts +5 -22
  381. package/src/documents/client-session-errors.ts +22 -0
  382. package/src/documents/client-session-registry.ts +237 -0
  383. package/src/documents/file-system-task-queue.ts +68 -0
  384. package/src/documents/hydranium-text-documents.ts +856 -142
  385. package/src/documents/index.ts +3 -0
  386. package/src/documents/language-client-text-shadow.ts +59 -11
  387. package/src/documents/self-save-registry.ts +52 -13
  388. package/src/index.ts +6 -0
  389. package/src/langium/ast-extension/ast-node-builder.ts +66 -22
  390. package/src/langium/bootstrap.ts +16 -9
  391. package/src/langium/config/configuration-provider.ts +119 -0
  392. package/src/langium/config/index.ts +1 -0
  393. package/src/langium/diagnostics/lsp-logger.ts +41 -6
  394. package/src/langium/document-builder/build-pipeline-integration.ts +50 -5
  395. package/src/langium/document-builder/build-session.ts +87 -0
  396. package/src/langium/document-builder/document-builder.ts +355 -13
  397. package/src/langium/document-builder/index.ts +1 -0
  398. package/src/langium/integration-services.ts +67 -6
  399. package/src/langium/integrity/integrity-rule.ts +13 -5
  400. package/src/langium/integrity/integrity-service.ts +202 -17
  401. package/src/langium/keys/containment.ts +87 -0
  402. package/src/langium/keys/index.ts +1 -0
  403. package/src/langium/keys/name-based-key-provider.ts +4 -0
  404. package/src/langium/language-module.ts +42 -4
  405. package/src/langium/model-service/client-session.ts +581 -0
  406. package/src/langium/model-service/index.ts +1 -0
  407. package/src/langium/model-service/model-service.ts +347 -298
  408. package/src/langium/module.ts +119 -22
  409. package/src/langium/naming/name-provider.ts +27 -5
  410. package/src/langium/naming/name-separator-validation.ts +34 -5
  411. package/src/langium/residency/cst-residency-service.ts +36 -14
  412. package/src/langium/scope/hydranium-scope-provider.ts +60 -22
  413. package/src/langium/serialization/abstract-serializer.ts +13 -32
  414. package/src/langium/service-registry.ts +19 -2
  415. package/src/langium/shared-services.ts +19 -2
  416. package/src/langium/transfer/transfer-encoder.ts +85 -24
  417. package/src/langium/trivia/comment-preserver.ts +1100 -0
  418. package/src/langium/trivia/document-ending-preserver.ts +55 -0
  419. package/src/langium/trivia/index.ts +14 -0
  420. package/src/langium/trivia/trivia-contribution.ts +39 -0
  421. package/src/langium/trivia/trivia-preserver.ts +54 -0
  422. package/src/langium/trivia/trivia-service.ts +99 -0
  423. package/src/langium/update-rewrite/update-rewrite.ts +1 -1
  424. package/src/langium/validation/document-validator.ts +537 -11
  425. package/src/langium/workspace/document-uri-policy.ts +3 -4
  426. package/src/langium/workspace/file-system-provider.ts +48 -8
  427. package/src/langium/workspace/hydranium-langium-document-factory.ts +34 -0
  428. package/src/langium/workspace/hydranium-workspace-manager.ts +30 -1
  429. package/src/langium/workspace/in-memory-file-system-provider.ts +62 -10
  430. package/src/langium/workspace/initialize-workspace.ts +43 -5
  431. package/src/langium/workspace/langium-documents.ts +106 -33
  432. package/src/langium/workspace/virtual-document.ts +21 -3
  433. package/src/langium/workspace/write-lock-scope.ts +1 -1
  434. package/src/locale/index.ts +10 -0
  435. package/src/locale/server-locale.ts +86 -0
  436. package/src/lsp/completion/hydranium-completion-provider.ts +82 -2
  437. package/src/lsp/connection-features.ts +67 -0
  438. package/src/lsp/diagnostics-connection.ts +56 -0
  439. package/src/lsp/hydranium-document-update-handler.ts +159 -79
  440. package/src/lsp/index.ts +3 -1
  441. package/src/lsp/lsp-latency.ts +62 -0
  442. package/src/lsp/semantic-token-provider.ts +74 -7
  443. package/src/lsp/shared-module.ts +4 -8
  444. package/src/lsp/start-language-server.ts +13 -7
  445. package/src/messages/carriers.ts +78 -0
  446. package/src/messages/index.ts +36 -0
  447. package/src/messages/renderer.ts +212 -0
  448. package/src/node/heap-ceiling.ts +108 -0
  449. package/src/node/index.ts +1 -0
  450. package/src/node/latency-from-env.ts +1 -1
  451. package/src/node/measure-memory.ts +1 -0
  452. package/src/node/node-file-system-provider.ts +154 -47
  453. package/src/node/profile-capture.ts +8 -2
  454. package/src/node/profiling-run.ts +3 -3
  455. package/src/node/rename-over-open-readers.ts +78 -0
  456. package/src/node/socket-launcher.ts +19 -4
  457. package/src/node/stdio-launcher.ts +1 -2
  458. package/src/testing/fake-document.ts +24 -5
  459. package/src/testing/make-noop-shared-services.ts +50 -2
  460. package/src/testing/make-test-services.ts +99 -24
  461. package/src/testing/node/index.ts +1 -0
  462. package/src/testing/node/lsp-harness.ts +2 -0
  463. package/src/testing/node/lsp-server-connection.ts +61 -11
  464. package/src/testing/node/scratch-workspace.ts +10 -5
  465. package/src/testing/node/spawned-server.ts +35 -1
  466. package/src/testing/node/unhandled-rejections.ts +31 -0
  467. package/src/testing/playwright/flaky-network-proxy.ts +240 -0
  468. package/src/testing/playwright/index.ts +1 -0
  469. package/src/testing/playwright/server-log-capture.ts +24 -5
  470. package/src/testing/playwright/server-log-rename-reporter.ts +12 -1
  471. package/src/testing/run-update-pipeline.ts +4 -4
  472. package/src/testing/stub-ast-document-manager.ts +18 -31
  473. package/src/testing/stub-document-builder.ts +32 -3
  474. package/src/testing/stub-hydranium-text-documents.ts +127 -22
  475. package/src/testing/stub-langium-documents.ts +3 -2
  476. package/src/testing/stub-model-service.ts +9 -8
  477. package/src/util/connection-liveness.ts +37 -14
  478. package/lib/lsp/instrument-connection.d.ts +0 -36
  479. package/lib/lsp/instrument-connection.d.ts.map +0 -1
  480. package/lib/lsp/instrument-connection.js +0 -62
  481. package/lib/lsp/instrument-connection.js.map +0 -1
  482. package/src/lsp/instrument-connection.ts +0 -66
@@ -31,13 +31,24 @@ const AST_EXTENSION_PHASES: readonly DocumentState[] = [
31
31
  ];
32
32
 
33
33
  /**
34
- * Build phases at which the `BuildPhasePassService` is driven. Same useful
35
- * set as {@link AST_EXTENSION_PHASES}: a pass registered at any other state
36
- * never fires (the listener is not wired), mirroring the AST-extension contract.
34
+ * Build phases at which the `BuildPhasePassService` is driven. A pass
35
+ * registered at any other state never fires (the listener is not wired), and
37
36
  * `runPasses` no-ops at a phase with no registered pass, so wiring the full set
38
37
  * unconditionally costs only an empty-bucket check per phase.
38
+ *
39
+ * `IndexedContent` belongs here and NOT in {@link AST_EXTENSION_PHASES}, so the
40
+ * two cannot be collapsed. Per document it carries nothing `Parsed` does; per
41
+ * BATCH it is the only phase meaning the global index is whole again, which
42
+ * batch work keyed on a complete index has nowhere else to run.
39
43
  */
40
- const BUILD_PHASE_PASS_STATES: readonly DocumentState[] = AST_EXTENSION_PHASES;
44
+ const BUILD_PHASE_PASS_STATES: readonly DocumentState[] = [
45
+ DocumentState.Parsed,
46
+ DocumentState.IndexedContent,
47
+ DocumentState.ComputedScopes,
48
+ DocumentState.Linked,
49
+ DocumentState.IndexedReferences,
50
+ DocumentState.Validated
51
+ ];
41
52
 
42
53
  /**
43
54
  * Default priority of the framework integrity passes. Integrity mutates / cleans
@@ -65,6 +76,19 @@ export interface BuildPipelineIntegrationOptions {
65
76
  readonly integrityPriority?: number;
66
77
  }
67
78
 
79
+ /**
80
+ * The build-pipeline slot. Empty because nothing calls this service — it wires
81
+ * itself in its constructor and every seam it offers is `protected`.
82
+ *
83
+ * Typing the slot by the class instead would stop an adopter's subclass
84
+ * satisfying it, since a class carries its `protected` members into the check
85
+ * and they compare by declaration rather than by shape. The cost of the empty
86
+ * shape is that any non-null value satisfies it, so a mis-bound slot compiles
87
+ * and the framework's phase listeners are then never attached.
88
+ */
89
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- the slot has no public member to name
90
+ export interface BuildPipelineIntegration {}
91
+
68
92
  /**
69
93
  * Wires the framework's build-time features (integrity rules, AST
70
94
  * enrichment) into Langium's document-build pipeline. The single shared
@@ -90,7 +114,7 @@ export interface BuildPipelineIntegrationOptions {
90
114
  * Eagerly constructed (via `DEFAULT_EAGER_SERVICES`) so the listeners are
91
115
  * attached before the first build cycle.
92
116
  */
93
- export class BuildPipelineIntegration {
117
+ export class DefaultBuildPipelineIntegration implements BuildPipelineIntegration {
94
118
  constructor(
95
119
  protected readonly services: ServerSharedServices,
96
120
  options: BuildPipelineIntegrationOptions = {}
@@ -128,6 +152,14 @@ export class BuildPipelineIntegration {
128
152
  );
129
153
  }
130
154
 
155
+ // Per DOCUMENT as well: `reparseAndRelink` re-indexes one document from
156
+ // inside the `Linked` phase and fires no build-phase notification, so a
157
+ // batch-level listener cannot see the AST it replaced.
158
+ builder.onDocumentPhase(
159
+ DocumentState.IndexedContent,
160
+ labelPhaseListener(() => this.clearScopeCaches(), 'BuildPipeline.clearScopeCaches')
161
+ );
162
+
131
163
  // AST enrichment stays per-document (onDocumentPhase) and node-granular —
132
164
  // unchanged by the build-phase-pass registry, which is batch-granular. The
133
165
  // listener calls the `extendAst` seam directly (the document-phase analog of
@@ -174,6 +206,19 @@ export class BuildPipelineIntegration {
174
206
  }
175
207
  }
176
208
 
209
+ /**
210
+ * Drop the cached scopes of every REGISTERED language, not of those owning a
211
+ * document in the batch. The index a scope is built from is
212
+ * workspace-global, so narrowing to the batch with
213
+ * {@link groupDocumentsByLanguage}, the way {@link callIntegrity} does,
214
+ * leaves a cross-grammar reference resolving against a mid-rebuild scope.
215
+ */
216
+ protected clearScopeCaches(): void {
217
+ for (const languageServices of this.services.ServiceRegistry.all) {
218
+ languageServices.references.ScopeProvider.clearScopeCaches();
219
+ }
220
+ }
221
+
177
222
  /** Run AST enrichment for a single document at `phase` via its language service. */
178
223
  protected extendAst(document: LangiumDocument, phase: DocumentState, cancelToken: CancellationToken): void {
179
224
  this.services.ServiceRegistry.getServices(document.uri).ast.AstExtensionService.extendDocument(document, phase, cancelToken);
@@ -0,0 +1,87 @@
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 { type URI } from '@hydranium/langium';
11
+
12
+ /** What a build is about, handed to `HydraniumDocumentBuilder.createBuildSession`. */
13
+ export interface BuildSessionContext {
14
+ /**
15
+ * Which entry point opened the build: `'build'` is the workspace-wide pass
16
+ * (initialization), `'update'` an incremental rebuild. A subclass deriving
17
+ * cascade state skips the work for `'build'`, where every document is in the
18
+ * set already and `shouldRelink` is never consulted.
19
+ */
20
+ readonly kind: 'build' | 'update';
21
+ /** Formatted description of what caused the build — a URI, a count summary. */
22
+ readonly trigger: string;
23
+ /** True when {@link trigger} already states the document count. */
24
+ readonly triggerCountsDocs: boolean;
25
+ /** URIs the build was asked to rebuild, already flattened and canonicalized. */
26
+ readonly changed: readonly URI[];
27
+ /** URIs the build was asked to delete, already expanded by `collectDeletedURIs`. Empty for a `build` call. */
28
+ readonly deleted: readonly URI[];
29
+ }
30
+
31
+ /**
32
+ * One rebuild, treated as a correlated unit.
33
+ *
34
+ * Everything a build phase needs to know about the build it belongs to — what
35
+ * triggered it, when it started, whether it was cancelled, and the log lines it
36
+ * has produced so far. A `HydraniumDocumentBuilder` opens one per `update` /
37
+ * `build` call and holds it for the duration, so a per-phase hook can reach
38
+ * build-wide facts that no per-line formatting hook could.
39
+ *
40
+ * **Identity is the object, not {@link traceId}.** `Tracer.time` short-circuits
41
+ * when its log level is suppressed and never calls `captureId`, so `traceId` is
42
+ * `undefined` on every build in a production configuration that logs above
43
+ * `debug`. A teardown guard keyed on the id would then compare `undefined`
44
+ * against `undefined` and let a preempted build clear its successor's state.
45
+ * Reference equality against `HydraniumDocumentBuilder.activeSession` holds in
46
+ * both configurations, which is why nothing here is keyed on the id.
47
+ *
48
+ * Adopters carrying build-scoped state of their own subclass this and return it
49
+ * from `HydraniumDocumentBuilder.createBuildSession`, narrowing with an
50
+ * `instanceof` where they read it back. That buys them the framework's
51
+ * preemption-correct teardown rather than a second copy of it.
52
+ */
53
+ export class BuildSession {
54
+ /**
55
+ * `Tracer.time` correlation id, so a phase line and the build line share a
56
+ * `#N`. `undefined` until the timer starts, and permanently `undefined` when
57
+ * the timing line is suppressed.
58
+ */
59
+ traceId?: number;
60
+ /** Set when the build ended in `OperationCancelled`, so the successor can tag itself "cancels #N". */
61
+ cancelled = false;
62
+ /** Phase-reached lines produced so far; the first one measures from {@link startMs} rather than from the previous phase. */
63
+ phasesLogged = 0;
64
+ /** Lines held back by {@link detailThresholdMs}; flushed or dropped when the build ends. */
65
+ readonly bufferedLines: string[] = [];
66
+
67
+ constructor(
68
+ /** Millisecond timestamp the build started at, on the same clock as `performance.now()`. */
69
+ readonly startMs: number,
70
+ /** What caused this build — a formatted URI, a count summary, or an adopter label. */
71
+ readonly trigger: string,
72
+ /** True when {@link trigger} already states the document count, so a phase line must not repeat it. */
73
+ readonly triggerCountsDocs: boolean,
74
+ /**
75
+ * Build duration at or above which the buffered lines are emitted; `0`
76
+ * disables buffering entirely. Captured per session so the flush decision
77
+ * uses the same value the buffering decision did, even if the underlying
78
+ * observable changed mid-build.
79
+ */
80
+ readonly detailThresholdMs: number
81
+ ) {}
82
+
83
+ /** True while lines are being held rather than emitted as they are produced. */
84
+ get buffers(): boolean {
85
+ return this.detailThresholdMs > 0;
86
+ }
87
+ }
@@ -9,6 +9,7 @@
9
9
 
10
10
  import { type Clock, type LogThreshold, type MaybeObservableValue, ObservableValue, type Tracer } from '@hydranium/protocol';
11
11
  import {
12
+ type AstNode,
12
13
  type BuildOptions,
13
14
  DefaultDocumentBuilder,
14
15
  type DocumentPhaseListener,
@@ -20,12 +21,17 @@ import {
20
21
  interruptAndCheck,
21
22
  isOperationCancelled
22
23
  } from '@hydranium/langium';
23
- import { CancellationToken, type Diagnostic } from 'vscode-languageserver-protocol';
24
+ // `Diagnostic` as a VALUE: `renderDiagnostics` needs its `getMessageString`
25
+ // namespace helper to read the `string | MarkupContent` union without
26
+ // restating it.
27
+ import { CancellationToken, Diagnostic } from 'vscode-languageserver-protocol';
24
28
  import { type LogNameOptions } from '../diagnostics/logger.js';
29
+ import type { MessageRenderer } from '../../messages/renderer.js';
25
30
  import { CST_REHYDRATION_RESET_STATE, isCstShed } from '../residency/cst-residency-service.js';
26
31
  import { type ExtendedServiceRegistry } from '../service-registry.js';
27
32
  import { type ServerSharedServicesMinimal } from '../shared-services.js';
28
33
  import { type DocumentUriPolicy } from '../workspace/document-uri-policy.js';
34
+ import { BuildSession, type BuildSessionContext } from './build-session.js';
29
35
  import { type LabeledPhaseListener, labelPhaseListener } from './labeled-phase-listener.js';
30
36
 
31
37
  /** Document states a phase-reached line is emitted for by default — every built phase. */
@@ -38,6 +44,20 @@ export const DEFAULT_LOGGED_PHASES: DocumentState[] = [
38
44
  DocumentState.Validated
39
45
  ];
40
46
 
47
+ /**
48
+ * The build reasons the framework stages through
49
+ * {@link HydraniumDocumentBuilder.markNextReason}: the LSP events the update
50
+ * handler dispatches on, and `didClose` for the revert the text store runs
51
+ * after a last close. Exposed so a subclass layering reasons of its own keeps
52
+ * the names the framework emits.
53
+ */
54
+ export const HYDRANIUM_BUILD_REASONS = Object.freeze({
55
+ didOpen: 'didOpen',
56
+ didChangeContent: 'didChangeContent',
57
+ didChangeWatchedFiles: 'didChangeWatchedFiles',
58
+ didClose: 'didClose'
59
+ } as const);
60
+
41
61
  /**
42
62
  * Consecutive re-queued builds that leave a waited-on document at the same state
43
63
  * before {@link HydraniumDocumentBuilder.awaitDocumentState} stops re-queuing it.
@@ -78,6 +98,18 @@ export interface DocumentBuilderOptions extends LogNameOptions {
78
98
  * logged. Default: `25`. Read per phase; accepts a {@link MaybeObservableValue}.
79
99
  */
80
100
  readonly slowBuildMs?: MaybeObservableValue<number>;
101
+ /**
102
+ * Build duration at or above which a build's phase-reached and slow-listener
103
+ * lines are emitted; they are held for the duration of the build and dropped
104
+ * when it finishes faster. Default `0` — no buffering, every line emitted as
105
+ * it is produced, which is the only setting that keeps lines interleaved with
106
+ * the rest of the log in real time.
107
+ *
108
+ * Set it to make a fast rebuild log nothing but its one build line. The
109
+ * decision needs the build's TOTAL duration, so it cannot be made by any
110
+ * per-line hook. Read once per build; accepts a {@link MaybeObservableValue}.
111
+ */
112
+ readonly phaseDetailMs?: MaybeObservableValue<number>;
81
113
  /**
82
114
  * Refresh cross-document `ComputedScopes` derivations when a referencing
83
115
  * document is cascade-rebuilt (see
@@ -105,15 +137,24 @@ export interface DocumentBuilderOptions extends LogNameOptions {
105
137
  * - **In-place rebuild helpers** — {@link reparse} and
106
138
  * {@link reparseAndRelink} — for a build-phase listener that mutated a
107
139
  * document's AST and must reconcile it within the same build.
108
- * - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics}).
140
+ * - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics}), followed
141
+ * by the **one server-side message render** every head inherits
142
+ * ({@link renderDiagnostics}).
143
+ * - **Build sessions** ({@link BuildSession}): each `update` / `build` call is
144
+ * one correlated unit carrying an id, a trigger label, a start time and
145
+ * cancellation lineage, so every line of a rebuild reads as belonging to it
146
+ * and a preempted build is distinguishable from the winner.
109
147
  * - **Logging instrumentation** (default on, opt-out via `logLevel: 'off'`):
110
- * phase-reached lines, slow-listener breakdowns on `notifyDocumentPhase`,
111
- * and slow-build-phase totals on `notifyBuildPhase`.
148
+ * a per-build line, phase-reached lines, slow-listener breakdowns on
149
+ * `notifyDocumentPhase`, and slow-build-phase totals on `notifyBuildPhase`.
112
150
  *
113
151
  * Adopters extend this class — the configuration knobs cover what most
114
152
  * adopters need; the `format*Line` methods, `formatUri`, and
115
153
  * `collectDeletedURIs` are protected so subclasses can customise wording or
116
- * domain-aware cascades without re-implementing surrounding logic.
154
+ * domain-aware cascades without re-implementing surrounding logic. An adopter
155
+ * with build-scoped state of its own subclasses {@link BuildSession} and
156
+ * overrides {@link createBuildSession}, which puts that state under the same
157
+ * preemption-correct teardown rather than a reimplementation of it.
117
158
  */
118
159
  export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
119
160
  protected readonly tracer: Tracer;
@@ -127,8 +168,11 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
127
168
  protected readonly slowListenerMs: ObservableValue<number>;
128
169
  /** Live slow-build-phase-total threshold; read `.value` per phase. */
129
170
  protected readonly slowBuildMs: ObservableValue<number>;
171
+ /** Live phase-detail buffering threshold; read `.value` once per build, onto the session. */
172
+ protected readonly phaseDetailMs: ObservableValue<number>;
130
173
  protected readonly uriPolicy: DocumentUriPolicy;
131
174
  protected readonly clock: Clock;
175
+ protected readonly messageRenderer: MessageRenderer;
132
176
  /** Narrower handle on the same registry as the inherited `serviceRegistry`, for {@link ExtendedServiceRegistry.registrations}. */
133
177
  protected readonly languageRegistry: ExtendedServiceRegistry;
134
178
  protected languageFileExtensions: string[] = [];
@@ -139,18 +183,36 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
139
183
  protected readonly refreshCrossDocumentComputedScopes: boolean;
140
184
  /** LSP event name (e.g. `'didChangeWatchedFiles'`) staged for the next `update()` call. */
141
185
  protected pendingUpdateReason?: string;
186
+ /**
187
+ * The build currently in progress, or `undefined` between builds.
188
+ *
189
+ * A subclass carrying its own build-scoped state returns a {@link BuildSession}
190
+ * subclass from {@link createBuildSession} and narrows this with a typeguard
191
+ * where it reads that state — rather than redeclaring the field, whose
192
+ * initialiser would run after `super()` and clear a session opened during
193
+ * construction.
194
+ */
195
+ protected activeSession?: BuildSession;
196
+ /**
197
+ * `traceId` of the last build that ended in cancellation, for the successor's
198
+ * "cancels #N" tag. Held here rather than on a session because the session
199
+ * that carries it is already gone by the time its successor is opened.
200
+ */
201
+ protected lastCancelledTraceId?: number;
142
202
 
143
203
  constructor(services: ServerSharedServicesMinimal, options: DocumentBuilderOptions = {}) {
144
204
  super(services);
145
205
  this.languageRegistry = services.ServiceRegistry;
146
206
  this.uriPolicy = services.workspace.DocumentUriPolicy;
147
207
  this.clock = services.Clock;
208
+ this.messageRenderer = services.MessageRenderer;
148
209
  this.tracer = services.Tracer.for(options.logName ?? 'DocumentBuilder').trace('instantiated');
149
210
  this.logLevel = options.logLevel ?? 'debug';
150
211
  this.loggedPhases = options.loggedPhases ?? DEFAULT_LOGGED_PHASES;
151
212
  this.slowPhaseMs = ObservableValue.from(options.slowPhaseMs ?? 25);
152
213
  this.slowListenerMs = ObservableValue.from(options.slowListenerMs ?? 5);
153
214
  this.slowBuildMs = ObservableValue.from(options.slowBuildMs ?? 25);
215
+ this.phaseDetailMs = ObservableValue.from(options.phaseDetailMs ?? 0);
154
216
  this.refreshCrossDocumentComputedScopes = options.refreshCrossDocumentComputedScopes ?? false;
155
217
  if (this.logLevel !== 'off') {
156
218
  this.registerPhaseListeners();
@@ -163,8 +225,8 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
163
225
 
164
226
  /**
165
227
  * Stage an LSP event name for the next `update()` call. Adopters call before
166
- * the update fires; `HydraniumDocumentUpdateHandler` does it for the
167
- * four LSP events.
228
+ * the update fires; `HydraniumDocumentUpdateHandler` does it for the LSP
229
+ * events, and the text store for the revert that follows a last close.
168
230
  *
169
231
  * The framework stages the value and never reads it back. The consumer is a
170
232
  * subclass overriding the build logging, which takes
@@ -193,7 +255,16 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
193
255
  const doc = this.langiumDocuments.getDocument(UriUtils.toUri(this.uriPolicy.canonicalUri(uri)));
194
256
  const docState = doc ? DocumentState[doc.state] : 'unknown (document not loaded)';
195
257
  const lastPhase = this.lastPhaseMs > 0 ? `${Math.round(performance.now() - this.lastPhaseMs)}ms ago` : 'no phase observed';
196
- return `current state: '${docState}', last phase: ${lastPhase}`;
258
+ return `current state: '${docState}', last phase: ${lastPhase}, active build: ${this.formatSession(this.activeSession)}`;
259
+ }
260
+
261
+ /** Render a session for a status line. `undefined` — no build in progress — reads as `none`. */
262
+ protected formatSession(session: BuildSession | undefined): string {
263
+ if (!session) {
264
+ return 'none';
265
+ }
266
+ const id = session.traceId !== undefined ? `#${session.traceId}` : 'untimed';
267
+ return `${id} (${session.trigger}, ${Math.round(performance.now() - session.startMs)}ms in)`;
197
268
  }
198
269
 
199
270
  // ============================================================
@@ -409,7 +480,35 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
409
480
  this.ensureLanguageFileExtensions();
410
481
  const changedURIs = changed.flatMap(uri => this.flattenAndAdaptURI(uri));
411
482
  const deletedURIs = deleted.flatMap(uri => this.collectDeletedURIs(uri));
412
- return super.update(changedURIs, deletedURIs, cancelToken);
483
+ return this.runInSession(
484
+ {
485
+ kind: 'update',
486
+ trigger: this.buildTriggerLabel(changedURIs, deletedURIs),
487
+ triggerCountsDocs: changedURIs.length + deletedURIs.length !== 1,
488
+ changed: changedURIs,
489
+ deleted: deletedURIs
490
+ },
491
+ this.rebuildLabel(changedURIs, deletedURIs),
492
+ () => super.update(changedURIs, deletedURIs, cancelToken)
493
+ );
494
+ }
495
+
496
+ /**
497
+ * The workspace-initialization entry point, bracketed by a session like
498
+ * {@link update}. Langium's `update` reaches `buildDocuments` directly rather
499
+ * than through here, so the two never nest.
500
+ */
501
+ override build<T extends AstNode>(
502
+ documents: Array<LangiumDocument<T>>,
503
+ options?: BuildOptions,
504
+ cancelToken?: CancellationToken
505
+ ): Promise<void> {
506
+ const uris = documents.map(document => document.uri);
507
+ return this.runInSession(
508
+ { kind: 'build', trigger: `${documents.length} docs`, triggerCountsDocs: true, changed: uris, deleted: [] },
509
+ `Build documents (${documents.length} docs)`,
510
+ () => super.build(documents, options, cancelToken)
511
+ );
413
512
  }
414
513
 
415
514
  /**
@@ -615,6 +714,149 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
615
714
  ];
616
715
  }
617
716
 
717
+ // ============================================================
718
+ // Build sessions — one rebuild as a correlated unit
719
+ // ============================================================
720
+
721
+ /**
722
+ * Open a session, run `body` inside it, and close it — the bracket every
723
+ * line of a rebuild is emitted within.
724
+ *
725
+ * The session is installed **synchronously**, before the timed body runs, so
726
+ * that state a subclass computed in {@link createBuildSession} is already
727
+ * readable by the time Langium's `update` consults `shouldRelink`.
728
+ *
729
+ * Teardown is preemption-correct, which is the reason this is framework code
730
+ * rather than a recipe. Langium's write mutex cancels an in-flight build when
731
+ * a later one arrives, so two sessions overlap: the successor installs itself
732
+ * as {@link activeSession} while the predecessor is still unwinding, and the
733
+ * predecessor's `finally` runs LAST. Clearing unconditionally there would
734
+ * discard the winner's state mid-build. Only the session that is still
735
+ * current clears — and the check is reference equality on the session object,
736
+ * not on {@link BuildSession.traceId}, which is `undefined` for every build
737
+ * whenever the timing level is suppressed and would compare equal to itself
738
+ * across two different builds.
739
+ *
740
+ * Re-entrancy is not hypothetical even without an adopter: {@link
741
+ * requeueOrphaned} calls `update` from inside a wait, while a build may be
742
+ * running.
743
+ */
744
+ protected runInSession(context: BuildSessionContext, label: string, body: () => Promise<void>): Promise<void> {
745
+ // Read before installing the new session: the id being superseded belongs
746
+ // to the OUTGOING build, or — when the previous one already finished
747
+ // cancelled — to the id it parked for its successor.
748
+ const supersededId = this.activeSession?.traceId ?? this.lastCancelledTraceId;
749
+ this.lastCancelledTraceId = undefined;
750
+ const reason = this.pendingUpdateReason;
751
+ this.pendingUpdateReason = undefined;
752
+ const tags: string[] = [];
753
+ if (reason) {
754
+ tags.push(`event: ${reason}`);
755
+ }
756
+ if (supersededId !== undefined) {
757
+ tags.push(`cancels #${supersededId}`);
758
+ }
759
+
760
+ const session = this.createBuildSession(context);
761
+ this.activeSession = session;
762
+ // A phase's "since previous phase" must measure from the build's start,
763
+ // not from whenever the last build's final phase happened to land.
764
+ this.lastPhaseMs = session.startMs;
765
+ return this.tracer.time(
766
+ label,
767
+ async () => {
768
+ try {
769
+ await body();
770
+ } catch (err: unknown) {
771
+ if (isOperationCancelled(err)) {
772
+ session.cancelled = true;
773
+ }
774
+ throw err;
775
+ } finally {
776
+ this.endSession(session);
777
+ }
778
+ },
779
+ this.logLevel,
780
+ {
781
+ logAfterMs: 0,
782
+ forceMemoryAboveMs: session.buffers ? session.detailThresholdMs : undefined,
783
+ captureId: id => {
784
+ session.traceId = id;
785
+ },
786
+ tags
787
+ }
788
+ );
789
+ }
790
+
791
+ /**
792
+ * Construct the session for one build. Override to return a
793
+ * {@link BuildSession} subclass carrying adopter build-scoped state — it is
794
+ * called before the build body, so anything derived here is readable
795
+ * throughout it.
796
+ */
797
+ protected createBuildSession(context: BuildSessionContext): BuildSession {
798
+ return new BuildSession(performance.now(), context.trigger, context.triggerCountsDocs, this.phaseDetailMs.value);
799
+ }
800
+
801
+ /**
802
+ * Close `session`: flush what it buffered, then release it if it is still the
803
+ * current one (see {@link runInSession} on why that check is conditional).
804
+ * The flush is unconditional — a preempted build's lines still describe work
805
+ * that happened.
806
+ */
807
+ protected endSession(session: BuildSession): void {
808
+ this.flushSession(session);
809
+ if (this.activeSession === session) {
810
+ this.activeSession = undefined;
811
+ if (session.cancelled) {
812
+ this.lastCancelledTraceId = session.traceId;
813
+ }
814
+ }
815
+ }
816
+
817
+ /**
818
+ * Emit the lines `session` held back, if it ran long enough to be worth the
819
+ * detail; drop them otherwise. Emits through {@link emit} rather than
820
+ * {@link log}, which would route them straight back into the buffer.
821
+ */
822
+ protected flushSession(session: BuildSession): void {
823
+ const elapsedMs = performance.now() - session.startMs;
824
+ if (elapsedMs >= session.detailThresholdMs) {
825
+ for (const line of session.bufferedLines) {
826
+ this.emit(line);
827
+ }
828
+ }
829
+ session.bufferedLines.length = 0;
830
+ }
831
+
832
+ /** Label for the build's own log line. Override to customise wording. */
833
+ protected rebuildLabel(changed: URI[], deleted: URI[]): string {
834
+ if (changed.length === 0 && deleted.length === 0) {
835
+ return 'Rebuild documents (nothing to do)';
836
+ }
837
+ if (changed.length === 1 && deleted.length === 0) {
838
+ return `Rebuild document: ${this.formatUri(changed[0])}`;
839
+ }
840
+ if (changed.length === 0 && deleted.length === 1) {
841
+ return `Rebuild after delete: ${this.formatUri(deleted[0])}`;
842
+ }
843
+ return `Rebuild documents (${changed.length} changed, ${deleted.length} deleted)`;
844
+ }
845
+
846
+ /** Short description of what triggered the build, repeated on every phase line. Override to customise wording. */
847
+ protected buildTriggerLabel(changed: URI[], deleted: URI[]): string {
848
+ if (changed.length === 0 && deleted.length === 0) {
849
+ return 'nothing';
850
+ }
851
+ if (changed.length === 1 && deleted.length === 0) {
852
+ return this.formatUri(changed[0]);
853
+ }
854
+ if (changed.length === 0 && deleted.length === 1) {
855
+ return `deleted ${this.formatUri(deleted[0])}`;
856
+ }
857
+ return `${changed.length} changed, ${deleted.length} deleted`;
858
+ }
859
+
618
860
  // ============================================================
619
861
  // Logging — phase-reached listeners
620
862
  // ============================================================
@@ -630,13 +872,35 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
630
872
  const now = performance.now();
631
873
  const elapsedMs = Math.round(now - this.lastPhaseMs);
632
874
  this.lastPhaseMs = now;
875
+ // Counted before the line is formatted, so the formatter stays a pure
876
+ // function of state a caller can also set up in a test.
877
+ if (this.activeSession) {
878
+ this.activeSession.phasesLogged++;
879
+ }
633
880
  this.log(this.phaseReachedLine(state, documents, elapsedMs));
634
881
  }
635
882
 
636
- /** Format the phase-reached log line. Override to customise wording. */
883
+ /**
884
+ * Format the phase-reached log line. Override to customise wording.
885
+ *
886
+ * Within a session the line names what triggered the build, so a phase read
887
+ * in isolation still says which rebuild it belongs to. `elapsedMs` is ignored
888
+ * for the FIRST phase of a session: it measures from the previous build's
889
+ * last phase, an idle gap that says nothing about this build.
890
+ */
637
891
  protected phaseReachedLine(state: DocumentState, documents: LangiumDocument[], elapsedMs: number): string {
638
- const docInfo = documents.length === 1 ? this.formatUri(documents[0].uri) : `${documents.length} docs`;
639
- return `Reached phase '${DocumentState[state]}' [${docInfo}, ${elapsedMs}ms since previous phase]`;
892
+ const session = this.activeSession;
893
+ let docInfo: string;
894
+ if (session) {
895
+ docInfo = session.triggerCountsDocs ? `building ${session.trigger}` : `building ${session.trigger}, ${documents.length} docs`;
896
+ } else {
897
+ docInfo = documents.length === 1 ? this.formatUri(documents[0].uri) : `${documents.length} docs`;
898
+ }
899
+ const elapsedInfo =
900
+ session && session.phasesLogged <= 1
901
+ ? `${Math.round(performance.now() - session.startMs)}ms since build start`
902
+ : `${elapsedMs}ms since previous phase`;
903
+ return `Reached phase '${DocumentState[state]}' [${docInfo}, ${elapsedInfo}]`;
640
904
  }
641
905
 
642
906
  // ============================================================
@@ -651,8 +915,12 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
651
915
  // build settling inside that window therefore appends after this call has
652
916
  // already deduped, and the appended duplicate is published by the listener
653
917
  // of the build that deduped. Only `serializeBuilds` closes the window.
918
+ //
919
+ // Dedupe before rendering: rendering is deterministic, so it cannot
920
+ // change which entries are structurally equal, and fewer survive to render.
654
921
  if (state === DocumentState.Validated) {
655
922
  this.dedupeDiagnostics(document);
923
+ this.renderDiagnostics(document);
656
924
  }
657
925
  if (this.logLevel === 'off') {
658
926
  return super.notifyDocumentPhase(document, state, cancelToken);
@@ -828,12 +1096,86 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
828
1096
  }
829
1097
  }
830
1098
 
1099
+ /**
1100
+ * Render every diagnostic on `document` through the bound message renderer,
1101
+ * in ONE pass over the finished list.
1102
+ *
1103
+ * All three heads read `document.diagnostics` — the LSP publish,
1104
+ * `TransferEncoder.toTransferDiagnostic` and the GLSP validation path — so
1105
+ * one pass here is what keeps the render from happening per head. It is also
1106
+ * the only placement that covers lexer and parser errors, which Langium
1107
+ * pushes onto the document without routing them through `toDiagnostic`.
1108
+ *
1109
+ * Running here rather than from a `Validated` phase listener needs no
1110
+ * ordering assumption: Langium publishes from `addDiagnosticsHandler`, a free
1111
+ * function it registers as such a listener, which can only be outrun.
1112
+ *
1113
+ * **It inherits {@link dedupeDiagnostics}'s window, and therefore the same
1114
+ * precondition.** A build settling inside the listener window appends
1115
+ * diagnostics this pass never saw, and the publisher of the build that
1116
+ * rendered sends them — unrendered. `ModelServiceOptions.serializeBuilds`
1117
+ * closes it and defaults to `true`, so "every diagnostic is rendered" holds
1118
+ * by default and is an opt-out rather than a guarantee. Opting out accepts
1119
+ * unrendered diagnostics on exactly the terms it already accepts duplicates.
1120
+ *
1121
+ * Entries are REPLACED rather than mutated: `sendDiagnostics` passes the
1122
+ * array by reference and serialises later, so an in-place message mutation
1123
+ * reaches the wire even when it runs after the publisher — which would make
1124
+ * a test for the ordering pass in either state.
1125
+ */
1126
+ protected renderDiagnostics(document: LangiumDocument): void {
1127
+ const diagnostics = document.diagnostics;
1128
+ if (!diagnostics || diagnostics.length === 0) {
1129
+ return;
1130
+ }
1131
+ let changed = false;
1132
+ // No try/catch: `renderDiagnostic` carries a no-throw contract, because an
1133
+ // error escaping this phase strands the document at `Validated` with
1134
+ // Langium's publisher never invoked.
1135
+ const rendered = diagnostics.map(diagnostic => {
1136
+ const text = this.messageRenderer.renderDiagnostic(diagnostic);
1137
+ // Against the message's STRING FORM, not the field. `renderDiagnostic`
1138
+ // answers a `string` by contract, while `Diagnostic.message` is
1139
+ // `string | MarkupContent` since LSP 3.17 — so comparing the answer
1140
+ // against the field never matches for a markup message, and a pass
1141
+ // that replaced on mismatch flattened every un-identified markup
1142
+ // diagnostic to its own plain text. That is silent data loss on the
1143
+ // path whose whole job is to leave such entries alone.
1144
+ if (text === Diagnostic.getMessageString(diagnostic)) {
1145
+ return diagnostic;
1146
+ }
1147
+ changed = true;
1148
+ return { ...diagnostic, message: text };
1149
+ });
1150
+ if (changed) {
1151
+ document.diagnostics = rendered;
1152
+ }
1153
+ }
1154
+
831
1155
  // ============================================================
832
1156
  // Internal helpers
833
1157
  // ============================================================
834
1158
 
835
- /** Dispatch a log line at the configured log level; a no-op when `logLevel === 'off'`. */
1159
+ /**
1160
+ * Dispatch a log line at the configured log level; a no-op when `logLevel ===
1161
+ * 'off'`.
1162
+ *
1163
+ * Held on the active session when it buffers, so the "was this build worth a
1164
+ * per-phase breakdown" decision — which needs the build's total duration, and
1165
+ * so cannot be taken by anything that runs while the lines are produced — is
1166
+ * deferred to {@link flushSession}.
1167
+ */
836
1168
  protected log(message: string): void {
1169
+ const session = this.activeSession;
1170
+ if (session?.buffers) {
1171
+ session.bufferedLines.push(message);
1172
+ return;
1173
+ }
1174
+ this.emit(message);
1175
+ }
1176
+
1177
+ /** Write a line out, bypassing session buffering. The single sink every framework log line reaches. */
1178
+ protected emit(message: string): void {
837
1179
  this.tracer.logAt(this.logLevel, message);
838
1180
  }
839
1181
  }