@hydranium/core 1.0.0-next.18 → 1.0.0-next.180

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 (572) hide show
  1. package/README.md +5 -1
  2. package/lib/documents/ast-document-manager.d.ts +190 -30
  3. package/lib/documents/ast-document-manager.d.ts.map +1 -1
  4. package/lib/documents/ast-document-manager.js +236 -40
  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 +187 -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 +447 -82
  23. package/lib/documents/hydranium-text-documents.d.ts.map +1 -1
  24. package/lib/documents/hydranium-text-documents.js +780 -160
  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-extension-service.d.ts.map +1 -1
  43. package/lib/langium/ast-extension/ast-extension-service.js.map +1 -1
  44. package/lib/langium/ast-extension/ast-node-builder.d.ts +32 -9
  45. package/lib/langium/ast-extension/ast-node-builder.d.ts.map +1 -1
  46. package/lib/langium/ast-extension/ast-node-builder.js +60 -22
  47. package/lib/langium/ast-extension/ast-node-builder.js.map +1 -1
  48. package/lib/langium/bootstrap.d.ts.map +1 -1
  49. package/lib/langium/bootstrap.js +16 -9
  50. package/lib/langium/bootstrap.js.map +1 -1
  51. package/lib/langium/build-phase-pass/build-phase-pass-service.d.ts.map +1 -1
  52. package/lib/langium/build-phase-pass/build-phase-pass-service.js.map +1 -1
  53. package/lib/langium/config/configuration-provider.d.ts +81 -0
  54. package/lib/langium/config/configuration-provider.d.ts.map +1 -0
  55. package/lib/langium/config/configuration-provider.js +112 -0
  56. package/lib/langium/config/configuration-provider.js.map +1 -0
  57. package/lib/langium/config/index.d.ts +1 -0
  58. package/lib/langium/config/index.d.ts.map +1 -1
  59. package/lib/langium/config/index.js +1 -0
  60. package/lib/langium/config/index.js.map +1 -1
  61. package/lib/langium/config/settings.js.map +1 -1
  62. package/lib/langium/diagnostics/hydranium-langium-profiler.d.ts.map +1 -1
  63. package/lib/langium/diagnostics/hydranium-langium-profiler.js.map +1 -1
  64. package/lib/langium/diagnostics/lsp-logger.d.ts +17 -0
  65. package/lib/langium/diagnostics/lsp-logger.d.ts.map +1 -1
  66. package/lib/langium/diagnostics/lsp-logger.js +40 -6
  67. package/lib/langium/diagnostics/lsp-logger.js.map +1 -1
  68. package/lib/langium/diagnostics/server-tracer.d.ts.map +1 -1
  69. package/lib/langium/diagnostics/server-tracer.js.map +1 -1
  70. package/lib/langium/document-builder/build-pipeline-integration.d.ts +21 -1
  71. package/lib/langium/document-builder/build-pipeline-integration.d.ts.map +1 -1
  72. package/lib/langium/document-builder/build-pipeline-integration.js +32 -5
  73. package/lib/langium/document-builder/build-pipeline-integration.js.map +1 -1
  74. package/lib/langium/document-builder/build-session.d.ts +93 -0
  75. package/lib/langium/document-builder/build-session.d.ts.map +1 -0
  76. package/lib/langium/document-builder/build-session.js +72 -0
  77. package/lib/langium/document-builder/build-session.js.map +1 -0
  78. package/lib/langium/document-builder/document-builder.d.ts +368 -21
  79. package/lib/langium/document-builder/document-builder.d.ts.map +1 -1
  80. package/lib/langium/document-builder/document-builder.js +641 -47
  81. package/lib/langium/document-builder/document-builder.js.map +1 -1
  82. package/lib/langium/document-builder/index.d.ts +1 -0
  83. package/lib/langium/document-builder/index.d.ts.map +1 -1
  84. package/lib/langium/document-builder/index.js +1 -0
  85. package/lib/langium/document-builder/index.js.map +1 -1
  86. package/lib/langium/documentation/comment-provider.d.ts.map +1 -1
  87. package/lib/langium/documentation/comment-provider.js.map +1 -1
  88. package/lib/langium/integration-services.d.ts +45 -1
  89. package/lib/langium/integration-services.d.ts.map +1 -1
  90. package/lib/langium/integration-services.js +10 -5
  91. package/lib/langium/integration-services.js.map +1 -1
  92. package/lib/langium/integrity/integrity-rule.d.ts +13 -5
  93. package/lib/langium/integrity/integrity-rule.d.ts.map +1 -1
  94. package/lib/langium/integrity/integrity-rule.js.map +1 -1
  95. package/lib/langium/integrity/integrity-service.d.ts +58 -13
  96. package/lib/langium/integrity/integrity-service.d.ts.map +1 -1
  97. package/lib/langium/integrity/integrity-service.js +213 -29
  98. package/lib/langium/integrity/integrity-service.js.map +1 -1
  99. package/lib/langium/keys/containment.d.ts +64 -0
  100. package/lib/langium/keys/containment.d.ts.map +1 -0
  101. package/lib/langium/keys/containment.js +53 -0
  102. package/lib/langium/keys/containment.js.map +1 -0
  103. package/lib/langium/keys/index.d.ts +1 -0
  104. package/lib/langium/keys/index.d.ts.map +1 -1
  105. package/lib/langium/keys/index.js +1 -0
  106. package/lib/langium/keys/index.js.map +1 -1
  107. package/lib/langium/keys/name-based-key-provider.d.ts +4 -0
  108. package/lib/langium/keys/name-based-key-provider.d.ts.map +1 -1
  109. package/lib/langium/keys/name-based-key-provider.js +4 -0
  110. package/lib/langium/keys/name-based-key-provider.js.map +1 -1
  111. package/lib/langium/keys/positional-key-provider.d.ts.map +1 -1
  112. package/lib/langium/keys/positional-key-provider.js.map +1 -1
  113. package/lib/langium/labeling/label-provider.d.ts.map +1 -1
  114. package/lib/langium/labeling/label-provider.js.map +1 -1
  115. package/lib/langium/language-module.d.ts +27 -2
  116. package/lib/langium/language-module.d.ts.map +1 -1
  117. package/lib/langium/language-module.js +16 -2
  118. package/lib/langium/language-module.js.map +1 -1
  119. package/lib/langium/model-service/client-session.d.ts +307 -0
  120. package/lib/langium/model-service/client-session.d.ts.map +1 -0
  121. package/lib/langium/model-service/client-session.js +395 -0
  122. package/lib/langium/model-service/client-session.js.map +1 -0
  123. package/lib/langium/model-service/index.d.ts +1 -0
  124. package/lib/langium/model-service/index.d.ts.map +1 -1
  125. package/lib/langium/model-service/index.js +1 -0
  126. package/lib/langium/model-service/index.js.map +1 -1
  127. package/lib/langium/model-service/model-service.d.ts +276 -226
  128. package/lib/langium/model-service/model-service.d.ts.map +1 -1
  129. package/lib/langium/model-service/model-service.js +251 -375
  130. package/lib/langium/model-service/model-service.js.map +1 -1
  131. package/lib/langium/module.d.ts +144 -35
  132. package/lib/langium/module.d.ts.map +1 -1
  133. package/lib/langium/module.js +46 -35
  134. package/lib/langium/module.js.map +1 -1
  135. package/lib/langium/naming/name-provider.d.ts +25 -4
  136. package/lib/langium/naming/name-provider.d.ts.map +1 -1
  137. package/lib/langium/naming/name-provider.js +2 -1
  138. package/lib/langium/naming/name-provider.js.map +1 -1
  139. package/lib/langium/naming/name-separator-validation.d.ts +23 -0
  140. package/lib/langium/naming/name-separator-validation.d.ts.map +1 -1
  141. package/lib/langium/naming/name-separator-validation.js +30 -1
  142. package/lib/langium/naming/name-separator-validation.js.map +1 -1
  143. package/lib/langium/project/abstract-project-manager.d.ts.map +1 -1
  144. package/lib/langium/project/abstract-project-manager.js +9 -2
  145. package/lib/langium/project/abstract-project-manager.js.map +1 -1
  146. package/lib/langium/project/project-change-event.d.ts +2 -2
  147. package/lib/langium/project/single-project-manager.d.ts.map +1 -1
  148. package/lib/langium/project/single-project-manager.js.map +1 -1
  149. package/lib/langium/residency/cst-residency-service.d.ts +31 -11
  150. package/lib/langium/residency/cst-residency-service.d.ts.map +1 -1
  151. package/lib/langium/residency/cst-residency-service.js +13 -56
  152. package/lib/langium/residency/cst-residency-service.js.map +1 -1
  153. package/lib/langium/scope/ast-node-description-provider.d.ts.map +1 -1
  154. package/lib/langium/scope/ast-node-description-provider.js.map +1 -1
  155. package/lib/langium/scope/hydranium-scope-computation.d.ts.map +1 -1
  156. package/lib/langium/scope/hydranium-scope-computation.js.map +1 -1
  157. package/lib/langium/scope/hydranium-scope-provider.d.ts +48 -13
  158. package/lib/langium/scope/hydranium-scope-provider.d.ts.map +1 -1
  159. package/lib/langium/scope/hydranium-scope-provider.js +56 -20
  160. package/lib/langium/scope/hydranium-scope-provider.js.map +1 -1
  161. package/lib/langium/scope/reference-builder.d.ts.map +1 -1
  162. package/lib/langium/scope/reference-builder.js.map +1 -1
  163. package/lib/langium/scope/reference-candidate-provider.d.ts.map +1 -1
  164. package/lib/langium/scope/reference-candidate-provider.js.map +1 -1
  165. package/lib/langium/scope/scope-extension-service.d.ts.map +1 -1
  166. package/lib/langium/scope/scope-extension-service.js.map +1 -1
  167. package/lib/langium/serialization/abstract-serializer.d.ts +11 -20
  168. package/lib/langium/serialization/abstract-serializer.d.ts.map +1 -1
  169. package/lib/langium/serialization/abstract-serializer.js +12 -21
  170. package/lib/langium/serialization/abstract-serializer.js.map +1 -1
  171. package/lib/langium/serialization/json-serializer.d.ts +1 -1
  172. package/lib/langium/serialization/json-serializer.d.ts.map +1 -1
  173. package/lib/langium/serialization/json-serializer.js.map +1 -1
  174. package/lib/langium/serialization/yaml-serializer.d.ts.map +1 -1
  175. package/lib/langium/serialization/yaml-serializer.js.map +1 -1
  176. package/lib/langium/service-registry.d.ts +15 -1
  177. package/lib/langium/service-registry.d.ts.map +1 -1
  178. package/lib/langium/service-registry.js +16 -0
  179. package/lib/langium/service-registry.js.map +1 -1
  180. package/lib/langium/shared-services.d.ts +15 -2
  181. package/lib/langium/shared-services.d.ts.map +1 -1
  182. package/lib/langium/shared-services.js.map +1 -1
  183. package/lib/langium/transfer/transfer-encoder.d.ts +60 -17
  184. package/lib/langium/transfer/transfer-encoder.d.ts.map +1 -1
  185. package/lib/langium/transfer/transfer-encoder.js +38 -16
  186. package/lib/langium/transfer/transfer-encoder.js.map +1 -1
  187. package/lib/langium/trivia/comment-preserver.d.ts +423 -0
  188. package/lib/langium/trivia/comment-preserver.d.ts.map +1 -0
  189. package/lib/langium/trivia/comment-preserver.js +906 -0
  190. package/lib/langium/trivia/comment-preserver.js.map +1 -0
  191. package/lib/langium/trivia/document-ending-preserver.d.ts +43 -0
  192. package/lib/langium/trivia/document-ending-preserver.d.ts.map +1 -0
  193. package/lib/langium/trivia/document-ending-preserver.js +48 -0
  194. package/lib/langium/trivia/document-ending-preserver.js.map +1 -0
  195. package/lib/langium/trivia/index.d.ts +14 -0
  196. package/lib/langium/trivia/index.d.ts.map +1 -0
  197. package/lib/langium/trivia/index.js +14 -0
  198. package/lib/langium/trivia/index.js.map +1 -0
  199. package/lib/langium/trivia/trivia-contribution.d.ts +37 -0
  200. package/lib/langium/trivia/trivia-contribution.d.ts.map +1 -0
  201. package/lib/langium/trivia/trivia-contribution.js +10 -0
  202. package/lib/langium/trivia/trivia-contribution.js.map +1 -0
  203. package/lib/langium/trivia/trivia-preserver.d.ts +50 -0
  204. package/lib/langium/trivia/trivia-preserver.d.ts.map +1 -0
  205. package/lib/langium/trivia/trivia-preserver.js +10 -0
  206. package/lib/langium/trivia/trivia-preserver.js.map +1 -0
  207. package/lib/langium/trivia/trivia-service.d.ts +70 -0
  208. package/lib/langium/trivia/trivia-service.d.ts.map +1 -0
  209. package/lib/langium/trivia/trivia-service.js +56 -0
  210. package/lib/langium/trivia/trivia-service.js.map +1 -0
  211. package/lib/langium/update-rewrite/normalize-empty-strings.d.ts.map +1 -1
  212. package/lib/langium/update-rewrite/update-rewrite-service.d.ts.map +1 -1
  213. package/lib/langium/update-rewrite/update-rewrite-service.js.map +1 -1
  214. package/lib/langium/update-rewrite/update-rewrite.d.ts +1 -1
  215. package/lib/langium/validation/document-validator.d.ts +294 -10
  216. package/lib/langium/validation/document-validator.d.ts.map +1 -1
  217. package/lib/langium/validation/document-validator.js +448 -5
  218. package/lib/langium/validation/document-validator.js.map +1 -1
  219. package/lib/langium/validation/validation-contribution-collector.d.ts.map +1 -1
  220. package/lib/langium/validation/validation-contribution-collector.js.map +1 -1
  221. package/lib/langium/workspace/document-uri-policy.d.ts +17 -12
  222. package/lib/langium/workspace/document-uri-policy.d.ts.map +1 -1
  223. package/lib/langium/workspace/document-uri-policy.js +10 -9
  224. package/lib/langium/workspace/document-uri-policy.js.map +1 -1
  225. package/lib/langium/workspace/file-not-found.d.ts +17 -0
  226. package/lib/langium/workspace/file-not-found.d.ts.map +1 -0
  227. package/lib/langium/workspace/file-not-found.js +20 -0
  228. package/lib/langium/workspace/file-not-found.js.map +1 -0
  229. package/lib/langium/workspace/file-system-provider.d.ts +84 -8
  230. package/lib/langium/workspace/file-system-provider.d.ts.map +1 -1
  231. package/lib/langium/workspace/file-system-provider.js +93 -14
  232. package/lib/langium/workspace/file-system-provider.js.map +1 -1
  233. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts +25 -0
  234. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts.map +1 -1
  235. package/lib/langium/workspace/hydranium-langium-document-factory.js +25 -0
  236. package/lib/langium/workspace/hydranium-langium-document-factory.js.map +1 -1
  237. package/lib/langium/workspace/hydranium-workspace-lock.d.ts +43 -1
  238. package/lib/langium/workspace/hydranium-workspace-lock.d.ts.map +1 -1
  239. package/lib/langium/workspace/hydranium-workspace-lock.js +58 -1
  240. package/lib/langium/workspace/hydranium-workspace-lock.js.map +1 -1
  241. package/lib/langium/workspace/hydranium-workspace-manager.d.ts +81 -8
  242. package/lib/langium/workspace/hydranium-workspace-manager.d.ts.map +1 -1
  243. package/lib/langium/workspace/hydranium-workspace-manager.js +128 -10
  244. package/lib/langium/workspace/hydranium-workspace-manager.js.map +1 -1
  245. package/lib/langium/workspace/in-memory-file-system-provider.d.ts +25 -2
  246. package/lib/langium/workspace/in-memory-file-system-provider.d.ts.map +1 -1
  247. package/lib/langium/workspace/in-memory-file-system-provider.js +41 -15
  248. package/lib/langium/workspace/in-memory-file-system-provider.js.map +1 -1
  249. package/lib/langium/workspace/index-manager.d.ts.map +1 -1
  250. package/lib/langium/workspace/index-manager.js.map +1 -1
  251. package/lib/langium/workspace/initialize-workspace.d.ts +31 -2
  252. package/lib/langium/workspace/initialize-workspace.d.ts.map +1 -1
  253. package/lib/langium/workspace/initialize-workspace.js +13 -5
  254. package/lib/langium/workspace/initialize-workspace.js.map +1 -1
  255. package/lib/langium/workspace/langium-documents.d.ts +79 -17
  256. package/lib/langium/workspace/langium-documents.d.ts.map +1 -1
  257. package/lib/langium/workspace/langium-documents.js +91 -29
  258. package/lib/langium/workspace/langium-documents.js.map +1 -1
  259. package/lib/langium/workspace/persistent-file-system-provider.d.ts +0 -7
  260. package/lib/langium/workspace/persistent-file-system-provider.d.ts.map +1 -1
  261. package/lib/langium/workspace/persistent-file-system-provider.js +0 -7
  262. package/lib/langium/workspace/persistent-file-system-provider.js.map +1 -1
  263. package/lib/langium/workspace/virtual-document.d.ts +48 -15
  264. package/lib/langium/workspace/virtual-document.d.ts.map +1 -1
  265. package/lib/langium/workspace/virtual-document.js +78 -18
  266. package/lib/langium/workspace/virtual-document.js.map +1 -1
  267. package/lib/langium/workspace/write-lock-scope.d.ts +20 -10
  268. package/lib/langium/workspace/write-lock-scope.d.ts.map +1 -1
  269. package/lib/langium/workspace/write-lock-scope.js +12 -4
  270. package/lib/langium/workspace/write-lock-scope.js.map +1 -1
  271. package/lib/locale/index.d.ts +10 -0
  272. package/lib/locale/index.d.ts.map +1 -0
  273. package/lib/locale/index.js +10 -0
  274. package/lib/locale/index.js.map +1 -0
  275. package/lib/locale/server-locale.d.ts +73 -0
  276. package/lib/locale/server-locale.d.ts.map +1 -0
  277. package/lib/locale/server-locale.js +61 -0
  278. package/lib/locale/server-locale.js.map +1 -0
  279. package/lib/lsp/completion/hydranium-completion-provider.d.ts +44 -2
  280. package/lib/lsp/completion/hydranium-completion-provider.d.ts.map +1 -1
  281. package/lib/lsp/completion/hydranium-completion-provider.js +68 -0
  282. package/lib/lsp/completion/hydranium-completion-provider.js.map +1 -1
  283. package/lib/lsp/connection-features.d.ts +23 -0
  284. package/lib/lsp/connection-features.d.ts.map +1 -0
  285. package/lib/lsp/connection-features.js +60 -0
  286. package/lib/lsp/connection-features.js.map +1 -0
  287. package/lib/lsp/diagnostics-connection.d.ts +27 -0
  288. package/lib/lsp/diagnostics-connection.d.ts.map +1 -0
  289. package/lib/lsp/diagnostics-connection.js +53 -0
  290. package/lib/lsp/diagnostics-connection.js.map +1 -0
  291. package/lib/lsp/hydranium-document-update-handler.d.ts +90 -79
  292. package/lib/lsp/hydranium-document-update-handler.d.ts.map +1 -1
  293. package/lib/lsp/hydranium-document-update-handler.js +152 -99
  294. package/lib/lsp/hydranium-document-update-handler.js.map +1 -1
  295. package/lib/lsp/index.d.ts +3 -1
  296. package/lib/lsp/index.d.ts.map +1 -1
  297. package/lib/lsp/index.js +3 -1
  298. package/lib/lsp/index.js.map +1 -1
  299. package/lib/lsp/lsp-latency.d.ts +39 -0
  300. package/lib/lsp/lsp-latency.d.ts.map +1 -0
  301. package/lib/lsp/lsp-latency.js +58 -0
  302. package/lib/lsp/lsp-latency.js.map +1 -0
  303. package/lib/lsp/semantic-token-provider.d.ts +34 -1
  304. package/lib/lsp/semantic-token-provider.d.ts.map +1 -1
  305. package/lib/lsp/semantic-token-provider.js +55 -8
  306. package/lib/lsp/semantic-token-provider.js.map +1 -1
  307. package/lib/lsp/shared-module.d.ts +4 -8
  308. package/lib/lsp/shared-module.d.ts.map +1 -1
  309. package/lib/lsp/shared-module.js.map +1 -1
  310. package/lib/lsp/start-language-server.d.ts +8 -7
  311. package/lib/lsp/start-language-server.d.ts.map +1 -1
  312. package/lib/lsp/start-language-server.js +13 -7
  313. package/lib/lsp/start-language-server.js.map +1 -1
  314. package/lib/messages/carriers.d.ts +54 -0
  315. package/lib/messages/carriers.d.ts.map +1 -0
  316. package/lib/messages/carriers.js +62 -0
  317. package/lib/messages/carriers.js.map +1 -0
  318. package/lib/messages/index.d.ts +25 -0
  319. package/lib/messages/index.d.ts.map +1 -0
  320. package/lib/messages/index.js +25 -0
  321. package/lib/messages/index.js.map +1 -0
  322. package/lib/messages/renderer.d.ts +142 -0
  323. package/lib/messages/renderer.d.ts.map +1 -0
  324. package/lib/messages/renderer.js +165 -0
  325. package/lib/messages/renderer.js.map +1 -0
  326. package/lib/node/event-loop-monitor.js.map +1 -1
  327. package/lib/node/heap-ceiling.d.ts +61 -0
  328. package/lib/node/heap-ceiling.d.ts.map +1 -0
  329. package/lib/node/heap-ceiling.js +72 -0
  330. package/lib/node/heap-ceiling.js.map +1 -0
  331. package/lib/node/index.d.ts +1 -0
  332. package/lib/node/index.d.ts.map +1 -1
  333. package/lib/node/index.js +1 -0
  334. package/lib/node/index.js.map +1 -1
  335. package/lib/node/latency-from-env.d.ts +1 -1
  336. package/lib/node/latency-from-env.js +1 -1
  337. package/lib/node/lint-grammar.js.map +1 -1
  338. package/lib/node/measure-memory.d.ts.map +1 -1
  339. package/lib/node/measure-memory.js +1 -0
  340. package/lib/node/measure-memory.js.map +1 -1
  341. package/lib/node/memory-monitor.js.map +1 -1
  342. package/lib/node/node-file-system-provider.d.ts +39 -4
  343. package/lib/node/node-file-system-provider.d.ts.map +1 -1
  344. package/lib/node/node-file-system-provider.js +109 -49
  345. package/lib/node/node-file-system-provider.js.map +1 -1
  346. package/lib/node/process-memory.js.map +1 -1
  347. package/lib/node/profile-capture.d.ts +8 -2
  348. package/lib/node/profile-capture.d.ts.map +1 -1
  349. package/lib/node/profile-capture.js.map +1 -1
  350. package/lib/node/profile-digest.js.map +1 -1
  351. package/lib/node/profiling-run.d.ts +2 -2
  352. package/lib/node/profiling-run.d.ts.map +1 -1
  353. package/lib/node/profiling-run.js +1 -1
  354. package/lib/node/profiling-run.js.map +1 -1
  355. package/lib/node/rename-over-open-readers.d.ts +52 -0
  356. package/lib/node/rename-over-open-readers.d.ts.map +1 -0
  357. package/lib/node/rename-over-open-readers.js +66 -0
  358. package/lib/node/rename-over-open-readers.js.map +1 -0
  359. package/lib/node/socket-launcher.d.ts +16 -1
  360. package/lib/node/socket-launcher.d.ts.map +1 -1
  361. package/lib/node/socket-launcher.js +4 -3
  362. package/lib/node/socket-launcher.js.map +1 -1
  363. package/lib/node/stdio-launcher.d.ts +1 -1
  364. package/lib/node/stdio-launcher.d.ts.map +1 -1
  365. package/lib/node/stdio-launcher.js +1 -1
  366. package/lib/node/stdio-launcher.js.map +1 -1
  367. package/lib/testing/document-uri-policy-conformance.js.map +1 -1
  368. package/lib/testing/fake-description.js.map +1 -1
  369. package/lib/testing/fake-document.d.ts +16 -4
  370. package/lib/testing/fake-document.d.ts.map +1 -1
  371. package/lib/testing/fake-document.js +18 -3
  372. package/lib/testing/fake-document.js.map +1 -1
  373. package/lib/testing/index.d.ts.map +1 -1
  374. package/lib/testing/index.js +1 -0
  375. package/lib/testing/index.js.map +1 -1
  376. package/lib/testing/langium-test-helpers.d.ts.map +1 -1
  377. package/lib/testing/langium-test-helpers.js +1 -0
  378. package/lib/testing/langium-test-helpers.js.map +1 -1
  379. package/lib/testing/make-noop-language-services.js.map +1 -1
  380. package/lib/testing/make-noop-shared-services.d.ts +14 -0
  381. package/lib/testing/make-noop-shared-services.d.ts.map +1 -1
  382. package/lib/testing/make-noop-shared-services.js +28 -2
  383. package/lib/testing/make-noop-shared-services.js.map +1 -1
  384. package/lib/testing/make-test-services.d.ts +62 -14
  385. package/lib/testing/make-test-services.d.ts.map +1 -1
  386. package/lib/testing/make-test-services.js +30 -9
  387. package/lib/testing/make-test-services.js.map +1 -1
  388. package/lib/testing/make-test-tracer.js.map +1 -1
  389. package/lib/testing/node/golden-corpus.js.map +1 -1
  390. package/lib/testing/node/index.d.ts +1 -0
  391. package/lib/testing/node/index.d.ts.map +1 -1
  392. package/lib/testing/node/index.js +1 -0
  393. package/lib/testing/node/index.js.map +1 -1
  394. package/lib/testing/node/lsp-harness.d.ts.map +1 -1
  395. package/lib/testing/node/lsp-harness.js +2 -0
  396. package/lib/testing/node/lsp-harness.js.map +1 -1
  397. package/lib/testing/node/lsp-server-connection.d.ts +11 -3
  398. package/lib/testing/node/lsp-server-connection.d.ts.map +1 -1
  399. package/lib/testing/node/lsp-server-connection.js +42 -9
  400. package/lib/testing/node/lsp-server-connection.js.map +1 -1
  401. package/lib/testing/node/scratch-workspace.d.ts.map +1 -1
  402. package/lib/testing/node/scratch-workspace.js +10 -5
  403. package/lib/testing/node/scratch-workspace.js.map +1 -1
  404. package/lib/testing/node/spawned-server.d.ts +14 -0
  405. package/lib/testing/node/spawned-server.d.ts.map +1 -1
  406. package/lib/testing/node/spawned-server.js +33 -1
  407. package/lib/testing/node/spawned-server.js.map +1 -1
  408. package/lib/testing/node/unhandled-rejections.d.ts +20 -0
  409. package/lib/testing/node/unhandled-rejections.d.ts.map +1 -0
  410. package/lib/testing/node/unhandled-rejections.js +32 -0
  411. package/lib/testing/node/unhandled-rejections.js.map +1 -0
  412. package/lib/testing/playwright/browser-capture-bridge.js.map +1 -1
  413. package/lib/testing/playwright/e2e-profiling.js.map +1 -1
  414. package/lib/testing/playwright/flaky-network-proxy.d.ts +76 -0
  415. package/lib/testing/playwright/flaky-network-proxy.d.ts.map +1 -0
  416. package/lib/testing/playwright/flaky-network-proxy.js +164 -0
  417. package/lib/testing/playwright/flaky-network-proxy.js.map +1 -0
  418. package/lib/testing/playwright/index.d.ts +1 -0
  419. package/lib/testing/playwright/index.d.ts.map +1 -1
  420. package/lib/testing/playwright/index.js +1 -0
  421. package/lib/testing/playwright/index.js.map +1 -1
  422. package/lib/testing/playwright/server-log-capture.d.ts +14 -4
  423. package/lib/testing/playwright/server-log-capture.d.ts.map +1 -1
  424. package/lib/testing/playwright/server-log-capture.js +21 -4
  425. package/lib/testing/playwright/server-log-capture.js.map +1 -1
  426. package/lib/testing/playwright/server-log-rename-reporter.d.ts.map +1 -1
  427. package/lib/testing/playwright/server-log-rename-reporter.js +10 -1
  428. package/lib/testing/playwright/server-log-rename-reporter.js.map +1 -1
  429. package/lib/testing/run-update-pipeline.d.ts +4 -4
  430. package/lib/testing/run-update-pipeline.d.ts.map +1 -1
  431. package/lib/testing/stub-ast-document-manager.d.ts +10 -9
  432. package/lib/testing/stub-ast-document-manager.d.ts.map +1 -1
  433. package/lib/testing/stub-ast-document-manager.js +17 -9
  434. package/lib/testing/stub-ast-document-manager.js.map +1 -1
  435. package/lib/testing/stub-document-builder.d.ts +26 -11
  436. package/lib/testing/stub-document-builder.d.ts.map +1 -1
  437. package/lib/testing/stub-document-builder.js +57 -4
  438. package/lib/testing/stub-document-builder.js.map +1 -1
  439. package/lib/testing/stub-hydranium-text-documents.d.ts +22 -7
  440. package/lib/testing/stub-hydranium-text-documents.d.ts.map +1 -1
  441. package/lib/testing/stub-hydranium-text-documents.js +92 -15
  442. package/lib/testing/stub-hydranium-text-documents.js.map +1 -1
  443. package/lib/testing/stub-index-manager.js.map +1 -1
  444. package/lib/testing/stub-langium-documents.d.ts +3 -2
  445. package/lib/testing/stub-langium-documents.d.ts.map +1 -1
  446. package/lib/testing/stub-langium-documents.js.map +1 -1
  447. package/lib/testing/stub-model-service.d.ts +7 -6
  448. package/lib/testing/stub-model-service.d.ts.map +1 -1
  449. package/lib/testing/stub-model-service.js +4 -4
  450. package/lib/testing/stub-model-service.js.map +1 -1
  451. package/lib/testing/stub-project-manager.js.map +1 -1
  452. package/lib/testing/stub-service-registry.js.map +1 -1
  453. package/lib/util/connection-liveness.d.ts +7 -6
  454. package/lib/util/connection-liveness.d.ts.map +1 -1
  455. package/lib/util/connection-liveness.js +35 -14
  456. package/lib/util/connection-liveness.js.map +1 -1
  457. package/lib/util/environment.d.ts.map +1 -1
  458. package/lib/util/environment.js.map +1 -1
  459. package/lib/util/registry.d.ts.map +1 -1
  460. package/package.json +35 -26
  461. package/src/documents/ast-document-manager.ts +349 -65
  462. package/src/documents/client-ids.ts +5 -22
  463. package/src/documents/client-session-errors.ts +24 -0
  464. package/src/documents/client-session-registry.ts +240 -0
  465. package/src/documents/file-system-task-queue.ts +68 -0
  466. package/src/documents/hydranium-text-documents.ts +973 -202
  467. package/src/documents/index.ts +3 -0
  468. package/src/documents/language-client-text-shadow.ts +59 -11
  469. package/src/documents/self-save-registry.ts +52 -13
  470. package/src/index.ts +6 -0
  471. package/src/langium/ast-extension/ast-node-builder.ts +66 -22
  472. package/src/langium/bootstrap.ts +16 -9
  473. package/src/langium/config/configuration-provider.ts +119 -0
  474. package/src/langium/config/index.ts +1 -0
  475. package/src/langium/diagnostics/lsp-logger.ts +41 -6
  476. package/src/langium/document-builder/build-pipeline-integration.ts +50 -5
  477. package/src/langium/document-builder/build-session.ts +87 -0
  478. package/src/langium/document-builder/document-builder.ts +724 -46
  479. package/src/langium/document-builder/index.ts +1 -0
  480. package/src/langium/integration-services.ts +67 -6
  481. package/src/langium/integrity/integrity-rule.ts +13 -5
  482. package/src/langium/integrity/integrity-service.ts +229 -30
  483. package/src/langium/keys/containment.ts +87 -0
  484. package/src/langium/keys/index.ts +1 -0
  485. package/src/langium/keys/name-based-key-provider.ts +4 -0
  486. package/src/langium/language-module.ts +42 -4
  487. package/src/langium/model-service/client-session.ts +606 -0
  488. package/src/langium/model-service/index.ts +1 -0
  489. package/src/langium/model-service/model-service.ts +418 -399
  490. package/src/langium/module.ts +193 -64
  491. package/src/langium/naming/name-provider.ts +27 -5
  492. package/src/langium/naming/name-separator-validation.ts +34 -5
  493. package/src/langium/project/abstract-project-manager.ts +9 -1
  494. package/src/langium/project/project-change-event.ts +2 -2
  495. package/src/langium/residency/cst-residency-service.ts +36 -14
  496. package/src/langium/scope/hydranium-scope-provider.ts +60 -22
  497. package/src/langium/serialization/abstract-serializer.ts +13 -32
  498. package/src/langium/service-registry.ts +19 -2
  499. package/src/langium/shared-services.ts +19 -2
  500. package/src/langium/transfer/transfer-encoder.ts +85 -24
  501. package/src/langium/trivia/comment-preserver.ts +1100 -0
  502. package/src/langium/trivia/document-ending-preserver.ts +55 -0
  503. package/src/langium/trivia/index.ts +14 -0
  504. package/src/langium/trivia/trivia-contribution.ts +39 -0
  505. package/src/langium/trivia/trivia-preserver.ts +54 -0
  506. package/src/langium/trivia/trivia-service.ts +99 -0
  507. package/src/langium/update-rewrite/update-rewrite.ts +1 -1
  508. package/src/langium/validation/document-validator.ts +537 -11
  509. package/src/langium/workspace/document-uri-policy.ts +17 -12
  510. package/src/langium/workspace/file-not-found.ts +23 -0
  511. package/src/langium/workspace/file-system-provider.ts +153 -16
  512. package/src/langium/workspace/hydranium-langium-document-factory.ts +34 -0
  513. package/src/langium/workspace/hydranium-workspace-lock.ts +86 -2
  514. package/src/langium/workspace/hydranium-workspace-manager.ts +153 -13
  515. package/src/langium/workspace/in-memory-file-system-provider.ts +47 -16
  516. package/src/langium/workspace/initialize-workspace.ts +43 -5
  517. package/src/langium/workspace/langium-documents.ts +113 -33
  518. package/src/langium/workspace/persistent-file-system-provider.ts +0 -7
  519. package/src/langium/workspace/virtual-document.ts +96 -19
  520. package/src/langium/workspace/write-lock-scope.ts +24 -11
  521. package/src/locale/index.ts +10 -0
  522. package/src/locale/server-locale.ts +86 -0
  523. package/src/lsp/completion/hydranium-completion-provider.ts +82 -2
  524. package/src/lsp/connection-features.ts +67 -0
  525. package/src/lsp/diagnostics-connection.ts +56 -0
  526. package/src/lsp/hydranium-document-update-handler.ts +182 -106
  527. package/src/lsp/index.ts +3 -1
  528. package/src/lsp/lsp-latency.ts +62 -0
  529. package/src/lsp/semantic-token-provider.ts +74 -7
  530. package/src/lsp/shared-module.ts +4 -8
  531. package/src/lsp/start-language-server.ts +13 -7
  532. package/src/messages/carriers.ts +78 -0
  533. package/src/messages/index.ts +36 -0
  534. package/src/messages/renderer.ts +212 -0
  535. package/src/node/heap-ceiling.ts +108 -0
  536. package/src/node/index.ts +1 -0
  537. package/src/node/latency-from-env.ts +1 -1
  538. package/src/node/measure-memory.ts +1 -0
  539. package/src/node/node-file-system-provider.ts +122 -51
  540. package/src/node/profile-capture.ts +8 -2
  541. package/src/node/profiling-run.ts +3 -3
  542. package/src/node/rename-over-open-readers.ts +78 -0
  543. package/src/node/socket-launcher.ts +19 -4
  544. package/src/node/stdio-launcher.ts +1 -2
  545. package/src/testing/fake-document.ts +24 -5
  546. package/src/testing/index.ts +1 -0
  547. package/src/testing/langium-test-helpers.ts +1 -0
  548. package/src/testing/make-noop-shared-services.ts +50 -2
  549. package/src/testing/make-test-services.ts +106 -30
  550. package/src/testing/node/index.ts +1 -0
  551. package/src/testing/node/lsp-harness.ts +2 -0
  552. package/src/testing/node/lsp-server-connection.ts +61 -11
  553. package/src/testing/node/scratch-workspace.ts +10 -5
  554. package/src/testing/node/spawned-server.ts +35 -1
  555. package/src/testing/node/unhandled-rejections.ts +31 -0
  556. package/src/testing/playwright/flaky-network-proxy.ts +240 -0
  557. package/src/testing/playwright/index.ts +1 -0
  558. package/src/testing/playwright/server-log-capture.ts +24 -5
  559. package/src/testing/playwright/server-log-rename-reporter.ts +12 -1
  560. package/src/testing/run-update-pipeline.ts +4 -4
  561. package/src/testing/stub-ast-document-manager.ts +28 -21
  562. package/src/testing/stub-document-builder.ts +83 -17
  563. package/src/testing/stub-hydranium-text-documents.ts +127 -22
  564. package/src/testing/stub-langium-documents.ts +3 -2
  565. package/src/testing/stub-model-service.ts +9 -8
  566. package/src/util/connection-liveness.ts +37 -14
  567. package/src/util/environment.ts +9 -1
  568. package/lib/lsp/instrument-connection.d.ts +0 -36
  569. package/lib/lsp/instrument-connection.d.ts.map +0 -1
  570. package/lib/lsp/instrument-connection.js +0 -62
  571. package/lib/lsp/instrument-connection.js.map +0 -1
  572. package/src/lsp/instrument-connection.ts +0 -66
