@hydranium/core 1.0.0-next.39 → 1.0.0-next.391

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 (805) hide show
  1. package/README.md +78 -82
  2. package/lib/browser/host-heads-in-worker.d.ts +77 -0
  3. package/lib/browser/host-heads-in-worker.d.ts.map +1 -0
  4. package/lib/browser/host-heads-in-worker.js +169 -0
  5. package/lib/browser/host-heads-in-worker.js.map +1 -0
  6. package/lib/browser/index.d.ts +12 -0
  7. package/lib/browser/index.d.ts.map +1 -0
  8. package/lib/browser/index.js +17 -0
  9. package/lib/browser/index.js.map +1 -0
  10. package/lib/browser/indexeddb-file-system-store.d.ts +82 -0
  11. package/lib/browser/indexeddb-file-system-store.d.ts.map +1 -0
  12. package/lib/browser/indexeddb-file-system-store.js +181 -0
  13. package/lib/browser/indexeddb-file-system-store.js.map +1 -0
  14. package/lib/browser/start-language-server-in-worker.d.ts +32 -0
  15. package/lib/browser/start-language-server-in-worker.d.ts.map +1 -0
  16. package/lib/browser/start-language-server-in-worker.js +40 -0
  17. package/lib/browser/start-language-server-in-worker.js.map +1 -0
  18. package/lib/documents/ast-document-manager.d.ts +254 -140
  19. package/lib/documents/ast-document-manager.d.ts.map +1 -1
  20. package/lib/documents/ast-document-manager.js +311 -128
  21. package/lib/documents/ast-document-manager.js.map +1 -1
  22. package/lib/documents/client-ids.d.ts +5 -19
  23. package/lib/documents/client-ids.d.ts.map +1 -1
  24. package/lib/documents/client-ids.js +5 -19
  25. package/lib/documents/client-ids.js.map +1 -1
  26. package/lib/documents/client-session-errors.d.ts +15 -0
  27. package/lib/documents/client-session-errors.d.ts.map +1 -0
  28. package/lib/documents/client-session-errors.js +15 -0
  29. package/lib/documents/client-session-errors.js.map +1 -0
  30. package/lib/documents/client-session-registry.d.ts +146 -0
  31. package/lib/documents/client-session-registry.d.ts.map +1 -0
  32. package/lib/documents/client-session-registry.js +207 -0
  33. package/lib/documents/client-session-registry.js.map +1 -0
  34. package/lib/documents/dirty-state-tracker.d.ts +101 -0
  35. package/lib/documents/dirty-state-tracker.d.ts.map +1 -0
  36. package/lib/documents/dirty-state-tracker.js +85 -0
  37. package/lib/documents/dirty-state-tracker.js.map +1 -0
  38. package/lib/documents/document-release-handler.d.ts +204 -0
  39. package/lib/documents/document-release-handler.d.ts.map +1 -0
  40. package/lib/documents/document-release-handler.js +317 -0
  41. package/lib/documents/document-release-handler.js.map +1 -0
  42. package/lib/documents/document-release-scheduler.d.ts +67 -0
  43. package/lib/documents/document-release-scheduler.d.ts.map +1 -0
  44. package/lib/documents/document-release-scheduler.js +80 -0
  45. package/lib/documents/document-release-scheduler.js.map +1 -0
  46. package/lib/documents/file-system-task-queue.d.ts +52 -0
  47. package/lib/documents/file-system-task-queue.d.ts.map +1 -0
  48. package/lib/documents/file-system-task-queue.js +40 -0
  49. package/lib/documents/file-system-task-queue.js.map +1 -0
  50. package/lib/documents/hydranium-text-documents.d.ts +453 -282
  51. package/lib/documents/hydranium-text-documents.d.ts.map +1 -1
  52. package/lib/documents/hydranium-text-documents.js +918 -504
  53. package/lib/documents/hydranium-text-documents.js.map +1 -1
  54. package/lib/documents/index.d.ts +10 -2
  55. package/lib/documents/index.d.ts.map +1 -1
  56. package/lib/documents/index.js +10 -2
  57. package/lib/documents/index.js.map +1 -1
  58. package/lib/documents/language-client-shadow.d.ts +234 -0
  59. package/lib/documents/language-client-shadow.d.ts.map +1 -0
  60. package/lib/documents/language-client-shadow.js +306 -0
  61. package/lib/documents/language-client-shadow.js.map +1 -0
  62. package/lib/documents/model-ledger.d.ts +47 -0
  63. package/lib/documents/model-ledger.d.ts.map +1 -0
  64. package/lib/documents/model-ledger.js +30 -0
  65. package/lib/documents/model-ledger.js.map +1 -0
  66. package/lib/documents/text-ledger.d.ts +64 -0
  67. package/lib/documents/text-ledger.d.ts.map +1 -0
  68. package/lib/documents/text-ledger.js +63 -0
  69. package/lib/documents/text-ledger.js.map +1 -0
  70. package/lib/documents/version-sync-service.d.ts +153 -0
  71. package/lib/documents/version-sync-service.d.ts.map +1 -0
  72. package/lib/documents/version-sync-service.js +186 -0
  73. package/lib/documents/version-sync-service.js.map +1 -0
  74. package/lib/index.d.ts +3 -0
  75. package/lib/index.d.ts.map +1 -1
  76. package/lib/index.js +3 -0
  77. package/lib/index.js.map +1 -1
  78. package/lib/langium/ast-extension/ast-extension-service.d.ts +42 -31
  79. package/lib/langium/ast-extension/ast-extension-service.d.ts.map +1 -1
  80. package/lib/langium/ast-extension/ast-extension-service.js +45 -19
  81. package/lib/langium/ast-extension/ast-extension-service.js.map +1 -1
  82. package/lib/langium/ast-extension/ast-node-builder.d.ts +12 -7
  83. package/lib/langium/ast-extension/ast-node-builder.d.ts.map +1 -1
  84. package/lib/langium/ast-extension/ast-node-builder.js +25 -9
  85. package/lib/langium/ast-extension/ast-node-builder.js.map +1 -1
  86. package/lib/langium/bootstrap.d.ts +49 -36
  87. package/lib/langium/bootstrap.d.ts.map +1 -1
  88. package/lib/langium/bootstrap.js +75 -36
  89. package/lib/langium/bootstrap.js.map +1 -1
  90. package/lib/langium/build-phase-pass/build-phase-pass-service.d.ts +9 -9
  91. package/lib/langium/build-phase-pass/build-phase-pass-service.d.ts.map +1 -1
  92. package/lib/langium/build-phase-pass/build-phase-pass-service.js +25 -16
  93. package/lib/langium/build-phase-pass/build-phase-pass-service.js.map +1 -1
  94. package/lib/langium/build-phase-pass/build-phase-pass.d.ts +20 -8
  95. package/lib/langium/build-phase-pass/build-phase-pass.d.ts.map +1 -1
  96. package/lib/langium/build-phase-pass/build-phase-pass.js +20 -0
  97. package/lib/langium/build-phase-pass/build-phase-pass.js.map +1 -1
  98. package/lib/langium/composite-ast-reflection.d.ts +46 -0
  99. package/lib/langium/composite-ast-reflection.d.ts.map +1 -0
  100. package/lib/langium/composite-ast-reflection.js +97 -0
  101. package/lib/langium/composite-ast-reflection.js.map +1 -0
  102. package/lib/langium/config/configuration-provider.d.ts +81 -0
  103. package/lib/langium/config/configuration-provider.d.ts.map +1 -0
  104. package/lib/langium/config/configuration-provider.js +112 -0
  105. package/lib/langium/config/configuration-provider.js.map +1 -0
  106. package/lib/langium/config/index.d.ts +1 -0
  107. package/lib/langium/config/index.d.ts.map +1 -1
  108. package/lib/langium/config/index.js +1 -0
  109. package/lib/langium/config/index.js.map +1 -1
  110. package/lib/langium/config/settings.js.map +1 -1
  111. package/lib/langium/diagnostics/console-tee.d.ts +27 -0
  112. package/lib/langium/diagnostics/console-tee.d.ts.map +1 -0
  113. package/lib/langium/diagnostics/console-tee.js +141 -0
  114. package/lib/langium/diagnostics/console-tee.js.map +1 -0
  115. package/lib/langium/diagnostics/hydranium-langium-profiler.d.ts +9 -20
  116. package/lib/langium/diagnostics/hydranium-langium-profiler.d.ts.map +1 -1
  117. package/lib/langium/diagnostics/hydranium-langium-profiler.js +15 -24
  118. package/lib/langium/diagnostics/hydranium-langium-profiler.js.map +1 -1
  119. package/lib/langium/diagnostics/log-preamble.js +1 -1
  120. package/lib/langium/diagnostics/log-preamble.js.map +1 -1
  121. package/lib/langium/diagnostics/logger.d.ts +25 -6
  122. package/lib/langium/diagnostics/logger.d.ts.map +1 -1
  123. package/lib/langium/diagnostics/logger.js +49 -17
  124. package/lib/langium/diagnostics/logger.js.map +1 -1
  125. package/lib/langium/diagnostics/lsp-logger.d.ts +25 -0
  126. package/lib/langium/diagnostics/lsp-logger.d.ts.map +1 -1
  127. package/lib/langium/diagnostics/lsp-logger.js +81 -46
  128. package/lib/langium/diagnostics/lsp-logger.js.map +1 -1
  129. package/lib/langium/diagnostics/server-tracer.d.ts.map +1 -1
  130. package/lib/langium/diagnostics/server-tracer.js.map +1 -1
  131. package/lib/langium/document-builder/build-pipeline-integration.d.ts +21 -1
  132. package/lib/langium/document-builder/build-pipeline-integration.d.ts.map +1 -1
  133. package/lib/langium/document-builder/build-pipeline-integration.js +43 -30
  134. package/lib/langium/document-builder/build-pipeline-integration.js.map +1 -1
  135. package/lib/langium/document-builder/build-session.d.ts +6 -5
  136. package/lib/langium/document-builder/build-session.d.ts.map +1 -1
  137. package/lib/langium/document-builder/build-session.js +5 -5
  138. package/lib/langium/document-builder/build-session.js.map +1 -1
  139. package/lib/langium/document-builder/document-builder.d.ts +390 -40
  140. package/lib/langium/document-builder/document-builder.d.ts.map +1 -1
  141. package/lib/langium/document-builder/document-builder.js +635 -102
  142. package/lib/langium/document-builder/document-builder.js.map +1 -1
  143. package/lib/langium/documentation/comment-provider.d.ts.map +1 -1
  144. package/lib/langium/documentation/comment-provider.js.map +1 -1
  145. package/lib/langium/integration-services.d.ts +20 -23
  146. package/lib/langium/integration-services.d.ts.map +1 -1
  147. package/lib/langium/integration-services.js.map +1 -1
  148. package/lib/langium/integrity/integrity-rule.d.ts +22 -8
  149. package/lib/langium/integrity/integrity-rule.d.ts.map +1 -1
  150. package/lib/langium/integrity/integrity-rule.js.map +1 -1
  151. package/lib/langium/integrity/integrity-service.d.ts +217 -29
  152. package/lib/langium/integrity/integrity-service.d.ts.map +1 -1
  153. package/lib/langium/integrity/integrity-service.js +588 -84
  154. package/lib/langium/integrity/integrity-service.js.map +1 -1
  155. package/lib/langium/keys/containment.d.ts +3 -2
  156. package/lib/langium/keys/containment.d.ts.map +1 -1
  157. package/lib/langium/keys/containment.js.map +1 -1
  158. package/lib/langium/keys/name-based-key-provider.d.ts +17 -10
  159. package/lib/langium/keys/name-based-key-provider.d.ts.map +1 -1
  160. package/lib/langium/keys/name-based-key-provider.js +24 -12
  161. package/lib/langium/keys/name-based-key-provider.js.map +1 -1
  162. package/lib/langium/keys/positional-key-provider.d.ts.map +1 -1
  163. package/lib/langium/keys/positional-key-provider.js.map +1 -1
  164. package/lib/langium/labeling/label-provider.d.ts.map +1 -1
  165. package/lib/langium/labeling/label-provider.js.map +1 -1
  166. package/lib/langium/language-module.d.ts +30 -5
  167. package/lib/langium/language-module.d.ts.map +1 -1
  168. package/lib/langium/language-module.js +21 -5
  169. package/lib/langium/language-module.js.map +1 -1
  170. package/lib/langium/model-service/client-session.d.ts +405 -0
  171. package/lib/langium/model-service/client-session.d.ts.map +1 -0
  172. package/lib/langium/model-service/client-session.js +479 -0
  173. package/lib/langium/model-service/client-session.js.map +1 -0
  174. package/lib/langium/model-service/index.d.ts +2 -0
  175. package/lib/langium/model-service/index.d.ts.map +1 -1
  176. package/lib/langium/model-service/index.js +2 -0
  177. package/lib/langium/model-service/index.js.map +1 -1
  178. package/lib/langium/model-service/model-events.d.ts +68 -0
  179. package/lib/langium/model-service/model-events.d.ts.map +1 -0
  180. package/lib/langium/model-service/model-events.js +10 -0
  181. package/lib/langium/model-service/model-events.js.map +1 -0
  182. package/lib/langium/model-service/model-service.d.ts +441 -323
  183. package/lib/langium/model-service/model-service.d.ts.map +1 -1
  184. package/lib/langium/model-service/model-service.js +602 -407
  185. package/lib/langium/model-service/model-service.js.map +1 -1
  186. package/lib/langium/module.d.ts +96 -37
  187. package/lib/langium/module.d.ts.map +1 -1
  188. package/lib/langium/module.js +41 -29
  189. package/lib/langium/module.js.map +1 -1
  190. package/lib/langium/naming/name-provider.d.ts +32 -7
  191. package/lib/langium/naming/name-provider.d.ts.map +1 -1
  192. package/lib/langium/naming/name-provider.js +10 -4
  193. package/lib/langium/naming/name-provider.js.map +1 -1
  194. package/lib/langium/naming/name-separator-validation.d.ts.map +1 -1
  195. package/lib/langium/project/abstract-project-manager.d.ts +184 -13
  196. package/lib/langium/project/abstract-project-manager.d.ts.map +1 -1
  197. package/lib/langium/project/abstract-project-manager.js +336 -16
  198. package/lib/langium/project/abstract-project-manager.js.map +1 -1
  199. package/lib/langium/project/project-change-event.d.ts +22 -3
  200. package/lib/langium/project/project-change-event.d.ts.map +1 -1
  201. package/lib/langium/project/project-manager.d.ts +28 -2
  202. package/lib/langium/project/project-manager.d.ts.map +1 -1
  203. package/lib/langium/project/single-project-manager.d.ts +7 -1
  204. package/lib/langium/project/single-project-manager.d.ts.map +1 -1
  205. package/lib/langium/project/single-project-manager.js +12 -0
  206. package/lib/langium/project/single-project-manager.js.map +1 -1
  207. package/lib/langium/residency/cst-residency-service.d.ts +92 -52
  208. package/lib/langium/residency/cst-residency-service.d.ts.map +1 -1
  209. package/lib/langium/residency/cst-residency-service.js +154 -58
  210. package/lib/langium/residency/cst-residency-service.js.map +1 -1
  211. package/lib/langium/scope/ast-node-description-provider.d.ts +46 -10
  212. package/lib/langium/scope/ast-node-description-provider.d.ts.map +1 -1
  213. package/lib/langium/scope/ast-node-description-provider.js +88 -15
  214. package/lib/langium/scope/ast-node-description-provider.js.map +1 -1
  215. package/lib/langium/scope/built-local-symbols.d.ts +12 -0
  216. package/lib/langium/scope/built-local-symbols.d.ts.map +1 -0
  217. package/lib/langium/scope/built-local-symbols.js +11 -0
  218. package/lib/langium/scope/built-local-symbols.js.map +1 -0
  219. package/lib/langium/scope/fallback-scope.d.ts +27 -0
  220. package/lib/langium/scope/fallback-scope.d.ts.map +1 -0
  221. package/lib/langium/scope/fallback-scope.js +35 -0
  222. package/lib/langium/scope/fallback-scope.js.map +1 -0
  223. package/lib/langium/scope/hydranium-scope-computation.d.ts +21 -18
  224. package/lib/langium/scope/hydranium-scope-computation.d.ts.map +1 -1
  225. package/lib/langium/scope/hydranium-scope-computation.js +38 -39
  226. package/lib/langium/scope/hydranium-scope-computation.js.map +1 -1
  227. package/lib/langium/scope/hydranium-scope-provider.d.ts +122 -32
  228. package/lib/langium/scope/hydranium-scope-provider.d.ts.map +1 -1
  229. package/lib/langium/scope/hydranium-scope-provider.js +217 -39
  230. package/lib/langium/scope/hydranium-scope-provider.js.map +1 -1
  231. package/lib/langium/scope/index.d.ts +1 -0
  232. package/lib/langium/scope/index.d.ts.map +1 -1
  233. package/lib/langium/scope/index.js +1 -0
  234. package/lib/langium/scope/index.js.map +1 -1
  235. package/lib/langium/scope/reference-builder.d.ts.map +1 -1
  236. package/lib/langium/scope/reference-builder.js.map +1 -1
  237. package/lib/langium/scope/reference-candidate-provider.d.ts +6 -5
  238. package/lib/langium/scope/reference-candidate-provider.d.ts.map +1 -1
  239. package/lib/langium/scope/reference-candidate-provider.js +3 -2
  240. package/lib/langium/scope/reference-candidate-provider.js.map +1 -1
  241. package/lib/langium/scope/scope-extension-service.d.ts +69 -37
  242. package/lib/langium/scope/scope-extension-service.d.ts.map +1 -1
  243. package/lib/langium/scope/scope-extension-service.js +102 -29
  244. package/lib/langium/scope/scope-extension-service.js.map +1 -1
  245. package/lib/langium/scope/scoped-ast-node-description.d.ts +1 -3
  246. package/lib/langium/scope/scoped-ast-node-description.d.ts.map +1 -1
  247. package/lib/langium/scope/scoped-ast-node-description.js +1 -3
  248. package/lib/langium/scope/scoped-ast-node-description.js.map +1 -1
  249. package/lib/langium/serialization/abstract-serializer.d.ts +38 -27
  250. package/lib/langium/serialization/abstract-serializer.d.ts.map +1 -1
  251. package/lib/langium/serialization/abstract-serializer.js +54 -30
  252. package/lib/langium/serialization/abstract-serializer.js.map +1 -1
  253. package/lib/langium/serialization/json-serializer.d.ts +8 -1
  254. package/lib/langium/serialization/json-serializer.d.ts.map +1 -1
  255. package/lib/langium/serialization/json-serializer.js +13 -3
  256. package/lib/langium/serialization/json-serializer.js.map +1 -1
  257. package/lib/langium/serialization/serializer.d.ts +1 -1
  258. package/lib/langium/serialization/yaml-serializer.d.ts +12 -0
  259. package/lib/langium/serialization/yaml-serializer.d.ts.map +1 -1
  260. package/lib/langium/serialization/yaml-serializer.js +24 -4
  261. package/lib/langium/serialization/yaml-serializer.js.map +1 -1
  262. package/lib/langium/service-registry.d.ts +29 -1
  263. package/lib/langium/service-registry.d.ts.map +1 -1
  264. package/lib/langium/service-registry.js +37 -0
  265. package/lib/langium/service-registry.js.map +1 -1
  266. package/lib/langium/shared-services.d.ts +10 -4
  267. package/lib/langium/shared-services.d.ts.map +1 -1
  268. package/lib/langium/shared-services.js.map +1 -1
  269. package/lib/langium/single-langium-copy.d.ts +22 -0
  270. package/lib/langium/single-langium-copy.d.ts.map +1 -0
  271. package/lib/langium/single-langium-copy.js +36 -0
  272. package/lib/langium/single-langium-copy.js.map +1 -0
  273. package/lib/langium/transfer/transfer-encoder.d.ts +60 -39
  274. package/lib/langium/transfer/transfer-encoder.d.ts.map +1 -1
  275. package/lib/langium/transfer/transfer-encoder.js +35 -24
  276. package/lib/langium/transfer/transfer-encoder.js.map +1 -1
  277. package/lib/langium/trivia/comment-preserver.d.ts +543 -0
  278. package/lib/langium/trivia/comment-preserver.d.ts.map +1 -0
  279. package/lib/langium/trivia/comment-preserver.js +1165 -0
  280. package/lib/langium/trivia/comment-preserver.js.map +1 -0
  281. package/lib/langium/trivia/document-ending-preserver.d.ts +51 -0
  282. package/lib/langium/trivia/document-ending-preserver.d.ts.map +1 -0
  283. package/lib/langium/trivia/document-ending-preserver.js +62 -0
  284. package/lib/langium/trivia/document-ending-preserver.js.map +1 -0
  285. package/lib/langium/trivia/index.d.ts +14 -0
  286. package/lib/langium/trivia/index.d.ts.map +1 -0
  287. package/lib/langium/trivia/index.js +14 -0
  288. package/lib/langium/trivia/index.js.map +1 -0
  289. package/lib/langium/trivia/trivia-contribution.d.ts +37 -0
  290. package/lib/langium/trivia/trivia-contribution.d.ts.map +1 -0
  291. package/lib/langium/trivia/trivia-contribution.js +10 -0
  292. package/lib/langium/trivia/trivia-contribution.js.map +1 -0
  293. package/lib/langium/trivia/trivia-preserver.d.ts +52 -0
  294. package/lib/langium/trivia/trivia-preserver.d.ts.map +1 -0
  295. package/lib/langium/trivia/trivia-preserver.js +10 -0
  296. package/lib/langium/trivia/trivia-preserver.js.map +1 -0
  297. package/lib/langium/trivia/trivia-service.d.ts +70 -0
  298. package/lib/langium/trivia/trivia-service.d.ts.map +1 -0
  299. package/lib/langium/trivia/trivia-service.js +56 -0
  300. package/lib/langium/trivia/trivia-service.js.map +1 -0
  301. package/lib/langium/update-rewrite/normalize-empty-strings.d.ts.map +1 -1
  302. package/lib/langium/update-rewrite/update-rewrite-service.d.ts +1 -1
  303. package/lib/langium/update-rewrite/update-rewrite-service.d.ts.map +1 -1
  304. package/lib/langium/update-rewrite/update-rewrite-service.js.map +1 -1
  305. package/lib/langium/update-rewrite/update-rewrite.d.ts +1 -1
  306. package/lib/langium/validation/document-validator.d.ts +168 -23
  307. package/lib/langium/validation/document-validator.d.ts.map +1 -1
  308. package/lib/langium/validation/document-validator.js +264 -26
  309. package/lib/langium/validation/document-validator.js.map +1 -1
  310. package/lib/langium/validation/validation-contribution-collector.d.ts +9 -1
  311. package/lib/langium/validation/validation-contribution-collector.d.ts.map +1 -1
  312. package/lib/langium/validation/validation-contribution-collector.js +1 -1
  313. package/lib/langium/validation/validation-contribution-collector.js.map +1 -1
  314. package/lib/langium/workspace/ast-node-locator.d.ts +24 -0
  315. package/lib/langium/workspace/ast-node-locator.d.ts.map +1 -0
  316. package/lib/langium/workspace/ast-node-locator.js +32 -0
  317. package/lib/langium/workspace/ast-node-locator.js.map +1 -0
  318. package/lib/langium/workspace/document-uri-policy.d.ts +24 -15
  319. package/lib/langium/workspace/document-uri-policy.d.ts.map +1 -1
  320. package/lib/langium/workspace/document-uri-policy.js +22 -13
  321. package/lib/langium/workspace/document-uri-policy.js.map +1 -1
  322. package/lib/langium/workspace/file-not-found.d.ts +23 -0
  323. package/lib/langium/workspace/file-not-found.d.ts.map +1 -0
  324. package/lib/langium/workspace/file-not-found.js +31 -0
  325. package/lib/langium/workspace/file-not-found.js.map +1 -0
  326. package/lib/langium/workspace/file-system-provider.d.ts +167 -8
  327. package/lib/langium/workspace/file-system-provider.d.ts.map +1 -1
  328. package/lib/langium/workspace/file-system-provider.js +115 -13
  329. package/lib/langium/workspace/file-system-provider.js.map +1 -1
  330. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts +78 -4
  331. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts.map +1 -1
  332. package/lib/langium/workspace/hydranium-langium-document-factory.js +188 -5
  333. package/lib/langium/workspace/hydranium-langium-document-factory.js.map +1 -1
  334. package/lib/langium/workspace/hydranium-workspace-lock.d.ts +50 -1
  335. package/lib/langium/workspace/hydranium-workspace-lock.d.ts.map +1 -1
  336. package/lib/langium/workspace/hydranium-workspace-lock.js +73 -1
  337. package/lib/langium/workspace/hydranium-workspace-lock.js.map +1 -1
  338. package/lib/langium/workspace/hydranium-workspace-manager.d.ts +105 -21
  339. package/lib/langium/workspace/hydranium-workspace-manager.d.ts.map +1 -1
  340. package/lib/langium/workspace/hydranium-workspace-manager.js +186 -31
  341. package/lib/langium/workspace/hydranium-workspace-manager.js.map +1 -1
  342. package/lib/langium/workspace/in-memory-file-system-provider.d.ts +26 -9
  343. package/lib/langium/workspace/in-memory-file-system-provider.d.ts.map +1 -1
  344. package/lib/langium/workspace/in-memory-file-system-provider.js +45 -22
  345. package/lib/langium/workspace/in-memory-file-system-provider.js.map +1 -1
  346. package/lib/langium/workspace/index-manager.d.ts.map +1 -1
  347. package/lib/langium/workspace/index-manager.js.map +1 -1
  348. package/lib/langium/workspace/index.d.ts +3 -0
  349. package/lib/langium/workspace/index.d.ts.map +1 -1
  350. package/lib/langium/workspace/index.js +3 -0
  351. package/lib/langium/workspace/index.js.map +1 -1
  352. package/lib/langium/workspace/initialize-workspace.d.ts +40 -3
  353. package/lib/langium/workspace/initialize-workspace.d.ts.map +1 -1
  354. package/lib/langium/workspace/initialize-workspace.js +68 -3
  355. package/lib/langium/workspace/initialize-workspace.js.map +1 -1
  356. package/lib/langium/workspace/langium-documents.d.ts +7 -0
  357. package/lib/langium/workspace/langium-documents.d.ts.map +1 -1
  358. package/lib/langium/workspace/langium-documents.js +18 -1
  359. package/lib/langium/workspace/langium-documents.js.map +1 -1
  360. package/lib/langium/workspace/persistent-file-system-provider.d.ts +16 -10
  361. package/lib/langium/workspace/persistent-file-system-provider.d.ts.map +1 -1
  362. package/lib/langium/workspace/persistent-file-system-provider.js +25 -13
  363. package/lib/langium/workspace/persistent-file-system-provider.js.map +1 -1
  364. package/lib/{documents → langium/workspace}/self-save-registry.d.ts +7 -9
  365. package/lib/langium/workspace/self-save-registry.d.ts.map +1 -0
  366. package/lib/{documents → langium/workspace}/self-save-registry.js +9 -11
  367. package/lib/langium/workspace/self-save-registry.js.map +1 -0
  368. package/lib/langium/workspace/syntax-errors.d.ts +23 -0
  369. package/lib/langium/workspace/syntax-errors.d.ts.map +1 -0
  370. package/lib/langium/workspace/syntax-errors.js +29 -0
  371. package/lib/langium/workspace/syntax-errors.js.map +1 -0
  372. package/lib/langium/workspace/virtual-document.d.ts +55 -21
  373. package/lib/langium/workspace/virtual-document.d.ts.map +1 -1
  374. package/lib/langium/workspace/virtual-document.js +87 -24
  375. package/lib/langium/workspace/virtual-document.js.map +1 -1
  376. package/lib/langium/workspace/write-lock-scope.d.ts +22 -10
  377. package/lib/langium/workspace/write-lock-scope.d.ts.map +1 -1
  378. package/lib/langium/workspace/write-lock-scope.js +15 -5
  379. package/lib/langium/workspace/write-lock-scope.js.map +1 -1
  380. package/lib/launcher/integrated-server.d.ts +3 -1
  381. package/lib/launcher/integrated-server.d.ts.map +1 -1
  382. package/lib/locale/server-locale.d.ts +6 -6
  383. package/lib/locale/server-locale.d.ts.map +1 -1
  384. package/lib/locale/server-locale.js.map +1 -1
  385. package/lib/lsp/completion/hydranium-completion-provider.d.ts +44 -2
  386. package/lib/lsp/completion/hydranium-completion-provider.d.ts.map +1 -1
  387. package/lib/lsp/completion/hydranium-completion-provider.js +68 -0
  388. package/lib/lsp/completion/hydranium-completion-provider.js.map +1 -1
  389. package/lib/lsp/connection-features.d.ts +23 -0
  390. package/lib/lsp/connection-features.d.ts.map +1 -0
  391. package/lib/lsp/connection-features.js +60 -0
  392. package/lib/lsp/connection-features.js.map +1 -0
  393. package/lib/lsp/diagnostics-connection.d.ts +27 -0
  394. package/lib/lsp/diagnostics-connection.d.ts.map +1 -0
  395. package/lib/lsp/diagnostics-connection.js +53 -0
  396. package/lib/lsp/diagnostics-connection.js.map +1 -0
  397. package/lib/lsp/edit-requests-guard.d.ts +31 -0
  398. package/lib/lsp/edit-requests-guard.d.ts.map +1 -0
  399. package/lib/lsp/edit-requests-guard.js +125 -0
  400. package/lib/lsp/edit-requests-guard.js.map +1 -0
  401. package/lib/lsp/hydranium-document-update-handler.d.ts +126 -82
  402. package/lib/lsp/hydranium-document-update-handler.d.ts.map +1 -1
  403. package/lib/lsp/hydranium-document-update-handler.js +234 -101
  404. package/lib/lsp/hydranium-document-update-handler.js.map +1 -1
  405. package/lib/lsp/index.d.ts +6 -2
  406. package/lib/lsp/index.d.ts.map +1 -1
  407. package/lib/lsp/index.js +6 -2
  408. package/lib/lsp/index.js.map +1 -1
  409. package/lib/lsp/lsp-latency.d.ts +39 -0
  410. package/lib/lsp/lsp-latency.d.ts.map +1 -0
  411. package/lib/lsp/lsp-latency.js +58 -0
  412. package/lib/lsp/lsp-latency.js.map +1 -0
  413. package/lib/lsp/save-text-document.d.ts +31 -0
  414. package/lib/lsp/save-text-document.d.ts.map +1 -0
  415. package/lib/lsp/save-text-document.js +52 -0
  416. package/lib/lsp/save-text-document.js.map +1 -0
  417. package/lib/lsp/semantic-token-provider.d.ts +58 -2
  418. package/lib/lsp/semantic-token-provider.d.ts.map +1 -1
  419. package/lib/lsp/semantic-token-provider.js +98 -9
  420. package/lib/lsp/semantic-token-provider.js.map +1 -1
  421. package/lib/lsp/shared-module.d.ts +4 -8
  422. package/lib/lsp/shared-module.d.ts.map +1 -1
  423. package/lib/lsp/shared-module.js.map +1 -1
  424. package/lib/lsp/start-language-server.d.ts +12 -7
  425. package/lib/lsp/start-language-server.d.ts.map +1 -1
  426. package/lib/lsp/start-language-server.js +21 -7
  427. package/lib/lsp/start-language-server.js.map +1 -1
  428. package/lib/messages/carriers.d.ts +4 -6
  429. package/lib/messages/carriers.d.ts.map +1 -1
  430. package/lib/messages/carriers.js +4 -6
  431. package/lib/messages/carriers.js.map +1 -1
  432. package/lib/messages/index.d.ts +2 -2
  433. package/lib/messages/index.d.ts.map +1 -1
  434. package/lib/messages/index.js +2 -2
  435. package/lib/messages/index.js.map +1 -1
  436. package/lib/messages/renderer.d.ts +10 -4
  437. package/lib/messages/renderer.d.ts.map +1 -1
  438. package/lib/messages/renderer.js +6 -0
  439. package/lib/messages/renderer.js.map +1 -1
  440. package/lib/node/event-loop-monitor.d.ts.map +1 -1
  441. package/lib/node/event-loop-monitor.js +3 -2
  442. package/lib/node/event-loop-monitor.js.map +1 -1
  443. package/lib/node/heap-ceiling.d.ts +61 -0
  444. package/lib/node/heap-ceiling.d.ts.map +1 -0
  445. package/lib/node/heap-ceiling.js +72 -0
  446. package/lib/node/heap-ceiling.js.map +1 -0
  447. package/lib/node/index.d.ts +1 -1
  448. package/lib/node/index.d.ts.map +1 -1
  449. package/lib/node/index.js +5 -1
  450. package/lib/node/index.js.map +1 -1
  451. package/lib/node/latency-from-env.d.ts +1 -1
  452. package/lib/node/latency-from-env.js +1 -1
  453. package/lib/node/lint-grammar.js.map +1 -1
  454. package/lib/node/log-file-sink.d.ts +3 -2
  455. package/lib/node/log-file-sink.d.ts.map +1 -1
  456. package/lib/node/log-file-sink.js +6 -2
  457. package/lib/node/log-file-sink.js.map +1 -1
  458. package/lib/node/log-preamble-node.d.ts +5 -3
  459. package/lib/node/log-preamble-node.d.ts.map +1 -1
  460. package/lib/node/log-preamble-node.js +13 -10
  461. package/lib/node/log-preamble-node.js.map +1 -1
  462. package/lib/node/measure-memory.d.ts.map +1 -1
  463. package/lib/node/measure-memory.js +5 -4
  464. package/lib/node/measure-memory.js.map +1 -1
  465. package/lib/node/memory-monitor.d.ts +2 -2
  466. package/lib/node/memory-monitor.d.ts.map +1 -1
  467. package/lib/node/memory-monitor.js +9 -10
  468. package/lib/node/memory-monitor.js.map +1 -1
  469. package/lib/node/node-file-system-provider.d.ts +67 -9
  470. package/lib/node/node-file-system-provider.d.ts.map +1 -1
  471. package/lib/node/node-file-system-provider.js +198 -53
  472. package/lib/node/node-file-system-provider.js.map +1 -1
  473. package/lib/node/profile-capture.d.ts +12 -4
  474. package/lib/node/profile-capture.d.ts.map +1 -1
  475. package/lib/node/profile-capture.js +8 -6
  476. package/lib/node/profile-capture.js.map +1 -1
  477. package/lib/node/profile-digest.js.map +1 -1
  478. package/lib/node/profiling-run.d.ts +13 -3
  479. package/lib/node/profiling-run.d.ts.map +1 -1
  480. package/lib/node/profiling-run.js +17 -8
  481. package/lib/node/profiling-run.js.map +1 -1
  482. package/lib/node/rename-over-open-readers.d.ts +61 -0
  483. package/lib/node/rename-over-open-readers.d.ts.map +1 -0
  484. package/lib/node/rename-over-open-readers.js +80 -0
  485. package/lib/node/rename-over-open-readers.js.map +1 -0
  486. package/lib/node/server-diagnostics.js +1 -1
  487. package/lib/node/server-diagnostics.js.map +1 -1
  488. package/lib/node/server-state-snapshot.d.ts +6 -5
  489. package/lib/node/server-state-snapshot.d.ts.map +1 -1
  490. package/lib/node/server-state-snapshot.js +20 -17
  491. package/lib/node/server-state-snapshot.js.map +1 -1
  492. package/lib/node/socket-launcher.d.ts +43 -7
  493. package/lib/node/socket-launcher.d.ts.map +1 -1
  494. package/lib/node/socket-launcher.js +42 -7
  495. package/lib/node/socket-launcher.js.map +1 -1
  496. package/lib/node/startup-cpu-profile.d.ts +29 -0
  497. package/lib/node/startup-cpu-profile.d.ts.map +1 -0
  498. package/lib/node/startup-cpu-profile.js +91 -0
  499. package/lib/node/startup-cpu-profile.js.map +1 -0
  500. package/lib/node/stdio-launcher.d.ts +13 -13
  501. package/lib/node/stdio-launcher.d.ts.map +1 -1
  502. package/lib/node/stdio-launcher.js +21 -11
  503. package/lib/node/stdio-launcher.js.map +1 -1
  504. package/lib/node/validate-workspace.d.ts +1 -1
  505. package/lib/node/validate-workspace.d.ts.map +1 -1
  506. package/lib/node/validate-workspace.js +5 -1
  507. package/lib/node/validate-workspace.js.map +1 -1
  508. package/lib/testing/document-uri-policy-conformance.js +1 -1
  509. package/lib/testing/document-uri-policy-conformance.js.map +1 -1
  510. package/lib/testing/fake-description.js.map +1 -1
  511. package/lib/testing/fake-document.d.ts +2 -1
  512. package/lib/testing/fake-document.d.ts.map +1 -1
  513. package/lib/testing/fake-document.js.map +1 -1
  514. package/lib/testing/index.d.ts +1 -1
  515. package/lib/testing/index.d.ts.map +1 -1
  516. package/lib/testing/index.js +2 -1
  517. package/lib/testing/index.js.map +1 -1
  518. package/lib/testing/langium-test-helpers.d.ts.map +1 -1
  519. package/lib/testing/langium-test-helpers.js +1 -0
  520. package/lib/testing/langium-test-helpers.js.map +1 -1
  521. package/lib/testing/make-noop-language-services.js.map +1 -1
  522. package/lib/testing/make-noop-shared-services.js.map +1 -1
  523. package/lib/testing/make-test-services.d.ts +45 -14
  524. package/lib/testing/make-test-services.d.ts.map +1 -1
  525. package/lib/testing/make-test-services.js +23 -7
  526. package/lib/testing/make-test-services.js.map +1 -1
  527. package/lib/testing/make-test-tracer.d.ts +12 -0
  528. package/lib/testing/make-test-tracer.d.ts.map +1 -1
  529. package/lib/testing/make-test-tracer.js +13 -0
  530. package/lib/testing/make-test-tracer.js.map +1 -1
  531. package/lib/testing/node/applied-edit-capture.d.ts +29 -0
  532. package/lib/testing/node/applied-edit-capture.d.ts.map +1 -0
  533. package/lib/testing/node/applied-edit-capture.js +117 -0
  534. package/lib/testing/node/applied-edit-capture.js.map +1 -0
  535. package/lib/testing/node/golden-corpus.js.map +1 -1
  536. package/lib/testing/node/index.d.ts +4 -1
  537. package/lib/testing/node/index.d.ts.map +1 -1
  538. package/lib/testing/node/index.js +4 -1
  539. package/lib/testing/node/index.js.map +1 -1
  540. package/lib/testing/node/lsp-harness.d.ts.map +1 -1
  541. package/lib/testing/node/lsp-harness.js +2 -0
  542. package/lib/testing/node/lsp-harness.js.map +1 -1
  543. package/lib/testing/node/lsp-server-connection.d.ts +21 -6
  544. package/lib/testing/node/lsp-server-connection.d.ts.map +1 -1
  545. package/lib/testing/node/lsp-server-connection.js +49 -106
  546. package/lib/testing/node/lsp-server-connection.js.map +1 -1
  547. package/lib/testing/node/scratch-workspace.d.ts +2 -1
  548. package/lib/testing/node/scratch-workspace.d.ts.map +1 -1
  549. package/lib/testing/node/scratch-workspace.js +12 -6
  550. package/lib/testing/node/scratch-workspace.js.map +1 -1
  551. package/lib/testing/node/settle-server.d.ts +33 -0
  552. package/lib/testing/node/settle-server.d.ts.map +1 -0
  553. package/lib/testing/node/settle-server.js +84 -0
  554. package/lib/testing/node/settle-server.js.map +1 -0
  555. package/lib/testing/node/spawned-server.d.ts +30 -1
  556. package/lib/testing/node/spawned-server.d.ts.map +1 -1
  557. package/lib/testing/node/spawned-server.js +39 -2
  558. package/lib/testing/node/spawned-server.js.map +1 -1
  559. package/lib/testing/playwright/browser-capture-bridge.js.map +1 -1
  560. package/lib/testing/playwright/e2e-profiling.js.map +1 -1
  561. package/lib/testing/playwright/flaky-network-proxy.d.ts +76 -0
  562. package/lib/testing/playwright/flaky-network-proxy.d.ts.map +1 -0
  563. package/lib/testing/playwright/flaky-network-proxy.js +164 -0
  564. package/lib/testing/playwright/flaky-network-proxy.js.map +1 -0
  565. package/lib/testing/playwright/index.d.ts +1 -0
  566. package/lib/testing/playwright/index.d.ts.map +1 -1
  567. package/lib/testing/playwright/index.js +1 -0
  568. package/lib/testing/playwright/index.js.map +1 -1
  569. package/lib/testing/playwright/server-log-capture.d.ts +46 -16
  570. package/lib/testing/playwright/server-log-capture.d.ts.map +1 -1
  571. package/lib/testing/playwright/server-log-capture.js +111 -40
  572. package/lib/testing/playwright/server-log-capture.js.map +1 -1
  573. package/lib/testing/playwright/server-log-fixture.d.ts +16 -0
  574. package/lib/testing/playwright/server-log-fixture.d.ts.map +1 -1
  575. package/lib/testing/playwright/server-log-fixture.js +25 -6
  576. package/lib/testing/playwright/server-log-fixture.js.map +1 -1
  577. package/lib/testing/playwright/server-log-region.d.ts +15 -0
  578. package/lib/testing/playwright/server-log-region.d.ts.map +1 -0
  579. package/lib/testing/playwright/server-log-region.js +30 -0
  580. package/lib/testing/playwright/server-log-region.js.map +1 -0
  581. package/lib/testing/playwright/server-log-rename-reporter.d.ts.map +1 -1
  582. package/lib/testing/playwright/server-log-rename-reporter.js +4 -3
  583. package/lib/testing/playwright/server-log-rename-reporter.js.map +1 -1
  584. package/lib/testing/run-update-pipeline.d.ts +8 -5
  585. package/lib/testing/run-update-pipeline.d.ts.map +1 -1
  586. package/lib/testing/run-update-pipeline.js.map +1 -1
  587. package/lib/testing/stub-ast-document-manager.d.ts +11 -51
  588. package/lib/testing/stub-ast-document-manager.d.ts.map +1 -1
  589. package/lib/testing/stub-ast-document-manager.js +31 -59
  590. package/lib/testing/stub-ast-document-manager.js.map +1 -1
  591. package/lib/testing/stub-document-builder.d.ts +25 -11
  592. package/lib/testing/stub-document-builder.d.ts.map +1 -1
  593. package/lib/testing/stub-document-builder.js +91 -2
  594. package/lib/testing/stub-document-builder.js.map +1 -1
  595. package/lib/testing/stub-hydranium-text-documents.d.ts +33 -10
  596. package/lib/testing/stub-hydranium-text-documents.d.ts.map +1 -1
  597. package/lib/testing/stub-hydranium-text-documents.js +132 -16
  598. package/lib/testing/stub-hydranium-text-documents.js.map +1 -1
  599. package/lib/testing/stub-index-manager.js.map +1 -1
  600. package/lib/testing/stub-langium-documents.d.ts +3 -2
  601. package/lib/testing/stub-langium-documents.d.ts.map +1 -1
  602. package/lib/testing/stub-langium-documents.js.map +1 -1
  603. package/lib/testing/stub-model-service.d.ts +8 -7
  604. package/lib/testing/stub-model-service.d.ts.map +1 -1
  605. package/lib/testing/stub-model-service.js +4 -4
  606. package/lib/testing/stub-model-service.js.map +1 -1
  607. package/lib/testing/stub-project-manager.d.ts.map +1 -1
  608. package/lib/testing/stub-project-manager.js +10 -0
  609. package/lib/testing/stub-project-manager.js.map +1 -1
  610. package/lib/testing/stub-self-save-registry.d.ts +1 -1
  611. package/lib/testing/stub-self-save-registry.d.ts.map +1 -1
  612. package/lib/testing/stub-service-registry.d.ts +1 -1
  613. package/lib/testing/stub-service-registry.js.map +1 -1
  614. package/lib/testing/stub-writable-file-system.d.ts +1 -1
  615. package/lib/testing/stub-writable-file-system.d.ts.map +1 -1
  616. package/lib/testing/stub-writable-file-system.js +2 -1
  617. package/lib/testing/stub-writable-file-system.js.map +1 -1
  618. package/lib/util/connection-liveness.d.ts +22 -6
  619. package/lib/util/connection-liveness.d.ts.map +1 -1
  620. package/lib/util/connection-liveness.js +75 -15
  621. package/lib/util/connection-liveness.js.map +1 -1
  622. package/lib/util/environment.d.ts +7 -0
  623. package/lib/util/environment.d.ts.map +1 -1
  624. package/lib/util/environment.js +15 -1
  625. package/lib/util/environment.js.map +1 -1
  626. package/lib/util/registry.d.ts.map +1 -1
  627. package/package.json +41 -60
  628. package/src/browser/host-heads-in-worker.ts +218 -0
  629. package/src/browser/index.ts +17 -0
  630. package/src/browser/indexeddb-file-system-store.ts +192 -0
  631. package/src/browser/start-language-server-in-worker.ts +56 -0
  632. package/src/documents/ast-document-manager.ts +477 -250
  633. package/src/documents/client-ids.ts +5 -22
  634. package/src/documents/client-session-errors.ts +26 -0
  635. package/src/documents/client-session-registry.ts +262 -0
  636. package/src/documents/dirty-state-tracker.ts +167 -0
  637. package/src/documents/document-release-handler.ts +404 -0
  638. package/src/documents/document-release-scheduler.ts +121 -0
  639. package/src/documents/file-system-task-queue.ts +77 -0
  640. package/src/documents/hydranium-text-documents.ts +1044 -615
  641. package/src/documents/index.ts +10 -2
  642. package/src/documents/language-client-shadow.ts +501 -0
  643. package/src/documents/model-ledger.ts +66 -0
  644. package/src/documents/text-ledger.ts +112 -0
  645. package/src/documents/version-sync-service.ts +304 -0
  646. package/src/index.ts +3 -0
  647. package/src/langium/ast-extension/ast-extension-service.ts +77 -41
  648. package/src/langium/ast-extension/ast-node-builder.ts +35 -13
  649. package/src/langium/bootstrap.ts +79 -43
  650. package/src/langium/build-phase-pass/build-phase-pass-service.ts +29 -19
  651. package/src/langium/build-phase-pass/build-phase-pass.ts +37 -8
  652. package/src/langium/composite-ast-reflection.ts +112 -0
  653. package/src/langium/config/configuration-provider.ts +119 -0
  654. package/src/langium/config/index.ts +1 -0
  655. package/src/langium/diagnostics/console-tee.ts +150 -0
  656. package/src/langium/diagnostics/hydranium-langium-profiler.ts +15 -39
  657. package/src/langium/diagnostics/log-preamble.ts +1 -1
  658. package/src/langium/diagnostics/logger.ts +51 -17
  659. package/src/langium/diagnostics/lsp-logger.ts +83 -45
  660. package/src/langium/document-builder/build-pipeline-integration.ts +57 -32
  661. package/src/langium/document-builder/build-session.ts +4 -3
  662. package/src/langium/document-builder/document-builder.ts +773 -106
  663. package/src/langium/integration-services.ts +20 -23
  664. package/src/langium/integrity/integrity-rule.ts +22 -8
  665. package/src/langium/integrity/integrity-service.ts +656 -90
  666. package/src/langium/keys/containment.ts +3 -2
  667. package/src/langium/keys/name-based-key-provider.ts +24 -12
  668. package/src/langium/language-module.ts +52 -9
  669. package/src/langium/model-service/client-session.ts +769 -0
  670. package/src/langium/model-service/index.ts +2 -0
  671. package/src/langium/model-service/model-events.ts +82 -0
  672. package/src/langium/model-service/model-service.ts +885 -532
  673. package/src/langium/module.ts +141 -65
  674. package/src/langium/naming/name-provider.ts +34 -8
  675. package/src/langium/project/abstract-project-manager.ts +409 -20
  676. package/src/langium/project/project-change-event.ts +25 -3
  677. package/src/langium/project/project-manager.ts +31 -2
  678. package/src/langium/project/single-project-manager.ts +16 -1
  679. package/src/langium/residency/cst-residency-service.ts +210 -87
  680. package/src/langium/scope/ast-node-description-provider.ts +111 -16
  681. package/src/langium/scope/built-local-symbols.ts +13 -0
  682. package/src/langium/scope/fallback-scope.ts +38 -0
  683. package/src/langium/scope/hydranium-scope-computation.ts +45 -44
  684. package/src/langium/scope/hydranium-scope-provider.ts +245 -41
  685. package/src/langium/scope/index.ts +1 -0
  686. package/src/langium/scope/reference-candidate-provider.ts +6 -5
  687. package/src/langium/scope/scope-extension-service.ts +148 -56
  688. package/src/langium/scope/scoped-ast-node-description.ts +1 -3
  689. package/src/langium/serialization/abstract-serializer.ts +57 -41
  690. package/src/langium/serialization/json-serializer.ts +14 -3
  691. package/src/langium/serialization/serializer.ts +1 -1
  692. package/src/langium/serialization/yaml-serializer.ts +26 -4
  693. package/src/langium/service-registry.ts +41 -2
  694. package/src/langium/shared-services.ts +13 -4
  695. package/src/langium/single-langium-copy.ts +42 -0
  696. package/src/langium/transfer/transfer-encoder.ts +76 -50
  697. package/src/langium/trivia/comment-preserver.ts +1410 -0
  698. package/src/langium/trivia/document-ending-preserver.ts +71 -0
  699. package/src/langium/trivia/index.ts +14 -0
  700. package/src/langium/trivia/trivia-contribution.ts +39 -0
  701. package/src/langium/trivia/trivia-preserver.ts +56 -0
  702. package/src/langium/trivia/trivia-service.ts +99 -0
  703. package/src/langium/update-rewrite/update-rewrite-service.ts +1 -1
  704. package/src/langium/update-rewrite/update-rewrite.ts +1 -1
  705. package/src/langium/validation/document-validator.ts +312 -31
  706. package/src/langium/validation/validation-contribution-collector.ts +10 -1
  707. package/src/langium/workspace/ast-node-locator.ts +33 -0
  708. package/src/langium/workspace/document-uri-policy.ts +32 -18
  709. package/src/langium/workspace/file-not-found.ts +35 -0
  710. package/src/langium/workspace/file-system-provider.ts +258 -16
  711. package/src/langium/workspace/hydranium-langium-document-factory.ts +239 -4
  712. package/src/langium/workspace/hydranium-workspace-lock.ts +101 -2
  713. package/src/langium/workspace/hydranium-workspace-manager.ts +214 -35
  714. package/src/langium/workspace/in-memory-file-system-provider.ts +54 -23
  715. package/src/langium/workspace/index.ts +3 -0
  716. package/src/langium/workspace/initialize-workspace.ts +96 -4
  717. package/src/langium/workspace/langium-documents.ts +19 -1
  718. package/src/langium/workspace/persistent-file-system-provider.ts +27 -15
  719. package/src/{documents → langium/workspace}/self-save-registry.ts +12 -14
  720. package/src/langium/workspace/syntax-errors.ts +34 -0
  721. package/src/langium/workspace/virtual-document.ts +106 -25
  722. package/src/langium/workspace/write-lock-scope.ts +27 -12
  723. package/src/launcher/integrated-server.ts +3 -1
  724. package/src/locale/server-locale.ts +6 -6
  725. package/src/lsp/completion/hydranium-completion-provider.ts +82 -2
  726. package/src/lsp/connection-features.ts +67 -0
  727. package/src/lsp/diagnostics-connection.ts +56 -0
  728. package/src/lsp/edit-requests-guard.ts +152 -0
  729. package/src/lsp/hydranium-document-update-handler.ts +284 -110
  730. package/src/lsp/index.ts +6 -2
  731. package/src/lsp/lsp-latency.ts +62 -0
  732. package/src/lsp/save-text-document.ts +63 -0
  733. package/src/lsp/semantic-token-provider.ts +146 -8
  734. package/src/lsp/shared-module.ts +4 -8
  735. package/src/lsp/start-language-server.ts +21 -7
  736. package/src/messages/carriers.ts +4 -6
  737. package/src/messages/index.ts +11 -2
  738. package/src/messages/renderer.ts +11 -3
  739. package/src/node/event-loop-monitor.ts +3 -4
  740. package/src/node/heap-ceiling.ts +108 -0
  741. package/src/node/index.ts +5 -1
  742. package/src/node/latency-from-env.ts +1 -1
  743. package/src/node/log-file-sink.ts +6 -2
  744. package/src/node/log-preamble-node.ts +20 -10
  745. package/src/node/measure-memory.ts +5 -4
  746. package/src/node/memory-monitor.ts +10 -10
  747. package/src/node/node-file-system-provider.ts +214 -57
  748. package/src/node/profile-capture.ts +16 -15
  749. package/src/node/profiling-run.ts +30 -8
  750. package/src/node/rename-over-open-readers.ts +94 -0
  751. package/src/node/server-diagnostics.ts +1 -1
  752. package/src/node/server-state-snapshot.ts +28 -20
  753. package/src/node/socket-launcher.ts +78 -14
  754. package/src/node/startup-cpu-profile.ts +94 -0
  755. package/src/node/stdio-launcher.ts +29 -19
  756. package/src/node/validate-workspace.ts +8 -2
  757. package/src/testing/document-uri-policy-conformance.ts +1 -1
  758. package/src/testing/fake-document.ts +2 -1
  759. package/src/testing/index.ts +2 -1
  760. package/src/testing/langium-test-helpers.ts +1 -0
  761. package/src/testing/make-test-services.ts +83 -31
  762. package/src/testing/make-test-tracer.ts +26 -0
  763. package/src/testing/node/applied-edit-capture.ts +141 -0
  764. package/src/testing/node/index.ts +4 -1
  765. package/src/testing/node/lsp-harness.ts +2 -0
  766. package/src/testing/node/lsp-server-connection.ts +83 -119
  767. package/src/testing/node/scratch-workspace.ts +12 -6
  768. package/src/testing/node/settle-server.ts +89 -0
  769. package/src/testing/node/spawned-server.ts +57 -3
  770. package/src/testing/parse-semantic-root.ts +1 -1
  771. package/src/testing/playwright/flaky-network-proxy.ts +240 -0
  772. package/src/testing/playwright/index.ts +1 -0
  773. package/src/testing/playwright/server-log-capture.ts +137 -47
  774. package/src/testing/playwright/server-log-fixture.ts +46 -6
  775. package/src/testing/playwright/server-log-region.ts +32 -0
  776. package/src/testing/playwright/server-log-rename-reporter.ts +4 -3
  777. package/src/testing/run-update-pipeline.ts +8 -5
  778. package/src/testing/stub-ast-document-manager.ts +47 -123
  779. package/src/testing/stub-document-builder.ts +128 -15
  780. package/src/testing/stub-hydranium-text-documents.ts +184 -27
  781. package/src/testing/stub-langium-documents.ts +3 -2
  782. package/src/testing/stub-model-service.ts +9 -8
  783. package/src/testing/stub-project-manager.ts +10 -0
  784. package/src/testing/stub-self-save-registry.ts +1 -1
  785. package/src/testing/stub-service-registry.ts +1 -1
  786. package/src/testing/stub-writable-file-system.ts +3 -2
  787. package/src/util/connection-liveness.ts +81 -15
  788. package/src/util/environment.ts +24 -2
  789. package/lib/documents/language-client-text-shadow.d.ts +0 -124
  790. package/lib/documents/language-client-text-shadow.d.ts.map +0 -1
  791. package/lib/documents/language-client-text-shadow.js +0 -190
  792. package/lib/documents/language-client-text-shadow.js.map +0 -1
  793. package/lib/documents/self-save-registry.d.ts.map +0 -1
  794. package/lib/documents/self-save-registry.js.map +0 -1
  795. package/lib/lsp/instrument-connection.d.ts +0 -36
  796. package/lib/lsp/instrument-connection.d.ts.map +0 -1
  797. package/lib/lsp/instrument-connection.js +0 -62
  798. package/lib/lsp/instrument-connection.js.map +0 -1
  799. package/lib/node/process-memory.d.ts +0 -66
  800. package/lib/node/process-memory.d.ts.map +0 -1
  801. package/lib/node/process-memory.js +0 -252
  802. package/lib/node/process-memory.js.map +0 -1
  803. package/src/documents/language-client-text-shadow.ts +0 -211
  804. package/src/lsp/instrument-connection.ts +0 -66
  805. package/src/node/process-memory.ts +0 -299
