@hydranium/core 1.0.0-next.13 → 1.0.0-next.132

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (482) hide show
  1. package/README.md +5 -1
  2. package/lib/documents/ast-document-manager.d.ts +92 -19
  3. package/lib/documents/ast-document-manager.d.ts.map +1 -1
  4. package/lib/documents/ast-document-manager.js +114 -26
  5. package/lib/documents/ast-document-manager.js.map +1 -1
  6. package/lib/documents/client-ids.d.ts +5 -19
  7. package/lib/documents/client-ids.d.ts.map +1 -1
  8. package/lib/documents/client-ids.js +5 -19
  9. package/lib/documents/client-ids.js.map +1 -1
  10. package/lib/documents/client-session-errors.d.ts +15 -0
  11. package/lib/documents/client-session-errors.d.ts.map +1 -0
  12. package/lib/documents/client-session-errors.js +15 -0
  13. package/lib/documents/client-session-errors.js.map +1 -0
  14. package/lib/documents/client-session-registry.d.ts +138 -0
  15. package/lib/documents/client-session-registry.d.ts.map +1 -0
  16. package/lib/documents/client-session-registry.js +184 -0
  17. package/lib/documents/client-session-registry.js.map +1 -0
  18. package/lib/documents/file-system-task-queue.d.ts +49 -0
  19. package/lib/documents/file-system-task-queue.d.ts.map +1 -0
  20. package/lib/documents/file-system-task-queue.js +34 -0
  21. package/lib/documents/file-system-task-queue.js.map +1 -0
  22. package/lib/documents/hydranium-text-documents.d.ts +386 -57
  23. package/lib/documents/hydranium-text-documents.d.ts.map +1 -1
  24. package/lib/documents/hydranium-text-documents.js +697 -113
  25. package/lib/documents/hydranium-text-documents.js.map +1 -1
  26. package/lib/documents/index.d.ts +3 -0
  27. package/lib/documents/index.d.ts.map +1 -1
  28. package/lib/documents/index.js +3 -0
  29. package/lib/documents/index.js.map +1 -1
  30. package/lib/documents/language-client-text-shadow.d.ts +41 -9
  31. package/lib/documents/language-client-text-shadow.d.ts.map +1 -1
  32. package/lib/documents/language-client-text-shadow.js +56 -11
  33. package/lib/documents/language-client-text-shadow.js.map +1 -1
  34. package/lib/documents/self-save-registry.d.ts +37 -6
  35. package/lib/documents/self-save-registry.d.ts.map +1 -1
  36. package/lib/documents/self-save-registry.js +28 -15
  37. package/lib/documents/self-save-registry.js.map +1 -1
  38. package/lib/index.d.ts +3 -0
  39. package/lib/index.d.ts.map +1 -1
  40. package/lib/index.js +6 -0
  41. package/lib/index.js.map +1 -1
  42. package/lib/langium/ast-extension/ast-node-builder.d.ts +32 -9
  43. package/lib/langium/ast-extension/ast-node-builder.d.ts.map +1 -1
  44. package/lib/langium/ast-extension/ast-node-builder.js +60 -22
  45. package/lib/langium/ast-extension/ast-node-builder.js.map +1 -1
  46. package/lib/langium/bootstrap.d.ts.map +1 -1
  47. package/lib/langium/bootstrap.js +16 -9
  48. package/lib/langium/bootstrap.js.map +1 -1
  49. package/lib/langium/config/configuration-provider.d.ts +81 -0
  50. package/lib/langium/config/configuration-provider.d.ts.map +1 -0
  51. package/lib/langium/config/configuration-provider.js +112 -0
  52. package/lib/langium/config/configuration-provider.js.map +1 -0
  53. package/lib/langium/config/index.d.ts +1 -0
  54. package/lib/langium/config/index.d.ts.map +1 -1
  55. package/lib/langium/config/index.js +1 -0
  56. package/lib/langium/config/index.js.map +1 -1
  57. package/lib/langium/diagnostics/lsp-logger.d.ts +17 -0
  58. package/lib/langium/diagnostics/lsp-logger.d.ts.map +1 -1
  59. package/lib/langium/diagnostics/lsp-logger.js +40 -6
  60. package/lib/langium/diagnostics/lsp-logger.js.map +1 -1
  61. package/lib/langium/document-builder/build-pipeline-integration.d.ts +21 -1
  62. package/lib/langium/document-builder/build-pipeline-integration.d.ts.map +1 -1
  63. package/lib/langium/document-builder/build-pipeline-integration.js +32 -5
  64. package/lib/langium/document-builder/build-pipeline-integration.js.map +1 -1
  65. package/lib/langium/document-builder/build-session.d.ts +93 -0
  66. package/lib/langium/document-builder/build-session.d.ts.map +1 -0
  67. package/lib/langium/document-builder/build-session.js +72 -0
  68. package/lib/langium/document-builder/build-session.js.map +1 -0
  69. package/lib/langium/document-builder/document-builder.d.ts +165 -9
  70. package/lib/langium/document-builder/document-builder.d.ts.map +1 -1
  71. package/lib/langium/document-builder/document-builder.js +313 -13
  72. package/lib/langium/document-builder/document-builder.js.map +1 -1
  73. package/lib/langium/document-builder/index.d.ts +1 -0
  74. package/lib/langium/document-builder/index.d.ts.map +1 -1
  75. package/lib/langium/document-builder/index.js +1 -0
  76. package/lib/langium/document-builder/index.js.map +1 -1
  77. package/lib/langium/integration-services.d.ts +45 -1
  78. package/lib/langium/integration-services.d.ts.map +1 -1
  79. package/lib/langium/integration-services.js +10 -5
  80. package/lib/langium/integration-services.js.map +1 -1
  81. package/lib/langium/integrity/integrity-rule.d.ts +13 -5
  82. package/lib/langium/integrity/integrity-rule.d.ts.map +1 -1
  83. package/lib/langium/integrity/integrity-rule.js.map +1 -1
  84. package/lib/langium/integrity/integrity-service.d.ts +50 -6
  85. package/lib/langium/integrity/integrity-service.d.ts.map +1 -1
  86. package/lib/langium/integrity/integrity-service.js +193 -17
  87. package/lib/langium/integrity/integrity-service.js.map +1 -1
  88. package/lib/langium/keys/containment.d.ts +64 -0
  89. package/lib/langium/keys/containment.d.ts.map +1 -0
  90. package/lib/langium/keys/containment.js +53 -0
  91. package/lib/langium/keys/containment.js.map +1 -0
  92. package/lib/langium/keys/index.d.ts +1 -0
  93. package/lib/langium/keys/index.d.ts.map +1 -1
  94. package/lib/langium/keys/index.js +1 -0
  95. package/lib/langium/keys/index.js.map +1 -1
  96. package/lib/langium/keys/name-based-key-provider.d.ts +4 -0
  97. package/lib/langium/keys/name-based-key-provider.d.ts.map +1 -1
  98. package/lib/langium/keys/name-based-key-provider.js +4 -0
  99. package/lib/langium/keys/name-based-key-provider.js.map +1 -1
  100. package/lib/langium/language-module.d.ts +27 -2
  101. package/lib/langium/language-module.d.ts.map +1 -1
  102. package/lib/langium/language-module.js +16 -2
  103. package/lib/langium/language-module.js.map +1 -1
  104. package/lib/langium/model-service/client-session.d.ts +299 -0
  105. package/lib/langium/model-service/client-session.d.ts.map +1 -0
  106. package/lib/langium/model-service/client-session.js +379 -0
  107. package/lib/langium/model-service/client-session.js.map +1 -0
  108. package/lib/langium/model-service/index.d.ts +1 -0
  109. package/lib/langium/model-service/index.d.ts.map +1 -1
  110. package/lib/langium/model-service/index.js +1 -0
  111. package/lib/langium/model-service/index.js.map +1 -1
  112. package/lib/langium/model-service/model-service.d.ts +226 -162
  113. package/lib/langium/model-service/model-service.d.ts.map +1 -1
  114. package/lib/langium/model-service/model-service.js +203 -309
  115. package/lib/langium/model-service/model-service.js.map +1 -1
  116. package/lib/langium/module.d.ts +102 -18
  117. package/lib/langium/module.d.ts.map +1 -1
  118. package/lib/langium/module.js +30 -12
  119. package/lib/langium/module.js.map +1 -1
  120. package/lib/langium/naming/name-provider.d.ts +25 -4
  121. package/lib/langium/naming/name-provider.d.ts.map +1 -1
  122. package/lib/langium/naming/name-provider.js +2 -1
  123. package/lib/langium/naming/name-provider.js.map +1 -1
  124. package/lib/langium/naming/name-separator-validation.d.ts +23 -0
  125. package/lib/langium/naming/name-separator-validation.d.ts.map +1 -1
  126. package/lib/langium/naming/name-separator-validation.js +30 -1
  127. package/lib/langium/naming/name-separator-validation.js.map +1 -1
  128. package/lib/langium/residency/cst-residency-service.d.ts +31 -11
  129. package/lib/langium/residency/cst-residency-service.d.ts.map +1 -1
  130. package/lib/langium/residency/cst-residency-service.js +13 -56
  131. package/lib/langium/residency/cst-residency-service.js.map +1 -1
  132. package/lib/langium/scope/hydranium-scope-provider.d.ts +48 -13
  133. package/lib/langium/scope/hydranium-scope-provider.d.ts.map +1 -1
  134. package/lib/langium/scope/hydranium-scope-provider.js +56 -20
  135. package/lib/langium/scope/hydranium-scope-provider.js.map +1 -1
  136. package/lib/langium/serialization/abstract-serializer.d.ts +11 -20
  137. package/lib/langium/serialization/abstract-serializer.d.ts.map +1 -1
  138. package/lib/langium/serialization/abstract-serializer.js +12 -21
  139. package/lib/langium/serialization/abstract-serializer.js.map +1 -1
  140. package/lib/langium/service-registry.d.ts +15 -1
  141. package/lib/langium/service-registry.d.ts.map +1 -1
  142. package/lib/langium/service-registry.js +16 -0
  143. package/lib/langium/service-registry.js.map +1 -1
  144. package/lib/langium/shared-services.d.ts +15 -2
  145. package/lib/langium/shared-services.d.ts.map +1 -1
  146. package/lib/langium/shared-services.js.map +1 -1
  147. package/lib/langium/transfer/transfer-encoder.d.ts +60 -17
  148. package/lib/langium/transfer/transfer-encoder.d.ts.map +1 -1
  149. package/lib/langium/transfer/transfer-encoder.js +38 -16
  150. package/lib/langium/transfer/transfer-encoder.js.map +1 -1
  151. package/lib/langium/trivia/comment-preserver.d.ts +423 -0
  152. package/lib/langium/trivia/comment-preserver.d.ts.map +1 -0
  153. package/lib/langium/trivia/comment-preserver.js +906 -0
  154. package/lib/langium/trivia/comment-preserver.js.map +1 -0
  155. package/lib/langium/trivia/document-ending-preserver.d.ts +43 -0
  156. package/lib/langium/trivia/document-ending-preserver.d.ts.map +1 -0
  157. package/lib/langium/trivia/document-ending-preserver.js +48 -0
  158. package/lib/langium/trivia/document-ending-preserver.js.map +1 -0
  159. package/lib/langium/trivia/index.d.ts +14 -0
  160. package/lib/langium/trivia/index.d.ts.map +1 -0
  161. package/lib/langium/trivia/index.js +14 -0
  162. package/lib/langium/trivia/index.js.map +1 -0
  163. package/lib/langium/trivia/trivia-contribution.d.ts +37 -0
  164. package/lib/langium/trivia/trivia-contribution.d.ts.map +1 -0
  165. package/lib/langium/trivia/trivia-contribution.js +10 -0
  166. package/lib/langium/trivia/trivia-contribution.js.map +1 -0
  167. package/lib/langium/trivia/trivia-preserver.d.ts +50 -0
  168. package/lib/langium/trivia/trivia-preserver.d.ts.map +1 -0
  169. package/lib/langium/trivia/trivia-preserver.js +10 -0
  170. package/lib/langium/trivia/trivia-preserver.js.map +1 -0
  171. package/lib/langium/trivia/trivia-service.d.ts +70 -0
  172. package/lib/langium/trivia/trivia-service.d.ts.map +1 -0
  173. package/lib/langium/trivia/trivia-service.js +56 -0
  174. package/lib/langium/trivia/trivia-service.js.map +1 -0
  175. package/lib/langium/update-rewrite/update-rewrite.d.ts +1 -1
  176. package/lib/langium/validation/document-validator.d.ts +294 -10
  177. package/lib/langium/validation/document-validator.d.ts.map +1 -1
  178. package/lib/langium/validation/document-validator.js +448 -5
  179. package/lib/langium/validation/document-validator.js.map +1 -1
  180. package/lib/langium/workspace/document-uri-policy.d.ts +3 -4
  181. package/lib/langium/workspace/document-uri-policy.d.ts.map +1 -1
  182. package/lib/langium/workspace/document-uri-policy.js +3 -4
  183. package/lib/langium/workspace/document-uri-policy.js.map +1 -1
  184. package/lib/langium/workspace/file-system-provider.d.ts +9 -1
  185. package/lib/langium/workspace/file-system-provider.d.ts.map +1 -1
  186. package/lib/langium/workspace/file-system-provider.js +40 -7
  187. package/lib/langium/workspace/file-system-provider.js.map +1 -1
  188. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts +25 -0
  189. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts.map +1 -1
  190. package/lib/langium/workspace/hydranium-langium-document-factory.js +25 -0
  191. package/lib/langium/workspace/hydranium-langium-document-factory.js.map +1 -1
  192. package/lib/langium/workspace/hydranium-workspace-manager.d.ts +21 -1
  193. package/lib/langium/workspace/hydranium-workspace-manager.d.ts.map +1 -1
  194. package/lib/langium/workspace/hydranium-workspace-manager.js +28 -0
  195. package/lib/langium/workspace/hydranium-workspace-manager.js.map +1 -1
  196. package/lib/langium/workspace/in-memory-file-system-provider.d.ts +23 -0
  197. package/lib/langium/workspace/in-memory-file-system-provider.d.ts.map +1 -1
  198. package/lib/langium/workspace/in-memory-file-system-provider.js +55 -9
  199. package/lib/langium/workspace/in-memory-file-system-provider.js.map +1 -1
  200. package/lib/langium/workspace/initialize-workspace.d.ts +31 -2
  201. package/lib/langium/workspace/initialize-workspace.d.ts.map +1 -1
  202. package/lib/langium/workspace/initialize-workspace.js +13 -5
  203. package/lib/langium/workspace/initialize-workspace.js.map +1 -1
  204. package/lib/langium/workspace/langium-documents.d.ts +79 -17
  205. package/lib/langium/workspace/langium-documents.d.ts.map +1 -1
  206. package/lib/langium/workspace/langium-documents.js +83 -28
  207. package/lib/langium/workspace/langium-documents.js.map +1 -1
  208. package/lib/langium/workspace/virtual-document.d.ts +18 -3
  209. package/lib/langium/workspace/virtual-document.d.ts.map +1 -1
  210. package/lib/langium/workspace/virtual-document.js +19 -2
  211. package/lib/langium/workspace/virtual-document.js.map +1 -1
  212. package/lib/langium/workspace/write-lock-scope.d.ts +1 -1
  213. package/lib/langium/workspace/write-lock-scope.js +1 -1
  214. package/lib/locale/index.d.ts +10 -0
  215. package/lib/locale/index.d.ts.map +1 -0
  216. package/lib/locale/index.js +10 -0
  217. package/lib/locale/index.js.map +1 -0
  218. package/lib/locale/server-locale.d.ts +73 -0
  219. package/lib/locale/server-locale.d.ts.map +1 -0
  220. package/lib/locale/server-locale.js +61 -0
  221. package/lib/locale/server-locale.js.map +1 -0
  222. package/lib/lsp/completion/hydranium-completion-provider.d.ts +44 -2
  223. package/lib/lsp/completion/hydranium-completion-provider.d.ts.map +1 -1
  224. package/lib/lsp/completion/hydranium-completion-provider.js +68 -0
  225. package/lib/lsp/completion/hydranium-completion-provider.js.map +1 -1
  226. package/lib/lsp/connection-features.d.ts +23 -0
  227. package/lib/lsp/connection-features.d.ts.map +1 -0
  228. package/lib/lsp/connection-features.js +60 -0
  229. package/lib/lsp/connection-features.js.map +1 -0
  230. package/lib/lsp/diagnostics-connection.d.ts +27 -0
  231. package/lib/lsp/diagnostics-connection.d.ts.map +1 -0
  232. package/lib/lsp/diagnostics-connection.js +53 -0
  233. package/lib/lsp/diagnostics-connection.js.map +1 -0
  234. package/lib/lsp/hydranium-document-update-handler.d.ts +70 -62
  235. package/lib/lsp/hydranium-document-update-handler.d.ts.map +1 -1
  236. package/lib/lsp/hydranium-document-update-handler.js +129 -75
  237. package/lib/lsp/hydranium-document-update-handler.js.map +1 -1
  238. package/lib/lsp/index.d.ts +3 -1
  239. package/lib/lsp/index.d.ts.map +1 -1
  240. package/lib/lsp/index.js +3 -1
  241. package/lib/lsp/index.js.map +1 -1
  242. package/lib/lsp/lsp-latency.d.ts +39 -0
  243. package/lib/lsp/lsp-latency.d.ts.map +1 -0
  244. package/lib/lsp/lsp-latency.js +58 -0
  245. package/lib/lsp/lsp-latency.js.map +1 -0
  246. package/lib/lsp/semantic-token-provider.d.ts +34 -1
  247. package/lib/lsp/semantic-token-provider.d.ts.map +1 -1
  248. package/lib/lsp/semantic-token-provider.js +55 -8
  249. package/lib/lsp/semantic-token-provider.js.map +1 -1
  250. package/lib/lsp/shared-module.d.ts +4 -8
  251. package/lib/lsp/shared-module.d.ts.map +1 -1
  252. package/lib/lsp/shared-module.js.map +1 -1
  253. package/lib/lsp/start-language-server.d.ts +8 -7
  254. package/lib/lsp/start-language-server.d.ts.map +1 -1
  255. package/lib/lsp/start-language-server.js +13 -7
  256. package/lib/lsp/start-language-server.js.map +1 -1
  257. package/lib/messages/carriers.d.ts +54 -0
  258. package/lib/messages/carriers.d.ts.map +1 -0
  259. package/lib/messages/carriers.js +62 -0
  260. package/lib/messages/carriers.js.map +1 -0
  261. package/lib/messages/index.d.ts +25 -0
  262. package/lib/messages/index.d.ts.map +1 -0
  263. package/lib/messages/index.js +25 -0
  264. package/lib/messages/index.js.map +1 -0
  265. package/lib/messages/renderer.d.ts +142 -0
  266. package/lib/messages/renderer.d.ts.map +1 -0
  267. package/lib/messages/renderer.js +165 -0
  268. package/lib/messages/renderer.js.map +1 -0
  269. package/lib/node/heap-ceiling.d.ts +61 -0
  270. package/lib/node/heap-ceiling.d.ts.map +1 -0
  271. package/lib/node/heap-ceiling.js +72 -0
  272. package/lib/node/heap-ceiling.js.map +1 -0
  273. package/lib/node/index.d.ts +1 -0
  274. package/lib/node/index.d.ts.map +1 -1
  275. package/lib/node/index.js +1 -0
  276. package/lib/node/index.js.map +1 -1
  277. package/lib/node/latency-from-env.d.ts +1 -1
  278. package/lib/node/latency-from-env.js +1 -1
  279. package/lib/node/measure-memory.d.ts.map +1 -1
  280. package/lib/node/measure-memory.js +1 -0
  281. package/lib/node/measure-memory.js.map +1 -1
  282. package/lib/node/node-file-system-provider.d.ts +35 -1
  283. package/lib/node/node-file-system-provider.d.ts.map +1 -1
  284. package/lib/node/node-file-system-provider.js +140 -45
  285. package/lib/node/node-file-system-provider.js.map +1 -1
  286. package/lib/node/profile-capture.d.ts +8 -2
  287. package/lib/node/profile-capture.d.ts.map +1 -1
  288. package/lib/node/profile-capture.js.map +1 -1
  289. package/lib/node/profiling-run.d.ts +2 -2
  290. package/lib/node/profiling-run.js +1 -1
  291. package/lib/node/profiling-run.js.map +1 -1
  292. package/lib/node/rename-over-open-readers.d.ts +52 -0
  293. package/lib/node/rename-over-open-readers.d.ts.map +1 -0
  294. package/lib/node/rename-over-open-readers.js +66 -0
  295. package/lib/node/rename-over-open-readers.js.map +1 -0
  296. package/lib/node/socket-launcher.d.ts +16 -1
  297. package/lib/node/socket-launcher.d.ts.map +1 -1
  298. package/lib/node/socket-launcher.js +4 -3
  299. package/lib/node/socket-launcher.js.map +1 -1
  300. package/lib/node/stdio-launcher.d.ts +1 -1
  301. package/lib/node/stdio-launcher.d.ts.map +1 -1
  302. package/lib/node/stdio-launcher.js +1 -1
  303. package/lib/node/stdio-launcher.js.map +1 -1
  304. package/lib/testing/fake-document.d.ts +16 -4
  305. package/lib/testing/fake-document.d.ts.map +1 -1
  306. package/lib/testing/fake-document.js +18 -3
  307. package/lib/testing/fake-document.js.map +1 -1
  308. package/lib/testing/make-noop-shared-services.d.ts +14 -0
  309. package/lib/testing/make-noop-shared-services.d.ts.map +1 -1
  310. package/lib/testing/make-noop-shared-services.js +28 -2
  311. package/lib/testing/make-noop-shared-services.js.map +1 -1
  312. package/lib/testing/make-test-services.d.ts +62 -14
  313. package/lib/testing/make-test-services.d.ts.map +1 -1
  314. package/lib/testing/make-test-services.js +25 -5
  315. package/lib/testing/make-test-services.js.map +1 -1
  316. package/lib/testing/node/index.d.ts +1 -0
  317. package/lib/testing/node/index.d.ts.map +1 -1
  318. package/lib/testing/node/index.js +1 -0
  319. package/lib/testing/node/index.js.map +1 -1
  320. package/lib/testing/node/lsp-harness.d.ts.map +1 -1
  321. package/lib/testing/node/lsp-harness.js +2 -0
  322. package/lib/testing/node/lsp-harness.js.map +1 -1
  323. package/lib/testing/node/lsp-server-connection.d.ts +11 -3
  324. package/lib/testing/node/lsp-server-connection.d.ts.map +1 -1
  325. package/lib/testing/node/lsp-server-connection.js +42 -9
  326. package/lib/testing/node/lsp-server-connection.js.map +1 -1
  327. package/lib/testing/node/scratch-workspace.d.ts.map +1 -1
  328. package/lib/testing/node/scratch-workspace.js +10 -5
  329. package/lib/testing/node/scratch-workspace.js.map +1 -1
  330. package/lib/testing/node/spawned-server.d.ts +14 -0
  331. package/lib/testing/node/spawned-server.d.ts.map +1 -1
  332. package/lib/testing/node/spawned-server.js +33 -1
  333. package/lib/testing/node/spawned-server.js.map +1 -1
  334. package/lib/testing/node/unhandled-rejections.d.ts +20 -0
  335. package/lib/testing/node/unhandled-rejections.d.ts.map +1 -0
  336. package/lib/testing/node/unhandled-rejections.js +32 -0
  337. package/lib/testing/node/unhandled-rejections.js.map +1 -0
  338. package/lib/testing/playwright/flaky-network-proxy.d.ts +76 -0
  339. package/lib/testing/playwright/flaky-network-proxy.d.ts.map +1 -0
  340. package/lib/testing/playwright/flaky-network-proxy.js +164 -0
  341. package/lib/testing/playwright/flaky-network-proxy.js.map +1 -0
  342. package/lib/testing/playwright/index.d.ts +1 -0
  343. package/lib/testing/playwright/index.d.ts.map +1 -1
  344. package/lib/testing/playwright/index.js +1 -0
  345. package/lib/testing/playwright/index.js.map +1 -1
  346. package/lib/testing/playwright/server-log-capture.d.ts +14 -4
  347. package/lib/testing/playwright/server-log-capture.d.ts.map +1 -1
  348. package/lib/testing/playwright/server-log-capture.js +21 -4
  349. package/lib/testing/playwright/server-log-capture.js.map +1 -1
  350. package/lib/testing/playwright/server-log-rename-reporter.d.ts.map +1 -1
  351. package/lib/testing/playwright/server-log-rename-reporter.js +10 -1
  352. package/lib/testing/playwright/server-log-rename-reporter.js.map +1 -1
  353. package/lib/testing/run-update-pipeline.d.ts +4 -4
  354. package/lib/testing/run-update-pipeline.d.ts.map +1 -1
  355. package/lib/testing/stub-ast-document-manager.d.ts +10 -9
  356. package/lib/testing/stub-ast-document-manager.d.ts.map +1 -1
  357. package/lib/testing/stub-ast-document-manager.js +8 -9
  358. package/lib/testing/stub-ast-document-manager.js.map +1 -1
  359. package/lib/testing/stub-document-builder.d.ts +8 -0
  360. package/lib/testing/stub-document-builder.d.ts.map +1 -1
  361. package/lib/testing/stub-document-builder.js +22 -3
  362. package/lib/testing/stub-document-builder.js.map +1 -1
  363. package/lib/testing/stub-hydranium-text-documents.d.ts +22 -7
  364. package/lib/testing/stub-hydranium-text-documents.d.ts.map +1 -1
  365. package/lib/testing/stub-hydranium-text-documents.js +92 -15
  366. package/lib/testing/stub-hydranium-text-documents.js.map +1 -1
  367. package/lib/testing/stub-langium-documents.d.ts +3 -2
  368. package/lib/testing/stub-langium-documents.d.ts.map +1 -1
  369. package/lib/testing/stub-langium-documents.js.map +1 -1
  370. package/lib/testing/stub-model-service.d.ts +7 -6
  371. package/lib/testing/stub-model-service.d.ts.map +1 -1
  372. package/lib/testing/stub-model-service.js +4 -4
  373. package/lib/testing/stub-model-service.js.map +1 -1
  374. package/lib/util/connection-liveness.d.ts +7 -6
  375. package/lib/util/connection-liveness.d.ts.map +1 -1
  376. package/lib/util/connection-liveness.js +35 -14
  377. package/lib/util/connection-liveness.js.map +1 -1
  378. package/package.json +17 -8
  379. package/src/documents/ast-document-manager.ts +195 -45
  380. package/src/documents/client-ids.ts +5 -22
  381. package/src/documents/client-session-errors.ts +22 -0
  382. package/src/documents/client-session-registry.ts +237 -0
  383. package/src/documents/file-system-task-queue.ts +68 -0
  384. package/src/documents/hydranium-text-documents.ts +853 -142
  385. package/src/documents/index.ts +3 -0
  386. package/src/documents/language-client-text-shadow.ts +59 -11
  387. package/src/documents/self-save-registry.ts +52 -13
  388. package/src/index.ts +6 -0
  389. package/src/langium/ast-extension/ast-node-builder.ts +66 -22
  390. package/src/langium/bootstrap.ts +16 -9
  391. package/src/langium/config/configuration-provider.ts +119 -0
  392. package/src/langium/config/index.ts +1 -0
  393. package/src/langium/diagnostics/lsp-logger.ts +41 -6
  394. package/src/langium/document-builder/build-pipeline-integration.ts +50 -5
  395. package/src/langium/document-builder/build-session.ts +87 -0
  396. package/src/langium/document-builder/document-builder.ts +355 -13
  397. package/src/langium/document-builder/index.ts +1 -0
  398. package/src/langium/integration-services.ts +67 -6
  399. package/src/langium/integrity/integrity-rule.ts +13 -5
  400. package/src/langium/integrity/integrity-service.ts +202 -17
  401. package/src/langium/keys/containment.ts +87 -0
  402. package/src/langium/keys/index.ts +1 -0
  403. package/src/langium/keys/name-based-key-provider.ts +4 -0
  404. package/src/langium/language-module.ts +42 -4
  405. package/src/langium/model-service/client-session.ts +581 -0
  406. package/src/langium/model-service/index.ts +1 -0
  407. package/src/langium/model-service/model-service.ts +347 -298
  408. package/src/langium/module.ts +132 -24
  409. package/src/langium/naming/name-provider.ts +27 -5
  410. package/src/langium/naming/name-separator-validation.ts +34 -5
  411. package/src/langium/residency/cst-residency-service.ts +36 -14
  412. package/src/langium/scope/hydranium-scope-provider.ts +60 -22
  413. package/src/langium/serialization/abstract-serializer.ts +13 -32
  414. package/src/langium/service-registry.ts +19 -2
  415. package/src/langium/shared-services.ts +19 -2
  416. package/src/langium/transfer/transfer-encoder.ts +85 -24
  417. package/src/langium/trivia/comment-preserver.ts +1100 -0
  418. package/src/langium/trivia/document-ending-preserver.ts +55 -0
  419. package/src/langium/trivia/index.ts +14 -0
  420. package/src/langium/trivia/trivia-contribution.ts +39 -0
  421. package/src/langium/trivia/trivia-preserver.ts +54 -0
  422. package/src/langium/trivia/trivia-service.ts +99 -0
  423. package/src/langium/update-rewrite/update-rewrite.ts +1 -1
  424. package/src/langium/validation/document-validator.ts +537 -11
  425. package/src/langium/workspace/document-uri-policy.ts +3 -4
  426. package/src/langium/workspace/file-system-provider.ts +48 -8
  427. package/src/langium/workspace/hydranium-langium-document-factory.ts +34 -0
  428. package/src/langium/workspace/hydranium-workspace-manager.ts +30 -1
  429. package/src/langium/workspace/in-memory-file-system-provider.ts +62 -10
  430. package/src/langium/workspace/initialize-workspace.ts +43 -5
  431. package/src/langium/workspace/langium-documents.ts +106 -33
  432. package/src/langium/workspace/virtual-document.ts +21 -3
  433. package/src/langium/workspace/write-lock-scope.ts +1 -1
  434. package/src/locale/index.ts +10 -0
  435. package/src/locale/server-locale.ts +86 -0
  436. package/src/lsp/completion/hydranium-completion-provider.ts +82 -2
  437. package/src/lsp/connection-features.ts +67 -0
  438. package/src/lsp/diagnostics-connection.ts +56 -0
  439. package/src/lsp/hydranium-document-update-handler.ts +158 -79
  440. package/src/lsp/index.ts +3 -1
  441. package/src/lsp/lsp-latency.ts +62 -0
  442. package/src/lsp/semantic-token-provider.ts +74 -7
  443. package/src/lsp/shared-module.ts +4 -8
  444. package/src/lsp/start-language-server.ts +13 -7
  445. package/src/messages/carriers.ts +78 -0
  446. package/src/messages/index.ts +36 -0
  447. package/src/messages/renderer.ts +212 -0
  448. package/src/node/heap-ceiling.ts +108 -0
  449. package/src/node/index.ts +1 -0
  450. package/src/node/latency-from-env.ts +1 -1
  451. package/src/node/measure-memory.ts +1 -0
  452. package/src/node/node-file-system-provider.ts +154 -47
  453. package/src/node/profile-capture.ts +8 -2
  454. package/src/node/profiling-run.ts +3 -3
  455. package/src/node/rename-over-open-readers.ts +78 -0
  456. package/src/node/socket-launcher.ts +19 -4
  457. package/src/node/stdio-launcher.ts +1 -2
  458. package/src/testing/fake-document.ts +24 -5
  459. package/src/testing/make-noop-shared-services.ts +50 -2
  460. package/src/testing/make-test-services.ts +101 -26
  461. package/src/testing/node/index.ts +1 -0
  462. package/src/testing/node/lsp-harness.ts +2 -0
  463. package/src/testing/node/lsp-server-connection.ts +61 -11
  464. package/src/testing/node/scratch-workspace.ts +10 -5
  465. package/src/testing/node/spawned-server.ts +35 -1
  466. package/src/testing/node/unhandled-rejections.ts +31 -0
  467. package/src/testing/playwright/flaky-network-proxy.ts +240 -0
  468. package/src/testing/playwright/index.ts +1 -0
  469. package/src/testing/playwright/server-log-capture.ts +24 -5
  470. package/src/testing/playwright/server-log-rename-reporter.ts +12 -1
  471. package/src/testing/run-update-pipeline.ts +4 -4
  472. package/src/testing/stub-ast-document-manager.ts +18 -31
  473. package/src/testing/stub-document-builder.ts +32 -3
  474. package/src/testing/stub-hydranium-text-documents.ts +127 -22
  475. package/src/testing/stub-langium-documents.ts +3 -2
  476. package/src/testing/stub-model-service.ts +9 -8
  477. package/src/util/connection-liveness.ts +37 -14
  478. package/lib/lsp/instrument-connection.d.ts +0 -36
  479. package/lib/lsp/instrument-connection.d.ts.map +0 -1
  480. package/lib/lsp/instrument-connection.js +0 -62
  481. package/lib/lsp/instrument-connection.js.map +0 -1
  482. package/src/lsp/instrument-connection.ts +0 -66