@@ -9,23 +9,32 @@
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,
15
16
  DocumentState,
16
17
  type LangiumDocument,
18
+ MultiMap,
17
19
  OperationCancelled,
18
20
  type URI,
19
21
  UriUtils,
22
+ type WorkspaceLock,
20
23
  interruptAndCheck,
21
24
  isOperationCancelled
22
25
  } from '@hydranium/langium';
23
- import { CancellationToken, type Diagnostic } from 'vscode-languageserver-protocol';
26
+ // `Diagnostic` as a VALUE: `renderDiagnostics` needs its `getMessageString`
27
+ // namespace helper to read the `string | MarkupContent` union without
28
+ // restating it.
29
+ import { CancellationToken, Diagnostic, Disposable } from 'vscode-languageserver-protocol';
24
30
  import { type LogNameOptions } from '../diagnostics/logger.js';
31
+ import type { MessageRenderer } from '../../messages/renderer.js';
25
32
  import { CST_REHYDRATION_RESET_STATE, isCstShed } from '../residency/cst-residency-service.js';
26
33
  import { type ExtendedServiceRegistry } from '../service-registry.js';
27
34
  import { type ServerSharedServicesMinimal } from '../shared-services.js';
28
35
  import { type DocumentUriPolicy } from '../workspace/document-uri-policy.js';
