@hydranium/core 1.0.0-next.19 → 1.0.0-next.192

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 (588) hide show
  1. package/README.md +6 -2
  2. package/lib/documents/ast-document-manager.d.ts +204 -62
  3. package/lib/documents/ast-document-manager.d.ts.map +1 -1
  4. package/lib/documents/ast-document-manager.js +249 -83
  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 +523 -101
  23. package/lib/documents/hydranium-text-documents.d.ts.map +1 -1
  24. package/lib/documents/hydranium-text-documents.js +961 -177
  25. package/lib/documents/hydranium-text-documents.js.map +1 -1
  26. package/lib/documents/index.d.ts +5 -0
  27. package/lib/documents/index.d.ts.map +1 -1
  28. package/lib/documents/index.js +5 -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/model-ledger.d.ts +47 -0
  35. package/lib/documents/model-ledger.d.ts.map +1 -0
  36. package/lib/documents/model-ledger.js +30 -0
  37. package/lib/documents/model-ledger.js.map +1 -0
  38. package/lib/documents/self-save-registry.d.ts +37 -6
  39. package/lib/documents/self-save-registry.d.ts.map +1 -1
  40. package/lib/documents/self-save-registry.js +28 -15
  41. package/lib/documents/self-save-registry.js.map +1 -1
  42. package/lib/documents/version-sync-service.d.ts +134 -0
  43. package/lib/documents/version-sync-service.d.ts.map +1 -0
  44. package/lib/documents/version-sync-service.js +171 -0
  45. package/lib/documents/version-sync-service.js.map +1 -0
  46. package/lib/index.d.ts +3 -0
  47. package/lib/index.d.ts.map +1 -1
  48. package/lib/index.js +6 -0
  49. package/lib/index.js.map +1 -1
  50. package/lib/langium/ast-extension/ast-extension-service.d.ts.map +1 -1
  51. package/lib/langium/ast-extension/ast-extension-service.js.map +1 -1
  52. package/lib/langium/ast-extension/ast-node-builder.d.ts +32 -9
  53. package/lib/langium/ast-extension/ast-node-builder.d.ts.map +1 -1
  54. package/lib/langium/ast-extension/ast-node-builder.js +60 -22
  55. package/lib/langium/ast-extension/ast-node-builder.js.map +1 -1
  56. package/lib/langium/bootstrap.d.ts.map +1 -1
  57. package/lib/langium/bootstrap.js +32 -9
  58. package/lib/langium/bootstrap.js.map +1 -1
  59. package/lib/langium/build-phase-pass/build-phase-pass-service.d.ts.map +1 -1
  60. package/lib/langium/build-phase-pass/build-phase-pass-service.js.map +1 -1
  61. package/lib/langium/config/configuration-provider.d.ts +81 -0
  62. package/lib/langium/config/configuration-provider.d.ts.map +1 -0
  63. package/lib/langium/config/configuration-provider.js +112 -0
  64. package/lib/langium/config/configuration-provider.js.map +1 -0
  65. package/lib/langium/config/index.d.ts +1 -0
  66. package/lib/langium/config/index.d.ts.map +1 -1
  67. package/lib/langium/config/index.js +1 -0
  68. package/lib/langium/config/index.js.map +1 -1
  69. package/lib/langium/config/settings.js.map +1 -1
  70. package/lib/langium/diagnostics/hydranium-langium-profiler.d.ts.map +1 -1
  71. package/lib/langium/diagnostics/hydranium-langium-profiler.js.map +1 -1
  72. package/lib/langium/diagnostics/logger.d.ts +10 -3
  73. package/lib/langium/diagnostics/logger.d.ts.map +1 -1
  74. package/lib/langium/diagnostics/logger.js +12 -5
  75. package/lib/langium/diagnostics/logger.js.map +1 -1
  76. package/lib/langium/diagnostics/lsp-logger.d.ts +17 -0
  77. package/lib/langium/diagnostics/lsp-logger.d.ts.map +1 -1
  78. package/lib/langium/diagnostics/lsp-logger.js +56 -13
  79. package/lib/langium/diagnostics/lsp-logger.js.map +1 -1
  80. package/lib/langium/diagnostics/server-tracer.d.ts.map +1 -1
  81. package/lib/langium/diagnostics/server-tracer.js.map +1 -1
  82. package/lib/langium/document-builder/build-pipeline-integration.d.ts +21 -1
  83. package/lib/langium/document-builder/build-pipeline-integration.d.ts.map +1 -1
  84. package/lib/langium/document-builder/build-pipeline-integration.js +32 -5
  85. package/lib/langium/document-builder/build-pipeline-integration.js.map +1 -1
  86. package/lib/langium/document-builder/build-session.d.ts +93 -0
  87. package/lib/langium/document-builder/build-session.d.ts.map +1 -0
  88. package/lib/langium/document-builder/build-session.js +72 -0
  89. package/lib/langium/document-builder/build-session.js.map +1 -0
  90. package/lib/langium/document-builder/document-builder.d.ts +382 -29
  91. package/lib/langium/document-builder/document-builder.d.ts.map +1 -1
  92. package/lib/langium/document-builder/document-builder.js +659 -61
  93. package/lib/langium/document-builder/document-builder.js.map +1 -1
  94. package/lib/langium/document-builder/index.d.ts +1 -0
  95. package/lib/langium/document-builder/index.d.ts.map +1 -1
  96. package/lib/langium/document-builder/index.js +1 -0
  97. package/lib/langium/document-builder/index.js.map +1 -1
  98. package/lib/langium/documentation/comment-provider.d.ts.map +1 -1
  99. package/lib/langium/documentation/comment-provider.js.map +1 -1
  100. package/lib/langium/integration-services.d.ts +45 -1
  101. package/lib/langium/integration-services.d.ts.map +1 -1
  102. package/lib/langium/integration-services.js +10 -5
  103. package/lib/langium/integration-services.js.map +1 -1
  104. package/lib/langium/integrity/integrity-rule.d.ts +13 -5
  105. package/lib/langium/integrity/integrity-rule.d.ts.map +1 -1
  106. package/lib/langium/integrity/integrity-rule.js.map +1 -1
  107. package/lib/langium/integrity/integrity-service.d.ts +58 -13
  108. package/lib/langium/integrity/integrity-service.d.ts.map +1 -1
  109. package/lib/langium/integrity/integrity-service.js +204 -29
  110. package/lib/langium/integrity/integrity-service.js.map +1 -1
  111. package/lib/langium/keys/containment.d.ts +64 -0
  112. package/lib/langium/keys/containment.d.ts.map +1 -0
  113. package/lib/langium/keys/containment.js +53 -0
  114. package/lib/langium/keys/containment.js.map +1 -0
  115. package/lib/langium/keys/index.d.ts +1 -0
  116. package/lib/langium/keys/index.d.ts.map +1 -1
  117. package/lib/langium/keys/index.js +1 -0
  118. package/lib/langium/keys/index.js.map +1 -1
  119. package/lib/langium/keys/name-based-key-provider.d.ts +4 -0
  120. package/lib/langium/keys/name-based-key-provider.d.ts.map +1 -1
  121. package/lib/langium/keys/name-based-key-provider.js +4 -0
  122. package/lib/langium/keys/name-based-key-provider.js.map +1 -1
  123. package/lib/langium/keys/positional-key-provider.d.ts.map +1 -1
  124. package/lib/langium/keys/positional-key-provider.js.map +1 -1
  125. package/lib/langium/labeling/label-provider.d.ts.map +1 -1
  126. package/lib/langium/labeling/label-provider.js.map +1 -1
  127. package/lib/langium/language-module.d.ts +27 -2
  128. package/lib/langium/language-module.d.ts.map +1 -1
  129. package/lib/langium/language-module.js +16 -2
  130. package/lib/langium/language-module.js.map +1 -1
  131. package/lib/langium/model-service/client-session.d.ts +311 -0
  132. package/lib/langium/model-service/client-session.d.ts.map +1 -0
  133. package/lib/langium/model-service/client-session.js +398 -0
  134. package/lib/langium/model-service/client-session.js.map +1 -0
  135. package/lib/langium/model-service/index.d.ts +1 -0
  136. package/lib/langium/model-service/index.d.ts.map +1 -1
  137. package/lib/langium/model-service/index.js +1 -0
  138. package/lib/langium/model-service/index.js.map +1 -1
  139. package/lib/langium/model-service/model-service.d.ts +353 -253
  140. package/lib/langium/model-service/model-service.d.ts.map +1 -1
  141. package/lib/langium/model-service/model-service.js +361 -408
  142. package/lib/langium/model-service/model-service.js.map +1 -1
  143. package/lib/langium/module.d.ts +150 -35
  144. package/lib/langium/module.d.ts.map +1 -1
  145. package/lib/langium/module.js +50 -35
  146. package/lib/langium/module.js.map +1 -1
  147. package/lib/langium/naming/name-provider.d.ts +25 -4
  148. package/lib/langium/naming/name-provider.d.ts.map +1 -1
  149. package/lib/langium/naming/name-provider.js +2 -1
  150. package/lib/langium/naming/name-provider.js.map +1 -1
  151. package/lib/langium/naming/name-separator-validation.d.ts +23 -0
  152. package/lib/langium/naming/name-separator-validation.d.ts.map +1 -1
  153. package/lib/langium/naming/name-separator-validation.js +30 -1
  154. package/lib/langium/naming/name-separator-validation.js.map +1 -1
  155. package/lib/langium/project/abstract-project-manager.d.ts.map +1 -1
  156. package/lib/langium/project/abstract-project-manager.js +9 -2
  157. package/lib/langium/project/abstract-project-manager.js.map +1 -1
  158. package/lib/langium/project/project-change-event.d.ts +2 -2
  159. package/lib/langium/project/single-project-manager.d.ts.map +1 -1
  160. package/lib/langium/project/single-project-manager.js.map +1 -1
  161. package/lib/langium/residency/cst-residency-service.d.ts +31 -11
  162. package/lib/langium/residency/cst-residency-service.d.ts.map +1 -1
  163. package/lib/langium/residency/cst-residency-service.js +23 -57
  164. package/lib/langium/residency/cst-residency-service.js.map +1 -1
  165. package/lib/langium/scope/ast-node-description-provider.d.ts.map +1 -1
  166. package/lib/langium/scope/ast-node-description-provider.js.map +1 -1
  167. package/lib/langium/scope/hydranium-scope-computation.d.ts.map +1 -1
  168. package/lib/langium/scope/hydranium-scope-computation.js.map +1 -1
  169. package/lib/langium/scope/hydranium-scope-provider.d.ts +48 -13
  170. package/lib/langium/scope/hydranium-scope-provider.d.ts.map +1 -1
  171. package/lib/langium/scope/hydranium-scope-provider.js +56 -20
  172. package/lib/langium/scope/hydranium-scope-provider.js.map +1 -1
  173. package/lib/langium/scope/reference-builder.d.ts.map +1 -1
  174. package/lib/langium/scope/reference-builder.js.map +1 -1
  175. package/lib/langium/scope/reference-candidate-provider.d.ts.map +1 -1
  176. package/lib/langium/scope/reference-candidate-provider.js.map +1 -1
  177. package/lib/langium/scope/scope-extension-service.d.ts.map +1 -1
  178. package/lib/langium/scope/scope-extension-service.js.map +1 -1
  179. package/lib/langium/serialization/abstract-serializer.d.ts +11 -20
  180. package/lib/langium/serialization/abstract-serializer.d.ts.map +1 -1
  181. package/lib/langium/serialization/abstract-serializer.js +12 -21
  182. package/lib/langium/serialization/abstract-serializer.js.map +1 -1
  183. package/lib/langium/serialization/json-serializer.d.ts +1 -1
  184. package/lib/langium/serialization/json-serializer.d.ts.map +1 -1
  185. package/lib/langium/serialization/json-serializer.js.map +1 -1
  186. package/lib/langium/serialization/yaml-serializer.d.ts.map +1 -1
  187. package/lib/langium/serialization/yaml-serializer.js.map +1 -1
  188. package/lib/langium/service-registry.d.ts +15 -1
  189. package/lib/langium/service-registry.d.ts.map +1 -1
  190. package/lib/langium/service-registry.js +16 -0
  191. package/lib/langium/service-registry.js.map +1 -1
  192. package/lib/langium/shared-services.d.ts +21 -4
  193. package/lib/langium/shared-services.d.ts.map +1 -1
  194. package/lib/langium/shared-services.js.map +1 -1
  195. package/lib/langium/transfer/transfer-encoder.d.ts +75 -23
  196. package/lib/langium/transfer/transfer-encoder.d.ts.map +1 -1
  197. package/lib/langium/transfer/transfer-encoder.js +44 -21
  198. package/lib/langium/transfer/transfer-encoder.js.map +1 -1
  199. package/lib/langium/trivia/comment-preserver.d.ts +423 -0
  200. package/lib/langium/trivia/comment-preserver.d.ts.map +1 -0
  201. package/lib/langium/trivia/comment-preserver.js +906 -0
  202. package/lib/langium/trivia/comment-preserver.js.map +1 -0
  203. package/lib/langium/trivia/document-ending-preserver.d.ts +43 -0
  204. package/lib/langium/trivia/document-ending-preserver.d.ts.map +1 -0
  205. package/lib/langium/trivia/document-ending-preserver.js +48 -0
  206. package/lib/langium/trivia/document-ending-preserver.js.map +1 -0
  207. package/lib/langium/trivia/index.d.ts +14 -0
  208. package/lib/langium/trivia/index.d.ts.map +1 -0
  209. package/lib/langium/trivia/index.js +14 -0
  210. package/lib/langium/trivia/index.js.map +1 -0
  211. package/lib/langium/trivia/trivia-contribution.d.ts +37 -0
  212. package/lib/langium/trivia/trivia-contribution.d.ts.map +1 -0
  213. package/lib/langium/trivia/trivia-contribution.js +10 -0
  214. package/lib/langium/trivia/trivia-contribution.js.map +1 -0
  215. package/lib/langium/trivia/trivia-preserver.d.ts +50 -0
  216. package/lib/langium/trivia/trivia-preserver.d.ts.map +1 -0
  217. package/lib/langium/trivia/trivia-preserver.js +10 -0
  218. package/lib/langium/trivia/trivia-preserver.js.map +1 -0
  219. package/lib/langium/trivia/trivia-service.d.ts +70 -0
  220. package/lib/langium/trivia/trivia-service.d.ts.map +1 -0
  221. package/lib/langium/trivia/trivia-service.js +56 -0
  222. package/lib/langium/trivia/trivia-service.js.map +1 -0
  223. package/lib/langium/update-rewrite/normalize-empty-strings.d.ts.map +1 -1
  224. package/lib/langium/update-rewrite/update-rewrite-service.d.ts.map +1 -1
  225. package/lib/langium/update-rewrite/update-rewrite-service.js.map +1 -1
  226. package/lib/langium/update-rewrite/update-rewrite.d.ts +1 -1
  227. package/lib/langium/validation/document-validator.d.ts +294 -10
  228. package/lib/langium/validation/document-validator.d.ts.map +1 -1
  229. package/lib/langium/validation/document-validator.js +448 -5
  230. package/lib/langium/validation/document-validator.js.map +1 -1
  231. package/lib/langium/validation/validation-contribution-collector.d.ts.map +1 -1
  232. package/lib/langium/validation/validation-contribution-collector.js.map +1 -1
  233. package/lib/langium/workspace/document-uri-policy.d.ts +17 -12
  234. package/lib/langium/workspace/document-uri-policy.d.ts.map +1 -1
  235. package/lib/langium/workspace/document-uri-policy.js +10 -9
  236. package/lib/langium/workspace/document-uri-policy.js.map +1 -1
  237. package/lib/langium/workspace/file-not-found.d.ts +17 -0
  238. package/lib/langium/workspace/file-not-found.d.ts.map +1 -0
  239. package/lib/langium/workspace/file-not-found.js +20 -0
  240. package/lib/langium/workspace/file-not-found.js.map +1 -0
  241. package/lib/langium/workspace/file-system-provider.d.ts +84 -8
  242. package/lib/langium/workspace/file-system-provider.d.ts.map +1 -1
  243. package/lib/langium/workspace/file-system-provider.js +93 -14
  244. package/lib/langium/workspace/file-system-provider.js.map +1 -1
  245. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts +56 -1
  246. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts.map +1 -1
  247. package/lib/langium/workspace/hydranium-langium-document-factory.js +79 -0
  248. package/lib/langium/workspace/hydranium-langium-document-factory.js.map +1 -1
  249. package/lib/langium/workspace/hydranium-workspace-lock.d.ts +43 -1
  250. package/lib/langium/workspace/hydranium-workspace-lock.d.ts.map +1 -1
  251. package/lib/langium/workspace/hydranium-workspace-lock.js +58 -1
  252. package/lib/langium/workspace/hydranium-workspace-lock.js.map +1 -1
  253. package/lib/langium/workspace/hydranium-workspace-manager.d.ts +81 -8
  254. package/lib/langium/workspace/hydranium-workspace-manager.d.ts.map +1 -1
  255. package/lib/langium/workspace/hydranium-workspace-manager.js +128 -10
  256. package/lib/langium/workspace/hydranium-workspace-manager.js.map +1 -1
  257. package/lib/langium/workspace/in-memory-file-system-provider.d.ts +25 -2
  258. package/lib/langium/workspace/in-memory-file-system-provider.d.ts.map +1 -1
  259. package/lib/langium/workspace/in-memory-file-system-provider.js +41 -15
  260. package/lib/langium/workspace/in-memory-file-system-provider.js.map +1 -1
  261. package/lib/langium/workspace/index-manager.d.ts.map +1 -1
  262. package/lib/langium/workspace/index-manager.js.map +1 -1
  263. package/lib/langium/workspace/initialize-workspace.d.ts +31 -2
  264. package/lib/langium/workspace/initialize-workspace.d.ts.map +1 -1
  265. package/lib/langium/workspace/initialize-workspace.js +13 -5
  266. package/lib/langium/workspace/initialize-workspace.js.map +1 -1
  267. package/lib/langium/workspace/langium-documents.d.ts +86 -17
  268. package/lib/langium/workspace/langium-documents.d.ts.map +1 -1
  269. package/lib/langium/workspace/langium-documents.js +101 -29
  270. package/lib/langium/workspace/langium-documents.js.map +1 -1
  271. package/lib/langium/workspace/persistent-file-system-provider.d.ts +0 -7
  272. package/lib/langium/workspace/persistent-file-system-provider.d.ts.map +1 -1
  273. package/lib/langium/workspace/persistent-file-system-provider.js +0 -7
  274. package/lib/langium/workspace/persistent-file-system-provider.js.map +1 -1
  275. package/lib/langium/workspace/virtual-document.d.ts +48 -15
  276. package/lib/langium/workspace/virtual-document.d.ts.map +1 -1
  277. package/lib/langium/workspace/virtual-document.js +78 -18
  278. package/lib/langium/workspace/virtual-document.js.map +1 -1
  279. package/lib/langium/workspace/write-lock-scope.d.ts +20 -10
  280. package/lib/langium/workspace/write-lock-scope.d.ts.map +1 -1
  281. package/lib/langium/workspace/write-lock-scope.js +12 -4
  282. package/lib/langium/workspace/write-lock-scope.js.map +1 -1
  283. package/lib/locale/index.d.ts +10 -0
  284. package/lib/locale/index.d.ts.map +1 -0
  285. package/lib/locale/index.js +10 -0
  286. package/lib/locale/index.js.map +1 -0
  287. package/lib/locale/server-locale.d.ts +73 -0
  288. package/lib/locale/server-locale.d.ts.map +1 -0
  289. package/lib/locale/server-locale.js +61 -0
  290. package/lib/locale/server-locale.js.map +1 -0
  291. package/lib/lsp/completion/hydranium-completion-provider.d.ts +44 -2
  292. package/lib/lsp/completion/hydranium-completion-provider.d.ts.map +1 -1
  293. package/lib/lsp/completion/hydranium-completion-provider.js +68 -0
  294. package/lib/lsp/completion/hydranium-completion-provider.js.map +1 -1
  295. package/lib/lsp/connection-features.d.ts +23 -0
  296. package/lib/lsp/connection-features.d.ts.map +1 -0
  297. package/lib/lsp/connection-features.js +60 -0
  298. package/lib/lsp/connection-features.js.map +1 -0
  299. package/lib/lsp/diagnostics-connection.d.ts +27 -0
  300. package/lib/lsp/diagnostics-connection.d.ts.map +1 -0
  301. package/lib/lsp/diagnostics-connection.js +53 -0
  302. package/lib/lsp/diagnostics-connection.js.map +1 -0
  303. package/lib/lsp/hydranium-document-update-handler.d.ts +90 -79
  304. package/lib/lsp/hydranium-document-update-handler.d.ts.map +1 -1
  305. package/lib/lsp/hydranium-document-update-handler.js +153 -99
  306. package/lib/lsp/hydranium-document-update-handler.js.map +1 -1
  307. package/lib/lsp/index.d.ts +3 -1
  308. package/lib/lsp/index.d.ts.map +1 -1
  309. package/lib/lsp/index.js +3 -1
  310. package/lib/lsp/index.js.map +1 -1
  311. package/lib/lsp/lsp-latency.d.ts +39 -0
  312. package/lib/lsp/lsp-latency.d.ts.map +1 -0
  313. package/lib/lsp/lsp-latency.js +58 -0
  314. package/lib/lsp/lsp-latency.js.map +1 -0
  315. package/lib/lsp/semantic-token-provider.d.ts +34 -1
  316. package/lib/lsp/semantic-token-provider.d.ts.map +1 -1
  317. package/lib/lsp/semantic-token-provider.js +55 -8
  318. package/lib/lsp/semantic-token-provider.js.map +1 -1
  319. package/lib/lsp/shared-module.d.ts +4 -8
  320. package/lib/lsp/shared-module.d.ts.map +1 -1
  321. package/lib/lsp/shared-module.js.map +1 -1
  322. package/lib/lsp/start-language-server.d.ts +8 -7
  323. package/lib/lsp/start-language-server.d.ts.map +1 -1
  324. package/lib/lsp/start-language-server.js +13 -7
  325. package/lib/lsp/start-language-server.js.map +1 -1
  326. package/lib/messages/carriers.d.ts +54 -0
  327. package/lib/messages/carriers.d.ts.map +1 -0
  328. package/lib/messages/carriers.js +62 -0
  329. package/lib/messages/carriers.js.map +1 -0
  330. package/lib/messages/index.d.ts +25 -0
  331. package/lib/messages/index.d.ts.map +1 -0
  332. package/lib/messages/index.js +25 -0
  333. package/lib/messages/index.js.map +1 -0
  334. package/lib/messages/renderer.d.ts +142 -0
  335. package/lib/messages/renderer.d.ts.map +1 -0
  336. package/lib/messages/renderer.js +165 -0
  337. package/lib/messages/renderer.js.map +1 -0
  338. package/lib/node/event-loop-monitor.js.map +1 -1
  339. package/lib/node/heap-ceiling.d.ts +61 -0
  340. package/lib/node/heap-ceiling.d.ts.map +1 -0
  341. package/lib/node/heap-ceiling.js +72 -0
  342. package/lib/node/heap-ceiling.js.map +1 -0
  343. package/lib/node/index.d.ts +1 -0
  344. package/lib/node/index.d.ts.map +1 -1
  345. package/lib/node/index.js +1 -0
  346. package/lib/node/index.js.map +1 -1
  347. package/lib/node/latency-from-env.d.ts +1 -1
  348. package/lib/node/latency-from-env.js +1 -1
  349. package/lib/node/lint-grammar.js.map +1 -1
  350. package/lib/node/measure-memory.d.ts.map +1 -1
  351. package/lib/node/measure-memory.js +1 -0
  352. package/lib/node/measure-memory.js.map +1 -1
  353. package/lib/node/memory-monitor.js.map +1 -1
  354. package/lib/node/node-file-system-provider.d.ts +39 -4
  355. package/lib/node/node-file-system-provider.d.ts.map +1 -1
  356. package/lib/node/node-file-system-provider.js +109 -49
  357. package/lib/node/node-file-system-provider.js.map +1 -1
  358. package/lib/node/process-memory.js.map +1 -1
  359. package/lib/node/profile-capture.d.ts +8 -2
  360. package/lib/node/profile-capture.d.ts.map +1 -1
  361. package/lib/node/profile-capture.js.map +1 -1
  362. package/lib/node/profile-digest.js.map +1 -1
  363. package/lib/node/profiling-run.d.ts +13 -3
  364. package/lib/node/profiling-run.d.ts.map +1 -1
  365. package/lib/node/profiling-run.js +17 -8
  366. package/lib/node/profiling-run.js.map +1 -1
  367. package/lib/node/rename-over-open-readers.d.ts +52 -0
  368. package/lib/node/rename-over-open-readers.d.ts.map +1 -0
  369. package/lib/node/rename-over-open-readers.js +66 -0
  370. package/lib/node/rename-over-open-readers.js.map +1 -0
  371. package/lib/node/socket-launcher.d.ts +16 -1
  372. package/lib/node/socket-launcher.d.ts.map +1 -1
  373. package/lib/node/socket-launcher.js +4 -3
  374. package/lib/node/socket-launcher.js.map +1 -1
  375. package/lib/node/stdio-launcher.d.ts +1 -1
  376. package/lib/node/stdio-launcher.d.ts.map +1 -1
  377. package/lib/node/stdio-launcher.js +1 -1
  378. package/lib/node/stdio-launcher.js.map +1 -1
  379. package/lib/testing/document-uri-policy-conformance.js.map +1 -1
  380. package/lib/testing/fake-description.js.map +1 -1
  381. package/lib/testing/fake-document.d.ts +16 -4
  382. package/lib/testing/fake-document.d.ts.map +1 -1
  383. package/lib/testing/fake-document.js +18 -3
  384. package/lib/testing/fake-document.js.map +1 -1
  385. package/lib/testing/index.d.ts +1 -1
  386. package/lib/testing/index.d.ts.map +1 -1
  387. package/lib/testing/index.js +2 -1
  388. package/lib/testing/index.js.map +1 -1
  389. package/lib/testing/langium-test-helpers.d.ts.map +1 -1
  390. package/lib/testing/langium-test-helpers.js +1 -0
  391. package/lib/testing/langium-test-helpers.js.map +1 -1
  392. package/lib/testing/make-noop-language-services.js.map +1 -1
  393. package/lib/testing/make-noop-shared-services.d.ts +14 -0
  394. package/lib/testing/make-noop-shared-services.d.ts.map +1 -1
  395. package/lib/testing/make-noop-shared-services.js +28 -2
  396. package/lib/testing/make-noop-shared-services.js.map +1 -1
  397. package/lib/testing/make-test-services.d.ts +69 -14
  398. package/lib/testing/make-test-services.d.ts.map +1 -1
  399. package/lib/testing/make-test-services.js +39 -10
  400. package/lib/testing/make-test-services.js.map +1 -1
  401. package/lib/testing/make-test-tracer.js.map +1 -1
  402. package/lib/testing/node/golden-corpus.js.map +1 -1
  403. package/lib/testing/node/index.d.ts +1 -0
  404. package/lib/testing/node/index.d.ts.map +1 -1
  405. package/lib/testing/node/index.js +1 -0
  406. package/lib/testing/node/index.js.map +1 -1
  407. package/lib/testing/node/lsp-harness.d.ts.map +1 -1
  408. package/lib/testing/node/lsp-harness.js +2 -0
  409. package/lib/testing/node/lsp-harness.js.map +1 -1
  410. package/lib/testing/node/lsp-server-connection.d.ts +11 -3
  411. package/lib/testing/node/lsp-server-connection.d.ts.map +1 -1
  412. package/lib/testing/node/lsp-server-connection.js +42 -9
  413. package/lib/testing/node/lsp-server-connection.js.map +1 -1
  414. package/lib/testing/node/scratch-workspace.d.ts.map +1 -1
  415. package/lib/testing/node/scratch-workspace.js +10 -5
  416. package/lib/testing/node/scratch-workspace.js.map +1 -1
  417. package/lib/testing/node/spawned-server.d.ts +14 -0
  418. package/lib/testing/node/spawned-server.d.ts.map +1 -1
  419. package/lib/testing/node/spawned-server.js +33 -1
  420. package/lib/testing/node/spawned-server.js.map +1 -1
  421. package/lib/testing/node/unhandled-rejections.d.ts +20 -0
  422. package/lib/testing/node/unhandled-rejections.d.ts.map +1 -0
  423. package/lib/testing/node/unhandled-rejections.js +32 -0
  424. package/lib/testing/node/unhandled-rejections.js.map +1 -0
  425. package/lib/testing/playwright/browser-capture-bridge.js.map +1 -1
  426. package/lib/testing/playwright/e2e-profiling.js.map +1 -1
  427. package/lib/testing/playwright/flaky-network-proxy.d.ts +76 -0
  428. package/lib/testing/playwright/flaky-network-proxy.d.ts.map +1 -0
  429. package/lib/testing/playwright/flaky-network-proxy.js +164 -0
  430. package/lib/testing/playwright/flaky-network-proxy.js.map +1 -0
  431. package/lib/testing/playwright/index.d.ts +1 -0
  432. package/lib/testing/playwright/index.d.ts.map +1 -1
  433. package/lib/testing/playwright/index.js +1 -0
  434. package/lib/testing/playwright/index.js.map +1 -1
  435. package/lib/testing/playwright/server-log-capture.d.ts +24 -8
  436. package/lib/testing/playwright/server-log-capture.d.ts.map +1 -1
  437. package/lib/testing/playwright/server-log-capture.js +27 -6
  438. package/lib/testing/playwright/server-log-capture.js.map +1 -1
  439. package/lib/testing/playwright/server-log-rename-reporter.d.ts.map +1 -1
  440. package/lib/testing/playwright/server-log-rename-reporter.js +10 -1
  441. package/lib/testing/playwright/server-log-rename-reporter.js.map +1 -1
  442. package/lib/testing/run-update-pipeline.d.ts +4 -4
  443. package/lib/testing/run-update-pipeline.d.ts.map +1 -1
  444. package/lib/testing/stub-ast-document-manager.d.ts +11 -9
  445. package/lib/testing/stub-ast-document-manager.d.ts.map +1 -1
  446. package/lib/testing/stub-ast-document-manager.js +23 -9
  447. package/lib/testing/stub-ast-document-manager.js.map +1 -1
  448. package/lib/testing/stub-document-builder.d.ts +26 -11
  449. package/lib/testing/stub-document-builder.d.ts.map +1 -1
  450. package/lib/testing/stub-document-builder.js +57 -4
  451. package/lib/testing/stub-document-builder.js.map +1 -1
  452. package/lib/testing/stub-hydranium-text-documents.d.ts +22 -7
  453. package/lib/testing/stub-hydranium-text-documents.d.ts.map +1 -1
  454. package/lib/testing/stub-hydranium-text-documents.js +97 -15
  455. package/lib/testing/stub-hydranium-text-documents.js.map +1 -1
  456. package/lib/testing/stub-index-manager.js.map +1 -1
  457. package/lib/testing/stub-langium-documents.d.ts +3 -2
  458. package/lib/testing/stub-langium-documents.d.ts.map +1 -1
  459. package/lib/testing/stub-langium-documents.js.map +1 -1
  460. package/lib/testing/stub-model-service.d.ts +7 -6
  461. package/lib/testing/stub-model-service.d.ts.map +1 -1
  462. package/lib/testing/stub-model-service.js +4 -4
  463. package/lib/testing/stub-model-service.js.map +1 -1
  464. package/lib/testing/stub-project-manager.js.map +1 -1
  465. package/lib/testing/stub-service-registry.js.map +1 -1
  466. package/lib/util/connection-liveness.d.ts +7 -6
  467. package/lib/util/connection-liveness.d.ts.map +1 -1
  468. package/lib/util/connection-liveness.js +35 -14
  469. package/lib/util/connection-liveness.js.map +1 -1
  470. package/lib/util/environment.d.ts.map +1 -1
  471. package/lib/util/environment.js.map +1 -1
  472. package/lib/util/registry.d.ts.map +1 -1
  473. package/package.json +35 -26
  474. package/src/documents/ast-document-manager.ts +377 -125
  475. package/src/documents/client-ids.ts +5 -22
  476. package/src/documents/client-session-errors.ts +24 -0
  477. package/src/documents/client-session-registry.ts +240 -0
  478. package/src/documents/file-system-task-queue.ts +68 -0
  479. package/src/documents/hydranium-text-documents.ts +1175 -225
  480. package/src/documents/index.ts +5 -0
  481. package/src/documents/language-client-text-shadow.ts +59 -11
  482. package/src/documents/model-ledger.ts +66 -0
  483. package/src/documents/self-save-registry.ts +52 -13
  484. package/src/documents/version-sync-service.ts +267 -0
  485. package/src/index.ts +6 -0
  486. package/src/langium/ast-extension/ast-node-builder.ts +66 -22
  487. package/src/langium/bootstrap.ts +32 -9
  488. package/src/langium/config/configuration-provider.ts +119 -0
  489. package/src/langium/config/index.ts +1 -0
  490. package/src/langium/diagnostics/logger.ts +12 -5
  491. package/src/langium/diagnostics/lsp-logger.ts +58 -12
  492. package/src/langium/document-builder/build-pipeline-integration.ts +50 -5
  493. package/src/langium/document-builder/build-session.ts +87 -0
  494. package/src/langium/document-builder/document-builder.ts +776 -59
  495. package/src/langium/document-builder/index.ts +1 -0
  496. package/src/langium/integration-services.ts +67 -6
  497. package/src/langium/integrity/integrity-rule.ts +13 -5
  498. package/src/langium/integrity/integrity-service.ts +220 -30
  499. package/src/langium/keys/containment.ts +87 -0
  500. package/src/langium/keys/index.ts +1 -0
  501. package/src/langium/keys/name-based-key-provider.ts +4 -0
  502. package/src/langium/language-module.ts +42 -4
  503. package/src/langium/model-service/client-session.ts +614 -0
  504. package/src/langium/model-service/index.ts +1 -0
  505. package/src/langium/model-service/model-service.ts +570 -433
  506. package/src/langium/module.ts +201 -64
  507. package/src/langium/naming/name-provider.ts +27 -5
  508. package/src/langium/naming/name-separator-validation.ts +34 -5
  509. package/src/langium/project/abstract-project-manager.ts +9 -1
  510. package/src/langium/project/project-change-event.ts +2 -2
  511. package/src/langium/residency/cst-residency-service.ts +46 -15
  512. package/src/langium/scope/hydranium-scope-provider.ts +60 -22
  513. package/src/langium/serialization/abstract-serializer.ts +13 -32
  514. package/src/langium/service-registry.ts +19 -2
  515. package/src/langium/shared-services.ts +25 -4
  516. package/src/langium/transfer/transfer-encoder.ts +102 -34
  517. package/src/langium/trivia/comment-preserver.ts +1100 -0
  518. package/src/langium/trivia/document-ending-preserver.ts +55 -0
  519. package/src/langium/trivia/index.ts +14 -0
  520. package/src/langium/trivia/trivia-contribution.ts +39 -0
  521. package/src/langium/trivia/trivia-preserver.ts +54 -0
  522. package/src/langium/trivia/trivia-service.ts +99 -0
  523. package/src/langium/update-rewrite/update-rewrite.ts +1 -1
  524. package/src/langium/validation/document-validator.ts +537 -11
  525. package/src/langium/workspace/document-uri-policy.ts +17 -12
  526. package/src/langium/workspace/file-not-found.ts +23 -0
  527. package/src/langium/workspace/file-system-provider.ts +153 -16
  528. package/src/langium/workspace/hydranium-langium-document-factory.ts +117 -0
  529. package/src/langium/workspace/hydranium-workspace-lock.ts +86 -2
  530. package/src/langium/workspace/hydranium-workspace-manager.ts +153 -13
  531. package/src/langium/workspace/in-memory-file-system-provider.ts +47 -16
  532. package/src/langium/workspace/initialize-workspace.ts +43 -5
  533. package/src/langium/workspace/langium-documents.ts +124 -33
  534. package/src/langium/workspace/persistent-file-system-provider.ts +0 -7
  535. package/src/langium/workspace/virtual-document.ts +96 -19
  536. package/src/langium/workspace/write-lock-scope.ts +24 -11
  537. package/src/locale/index.ts +10 -0
  538. package/src/locale/server-locale.ts +86 -0
  539. package/src/lsp/completion/hydranium-completion-provider.ts +82 -2
  540. package/src/lsp/connection-features.ts +67 -0
  541. package/src/lsp/diagnostics-connection.ts +56 -0
  542. package/src/lsp/hydranium-document-update-handler.ts +185 -106
  543. package/src/lsp/index.ts +3 -1
  544. package/src/lsp/lsp-latency.ts +62 -0
  545. package/src/lsp/semantic-token-provider.ts +74 -7
  546. package/src/lsp/shared-module.ts +4 -8
  547. package/src/lsp/start-language-server.ts +13 -7
  548. package/src/messages/carriers.ts +78 -0
  549. package/src/messages/index.ts +36 -0
  550. package/src/messages/renderer.ts +212 -0
  551. package/src/node/heap-ceiling.ts +108 -0
  552. package/src/node/index.ts +1 -0
  553. package/src/node/latency-from-env.ts +1 -1
  554. package/src/node/measure-memory.ts +1 -0
  555. package/src/node/node-file-system-provider.ts +122 -51
  556. package/src/node/profile-capture.ts +8 -2
  557. package/src/node/profiling-run.ts +30 -8
  558. package/src/node/rename-over-open-readers.ts +78 -0
  559. package/src/node/socket-launcher.ts +19 -4
  560. package/src/node/stdio-launcher.ts +1 -2
  561. package/src/testing/fake-document.ts +24 -5
  562. package/src/testing/index.ts +2 -1
  563. package/src/testing/langium-test-helpers.ts +1 -0
  564. package/src/testing/make-noop-shared-services.ts +50 -2
  565. package/src/testing/make-test-services.ts +120 -31
  566. package/src/testing/node/index.ts +1 -0
  567. package/src/testing/node/lsp-harness.ts +2 -0
  568. package/src/testing/node/lsp-server-connection.ts +61 -11
  569. package/src/testing/node/scratch-workspace.ts +10 -5
  570. package/src/testing/node/spawned-server.ts +35 -1
  571. package/src/testing/node/unhandled-rejections.ts +31 -0
  572. package/src/testing/playwright/flaky-network-proxy.ts +240 -0
  573. package/src/testing/playwright/index.ts +1 -0
  574. package/src/testing/playwright/server-log-capture.ts +45 -11
  575. package/src/testing/playwright/server-log-rename-reporter.ts +12 -1
  576. package/src/testing/run-update-pipeline.ts +4 -4
  577. package/src/testing/stub-ast-document-manager.ts +37 -22
  578. package/src/testing/stub-document-builder.ts +83 -17
  579. package/src/testing/stub-hydranium-text-documents.ts +133 -23
  580. package/src/testing/stub-langium-documents.ts +3 -2
  581. package/src/testing/stub-model-service.ts +9 -8
  582. package/src/util/connection-liveness.ts +37 -14
  583. package/src/util/environment.ts +9 -1
  584. package/lib/lsp/instrument-connection.d.ts +0 -36
  585. package/lib/lsp/instrument-connection.d.ts.map +0 -1
  586. package/lib/lsp/instrument-connection.js +0 -62
  587. package/lib/lsp/instrument-connection.js.map +0 -1
  588. package/src/lsp/instrument-connection.ts +0 -66