@@ -0,0 +1,581 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+
10
+ import {
11
+ type BasedOn,
12
+ ConflictError,
13
+ isSnapshotVersion,
14
+ Logger,
15
+ type MaybeObservableValue,
16
+ type MaybePromise,
17
+ ObservableValue,
18
+ type Tracer,
19
+ type TransferElement
20
+ } from '@hydranium/protocol';
21
+ import { type AstNode, UriUtils } from '@hydranium/langium';
22
+ import { type CancellationToken, type Disposable } from 'vscode-languageserver';
23
+ import { type AstDocument } from '../../documents/ast-document-manager.js';
24
+ import { DocumentNotOpenError, SessionClosedError } from '../../documents/client-session-errors.js';
25
+ import { type OpenOptions, type SessionEndCause } from '../../documents/client-session-registry.js';
26
+ import { type LogNameOptions } from '../diagnostics/logger.js';
27
+ import { type ServerSharedServices } from '../module.js';
28
+ import { type AstDiagnostic } from '../validation/document-validator.js';
29
+ import { type ModelService } from './model-service.js';
30
+
31
+ /** What a session's `update` and `save` write into one document; the session supplies its own client id. */
32
+ export interface ClientSessionWriteArgs<TTransfer> {
33
+ uri: string;
34
+ /** The whole structured model root, or its serialised textual form. */
35
+ model: TTransfer | string;
36
+ /**
37
+ * The version the write was authored against, or `'anything'` to write
38
+ * unconditionally. Required, so an ungated write is a decision the caller
39
+ * makes rather than a field it forgot.
40
+ */
41
+ basedOn: BasedOn;
42
+ }
43
+
44
+ /** What a session's `updateAll` writes, all or none. */
45
+ export interface ClientSessionUpdateAllArgs<TTransfer> {
46
+ updates: ClientSessionWriteArgs<TTransfer>[];
47
+ }
48
+
49
+ /**
50
+ * One participant's handle on the documents it works on, started by
51
+ * `ModelService.createSession`.
52
+ *
53
+ * The session writes only what it has open: `update` and `save` fail with
54
+ * `DocumentNotOpenError` unless this session has the URI open when the text is
55
+ * applied, and the check and the apply are one synchronous step, so a write
56
+ * either lands while the document is open or fails. A document stays open until
57
+ * this session closes it, the session ends, or the file is deleted.
58
+ *
59
+ * One open per URI, without reference counting: opening a URI the session
60
+ * already has open changes nothing, and one `close` ends it.
61
+ *
62
+ * After `dispose`, every other member throws `SessionClosedError`
63
+ * synchronously, before returning a promise.
64
+ *
65
+ * Reads need no session and live on `ModelService`.
66
+ */
67
+ export interface ClientSession<
68
+ TAst extends AstNode,
69
+ TDiagnostic extends AstDiagnostic = AstDiagnostic,
70
+ TTransfer extends TransferElement = TransferElement,
71
+ TOpenOptions extends OpenOptions = OpenOptions
72
+ > {
73
+ /** Unique in the process while the session is live: the author label on its writes and the key of its opens. */
74
+ readonly clientId: string;
75
+ readonly label: string;
76
+
77
+ /**
78
+ * Open `uri` for this session, reading it from disk unless some client has
79
+ * it open already or it holds this client's unsaved text within its revert
80
+ * grace. `options` are kept for this open until it closes; a repeat open,
81
+ * concurrent or not, keeps the options of the first.
82
+ */
83
+ open(uri: string, options?: TOpenOptions): Promise<void>;
84
+ /** The options this session opened `uri` with, or `undefined` when it gave none or does not have `uri` open. */
85
+ openOptions(uri: string): TOpenOptions | undefined;
86
+ /**
87
+ * Create a document with `text` and open it for this session. It reaches
88
+ * disk on the first `save`. Fails when the file exists, any client has the
89
+ * URI open, or the URI waits out the revert grace, and of two creates of one
90
+ * URI at most one succeeds.
91
+ */
92
+ create(uri: string, text: string): Promise<void>;
93
+ update(args: ClientSessionWriteArgs<TTransfer>, cancelToken?: CancellationToken): Promise<AstDocument<TAst, TDiagnostic>>;
94
+ /**
95
+ * Write several documents this session has open, all or none: a
96
+ * `ConflictError` or `DocumentNotOpenError` for any of them is thrown before
97
+ * any text applies. Resolves to the rebuilt documents, in the order given.
98
+ */
99
+ updateAll(args: ClientSessionUpdateAllArgs<TTransfer>, cancelToken?: CancellationToken): Promise<AstDocument<TAst, TDiagnostic>[]>;
100
+ /** Write `args.model` as {@link update} does, then persist the document. */
101
+ save(args: ClientSessionWriteArgs<TTransfer>, cancelToken?: CancellationToken): Promise<AstDocument<TAst, TDiagnostic>>;
102
+ /** Close this session's open of `uri`, at once. A no-op when it does not have `uri` open. */
103
+ close(uri: string): Promise<void>;
104
+ /**
105
+ * Open `uri`, run `fn`, and close `uri` when `fn` settles, whether it
106
+ * returned or threw. A URI the session already had open, or is still
107
+ * opening through another call, stays open: the close undoes only the open
108
+ * this call made.
109
+ */
110
+ withOpen<T>(uri: string, fn: () => MaybePromise<T>): Promise<T>;
111
+ /** Whether an event's `sourceClientId` names this session, i.e. the event echoes its own write. */
112
+ isOwnEcho(sourceClientId: string): boolean;
113
+ /**
114
+ * End the session: close everything it has open and free its id.
115
+ * Idempotent. `cause` is `'lost'` when the session ends because its
116
+ * client's connection went away, which lets each document it was the last
117
+ * to have open wait out the store's revert grace; ending it for any other
118
+ * reason reverts such a document at once.
119
+ */
120
+ dispose(cause?: SessionEndCause): void;
121
+ }
122
+
123
+ /**
124
+ * The framework's {@link ClientSession}, built by
125
+ * {@link DefaultClientSessionFactory}.
126
+ *
127
+ * Override the protected method behind a member to change how every session
128
+ * writes, and return the subclass from a {@link ClientSessionFactory} bound on
129
+ * `model.ClientSessionFactory`. Serialising a model and rebuilding a document
130
+ * are the {@link ModelService}'s.
131
+ *
132
+ * An override of {@link dispose} calls `super.dispose(cause)`: that is what
133
+ * closes the session's opens and frees its id, and dropping `cause` reverts
134
+ * a lost client's documents without their grace.
135
+ */
136
+ export class DefaultClientSession<
137
+ TAst extends AstNode,
138
+ TDiagnostic extends AstDiagnostic = AstDiagnostic,
139
+ TTransfer extends TransferElement = TransferElement,
140
+ TOpenOptions extends OpenOptions = OpenOptions
141
+ > implements ClientSession<TAst, TDiagnostic, TTransfer, TOpenOptions> {
142
+ protected disposed = false;
143
+ /**
144
+ * This session's opens still under way, by canonical URI. Recorded before
145
+ * the first await, so a second open of the same URI joins the first rather
146
+ * than racing it, and `withOpen` can tell an open another call is making.
147
+ */
148
+ protected readonly pendingOpens = new Map<string, Promise<void>>();
149
+ /**
150
+ * The options of this session's opens, by canonical URI. A first open
151
+ * records its entry before the store has the URI open, and the entry goes
152
+ * when that open closes, whoever ends it: this session, or the store for a
153
+ * deleted file. A first open that fails never opens, so nothing closes it
154
+ * and its entry stays until the next first open of the URI overwrites it;
155
+ * {@link openOptions} therefore reads an entry only while the store has the
156
+ * URI open for this session.
157
+ */
158
+ protected readonly openOptionsByUri = new Map<string, TOpenOptions | undefined>();
159
+ /** Drops an open's options from {@link openOptionsByUri} when the store closes the open. */
160
+ protected readonly closeListener: Disposable;
161
+ /** Logs under `logName`, `ClientSession` when none is given, with this session's id in a bracket of its own, so a line names the session that wrote. */
162
+ protected readonly tracer: Tracer;
163
+ /** The service bound on `model.ModelService`, which serialises and rebuilds for this session. */
164
+ protected readonly modelService: ModelService<TAst, TDiagnostic, TTransfer>;
165
+ /** See {@link ClientSessionFactoryOptions.slowUpdateWarnMs}; `undefined` when not set. */
166
+ protected readonly slowUpdateWarn?: ObservableValue<number>;
167
+ readonly clientId: string;
168
+ readonly label: string;
169
+
170
+ constructor(
171
+ protected readonly services: ServerSharedServices,
172
+ options: ClientSessionOptions
173
+ ) {
174
+ this.clientId = options.clientId;
175
+ this.label = options.label ?? options.clientId;
176
+ // The slot is shared across grammars; this session's types hold for the
177
+ // grammar that started it, as `createSession`'s narrowing does.
178
+ this.modelService = services.model.ModelService as ModelService<TAst, TDiagnostic, TTransfer>;
179
+ this.slowUpdateWarn = options.slowUpdateWarnMs !== undefined ? ObservableValue.from(options.slowUpdateWarnMs) : undefined;
180
+ this.tracer = services.Tracer.for(options.logName ?? 'ClientSession').with(this.clientId);
181
+ this.closeListener = services.workspace.TextDocuments.onDidClose(event => {
182
+ if (event.clientId === this.clientId) {
183
+ this.openOptionsByUri.delete(event.document.uri);
184
+ }
185
+ });
186
+ }
187
+
188
+ open(uri: string, options?: TOpenOptions): Promise<void> {
189
+ this.assertLive();
190
+ return this.openDocument(uri, options);
191
+ }
192
+
193
+ openOptions(uri: string): TOpenOptions | undefined {
194
+ this.assertLive();
195
+ return this.services.workspace.TextDocuments.isOpenInClient(uri, this.clientId)
196
+ ? this.openOptionsByUri.get(this.canonicalKey(uri))
197
+ : undefined;
198
+ }
199
+
200
+ create(uri: string, text: string): Promise<void> {
201
+ this.assertLive();
202
+ return this.createDocument(uri, text);
203
+ }
204
+
205
+ update(args: ClientSessionWriteArgs<TTransfer>, cancelToken?: CancellationToken): Promise<AstDocument<TAst, TDiagnostic>> {
206
+ this.assertLive();
207
+ return this.updateDocument(args, cancelToken);
208
+ }
209
+
210
+ updateAll(args: ClientSessionUpdateAllArgs<TTransfer>, cancelToken?: CancellationToken): Promise<AstDocument<TAst, TDiagnostic>[]> {
211
+ this.assertLive();
212
+ return this.updateDocuments(args, cancelToken);
213
+ }
214
+
215
+ save(args: ClientSessionWriteArgs<TTransfer>, cancelToken?: CancellationToken): Promise<AstDocument<TAst, TDiagnostic>> {
216
+ this.assertLive();
217
+ return this.saveDocument(args, cancelToken);
218
+ }
219
+
220
+ close(uri: string): Promise<void> {
221
+ this.assertLive();
222
+ return this.closeDocument(uri);
223
+ }
224
+
225
+ withOpen<T>(uri: string, fn: () => MaybePromise<T>): Promise<T> {
226
+ this.assertLive();
227
+ return this.runWithOpen(uri, fn);
228
+ }
229
+
230
+ isOwnEcho(sourceClientId: string): boolean {
231
+ this.assertLive();
232
+ return sourceClientId === this.clientId;
233
+ }
234
+
235
+ dispose(cause?: SessionEndCause): void {
236
+ if (this.disposed) {
237
+ return;
238
+ }
239
+ this.disposed = true;
240
+ this.services.workspace.TextDocuments.closeSession(this.clientId, cause);
241
+ this.closeListener.dispose();
242
+ }
243
+
244
+ protected assertLive(): void {
245
+ if (this.disposed) {
246
+ throw new SessionClosedError(this.clientId);
247
+ }
248
+ }
249
+
250
+ /** Throw `DocumentNotOpenError` unless this session has `uri` open. */
251
+ protected assertOpen(uri: string): void {
252
+ if (!this.services.workspace.TextDocuments.isOpenInClient(uri, this.clientId)) {
253
+ throw new DocumentNotOpenError(uri, this.clientId);
254
+ }
255
+ }
256
+
257
+ /**
258
+ * Throw `ConflictError` when `basedOn` names a version other than
259
+ * `currentVersion`. A write calls it at the door and again in the
260
+ * synchronous step that applies the text, and has to call it synchronously
261
+ * there: a check separated from the apply by an await lets two writes based
262
+ * on one version both apply.
263
+ */
264
+ protected assertBasedOn(uri: string, basedOn: BasedOn, currentVersion: number): void {
265
+ if (isSnapshotVersion(basedOn) && currentVersion !== basedOn) {
266
+ // Distinct from the post-build "superseded" debug line of an update: this
267
+ // is a based-on-stale rejection (the write never applies), not two
268
+ // writes racing.
269
+ this.tracer.debug(`Conflict on ${uri}: based-on v${basedOn} stale, server at v${currentVersion}`);
270
+ throw new ConflictError(uri, basedOn, currentVersion);
271
+ }
272
+ }
273
+
274
+ /**
275
+ * Serialise `args.model`, apply it to the store under this session's id,
276
+ * rebuild, and resolve to the rebuilt document.
277
+ *
278
+ * The open check and the `basedOn` gate run at the door, so a write that
279
+ * cannot land is refused before any adopter serialiser runs, and again in
280
+ * the synchronous step that applies the text: made only before the
281
+ * serialiser's await, a close during it lets the write land on a document
282
+ * this session no longer has open, and two writes based on one version
283
+ * both apply.
284
+ *
285
+ * Resolves with the latest build of the document, which may already carry
286
+ * a newer write; that is logged at debug, and a slow update at warn when
287
+ * `ClientSessionFactoryOptions.slowUpdateWarnMs` is set.
288
+ */
289
+ protected async updateDocument(
290
+ args: ClientSessionWriteArgs<TTransfer>,
291
+ cancelToken?: CancellationToken
292
+ ): Promise<AstDocument<TAst, TDiagnostic>> {
293
+ const service = this.modelService;
294
+ const slowWarn = this.slowUpdateWarn && { threshold: this.slowUpdateWarn, stopwatch: this.services.Clock.stopwatch() };
295
+ const uri = this.canonicalKey(args.uri);
296
+ const profile = Logger.isLevelEnabled('debug') ? this.tracer.profile(`model-update ${uri}`) : undefined;
297
+ const run = async <T>(stage: string, fn: () => MaybePromise<T>): Promise<T> => (profile ? profile.scope(stage, fn) : fn());
298
+ const textDocuments = this.services.workspace.TextDocuments;
299
+ this.assertOpen(uri);
300
+ this.assertBasedOn(uri, args.basedOn, textDocuments.version(uri));
301
+ const text = await run('serialize', () => service.modelToText(uri, args.model, cancelToken));
302
+ const appliedVersion = await run('apply', () => {
303
+ this.assertOpen(uri);
304
+ this.assertBasedOn(uri, args.basedOn, textDocuments.version(uri));
305
+ return this.services.workspace.AstDocumentManager.update(uri, text, this.clientId);
306
+ });
307
+ // Through the public `rebuild`, so an override of it stays in the path.
308
+ // An override that awaits before calling the base can outlast the build
309
+ // this write already has, and then builds it twice; see
310
+ // `ModelService.rebuild`.
311
+ const doc = await run('rebuild', () => service.rebuild(uri, undefined, cancelToken));
312
+ const finalVersion = textDocuments.version(uri);
313
+ if (finalVersion > appliedVersion) {
314
+ this.tracer.debug(`Update to v${appliedVersion} ready at v${finalVersion} (changed again before it settled)`);
315
+ } else {
316
+ this.tracer.debug(`Update to v${appliedVersion} ready`);
317
+ }
318
+ if (slowWarn) {
319
+ const elapsed = Math.round(slowWarn.stopwatch.elapsedMs);
320
+ const threshold = slowWarn.threshold.value;
321
+ if (elapsed >= threshold) {
322
+ this.tracer.withUri(uri).warn(`Slow update: ${elapsed}ms ≥ ${threshold}ms (v${appliedVersion}, client=${this.clientId})`);
323
+ }
324
+ }
325
+ profile?.report('debug');
326
+ return doc;
327
+ }
328
+
329
+ /**
330
+ * Write every document of `args.updates`, all or none: every model is
331
+ * serialised first, then every open check and `basedOn` gate runs and every
332
+ * text is applied in one synchronous step. Checked at the door as well, so
333
+ * a stale set is refused before any adopter serialiser runs.
334
+ *
335
+ * The apply step relies on `AstDocumentManager.update` applying its text
336
+ * before its first await, as the default does: an override that awaits first
337
+ * lets another write land between two documents of the set.
338
+ */
339
+ protected async updateDocuments(
340
+ args: ClientSessionUpdateAllArgs<TTransfer>,
341
+ cancelToken?: CancellationToken
342
+ ): Promise<AstDocument<TAst, TDiagnostic>[]> {
343
+ const service = this.modelService;
344
+ const { updates } = args;
345
+ const textDocuments = this.services.workspace.TextDocuments;
346
+ const uris = updates.map(update => this.canonicalKey(update.uri));
347
+ if (new Set(uris).size !== uris.length) {
348
+ throw new Error(`updateAll names a document more than once: ${uris.join(', ')}`);
349
+ }
350
+ const check = (): void =>
351
+ updates.forEach((update, i) => {
352
+ this.assertOpen(uris[i]);
353
+ this.assertBasedOn(uris[i], update.basedOn, textDocuments.version(uris[i]));
354
+ });
355
+ check();
356
+ const texts: string[] = [];
357
+ for (const [i, update] of updates.entries()) {
358
+ texts.push(await service.modelToText(uris[i], update.model, cancelToken));
359
+ }
360
+ // One synchronous step from the first check to the last apply: an await
361
+ // anywhere in it lets a close or another write land after its document
362
+ // was checked, and the set then half-applies before a later check fails.
363
+ check();
364
+ const applied = uris.map((uri, i) => this.services.workspace.AstDocumentManager.update(uri, texts[i], this.clientId));
365
+ await Promise.all(applied);
366
+ return Promise.all(uris.map(uri => service.rebuild(uri, undefined, cancelToken)));
367
+ }
368
+
369
+ /**
370
+ * Write `args.model` through {@link updateDocument}, so an override of it
371
+ * applies to saves too, then persist the document.
372
+ *
373
+ * Fails with `DocumentNotOpenError` and writes nothing when this session
374
+ * closes the URI while the text is being built: the check sits in the same
375
+ * synchronous step as the manager taking the text. Checked any earlier, a
376
+ * session that closes the URI during the rebuild still has the shared
377
+ * text, other clients' edits included, written in its name. Once taken,
378
+ * the write completes whatever the session does next.
379
+ */
380
+ protected async saveDocument(
381
+ args: ClientSessionWriteArgs<TTransfer>,
382
+ cancelToken?: CancellationToken
383
+ ): Promise<AstDocument<TAst, TDiagnostic>> {
384
+ const doc = await this.updateDocument(args, cancelToken);
385
+ const uri = this.canonicalKey(args.uri);
386
+ this.assertOpen(uri);
387
+ await this.services.workspace.AstDocumentManager.save(uri, this.clientId);
388
+ return doc;
389
+ }
390
+
391
+ protected async closeDocument(uri: string): Promise<void> {
392
+ await this.services.workspace.AstDocumentManager.close({ uri, clientId: this.clientId });
393
+ }
394
+
395
+ /** Open `uri`, or join the open of it this session already has under way, whose options then stand. */
396
+ protected openDocument(uri: string, options: TOpenOptions | undefined): Promise<void> {
397
+ const key = this.canonicalKey(uri);
398
+ const pending = this.pendingOpens.get(key);
399
+ if (pending) {
400
+ return pending;
401
+ }
402
+ const opening = this.registerOpen(uri, options).finally(() => {
403
+ if (this.pendingOpens.get(key) === opening) {
404
+ this.pendingOpens.delete(key);
405
+ }
406
+ });
407
+ this.pendingOpens.set(key, opening);
408
+ return opening;
409
+ }
410
+
411
+ /**
412
+ * Open `uri` in the store for this session. The open path does not thread
413
+ * cancellation: the file read behind it takes no token, so a cancelled
414
+ * caller still completes the open.
415
+ *
416
+ * A first open records its options before the store opens the URI, so a
417
+ * listener of the store's open reads this open's options rather than an
418
+ * earlier one's.
419
+ */
420
+ protected async registerOpen(uri: string, options: TOpenOptions | undefined): Promise<void> {
421
+ const wasOpen = this.services.workspace.TextDocuments.isOpenInClient(uri, this.clientId);
422
+ if (!wasOpen) {
423
+ this.openOptionsByUri.set(this.canonicalKey(uri), options);
424
+ }
425
+ await this.services.workspace.AstDocumentManager.open({ uri, clientId: this.clientId });
426
+ await this.rejectIfEnded(uri, wasOpen);
427
+ }
428
+
429
+ protected canonicalKey(uri: string): string {
430
+ return this.services.workspace.DocumentUriPolicy.canonicalUri(uri);
431
+ }
432
+
433
+ protected async createDocument(uri: string, text: string): Promise<void> {
434
+ if (await this.services.workspace.FileSystemProvider.exists(UriUtils.toUri(uri))) {
435
+ throw new Error(`Cannot create ${uri}: the file exists`);
436
+ }
437
+ this.assertLive();
438
+ if (this.services.workspace.TextDocuments.isRevertPending(uri)) {
439
+ throw new Error(`Cannot create ${uri}: it holds the unsaved text of a lost client, waiting out the revert grace`);
440
+ }
441
+ if (this.modelService.isOpen(uri)) {
442
+ throw new Error(`Cannot create ${uri}: it is open in a client`);
443
+ }
444
+ // The check above cannot see an open that registers while this one is
445
+ // under way, and opening an already-open URI only attaches, dropping
446
+ // `text`. Only an open that creates the document fires `onDidOpen`, so
447
+ // hearing it for this session, during this open, is what proves the
448
+ // document holds `text`; the client list afterwards cannot, since a
449
+ // client that registered first may have closed again by then.
450
+ const key = this.canonicalKey(uri);
451
+ let created = false;
452
+ const listener = this.services.workspace.TextDocuments.onDidOpen(event => {
453
+ if (event.clientId === this.clientId && event.document.uri === key) {
454
+ created = true;
455
+ }
456
+ });
457
+ try {
458
+ await this.services.workspace.AstDocumentManager.open({ uri, clientId: this.clientId, text });
459
+ } finally {
460
+ listener.dispose();
461
+ }
462
+ await this.rejectIfEnded(uri, false);
463
+ if (!created) {
464
+ await this.closeDocument(uri);
465
+ throw new Error(`Cannot create ${uri}: it is open in a client`);
466
+ }
467
+ }
468
+
469
+ protected async runWithOpen<T>(uri: string, fn: () => MaybePromise<T>): Promise<T> {
470
+ // An open another call of this session is still making counts as made:
471
+ // closing it afterwards would take away an open that call asked for.
472
+ const alreadyOpen =
473
+ this.services.workspace.TextDocuments.isOpenInClient(uri, this.clientId) || this.pendingOpens.has(this.canonicalKey(uri));
474
+ await this.openDocument(uri, undefined);
475
+ try {
476
+ return await fn();
477
+ } finally {
478
+ if (!alreadyOpen && !this.disposed) {
479
+ await this.closeDocument(uri);
480
+ }
481
+ }
482
+ }
483
+
484
+ /**
485
+ * Undo an open that completed after the session ended, then fail it.
486
+ *
487
+ * Ending the session closed only what it had open at that moment. An open
488
+ * still reading from disk registers afterwards, under an id that is no
489
+ * longer a session, and nothing would ever close it.
490
+ *
491
+ * Opens are keyed by id, so once a new session holds the same id this open
492
+ * is indistinguishable from one of its own, and closing it would close the
493
+ * new session's. It is left to that session, which releases it at its end.
494
+ */
495
+ protected async rejectIfEnded(uri: string, wasOpen: boolean): Promise<void> {
496
+ if (!this.disposed) {
497
+ return;
498
+ }
499
+ if (!wasOpen && this.modelService.getSession(this.clientId) === undefined) {
500
+ await this.closeDocument(uri);
501
+ }
502
+ throw new SessionClosedError(this.clientId);
503
+ }
504
+ }
505
+
506
+ /** Constructor options for {@link DefaultClientSessionFactory}. */
507
+ export interface ClientSessionFactoryOptions extends LogNameOptions {
508
+ /**
509
+ * The name the factory and every session it builds log under, so one
510
+ * option renames both. Default: `ClientSessionFactory` for the factory,
511
+ * and `ClientSession` for a session, which adds its client id in a bracket
512
+ * of its own.
513
+ */
514
+ readonly logName?: string;
515
+ /**
516
+ * When set, a session's `update` logs a `warn` line if its end-to-end wait
517
+ * (serialise, apply, rebuild) takes at least this many milliseconds. Default
518
+ * `undefined`: no warn line, and no per-update stopwatch.
519
+ *
520
+ * Observability only: the update is neither aborted nor resolved
521
+ * differently. A hard timeout that throws is an override of
522
+ * `DefaultClientSession.updateDocument` racing the parent call against a
523
+ * deadline.
524
+ *
525
+ * A recommended starting threshold is 2-5 seconds; workspaces with very
526
+ * large documents or slow validation can exceed 5 s on a cold build. A
527
+ * `Settings.number` binding retunes it live.
528
+ */
529
+ readonly slowUpdateWarnMs?: MaybeObservableValue<number>;
530
+ }
531
+
532
+ /**
533
+ * Constructor options for {@link DefaultClientSession}: the factory's options,
534
+ * which it forwards, plus the session's identity.
535
+ */
536
+ export interface ClientSessionOptions extends ClientSessionFactoryOptions {
537
+ readonly clientId: string;
538
+ /** What the session is. Pass one: the client id stands in for it otherwise. */
539
+ readonly label?: string;
540
+ }
541
+
542
+ /**
543
+ * Builds the handle for a session `ModelService.createSession` has already
544
+ * registered, so registration and the uniqueness check cannot be skipped by
545
+ * binding a factory of one's own. Bind one on `model.ClientSessionFactory` to
546
+ * use a session class of your own. A factory that does not pass
547
+ * {@link ClientSessionFactoryOptions.slowUpdateWarnMs} on to its sessions
548
+ * loses their slow-update warn; subclassing {@link DefaultClientSessionFactory}
549
+ * keeps it.
550
+ *
551
+ * Typed for every grammar, since the slot is shared: `createSession` narrows
552
+ * the result to its caller's types.
553
+ */
554
+ export interface ClientSessionFactory {
555
+ create(clientId: string, label: string): ClientSession<AstNode>;
556
+ }
557
+
558
+ /**
559
+ * The framework's {@link ClientSessionFactory}: a {@link DefaultClientSession}
560
+ * over the {@link ModelService} bound on `model.ModelService`, which the session
561
+ * serialises and rebuilds through. A model service constructed outside that
562
+ * slot therefore starts sessions that write through the bound one.
563
+ *
564
+ * A subclass that overrides {@link create} to build a session class of its
565
+ * own passes {@link options} on to that session's constructor; a session built
566
+ * without them has no slow-update warn and logs under the default name.
567
+ */
568
+ export class DefaultClientSessionFactory implements ClientSessionFactory {
569
+ protected readonly tracer: Tracer;
570
+
571
+ constructor(
572
+ protected readonly services: ServerSharedServices,
573
+ protected readonly options: ClientSessionFactoryOptions = {}
574
+ ) {
575
+ this.tracer = services.Tracer.for(options.logName ?? 'ClientSessionFactory').trace('instantiated');
576
+ }
577
+
578
+ create(clientId: string, label: string): ClientSession<AstNode> {
579
+ return new DefaultClientSession(this.services, { ...this.options, clientId, label });
580
+ }
581
+ }
@@ -8,3 +8,4 @@
8
8
  ********************************************************************************/
9
9
 
10
10
  export * from './model-service.js';
11
+ export * from './client-session.js';