@@ -6,13 +6,15 @@
6
6
  *
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
- import { ObservableValue } from '@hydranium/protocol';
10
- import { DefaultDocumentBuilder, DocumentState, OperationCancelled, UriUtils, interruptAndCheck, isOperationCancelled } from '@hydranium/langium';
9
+ import { Deferred, ObservableValue, describeErrorWithStack } from '@hydranium/protocol';
10
+ import { DefaultDocumentBuilder, DocumentState, MultiMap, OperationCancelled, URI, UriUtils, interruptAndCheck, isOperationCancelled } from '@hydranium/langium';
11
11
  // `Diagnostic` as a VALUE: `renderDiagnostics` needs its `getMessageString`
12
12
  // namespace helper to read the `string | MarkupContent` union without
13
13
  // restating it.
14
- import { CancellationToken, Diagnostic } from 'vscode-languageserver-protocol';
14
+ import { CancellationToken, Diagnostic, Disposable } from 'vscode-languageserver-protocol';
15
+ import { IntegrityService } from '../integrity/integrity-service.js';
15
16
  import { CST_REHYDRATION_RESET_STATE, isCstShed } from '../residency/cst-residency-service.js';
17
+ import { HydraniumWorkspaceLock } from '../workspace/hydranium-workspace-lock.js';
16
18
  import { BuildSession } from './build-session.js';