36
+ import { HydraniumWorkspaceLock } from '../workspace/hydranium-workspace-lock.js';
37
+ import { BuildSession, type BuildSessionContext } from './build-session.js';
29
38
  import { type LabeledPhaseListener, labelPhaseListener } from './labeled-phase-listener.js';
30
39
 
31
40
  /** Document states a phase-reached line is emitted for by default — every built phase. */
@@ -38,6 +47,20 @@ export const DEFAULT_LOGGED_PHASES: DocumentState[] = [
38
47
  DocumentState.Validated
39
48
  ];
40
49
 
50
+ /**
51
+ * The build reasons the framework stages through
52
+ * {@link HydraniumDocumentBuilder.markNextReason}: the LSP events the update
53
+ * handler dispatches on, and `didClose` for the revert the text store runs
54
+ * after a last close. Exposed so a subclass layering reasons of its own keeps
55
+ * the names the framework emits.
56
+ */
57
+ export const HYDRANIUM_BUILD_REASONS = Object.freeze({
58
+ didOpen: 'didOpen',
59
+ didChangeContent: 'didChangeContent',
60
+ didChangeWatchedFiles: 'didChangeWatchedFiles',
61
+ didClose: 'didClose'
62
+ } as const);
63
+
41
64
  /**
42
65
  * Consecutive re-queued builds that leave a waited-on document at the same state
43
66
  * before {@link HydraniumDocumentBuilder.awaitDocumentState} stops re-queuing it.
@@ -78,6 +101,18 @@ export interface DocumentBuilderOptions extends LogNameOptions {
78
101
  * logged. Default: `25`. Read per phase; accepts a {@link MaybeObservableValue}.
79
102
  */