@@ -7,9 +7,14 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
  import { ObservableValue } from '@hydranium/protocol';
10
- import { DefaultDocumentBuilder, DocumentState, OperationCancelled, UriUtils, interruptAndCheck, isOperationCancelled } from '@hydranium/langium';
11
- import { CancellationToken } from 'vscode-languageserver-protocol';
10
+ import { DefaultDocumentBuilder, DocumentState, MultiMap, OperationCancelled, URI, UriUtils, interruptAndCheck, isOperationCancelled } from '@hydranium/langium';
11
+ // `Diagnostic` as a VALUE: `renderDiagnostics` needs its `getMessageString`
12
+ // namespace helper to read the `string | MarkupContent` union without
13
+ // restating it.
14
+ import { CancellationToken, Diagnostic, Disposable } from 'vscode-languageserver-protocol';
12
15
  import { CST_REHYDRATION_RESET_STATE, isCstShed } from '../residency/cst-residency-service.js';
16
+ import { HydraniumWorkspaceLock } from '../workspace/hydranium-workspace-lock.js';
17
+ import { BuildSession } from './build-session.js';
13
18
  import { labelPhaseListener } from './labeled-phase-listener.js';
14
19
  /** Document states a phase-reached line is emitted for by default — every built phase. */
15
20
  export const DEFAULT_LOGGED_PHASES = [
@@ -20,6 +25,19 @@ export const DEFAULT_LOGGED_PHASES = [
20
25
  DocumentState.IndexedReferences,
21
26
  DocumentState.Validated
22
27
  ];
28
+ /**
29
+ * The build reasons the framework stages through
30
+ * {@link HydraniumDocumentBuilder.markNextReason}: the LSP events the update
31
+ * handler dispatches on, and `didClose` for the revert the text store runs
32
+ * after a last close. Exposed so a subclass layering reasons of its own keeps
33
+ * the names the framework emits.
34
+ */
35
+ export const HYDRANIUM_BUILD_REASONS = Object.freeze({
36
+ didOpen: 'didOpen',
37
+ didChangeContent: 'didChangeContent',
38
+ didChangeWatchedFiles: 'didChangeWatchedFiles',
39
+ didClose: 'didClose'
40
+ });
23
41
  /**
24
42
  * Consecutive re-queued builds that leave a waited-on document at the same state
25
43
  * before {@link HydraniumDocumentBuilder.awaitDocumentState} stops re-queuing it.
@@ -32,25 +50,37 @@ const MAX_STALLED_REQUEUES = 3;
32
50
  * Extends Langium's {@link DefaultDocumentBuilder} with:
33
51
  *
34
52
  * - **Bug-fixes** (always on): an {@link awaitDocumentState} that waits where
35
- * the default rejects, a {@link prepareBuild} that keeps a cancelled
53
+ * the default rejects (re-queuing, under the workspace lock, a document no
54
+ * build will carry), a {@link prepareBuild} that keeps a cancelled
36
55
  * non-validating build from suppressing validation, and a
37
56
  * {@link shouldRelink} that never judges a document unaffected on an index
38
57
  * that does not describe it.
58
+ * - **Shared locked builds** ({@link scheduleUpdate}): build requests that
59
+ * coincide share one locked build instead of cancelling each other.
39
60
  * - **URI handling** (always on): directory-aware flattening and cascade
40
61
  * deletes in {@link update}, plus the CST-rehydration and cross-document
41
62
  * refresh resets in {@link resetToState}.
42
63
  * - **In-place rebuild helpers** — {@link reparse} and
43
64
  * {@link reparseAndRelink} — for a build-phase listener that mutated a
44
65
  * document's AST and must reconcile it within the same build.
45
- * - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics}).
66
+ * - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics}), followed
67
+ * by the **one server-side message render** every head inherits
68
+ * ({@link renderDiagnostics}).
69
+ * - **Build sessions** ({@link BuildSession}): each `update` / `build` call is
70
+ * one correlated unit carrying an id, a trigger label, a start time and
71
+ * cancellation lineage, so every line of a rebuild reads as belonging to it
72
+ * and a preempted build is distinguishable from the winner.
46
73
  * - **Logging instrumentation** (default on, opt-out via `logLevel: 'off'`):
47
- * phase-reached lines, slow-listener breakdowns on `notifyDocumentPhase`,
48
- * and slow-build-phase totals on `notifyBuildPhase`.
74
+ * a per-build line, phase-reached lines, slow-listener breakdowns on
75
+ * `notifyDocumentPhase`, and slow-build-phase totals on `notifyBuildPhase`.
49
76
  *
50
77
  * Adopters extend this class — the configuration knobs cover what most
51
78
  * adopters need; the `format*Line` methods, `formatUri`, and
52
79
  * `collectDeletedURIs` are protected so subclasses can customise wording or
53
- * domain-aware cascades without re-implementing surrounding logic.
80
+ * domain-aware cascades without re-implementing surrounding logic. An adopter
81
+ * with build-scoped state of its own subclasses {@link BuildSession} and
82
+ * overrides {@link createBuildSession}, which puts that state under the same
83
+ * preemption-correct teardown rather than a reimplementation of it.
54
84
  */
55
85
  export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
56
86
  tracer;
@@ -64,8 +94,15 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
64
94
  slowListenerMs;
65
95
  /** Live slow-build-phase-total threshold; read `.value` per phase. */
66
96
  slowBuildMs;
97
+ /** Live phase-detail buffering threshold; read `.value` once per build, onto the session. */
98
+ phaseDetailMs;
67
99
  uriPolicy;
68
100
  clock;
101
+ messageRenderer;
102
+ /** The lock {@link scheduleUpdate} builds under. */
103
+ workspaceLock;
104
+ /** The latest write {@link scheduleUpdate} queued, until it ends; see {@link ScheduledUpdate}. */
105
+ scheduledUpdate;
69
106
  /** Narrower handle on the same registry as the inherited `serviceRegistry`, for {@link ExtendedServiceRegistry.registrations}. */
70
107
  languageRegistry;
71
108
  languageFileExtensions = [];
@@ -76,17 +113,45 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
76
113
  refreshCrossDocumentComputedScopes;
77
114
  /** LSP event name (e.g. `'didChangeWatchedFiles'`) staged for the next `update()` call. */
78
115
  pendingUpdateReason;
116
+ /**
117
+ * The build currently in progress, or `undefined` between builds.
118
+ *
119
+ * A subclass carrying its own build-scoped state returns a {@link BuildSession}
120
+ * subclass from {@link createBuildSession} and narrows this with a typeguard
121
+ * where it reads that state — rather than redeclaring the field, whose
122
+ * initialiser would run after `super()` and clear a session opened during
123
+ * construction.
124
+ */
125
+ activeSession;
126
+ /**
127
+ * `traceId` of the last build that ended in cancellation, for the successor's
128
+ * "cancels #N" tag. Held here rather than on a session because the session
129
+ * that carries it is already gone by the time its successor is opened.
130
+ */
131
+ lastCancelledTraceId;
132
+ /** Registered through {@link onDocumentPhaseDelivered}, by phase. */
133
+ documentPhaseDeliveredListeners = new MultiMap();
134
+ /** Registered through {@link onBuildEnded}. */
135
+ buildEndedListeners = new Set();
136
+ /** Set while the lock read {@link checkWaitsOnceDrained} queued has not run. */
137
+ drainCheckQueued = false;
138
+ /** Resolved per call: the sync service reaches this builder. */
139
+ versionSyncService;
79
140
  constructor(services, options = {}) {
80
141
  super(services);
81
142
  this.languageRegistry = services.ServiceRegistry;
82
143
  this.uriPolicy = services.workspace.DocumentUriPolicy;
83
144
  this.clock = services.Clock;
145
+ this.messageRenderer = services.MessageRenderer;
146
+ this.workspaceLock = services.workspace.WorkspaceLock;
147
+ this.versionSyncService = () => services.workspace.VersionSyncService;
84
148
  this.tracer = services.Tracer.for(options.logName ?? 'DocumentBuilder').trace('instantiated');
85
149
  this.logLevel = options.logLevel ?? 'debug';
86
150
  this.loggedPhases = options.loggedPhases ?? DEFAULT_LOGGED_PHASES;
87
151
  this.slowPhaseMs = ObservableValue.from(options.slowPhaseMs ?? 25);
88
152
  this.slowListenerMs = ObservableValue.from(options.slowListenerMs ?? 5);
89
153
  this.slowBuildMs = ObservableValue.from(options.slowBuildMs ?? 25);
154
+ this.phaseDetailMs = ObservableValue.from(options.phaseDetailMs ?? 0);
90
155
  this.refreshCrossDocumentComputedScopes = options.refreshCrossDocumentComputedScopes ?? false;
91
156
  if (this.logLevel !== 'off') {
92
157
  this.registerPhaseListeners();
@@ -97,8 +162,8 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
97
162
  // ============================================================
98
163
  /**
99
164
  * Stage an LSP event name for the next `update()` call. Adopters call before
100
- * the update fires; `HydraniumDocumentUpdateHandler` does it for the
101
- * four LSP events.
165
+ * the update fires; `HydraniumDocumentUpdateHandler` does it for the LSP
166
+ * events, and the text store for the revert that follows a last close.
102
167
  *
103
168
  * The framework stages the value and never reads it back. The consumer is a
104
169
  * subclass overriding the build logging, which takes
@@ -109,6 +174,36 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
109
174
  markNextReason(reason) {
110
175
  this.pendingUpdateReason = reason;
111
176
  }
177
+ /**
178
+ * Call `listener` with a document once every {@link onDocumentPhase}
179
+ * listener of `state` ran for it and none was skipped by cancellation, and
180
+ * with the text version the phase listeners were called at. A write during
181
+ * them moves the document's own version on, past what they saw.
182
+ *
183
+ * Only here is it known what the phase listeners delivered. Langium sets the
184
+ * document's state before it notifies, and a cancel between two listeners
185
+ * skips the rest, leaving the document at the phase with those listeners
186
+ * never run and nothing to run them later. A build-phase listener comes too
187
+ * late: a cancel after this document but before the batch ends skips it,
188
+ * although every listener of this document ran.
189
+ */
190
+ onDocumentPhaseDelivered(state, listener) {
191
+ this.documentPhaseDeliveredListeners.add(state, listener);
192
+ return Disposable.create(() => this.documentPhaseDeliveredListeners.delete(state, listener));
193
+ }
194
+ /**
195
+ * Call `listener` with `drained` false once a build has run every phase
196
+ * ({@link buildDocuments}), and true once the lock has drained after a
197
+ * build that threw ({@link checkWaitsOnceDrained}); builds that throw
198
+ * before that drain share one call, so this does not count builds. A
199
+ * listener runs synchronously, inside the build or inside that check's lock
200
+ * read. A throw fails the finished build; in the read it skips the
201
+ * listeners after it and surfaces only as an unhandled rejection.
202
+ */
203
+ onBuildEnded(listener) {
204
+ this.buildEndedListeners.add(listener);
205
+ return Disposable.create(() => this.buildEndedListeners.delete(listener));
206
+ }
112
207
  /**
113
208
  * Diagnostic snapshot for use in timeout/error messages around document
114
209
  * state.
@@ -126,11 +221,21 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
126
221
  const doc = this.langiumDocuments.getDocument(UriUtils.toUri(this.uriPolicy.canonicalUri(uri)));
127
222
  const docState = doc ? DocumentState[doc.state] : 'unknown (document not loaded)';
128
223
  const lastPhase = this.lastPhaseMs > 0 ? `${Math.round(performance.now() - this.lastPhaseMs)}ms ago` : 'no phase observed';
129
- return `current state: '${docState}', last phase: ${lastPhase}`;
224
+ return `current state: '${docState}', last phase: ${lastPhase}, active build: ${this.formatSession(this.activeSession)}`;
225
+ }
226
+ /** Render a session for a status line. `undefined` — no build in progress — reads as `none`. */
227
+ formatSession(session) {
228
+ if (!session) {
229
+ return 'none';
230
+ }
231
+ const id = session.traceId !== undefined ? `#${session.traceId}` : 'untimed';
232
+ return `${id} (${session.trigger}, ${Math.round(performance.now() - session.startMs)}ms in)`;
233
+ }
234
+ waitUntil(state, uriOrToken, cancelToken, options = {}) {
235
+ return URI.isUri(uriOrToken)
236
+ ? this.awaitDocumentState(state, uriOrToken, cancelToken ?? CancellationToken.None, options)
237
+ : super.waitUntil(state, uriOrToken);
130
238
  }
131
- // ============================================================
132
- // Bug-fixes (always on)
133
- // ============================================================
134
239
  /**
135
240
  * Two edge cases the default Langium implementation rejects on:
136
241
  * - Document below target state with no build active (newly-created file):
@@ -145,20 +250,38 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
145
250
  *
146
251
  * Replacing Langium's rejection with a wait makes the wait's liveness this
147
252
  * class's responsibility: a listener can only fire if some build is still
148
- * going to reach `state`. Both re-queue sites below exist for that, and they
149
- * differ only in when the orphaning is observed — {@link isOrphaned} at
150
- * registration time, the `onBuildPhase` branch for a build cancelled after
151
- * the wait was already armed. Re-queuing stops after
253
+ * going to reach `state`. So the wait re-queues the document whenever
254
+ * {@link isOrphaned} holds: once when it is armed, and again after every
255
+ * build that completes (see {@link buildDocuments}). The second check is
256
+ * the one a wait armed during a build needs, since only the build's end
257
+ * shows whether it left the document behind; Langium's `onBuildPhase` for
258
+ * `Validated` cannot serve, as it stays silent for a build that validates
259
+ * nothing, such as the workspace's initial one. A build that throws is
260
+ * checked once the lock drains instead (see {@link checkWaitsOnceDrained}):
261
+ * whatever cancelled it may build nothing. Re-queuing stops after
152
262
  * {@link MAX_STALLED_REQUEUES} builds that fail to advance the document, so a
153
263
  * document the builder will never carry to `state` degrades to a pending wait
154
- * plus a warning rather than an endless build loop.
264
+ * plus a warning rather than an endless build loop. With `rejectWhenStuck`,
265
+ * the wait rejects instead, both then and once
266
+ * `VersionSyncService.requestRecoveryBuild` gives up a re-queued build.
267
+ *
268
+ * A wait for `Validated` on a document that a validating build skips
269
+ * resolves once that build has indexed its references, without diagnostics:
270
+ * see {@link skipsValidation}. Waiting on would never end, and re-queuing
271
+ * would skip it again.
272
+ *
273
+ * A re-queued build takes the {@link WorkspaceLock} (see
274
+ * {@link requeueOrphaned}), so a caller that awaits this wait while it holds
275
+ * the lock, inside a read or write action, deadlocks on a document that needs
276
+ * a re-queue: the build waits for that action to end. Await it outside the
277
+ * lock.
155
278
  */
156
- awaitDocumentState(state, uri, cancelToken) {
279
+ awaitDocumentState(state, uri, cancelToken, { rejectWhenStuck = false } = {}) {
157
280
  const document = this.langiumDocuments.getDocument(uri);
158
281
  if (!document) {
159
282
  return super.awaitDocumentState(state, uri, cancelToken);
160
283
  }
161
- if (document.state >= state) {
284
+ if (document.state >= state || (state === DocumentState.Validated && this.skipsValidation(document))) {
162
285
  return Promise.resolve(uri);
163
286
  }
164
287
  return new Promise((resolve, reject) => {
@@ -171,14 +294,23 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
171
294
  // land while a busy workspace keeps cancelling builds.
172
295
  let stalledRequeues = 0;
173
296
  let lastRequeueState;
297
+ const giveUp = (reason) => {
298
+ cleanup();
299
+ reject(new Error(`Gave up building ${this.formatUri(uri)} to '${DocumentState[state]}' ` +
300
+ `(at '${DocumentState[document.state]}'): ${reason}`));
301
+ };
174
302
  const requeue = (reason) => {
175
303
  if (document.state === lastRequeueState) {
176
304
  if (++stalledRequeues > MAX_STALLED_REQUEUES) {
305
+ const stalled = `${stalledRequeues} builds did not advance it`;
306
+ if (rejectWhenStuck) {
307
+ giveUp(stalled);
308
+ return;
309
+ }
177
310
  this.tracer
178
311
  .withUri(uri.toString())
179
312
  .warn(`Giving up re-queuing ${this.formatUri(uri)}: stuck at '${DocumentState[document.state]}', needs ` +
180
- `'${DocumentState[state]}' after ${stalledRequeues} builds that did not advance it. ` +
181
- 'The wait now depends on its cancellation token.');
313
+ `'${DocumentState[state]}' after ${stalled}. The wait now depends on its cancellation token.`);
182
314
  return;
183
315
  }
184
316
  }
@@ -186,7 +318,11 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
186
318
  stalledRequeues = 0;
187
319
  lastRequeueState = document.state;
188
320
  }
189
- this.requeueOrphaned(document, state, reason);
321
+ void this.requeueOrphaned(document, state, reason).then(built => {
322
+ if (!built && rejectWhenStuck) {
323
+ giveUp('its recovery build failed');
324
+ }
325
+ });
190
326
  };
191
327
  const phaseDisposable = this.onDocumentPhase(state, labelPhaseListener((doc) => {
192
328
  if (UriUtils.equals(doc.uri, uri)) {
@@ -194,34 +330,64 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
194
330
  resolve(doc.uri);
195
331
  }
196
332
  }, 'awaitDocumentState'));
197
- const buildDisposable = this.onBuildPhase(DocumentState.Validated, () => {
198
- if (document.state >= state) {
333
+ // The phase after which a validating build either validates the
334
+ // document or has skipped it.
335
+ const skipDisposable = state === DocumentState.Validated
336
+ ? this.onDocumentPhase(DocumentState.IndexedReferences, labelPhaseListener((doc) => {
337
+ if (UriUtils.equals(doc.uri, uri) && this.skipsValidation(doc)) {
338
+ cleanup();
339
+ resolve(doc.uri);
340
+ }
341
+ }, 'awaitDocumentState.skipsValidation'))
342
+ : Disposable.create(() => undefined);
343
+ const buildEnded = (drained) => {
344
+ if (document.state >= state || (state === DocumentState.Validated && this.skipsValidation(document))) {
199
345
  cleanup();
200
346
  resolve(uri);
201
347
  }
202
- else {
203
- // Orphaned by a cancelled build — re-queue so the next build catches it up.
204
- requeue('cancelled build');
348
+ else if (drained ? this.activeSession === undefined : this.isOrphaned(document, state)) {
349
+ // No build is left to carry the document to `state`. Either
350
+ // check fails only while an unlocked build still runs; that
351
+ // build carries the document or ends here too.
352
+ requeue(drained ? 'build ended early' : 'build ended short of the target');
205
353
  }
206
- });
354
+ };
355
+ const buildDisposable = this.onBuildEnded(buildEnded);
207
356
  const cancelDisposable = cancelToken.onCancellationRequested(() => {
208
357
  cleanup();
209
358
  reject(OperationCancelled);
210
359
  });
211
360
  const cleanup = () => {
212
361
  phaseDisposable.dispose();
362
+ skipDisposable.dispose();
213
363
  buildDisposable.dispose();
214
364
  cancelDisposable.dispose();
215
365
  };
216
366
  // Orphaned BEFORE the wait was armed: the build that would have
217
- // advanced this document has already finished, so neither listener
218
- // above can ever fire. Re-queue now — the listeners are registered, so
219
- // the resulting build resolves this wait.
220
- if (this.isOrphaned(document, state)) {
367
+ // advanced this document has already finished, so none of these
368
+ // listeners fires until some other build runs. Re-queue now — the listeners are
369
+ // registered, so the resulting build resolves this wait.
370
+ // With `rejectWhenStuck`, also a document a failed build left behind:
371
+ // no build ends to re-queue it, so the wait would never give up.
372
+ if (this.isOrphaned(document, state) || (rejectWhenStuck && this.activeSession === undefined)) {
221
373
  requeue('quiescent builder');
222
374
  }
223
375
  });
224
376
  }
377
+ /**
378
+ * Whether the build that carries or last carried `document` has indexed its
379
+ * references, asks for validation, and still skips it, which is an override
380
+ * of `shouldValidate` excluding it. A build that does not ask for
381
+ * validation, such as the workspace's initial one, is not a skip: the next
382
+ * validating build validates the document. Nor is a document below
383
+ * `IndexedReferences`: the build writes its options before the first phase,
384
+ * so the document would pass for skipped before it is even parsed.
385
+ */
386
+ skipsValidation(document) {
387
+ return (document.state >= DocumentState.IndexedReferences &&
388
+ Boolean(this.getBuildOptions(document).validation) &&
389
+ !this.shouldValidate(document));
390
+ }
225
391
  /**
226
392
  * Whether no build will advance `document` to `state`, so a wait on it can
227
393
  * only be resolved by starting one.
@@ -239,24 +405,193 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
239
405
  * `currentState` still advances to `Validated` (the validation phase runs
240
406
  * over an empty document list). Any first read that wants diagnostics — a
241
407
  * one-shot data-head read, a CLI query, `ModelService.validated` — lands
242
- * here.
408
+ * here. A read that arrives while that build still runs finds `currentState`
409
+ * below `state`, so this holds for it only once the build has ended, which
410
+ * is why {@link awaitDocumentState} asks again then.
243
411
  */
244
412
  isOrphaned(document, state) {
245
413
  return document.state < state && this.currentState >= state;
246
414
  }
247
415
  /**
248
- * Schedule a build for a document no in-flight build will advance. Deliberately
249
- * fire-and-forget: the caller is a waiter that resolves off the resulting phase
250
- * notification, so awaiting here would invert the dependency. A rejection is
251
- * logged rather than swallowed — it leaves the waiter pending until its own
252
- * cancellation token fires, which is worth a line in the log.
416
+ * Schedule a build for a document no in-flight build will advance, through
417
+ * `VersionSyncService.requestRecoveryBuild`: from a {@link WorkspaceLock} read, so
418
+ * the build neither runs beside a locked one nor cancels the build a
419
+ * re-queue is fired from, and skipped if a write that ran meanwhile carried
420
+ * the document to `state`. The waiter resolves off the resulting phase
421
+ * notification; the answer only tells it whether the build was given up.
253
422
  */
254
423
  requeueOrphaned(document, state, reason) {
255
424
  const tracer = this.tracer.withUri(document.uri.toString());
256
425
  tracer.info(`Re-queuing orphaned document (at '${DocumentState[document.state]}', needs '${DocumentState[state]}'): ${reason}`);
257
- this.update([document.uri], []).catch((err) => {
258
- if (!isOperationCancelled(err)) {
259
- tracer.error(`Re-queue build failed: ${err instanceof Error ? err.message : String(err)}`);
426
+ return this.versionSyncService().requestRecoveryBuild(document.uri, {
427
+ // Skipped on purpose: a waiting caller is answered sooner, at the cost
428
+ // of a possible duplicate build once the debounce fires.
429
+ ignoreDeferred: true,
430
+ stillNeeded: () => document.state < state
431
+ });
432
+ }
433
+ // ============================================================
434
+ // Scheduled updates — one locked build for requests that coincide
435
+ // ============================================================
436
+ /**
437
+ * Build `changed` and `deleted` under the {@link WorkspaceLock}, as
438
+ * `workspaceLock.write(token => update(changed, deleted, token))` would,
439
+ * except where the build this method queued last already carries the
440
+ * request. The promise settles when the build that carries the request
441
+ * ends, completed or cancelled, as the lock's own promise does.
442
+ *
443
+ * Without it, requests that coincide cancel each other: each lock write
444
+ * cancels the one before it, after Langium's `update` has already reset the
445
+ * documents, scanned the workspace for relinking and called every
446
+ * `onUpdate` listener.
447
+ *
448
+ * - **Queued, not yet running:** the request merges into it, so nothing is
449
+ * cancelled. The later of a change and a deletion of one URI wins, so
450
+ * each URI reaches `update` in one list only: a file deleted and written
451
+ * again before the build starts is a change.
452
+ * - **Running:** the request joins it only when {@link canJoinRunningUpdate}
453
+ * holds, which keeps an edit made while it runs cancelling it.
454
+ * - **Otherwise,** or when anything else has cancelled that write since it
455
+ * was queued, a new write, which cancels the running build as any lock
456
+ * write does.
457
+ *
458
+ * `reason` is staged through {@link markNextReason} when the write runs. The
459
+ * latest reason of a merged request wins, as it does in the update
460
+ * handler's own debounced burst; a joining request's reason is dropped, since
461
+ * the build it joins has already started. A request without one leaves a
462
+ * reason staged by the caller in place.
463
+ *
464
+ * A caller that must run code of its own inside the write action takes the
465
+ * lock itself, and forgoes the sharing. A lock that is not a
466
+ * {@link HydraniumWorkspaceLock} cannot report a cancelled queued write, so
467
+ * every request then takes its own write.
468
+ */
469
+ scheduleUpdate(changed, deleted, reason) {
470
+ const lock = this.workspaceLock;
471
+ if (!(lock instanceof HydraniumWorkspaceLock)) {
472
+ return lock.write(token => {
473
+ if (reason !== undefined) {
474
+ this.markNextReason(reason);
475
+ }
476
+ return this.update(changed, deleted, token);
477
+ });
478
+ }
479
+ const scheduled = this.scheduledUpdate;
480
+ if (scheduled && scheduled.cancellations === lock.writeCancellations) {
481
+ if (!scheduled.takenVersions) {
482
+ for (const uri of changed) {
483
+ scheduled.changed.set(uri.toString(), uri);
484
+ scheduled.deleted.delete(uri.toString());
485
+ }
486
+ for (const uri of deleted) {
487
+ scheduled.deleted.set(uri.toString(), uri);
488
+ scheduled.changed.delete(uri.toString());
489
+ }
490
+ scheduled.reason = reason ?? scheduled.reason;
491
+ return scheduled.promise;
492
+ }
493
+ if (this.canJoinRunningUpdate(scheduled, changed, deleted)) {
494
+ return scheduled.promise;
495
+ }
496
+ }
497
+ // The action runs on a later tick, by which time `request` is assigned.
498
+ const promise = lock.write(token => this.runScheduledUpdate(request, token));
499
+ const request = {
500
+ changed: new Map(changed.map(uri => [uri.toString(), uri])),
501
+ deleted: new Map(deleted.map(uri => [uri.toString(), uri])),
502
+ reason,
503
+ cancellations: lock.writeCancellations,
504
+ promise
505
+ };
506
+ this.scheduledUpdate = request;
507
+ return promise;
508
+ }
509
+ /**
510
+ * Whether a request for `changed` and `deleted` is carried by the running
511
+ * `scheduled` build, whose write nothing has cancelled: the request deletes
512
+ * nothing, and each changed URI is one the build took, held by the text
513
+ * store at the version it had when the build started.
514
+ *
515
+ * Each condition keeps a request from joining a build that would miss its
516
+ * change. Text that moved since the start may be newer than what the build
517
+ * parsed; a URI the text store does not hold is read from its file, which
518
+ * may have changed after the build read it; and a deletion may concern a
519
+ * document the build has already built. A joined request is also absent
520
+ * from the running `update`'s `onUpdate` call, which reported the store as
521
+ * it was when the build started; at an unchanged version that is the store
522
+ * the request sees.
523
+ */
524
+ canJoinRunningUpdate(scheduled, changed, deleted) {
525
+ const taken = scheduled.takenVersions;
526
+ if (!taken || deleted.length > 0) {
527
+ return false;
528
+ }
529
+ return changed.every(uri => taken.has(uri.toString()) && taken.get(uri.toString()) === this.textDocuments?.get(uri)?.version);
530
+ }
531
+ /**
532
+ * The write action of a {@link scheduleUpdate}: freeze the request, record
533
+ * what it takes, stage its reason and run `update`. Releases
534
+ * {@link scheduledUpdate} inside the lock, whatever throws, so a request
535
+ * arriving after the build ends starts a write of its own rather than
536
+ * joining a build that is over.
537
+ */
538
+ async runScheduledUpdate(request, token) {
539
+ try {
540
+ const taken = new Map();
541
+ for (const [key, uri] of request.changed) {
542
+ const version = this.textDocuments?.get(uri)?.version;
543
+ if (version !== undefined) {
544
+ taken.set(key, version);
545
+ }
546
+ }
547
+ request.takenVersions = taken;
548
+ if (request.reason !== undefined) {
549
+ this.markNextReason(request.reason);
550
+ }
551
+ await this.update([...request.changed.values()], [...request.deleted.values()], token);
552
+ }
553
+ finally {
554
+ if (this.scheduledUpdate === request) {
555
+ this.scheduledUpdate = undefined;
556
+ }
557
+ }
558
+ }
559
+ /**
560
+ * Tell the {@link buildEndedListeners} once every phase has run, which is
561
+ * the one point where a build that skipped a waited-on document can be seen
562
+ * to have ended. Langium's `onBuildPhase` for `Validated` is not: it stays
563
+ * silent when no document reached that phase, which is every build that
564
+ * validates nothing, the workspace's initial one among them.
565
+ *
566
+ * A build that throws, whether cancelled or failed, tells none of them
567
+ * here: `currentState` is then below `Validated`, so {@link isOrphaned}
568
+ * could hold for no wait. {@link checkWaitsOnceDrained} tells them instead.
569
+ */
570
+ async buildDocuments(documents, options, cancelToken) {
571
+ await super.buildDocuments(documents, options, cancelToken);
572
+ for (const listener of [...this.buildEndedListeners]) {
573
+ listener(false);
574
+ }
575
+ }
576
+ /**
577
+ * After a build that threw, tell the {@link buildEndedListeners}, with
578
+ * `drained` set, from a {@link WorkspaceLock} read: it runs once no write
579
+ * runs or is queued, so no locked build is left that could still carry a
580
+ * waited-on document. A cancelled build is usually followed by its
581
+ * canceller's, but a write that builds nothing, such as a last-close revert
582
+ * that finds its document reopened, leaves a wait armed during the build
583
+ * with nothing to resolve it, and so does a build that fails. One read
584
+ * serves every build that throws before it runs.
585
+ */
586
+ checkWaitsOnceDrained() {
587
+ if (this.drainCheckQueued) {
588
+ return;
589
+ }
590
+ this.drainCheckQueued = true;
591
+ void this.workspaceLock.read(() => {
592
+ this.drainCheckQueued = false;
593
+ for (const listener of [...this.buildEndedListeners]) {
594
+ listener(true);
260
595
  }
261
596
  });
262
597
  }
@@ -331,7 +666,22 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
331
666
  this.ensureLanguageFileExtensions();
332
667
  const changedURIs = changed.flatMap(uri => this.flattenAndAdaptURI(uri));
333
668
  const deletedURIs = deleted.flatMap(uri => this.collectDeletedURIs(uri));
334
- return super.update(changedURIs, deletedURIs, cancelToken);
669
+ return this.runInSession({
670
+ kind: 'update',
671
+ trigger: this.buildTriggerLabel(changedURIs, deletedURIs),
672
+ triggerCountsDocs: changedURIs.length + deletedURIs.length !== 1,
673
+ changed: changedURIs,
674
+ deleted: deletedURIs
675
+ }, this.rebuildLabel(changedURIs, deletedURIs), () => super.update(changedURIs, deletedURIs, cancelToken));
676
+ }
677
+ /**
678
+ * The workspace-initialization entry point, bracketed by a session like
679
+ * {@link update}. Langium's `update` reaches `buildDocuments` directly rather
680
+ * than through here, so the two never nest.
681
+ */
682
+ build(documents, options, cancelToken) {
683
+ const uris = documents.map(document => document.uri);
684
+ return this.runInSession({ kind: 'build', trigger: `${documents.length} docs`, triggerCountsDocs: true, changed: uris, deleted: [] }, `Build documents (${documents.length} docs)`, () => super.build(documents, options, cancelToken));
335
685
  }
336
686
  /**
337
687
  * Refresh cross-document `ComputedScopes` derivations on cascade, when
@@ -472,13 +822,25 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
472
822
  * documents*: the Node provider walks the real filesystem (a freshly added
473
823
  * directory or never-opened file still builds), while a browser / empty
474
824
  * provider yields nothing. `uriPolicy.loadUri` first maps the URI to its
475
- * load identity — `undefined` (no on-disk content) short-circuits to `[]`
476
- * rather than a doomed read, and a symlink resolves to its real path so the
477
- * built documents key the same way every other layer does.
825
+ * load identity, and a symlink resolves to its real path so the built
826
+ * documents key the same way every other layer does.
827
+ *
828
+ * A URI with no on-disk content is dropped rather than read, unless the text
829
+ * store or the document registry holds it, under its canonical URI, the key
830
+ * both hold it by. A document created and not yet saved has text but no
831
+ * file, and a policy that checks the disk reports it absent. A registered
832
+ * document whose file has gone is kept too: its rebuild then fails on the
833
+ * read, which is how the revert on last close learns to remove it rather
834
+ * than leave it holding its last client's text.
478
835
  */
479
836
  flattenAndAdaptURI(uri) {
480
837
  const resolved = this.uriPolicy.loadUri(uri);
481
- return resolved ? this.collectLanguageFiles(resolved) : [];
838
+ if (resolved) {
839
+ return this.collectLanguageFiles(resolved);
840
+ }
841
+ const canonical = UriUtils.toUri(this.uriPolicy.canonicalUri(uri));
842
+ const held = this.textDocuments?.get(canonical) !== undefined || this.langiumDocuments.hasDocument(canonical);
843
+ return held ? this.collectLanguageFiles(canonical) : [];
482
844
  }
483
845
  /** Recurse `uri` through the `FileSystemProvider`, gathering registered
484
846
  * language files. A directory's entries carry their own `isDirectory`, so
@@ -528,6 +890,140 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
528
890
  ];
529
891
  }
530
892
  // ============================================================
893
+ // Build sessions — one rebuild as a correlated unit
894
+ // ============================================================
895
+ /**
896
+ * Open a session, run `body` inside it, and close it — the bracket every
897
+ * line of a rebuild is emitted within.
898
+ *
899
+ * The session is installed **synchronously**, before the timed body runs, so
900
+ * that state a subclass computed in {@link createBuildSession} is already
901
+ * readable by the time Langium's `update` consults `shouldRelink`.
902
+ *
903
+ * Teardown is preemption-correct, which is the reason this is framework code
904
+ * rather than a recipe. A build outside the workspace lock overlaps another:
905
+ * the later one installs itself as {@link activeSession} while the earlier
906
+ * one is still running, and the earlier one's `finally` runs LAST. Clearing
907
+ * unconditionally there would discard the later build's state mid-build.
908
+ * Only the session that is still current clears — and the check is
909
+ * reference equality on the session object,
910
+ * not on {@link BuildSession.traceId}, which is `undefined` for every build
911
+ * whenever the timing level is suppressed and would compare equal to itself
912
+ * across two different builds.
913
+ *
914
+ * Builds outside the lock are not hypothetical even without an adopter: the
915
+ * model service under `allowReentrantBuilds` starts one. Two locked builds
916
+ * never overlap, since the lock starts a write only once the write it
917
+ * cancelled has unwound.
918
+ */
919
+ runInSession(context, label, body) {
920
+ // Read before installing the new session: the id being superseded belongs
921
+ // to the OUTGOING build, or — when the previous one already finished
922
+ // cancelled — to the id it parked for its successor.
923
+ const supersededId = this.activeSession?.traceId ?? this.lastCancelledTraceId;
924
+ this.lastCancelledTraceId = undefined;
925
+ const reason = this.pendingUpdateReason;
926
+ this.pendingUpdateReason = undefined;
927
+ const tags = [];
928
+ if (reason) {
929
+ tags.push(`event: ${reason}`);
930
+ }
931
+ if (supersededId !== undefined) {
932
+ tags.push(`cancels #${supersededId}`);
933
+ }
934
+ const session = this.createBuildSession(context);
935
+ this.activeSession = session;
936
+ // A phase's "since previous phase" must measure from the build's start,
937
+ // not from whenever the last build's final phase happened to land.
938
+ this.lastPhaseMs = session.startMs;
939
+ return this.tracer.time(label, async () => {
940
+ try {
941
+ await body();
942
+ }
943
+ catch (err) {
944
+ if (isOperationCancelled(err)) {
945
+ session.cancelled = true;
946
+ }
947
+ this.checkWaitsOnceDrained();
948
+ throw err;
949
+ }
950
+ finally {
951
+ this.endSession(session);
952
+ }
953
+ }, this.logLevel, {
954
+ logAfterMs: 0,
955
+ forceMemoryAboveMs: session.buffers ? session.detailThresholdMs : undefined,
956
+ captureId: id => {
957
+ session.traceId = id;
958
+ },
959
+ tags
960
+ });
961
+ }
962
+ /**
963
+ * Construct the session for one build. Override to return a
964
+ * {@link BuildSession} subclass carrying adopter build-scoped state — it is
965
+ * called before the build body, so anything derived here is readable
966
+ * throughout it.
967
+ */
968
+ createBuildSession(context) {
969
+ return new BuildSession(performance.now(), context.trigger, context.triggerCountsDocs, this.phaseDetailMs.value);
970
+ }
971
+ /**
972
+ * Close `session`: flush what it buffered, then release it if it is still the
973
+ * current one (see {@link runInSession} on why that check is conditional).
974
+ * The flush is unconditional — a preempted build's lines still describe work
975
+ * that happened.
976
+ */
977
+ endSession(session) {
978
+ this.flushSession(session);
979
+ if (this.activeSession === session) {
980
+ this.activeSession = undefined;
981
+ if (session.cancelled) {
982
+ this.lastCancelledTraceId = session.traceId;
983
+ }
984
+ }
985
+ }
986
+ /**
987
+ * Emit the lines `session` held back, if it ran long enough to be worth the
988
+ * detail; drop them otherwise. Emits through {@link emit} rather than
989
+ * {@link log}, which would route them straight back into the buffer.
990
+ */
991
+ flushSession(session) {
992
+ const elapsedMs = performance.now() - session.startMs;
993
+ if (elapsedMs >= session.detailThresholdMs) {
994
+ for (const line of session.bufferedLines) {
995
+ this.emit(line);
996
+ }
997
+ }
998
+ session.bufferedLines.length = 0;
999
+ }
1000
+ /** Label for the build's own log line. Override to customise wording. */
1001
+ rebuildLabel(changed, deleted) {
1002
+ if (changed.length === 0 && deleted.length === 0) {
1003
+ return 'Rebuild documents (nothing to do)';
1004
+ }
1005
+ if (changed.length === 1 && deleted.length === 0) {
1006
+ return `Rebuild document: ${this.formatUri(changed[0])}`;
1007
+ }
1008
+ if (changed.length === 0 && deleted.length === 1) {
1009
+ return `Rebuild after delete: ${this.formatUri(deleted[0])}`;
1010
+ }
1011
+ return `Rebuild documents (${changed.length} changed, ${deleted.length} deleted)`;
1012
+ }
1013
+ /** Short description of what triggered the build, repeated on every phase line. Override to customise wording. */
1014
+ buildTriggerLabel(changed, deleted) {
1015
+ if (changed.length === 0 && deleted.length === 0) {
1016
+ return 'nothing';
1017
+ }
1018
+ if (changed.length === 1 && deleted.length === 0) {
1019
+ return this.formatUri(changed[0]);
1020
+ }
1021
+ if (changed.length === 0 && deleted.length === 1) {
1022
+ return `deleted ${this.formatUri(deleted[0])}`;
1023
+ }
1024
+ return `${changed.length} changed, ${deleted.length} deleted`;
1025
+ }
1026
+ // ============================================================
531
1027
  // Logging — phase-reached listeners
532
1028
  // ============================================================
533
1029
  registerPhaseListeners() {
@@ -540,15 +1036,37 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
540
1036
  const now = performance.now();
541
1037
  const elapsedMs = Math.round(now - this.lastPhaseMs);
542
1038
  this.lastPhaseMs = now;
1039
+ // Counted before the line is formatted, so the formatter stays a pure
1040
+ // function of state a caller can also set up in a test.
1041
+ if (this.activeSession) {
1042
+ this.activeSession.phasesLogged++;
1043
+ }
543
1044
  this.log(this.phaseReachedLine(state, documents, elapsedMs));
544
1045
  }
545
- /** Format the phase-reached log line. Override to customise wording. */
1046
+ /**
1047
+ * Format the phase-reached log line. Override to customise wording.
1048
+ *
1049
+ * Within a session the line names what triggered the build, so a phase read
1050
+ * in isolation still says which rebuild it belongs to. `elapsedMs` is ignored
1051
+ * for the FIRST phase of a session: it measures from the previous build's
1052
+ * last phase, an idle gap that says nothing about this build.
1053
+ */
546
1054
  phaseReachedLine(state, documents, elapsedMs) {
547
- const docInfo = documents.length === 1 ? this.formatUri(documents[0].uri) : `${documents.length} docs`;
548
- return `Reached phase '${DocumentState[state]}' [${docInfo}, ${elapsedMs}ms since previous phase]`;
1055
+ const session = this.activeSession;
1056
+ let docInfo;
1057
+ if (session) {
1058
+ docInfo = session.triggerCountsDocs ? `building ${session.trigger}` : `building ${session.trigger}, ${documents.length} docs`;
1059
+ }
1060
+ else {
1061
+ docInfo = documents.length === 1 ? this.formatUri(documents[0].uri) : `${documents.length} docs`;
1062
+ }
1063
+ const elapsedInfo = session && session.phasesLogged <= 1
1064
+ ? `${Math.round(performance.now() - session.startMs)}ms since build start`
1065
+ : `${elapsedMs}ms since previous phase`;
1066
+ return `Reached phase '${DocumentState[state]}' [${docInfo}, ${elapsedInfo}]`;
549
1067
  }
550
1068
  // ============================================================
551
- // Logging — slow-listener breakdown on notifyDocumentPhase
1069
+ // notifyDocumentPhase — the delivery hook and the slow-listener breakdown
552
1070
  // ============================================================
553
1071
  async notifyDocumentPhase(document, state, cancelToken) {
554
1072
  // Before the listeners, one of which is Langium's diagnostics publisher.
@@ -557,17 +1075,16 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
557
1075
  // replacing it, and the publisher reads that array when it is invoked. A
558
1076
  // build settling inside that window therefore appends after this call has
559
1077
  // already deduped, and the appended duplicate is published by the listener
560
- // of the build that deduped. Only `serializeBuilds` closes the window.
1078
+ // of the build that deduped. Only the write lock closes the window.
1079
+ //
1080
+ // Dedupe before rendering: rendering is deterministic, so it cannot
1081
+ // change which entries are structurally equal, and fewer survive to render.
561
1082
  if (state === DocumentState.Validated) {
562
1083
  this.dedupeDiagnostics(document);
563
- }
564
- if (this.logLevel === 'off') {
565
- return super.notifyDocumentPhase(document, state, cancelToken);
1084
+ this.renderDiagnostics(document);
566
1085
  }
567
1086
  const listeners = this.documentPhaseListeners.get(state).slice();
568
- if (listeners.length === 0) {
569
- return;
570
- }
1087
+ const version = document.textDocument.version;
571
1088
  const perListenerMs = [];
572
1089
  let cancelledListeners = 0;
573
1090
  const { elapsedMs: totalMs } = await this.clock.measure(async () => {
@@ -587,6 +1104,14 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
587
1104
  perListenerMs.push(elapsedMs);
588
1105
  }
589
1106
  });
1107
+ if (cancelledListeners === 0) {
1108
+ for (const delivered of this.documentPhaseDeliveredListeners.get(state).slice()) {
1109
+ delivered(document, version);
1110
+ }
1111
+ }
1112
+ if (this.logLevel === 'off' || listeners.length === 0) {
1113
+ return;
1114
+ }
590
1115
  if (cancelledListeners > 0) {
591
1116
  this.tracer
592
1117
  .withUri(document.uri.toString())
@@ -660,8 +1185,8 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
660
1185
  * twice: Langium's validate appends to `document.diagnostics` when they are
661
1186
  * already set — deliberately, so a category-partitioned pass keeps the earlier
662
1187
  * category's findings — and a repeated FULL pass therefore doubles the list.
663
- * `ModelServiceOptions.serializeBuilds` prevents that at the source; this is
664
- * the net for configurations that allow concurrent builds anyway.
1188
+ * The write lock prevents that at the source; this is the net for builds
1189
+ * that skip it, as `ModelServiceOptions.allowReentrantBuilds` lets one do.
665
1190
  *
666
1191
  * Clearing the list before a pass is NOT an alternative: the append happens at
667
1192
  * pass completion, so two interleaved passes both clear, both finish, and the
@@ -718,11 +1243,84 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
718
1243
  document.diagnostics = unique;
719
1244
  }
720
1245
  }
1246
+ /**
1247
+ * Render every diagnostic on `document` through the bound message renderer,
1248
+ * in ONE pass over the finished list.
1249
+ *
1250
+ * All three heads read `document.diagnostics` — the LSP publish,
1251
+ * `TransferEncoder.toTransferDiagnostic` and the GLSP validation path — so
1252
+ * one pass here is what keeps the render from happening per head. It is also
1253
+ * the only placement that covers lexer and parser errors, which Langium
1254
+ * pushes onto the document without routing them through `toDiagnostic`.
1255
+ *
1256
+ * Running here rather than from a `Validated` phase listener needs no
1257
+ * ordering assumption: Langium publishes from `addDiagnosticsHandler`, a free
1258
+ * function it registers as such a listener, which can only be outrun.
1259
+ *
1260
+ * **It inherits {@link dedupeDiagnostics}'s window, and therefore the same
1261
+ * precondition.** A build settling inside the listener window appends
1262
+ * diagnostics this pass never saw, and the publisher of the build that
1263
+ * rendered sends them — unrendered. The write lock closes it, so "every
1264
+ * diagnostic is rendered" holds while
1265
+ * `ModelServiceOptions.allowReentrantBuilds` is `false`, its default.
1266
+ * Turning it on accepts unrendered diagnostics on exactly the terms it
1267
+ * already accepts duplicates.
1268
+ *
1269
+ * Entries are REPLACED rather than mutated: `sendDiagnostics` passes the
1270
+ * array by reference and serialises later, so an in-place message mutation
1271
+ * reaches the wire even when it runs after the publisher — which would make
1272
+ * a test for the ordering pass in either state.
1273
+ */
1274
+ renderDiagnostics(document) {
1275
+ const diagnostics = document.diagnostics;
1276
+ if (!diagnostics || diagnostics.length === 0) {
1277
+ return;
1278
+ }
1279
+ let changed = false;
1280
+ // No try/catch: `renderDiagnostic` carries a no-throw contract, because an
1281
+ // error escaping this phase strands the document at `Validated` with
1282
+ // Langium's publisher never invoked.
1283
+ const rendered = diagnostics.map(diagnostic => {
1284
+ const text = this.messageRenderer.renderDiagnostic(diagnostic);
1285
+ // Against the message's STRING FORM, not the field. `renderDiagnostic`
1286
+ // answers a `string` by contract, while `Diagnostic.message` is
1287
+ // `string | MarkupContent` since LSP 3.17 — so comparing the answer
1288
+ // against the field never matches for a markup message, and a pass
1289
+ // that replaced on mismatch flattened every un-identified markup
1290
+ // diagnostic to its own plain text. That is silent data loss on the
1291
+ // path whose whole job is to leave such entries alone.
1292
+ if (text === Diagnostic.getMessageString(diagnostic)) {
1293
+ return diagnostic;
1294
+ }
1295
+ changed = true;
1296
+ return { ...diagnostic, message: text };
1297
+ });
1298
+ if (changed) {
1299
+ document.diagnostics = rendered;
1300
+ }
1301
+ }
721
1302
  // ============================================================
722
1303
  // Internal helpers
723
1304
  // ============================================================
724
- /** Dispatch a log line at the configured log level; a no-op when `logLevel === 'off'`. */
1305
+ /**
1306
+ * Dispatch a log line at the configured log level; a no-op when `logLevel ===
1307
+ * 'off'`.
1308
+ *
1309
+ * Held on the active session when it buffers, so the "was this build worth a
1310
+ * per-phase breakdown" decision — which needs the build's total duration, and
1311
+ * so cannot be taken by anything that runs while the lines are produced — is
1312
+ * deferred to {@link flushSession}.
1313
+ */
725
1314
  log(message) {
1315
+ const session = this.activeSession;
1316
+ if (session?.buffers) {
1317
+ session.bufferedLines.push(message);
1318
+ return;
1319
+ }
1320
+ this.emit(message);
1321
+ }
1322
+ /** Write a line out, bypassing session buffering. The single sink every framework log line reaches. */
1323
+ emit(message) {
726
1324
  this.tracer.logAt(this.logLevel, message);
727
1325
  }
728
1326
  }