17
19
  import { labelPhaseListener } from './labeled-phase-listener.js';
18
20
  /** Document states a phase-reached line is emitted for by default — every built phase. */
@@ -24,6 +26,22 @@ export const DEFAULT_LOGGED_PHASES = [
24
26
  DocumentState.IndexedReferences,
25
27
  DocumentState.Validated
26
28
  ];
29
+ /**
30
+ * The build reasons the framework stages through
31
+ * {@link HydraniumDocumentBuilder.markNextReason}: the LSP events the update
32
+ * handler dispatches on, `didRelease` for the builds the
33
+ * `DocumentReleaseHandler` runs once the text store has released a document,
34
+ * and `memberRelink` for the follow-up builds a project manager queues to
35
+ * relink a changed project's members. Exposed so a subclass layering reasons
36
+ * of its own keeps the names the framework emits.
37
+ */
38
+ export const HYDRANIUM_BUILD_REASONS = Object.freeze({
39
+ didOpen: 'didOpen',
40
+ didChangeContent: 'didChangeContent',
41
+ didChangeWatchedFiles: 'didChangeWatchedFiles',
42
+ didRelease: 'didRelease',
43
+ memberRelink: 'memberRelink'
44
+ });
27
45
  /**
28
46
  * Consecutive re-queued builds that leave a waited-on document at the same state
29
47
  * before {@link HydraniumDocumentBuilder.awaitDocumentState} stops re-queuing it.
@@ -32,14 +50,29 @@ export const DEFAULT_LOGGED_PHASES = [
32
50
  * case this exists for.
33
51
  */