80
103
  readonly slowBuildMs?: MaybeObservableValue<number>;
104
+ /**
105
+ * Build duration at or above which a build's phase-reached and slow-listener
106
+ * lines are emitted; they are held for the duration of the build and dropped
107
+ * when it finishes faster. Default `0` — no buffering, every line emitted as
108
+ * it is produced, which is the only setting that keeps lines interleaved with
109
+ * the rest of the log in real time.
110
+ *
111
+ * Set it to make a fast rebuild log nothing but its one build line. The
112
+ * decision needs the build's TOTAL duration, so it cannot be made by any
113
+ * per-line hook. Read once per build; accepts a {@link MaybeObservableValue}.
114
+ */
115
+ readonly phaseDetailMs?: MaybeObservableValue<number>;
81
116
  /**
82
117
  * Refresh cross-document `ComputedScopes` derivations when a referencing
83
118
  * document is cascade-rebuilt (see
@@ -91,29 +126,63 @@ export interface DocumentBuilderOptions extends LogNameOptions {
91
126
  readonly refreshCrossDocumentComputedScopes?: boolean;
92
127
  }
93
128
 
129
+ /**
130
+ * One locked build {@link HydraniumDocumentBuilder.scheduleUpdate} queued,
131
+ * which later requests merge into while it waits and join while it runs.
132
+ */
133
+ export interface ScheduledUpdate {
134
+ /** URIs to build, by URI string. Merged requests change it while the write is queued; fixed once it runs. */
135
+ readonly changed: Map<string, URI>;
136
+ /** URIs to delete, by URI string, under the same rule as {@link changed}. */
137
+ readonly deleted: Map<string, URI>;
138
+ /** The latest build reason any merged request gave; staged through {@link HydraniumDocumentBuilder.markNextReason} when the write runs. */
139
+ reason?: string;
140
+ /** The lock's {@link HydraniumWorkspaceLock.writeCancellations} right after this write was queued. */
141
+ readonly cancellations: number;
142
+ /**
143
+ * Set when the write starts to run, so its presence marks a running build:
144
+ * the text version of each changed URI the text store holds at that point.
145
+ */
146
+ takenVersions?: Map<string, number>;
147
+ /** The lock's promise for this write: settles when the build completes or is cancelled. */
148
+ readonly promise: Promise<void>;
149
+ }
150
+
94
151
  /**
95
152
  * Extends Langium's {@link DefaultDocumentBuilder} with:
96
153
  *
97
154
  * - **Bug-fixes** (always on): an {@link awaitDocumentState} that waits where
98
- * the default rejects, a {@link prepareBuild} that keeps a cancelled
155
+ * the default rejects (re-queuing, under the workspace lock, a document no
156
+ * build will carry), a {@link prepareBuild} that keeps a cancelled
99
157
  * non-validating build from suppressing validation, and a
100
158
  * {@link shouldRelink} that never judges a document unaffected on an index
101
159
  * that does not describe it.
160
+ * - **Shared locked builds** ({@link scheduleUpdate}): build requests that
161
+ * coincide share one locked build instead of cancelling each other.
102
162
  * - **URI handling** (always on): directory-aware flattening and cascade
103
163
  * deletes in {@link update}, plus the CST-rehydration and cross-document
104
164
  * refresh resets in {@link resetToState}.
105
165
  * - **In-place rebuild helpers** — {@link reparse} and
106
166
  * {@link reparseAndRelink} — for a build-phase listener that mutated a
107
167
  * document's AST and must reconcile it within the same build.
108
- * - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics}).
168
+ * - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics}), followed
169
+ * by the **one server-side message render** every head inherits
170
+ * ({@link renderDiagnostics}).
171
+ * - **Build sessions** ({@link BuildSession}): each `update` / `build` call is
172
+ * one correlated unit carrying an id, a trigger label, a start time and
173
+ * cancellation lineage, so every line of a rebuild reads as belonging to it
174
+ * and a preempted build is distinguishable from the winner.
109
175
  * - **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`.
176
+ * a per-build line, phase-reached lines, slow-listener breakdowns on
177
+ * `notifyDocumentPhase`, and slow-build-phase totals on `notifyBuildPhase`.
112
178
  *
113
179
  * Adopters extend this class — the configuration knobs cover what most
114
180
  * adopters need; the `format*Line` methods, `formatUri`, and
115
181
  * `collectDeletedURIs` are protected so subclasses can customise wording or
116
- * domain-aware cascades without re-implementing surrounding logic.
182
+ * domain-aware cascades without re-implementing surrounding logic. An adopter
183
+ * with build-scoped state of its own subclasses {@link BuildSession} and
184
+ * overrides {@link createBuildSession}, which puts that state under the same
185
+ * preemption-correct teardown rather than a reimplementation of it.
117
186
  */
