@hydranium/core 1.0.0-next.16 → 1.0.0-next.168

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