34
52
  const MAX_STALLED_REQUEUES = 3;
53
+ /**
54
+ * Whether `store` reports the clients holding a document. Checked by shape,
55
+ * because importing the store's class here closes an import cycle.
56
+ */
57
+ function tracksClients(store) {
58
+ return store !== undefined && 'clientsOf' in store && typeof store.clientsOf === 'function';
59
+ }
60
+ function sameClients(taken, current) {
61
+ return taken !== undefined && taken.length === current.length && taken.every((client, i) => client === current[i]);
62
+ }
35
63
  /**
36
64
  * Extends Langium's {@link DefaultDocumentBuilder} with:
37
65
  *
38
66
  * - **Bug-fixes** (always on): an {@link awaitDocumentState} that waits where
39
- * the default rejects, a {@link prepareBuild} that keeps a cancelled
67
+ * the default rejects (re-queuing, under the workspace lock, a document no
68
+ * build will carry), an {@link awaitBuilderState} that resolves once a
69
+ * phase ends, whether armed during its notification or on a phase no
70
+ * document reached, a {@link prepareBuild} that keeps a cancelled
40
71
  * non-validating build from suppressing validation, and a
41
72
  * {@link shouldRelink} that never judges a document unaffected on an index
42
73
  * that does not describe it.
74
+ * - **Shared locked builds** ({@link scheduleUpdate}): build requests that
75
+ * coincide share one locked build instead of cancelling each other.
43
76
  * - **URI handling** (always on): directory-aware flattening and cascade
44
77
  * deletes in {@link update}, plus the CST-rehydration and cross-document
45
78
  * refresh resets in {@link resetToState}.
@@ -82,12 +115,17 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
82
115
  uriPolicy;
83
116
  clock;
84
117
  messageRenderer;
118
+ /** The lock {@link scheduleUpdate} builds under. */
119
+ workspaceLock;
120
+ /** The latest write {@link scheduleUpdate} queued, until it ends; see {@link ScheduledUpdate}. */
121
+ scheduledUpdate;
85
122
  /** Narrower handle on the same registry as the inherited `serviceRegistry`, for {@link ExtendedServiceRegistry.registrations}. */