118
187
  export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
119
188
  protected readonly tracer: Tracer;
@@ -127,8 +196,15 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
127
196
  protected readonly slowListenerMs: ObservableValue<number>;
128
197
  /** Live slow-build-phase-total threshold; read `.value` per phase. */
129
198
  protected readonly slowBuildMs: ObservableValue<number>;
199
+ /** Live phase-detail buffering threshold; read `.value` once per build, onto the session. */
200
+ protected readonly phaseDetailMs: ObservableValue<number>;
130
201
  protected readonly uriPolicy: DocumentUriPolicy;
131
202
  protected readonly clock: Clock;
203
+ protected readonly messageRenderer: MessageRenderer;
204
+ /** The lock {@link scheduleUpdate} builds under. */
205
+ protected readonly workspaceLock: WorkspaceLock;
206
+ /** The latest write {@link scheduleUpdate} queued, until it ends; see {@link ScheduledUpdate}. */
207
+ protected scheduledUpdate?: ScheduledUpdate;
132
208
  /** Narrower handle on the same registry as the inherited `serviceRegistry`, for {@link ExtendedServiceRegistry.registrations}. */
133
209
  protected readonly languageRegistry: ExtendedServiceRegistry;
134
210
  protected languageFileExtensions: string[] = [];
@@ -139,18 +215,43 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
139
215
  protected readonly refreshCrossDocumentComputedScopes: boolean;
140
216
  /** LSP event name (e.g. `'didChangeWatchedFiles'`) staged for the next `update()` call. */
141
217
  protected pendingUpdateReason?: string;
218
+ /**
219
+ * The build currently in progress, or `undefined` between builds.
220
+ *
221
+ * A subclass carrying its own build-scoped state returns a {@link BuildSession}
222
+ * subclass from {@link createBuildSession} and narrows this with a typeguard
223
+ * where it reads that state — rather than redeclaring the field, whose
224
+ * initialiser would run after `super()` and clear a session opened during
225
+ * construction.
226
+ */
227
+ protected activeSession?: BuildSession;
228
+ /**
229
+ * `traceId` of the last build that ended in cancellation, for the successor's
230
+ * "cancels #N" tag. Held here rather than on a session because the session
231
+ * that carries it is already gone by the time its successor is opened.
232
+ */
233
+ protected lastCancelledTraceId?: number;
234
+ /** Registered through {@link onDocumentPhaseDelivered}, by phase. */
235
+ protected readonly documentPhaseDeliveredListeners = new MultiMap<DocumentState, (document: LangiumDocument, version: number) => void>();
236
+ /** Registered through {@link onBuildEnded}. */
237
+ protected readonly buildEndedListeners = new Set<(drained: boolean) => void>();
238
+ /** Set while the lock read {@link checkWaitsOnceDrained} queued has not run. */
239
+ protected drainCheckQueued = false;
142
240
 
143
241
  constructor(services: ServerSharedServicesMinimal, options: DocumentBuilderOptions = {}) {
144
242
  super(services);
145
243
  this.languageRegistry = services.ServiceRegistry;
146
244
  this.uriPolicy = services.workspace.DocumentUriPolicy;
147
245
  this.clock = services.Clock;
246
+ this.messageRenderer = services.MessageRenderer;
247
+ this.workspaceLock = services.workspace.WorkspaceLock;
148
248
  this.tracer = services.Tracer.for(options.logName ?? 'DocumentBuilder').trace('instantiated');
149
249
  this.logLevel = options.logLevel ?? 'debug';
150
250
  this.loggedPhases = options.loggedPhases ?? DEFAULT_LOGGED_PHASES;
151
251
  this.slowPhaseMs = ObservableValue.from(options.slowPhaseMs ?? 25);
152
252
  this.slowListenerMs = ObservableValue.from(options.slowListenerMs ?? 5);
153
253
  this.slowBuildMs = ObservableValue.from(options.slowBuildMs ?? 25);
254
+ this.phaseDetailMs = ObservableValue.from(options.phaseDetailMs ?? 0);
154
255
  this.refreshCrossDocumentComputedScopes = options.refreshCrossDocumentComputedScopes ?? false;
155
256
  if (this.logLevel !== 'off') {
156
257
  this.registerPhaseListeners();
@@ -163,8 +264,8 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
163
264
 
164
265
  /**
165
266
  * 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.
267
+ * the update fires; `HydraniumDocumentUpdateHandler` does it for the LSP
268
+ * events, and the text store for the revert that follows a last close.
168
269
  *
169
270
  * The framework stages the value and never reads it back. The consumer is a
170
271
  * subclass overriding the build logging, which takes
@@ -176,6 +277,38 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
176
277
  this.pendingUpdateReason = reason;
177
278
  }
178
279
 
280
+ /**
281
+ * Call `listener` with a document once every {@link onDocumentPhase}
282
+ * listener of `state` ran for it and none was skipped by cancellation, and
283
+ * with the text version the phase listeners were called at. A write during
284
+ * them moves the document's own version on, past what they saw.
285
+ *
286
+ * Only here is it known what the phase listeners delivered. Langium sets the
287
+ * document's state before it notifies, and a cancel between two listeners
288
+ * skips the rest, leaving the document at the phase with those listeners
289
+ * never run and nothing to run them later. A build-phase listener comes too
290
+ * late: a cancel after this document but before the batch ends skips it,
291
+ * although every listener of this document ran.
292
+ */
293
+ onDocumentPhaseDelivered(state: DocumentState, listener: (document: LangiumDocument, version: number) => void): Disposable {
294
+ this.documentPhaseDeliveredListeners.add(state, listener);
295
+ return Disposable.create(() => this.documentPhaseDeliveredListeners.delete(state, listener));
296
+ }
297
+
298
+ /**
299
+ * Call `listener` with `drained` false once a build has run every phase
300
+ * ({@link buildDocuments}), and true once the lock has drained after a
301
+ * build that threw ({@link checkWaitsOnceDrained}); builds that throw
302
+ * before that drain share one call, so this does not count builds. A
303
+ * listener runs synchronously, inside the build or inside that check's lock
304
+ * read. A throw fails the finished build; in the read it skips the
305
+ * listeners after it and surfaces only as an unhandled rejection.
306
+ */
307
+ protected onBuildEnded(listener: (drained: boolean) => void): Disposable {
308
+ this.buildEndedListeners.add(listener);
309
+ return Disposable.create(() => this.buildEndedListeners.delete(listener));
310
+ }
311
+
179
312
  /**
180
313
  * Diagnostic snapshot for use in timeout/error messages around document
181
314
  * state.
@@ -193,7 +326,16 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
193
326
  const doc = this.langiumDocuments.getDocument(UriUtils.toUri(this.uriPolicy.canonicalUri(uri)));
194
327
  const docState = doc ? DocumentState[doc.state] : 'unknown (document not loaded)';
195
328
  const lastPhase = this.lastPhaseMs > 0 ? `${Math.round(performance.now() - this.lastPhaseMs)}ms ago` : 'no phase observed';
196
- return `current state: '${docState}', last phase: ${lastPhase}`;
329
+ return `current state: '${docState}', last phase: ${lastPhase}, active build: ${this.formatSession(this.activeSession)}`;
330
+ }
331
+
332
+ /** Render a session for a status line. `undefined` — no build in progress — reads as `none`. */
333
+ protected formatSession(session: BuildSession | undefined): string {
334
+ if (!session) {
335
+ return 'none';
336
+ }
337
+ const id = session.traceId !== undefined ? `#${session.traceId}` : 'untimed';
338
+ return `${id} (${session.trigger}, ${Math.round(performance.now() - session.startMs)}ms in)`;
197
339
  }
198
340
 
199
341
  // ============================================================
@@ -214,20 +356,36 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
214
356
  *
215
357
  * Replacing Langium's rejection with a wait makes the wait's liveness this
216
358
  * class's responsibility: a listener can only fire if some build is still
217
- * going to reach `state`. Both re-queue sites below exist for that, and they
218
- * differ only in when the orphaning is observed — {@link isOrphaned} at
219
- * registration time, the `onBuildPhase` branch for a build cancelled after
220
- * the wait was already armed. Re-queuing stops after
359
+ * going to reach `state`. So the wait re-queues the document whenever
360
+ * {@link isOrphaned} holds: once when it is armed, and again after every
361
+ * build that completes (see {@link buildDocuments}). The second check is
362
+ * the one a wait armed during a build needs, since only the build's end
363
+ * shows whether it left the document behind; Langium's `onBuildPhase` for
364
+ * `Validated` cannot serve, as it stays silent for a build that validates
365
+ * nothing, such as the workspace's initial one. A build that throws is
366
+ * checked once the lock drains instead (see {@link checkWaitsOnceDrained}):
367
+ * whatever cancelled it may build nothing. Re-queuing stops after
221
368
  * {@link MAX_STALLED_REQUEUES} builds that fail to advance the document, so a
222
369
  * document the builder will never carry to `state` degrades to a pending wait
223
370
  * plus a warning rather than an endless build loop.
371
+ *
372
+ * A wait for `Validated` on a document that a validating build skips
373
+ * resolves once that build has indexed its references, without diagnostics:
374
+ * see {@link skipsValidation}. Waiting on would never end, and re-queuing
375
+ * would skip it again.
376
+ *
377
+ * A re-queued build takes the {@link WorkspaceLock} (see
378
+ * {@link requeueOrphaned}), so a caller that awaits this wait while it holds
379
+ * the lock, inside a read or write action, deadlocks on a document that needs
380
+ * a re-queue: the build waits for that action to end. Await it outside the
381
+ * lock.
224
382
  */
225
383
  protected override awaitDocumentState(state: DocumentState, uri: URI, cancelToken: CancellationToken): Promise<URI> {
226
384
  const document = this.langiumDocuments.getDocument(uri);
227
385
  if (!document) {
228
386
  return super.awaitDocumentState(state, uri, cancelToken);
229
387
  }
230
- if (document.state >= state) {
388
+ if (document.state >= state || (state === DocumentState.Validated && this.skipsValidation(document))) {
231
389
  return Promise.resolve(uri);
232
390
  }
233
391
  return new Promise<URI>((resolve, reject) => {
@@ -267,34 +425,69 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
267
425
  }
268
426
  }, 'awaitDocumentState')
269
427
  );
270
- const buildDisposable = this.onBuildPhase(DocumentState.Validated, () => {
271
- if (document.state >= state) {
428
+ // The phase after which a validating build either validates the
429
+ // document or has skipped it.
430
+ const skipDisposable =
431
+ state === DocumentState.Validated
432
+ ? this.onDocumentPhase(
433
+ DocumentState.IndexedReferences,
434
+ labelPhaseListener((doc: LangiumDocument): void => {
435
+ if (UriUtils.equals(doc.uri, uri) && this.skipsValidation(doc)) {
436
+ cleanup();
437
+ resolve(doc.uri);
438
+ }
439
+ }, 'awaitDocumentState.skipsValidation')
440
+ )
441
+ : Disposable.create(() => undefined);
442
+ const buildEnded = (drained: boolean): void => {
443
+ if (document.state >= state || (state === DocumentState.Validated && this.skipsValidation(document))) {
272
444
  cleanup();
273
445
  resolve(uri);
274
- } else {
275
- // Orphaned by a cancelled build — re-queue so the next build catches it up.
276
- requeue('cancelled build');
446
+ } else if (drained ? this.activeSession === undefined : this.isOrphaned(document, state)) {
447
+ // No build is left to carry the document to `state`. Either
448
+ // check fails only while an unlocked build still runs; that
449
+ // build carries the document or ends here too.
450
+ requeue(drained ? 'build ended early' : 'build ended short of the target');
277
451
  }
278
- });
452
+ };
453
+ const buildDisposable = this.onBuildEnded(buildEnded);
279
454
  const cancelDisposable = cancelToken.onCancellationRequested(() => {
280
455
  cleanup();
281
456
  reject(OperationCancelled);
282
457
  });
283
458
  const cleanup = (): void => {
284
459
  phaseDisposable.dispose();
460
+ skipDisposable.dispose();
285
461
  buildDisposable.dispose();
286
462
  cancelDisposable.dispose();
287
463
  };
288
464
  // Orphaned BEFORE the wait was armed: the build that would have
289
- // advanced this document has already finished, so neither listener
290
- // above can ever fire. Re-queue now — the listeners are registered, so
291
- // the resulting build resolves this wait.
465
+ // advanced this document has already finished, so none of these
466
+ // listeners fires until some other build runs. Re-queue now — the listeners are
467
+ // registered, so the resulting build resolves this wait.
292
468
  if (this.isOrphaned(document, state)) {
293
469
  requeue('quiescent builder');
294
470
  }
295
471
  });
296
472
  }
297
473
 
474
+ /**
475
+ * Whether the build that carries or last carried `document` has indexed its
476
+ * references, asks for validation, and still skips it, which is an override
477
+ * of `shouldValidate` excluding it. A build that does not ask for
478
+ * validation, such as the workspace's initial one, is not a skip: the next
479
+ * validating build validates the document. Nor is a document below
480
+ * `IndexedReferences`: the build writes its options before the first phase,
481
+ * so the document would pass for skipped before it is even parsed.
482
+ */
483
+ protected skipsValidation(document: LangiumDocument): boolean {
484
+ return (
485
+ document.state >= DocumentState.IndexedReferences &&
486
+ Boolean(this.getBuildOptions(document).validation) &&
487
+ !this.shouldValidate(document)
488
+ );
489
+ }
490
+
298
491
  /**
299
492
  * Whether no build will advance `document` to `state`, so a wait on it can
300
493
  * only be resolved by starting one.
@@ -312,7 +505,9 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
312
505
  * `currentState` still advances to `Validated` (the validation phase runs
313
506
  * over an empty document list). Any first read that wants diagnostics — a
314
507
  * one-shot data-head read, a CLI query, `ModelService.validated` — lands
315
- * here.
508
+ * here. A read that arrives while that build still runs finds `currentState`
509
+ * below `state`, so this holds for it only once the build has ended, which
510
+ * is why {@link awaitDocumentState} asks again then.
316
511
  */