86
123
  languageRegistry;
87
124
  languageFileExtensions = [];
88
125
  /** {@link ExtendedServiceRegistry.registrations} {@link languageFileExtensions} was built at; `-1` until first built. */
89
126
  cachedRegistrations = -1;
90
- lastPhaseMs = 0;
127
+ /** Running since the last phase was reached, or since the active build started. */
128
+ sinceLastPhase;
91
129
  /** Resolved from {@link DocumentBuilderOptions.refreshCrossDocumentComputedScopes}. */
92
130
  refreshCrossDocumentComputedScopes;
93
131
  /** LSP event name (e.g. `'didChangeWatchedFiles'`) staged for the next `update()` call. */
@@ -102,18 +140,41 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
102
140
  * construction.
103
141
  */
104
142
  activeSession;
143
+ /** Set while an explicit {@link build} calls the `onUpdate` listeners, see {@link isInsideBuildUpdate}. */
144
+ insideBuildUpdate = false;
145
+ /** How many builds have started and not ended. */
146
+ runningBuilds = 0;
147
+ /** Resolved once {@link runningBuilds} drops back to zero. Set while it is above. */
148
+ runningBuildsEnded;
105
149
  /**
106
150
  * `traceId` of the last build that ended in cancellation, for the successor's
107
151
  * "cancels #N" tag. Held here rather than on a session because the session
108
152
  * that carries it is already gone by the time its successor is opened.
109
153
  */
110
154
  lastCancelledTraceId;
155
+ /** Registered through {@link onDocumentPhaseDelivered}, by phase. */
156
+ documentPhaseDeliveredListeners = new MultiMap();
157
+ /** Registered through {@link onBuildEnded}. */
158
+ buildEndedListeners = new Set();
159
+ /** Held by {@link awaitBuilderState} until {@link runCancelable} sees their state reached. */
160
+ builderStateWaits = new Set();
161
+ /** Set while the lock read {@link checkWaitsOnceDrained} queued has not run. */
162
+ drainCheckQueued = false;
163
+ /** A thunk: a version-sync service whose constructor reads the builder would otherwise be a cycle. */
164
+ versionSyncService;
165
+ /** A thunk: a residency service whose constructor reads the builder would otherwise be a cycle. */
166
+ cstResidency;
167
+ modelLedger;
111
168
  constructor(services, options = {}) {
112
169
  super(services);
113
170
  this.languageRegistry = services.ServiceRegistry;
114
171
  this.uriPolicy = services.workspace.DocumentUriPolicy;
115
172
  this.clock = services.Clock;
116
173
  this.messageRenderer = services.MessageRenderer;
174
+ this.workspaceLock = services.workspace.WorkspaceLock;
175
+ this.versionSyncService = () => services.workspace.VersionSyncService;
176
+ this.cstResidency = () => services.workspace.CstResidencyService;
177
+ this.modelLedger = services.workspace.ModelLedger;
117
178
  this.tracer = services.Tracer.for(options.logName ?? 'DocumentBuilder').trace('instantiated');
118
179
  this.logLevel = options.logLevel ?? 'debug';
119
180
  this.loggedPhases = options.loggedPhases ?? DEFAULT_LOGGED_PHASES;
@@ -131,8 +192,8 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
131
192
  // ============================================================
132
193
  /**
133
194
  * Stage an LSP event name for the next `update()` call. Adopters call before
134
- * the update fires; `HydraniumDocumentUpdateHandler` does it for the
135
- * four LSP events.
195
+ * the update fires; `HydraniumDocumentUpdateHandler` does it for the LSP
196
+ * events, and the release handler for the builds that follow a release.
136
197
  *
137
198
  * The framework stages the value and never reads it back. The consumer is a
138
199
  * subclass overriding the build logging, which takes
@@ -143,6 +204,76 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
143
204
  markNextReason(reason) {
144
205
  this.pendingUpdateReason = reason;
145
206
  }
207
+ /**
208
+ * Call `listener` with a document once every {@link onDocumentPhase}
209
+ * listener of `state` ran for it and none was skipped by cancellation, and
210
+ * with the text version the phase listeners were called at. A write during
211
+ * them moves the document's own version on, past what they saw.
212
+ *
213
+ * Only here is it known what the phase listeners delivered. Langium sets the
214
+ * document's state before it notifies, and a cancel between two listeners
215
+ * skips the rest, leaving the document at the phase with those listeners
216
+ * never run and nothing to run them later. A build-phase listener comes too
217
+ * late: a cancel after this document but before the batch ends skips it,
218
+ * although every listener of this document ran.
219
+ */
220
+ onDocumentPhaseDelivered(state, listener) {
221
+ this.documentPhaseDeliveredListeners.add(state, listener);
222
+ return Disposable.create(() => this.documentPhaseDeliveredListeners.delete(state, listener));
223
+ }
224
+ /**
225
+ * Call `listener` when a build ends: once it has run every phase, which
226
+ * Langium's `onBuildPhase` cannot tell for a build that validates nothing,
227
+ * and once the lock has drained after builds that threw. Builds that throw
228
+ * before that drain share one call, so this does not count builds.
229
+ *
230
+ * A listener runs synchronously, inside the build or inside the lock read
231
+ * that waits for the drain, so it must not wait on a build. One that
232
+ * throws is logged and skipped; the build and the other listeners go on.
233
+ */
234
+ onBuildEnded(listener) {
235
+ this.buildEndedListeners.add(listener);
236
+ return Disposable.create(() => this.buildEndedListeners.delete(listener));
237
+ }
238
+ /** Tell every {@link buildEndedListeners} entry, each in isolation. */
239
+ notifyBuildEnded(event) {
240
+ for (const listener of [...this.buildEndedListeners]) {
241
+ try {
242
+ listener(event);
243
+ }
244
+ catch (error) {
245
+ this.tracer.error(`A build-ended listener failed: ${describeErrorWithStack(error)}`);
246
+ }
247
+ }
248
+ }
249
+ /**
250
+ * Whether an explicit {@link build}, rather than {@link update}, is calling
251
+ * the `onUpdate` listeners. Langium calls them from both. A listener reads
252
+ * this before its first await, since it is set only while `build` runs
253
+ * synchronously, which reaches the listeners. That makes it exact while
254
+ * builds overlap, where no record of the running builds could tell which
255
+ * one is calling.
256
+ */
257
+ isInsideBuildUpdate() {
258
+ return this.insideBuildUpdate;
259
+ }
260
+ /**
261
+ * Whether the build calling the `onUpdate` listeners overlaps another build
262
+ * that still runs, such as an update outside the lock while a locked build
263
+ * runs. A listener reads this before its first await.
264
+ */
265
+ overlapsRunningBuild() {
266
+ return this.runningBuilds > 1;
267
+ }
268
+ /**
269
+ * Resolves once no build is in progress, however each ended, and never
270
+ * rejects. It is `undefined` between builds. During a lock read no locked
271
+ * build runs, so a build seen there runs outside the lock. Builds that
272
+ * overlap count until the last of them ends.
273
+ */
274
+ get activeBuild() {
275
+ return this.runningBuildsEnded?.promise;
276
+ }
146
277
  /**
147
278
  * Diagnostic snapshot for use in timeout/error messages around document
148
279
  * state.
@@ -159,20 +290,44 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
159
290
  // the document is keyed by its real path.
160
291
  const doc = this.langiumDocuments.getDocument(UriUtils.toUri(this.uriPolicy.canonicalUri(uri)));
161
292
  const docState = doc ? DocumentState[doc.state] : 'unknown (document not loaded)';
162
- const lastPhase = this.lastPhaseMs > 0 ? `${Math.round(performance.now() - this.lastPhaseMs)}ms ago` : 'no phase observed';
293
+ const lastPhase = this.sinceLastPhase ? `${Math.round(this.sinceLastPhase.elapsedMs)}ms ago` : 'no phase observed';
163
294
  return `current state: '${docState}', last phase: ${lastPhase}, active build: ${this.formatSession(this.activeSession)}`;
164
295
  }
296
+ /**
297
+ * The last phase a rebuild reaches under {@link updateBuildOptions}:
298
+ * `Validated`, or {@link IntegrityService.SettledState} when rebuilds do
299
+ * not validate, since no build then reaches `Validated` and a wait for it
300
+ * would never end. A document a `shouldValidate` override skips stops
301
+ * short of it; waiting on it is this builder's to resolve. An override that
302
+ * returns a phase rebuilds never reach makes every wait for it hang, the
303
+ * session writes that answer at it included.
304
+ */
305
+ finalBuildState() {
306
+ return this.updateBuildOptions.validation ? DocumentState.Validated : IntegrityService.SettledState;
307
+ }
308
+ /**
309
+ * Whether the build that carries `document` validates it, as Langium's
310
+ * protected `shouldValidate` decides. One it does not validate ends that
311
+ * build at `IndexedReferences`. Answers for the running build once its
312
+ * first phase has started, and before that for the build that last
313
+ * carried `document`.
314
+ */
315
+ shouldValidateDocument(document) {
316
+ return this.shouldValidate(document);
317
+ }
165
318
  /** Render a session for a status line. `undefined` — no build in progress — reads as `none`. */
166
319
  formatSession(session) {
167
320
  if (!session) {
168
321
  return 'none';
169
322
  }
170
323
  const id = session.traceId !== undefined ? `#${session.traceId}` : 'untimed';
171
- return `${id} (${session.trigger}, ${Math.round(performance.now() - session.startMs)}ms in)`;
324
+ return `${id} (${session.trigger}, ${Math.round(session.sinceStart.elapsedMs)}ms in)`;
325
+ }
326
+ waitUntil(state, uriOrToken, cancelToken, options = {}) {
327
+ return URI.isUri(uriOrToken)
328
+ ? this.awaitDocumentState(state, uriOrToken, cancelToken ?? CancellationToken.None, options)
329
+ : super.waitUntil(state, uriOrToken);
172
330
  }
173
- // ============================================================
174
- // Bug-fixes (always on)
175
- // ============================================================
176
331
  /**
177
332
  * Two edge cases the default Langium implementation rejects on:
178
333
  * - Document below target state with no build active (newly-created file):
@@ -187,20 +342,38 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
187
342
  *
188
343
  * Replacing Langium's rejection with a wait makes the wait's liveness this
189
344
  * class's responsibility: a listener can only fire if some build is still
190
- * going to reach `state`. Both re-queue sites below exist for that, and they
191
- * differ only in when the orphaning is observed — {@link isOrphaned} at
192
- * registration time, the `onBuildPhase` branch for a build cancelled after
193
- * the wait was already armed. Re-queuing stops after
345
+ * going to reach `state`. So the wait re-queues the document whenever
346
+ * {@link isOrphaned} holds: once when it is armed, and again after every
347
+ * build that completes (see {@link buildDocuments}). The second check is
348
+ * the one a wait armed during a build needs, since only the build's end
349
+ * shows whether it left the document behind; Langium's `onBuildPhase` for
350
+ * `Validated` cannot serve, as it stays silent for a build that validates
351
+ * nothing, such as the workspace's initial one. A build that throws is
352
+ * checked once the lock drains instead (see {@link checkWaitsOnceDrained}):
353
+ * whatever cancelled it may build nothing. Re-queuing stops after
194
354
  * {@link MAX_STALLED_REQUEUES} builds that fail to advance the document, so a
195
355
  * document the builder will never carry to `state` degrades to a pending wait
196
- * plus a warning rather than an endless build loop.
356
+ * plus a warning rather than an endless build loop. With `rejectWhenStuck`,
357
+ * the wait rejects instead, both then and once
358
+ * `VersionSyncService.requestRecoveryBuild` gives up a re-queued build.
359
+ *
360
+ * A wait for `Validated` on a document that a validating build skips
361
+ * resolves once that build has indexed its references, without diagnostics:
362
+ * see {@link skipsValidation}. Waiting on would never end, and re-queuing
363
+ * would skip it again.
364
+ *
365
+ * A re-queued build takes the {@link WorkspaceLock} (see
366
+ * {@link requeueOrphaned}), so a caller that awaits this wait while it holds
367
+ * the lock, inside a read or write action, deadlocks on a document that needs
368
+ * a re-queue: the build waits for that action to end. Await it outside the
369
+ * lock.
197
370
  */
198
- awaitDocumentState(state, uri, cancelToken) {
371
+ awaitDocumentState(state, uri, cancelToken, { rejectWhenStuck = false } = {}) {
199
372
  const document = this.langiumDocuments.getDocument(uri);
200
373
  if (!document) {
201
374
  return super.awaitDocumentState(state, uri, cancelToken);
202
375
  }
203
- if (document.state >= state) {
376
+ if (document.state >= state || (state === DocumentState.Validated && this.skipsValidation(document))) {
204
377
  return Promise.resolve(uri);
205
378
  }
206
379
  return new Promise((resolve, reject) => {
@@ -213,14 +386,25 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
213
386
  // land while a busy workspace keeps cancelling builds.
214
387
  let stalledRequeues = 0;
215
388
  let lastRequeueState;
389
+ let settled = false;
390
+ let cancelled = false;
391
+ const giveUp = (reason, cause) => {
392
+ cleanup();
393
+ reject(new Error(`Gave up building ${this.formatUri(uri)} to '${DocumentState[state]}' ` +
394
+ `(at '${DocumentState[document.state]}'): ${reason}`, { cause }));
395
+ };
216
396
  const requeue = (reason) => {
217
397
  if (document.state === lastRequeueState) {
218
398
  if (++stalledRequeues > MAX_STALLED_REQUEUES) {
399
+ const stalled = `${stalledRequeues} builds did not advance it`;
400
+ if (rejectWhenStuck) {
401
+ giveUp(stalled);
402
+ return;
403
+ }
219
404
  this.tracer
220
405
  .withUri(uri.toString())
221
406
  .warn(`Giving up re-queuing ${this.formatUri(uri)}: stuck at '${DocumentState[document.state]}', needs ` +
222
- `'${DocumentState[state]}' after ${stalledRequeues} builds that did not advance it. ` +
223
- 'The wait now depends on its cancellation token.');
407
+ `'${DocumentState[state]}' after ${stalled}. The wait now depends on its cancellation token.`);
224
408
  return;
225
409
  }
226
410
  }
@@ -228,7 +412,20 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
228
412
  stalledRequeues = 0;
229
413
  lastRequeueState = document.state;
230
414
  }
231
- this.requeueOrphaned(document, state, reason);
415
+ this.requeueOrphaned(document, state, reason).catch((error) => {
416
+ const line = `A recovery build of ${this.formatUri(uri)} failed. ${describeErrorWithStack(error)}`;
417
+ if (rejectWhenStuck && !settled) {
418
+ giveUp('its recovery build failed', error);
419
+ }
420
+ else if (settled && !cancelled) {
421
+ // The wait ended with an outcome its caller reports, and the retry warned.
422
+ this.tracer.withUri(uri.toString()).debug(line);
423
+ }
424
+ else {
425
+ // The waiter has gone, or waits on its cancellation token alone, so nothing else reports this.
426
+ this.tracer.withUri(uri.toString()).error(line);
427
+ }
428
+ });
232
429
  };
233
430
  const phaseDisposable = this.onDocumentPhase(state, labelPhaseListener((doc) => {
234
431
  if (UriUtils.equals(doc.uri, uri)) {
@@ -236,34 +433,66 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
236
433
  resolve(doc.uri);
237
434
  }
238
435
  }, 'awaitDocumentState'));
239
- const buildDisposable = this.onBuildPhase(DocumentState.Validated, () => {
240
- if (document.state >= state) {
436
+ // The phase after which a validating build either validates the
437
+ // document or has skipped it.
438
+ const skipDisposable = state === DocumentState.Validated
439
+ ? this.onDocumentPhase(DocumentState.IndexedReferences, labelPhaseListener((doc) => {
440
+ if (UriUtils.equals(doc.uri, uri) && this.skipsValidation(doc)) {
441
+ cleanup();
442
+ resolve(doc.uri);
443
+ }
444
+ }, 'awaitDocumentState.skipsValidation'))
445
+ : Disposable.create(() => undefined);
446
+ const buildEnded = ({ completed }) => {
447
+ if (document.state >= state || (state === DocumentState.Validated && this.skipsValidation(document))) {
241
448
  cleanup();
242
449
  resolve(uri);
243
450
  }
244
- else {
245
- // Orphaned by a cancelled build — re-queue so the next build catches it up.
246
- requeue('cancelled build');
451
+ else if (completed ? this.isOrphaned(document, state) : this.activeSession === undefined) {
452
+ // No build is left to carry the document to `state`. Either
453
+ // check fails only while an unlocked build still runs; that
454
+ // build carries the document or ends here too.
455
+ requeue(completed ? 'build ended short of the target' : 'build ended early');
247
456
  }
248
- });
457
+ };
458
+ const buildDisposable = this.onBuildEnded(buildEnded);
249
459
  const cancelDisposable = cancelToken.onCancellationRequested(() => {
460
+ cancelled = true;
250
461
  cleanup();
251
462
  reject(OperationCancelled);
252
463
  });
253
464
  const cleanup = () => {
465
+ settled = true;
254
466
  phaseDisposable.dispose();
467
+ skipDisposable.dispose();
255
468
  buildDisposable.dispose();
256
469
  cancelDisposable.dispose();
257
470
  };
258
471
  // Orphaned BEFORE the wait was armed: the build that would have
259
- // advanced this document has already finished, so neither listener
260
- // above can ever fire. Re-queue now — the listeners are registered, so
261
- // the resulting build resolves this wait.
262
- if (this.isOrphaned(document, state)) {
472
+ // advanced this document has already finished, so none of these
473
+ // listeners fires until some other build runs. Re-queue now — the listeners are
474
+ // registered, so the resulting build resolves this wait.
475
+ // With `rejectWhenStuck`, also a document a failed build left behind:
476
+ // no build ends to re-queue it, so the wait would never give up.
477
+ if (this.isOrphaned(document, state) || (rejectWhenStuck && this.activeSession === undefined)) {
263
478
  requeue('quiescent builder');
264
479
  }
265
480
  });
266
481
  }
482
+ /**
483
+ * Whether the build that carries or last carried `document` has indexed its
484
+ * references, asks for validation, and still skips it, which is an override
485
+ * of `shouldValidate` excluding it. A build that does not ask for
486
+ * validation, such as the workspace's initial one, is not a skip: the next
487
+ * validating build validates the document. Nor is a document below
488
+ * `IndexedReferences`: the build writes its options before the first phase,
489
+ * so the document would pass for skipped before it is even parsed.
490
+ */
491
+ skipsValidation(document) {
492
+ return (document.state >= DocumentState.IndexedReferences &&
493
+ Boolean(this.getBuildOptions(document).validation) &&
494
+ !this.shouldValidate(document));
495
+ }
267
496
  /**
268
497
  * Whether no build will advance `document` to `state`, so a wait on it can
269
498
  * only be resolved by starting one.
@@ -281,25 +510,307 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
281
510
  * `currentState` still advances to `Validated` (the validation phase runs
282
511
  * over an empty document list). Any first read that wants diagnostics — a
283
512
  * one-shot data-head read, a CLI query, `ModelService.validated` — lands
284
- * here.
513
+ * here. A read that arrives while that build still runs finds `currentState`
514
+ * below `state`, so this holds for it only once the build has ended, which
515
+ * is why {@link awaitDocumentState} asks again then.
285
516
  */
286
517
  isOrphaned(document, state) {
287
518
  return document.state < state && this.currentState >= state;
288
519
  }
289
520
  /**
290
- * Schedule a build for a document no in-flight build will advance. Deliberately
291
- * fire-and-forget: the caller is a waiter that resolves off the resulting phase
292
- * notification, so awaiting here would invert the dependency. A rejection is
293
- * logged rather than swallowed — it leaves the waiter pending until its own
294
- * cancellation token fires, which is worth a line in the log.
521
+ * Resolve once `currentState` reaches `state`, which {@link runCancelable}
522
+ * checks after every phase.
523
+ *
524
+ * Langium's waits for `onBuildPhase(state)`, which never fires for a wait
525
+ * armed while that phase notifies its listeners: the notification calls a
526
+ * copy of the listener list taken before it yields to the event loop, and
527
+ * `currentState` is raised only after it. Nor does it fire for a phase no
528
+ * document reached. Either way the wait never ends, and neither does the
529
+ * request Langium holds on it.
530
+ */
531
+ awaitBuilderState(state, cancelToken) {
532
+ if (this.currentState >= state) {
533
+ return Promise.resolve();
534
+ }
535
+ if (cancelToken.isCancellationRequested) {
536
+ return Promise.reject(OperationCancelled);
537
+ }
538
+ return new Promise((resolve, reject) => {
539
+ const settle = (outcome) => {
540
+ this.builderStateWaits.delete(wait);
541
+ cancelled.dispose();
542
+ outcome();
543
+ };
544
+ const wait = { state, resolve: () => settle(resolve) };
545
+ const cancelled = cancelToken.onCancellationRequested(() => settle(() => reject(OperationCancelled)));
546
+ this.builderStateWaits.add(wait);
547
+ });
548
+ }
549
+ async runCancelable(documents, targetState, cancelToken, callback) {
550
+ await super.runCancelable(documents, targetState, cancelToken, callback);
551
+ for (const wait of this.builderStateWaits) {
552
+ if (this.currentState >= wait.state) {
553
+ wait.resolve();
554
+ }
555
+ }
556
+ }
557
+ /**
558
+ * Schedule a build for a document no in-flight build will advance, through
559
+ * `VersionSyncService.requestRecoveryBuild`: from a {@link WorkspaceLock} read, so
560
+ * the build neither runs beside a locked one nor cancels the build a
561
+ * re-queue is fired from, and skipped if a write that ran meanwhile carried
562
+ * the document to `state`. The waiter resolves off the resulting phase
563
+ * notification; the promise only tells it whether the build was given up.
295
564
  */
296
565
  requeueOrphaned(document, state, reason) {
297
566
  const tracer = this.tracer.withUri(document.uri.toString());
298
- tracer.info(`Re-queuing orphaned document (at '${DocumentState[document.state]}', needs '${DocumentState[state]}'): ${reason}`);
299
- this.update([document.uri], []).catch((err) => {
300
- if (!isOperationCancelled(err)) {
301
- tracer.error(`Re-queue build failed: ${err instanceof Error ? err.message : String(err)}`);
567
+ tracer.debug(`Re-queuing orphaned document (at '${DocumentState[document.state]}', needs '${DocumentState[state]}'): ${reason}`);
568
+ return this.versionSyncService().requestRecoveryBuild(document.uri, {
569
+ // Skipped on purpose: a waiting caller is answered sooner, at the cost
570
+ // of a possible duplicate build once the debounce fires.
571
+ ignoreDeferred: true,
572
+ stillNeeded: () => document.state < state
573
+ });
574
+ }
575
+ // ============================================================
576
+ // Scheduled updates — one locked build for requests that coincide
577
+ // ============================================================
578
+ /**
579
+ * Build `changed` and `deleted` under the {@link WorkspaceLock}, as
580
+ * `workspaceLock.write(token => update(changed, deleted, token))` would,
581
+ * except where the build this method queued last already carries the
582
+ * request. The promise settles when the build that carries the request
583
+ * ends, completed or cancelled, as the lock's own promise does.
584
+ *
585
+ * Without it, requests that coincide cancel each other: each lock write
586
+ * cancels the one before it, after Langium's `update` has already reset the
587
+ * documents, scanned the workspace for relinking and called every
588
+ * `onUpdate` listener.
589
+ *
590
+ * - **Queued, not yet running:** the request merges into it, so nothing is
591
+ * cancelled. The later of a change and a deletion of one URI wins, so
592
+ * each URI reaches `update` in one list only: a file deleted and written
593
+ * again before the build starts is a change.
594
+ * - **Running:** the request joins it only when {@link canJoinRunningUpdate}
595
+ * holds, which keeps an edit made while it runs cancelling it.
596
+ * - **Otherwise,** or when anything else has cancelled that write since it
597
+ * was queued, a new write, which cancels the running build as any lock
598
+ * write does.
599
+ *
600
+ * `reason` is staged through {@link markNextReason} when the write runs. The
601
+ * latest reason of a merged request wins, as it does in the update
602
+ * handler's own debounced burst; a joining request's reason is dropped, since
603
+ * the build it joins has already started. A request without one leaves a
604
+ * reason staged by the caller in place.
605
+ *
606
+ * A caller that must run code of its own inside the write action takes the
607
+ * lock itself, and forgoes the sharing. A lock that is not a
608
+ * {@link HydraniumWorkspaceLock} cannot report a cancelled queued write, so
609
+ * every request then takes its own write.
610
+ */
611
+ scheduleUpdate(changed, deleted, reason) {
612
+ const lock = this.workspaceLock;
613
+ if (!(lock instanceof HydraniumWorkspaceLock)) {
614
+ return lock.write(token => {
615
+ if (reason !== undefined) {
616
+ this.markNextReason(reason);
617
+ }
618
+ return this.update(changed, deleted, token);
619
+ });
620
+ }
621
+ const scheduled = this.scheduledUpdate;
622
+ if (scheduled && scheduled.cancellations === lock.writeCancellations) {
623
+ if (!scheduled.takenVersions) {
624
+ for (const uri of changed) {
625
+ scheduled.changed.set(uri.toString(), uri);
626
+ scheduled.deleted.delete(uri.toString());
627
+ }
628
+ for (const uri of deleted) {
629
+ scheduled.deleted.set(uri.toString(), uri);
630
+ scheduled.changed.delete(uri.toString());
631
+ }
632
+ scheduled.reason = reason ?? scheduled.reason;
633
+ return scheduled.promise;
634
+ }
635
+ if (this.canJoinRunningUpdate(scheduled, changed, deleted)) {
636
+ return scheduled.promise;
637
+ }
638
+ }
639
+ // The action runs on a later tick, by which time `request` is assigned.
640
+ const promise = lock.write(token => this.runScheduledUpdate(request, token));
641
+ const request = {
642
+ changed: new Map(changed.map(uri => [uri.toString(), uri])),
643
+ deleted: new Map(deleted.map(uri => [uri.toString(), uri])),
644
+ reason,
645
+ cancellations: lock.writeCancellations,
646
+ promise
647
+ };
648
+ this.scheduledUpdate = request;
649
+ return promise;
650
+ }
651
+ /**
652
+ * Whether a request for `changed` and `deleted` is carried by the running
653
+ * `scheduled` build, whose write nothing has cancelled: the request deletes
654
+ * nothing, and each changed URI is one the build took, held by the text
655
+ * store at the version it had when the build started.
656
+ *
657
+ * Each condition keeps a request from joining a build that would miss its
658
+ * change. Text that moved since the start may be newer than what the build
659
+ * parsed; a URI the text store does not hold is read from its file, which
660
+ * may have changed after the build read it; and a deletion may concern a
661
+ * document the build has already built. A joined request is also absent
662
+ * from the running `update`'s `onUpdate` call, which reported the store as
663
+ * it was when the build started; at an unchanged version that is the store
664
+ * the request sees.
665
+ *
666
+ * The clients holding each URI must be unchanged too. Phase listeners that
667
+ * ask who holds a document, such as the push to an editor, may already have
668
+ * run for it, so a client that attached since would get no build that sees it.
669
+ */
670
+ canJoinRunningUpdate(scheduled, changed, deleted) {
671
+ const taken = scheduled.takenVersions;
672
+ const takenClients = scheduled.takenClients;
673
+ if (!taken || deleted.length > 0) {
674
+ return false;
675
+ }
676
+ return changed.every(uri => taken.has(uri.toString()) &&
677
+ taken.get(uri.toString()) === this.textDocuments?.get(uri)?.version &&
678
+ sameClients(takenClients?.get(uri.toString()), this.clientsHolding(uri)));
679
+ }
680
+ /** The clients holding `uri` in the text store, or none when the store does not track them. */
681
+ clientsHolding(uri) {
682
+ const store = this.textDocuments;
683
+ return tracksClients(store) ? store.clientsOf(uri.toString()) : [];
684
+ }
685
+ /**
686
+ * The write action of a {@link scheduleUpdate}: freeze the request, record
687
+ * what it takes, stage its reason and run `update`. Releases
688
+ * {@link scheduledUpdate} inside the lock, whatever throws, so a request
689
+ * arriving after the build ends starts a write of its own rather than
690
+ * joining a build that is over.
691
+ */
692
+ async runScheduledUpdate(request, token) {
693
+ try {
694
+ const taken = new Map();
695
+ const takenClients = new Map();
696
+ for (const [key, uri] of request.changed) {
697
+ const version = this.textDocuments?.get(uri)?.version;
698
+ if (version !== undefined) {
699
+ taken.set(key, version);
700
+ }
701
+ takenClients.set(key, this.clientsHolding(uri));
702
+ }
703
+ request.takenClients = takenClients;
704
+ request.takenVersions = taken;
705
+ if (request.reason !== undefined) {
706
+ this.markNextReason(request.reason);
707
+ }
708
+ await this.update([...request.changed.values()], [...request.deleted.values()], token);
709
+ }
710
+ finally {
711
+ if (this.scheduledUpdate === request) {
712
+ this.scheduledUpdate = undefined;
713
+ }
714
+ }
715
+ }
716
+ /**
717
+ * Tell the {@link buildEndedListeners} once every phase has run, which is
718
+ * the one point where a build that skipped a waited-on document can be seen
719
+ * to have ended. Langium's `onBuildPhase` for `Validated` is not: it stays
720
+ * silent when no document reached that phase, which is every build that
721
+ * validates nothing, the workspace's initial one among them.
722
+ *
723
+ * A build that throws, whether cancelled or failed, tells none of them
724
+ * here: `currentState` is then below `Validated`, so {@link isOrphaned}
725
+ * could hold for no wait. {@link checkWaitsOnceDrained} tells them instead.
726
+ */
727
+ async buildDocuments(documents, options, cancelToken) {
728
+ await this.rehydrateShedDocuments(documents, cancelToken);
729
+ this.unlinkPrelinkedReferences(documents);
730
+ await super.buildDocuments(documents, options, cancelToken);
731
+ this.notifyBuildEnded({ completed: true });
732
+ }
733
+ /**
734
+ * Graft the CST back onto every shed document the build advances, keeping
735
+ * its AST nodes so dependents outside the build stay linked to them.
736
+ * Indexing a document's references without its CST drops them from the
737
+ * reference index, so it would no longer be relinked when its targets
738
+ * change. Runs before Langium prepares the build, one document at a time
739
+ * with a cancellation check between, as the parse phase does. A refused or
740
+ * diverged graft resets the document to `Changed`, so this build re-parses
741
+ * it, and asks for a build after this one, whose relink selection reaches
742
+ * its dependents as those of a changed document. A document without a CST
743
+ * or a text to graft one from is reset the same way when it can be re-read.
744
+ */
745
+ async rehydrateShedDocuments(documents, cancelToken) {
746
+ for (const document of documents) {
747
+ if (document.state < DocumentState.Validated && isCstShed(document, this.modelLedger)) {
748
+ await interruptAndCheck(cancelToken);
749
+ this.tracer.debug(`rehydrating CST of ${this.formatUri(document.uri)} (re-entered build while shed)`);
750
+ this.cstResidency().rehydrate(document);
751
+ if (isCstShed(document, this.modelLedger)) {
752
+ this.resetToState(document, CST_REHYDRATION_RESET_STATE);
753
+ this.versionSyncService().rebuildWhileCurrent(document);
754
+ }
755
+ }
756
+ else if (document.state < DocumentState.Validated && this.hasNoCstToGraft(document) && (await this.hasReadableText(document))) {
757
+ await interruptAndCheck(cancelToken);
758
+ this.tracer.debug(`re-reading ${this.formatUri(document.uri)} (re-entered build without a CST to graft)`);
759
+ this.resetToState(document, CST_REHYDRATION_RESET_STATE);
760
+ this.versionSyncService().rebuildWhileCurrent(document);
761
+ }
762
+ }
763
+ }
764
+ /**
765
+ * Whether `document` has an AST but no CST and no text to graft one from,
766
+ * as a `fromModel` document without a serializer has. Such a document is
767
+ * re-read when {@link hasReadableText}, so its references are indexed.
768
+ * Synchronous, so a build awaits nothing for a document with a CST.
769
+ */
770
+ hasNoCstToGraft(document) {
771
+ const root = document.parseResult?.value;
772
+ return (document.state >= DocumentState.Parsed &&
773
+ root !== undefined &&
774
+ root.$cstNode === undefined &&
775
+ this.modelLedger.textOf(root) === undefined);
776
+ }
777
+ /** Whether the store or a file holds the text of `document`. Without either, reading it would fail. */
778
+ async hasReadableText(document) {
779
+ return this.textDocuments?.get(document.uri) !== undefined || (await this.fileSystemProvider.exists(document.uri));
780
+ }
781
+ /**
782
+ * Unlink every document of the build that is below `Linked` but lists
783
+ * references, so the link phase resolves and indexes them. Such a document
784
+ * is mostly a code-built one, which holds the targets its code set until
785
+ * its first build. Any other document had references resolved before its
786
+ * link phase, by a cancelled build or a lazy read, and they are resolved
787
+ * again.
788
+ */
789
+ unlinkPrelinkedReferences(documents) {
790
+ for (const document of documents) {
791
+ if (document.state < DocumentState.Linked && document.references.length > 0) {
792
+ this.languageRegistry.getServices(document.uri).references.Linker.unlink(document);
302
793
  }
794
+ }
795
+ }
796
+ /**
797
+ * After a build that threw, tell the {@link buildEndedListeners}, with
798
+ * `completed` false, from a {@link WorkspaceLock} read: it runs once no write
799
+ * runs or is queued, so no locked build is left that could still carry a
800
+ * waited-on document. A cancelled build is usually followed by its
801
+ * canceller's, but a write that builds nothing, such as a release build
802
+ * that finds its document reopened, leaves a wait armed during the build
803
+ * with nothing to resolve it, and so does a build that fails. One read
804
+ * serves every build that throws before it runs.
805
+ */
806
+ checkWaitsOnceDrained() {
807
+ if (this.drainCheckQueued) {
808
+ return;
809
+ }
810
+ this.drainCheckQueued = true;
811
+ void this.workspaceLock.read(() => {
812
+ this.drainCheckQueued = false;
813
+ this.notifyBuildEnded({ completed: false });
303
814
  });
304
815
  }
305
816
  /**
@@ -359,6 +870,9 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
359
870
  * Treating an un-indexed document as affected is the conservative reading and
360
871
  * costs nothing in steady state — documents sit at `Validated` there, so this
361
872
  * branch is only taken for documents an interrupted build left behind.
873
+ *
874
+ * Public so a service that requests a build can skip one that would relink
875
+ * nothing.
362
876
  */
363
877
  shouldRelink(document, changedUris) {
364
878
  if (document.state < DocumentState.IndexedReferences) {
@@ -388,7 +902,14 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
388
902
  */
389
903
  build(documents, options, cancelToken) {
390
904
  const uris = documents.map(document => document.uri);
391
- return this.runInSession({ kind: 'build', trigger: `${documents.length} docs`, triggerCountsDocs: true, changed: uris, deleted: [] }, `Build documents (${documents.length} docs)`, () => super.build(documents, options, cancelToken));
905
+ const outer = this.insideBuildUpdate;
906
+ this.insideBuildUpdate = true;
907
+ try {
908
+ return this.runInSession({ kind: 'build', trigger: `${documents.length} docs`, triggerCountsDocs: true, changed: uris, deleted: [] }, `Build documents (${documents.length} docs)`, () => super.build(documents, options, cancelToken));
909
+ }
910
+ finally {
911
+ this.insideBuildUpdate = outer;
912
+ }
392
913
  }
393
914
  /**
394
915
  * Refresh cross-document `ComputedScopes` derivations on cascade, when
@@ -416,27 +937,6 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
416
937
  * document per cascade.
417
938
  */
418
939
  resetToState(document, state) {
419
- // Rehydrate-on-re-entry after CST shedding. A document whose CST was shed to
420
- // reclaim memory (its `parseResult.value.$cstNode` nulled while the AST stays
421
- // resident) cannot be relinked or re-indexed in place: Langium's
422
- // `DefaultReferenceDescriptionProvider` derives the reference index — and thus
423
- // `IndexManager.isAffected`, plus the `segment` used by rename / find-references —
424
- // from each `reference.$refNode`. Re-running `IndexedReferences` with a shed CST
425
- // drops the document's cross-references from the index (the provider skips any
426
- // reference whose `$refNode` is missing), so its dependents silently stop being
427
- // relinked when a referenced document changes, and they keep stale `.ref`s.
428
- //
429
- // So any re-entry into the build for a shed document must start from a full
430
- // re-parse, which rebuilds the CST (and every `$refNode`). The residency
431
- // feature owns both the "is shed" predicate and the recovery reset state
432
- // (`CST_REHYDRATION_RESET_STATE`, necessarily `Changed`); this
433
- // supersedes the `IndexedContent` cascade reset below — a re-parse re-runs
434
- // every phase regardless.
435
- if (isCstShed(document)) {
436
- this.tracer.debug(`rehydrating CST of ${this.formatUri(document.uri)} (re-entered build while shed)`);
437
- super.resetToState(document, CST_REHYDRATION_RESET_STATE);
438
- return;
439
- }
440
940
  const targetState = this.refreshCrossDocumentComputedScopes && state === DocumentState.ComputedScopes ? DocumentState.IndexedContent : state;
441
941
  super.resetToState(document, targetState);
442
942
  }
@@ -477,6 +977,10 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
477
977
  * re-parsed AST would otherwise lack them. The caller
478
978
  * runs inside the `Linked` build phase; the build carries the document
479
979
  * through IndexedReferences + Validation (and their `onDocumentPhase`) next.
980
+ *
981
+ * Only this document is relinked. The documents that reference it still
982
+ * hold nodes a re-parse replaced, or names a mutation changed, so the
983
+ * caller has to relink them in a later build.
480
984
  */
481
985
  async reparseAndRelink(document, cancelToken = CancellationToken.None) {
482
986
  const languageServices = this.serviceRegistry.getServices(document.uri);
@@ -529,13 +1033,25 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
529
1033
  * documents*: the Node provider walks the real filesystem (a freshly added
530
1034
  * directory or never-opened file still builds), while a browser / empty
531
1035
  * provider yields nothing. `uriPolicy.loadUri` first maps the URI to its
532
- * load identity — `undefined` (no on-disk content) short-circuits to `[]`
533
- * rather than a doomed read, and a symlink resolves to its real path so the
534
- * built documents key the same way every other layer does.
1036
+ * load identity, and a symlink resolves to its real path so the built
1037
+ * documents key the same way every other layer does.
1038
+ *
1039
+ * A URI with no on-disk content is dropped rather than read, unless the text
1040
+ * store or the document registry holds it, under its canonical URI, the key
1041
+ * both hold it by. A document created and not yet saved has text but no
1042
+ * file, and a policy that checks the disk reports it absent. A registered
1043
+ * document whose file has gone is kept too: its rebuild then fails on the
1044
+ * read, which is how the release handler learns to remove it rather
1045
+ * than leave it holding its last client's text.
535
1046
  */
536
1047
  flattenAndAdaptURI(uri) {
537
1048
  const resolved = this.uriPolicy.loadUri(uri);
538
- return resolved ? this.collectLanguageFiles(resolved) : [];
1049
+ if (resolved) {
1050
+ return this.collectLanguageFiles(resolved);
1051
+ }
1052
+ const canonical = UriUtils.toUri(this.uriPolicy.canonicalUri(uri));
1053
+ const held = this.textDocuments?.get(canonical) !== undefined || this.langiumDocuments.hasDocument(canonical);
1054
+ return held ? this.collectLanguageFiles(canonical) : [];
539
1055
  }
540
1056
  /** Recurse `uri` through the `FileSystemProvider`, gathering registered
541
1057
  * language files. A directory's entries carry their own `isDirectory`, so
@@ -596,19 +1112,20 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
596
1112
  * readable by the time Langium's `update` consults `shouldRelink`.
597
1113
  *
598
1114
  * Teardown is preemption-correct, which is the reason this is framework code
599
- * rather than a recipe. Langium's write mutex cancels an in-flight build when
600
- * a later one arrives, so two sessions overlap: the successor installs itself
601
- * as {@link activeSession} while the predecessor is still unwinding, and the
602
- * predecessor's `finally` runs LAST. Clearing unconditionally there would
603
- * discard the winner's state mid-build. Only the session that is still
604
- * current clears — and the check is reference equality on the session object,
1115
+ * rather than a recipe. A build outside the workspace lock overlaps another:
1116
+ * the later one installs itself as {@link activeSession} while the earlier
1117
+ * one is still running, and the earlier one's `finally` runs LAST. Clearing
1118
+ * unconditionally there would discard the later build's state mid-build.
1119
+ * Only the session that is still current clears — and the check is
1120
+ * reference equality on the session object,
605
1121
  * not on {@link BuildSession.traceId}, which is `undefined` for every build
606
1122
  * whenever the timing level is suppressed and would compare equal to itself
607
1123
  * across two different builds.
608
1124
  *
609
- * Re-entrancy is not hypothetical even without an adopter: {@link
610
- * requeueOrphaned} calls `update` from inside a wait, while a build may be
611
- * running.
1125
+ * Builds outside the lock are not hypothetical even without an adopter: the
1126
+ * model service under `allowReentrantBuilds` starts one. Two locked builds
1127
+ * never overlap, since the lock starts a write only once the write it
1128
+ * cancelled has unwound.
612
1129
  */
613
1130
  runInSession(context, label, body) {
614
1131
  // Read before installing the new session: the id being superseded belongs
@@ -629,8 +1146,13 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
629
1146
  this.activeSession = session;
630
1147
  // A phase's "since previous phase" must measure from the build's start,
631
1148
  // not from whenever the last build's final phase happened to land.
632
- this.lastPhaseMs = session.startMs;
1149
+ this.sinceLastPhase = session.sinceStart;
633
1150
  return this.tracer.time(label, async () => {
1151
+ // Counted in the body, which the tracer calls synchronously, so a
1152
+ // tracer that throws first leaves no build counted forever.
1153
+ if (this.runningBuilds++ === 0) {
1154
+ this.runningBuildsEnded = new Deferred();
1155
+ }
634
1156
  try {
635
1157
  await body();
636
1158
  }
@@ -638,10 +1160,19 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
638
1160
  if (isOperationCancelled(err)) {
639
1161
  session.cancelled = true;
640
1162
  }
1163
+ this.checkWaitsOnceDrained();
641
1164
  throw err;
642
1165
  }
643
1166
  finally {
644
- this.endSession(session);
1167
+ try {
1168
+ this.endSession(session);
1169
+ }
1170
+ finally {
1171
+ if (--this.runningBuilds === 0) {
1172
+ this.runningBuildsEnded?.resolve();
1173
+ this.runningBuildsEnded = undefined;
1174
+ }
1175
+ }
645
1176
  }
646
1177
  }, this.logLevel, {
647
1178
  logAfterMs: 0,
@@ -659,7 +1190,7 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
659
1190
  * throughout it.
660
1191
  */
661
1192
  createBuildSession(context) {
662
- return new BuildSession(performance.now(), context.trigger, context.triggerCountsDocs, this.phaseDetailMs.value);
1193
+ return new BuildSession(this.clock.stopwatch(), context.trigger, context.triggerCountsDocs, this.phaseDetailMs.value);
663
1194
  }
664
1195
  /**
665
1196
  * Close `session`: flush what it buffered, then release it if it is still the
@@ -682,8 +1213,7 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
682
1213
  * {@link log}, which would route them straight back into the buffer.
683
1214
  */
684
1215
  flushSession(session) {
685
- const elapsedMs = performance.now() - session.startMs;
686
- if (elapsedMs >= session.detailThresholdMs) {
1216
+ if (session.sinceStart.elapsedMs >= session.detailThresholdMs) {
687
1217
  for (const line of session.bufferedLines) {
688
1218
  this.emit(line);
689
1219
  }
@@ -726,9 +1256,8 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
726
1256
  }
727
1257
  /** Called once per phase-reached event. Override to add custom side-effects beyond logging. */
728
1258
  onPhaseReached(state, documents) {
729
- const now = performance.now();
730
- const elapsedMs = Math.round(now - this.lastPhaseMs);
731
- this.lastPhaseMs = now;
1259
+ const elapsedMs = Math.round(this.sinceLastPhase?.elapsedMs ?? 0);
1260
+ this.sinceLastPhase = this.clock.stopwatch();
732
1261
  // Counted before the line is formatted, so the formatter stays a pure
733
1262
  // function of state a caller can also set up in a test.
734
1263
  if (this.activeSession) {
@@ -754,12 +1283,12 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
754
1283
  docInfo = documents.length === 1 ? this.formatUri(documents[0].uri) : `${documents.length} docs`;
755
1284
  }
756
1285
  const elapsedInfo = session && session.phasesLogged <= 1
757
- ? `${Math.round(performance.now() - session.startMs)}ms since build start`
1286
+ ? `${Math.round(session.sinceStart.elapsedMs)}ms since build start`
758
1287
  : `${elapsedMs}ms since previous phase`;
759
1288
  return `Reached phase '${DocumentState[state]}' [${docInfo}, ${elapsedInfo}]`;
760
1289
  }
761
1290
  // ============================================================
762
- // Logging — slow-listener breakdown on notifyDocumentPhase
1291
+ // notifyDocumentPhase — the delivery hook and the slow-listener breakdown
763
1292
  // ============================================================
764
1293
  async notifyDocumentPhase(document, state, cancelToken) {
765
1294
  // Before the listeners, one of which is Langium's diagnostics publisher.
@@ -768,7 +1297,7 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
768
1297
  // replacing it, and the publisher reads that array when it is invoked. A
769
1298
  // build settling inside that window therefore appends after this call has
770
1299
  // already deduped, and the appended duplicate is published by the listener
771
- // of the build that deduped. Only `serializeBuilds` closes the window.
1300
+ // of the build that deduped. Only the write lock closes the window.
772
1301
  //
773
1302
  // Dedupe before rendering: rendering is deterministic, so it cannot
774
1303
  // change which entries are structurally equal, and fewer survive to render.
@@ -776,13 +1305,8 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
776
1305
  this.dedupeDiagnostics(document);
777
1306
  this.renderDiagnostics(document);
778
1307
  }
779
- if (this.logLevel === 'off') {
780
- return super.notifyDocumentPhase(document, state, cancelToken);
781
- }
782
1308
  const listeners = this.documentPhaseListeners.get(state).slice();
783
- if (listeners.length === 0) {
784
- return;
785
- }
1309
+ const version = document.textDocument.version;
786
1310
  const perListenerMs = [];
787
1311
  let cancelledListeners = 0;
788
1312
  const { elapsedMs: totalMs } = await this.clock.measure(async () => {
@@ -802,10 +1326,18 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
802
1326
  perListenerMs.push(elapsedMs);
803
1327
  }
804
1328
  });
1329
+ if (cancelledListeners === 0) {
1330
+ for (const delivered of this.documentPhaseDeliveredListeners.get(state).slice()) {
1331
+ delivered(document, version);
1332
+ }
1333
+ }
1334
+ if (this.logLevel === 'off' || listeners.length === 0) {
1335
+ return;
1336
+ }
805
1337
  if (cancelledListeners > 0) {
806
1338
  this.tracer
807
1339
  .withUri(document.uri.toString())
808
- .info(this.cancelledDocumentPhaseLine(document, state, cancelledListeners, listeners.length));
1340
+ .debug(this.cancelledDocumentPhaseLine(document, state, cancelledListeners, listeners.length));
809
1341
  }
810
1342
  if (totalMs >= this.slowPhaseMs.value) {
811
1343
  this.log(this.slowDocumentPhaseLine(document, state, listeners, perListenerMs, totalMs));
@@ -875,8 +1407,8 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
875
1407
  * twice: Langium's validate appends to `document.diagnostics` when they are
876
1408
  * already set — deliberately, so a category-partitioned pass keeps the earlier
877
1409
  * category's findings — and a repeated FULL pass therefore doubles the list.
878
- * `ModelServiceOptions.serializeBuilds` prevents that at the source; this is
879
- * the net for configurations that allow concurrent builds anyway.
1410
+ * The write lock prevents that at the source; this is the net for builds
1411
+ * that skip it, as `ModelServiceOptions.allowReentrantBuilds` lets one do.
880
1412
  *
881
1413
  * Clearing the list before a pass is NOT an alternative: the append happens at
882
1414
  * pass completion, so two interleaved passes both clear, both finish, and the
@@ -950,10 +1482,11 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
950
1482
  * **It inherits {@link dedupeDiagnostics}'s window, and therefore the same
951
1483
  * precondition.** A build settling inside the listener window appends
952
1484
  * diagnostics this pass never saw, and the publisher of the build that
953
- * rendered sends them — unrendered. `ModelServiceOptions.serializeBuilds`
954
- * closes it and defaults to `true`, so "every diagnostic is rendered" holds
955
- * by default and is an opt-out rather than a guarantee. Opting out accepts
956
- * unrendered diagnostics on exactly the terms it already accepts duplicates.
1485
+ * rendered sends them — unrendered. The write lock closes it, so "every
1486
+ * diagnostic is rendered" holds while
1487
+ * `ModelServiceOptions.allowReentrantBuilds` is `false`, its default.
1488
+ * Turning it on accepts unrendered diagnostics on exactly the terms it
1489
+ * already accepts duplicates.
957
1490
  *
958
1491
  * Entries are REPLACED rather than mutated: `sendDiagnostics` passes the
959
1492
  * array by reference and serialises later, so an in-place message mutation
@@ -973,7 +1506,7 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
973
1506
  const text = this.messageRenderer.renderDiagnostic(diagnostic);
974
1507
  // Against the message's STRING FORM, not the field. `renderDiagnostic`
975
1508
  // answers a `string` by contract, while `Diagnostic.message` is
976
- // `string | MarkupContent` since LSP 3.17 — so comparing the answer
1509
+ // `string | MarkupContent` since LSP 3.18 — so comparing the answer
977
1510
  // against the field never matches for a markup message, and a pass
978
1511
  // that replaced on mismatch flattened every un-identified markup
979
1512
  // diagnostic to its own plain text. That is silent data loss on the