317
512
  protected isOrphaned(document: LangiumDocument, state: DocumentState): boolean {
318
513
  return document.state < state && this.currentState >= state;
@@ -324,13 +519,207 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
324
519
  * notification, so awaiting here would invert the dependency. A rejection is
325
520
  * logged rather than swallowed — it leaves the waiter pending until its own
326
521
  * cancellation token fires, which is worth a line in the log.
522
+ *
523
+ * The build is a {@link scheduleUpdate}, entered from a {@link WorkspaceLock}
524
+ * read. The read waits until no write runs or is queued, so the build neither
525
+ * runs beside a locked one nor cancels the build a re-queue is fired from.
526
+ * Unlocked, it runs beside a locked build that cannot cancel it: both
527
+ * validate the same version and deliver it twice. Taking the write directly,
528
+ * without the read, cancels the running build and skips the rest of its
529
+ * build-phase listeners. The read must not await the write, which queues
530
+ * behind that read. A build scheduled in the gap between the read batch
531
+ * starting and this action running is still queued, so the re-queue merges
532
+ * into it rather than cancelling it.
533
+ *
534
+ * A write that ran while the read waited may have carried the document to
535
+ * `state` already, and a second build would deliver that version again; the
536
+ * read skips the write then.
327
537
  */
328
538
  protected requeueOrphaned(document: LangiumDocument, state: DocumentState, reason: string): void {
329
539
  const tracer = this.tracer.withUri(document.uri.toString());
330
540
  tracer.info(`Re-queuing orphaned document (at '${DocumentState[document.state]}', needs '${DocumentState[state]}'): ${reason}`);
331
- this.update([document.uri], []).catch((err: unknown) => {
332
- if (!isOperationCancelled(err)) {
333
- tracer.error(`Re-queue build failed: ${err instanceof Error ? err.message : String(err)}`);
541
+ void this.workspaceLock.read(() => {
542
+ if (document.state >= state) {
543
+ return;
544
+ }
545
+ this.scheduleUpdate([document.uri], []).catch((err: unknown) => {
546
+ if (!isOperationCancelled(err)) {
547
+ tracer.error(`Re-queue build failed: ${err instanceof Error ? err.message : String(err)}`);
548
+ }
549
+ });
550
+ });
551
+ }
552
+
553
+ // ============================================================
554
+ // Scheduled updates — one locked build for requests that coincide
555
+ // ============================================================
556
+
557
+ /**
558
+ * Build `changed` and `deleted` under the {@link WorkspaceLock}, as
559
+ * `workspaceLock.write(token => update(changed, deleted, token))` would,
560
+ * except where the build this method queued last already carries the
561
+ * request. The promise settles when the build that carries the request
562
+ * ends, completed or cancelled, as the lock's own promise does.
563
+ *
564
+ * Without it, requests that coincide cancel each other: each lock write
565
+ * cancels the one before it, after Langium's `update` has already reset the
566
+ * documents, scanned the workspace for relinking and called every
567
+ * `onUpdate` listener.
568
+ *
569
+ * - **Queued, not yet running:** the request merges into it, so nothing is
570
+ * cancelled. The later of a change and a deletion of one URI wins, so
571
+ * each URI reaches `update` in one list only: a file deleted and written
572
+ * again before the build starts is a change.
573
+ * - **Running:** the request joins it only when {@link canJoinRunningUpdate}
574
+ * holds, which keeps an edit made while it runs cancelling it.
575
+ * - **Otherwise,** or when anything else has cancelled that write since it
576
+ * was queued, a new write, which cancels the running build as any lock
577
+ * write does.
578
+ *
579
+ * `reason` is staged through {@link markNextReason} when the write runs. The
580
+ * latest reason of a merged request wins, as it does in the update
581
+ * handler's own debounced burst; a joining request's reason is dropped, since
582
+ * the build it joins has already started. A request without one leaves a
583
+ * reason staged by the caller in place.
584
+ *
585
+ * A caller that must run code of its own inside the write action takes the
586
+ * lock itself, and forgoes the sharing. A lock that is not a
587
+ * {@link HydraniumWorkspaceLock} cannot report a cancelled queued write, so
588
+ * every request then takes its own write.
589
+ */
590
+ scheduleUpdate(changed: URI[], deleted: URI[], reason?: string): Promise<void> {
591
+ const lock = this.workspaceLock;
592
+ if (!(lock instanceof HydraniumWorkspaceLock)) {
593
+ return lock.write(token => {
594
+ if (reason !== undefined) {
595
+ this.markNextReason(reason);
596
+ }
597
+ return this.update(changed, deleted, token);
598
+ });
599
+ }
600
+ const scheduled = this.scheduledUpdate;
601
+ if (scheduled && scheduled.cancellations === lock.writeCancellations) {
602
+ if (!scheduled.takenVersions) {
603
+ for (const uri of changed) {
604
+ scheduled.changed.set(uri.toString(), uri);
605
+ scheduled.deleted.delete(uri.toString());
606
+ }
607
+ for (const uri of deleted) {
608
+ scheduled.deleted.set(uri.toString(), uri);
609
+ scheduled.changed.delete(uri.toString());
610
+ }
611
+ scheduled.reason = reason ?? scheduled.reason;
612
+ return scheduled.promise;
613
+ }
614
+ if (this.canJoinRunningUpdate(scheduled, changed, deleted)) {
615
+ return scheduled.promise;
616
+ }
617
+ }
618
+ // The action runs on a later tick, by which time `request` is assigned.
619
+ const promise = lock.write(token => this.runScheduledUpdate(request, token));
620
+ const request: ScheduledUpdate = {
621
+ changed: new Map(changed.map(uri => [uri.toString(), uri])),
622
+ deleted: new Map(deleted.map(uri => [uri.toString(), uri])),
623
+ reason,
624
+ cancellations: lock.writeCancellations,
625
+ promise
626
+ };
627
+ this.scheduledUpdate = request;
628
+ return promise;
629
+ }
630
+
631
+ /**
632
+ * Whether a request for `changed` and `deleted` is carried by the running
633
+ * `scheduled` build, whose write nothing has cancelled: the request deletes
634
+ * nothing, and each changed URI is one the build took, held by the text
635
+ * store at the version it had when the build started.
636
+ *
637
+ * Each condition keeps a request from joining a build that would miss its
638
+ * change. Text that moved since the start may be newer than what the build
639
+ * parsed; a URI the text store does not hold is read from its file, which
640
+ * may have changed after the build read it; and a deletion may concern a
641
+ * document the build has already built. A joined request is also absent
642
+ * from the running `update`'s `onUpdate` call, which reported the store as
643
+ * it was when the build started; at an unchanged version that is the store
644
+ * the request sees.
645
+ */
646
+ protected canJoinRunningUpdate(scheduled: ScheduledUpdate, changed: URI[], deleted: URI[]): boolean {
647
+ const taken = scheduled.takenVersions;
648
+ if (!taken || deleted.length > 0) {
649
+ return false;
650
+ }
651
+ return changed.every(uri => taken.has(uri.toString()) && taken.get(uri.toString()) === this.textDocuments?.get(uri)?.version);
652
+ }
653
+
654
+ /**
655
+ * The write action of a {@link scheduleUpdate}: freeze the request, record
656
+ * what it takes, stage its reason and run `update`. Releases
657
+ * {@link scheduledUpdate} inside the lock, whatever throws, so a request
658
+ * arriving after the build ends starts a write of its own rather than
659
+ * joining a build that is over.
660
+ */
661
+ protected async runScheduledUpdate(request: ScheduledUpdate, token: CancellationToken): Promise<void> {
662
+ try {
663
+ const taken = new Map<string, number>();
664
+ for (const [key, uri] of request.changed) {
665
+ const version = this.textDocuments?.get(uri)?.version;
666
+ if (version !== undefined) {
667
+ taken.set(key, version);
668
+ }
669
+ }
670
+ request.takenVersions = taken;
671
+ if (request.reason !== undefined) {
672
+ this.markNextReason(request.reason);
673
+ }
674
+ await this.update([...request.changed.values()], [...request.deleted.values()], token);
675
+ } finally {
676
+ if (this.scheduledUpdate === request) {
677
+ this.scheduledUpdate = undefined;
678
+ }
679
+ }
680
+ }
681
+
682
+ /**
683
+ * Tell the {@link buildEndedListeners} once every phase has run, which is
684
+ * the one point where a build that skipped a waited-on document can be seen
685
+ * to have ended. Langium's `onBuildPhase` for `Validated` is not: it stays
686
+ * silent when no document reached that phase, which is every build that
687
+ * validates nothing, the workspace's initial one among them.
688
+ *
689
+ * A build that throws, whether cancelled or failed, tells none of them
690
+ * here: `currentState` is then below `Validated`, so {@link isOrphaned}
691
+ * could hold for no wait. {@link checkWaitsOnceDrained} tells them instead.
692
+ */
693
+ protected override async buildDocuments(
694
+ documents: LangiumDocument[],
695
+ options: BuildOptions,
696
+ cancelToken: CancellationToken
697
+ ): Promise<void> {
698
+ await super.buildDocuments(documents, options, cancelToken);
699
+ for (const listener of [...this.buildEndedListeners]) {
700
+ listener(false);
701
+ }
702
+ }
703
+
704
+ /**
705
+ * After a build that threw, tell the {@link buildEndedListeners}, with
706
+ * `drained` set, from a {@link WorkspaceLock} read: it runs once no write
707
+ * runs or is queued, so no locked build is left that could still carry a
708
+ * waited-on document. A cancelled build is usually followed by its
709
+ * canceller's, but a write that builds nothing, such as a last-close revert
710
+ * that finds its document reopened, leaves a wait armed during the build
711
+ * with nothing to resolve it, and so does a build that fails. One read
712
+ * serves every build that throws before it runs.
713
+ */
714
+ protected checkWaitsOnceDrained(): void {
715
+ if (this.drainCheckQueued) {
716
+ return;
717
+ }
718
+ this.drainCheckQueued = true;
719
+ void this.workspaceLock.read(() => {
720
+ this.drainCheckQueued = false;
721
+ for (const listener of [...this.buildEndedListeners]) {
722
+ listener(true);
334
723
  }
335
724
  });
336
725
  }
@@ -409,7 +798,35 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
409
798
  this.ensureLanguageFileExtensions();
410
799
  const changedURIs = changed.flatMap(uri => this.flattenAndAdaptURI(uri));
411
800
  const deletedURIs = deleted.flatMap(uri => this.collectDeletedURIs(uri));
412
- return super.update(changedURIs, deletedURIs, cancelToken);
801
+ return this.runInSession(
802
+ {
803
+ kind: 'update',
804
+ trigger: this.buildTriggerLabel(changedURIs, deletedURIs),
805
+ triggerCountsDocs: changedURIs.length + deletedURIs.length !== 1,
806
+ changed: changedURIs,
807
+ deleted: deletedURIs
808
+ },
809
+ this.rebuildLabel(changedURIs, deletedURIs),
810
+ () => super.update(changedURIs, deletedURIs, cancelToken)
811
+ );
812
+ }
813
+
814
+ /**
815
+ * The workspace-initialization entry point, bracketed by a session like
816
+ * {@link update}. Langium's `update` reaches `buildDocuments` directly rather
817
+ * than through here, so the two never nest.
818
+ */
819
+ override build<T extends AstNode>(
820
+ documents: Array<LangiumDocument<T>>,
821
+ options?: BuildOptions,
822
+ cancelToken?: CancellationToken
823
+ ): Promise<void> {
824
+ const uris = documents.map(document => document.uri);
825
+ return this.runInSession(
826
+ { kind: 'build', trigger: `${documents.length} docs`, triggerCountsDocs: true, changed: uris, deleted: [] },
827
+ `Build documents (${documents.length} docs)`,
828
+ () => super.build(documents, options, cancelToken)
829
+ );
413
830
  }
414
831
 
415
832
  /**
@@ -556,13 +973,25 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
556
973
  * documents*: the Node provider walks the real filesystem (a freshly added
557
974
  * directory or never-opened file still builds), while a browser / empty
558
975
  * provider yields nothing. `uriPolicy.loadUri` first maps the URI to its
559
- * load identity — `undefined` (no on-disk content) short-circuits to `[]`
560
- * rather than a doomed read, and a symlink resolves to its real path so the
561
- * built documents key the same way every other layer does.
976
+ * load identity, and a symlink resolves to its real path so the built
977
+ * documents key the same way every other layer does.
978
+ *
979
+ * A URI with no on-disk content is dropped rather than read, unless the text
980
+ * store or the document registry holds it, under its canonical URI, the key
981
+ * both hold it by. A document created and not yet saved has text but no
982
+ * file, and a policy that checks the disk reports it absent. A registered
983
+ * document whose file has gone is kept too: its rebuild then fails on the
984
+ * read, which is how the revert on last close learns to remove it rather
985
+ * than leave it holding its last client's text.
562
986
  */
563
987
  protected flattenAndAdaptURI(uri: URI): URI[] {
564
988
  const resolved = this.uriPolicy.loadUri(uri);
565
- return resolved ? this.collectLanguageFiles(resolved) : [];
989
+ if (resolved) {
990
+ return this.collectLanguageFiles(resolved);
991
+ }
992
+ const canonical = UriUtils.toUri(this.uriPolicy.canonicalUri(uri));
993
+ const held = this.textDocuments?.get(canonical) !== undefined || this.langiumDocuments.hasDocument(canonical);
994
+ return held ? this.collectLanguageFiles(canonical) : [];
566
995
  }
567
996
 
568
997
  /** Recurse `uri` through the `FileSystemProvider`, gathering registered
@@ -615,6 +1044,151 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
615
1044
  ];
616
1045
  }
617
1046
 
1047
+ // ============================================================
1048
+ // Build sessions — one rebuild as a correlated unit
1049
+ // ============================================================
1050
+
1051
+ /**
1052
+ * Open a session, run `body` inside it, and close it — the bracket every
1053
+ * line of a rebuild is emitted within.
1054
+ *
1055
+ * The session is installed **synchronously**, before the timed body runs, so
1056
+ * that state a subclass computed in {@link createBuildSession} is already
1057
+ * readable by the time Langium's `update` consults `shouldRelink`.
1058
+ *
1059
+ * Teardown is preemption-correct, which is the reason this is framework code
1060
+ * rather than a recipe. A build outside the workspace lock overlaps another:
1061
+ * the later one installs itself as {@link activeSession} while the earlier
1062
+ * one is still running, and the earlier one's `finally` runs LAST. Clearing
1063
+ * unconditionally there would discard the later build's state mid-build.
1064
+ * Only the session that is still current clears — and the check is
1065
+ * reference equality on the session object,
1066
+ * not on {@link BuildSession.traceId}, which is `undefined` for every build
1067
+ * whenever the timing level is suppressed and would compare equal to itself
1068
+ * across two different builds.
1069
+ *
1070
+ * Builds outside the lock are not hypothetical even without an adopter: the
1071
+ * model service under `allowReentrantBuilds` starts one. Two locked builds
1072
+ * never overlap, since the lock starts a write only once the write it
1073
+ * cancelled has unwound.
1074
+ */
1075
+ protected runInSession(context: BuildSessionContext, label: string, body: () => Promise<void>): Promise<void> {
1076
+ // Read before installing the new session: the id being superseded belongs
1077
+ // to the OUTGOING build, or — when the previous one already finished
1078
+ // cancelled — to the id it parked for its successor.
1079
+ const supersededId = this.activeSession?.traceId ?? this.lastCancelledTraceId;
1080
+ this.lastCancelledTraceId = undefined;
1081
+ const reason = this.pendingUpdateReason;
1082
+ this.pendingUpdateReason = undefined;
1083
+ const tags: string[] = [];
1084
+ if (reason) {
1085
+ tags.push(`event: ${reason}`);
1086
+ }
1087
+ if (supersededId !== undefined) {
1088
+ tags.push(`cancels #${supersededId}`);
1089
+ }
1090
+
1091
+ const session = this.createBuildSession(context);
1092
+ this.activeSession = session;
1093
+ // A phase's "since previous phase" must measure from the build's start,
1094
+ // not from whenever the last build's final phase happened to land.
1095
+ this.lastPhaseMs = session.startMs;
1096
+ return this.tracer.time(
1097
+ label,
1098
+ async () => {
1099
+ try {
1100
+ await body();
1101
+ } catch (err: unknown) {
1102
+ if (isOperationCancelled(err)) {
1103
+ session.cancelled = true;
1104
+ }
1105
+ this.checkWaitsOnceDrained();
1106
+ throw err;
1107
+ } finally {
1108
+ this.endSession(session);
1109
+ }
1110
+ },
1111
+ this.logLevel,
1112
+ {
1113
+ logAfterMs: 0,
1114
+ forceMemoryAboveMs: session.buffers ? session.detailThresholdMs : undefined,
1115
+ captureId: id => {
1116
+ session.traceId = id;
1117
+ },
1118
+ tags
1119
+ }
1120
+ );
1121
+ }
1122
+
1123
+ /**
1124
+ * Construct the session for one build. Override to return a
1125
+ * {@link BuildSession} subclass carrying adopter build-scoped state — it is
1126
+ * called before the build body, so anything derived here is readable
1127
+ * throughout it.
1128
+ */
1129
+ protected createBuildSession(context: BuildSessionContext): BuildSession {
1130
+ return new BuildSession(performance.now(), context.trigger, context.triggerCountsDocs, this.phaseDetailMs.value);
1131
+ }
1132
+
1133
+ /**
1134
+ * Close `session`: flush what it buffered, then release it if it is still the
1135
+ * current one (see {@link runInSession} on why that check is conditional).
1136
+ * The flush is unconditional — a preempted build's lines still describe work
1137
+ * that happened.
1138
+ */
1139
+ protected endSession(session: BuildSession): void {
1140
+ this.flushSession(session);
1141
+ if (this.activeSession === session) {
1142
+ this.activeSession = undefined;
1143
+ if (session.cancelled) {
1144
+ this.lastCancelledTraceId = session.traceId;
1145
+ }
1146
+ }
1147
+ }
1148
+
1149
+ /**
1150
+ * Emit the lines `session` held back, if it ran long enough to be worth the
1151
+ * detail; drop them otherwise. Emits through {@link emit} rather than
1152
+ * {@link log}, which would route them straight back into the buffer.
1153
+ */
1154
+ protected flushSession(session: BuildSession): void {
1155
+ const elapsedMs = performance.now() - session.startMs;
1156
+ if (elapsedMs >= session.detailThresholdMs) {
1157
+ for (const line of session.bufferedLines) {
1158
+ this.emit(line);
1159
+ }
1160
+ }
1161
+ session.bufferedLines.length = 0;
1162
+ }
1163
+
1164
+ /** Label for the build's own log line. Override to customise wording. */
1165
+ protected rebuildLabel(changed: URI[], deleted: URI[]): string {
1166
+ if (changed.length === 0 && deleted.length === 0) {
1167
+ return 'Rebuild documents (nothing to do)';
1168
+ }
1169
+ if (changed.length === 1 && deleted.length === 0) {
1170
+ return `Rebuild document: ${this.formatUri(changed[0])}`;
1171
+ }
1172
+ if (changed.length === 0 && deleted.length === 1) {
1173
+ return `Rebuild after delete: ${this.formatUri(deleted[0])}`;
1174
+ }
1175
+ return `Rebuild documents (${changed.length} changed, ${deleted.length} deleted)`;
1176
+ }
1177
+
1178
+ /** Short description of what triggered the build, repeated on every phase line. Override to customise wording. */
1179
+ protected buildTriggerLabel(changed: URI[], deleted: URI[]): string {
1180
+ if (changed.length === 0 && deleted.length === 0) {
1181
+ return 'nothing';
1182
+ }
1183
+ if (changed.length === 1 && deleted.length === 0) {
1184
+ return this.formatUri(changed[0]);
1185
+ }
1186
+ if (changed.length === 0 && deleted.length === 1) {
1187
+ return `deleted ${this.formatUri(deleted[0])}`;
1188
+ }
1189
+ return `${changed.length} changed, ${deleted.length} deleted`;
1190
+ }
1191
+
618
1192
  // ============================================================
619
1193
  // Logging — phase-reached listeners
620
1194
  // ============================================================
@@ -630,17 +1204,39 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
630
1204
  const now = performance.now();
631
1205
  const elapsedMs = Math.round(now - this.lastPhaseMs);
632
1206
  this.lastPhaseMs = now;
1207
+ // Counted before the line is formatted, so the formatter stays a pure
1208
+ // function of state a caller can also set up in a test.
1209
+ if (this.activeSession) {
1210
+ this.activeSession.phasesLogged++;
1211
+ }
633
1212
  this.log(this.phaseReachedLine(state, documents, elapsedMs));
634
1213
  }
635
1214
 
636
- /** Format the phase-reached log line. Override to customise wording. */
1215
+ /**
1216
+ * Format the phase-reached log line. Override to customise wording.
1217
+ *
1218
+ * Within a session the line names what triggered the build, so a phase read
1219
+ * in isolation still says which rebuild it belongs to. `elapsedMs` is ignored
1220
+ * for the FIRST phase of a session: it measures from the previous build's
1221
+ * last phase, an idle gap that says nothing about this build.
1222
+ */
637
1223
  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]`;
1224
+ const session = this.activeSession;
1225
+ let docInfo: string;
1226
+ if (session) {
1227
+ docInfo = session.triggerCountsDocs ? `building ${session.trigger}` : `building ${session.trigger}, ${documents.length} docs`;
1228
+ } else {
1229
+ docInfo = documents.length === 1 ? this.formatUri(documents[0].uri) : `${documents.length} docs`;
1230
+ }
1231
+ const elapsedInfo =
1232
+ session && session.phasesLogged <= 1
1233
+ ? `${Math.round(performance.now() - session.startMs)}ms since build start`
1234
+ : `${elapsedMs}ms since previous phase`;
1235
+ return `Reached phase '${DocumentState[state]}' [${docInfo}, ${elapsedInfo}]`;
640
1236
  }
641
1237
 
642
1238
  // ============================================================
643
- // Logging — slow-listener breakdown on notifyDocumentPhase
1239
+ // notifyDocumentPhase — the delivery hook and the slow-listener breakdown
644
1240
  // ============================================================
645
1241
 
646
1242
  override async notifyDocumentPhase(document: LangiumDocument, state: DocumentState, cancelToken: CancellationToken): Promise<void> {
@@ -650,17 +1246,16 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
650
1246
  // replacing it, and the publisher reads that array when it is invoked. A
651
1247
  // build settling inside that window therefore appends after this call has
652
1248
  // already deduped, and the appended duplicate is published by the listener
653
- // of the build that deduped. Only `serializeBuilds` closes the window.
1249
+ // of the build that deduped. Only the write lock closes the window.
1250
+ //
1251
+ // Dedupe before rendering: rendering is deterministic, so it cannot
1252
+ // change which entries are structurally equal, and fewer survive to render.
654
1253
  if (state === DocumentState.Validated) {
655
1254
  this.dedupeDiagnostics(document);
656
- }
657
- if (this.logLevel === 'off') {
658
- return super.notifyDocumentPhase(document, state, cancelToken);
1255
+ this.renderDiagnostics(document);
659
1256
  }
660
1257
  const listeners = this.documentPhaseListeners.get(state).slice();
661
- if (listeners.length === 0) {
662
- return;
663
- }
1258
+ const version = document.textDocument.version;
664
1259
  const perListenerMs: number[] = [];
665
1260
  let cancelledListeners = 0;
666
1261
  const { elapsedMs: totalMs } = await this.clock.measure(async () => {
@@ -679,6 +1274,14 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
679
1274
  perListenerMs.push(elapsedMs);
680
1275
  }
681
1276
  });
1277
+ if (cancelledListeners === 0) {
1278
+ for (const delivered of this.documentPhaseDeliveredListeners.get(state).slice()) {
1279
+ delivered(document, version);
1280
+ }
1281
+ }
1282
+ if (this.logLevel === 'off' || listeners.length === 0) {
1283
+ return;
1284
+ }
682
1285
  if (cancelledListeners > 0) {
683
1286
  this.tracer
684
1287
  .withUri(document.uri.toString())
@@ -769,8 +1372,8 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
769
1372
  * twice: Langium's validate appends to `document.diagnostics` when they are
770
1373
  * already set — deliberately, so a category-partitioned pass keeps the earlier
771
1374
  * category's findings — and a repeated FULL pass therefore doubles the list.
772
- * `ModelServiceOptions.serializeBuilds` prevents that at the source; this is
773
- * the net for configurations that allow concurrent builds anyway.
1375
+ * The write lock prevents that at the source; this is the net for builds
1376
+ * that skip it, as `ModelServiceOptions.allowReentrantBuilds` lets one do.
774
1377
  *
775
1378
  * Clearing the list before a pass is NOT an alternative: the append happens at
776
1379
  * pass completion, so two interleaved passes both clear, both finish, and the
@@ -828,12 +1431,87 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
828
1431
  }
829
1432
  }
830
1433
 
1434
+ /**
1435
+ * Render every diagnostic on `document` through the bound message renderer,
1436
+ * in ONE pass over the finished list.
1437
+ *
1438
+ * All three heads read `document.diagnostics` — the LSP publish,
1439
+ * `TransferEncoder.toTransferDiagnostic` and the GLSP validation path — so
1440
+ * one pass here is what keeps the render from happening per head. It is also
1441
+ * the only placement that covers lexer and parser errors, which Langium
1442
+ * pushes onto the document without routing them through `toDiagnostic`.
1443
+ *
1444
+ * Running here rather than from a `Validated` phase listener needs no
1445
+ * ordering assumption: Langium publishes from `addDiagnosticsHandler`, a free
1446
+ * function it registers as such a listener, which can only be outrun.
1447
+ *
1448
+ * **It inherits {@link dedupeDiagnostics}'s window, and therefore the same
1449
+ * precondition.** A build settling inside the listener window appends
1450
+ * diagnostics this pass never saw, and the publisher of the build that
1451
+ * rendered sends them — unrendered. The write lock closes it, so "every
1452
+ * diagnostic is rendered" holds while
1453
+ * `ModelServiceOptions.allowReentrantBuilds` is `false`, its default.
1454
+ * Turning it on accepts unrendered diagnostics on exactly the terms it
1455
+ * already accepts duplicates.
1456
+ *
1457
+ * Entries are REPLACED rather than mutated: `sendDiagnostics` passes the
1458
+ * array by reference and serialises later, so an in-place message mutation
1459
+ * reaches the wire even when it runs after the publisher — which would make
1460
+ * a test for the ordering pass in either state.
1461
+ */
1462
+ protected renderDiagnostics(document: LangiumDocument): void {
1463
+ const diagnostics = document.diagnostics;
1464
+ if (!diagnostics || diagnostics.length === 0) {
1465
+ return;
1466
+ }
1467
+ let changed = false;
1468
+ // No try/catch: `renderDiagnostic` carries a no-throw contract, because an
1469
+ // error escaping this phase strands the document at `Validated` with
1470
+ // Langium's publisher never invoked.
1471
+ const rendered = diagnostics.map(diagnostic => {
1472
+ const text = this.messageRenderer.renderDiagnostic(diagnostic);
1473
+ // Against the message's STRING FORM, not the field. `renderDiagnostic`
1474
+ // answers a `string` by contract, while `Diagnostic.message` is
1475
+ // `string | MarkupContent` since LSP 3.17 — so comparing the answer
1476
+ // against the field never matches for a markup message, and a pass
1477
+ // that replaced on mismatch flattened every un-identified markup
1478
+ // diagnostic to its own plain text. That is silent data loss on the
1479
+ // path whose whole job is to leave such entries alone.
1480
+ if (text === Diagnostic.getMessageString(diagnostic)) {
1481
+ return diagnostic;
1482
+ }
1483
+ changed = true;
1484
+ return { ...diagnostic, message: text };
1485
+ });
1486
+ if (changed) {
1487
+ document.diagnostics = rendered;
1488
+ }
1489
+ }
1490
+
831
1491
  // ============================================================
832
1492
  // Internal helpers
833
1493
  // ============================================================
834
1494
 
835
- /** Dispatch a log line at the configured log level; a no-op when `logLevel === 'off'`. */
1495
+ /**
1496
+ * Dispatch a log line at the configured log level; a no-op when `logLevel ===
1497
+ * 'off'`.
1498
+ *
1499
+ * Held on the active session when it buffers, so the "was this build worth a
1500
+ * per-phase breakdown" decision — which needs the build's total duration, and
1501
+ * so cannot be taken by anything that runs while the lines are produced — is
1502
+ * deferred to {@link flushSession}.
1503
+ */
836
1504
  protected log(message: string): void {
1505
+ const session = this.activeSession;
1506
+ if (session?.buffers) {
1507
+ session.bufferedLines.push(message);
1508
+ return;
1509
+ }
1510
+ this.emit(message);
1511
+ }
1512
+
1513
+ /** Write a line out, bypassing session buffering. The single sink every framework log line reaches. */
1514
+ protected emit(message: string): void {
837
1515
  this.tracer.logAt(this.logLevel, message);
838
1516
  }
839
1517
  }