@hydranium/core 1.0.0-next.27 → 1.0.0-next.271

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 (735) hide show
  1. package/README.md +64 -82
  2. package/lib/documents/ast-document-manager.d.ts +219 -122
  3. package/lib/documents/ast-document-manager.d.ts.map +1 -1
  4. package/lib/documents/ast-document-manager.js +242 -130
  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 +146 -0
  15. package/lib/documents/client-session-registry.d.ts.map +1 -0
  16. package/lib/documents/client-session-registry.js +207 -0
  17. package/lib/documents/client-session-registry.js.map +1 -0
  18. package/lib/documents/dirty-state-tracker.d.ts +86 -0
  19. package/lib/documents/dirty-state-tracker.d.ts.map +1 -0
  20. package/lib/documents/dirty-state-tracker.js +72 -0
  21. package/lib/documents/dirty-state-tracker.js.map +1 -0
  22. package/lib/documents/document-release-handler.d.ts +204 -0
  23. package/lib/documents/document-release-handler.d.ts.map +1 -0
  24. package/lib/documents/document-release-handler.js +317 -0
  25. package/lib/documents/document-release-handler.js.map +1 -0
  26. package/lib/documents/document-release-scheduler.d.ts +67 -0
  27. package/lib/documents/document-release-scheduler.d.ts.map +1 -0
  28. package/lib/documents/document-release-scheduler.js +80 -0
  29. package/lib/documents/document-release-scheduler.js.map +1 -0
  30. package/lib/documents/file-system-task-queue.d.ts +49 -0
  31. package/lib/documents/file-system-task-queue.d.ts.map +1 -0
  32. package/lib/documents/file-system-task-queue.js +34 -0
  33. package/lib/documents/file-system-task-queue.js.map +1 -0
  34. package/lib/documents/hydranium-text-documents.d.ts +401 -282
  35. package/lib/documents/hydranium-text-documents.d.ts.map +1 -1
  36. package/lib/documents/hydranium-text-documents.js +827 -483
  37. package/lib/documents/hydranium-text-documents.js.map +1 -1
  38. package/lib/documents/index.d.ts +10 -2
  39. package/lib/documents/index.d.ts.map +1 -1
  40. package/lib/documents/index.js +10 -2
  41. package/lib/documents/index.js.map +1 -1
  42. package/lib/documents/language-client-shadow.d.ts +218 -0
  43. package/lib/documents/language-client-shadow.d.ts.map +1 -0
  44. package/lib/documents/language-client-shadow.js +284 -0
  45. package/lib/documents/language-client-shadow.js.map +1 -0
  46. package/lib/documents/model-ledger.d.ts +47 -0
  47. package/lib/documents/model-ledger.d.ts.map +1 -0
  48. package/lib/documents/model-ledger.js +30 -0
  49. package/lib/documents/model-ledger.js.map +1 -0
  50. package/lib/documents/text-ledger.d.ts +64 -0
  51. package/lib/documents/text-ledger.d.ts.map +1 -0
  52. package/lib/documents/text-ledger.js +63 -0
  53. package/lib/documents/text-ledger.js.map +1 -0
  54. package/lib/documents/version-sync-service.d.ts +138 -0
  55. package/lib/documents/version-sync-service.d.ts.map +1 -0
  56. package/lib/documents/version-sync-service.js +173 -0
  57. package/lib/documents/version-sync-service.js.map +1 -0
  58. package/lib/index.d.ts +5 -0
  59. package/lib/index.d.ts.map +1 -1
  60. package/lib/index.js +8 -0
  61. package/lib/index.js.map +1 -1
  62. package/lib/langium/ast-extension/ast-extension-service.d.ts +3 -0
  63. package/lib/langium/ast-extension/ast-extension-service.d.ts.map +1 -1
  64. package/lib/langium/ast-extension/ast-extension-service.js.map +1 -1
  65. package/lib/langium/ast-extension/ast-node-builder.d.ts +32 -9
  66. package/lib/langium/ast-extension/ast-node-builder.d.ts.map +1 -1
  67. package/lib/langium/ast-extension/ast-node-builder.js +60 -22
  68. package/lib/langium/ast-extension/ast-node-builder.js.map +1 -1
  69. package/lib/langium/bootstrap.d.ts +34 -25
  70. package/lib/langium/bootstrap.d.ts.map +1 -1
  71. package/lib/langium/bootstrap.js +77 -37
  72. package/lib/langium/bootstrap.js.map +1 -1
  73. package/lib/langium/build-phase-pass/build-phase-pass-service.d.ts +1 -1
  74. package/lib/langium/build-phase-pass/build-phase-pass-service.d.ts.map +1 -1
  75. package/lib/langium/build-phase-pass/build-phase-pass-service.js.map +1 -1
  76. package/lib/langium/build-phase-pass/build-phase-pass.d.ts +1 -1
  77. package/lib/langium/composite-ast-reflection.d.ts +46 -0
  78. package/lib/langium/composite-ast-reflection.d.ts.map +1 -0
  79. package/lib/langium/composite-ast-reflection.js +97 -0
  80. package/lib/langium/composite-ast-reflection.js.map +1 -0
  81. package/lib/langium/config/configuration-provider.d.ts +81 -0
  82. package/lib/langium/config/configuration-provider.d.ts.map +1 -0
  83. package/lib/langium/config/configuration-provider.js +112 -0
  84. package/lib/langium/config/configuration-provider.js.map +1 -0
  85. package/lib/langium/config/index.d.ts +1 -0
  86. package/lib/langium/config/index.d.ts.map +1 -1
  87. package/lib/langium/config/index.js +1 -0
  88. package/lib/langium/config/index.js.map +1 -1
  89. package/lib/langium/config/settings.js.map +1 -1
  90. package/lib/langium/diagnostics/hydranium-langium-profiler.d.ts +9 -20
  91. package/lib/langium/diagnostics/hydranium-langium-profiler.d.ts.map +1 -1
  92. package/lib/langium/diagnostics/hydranium-langium-profiler.js +15 -24
  93. package/lib/langium/diagnostics/hydranium-langium-profiler.js.map +1 -1
  94. package/lib/langium/diagnostics/log-preamble.js +1 -1
  95. package/lib/langium/diagnostics/log-preamble.js.map +1 -1
  96. package/lib/langium/diagnostics/logger.d.ts +10 -3
  97. package/lib/langium/diagnostics/logger.d.ts.map +1 -1
  98. package/lib/langium/diagnostics/logger.js +12 -5
  99. package/lib/langium/diagnostics/logger.js.map +1 -1
  100. package/lib/langium/diagnostics/lsp-logger.d.ts +17 -0
  101. package/lib/langium/diagnostics/lsp-logger.d.ts.map +1 -1
  102. package/lib/langium/diagnostics/lsp-logger.js +58 -17
  103. package/lib/langium/diagnostics/lsp-logger.js.map +1 -1
  104. package/lib/langium/diagnostics/server-tracer.d.ts.map +1 -1
  105. package/lib/langium/diagnostics/server-tracer.js.map +1 -1
  106. package/lib/langium/document-builder/build-pipeline-integration.d.ts +21 -1
  107. package/lib/langium/document-builder/build-pipeline-integration.d.ts.map +1 -1
  108. package/lib/langium/document-builder/build-pipeline-integration.js +32 -5
  109. package/lib/langium/document-builder/build-pipeline-integration.js.map +1 -1
  110. package/lib/langium/document-builder/build-session.d.ts +6 -5
  111. package/lib/langium/document-builder/build-session.d.ts.map +1 -1
  112. package/lib/langium/document-builder/build-session.js +5 -5
  113. package/lib/langium/document-builder/build-session.js.map +1 -1
  114. package/lib/langium/document-builder/document-builder.d.ts +309 -35
  115. package/lib/langium/document-builder/document-builder.d.ts.map +1 -1
  116. package/lib/langium/document-builder/document-builder.js +511 -75
  117. package/lib/langium/document-builder/document-builder.js.map +1 -1
  118. package/lib/langium/documentation/comment-provider.d.ts.map +1 -1
  119. package/lib/langium/documentation/comment-provider.js.map +1 -1
  120. package/lib/langium/integration-services.d.ts +61 -19
  121. package/lib/langium/integration-services.d.ts.map +1 -1
  122. package/lib/langium/integration-services.js +10 -5
  123. package/lib/langium/integration-services.js.map +1 -1
  124. package/lib/langium/integrity/integrity-rule.d.ts +16 -8
  125. package/lib/langium/integrity/integrity-rule.d.ts.map +1 -1
  126. package/lib/langium/integrity/integrity-rule.js.map +1 -1
  127. package/lib/langium/integrity/integrity-service.d.ts +83 -27
  128. package/lib/langium/integrity/integrity-service.d.ts.map +1 -1
  129. package/lib/langium/integrity/integrity-service.js +273 -63
  130. package/lib/langium/integrity/integrity-service.js.map +1 -1
  131. package/lib/langium/keys/containment.d.ts +64 -0
  132. package/lib/langium/keys/containment.d.ts.map +1 -0
  133. package/lib/langium/keys/containment.js +53 -0
  134. package/lib/langium/keys/containment.js.map +1 -0
  135. package/lib/langium/keys/index.d.ts +1 -0
  136. package/lib/langium/keys/index.d.ts.map +1 -1
  137. package/lib/langium/keys/index.js +1 -0
  138. package/lib/langium/keys/index.js.map +1 -1
  139. package/lib/langium/keys/name-based-key-provider.d.ts +4 -0
  140. package/lib/langium/keys/name-based-key-provider.d.ts.map +1 -1
  141. package/lib/langium/keys/name-based-key-provider.js +4 -0
  142. package/lib/langium/keys/name-based-key-provider.js.map +1 -1
  143. package/lib/langium/keys/positional-key-provider.d.ts.map +1 -1
  144. package/lib/langium/keys/positional-key-provider.js.map +1 -1
  145. package/lib/langium/labeling/label-provider.d.ts.map +1 -1
  146. package/lib/langium/labeling/label-provider.js.map +1 -1
  147. package/lib/langium/language-module.d.ts +30 -5
  148. package/lib/langium/language-module.d.ts.map +1 -1
  149. package/lib/langium/language-module.js +18 -4
  150. package/lib/langium/language-module.js.map +1 -1
  151. package/lib/langium/model-service/client-session.d.ts +343 -0
  152. package/lib/langium/model-service/client-session.d.ts.map +1 -0
  153. package/lib/langium/model-service/client-session.js +428 -0
  154. package/lib/langium/model-service/client-session.js.map +1 -0
  155. package/lib/langium/model-service/index.d.ts +2 -0
  156. package/lib/langium/model-service/index.d.ts.map +1 -1
  157. package/lib/langium/model-service/index.js +2 -0
  158. package/lib/langium/model-service/index.js.map +1 -1
  159. package/lib/langium/model-service/model-events.d.ts +61 -0
  160. package/lib/langium/model-service/model-events.d.ts.map +1 -0
  161. package/lib/langium/model-service/model-events.js +10 -0
  162. package/lib/langium/model-service/model-events.js.map +1 -0
  163. package/lib/langium/model-service/model-service.d.ts +433 -282
  164. package/lib/langium/model-service/model-service.d.ts.map +1 -1
  165. package/lib/langium/model-service/model-service.js +537 -441
  166. package/lib/langium/model-service/model-service.js.map +1 -1
  167. package/lib/langium/module.d.ts +151 -36
  168. package/lib/langium/module.d.ts.map +1 -1
  169. package/lib/langium/module.js +48 -36
  170. package/lib/langium/module.js.map +1 -1
  171. package/lib/langium/naming/name-provider.d.ts +27 -6
  172. package/lib/langium/naming/name-provider.d.ts.map +1 -1
  173. package/lib/langium/naming/name-provider.js +4 -3
  174. package/lib/langium/naming/name-provider.js.map +1 -1
  175. package/lib/langium/naming/name-separator-validation.d.ts +23 -1
  176. package/lib/langium/naming/name-separator-validation.d.ts.map +1 -1
  177. package/lib/langium/naming/name-separator-validation.js +22 -0
  178. package/lib/langium/naming/name-separator-validation.js.map +1 -1
  179. package/lib/langium/project/abstract-project-manager.d.ts.map +1 -1
  180. package/lib/langium/project/abstract-project-manager.js +13 -6
  181. package/lib/langium/project/abstract-project-manager.js.map +1 -1
  182. package/lib/langium/project/project-change-event.d.ts +2 -2
  183. package/lib/langium/project/single-project-manager.d.ts.map +1 -1
  184. package/lib/langium/project/single-project-manager.js.map +1 -1
  185. package/lib/langium/residency/cst-residency-service.d.ts +35 -12
  186. package/lib/langium/residency/cst-residency-service.d.ts.map +1 -1
  187. package/lib/langium/residency/cst-residency-service.js +23 -57
  188. package/lib/langium/residency/cst-residency-service.js.map +1 -1
  189. package/lib/langium/scope/ast-node-description-provider.d.ts.map +1 -1
  190. package/lib/langium/scope/ast-node-description-provider.js.map +1 -1
  191. package/lib/langium/scope/fallback-scope.d.ts +27 -0
  192. package/lib/langium/scope/fallback-scope.d.ts.map +1 -0
  193. package/lib/langium/scope/fallback-scope.js +35 -0
  194. package/lib/langium/scope/fallback-scope.js.map +1 -0
  195. package/lib/langium/scope/hydranium-scope-computation.d.ts +21 -18
  196. package/lib/langium/scope/hydranium-scope-computation.d.ts.map +1 -1
  197. package/lib/langium/scope/hydranium-scope-computation.js +38 -39
  198. package/lib/langium/scope/hydranium-scope-computation.js.map +1 -1
  199. package/lib/langium/scope/hydranium-scope-provider.d.ts +61 -24
  200. package/lib/langium/scope/hydranium-scope-provider.d.ts.map +1 -1
  201. package/lib/langium/scope/hydranium-scope-provider.js +74 -35
  202. package/lib/langium/scope/hydranium-scope-provider.js.map +1 -1
  203. package/lib/langium/scope/index.d.ts +1 -0
  204. package/lib/langium/scope/index.d.ts.map +1 -1
  205. package/lib/langium/scope/index.js +1 -0
  206. package/lib/langium/scope/index.js.map +1 -1
  207. package/lib/langium/scope/reference-builder.d.ts.map +1 -1
  208. package/lib/langium/scope/reference-builder.js.map +1 -1
  209. package/lib/langium/scope/reference-candidate-provider.d.ts +6 -5
  210. package/lib/langium/scope/reference-candidate-provider.d.ts.map +1 -1
  211. package/lib/langium/scope/reference-candidate-provider.js +3 -2
  212. package/lib/langium/scope/reference-candidate-provider.js.map +1 -1
  213. package/lib/langium/scope/scope-extension-service.d.ts +41 -37
  214. package/lib/langium/scope/scope-extension-service.d.ts.map +1 -1
  215. package/lib/langium/scope/scope-extension-service.js +57 -29
  216. package/lib/langium/scope/scope-extension-service.js.map +1 -1
  217. package/lib/langium/scope/scoped-ast-node-description.d.ts +1 -3
  218. package/lib/langium/scope/scoped-ast-node-description.d.ts.map +1 -1
  219. package/lib/langium/scope/scoped-ast-node-description.js +1 -3
  220. package/lib/langium/scope/scoped-ast-node-description.js.map +1 -1
  221. package/lib/langium/serialization/abstract-serializer.d.ts +11 -20
  222. package/lib/langium/serialization/abstract-serializer.d.ts.map +1 -1
  223. package/lib/langium/serialization/abstract-serializer.js +12 -21
  224. package/lib/langium/serialization/abstract-serializer.js.map +1 -1
  225. package/lib/langium/serialization/json-serializer.d.ts +1 -1
  226. package/lib/langium/serialization/json-serializer.d.ts.map +1 -1
  227. package/lib/langium/serialization/json-serializer.js.map +1 -1
  228. package/lib/langium/serialization/serializer.d.ts +1 -1
  229. package/lib/langium/serialization/yaml-serializer.d.ts.map +1 -1
  230. package/lib/langium/serialization/yaml-serializer.js.map +1 -1
  231. package/lib/langium/service-registry.d.ts +29 -1
  232. package/lib/langium/service-registry.d.ts.map +1 -1
  233. package/lib/langium/service-registry.js +37 -0
  234. package/lib/langium/service-registry.js.map +1 -1
  235. package/lib/langium/shared-services.d.ts +23 -6
  236. package/lib/langium/shared-services.d.ts.map +1 -1
  237. package/lib/langium/shared-services.js.map +1 -1
  238. package/lib/langium/single-langium-copy.d.ts +22 -0
  239. package/lib/langium/single-langium-copy.d.ts.map +1 -0
  240. package/lib/langium/single-langium-copy.js +36 -0
  241. package/lib/langium/single-langium-copy.js.map +1 -0
  242. package/lib/langium/transfer/transfer-encoder.d.ts +88 -36
  243. package/lib/langium/transfer/transfer-encoder.d.ts.map +1 -1
  244. package/lib/langium/transfer/transfer-encoder.js +46 -24
  245. package/lib/langium/transfer/transfer-encoder.js.map +1 -1
  246. package/lib/langium/trivia/comment-preserver.d.ts +423 -0
  247. package/lib/langium/trivia/comment-preserver.d.ts.map +1 -0
  248. package/lib/langium/trivia/comment-preserver.js +906 -0
  249. package/lib/langium/trivia/comment-preserver.js.map +1 -0
  250. package/lib/langium/trivia/document-ending-preserver.d.ts +43 -0
  251. package/lib/langium/trivia/document-ending-preserver.d.ts.map +1 -0
  252. package/lib/langium/trivia/document-ending-preserver.js +48 -0
  253. package/lib/langium/trivia/document-ending-preserver.js.map +1 -0
  254. package/lib/langium/trivia/index.d.ts +14 -0
  255. package/lib/langium/trivia/index.d.ts.map +1 -0
  256. package/lib/langium/trivia/index.js +14 -0
  257. package/lib/langium/trivia/index.js.map +1 -0
  258. package/lib/langium/trivia/trivia-contribution.d.ts +37 -0
  259. package/lib/langium/trivia/trivia-contribution.d.ts.map +1 -0
  260. package/lib/langium/trivia/trivia-contribution.js +10 -0
  261. package/lib/langium/trivia/trivia-contribution.js.map +1 -0
  262. package/lib/langium/trivia/trivia-preserver.d.ts +50 -0
  263. package/lib/langium/trivia/trivia-preserver.d.ts.map +1 -0
  264. package/lib/langium/trivia/trivia-preserver.js +10 -0
  265. package/lib/langium/trivia/trivia-preserver.js.map +1 -0
  266. package/lib/langium/trivia/trivia-service.d.ts +70 -0
  267. package/lib/langium/trivia/trivia-service.d.ts.map +1 -0
  268. package/lib/langium/trivia/trivia-service.js +56 -0
  269. package/lib/langium/trivia/trivia-service.js.map +1 -0
  270. package/lib/langium/update-rewrite/normalize-empty-strings.d.ts.map +1 -1
  271. package/lib/langium/update-rewrite/update-rewrite-service.d.ts +1 -1
  272. package/lib/langium/update-rewrite/update-rewrite-service.d.ts.map +1 -1
  273. package/lib/langium/update-rewrite/update-rewrite-service.js.map +1 -1
  274. package/lib/langium/update-rewrite/update-rewrite.d.ts +1 -1
  275. package/lib/langium/validation/document-validator.d.ts +280 -9
  276. package/lib/langium/validation/document-validator.d.ts.map +1 -1
  277. package/lib/langium/validation/document-validator.js +453 -8
  278. package/lib/langium/validation/document-validator.js.map +1 -1
  279. package/lib/langium/validation/validation-contribution-collector.d.ts +9 -1
  280. package/lib/langium/validation/validation-contribution-collector.d.ts.map +1 -1
  281. package/lib/langium/validation/validation-contribution-collector.js +1 -1
  282. package/lib/langium/validation/validation-contribution-collector.js.map +1 -1
  283. package/lib/langium/workspace/document-uri-policy.d.ts +15 -10
  284. package/lib/langium/workspace/document-uri-policy.d.ts.map +1 -1
  285. package/lib/langium/workspace/document-uri-policy.js +7 -5
  286. package/lib/langium/workspace/document-uri-policy.js.map +1 -1
  287. package/lib/langium/workspace/file-not-found.d.ts +23 -0
  288. package/lib/langium/workspace/file-not-found.d.ts.map +1 -0
  289. package/lib/langium/workspace/file-not-found.js +31 -0
  290. package/lib/langium/workspace/file-not-found.js.map +1 -0
  291. package/lib/langium/workspace/file-system-provider.d.ts +147 -9
  292. package/lib/langium/workspace/file-system-provider.d.ts.map +1 -1
  293. package/lib/langium/workspace/file-system-provider.js +97 -14
  294. package/lib/langium/workspace/file-system-provider.js.map +1 -1
  295. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts +56 -1
  296. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts.map +1 -1
  297. package/lib/langium/workspace/hydranium-langium-document-factory.js +79 -0
  298. package/lib/langium/workspace/hydranium-langium-document-factory.js.map +1 -1
  299. package/lib/langium/workspace/hydranium-workspace-lock.d.ts +43 -1
  300. package/lib/langium/workspace/hydranium-workspace-lock.d.ts.map +1 -1
  301. package/lib/langium/workspace/hydranium-workspace-lock.js +58 -1
  302. package/lib/langium/workspace/hydranium-workspace-lock.js.map +1 -1
  303. package/lib/langium/workspace/hydranium-workspace-manager.d.ts +82 -9
  304. package/lib/langium/workspace/hydranium-workspace-manager.d.ts.map +1 -1
  305. package/lib/langium/workspace/hydranium-workspace-manager.js +129 -12
  306. package/lib/langium/workspace/hydranium-workspace-manager.js.map +1 -1
  307. package/lib/langium/workspace/in-memory-file-system-provider.d.ts +22 -7
  308. package/lib/langium/workspace/in-memory-file-system-provider.d.ts.map +1 -1
  309. package/lib/langium/workspace/in-memory-file-system-provider.js +36 -19
  310. package/lib/langium/workspace/in-memory-file-system-provider.js.map +1 -1
  311. package/lib/langium/workspace/index-manager.d.ts.map +1 -1
  312. package/lib/langium/workspace/index-manager.js.map +1 -1
  313. package/lib/langium/workspace/index.d.ts +1 -0
  314. package/lib/langium/workspace/index.d.ts.map +1 -1
  315. package/lib/langium/workspace/index.js +1 -0
  316. package/lib/langium/workspace/index.js.map +1 -1
  317. package/lib/langium/workspace/initialize-workspace.d.ts +31 -2
  318. package/lib/langium/workspace/initialize-workspace.d.ts.map +1 -1
  319. package/lib/langium/workspace/initialize-workspace.js +13 -5
  320. package/lib/langium/workspace/initialize-workspace.js.map +1 -1
  321. package/lib/langium/workspace/langium-documents.d.ts +37 -4
  322. package/lib/langium/workspace/langium-documents.d.ts.map +1 -1
  323. package/lib/langium/workspace/langium-documents.js +49 -4
  324. package/lib/langium/workspace/langium-documents.js.map +1 -1
  325. package/lib/langium/workspace/persistent-file-system-provider.d.ts +1 -8
  326. package/lib/langium/workspace/persistent-file-system-provider.d.ts.map +1 -1
  327. package/lib/langium/workspace/persistent-file-system-provider.js +2 -8
  328. package/lib/langium/workspace/persistent-file-system-provider.js.map +1 -1
  329. package/lib/langium/workspace/self-save-registry.d.ts +84 -0
  330. package/lib/langium/workspace/self-save-registry.d.ts.map +1 -0
  331. package/lib/{documents → langium/workspace}/self-save-registry.js +33 -22
  332. package/lib/langium/workspace/self-save-registry.js.map +1 -0
  333. package/lib/langium/workspace/virtual-document.d.ts +48 -15
  334. package/lib/langium/workspace/virtual-document.d.ts.map +1 -1
  335. package/lib/langium/workspace/virtual-document.js +78 -18
  336. package/lib/langium/workspace/virtual-document.js.map +1 -1
  337. package/lib/langium/workspace/write-lock-scope.d.ts +20 -10
  338. package/lib/langium/workspace/write-lock-scope.d.ts.map +1 -1
  339. package/lib/langium/workspace/write-lock-scope.js +12 -4
  340. package/lib/langium/workspace/write-lock-scope.js.map +1 -1
  341. package/lib/launcher/integrated-server.d.ts +3 -1
  342. package/lib/launcher/integrated-server.d.ts.map +1 -1
  343. package/lib/locale/index.d.ts +10 -0
  344. package/lib/locale/index.d.ts.map +1 -0
  345. package/lib/locale/index.js +10 -0
  346. package/lib/locale/index.js.map +1 -0
  347. package/lib/locale/server-locale.d.ts +73 -0
  348. package/lib/locale/server-locale.d.ts.map +1 -0
  349. package/lib/locale/server-locale.js +61 -0
  350. package/lib/locale/server-locale.js.map +1 -0
  351. package/lib/lsp/completion/hydranium-completion-provider.d.ts +44 -2
  352. package/lib/lsp/completion/hydranium-completion-provider.d.ts.map +1 -1
  353. package/lib/lsp/completion/hydranium-completion-provider.js +68 -0
  354. package/lib/lsp/completion/hydranium-completion-provider.js.map +1 -1
  355. package/lib/lsp/connection-features.d.ts +23 -0
  356. package/lib/lsp/connection-features.d.ts.map +1 -0
  357. package/lib/lsp/connection-features.js +60 -0
  358. package/lib/lsp/connection-features.js.map +1 -0
  359. package/lib/lsp/diagnostics-connection.d.ts +27 -0
  360. package/lib/lsp/diagnostics-connection.d.ts.map +1 -0
  361. package/lib/lsp/diagnostics-connection.js +53 -0
  362. package/lib/lsp/diagnostics-connection.js.map +1 -0
  363. package/lib/lsp/hydranium-document-update-handler.d.ts +92 -81
  364. package/lib/lsp/hydranium-document-update-handler.d.ts.map +1 -1
  365. package/lib/lsp/hydranium-document-update-handler.js +155 -101
  366. package/lib/lsp/hydranium-document-update-handler.js.map +1 -1
  367. package/lib/lsp/index.d.ts +3 -1
  368. package/lib/lsp/index.d.ts.map +1 -1
  369. package/lib/lsp/index.js +3 -1
  370. package/lib/lsp/index.js.map +1 -1
  371. package/lib/lsp/lsp-latency.d.ts +39 -0
  372. package/lib/lsp/lsp-latency.d.ts.map +1 -0
  373. package/lib/lsp/lsp-latency.js +58 -0
  374. package/lib/lsp/lsp-latency.js.map +1 -0
  375. package/lib/lsp/semantic-token-provider.d.ts +34 -1
  376. package/lib/lsp/semantic-token-provider.d.ts.map +1 -1
  377. package/lib/lsp/semantic-token-provider.js +55 -8
  378. package/lib/lsp/semantic-token-provider.js.map +1 -1
  379. package/lib/lsp/shared-module.d.ts +4 -8
  380. package/lib/lsp/shared-module.d.ts.map +1 -1
  381. package/lib/lsp/shared-module.js.map +1 -1
  382. package/lib/lsp/start-language-server.d.ts +8 -7
  383. package/lib/lsp/start-language-server.d.ts.map +1 -1
  384. package/lib/lsp/start-language-server.js +13 -7
  385. package/lib/lsp/start-language-server.js.map +1 -1
  386. package/lib/messages/carriers.d.ts +18 -12
  387. package/lib/messages/carriers.d.ts.map +1 -1
  388. package/lib/messages/carriers.js +22 -13
  389. package/lib/messages/carriers.js.map +1 -1
  390. package/lib/messages/index.d.ts +4 -1
  391. package/lib/messages/index.d.ts.map +1 -1
  392. package/lib/messages/index.js +4 -1
  393. package/lib/messages/index.js.map +1 -1
  394. package/lib/messages/renderer.d.ts +142 -0
  395. package/lib/messages/renderer.d.ts.map +1 -0
  396. package/lib/messages/renderer.js +165 -0
  397. package/lib/messages/renderer.js.map +1 -0
  398. package/lib/node/event-loop-monitor.d.ts.map +1 -1
  399. package/lib/node/event-loop-monitor.js +2 -1
  400. package/lib/node/event-loop-monitor.js.map +1 -1
  401. package/lib/node/heap-ceiling.d.ts +61 -0
  402. package/lib/node/heap-ceiling.d.ts.map +1 -0
  403. package/lib/node/heap-ceiling.js +72 -0
  404. package/lib/node/heap-ceiling.js.map +1 -0
  405. package/lib/node/index.d.ts +1 -1
  406. package/lib/node/index.d.ts.map +1 -1
  407. package/lib/node/index.js +1 -1
  408. package/lib/node/index.js.map +1 -1
  409. package/lib/node/latency-from-env.d.ts +1 -1
  410. package/lib/node/latency-from-env.js +1 -1
  411. package/lib/node/lint-grammar.js.map +1 -1
  412. package/lib/node/log-preamble-node.d.ts +5 -3
  413. package/lib/node/log-preamble-node.d.ts.map +1 -1
  414. package/lib/node/log-preamble-node.js +13 -10
  415. package/lib/node/log-preamble-node.js.map +1 -1
  416. package/lib/node/measure-memory.d.ts.map +1 -1
  417. package/lib/node/measure-memory.js +5 -4
  418. package/lib/node/measure-memory.js.map +1 -1
  419. package/lib/node/memory-monitor.d.ts +2 -2
  420. package/lib/node/memory-monitor.d.ts.map +1 -1
  421. package/lib/node/memory-monitor.js +9 -10
  422. package/lib/node/memory-monitor.js.map +1 -1
  423. package/lib/node/node-file-system-provider.d.ts +54 -9
  424. package/lib/node/node-file-system-provider.d.ts.map +1 -1
  425. package/lib/node/node-file-system-provider.js +141 -52
  426. package/lib/node/node-file-system-provider.js.map +1 -1
  427. package/lib/node/profile-capture.d.ts +12 -4
  428. package/lib/node/profile-capture.d.ts.map +1 -1
  429. package/lib/node/profile-capture.js +8 -6
  430. package/lib/node/profile-capture.js.map +1 -1
  431. package/lib/node/profile-digest.js.map +1 -1
  432. package/lib/node/profiling-run.d.ts +13 -3
  433. package/lib/node/profiling-run.d.ts.map +1 -1
  434. package/lib/node/profiling-run.js +17 -8
  435. package/lib/node/profiling-run.js.map +1 -1
  436. package/lib/node/rename-over-open-readers.d.ts +61 -0
  437. package/lib/node/rename-over-open-readers.d.ts.map +1 -0
  438. package/lib/node/rename-over-open-readers.js +80 -0
  439. package/lib/node/rename-over-open-readers.js.map +1 -0
  440. package/lib/node/server-diagnostics.js +1 -1
  441. package/lib/node/server-diagnostics.js.map +1 -1
  442. package/lib/node/server-state-snapshot.js +4 -4
  443. package/lib/node/server-state-snapshot.js.map +1 -1
  444. package/lib/node/socket-launcher.d.ts +20 -4
  445. package/lib/node/socket-launcher.d.ts.map +1 -1
  446. package/lib/node/socket-launcher.js +8 -7
  447. package/lib/node/socket-launcher.js.map +1 -1
  448. package/lib/node/stdio-launcher.d.ts +6 -5
  449. package/lib/node/stdio-launcher.d.ts.map +1 -1
  450. package/lib/node/stdio-launcher.js +13 -4
  451. package/lib/node/stdio-launcher.js.map +1 -1
  452. package/lib/testing/document-uri-policy-conformance.js +1 -1
  453. package/lib/testing/document-uri-policy-conformance.js.map +1 -1
  454. package/lib/testing/fake-description.js.map +1 -1
  455. package/lib/testing/fake-document.d.ts +16 -4
  456. package/lib/testing/fake-document.d.ts.map +1 -1
  457. package/lib/testing/fake-document.js +18 -3
  458. package/lib/testing/fake-document.js.map +1 -1
  459. package/lib/testing/index.d.ts +1 -1
  460. package/lib/testing/index.d.ts.map +1 -1
  461. package/lib/testing/index.js +2 -1
  462. package/lib/testing/index.js.map +1 -1
  463. package/lib/testing/langium-test-helpers.d.ts.map +1 -1
  464. package/lib/testing/langium-test-helpers.js +1 -0
  465. package/lib/testing/langium-test-helpers.js.map +1 -1
  466. package/lib/testing/make-noop-language-services.js.map +1 -1
  467. package/lib/testing/make-noop-shared-services.d.ts +14 -0
  468. package/lib/testing/make-noop-shared-services.d.ts.map +1 -1
  469. package/lib/testing/make-noop-shared-services.js +28 -2
  470. package/lib/testing/make-noop-shared-services.js.map +1 -1
  471. package/lib/testing/make-test-services.d.ts +72 -14
  472. package/lib/testing/make-test-services.d.ts.map +1 -1
  473. package/lib/testing/make-test-services.js +42 -10
  474. package/lib/testing/make-test-services.js.map +1 -1
  475. package/lib/testing/make-test-tracer.d.ts +12 -0
  476. package/lib/testing/make-test-tracer.d.ts.map +1 -1
  477. package/lib/testing/make-test-tracer.js +13 -0
  478. package/lib/testing/make-test-tracer.js.map +1 -1
  479. package/lib/testing/node/applied-edit-capture.d.ts +29 -0
  480. package/lib/testing/node/applied-edit-capture.d.ts.map +1 -0
  481. package/lib/testing/node/applied-edit-capture.js +115 -0
  482. package/lib/testing/node/applied-edit-capture.js.map +1 -0
  483. package/lib/testing/node/golden-corpus.js.map +1 -1
  484. package/lib/testing/node/index.d.ts +1 -0
  485. package/lib/testing/node/index.d.ts.map +1 -1
  486. package/lib/testing/node/index.js +1 -0
  487. package/lib/testing/node/index.js.map +1 -1
  488. package/lib/testing/node/lsp-harness.d.ts.map +1 -1
  489. package/lib/testing/node/lsp-harness.js +2 -0
  490. package/lib/testing/node/lsp-harness.js.map +1 -1
  491. package/lib/testing/node/lsp-server-connection.d.ts +12 -4
  492. package/lib/testing/node/lsp-server-connection.d.ts.map +1 -1
  493. package/lib/testing/node/lsp-server-connection.js +45 -106
  494. package/lib/testing/node/lsp-server-connection.js.map +1 -1
  495. package/lib/testing/node/scratch-workspace.d.ts.map +1 -1
  496. package/lib/testing/node/scratch-workspace.js +10 -5
  497. package/lib/testing/node/scratch-workspace.js.map +1 -1
  498. package/lib/testing/node/spawned-server.d.ts +30 -1
  499. package/lib/testing/node/spawned-server.d.ts.map +1 -1
  500. package/lib/testing/node/spawned-server.js +39 -2
  501. package/lib/testing/node/spawned-server.js.map +1 -1
  502. package/lib/testing/node/unhandled-rejections.d.ts +20 -0
  503. package/lib/testing/node/unhandled-rejections.d.ts.map +1 -0
  504. package/lib/testing/node/unhandled-rejections.js +32 -0
  505. package/lib/testing/node/unhandled-rejections.js.map +1 -0
  506. package/lib/testing/playwright/browser-capture-bridge.js.map +1 -1
  507. package/lib/testing/playwright/e2e-profiling.js.map +1 -1
  508. package/lib/testing/playwright/flaky-network-proxy.d.ts +76 -0
  509. package/lib/testing/playwright/flaky-network-proxy.d.ts.map +1 -0
  510. package/lib/testing/playwright/flaky-network-proxy.js +164 -0
  511. package/lib/testing/playwright/flaky-network-proxy.js.map +1 -0
  512. package/lib/testing/playwright/index.d.ts +1 -0
  513. package/lib/testing/playwright/index.d.ts.map +1 -1
  514. package/lib/testing/playwright/index.js +1 -0
  515. package/lib/testing/playwright/index.js.map +1 -1
  516. package/lib/testing/playwright/server-log-capture.d.ts +35 -8
  517. package/lib/testing/playwright/server-log-capture.d.ts.map +1 -1
  518. package/lib/testing/playwright/server-log-capture.js +39 -6
  519. package/lib/testing/playwright/server-log-capture.js.map +1 -1
  520. package/lib/testing/playwright/server-log-fixture.d.ts +16 -0
  521. package/lib/testing/playwright/server-log-fixture.d.ts.map +1 -1
  522. package/lib/testing/playwright/server-log-fixture.js +25 -6
  523. package/lib/testing/playwright/server-log-fixture.js.map +1 -1
  524. package/lib/testing/playwright/server-log-region.d.ts +15 -0
  525. package/lib/testing/playwright/server-log-region.d.ts.map +1 -0
  526. package/lib/testing/playwright/server-log-region.js +30 -0
  527. package/lib/testing/playwright/server-log-region.js.map +1 -0
  528. package/lib/testing/playwright/server-log-rename-reporter.d.ts.map +1 -1
  529. package/lib/testing/playwright/server-log-rename-reporter.js +10 -1
  530. package/lib/testing/playwright/server-log-rename-reporter.js.map +1 -1
  531. package/lib/testing/run-update-pipeline.d.ts +6 -5
  532. package/lib/testing/run-update-pipeline.d.ts.map +1 -1
  533. package/lib/testing/run-update-pipeline.js.map +1 -1
  534. package/lib/testing/stub-ast-document-manager.d.ts +11 -52
  535. package/lib/testing/stub-ast-document-manager.d.ts.map +1 -1
  536. package/lib/testing/stub-ast-document-manager.js +24 -65
  537. package/lib/testing/stub-ast-document-manager.js.map +1 -1
  538. package/lib/testing/stub-document-builder.d.ts +33 -11
  539. package/lib/testing/stub-document-builder.d.ts.map +1 -1
  540. package/lib/testing/stub-document-builder.js +103 -5
  541. package/lib/testing/stub-document-builder.js.map +1 -1
  542. package/lib/testing/stub-hydranium-text-documents.d.ts +33 -10
  543. package/lib/testing/stub-hydranium-text-documents.d.ts.map +1 -1
  544. package/lib/testing/stub-hydranium-text-documents.js +115 -16
  545. package/lib/testing/stub-hydranium-text-documents.js.map +1 -1
  546. package/lib/testing/stub-index-manager.js.map +1 -1
  547. package/lib/testing/stub-langium-documents.d.ts +3 -2
  548. package/lib/testing/stub-langium-documents.d.ts.map +1 -1
  549. package/lib/testing/stub-langium-documents.js.map +1 -1
  550. package/lib/testing/stub-model-service.d.ts +9 -8
  551. package/lib/testing/stub-model-service.d.ts.map +1 -1
  552. package/lib/testing/stub-model-service.js +6 -6
  553. package/lib/testing/stub-model-service.js.map +1 -1
  554. package/lib/testing/stub-project-manager.js.map +1 -1
  555. package/lib/testing/stub-self-save-registry.d.ts +1 -1
  556. package/lib/testing/stub-self-save-registry.d.ts.map +1 -1
  557. package/lib/testing/stub-service-registry.d.ts +1 -1
  558. package/lib/testing/stub-service-registry.js.map +1 -1
  559. package/lib/testing/stub-writable-file-system.d.ts +1 -1
  560. package/lib/testing/stub-writable-file-system.d.ts.map +1 -1
  561. package/lib/testing/stub-writable-file-system.js +2 -1
  562. package/lib/testing/stub-writable-file-system.js.map +1 -1
  563. package/lib/util/connection-liveness.d.ts +19 -6
  564. package/lib/util/connection-liveness.d.ts.map +1 -1
  565. package/lib/util/connection-liveness.js +61 -15
  566. package/lib/util/connection-liveness.js.map +1 -1
  567. package/lib/util/environment.d.ts.map +1 -1
  568. package/lib/util/environment.js.map +1 -1
  569. package/lib/util/registry.d.ts.map +1 -1
  570. package/package.json +29 -53
  571. package/src/documents/ast-document-manager.ts +383 -231
  572. package/src/documents/client-ids.ts +5 -22
  573. package/src/documents/client-session-errors.ts +24 -0
  574. package/src/documents/client-session-registry.ts +262 -0
  575. package/src/documents/dirty-state-tracker.ts +140 -0
  576. package/src/documents/document-release-handler.ts +404 -0
  577. package/src/documents/document-release-scheduler.ts +121 -0
  578. package/src/documents/file-system-task-queue.ts +68 -0
  579. package/src/documents/hydranium-text-documents.ts +944 -595
  580. package/src/documents/index.ts +10 -2
  581. package/src/documents/language-client-shadow.ts +452 -0
  582. package/src/documents/model-ledger.ts +66 -0
  583. package/src/documents/text-ledger.ts +112 -0
  584. package/src/documents/version-sync-service.ts +275 -0
  585. package/src/index.ts +8 -0
  586. package/src/langium/ast-extension/ast-extension-service.ts +3 -0
  587. package/src/langium/ast-extension/ast-node-builder.ts +66 -22
  588. package/src/langium/bootstrap.ts +77 -37
  589. package/src/langium/build-phase-pass/build-phase-pass-service.ts +1 -1
  590. package/src/langium/build-phase-pass/build-phase-pass.ts +1 -1
  591. package/src/langium/composite-ast-reflection.ts +112 -0
  592. package/src/langium/config/configuration-provider.ts +119 -0
  593. package/src/langium/config/index.ts +1 -0
  594. package/src/langium/diagnostics/hydranium-langium-profiler.ts +15 -39
  595. package/src/langium/diagnostics/log-preamble.ts +1 -1
  596. package/src/langium/diagnostics/logger.ts +12 -5
  597. package/src/langium/diagnostics/lsp-logger.ts +61 -16
  598. package/src/langium/document-builder/build-pipeline-integration.ts +50 -5
  599. package/src/langium/document-builder/build-session.ts +4 -3
  600. package/src/langium/document-builder/document-builder.ts +616 -73
  601. package/src/langium/integration-services.ts +83 -24
  602. package/src/langium/integrity/integrity-rule.ts +16 -8
  603. package/src/langium/integrity/integrity-service.ts +296 -69
  604. package/src/langium/keys/containment.ts +87 -0
  605. package/src/langium/keys/index.ts +1 -0
  606. package/src/langium/keys/name-based-key-provider.ts +4 -0
  607. package/src/langium/language-module.ts +49 -8
  608. package/src/langium/model-service/client-session.ts +661 -0
  609. package/src/langium/model-service/index.ts +2 -0
  610. package/src/langium/model-service/model-events.ts +75 -0
  611. package/src/langium/model-service/model-service.ts +824 -471
  612. package/src/langium/module.ts +201 -66
  613. package/src/langium/naming/name-provider.ts +29 -7
  614. package/src/langium/naming/name-separator-validation.ts +25 -3
  615. package/src/langium/project/abstract-project-manager.ts +13 -5
  616. package/src/langium/project/project-change-event.ts +2 -2
  617. package/src/langium/residency/cst-residency-service.ts +50 -16
  618. package/src/langium/scope/fallback-scope.ts +38 -0
  619. package/src/langium/scope/hydranium-scope-computation.ts +45 -44
  620. package/src/langium/scope/hydranium-scope-provider.ts +89 -38
  621. package/src/langium/scope/index.ts +1 -0
  622. package/src/langium/scope/reference-candidate-provider.ts +6 -5
  623. package/src/langium/scope/scope-extension-service.ts +74 -59
  624. package/src/langium/scope/scoped-ast-node-description.ts +1 -3
  625. package/src/langium/serialization/abstract-serializer.ts +13 -32
  626. package/src/langium/serialization/serializer.ts +1 -1
  627. package/src/langium/service-registry.ts +41 -2
  628. package/src/langium/shared-services.ts +26 -6
  629. package/src/langium/single-langium-copy.ts +42 -0
  630. package/src/langium/transfer/transfer-encoder.ts +115 -47
  631. package/src/langium/trivia/comment-preserver.ts +1100 -0
  632. package/src/langium/trivia/document-ending-preserver.ts +55 -0
  633. package/src/langium/trivia/index.ts +14 -0
  634. package/src/langium/trivia/trivia-contribution.ts +39 -0
  635. package/src/langium/trivia/trivia-preserver.ts +54 -0
  636. package/src/langium/trivia/trivia-service.ts +99 -0
  637. package/src/langium/update-rewrite/update-rewrite-service.ts +1 -1
  638. package/src/langium/update-rewrite/update-rewrite.ts +1 -1
  639. package/src/langium/validation/document-validator.ts +528 -13
  640. package/src/langium/validation/validation-contribution-collector.ts +10 -1
  641. package/src/langium/workspace/document-uri-policy.ts +15 -10
  642. package/src/langium/workspace/file-not-found.ts +35 -0
  643. package/src/langium/workspace/file-system-provider.ts +221 -17
  644. package/src/langium/workspace/hydranium-langium-document-factory.ts +117 -0
  645. package/src/langium/workspace/hydranium-workspace-lock.ts +86 -2
  646. package/src/langium/workspace/hydranium-workspace-manager.ts +155 -16
  647. package/src/langium/workspace/in-memory-file-system-provider.ts +41 -20
  648. package/src/langium/workspace/index.ts +1 -0
  649. package/src/langium/workspace/initialize-workspace.ts +43 -5
  650. package/src/langium/workspace/langium-documents.ts +63 -5
  651. package/src/langium/workspace/persistent-file-system-provider.ts +3 -9
  652. package/src/langium/workspace/self-save-registry.ts +118 -0
  653. package/src/langium/workspace/virtual-document.ts +96 -19
  654. package/src/langium/workspace/write-lock-scope.ts +24 -11
  655. package/src/launcher/integrated-server.ts +3 -1
  656. package/src/locale/index.ts +10 -0
  657. package/src/locale/server-locale.ts +86 -0
  658. package/src/lsp/completion/hydranium-completion-provider.ts +82 -2
  659. package/src/lsp/connection-features.ts +67 -0
  660. package/src/lsp/diagnostics-connection.ts +56 -0
  661. package/src/lsp/hydranium-document-update-handler.ts +197 -110
  662. package/src/lsp/index.ts +3 -1
  663. package/src/lsp/lsp-latency.ts +62 -0
  664. package/src/lsp/semantic-token-provider.ts +74 -7
  665. package/src/lsp/shared-module.ts +4 -8
  666. package/src/lsp/start-language-server.ts +13 -7
  667. package/src/messages/carriers.ts +23 -15
  668. package/src/messages/index.ts +13 -1
  669. package/src/messages/renderer.ts +212 -0
  670. package/src/node/event-loop-monitor.ts +2 -1
  671. package/src/node/heap-ceiling.ts +108 -0
  672. package/src/node/index.ts +1 -1
  673. package/src/node/latency-from-env.ts +1 -1
  674. package/src/node/log-preamble-node.ts +20 -10
  675. package/src/node/measure-memory.ts +5 -4
  676. package/src/node/memory-monitor.ts +10 -10
  677. package/src/node/node-file-system-provider.ts +157 -56
  678. package/src/node/profile-capture.ts +16 -15
  679. package/src/node/profiling-run.ts +30 -8
  680. package/src/node/rename-over-open-readers.ts +94 -0
  681. package/src/node/server-diagnostics.ts +1 -1
  682. package/src/node/server-state-snapshot.ts +5 -5
  683. package/src/node/socket-launcher.ts +27 -11
  684. package/src/node/stdio-launcher.ts +18 -9
  685. package/src/testing/document-uri-policy-conformance.ts +1 -1
  686. package/src/testing/fake-document.ts +24 -5
  687. package/src/testing/index.ts +2 -1
  688. package/src/testing/langium-test-helpers.ts +1 -0
  689. package/src/testing/make-noop-shared-services.ts +50 -2
  690. package/src/testing/make-test-services.ts +125 -31
  691. package/src/testing/make-test-tracer.ts +26 -0
  692. package/src/testing/node/applied-edit-capture.ts +139 -0
  693. package/src/testing/node/index.ts +1 -0
  694. package/src/testing/node/lsp-harness.ts +2 -0
  695. package/src/testing/node/lsp-server-connection.ts +74 -117
  696. package/src/testing/node/scratch-workspace.ts +10 -5
  697. package/src/testing/node/spawned-server.ts +57 -3
  698. package/src/testing/node/unhandled-rejections.ts +31 -0
  699. package/src/testing/parse-semantic-root.ts +1 -1
  700. package/src/testing/playwright/flaky-network-proxy.ts +240 -0
  701. package/src/testing/playwright/index.ts +1 -0
  702. package/src/testing/playwright/server-log-capture.ts +63 -11
  703. package/src/testing/playwright/server-log-fixture.ts +46 -6
  704. package/src/testing/playwright/server-log-region.ts +32 -0
  705. package/src/testing/playwright/server-log-rename-reporter.ts +12 -1
  706. package/src/testing/run-update-pipeline.ts +6 -5
  707. package/src/testing/stub-ast-document-manager.ts +36 -138
  708. package/src/testing/stub-document-builder.ts +133 -18
  709. package/src/testing/stub-hydranium-text-documents.ts +165 -27
  710. package/src/testing/stub-langium-documents.ts +3 -2
  711. package/src/testing/stub-model-service.ts +11 -10
  712. package/src/testing/stub-self-save-registry.ts +1 -1
  713. package/src/testing/stub-service-registry.ts +1 -1
  714. package/src/testing/stub-writable-file-system.ts +3 -2
  715. package/src/util/connection-liveness.ts +67 -15
  716. package/src/util/environment.ts +9 -1
  717. package/lib/documents/language-client-text-shadow.d.ts +0 -101
  718. package/lib/documents/language-client-text-shadow.d.ts.map +0 -1
  719. package/lib/documents/language-client-text-shadow.js +0 -156
  720. package/lib/documents/language-client-text-shadow.js.map +0 -1
  721. package/lib/documents/self-save-registry.d.ts +0 -55
  722. package/lib/documents/self-save-registry.d.ts.map +0 -1
  723. package/lib/documents/self-save-registry.js.map +0 -1
  724. package/lib/lsp/instrument-connection.d.ts +0 -36
  725. package/lib/lsp/instrument-connection.d.ts.map +0 -1
  726. package/lib/lsp/instrument-connection.js +0 -62
  727. package/lib/lsp/instrument-connection.js.map +0 -1
  728. package/lib/node/process-memory.d.ts +0 -66
  729. package/lib/node/process-memory.d.ts.map +0 -1
  730. package/lib/node/process-memory.js +0 -252
  731. package/lib/node/process-memory.js.map +0 -1
  732. package/src/documents/language-client-text-shadow.ts +0 -175
  733. package/src/documents/self-save-registry.ts +0 -81
  734. package/src/lsp/instrument-connection.ts +0 -66
  735. package/src/node/process-memory.ts +0 -299
@@ -20,7 +20,7 @@
20
20
  // on lsp-server, contradicting the peer architecture.
21
21
  // eslint-disable-next-line @typescript-eslint/no-restricted-imports
22
22
  import { NormalizedTextDocuments } from '@hydranium/langium/lsp';
23
- import { UriUtils } from '@hydranium/langium';
23
+ import { type URI, UriUtils } from '@hydranium/langium';
24
24
  import { type ServerSharedServices } from '../langium/module.js';
25
25
  import {
26
26
  type ApplyWorkspaceEditResult,
@@ -31,7 +31,7 @@ import {
31
31
  type DidOpenTextDocumentParams,
32
32
  type DidSaveTextDocumentParams,
33
33
  type Disposable,
34
- type Emitter,
34
+ Emitter,
35
35
  type Event,
36
36
  type HandlerResult,
37
37
  OptionalVersionedTextDocumentIdentifier,
@@ -45,10 +45,33 @@ import {
45
45
  type WillSaveTextDocumentParams
46
46
  } from 'vscode-languageserver';
47
47
  import { type DocumentUri, TextDocument, type TextDocumentContentChangeEvent } from 'vscode-languageserver-textdocument';
48
- import { type CanonicalUri, type LanguageClientUri, asLanguageClientUri, DisposableCollection, type Tracer } from '@hydranium/protocol';
48
+ import {
49
+ type CanonicalUri,
50
+ type LanguageClientUri,
51
+ asLanguageClientUri,
52
+ DisposableCollection,
53
+ type TextState,
54
+ type TextVersion,
55
+ STALE_VERSION,
56
+ type Tracer,
57
+ UNRECORDED_VERSION,
58
+ describeError,
59
+ describeErrorWithStack
60
+ } from '@hydranium/protocol';
49
61
  import { type LogNameOptions } from '../langium/diagnostics/logger.js';
50
62
  import { LANGUAGE_CLIENT_ID } from './client-ids.js';
51
- import { isFullReplace, LanguageClientTextShadow } from './language-client-text-shadow.js';
63
+ import { INTEGRITY_CLIENT_ID } from '../langium/integrity/integrity-rule.js';
64
+ import { type ClientSessionClosedEvent, ClientSessionRegistry, type SessionEndCause } from './client-session-registry.js';
65
+ import { DefaultLanguageClientShadow, type LanguageClientChangeVerdict, type LanguageClientShadow } from './language-client-shadow.js';
66
+ import { DefaultTextLedger, type TextLedger } from './text-ledger.js';
67
+ import { isDocumentReleaseSkippedError, type ReleasedDocument } from './document-release-handler.js';
68
+ import { DefaultDocumentReleaseScheduler, type DocumentReleaseScheduler } from './document-release-scheduler.js';
69
+ import {
70
+ type CleanAnnouncement,
71
+ DefaultDirtyStateTracker,
72
+ type DirtyStateTracker,
73
+ type DocumentDirtyChangedEvent
74
+ } from './dirty-state-tracker.js';
52
75
 
53
76
  /**
54
77
  * The LSP spec's "version is intentionally unknown" for an
@@ -74,47 +97,39 @@ export interface HydraniumTextDocumentsOptions<T extends TextDocument = TextDocu
74
97
  * Adopters with a custom text-document type (rare) pass their factory.
75
98
  */
76
99
  readonly configuration?: TextDocumentsConfiguration<T>;
100
+ /**
101
+ * How long a document whose last open closed because its client's
102
+ * connection was lost keeps its text before the store releases it. An open
103
+ * by a client lost from the document, within this time of its own loss,
104
+ * cancels the release, so a client that registers again under its id after
105
+ * a dropped connection finds its unsaved edits. Any other open releases the
106
+ * document first and then opens it as a first open does, from the text the
107
+ * opener supplies (an editor's own) or else from the file. Meanwhile the
108
+ * document counts as open for the integrity service, which therefore writes
109
+ * none of its unsaved text to disk. A close the client makes itself, or
110
+ * ending its session, releases at once whatever this is.
111
+ *
112
+ * Defaults to 10 s. `0` releases such a document at once as well, in the
113
+ * close itself rather than on a timer.
114
+ */
115
+ readonly releaseGraceMs?: number;
77
116
  }
78
117
 
79
118
  /**
80
- * All per-URI client-facing tracking the manager keys by normalized URI,
81
- * collapsed into one record so a URI's full state lives in one place and the
82
- * last-client close clears every axis in a single delete. (Parallel per-axis
83
- * maps are the substrate of a close-on-stale-state desync — one map can be
84
- * cleared while another lingers.)
85
- *
86
- * Two neighbours deliberately stay separate:
87
- * - The inherited `__syncedDocuments` (Langium's parsed `TextDocument` store).
88
- * - {@link LanguageClientTextShadow} (`__shadow`), a self-contained,
89
- * separately-tested diff/apply-verify abstraction that owns its own baseline
90
- * text; folding its storage here would couple a clean utility to this record
91
- * for no real gain.
119
+ * The default of {@link HydraniumTextDocumentsOptions.releaseGraceMs}: long
120
+ * enough for a client whose connection dropped to register again and reopen
121
+ * its documents, which a data client does as soon as it has a connection.
92
122
  */
93
- interface DocumentTracking {
94
- /** Client ids currently holding this document open (multi-client membership). */
95
- readonly clients: Set<string>;
96
- /** Author of each version, sparse-indexed by the SHARED (server-assigned) version number. */
97
- readonly versionAuthors: string[];
98
- /**
99
- * Last version id each client declared for this document (didOpen baseline,
100
- * advanced by every accepted didChange). Client version ids are CLIENT-owned
101
- * per LSP (Monaco numbers its own buffer) and are used ONLY for this
102
- * per-client staleness guard — they never leak into the shared version
103
- * sequence, which the server assigns (see {@link HydraniumTextDocuments.__versionSequences}).
104
- */
105
- readonly clientVersions: Map<string, number>;
106
- /** Content staged by integrity rules for a closed document. Consumed on next open. */
107
- pendingContent?: string;
108
- /**
109
- * The URI(s) the LSP textual language client opened this (canonically-keyed)
110
- * document under. Usually one; a set because the same physical file can be
111
- * opened under more than one URI (a symlink path and its real path). This is
112
- * the egress address: `applyEditToLanguageClient`
113
- * targets these, since the document is *keyed* by its canonical identity but
114
- * Monaco holds it under the URI it opened. Lifecycle-bound — cleared with the
115
- * record on last close.
116
- */
117
- languageClientUris?: Set<LanguageClientUri>;
123
+ const DEFAULT_RELEASE_GRACE_MS = 10_000;
124
+
125
+ /** Delivered by {@link HydraniumTextDocuments.onDidSaveInLanguageClient}. */
126
+ export interface LanguageClientSavedEvent {
127
+ readonly uri: string;
128
+ }
129
+
130
+ /** Delivered by {@link HydraniumTextDocuments.onDidReleaseDocument}. */
131
+ export interface DocumentReleasedEvent {
132
+ readonly uri: CanonicalUri;
118
133
  }
119
134
 
120
135
  /**
@@ -129,25 +144,20 @@ export interface OpenDocument {
129
144
  }
130
145
 
131
146
  /**
132
- * Where a URI's shared version sequence left off — written once at last-client
133
- * close, consulted at the next open so the sequence CONTINUES instead of
134
- * restarting at whatever version id the reopening client declares. One entry
135
- * of {@link HydraniumTextDocuments.__versionSequences}.
136
- */
137
- interface VersionSequence {
138
- /** The shared version at last-client close. */
139
- readonly version: number;
140
- /** {@link contentHash} of the synced text at last-client close. */
141
- readonly contentHash: string;
142
- }
143
-
144
- /**
145
- * Upper bound on {@link HydraniumTextDocuments.__pendingPushes} entries
146
- * per URI. Echoes normally return within milliseconds and consume their
147
- * entry; a queue this deep means the client stopped echoing — cap instead
148
- * of leaking.
147
+ * What {@link HydraniumTextDocuments.commitRepair} did with an integrity repair.
148
+ *
149
+ * Three outcomes rather than a document-or-nothing, because the two ways of
150
+ * getting nothing call for opposite responses: `not-open` means there is no
151
+ * store document to correct and the caller carries on with the one it holds,
152
+ * while `stale` means there IS one and it has moved past the text the repair
153
+ * was computed against — so carrying on would persist a correction over an edit
154
+ * that superseded it. Collapsing them lets the second read as permission to
155
+ * proceed, which is the failure this shape exists to make unrepresentable.
149
156
  */
150
- const PENDING_ECHO_CAP = 32;
157
+ export type RepairCommit<T extends TextDocument> =
158
+ | { readonly status: 'committed'; readonly document: T }
159
+ | { readonly status: 'stale' }
160
+ | { readonly status: 'not-open' };
151
161
 
152
162
  /**
153
163
  * The one field of `vscode-languageserver`'s `Connection` this class has to
@@ -159,182 +169,137 @@ interface ConnectionWithTextDocumentSync {
159
169
  }
160
170
 
161
171
  /**
162
- * One text pushed to the LSP textual language client by
163
- * {@link HydraniumTextDocuments.applyEditToLanguageClient} whose echo has not
164
- * come back yet. One entry of {@link HydraniumTextDocuments.__pendingPushes}.
165
- */
166
- interface PendingPush {
167
- /**
168
- * The text the client held BEFORE this push — the shadow baseline the
169
- * push's edits were diffed against, and therefore the text the client's
170
- * echo addresses with its ranges.
171
- *
172
- * `undefined` when the push was a full replace sent with no baseline (a
173
- * first sync, or the recovery push after a rejection). There is then no
174
- * knowing what the client held, so the echo is reconstructed against the
175
- * synced text instead — which is sound for a full replace, whose
176
- * application is position-independent.
177
- */
178
- readonly before: string | undefined;
179
- /** {@link contentHash} of the text this push moves the client to. */
180
- readonly afterHash: string;
181
- }
182
-
183
- /**
184
- * What an incoming language-client change turns out to be once reconstructed
185
- * against the pushes still in flight — the return of
186
- * {@link HydraniumTextDocuments.classifyLanguageClientChange}.
187
- */
188
- type LanguageClientChangeOrigin =
189
- /** The client is reporting a text we pushed it. The synced document is already there. */
190
- | { readonly kind: 'echo' }
191
- /**
192
- * The client's buffer has moved somewhere we did not push it — it coalesced
193
- * a genuine keystroke into the echo, or typed before the push arrived. The
194
- * reconstructed text is what it now holds, and is authoritative.
195
- */
196
- | { readonly kind: 'divergent'; readonly text: string };
197
-
198
- /**
199
- * Cheap, stable, non-cryptographic content hash (cyrb53) for the version
200
- * sequence's "did the content change across close/reopen?" question. Only
201
- * needs to be collision-resistant enough that an accidental match across two
202
- * DIFFERENT revisions of the same file is practically impossible; 53 bits of
203
- * a well-mixed hash over full text + length gives that without pulling in
204
- * `node:crypto` (this module must stay runnable in browser hosts).
205
- */
206
- function contentHash(text: string): string {
207
- let h1 = 0xdeadbeef;
208
- let h2 = 0x41c6ce57;
209
- for (let index = 0; index < text.length; index++) {
210
- const code = text.charCodeAt(index);
211
- h1 = Math.imul(h1 ^ code, 2654435761);
212
- h2 = Math.imul(h2 ^ code, 1597334677);
213
- }
214
- h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
215
- h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
216
- h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
217
- h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
218
- return `${(4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36)}:${text.length}`;
219
- }
220
-
221
- /**
222
- * Multi-client text-document tracking on top of Langium's `NormalizedTextDocuments`.
172
+ * The one text store every head writes to, on top of Langium's
173
+ * `NormalizedTextDocuments`, and the LSP text-sync endpoint: every
174
+ * `textDocument/*` notification and every `workspace/applyEdit` push goes
175
+ * through here.
223
176
  *
224
- * Adds the framework features used by the integrity, model-server, and GLSP layers:
225
- * - Per-document client membership (multiple clients can attach to the same URI).
226
- * - A SERVER-OWNED shared version sequence: per-URI, monotonic across
227
- * close/reopen cycles, advancing exactly when the synced content changes.
228
- * Client-declared version ids (Monaco's buffer numbering) feed only a
229
- * per-client staleness guard and never leak into the shared sequence —
230
- * the two are different things (an editor's edit-operation counter vs the
231
- * document's content-revision number), and splicing them lets versions drift
232
- * silently past `baseVersion` gate holders.
233
- * - Version-author history so each edit is attributable to its originating client.
234
- * - Pending-content staging used by the integrity service to thread corrections
235
- * through `workspace/applyEdit` cycles for currently-closed documents.
236
- * - `didOpen` notifications arriving over the LSP connection wait on the
237
- * workspace-ready promise, so a client's first open cannot race workspace
238
- * discovery. Direct {@link notifyDidOpenTextDocument} calls (the non-LSP
239
- * heads) do not pass that gate — their caller owns the ordering.
177
+ * Each open, change, close and save is one synchronous transition over the
178
+ * held document and the collaborators its `create…` methods build. A
179
+ * collaborator that defers its part lets a listener of the transition's event
180
+ * read state from before it. A document no client holds any more is
181
+ * released to the `DocumentReleaseHandler` slot, after
182
+ * {@link HydraniumTextDocumentsOptions.releaseGraceMs} when its last client's
183
+ * connection was lost.
184
+ *
185
+ * Client-declared version ids feed only the per-client staleness guard and
186
+ * never a running shared sequence: the two count different things, and
187
+ * splicing them lets versions drift past base-version gate holders. A URI
188
+ * with no ledger record and no built root starts at its opener's declared id:
189
+ * no version was handed out for it.
190
+ *
191
+ * `didOpen` notifications arriving over the LSP connection wait on the
192
+ * workspace-ready promise, so a client's first open cannot race workspace
193
+ * discovery. Direct {@link notifyDidOpenTextDocument} calls (the non-LSP
194
+ * heads) do not pass that gate — their caller owns the ordering.
240
195
  */
241
196
  export class HydraniumTextDocuments<T extends TextDocument = TextDocument> extends NormalizedTextDocuments<T> {
242
- /**
243
- * Per-URI client-facing tracking ({@link DocumentTracking}): client
244
- * membership, version-author history, and integrity-staged pending content,
245
- * keyed by normalized URI. One record per URI so the last-client close clears
246
- * every axis atomically. The language-client diff baseline stays in
247
- * {@link __shadow} (its own abstraction); the parsed-document store stays in
248
- * the inherited `__syncedDocuments`.
249
- */
250
- protected __documents = new Map<CanonicalUri, DocumentTracking>();
197
+ /** Content staged by integrity rules for a document no client holds, consumed by its first open. */
198
+ protected readonly __pendingContent = new Map<CanonicalUri, string>();
251
199
 
252
200
  /**
253
- * Per-URI shared-version continuity across close/reopen cycles
254
- * ({@link VersionSequence}), written at last-client close and consulted by
255
- * the next first-client open. DELIBERATELY outside {@link DocumentTracking}:
256
- * that record is deleted on last close, while the version sequence must
257
- * survive it — the shared version is a server-owned, monotonic,
258
- * advances-iff-content-changes counter that never resets while the server
259
- * lives. That invariant is what makes an optimistic `baseVersion` gate
260
- * sound: "version unchanged ⇔ content unchanged", with no false conflicts
261
- * from close/reopen version resets and no false passes from a reopened
262
- * sequence coincidentally landing on a stale writer's number.
263
- *
264
- * Never pruned: two small values per URI ever touched — bounded by
265
- * workspace size, not by activity.
201
+ * Which client has which document open, which client ids are registered
202
+ * sessions, and each client's declared version, the staleness guard's
203
+ * baseline. Every open-state predicate on this class reads it, so an open
204
+ * recorded anywhere else is invisible to the last-close transition.
266
205
  */
267
- protected readonly __versionSequences = new Map<CanonicalUri, VersionSequence>();
206
+ protected readonly __sessions = new ClientSessionRegistry();
268
207
 
269
- /**
270
- * Texts pushed to the LSP textual language client via
271
- * {@link applyEditToLanguageClient} whose echoes have not come back yet
272
- * ({@link PendingPush}), keyed like the shadow by language-client URI.
273
- * Outbound pushes and inbound echoes are uncorrelated on the wire; this
274
- * FIFO is the explicit correlation, and it is what
275
- * {@link classifyLanguageClientChange} reconstructs against.
276
- *
277
- * **Each entry keeps the client's PRE-push text, not only a hash of the
278
- * post-push one.** A hash alone can classify a full-text echo, whose
279
- * application is a no-op either way — and that is all it ever classified,
280
- * because a conforming client echoes INCREMENTAL ranges keyed to its
281
- * previous buffer. Those ranges cannot be applied to the synced text (which
282
- * the authored write already advanced) and cannot be reconstructed without
283
- * the baseline: the line they insert lands twice, validates cleanly, and
284
- * compounds on every later edit.
285
- *
286
- * Lifecycle: entries are consumed by the matching echo (together with any
287
- * older entries it supersedes), and the whole queue drops when the client
288
- * stops being a pure mirror — a divergent change, an `applyEdit`
289
- * failure/rejection (shadow invalidation), a close, or an explicit
290
- * shadow (re)baseline. {@link PENDING_ECHO_CAP} bounds the queue against
291
- * a pathological echo that never arrives; the memory cost until then is
292
- * one pre-push text per in-flight push, for milliseconds.
293
- */
294
- protected readonly __pendingPushes = new Map<LanguageClientUri, PendingPush[]>();
295
-
296
- /**
297
- * Tracked text content per URI for the LSP textual language client (Monaco / VS Code).
298
- * Owned here so {@link applyEditToLanguageClient} can compute minimal `workspace/applyEdit`
299
- * diffs instead of full-document replaces (5–20 s → <500 ms on 20-30 KB YAML diagrams).
300
- *
301
- * Auto-tracked from the multi-client text-document events: open / change / close of
302
- * the language client (re)baseline or invalidate the shadow. Other client ids
303
- * (form editor, GLSP, integrity) do NOT touch the shadow — only what Monaco believes
304
- * it has matters for the diff.
305
- *
306
- * Apply-verify safety net is built in: if the diff doesn't reconstruct `newText`
307
- * exactly, {@link LanguageClientTextShadow.computeEdits} falls back to a full-range
308
- * replace and invokes the `onFallback` callback — a diff regression becomes log
309
- * noise, not a 0-byte save.
310
- *
311
- * Assigned in the constructor body so the `onFallback` callback can capture
312
- * `this.logger` after the parameter-property assignment has run (field
313
- * initializers fire BEFORE parameter-property assignment in TS).
314
- */
315
- protected readonly __shadow: LanguageClientTextShadow;
208
+ /** The version each open document was opened at; see {@link openedVersion}. */
209
+ protected readonly __openedVersions = new Map<CanonicalUri, TextVersion>();
316
210
 
317
211
  protected readonly tracer: Tracer;
318
212
  protected readonly configuration: TextDocumentsConfiguration<T>;
213
+ protected __textLedger: TextLedger | undefined;
214
+ protected __languageClientShadow: LanguageClientShadow | undefined;
215
+ protected __dirtyStateTracker: DirtyStateTracker | undefined;
216
+ protected __documentReleaseScheduler: DocumentReleaseScheduler | undefined;
217
+ protected readonly documentReleasedEmitter = new Emitter<DocumentReleasedEvent>();
218
+ protected readonly languageClientSavedEmitter = new Emitter<LanguageClientSavedEvent>();
319
219
 
320
220
  constructor(
321
221
  protected services: ServerSharedServices,
322
- options: HydraniumTextDocumentsOptions<T> = {}
222
+ protected readonly options: HydraniumTextDocumentsOptions<T> = {}
323
223
  ) {
324
224
  const configuration = options.configuration ?? (TextDocument as unknown as TextDocumentsConfiguration<T>);
325
225
  super(configuration);
326
226
  this.configuration = configuration;
327
227
  this.tracer = services.Tracer.for(options.logName ?? 'TextDocuments').trace('instantiated');
328
- this.__shadow = new LanguageClientTextShadow(
329
- (uri, reason) => this.tracer.with(uri).warn(`Diff apply-verify fallback (${reason}) — using full-document replace`),
330
- this
331
- );
332
228
  }
333
229
 
334
- // Re-exposed configuration factories — for framework-internal callers
335
- // (LanguageClientTextShadow's apply-verify probe; IntegrityService.resyncDocument)
336
- // that need to materialise documents outside the canonical didOpen/didChange flow
337
- // and must respect the adopter's custom text-document type.
230
+ // Each collaborator is built on first use, after every constructor has run,
231
+ // so a create method may read its subclass's fields and the other collaborators.
232
+
233
+ protected get textLedger(): TextLedger {
234
+ return (this.__textLedger ??= this.createTextLedger());
235
+ }
236
+
237
+ protected get languageClientShadow(): LanguageClientShadow {
238
+ return (this.__languageClientShadow ??= this.createLanguageClientShadow());
239
+ }
240
+
241
+ protected get dirtyStateTracker(): DirtyStateTracker {
242
+ return (this.__dirtyStateTracker ??= this.createDirtyStateTracker());
243
+ }
244
+
245
+ protected get documentReleaseScheduler(): DocumentReleaseScheduler {
246
+ return (this.__documentReleaseScheduler ??= this.createDocumentReleaseScheduler());
247
+ }
248
+
249
+ protected createTextLedger(): TextLedger {
250
+ return new DefaultTextLedger();
251
+ }
252
+
253
+ protected createLanguageClientShadow(): LanguageClientShadow {
254
+ return new DefaultLanguageClientShadow(this, this.tracer);
255
+ }
256
+
257
+ protected createDirtyStateTracker(): DirtyStateTracker {
258
+ return new DefaultDirtyStateTracker(this.textLedger);
259
+ }
260
+
261
+ protected createDocumentReleaseScheduler(): DocumentReleaseScheduler {
262
+ return new DefaultDocumentReleaseScheduler(this.services.Clock, this.options.releaseGraceMs ?? DEFAULT_RELEASE_GRACE_MS);
263
+ }
264
+
265
+ /** Hold `document` as the text of `key`, a new version authored by `author`. */
266
+ protected commitText(key: CanonicalUri, document: T, author: string): void {
267
+ this.__syncedDocuments.set(key, document);
268
+ this.setAuthor(key, document.version, author);
269
+ this.dirtyStateTracker.refreshDirty(key, document);
270
+ }
271
+
272
+ /**
273
+ * Apply `changes` to `document`, the held text of `key`, and hold the
274
+ * result. The version steps only when the text changes, which is what a
275
+ * base-version gate relies on: unchanged text keeps its version and its
276
+ * author. The new text is known only once the changes are applied, so they
277
+ * go in at a tentative step that an identical result rolls back.
278
+ */
279
+ protected commitChange(
280
+ key: CanonicalUri,
281
+ document: T,
282
+ changes: TextDocumentContentChangeEvent[],
283
+ author: string
284
+ ): { document: T; changed: boolean } {
285
+ const previousText = document.getText();
286
+ const version = document.version;
287
+ let next = this.update(document, changes, version + 1);
288
+ const changed = next.getText() !== previousText;
289
+ if (changed) {
290
+ this.commitText(key, next, author);
291
+ } else {
292
+ // An empty-changes update only re-stamps the version.
293
+ next = this.update(next, [], version);
294
+ this.__syncedDocuments.set(key, next);
295
+ }
296
+ return { document: next, changed };
297
+ }
298
+
299
+ // The configuration's factories. Every document the store makes or changes
300
+ // goes through them, so an override sees each call: the store's own writes,
301
+ // callers outside the didOpen/didChange flow, and the shadow's throwaway
302
+ // probes, at version 0 under a client URI.
338
303
 
339
304
  public create(uri: string, languageId: string, version: number, content: string): T {
340
305
  return this.configuration.create(uri, languageId, version, content);
@@ -403,7 +368,7 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
403
368
  const disposables = new DisposableCollection();
404
369
  disposables.push(
405
370
  connection.onDidOpenTextDocument(async (event: DidOpenTextDocumentParams) => {
406
- await this.services.workspace.WorkspaceManager.workspaceInitialized;
371
+ await this.initialBuildFinished();
407
372
  this.notifyDidOpenTextDocument(event);
408
373
  })
409
374
  );
@@ -429,7 +394,7 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
429
394
  );
430
395
  disposables.push(
431
396
  connection.onDidSaveTextDocument((event: DidSaveTextDocumentParams) => {
432
- this.notifyDidSaveTextDocument(event);
397
+ void this.notifyLanguageClientSave(event);
433
398
  })
434
399
  );
435
400
  return disposables;
@@ -450,84 +415,66 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
450
415
  const uri = this.documentKey(td.uri);
451
416
  let document = this.__syncedDocuments.get(uri);
452
417
  if (document !== undefined) {
453
- // Per-client staleness guard: client version ids are CLIENT-owned per
454
- // LSP (Monaco numbers its own buffer), so an incoming id is compared
455
- // against THAT client's last declared id — never against the shared
456
- // version, which the server assigns and which routinely runs ahead of
457
- // a client's ids (authored ModelService writes advance it without the
458
- // client knowing). Gating on the shared version drops real edits in
459
- // exactly that lag window. A client with no baseline (never opened —
460
- // a protocol anomaly) falls back to the shared-version compare, the
461
- // conservative answer.
462
- const record = this.trackingFor(uri);
463
- const lastSeen = record.clientVersions.get(clientId) ?? document.version;
418
+ // Client version ids are the client's own, so compared against what
419
+ // that client declared, never against the shared version: an authored
420
+ // write advances that without the client knowing, and gating on it
421
+ // drops real edits. The editor is checked per URI, since each is its
422
+ // own buffer; its client-wide entry is only the fallback for a URI it
423
+ // never opened, and may name another URI's buffer. A client with no
424
+ // baseline falls back to the shared version.
425
+ const clientUri = this.toLanguageClientUri(td.uri);
426
+ const editor = clientId === LANGUAGE_CLIENT_ID;
427
+ const lastSeen =
428
+ (editor ? this.languageClientShadow.declaredVersion(uri, clientUri) : undefined) ??
429
+ this.__sessions.clientVersionOf(uri, clientId) ??
430
+ document.version;
464
431
  if (lastSeen >= td.version) {
465
432
  // Distinguish "already at this version" (common: an echo from the client that triggered
466
433
  // the update) from "incoming version older than ours" (stale race).
467
434
  const reason =
468
435
  lastSeen === td.version ? `already at version ${lastSeen}` : `incoming version ${td.version} older than current ${lastSeen}`;
469
- this.logUri(uri, `Ignore update by ${clientId}: ${reason}`, 'debug');
436
+ this.logUri(uri, `Ignore update by ${this.formatClientId(clientId)}: ${reason}`, 'debug');
470
437
  return;
471
438
  }
472
- record.clientVersions.set(clientId, td.version);
473
-
474
- // A language-client change arriving while one of our own pushes is in
475
- // flight is keyed to the buffer the client held BEFORE that push, NOT
476
- // to the synced text — the authored write already advanced the latter.
477
- // Resolve which it is, and against what, before touching anything.
478
- const inFlight =
479
- clientId === LANGUAGE_CLIENT_ID
480
- ? this.classifyLanguageClientChange(this.toLanguageClientUri(td.uri), document, changes)
481
- : undefined;
482
- if (inFlight?.kind === 'echo') {
483
- // The client is reporting a text we pushed it, so the synced
484
- // document is ALREADY there and the changes must not be applied a
485
- // second time. Nothing is minted and no rebuild fires. The
486
- // per-client baseline advanced above (the client's ids keep
487
- // counting); the shadow is deliberately NOT touched — it
488
- // optimistically tracks the NEWEST pushed text, and dragging it
489
- // back would make the next outbound diff wrong against what the
490
- // client actually holds.
439
+ this.__sessions.setClientVersion(uri, clientId, td.version);
440
+
441
+ // An editor change is keyed to the buffer the editor holds, which is
442
+ // the synced text only while the two agree — an authored write
443
+ // advances the synced text without the editor knowing, and a push in
444
+ // flight moves the editor without the store knowing.
445
+ const verdict: LanguageClientChangeVerdict = editor
446
+ ? this.languageClientShadow.acceptChange(uri, clientUri, td.version, document, changes)
447
+ : { kind: 'direct' };
448
+ if (verdict.kind === 'echo') {
449
+ // The synced document is already there, so the changes must not be
450
+ // applied a second time: nothing is minted and no rebuild fires. The
451
+ // shadow keeps the newest pushed text, which is what the next
452
+ // outbound diff has to be keyed to.
491
453
  this.logUri(uri, `Skip rebuild: echo of a server-authored push (client version ${td.version})`, 'debug');
492
454
  return;
493
455
  }
494
456
 
495
- // The SHARED version advances iff the content actually changes — the
496
- // invariant optimistic `baseVersion` gates rely on. The new text is
497
- // only known after applying the (possibly incremental) changes, so
498
- // apply at a tentative +1 and roll the version back on an identical
499
- // result (an empty-changes update only re-stamps the version).
500
- //
501
- // A divergent in-flight change is applied as its RECONSTRUCTED text
502
- // rather than as its own ranges: the ranges address the pre-push
503
- // baseline, so applying them here would splice the wrong lines.
504
- const previousText = document.getText();
505
- const sharedVersion = document.version;
506
- document = this.configuration.update(document, inFlight === undefined ? changes : [{ text: inFlight.text }], sharedVersion + 1);
507
- const changed = document.getText() !== previousText;
508
- if (!changed) {
509
- document = this.configuration.update(document, [], sharedVersion);
510
- }
511
- this.__syncedDocuments.set(uri, document);
512
- if (changed) {
513
- this.setAuthor(uri, document.version, clientId);
514
- }
515
- if (clientId === LANGUAGE_CLIENT_ID) {
516
- // Monaco just told us about its new content; record it so the next outbound
517
- // applyEditToLanguageClient diffs against the right baseline. Keyed by the
518
- // language-client URI (what Monaco holds), not the canonical document key.
519
- this.__shadow.set(this.toLanguageClientUri(td.uri), document.getText());
520
- // Content-identical echo: the language client is echoing text we already had
521
- // (e.g. Monaco re-emitting a server-pushed applyEditToLanguageClient). The model is
522
- // unchanged, so skip the rebuild. The per-client baseline + shadow still advanced
523
- // above so future staleness checks and diffs are correct. Restricted to the
524
- // language client: a ModelService-authored change is never skipped.
525
- if (!changed) {
457
+ // A divergent change is applied as its reconstructed text rather than
458
+ // as its own ranges: those ranges address the editor's own buffer, so
459
+ // applying them here would splice the wrong lines.
460
+ const committed = this.commitChange(uri, document, verdict.kind === 'direct' ? changes : [{ text: verdict.text }], clientId);
461
+ document = committed.document;
462
+ if (editor) {
463
+ this.languageClientShadow.setLanguageClientText(clientUri, document.getText());
464
+ // Content-identical echo: the editor is echoing text we already had.
465
+ // The model is unchanged, so skip the rebuild. Restricted to the
466
+ // editor: a ModelService-authored change is never skipped.
467
+ if (!committed.changed) {
526
468
  this.logUri(uri, `Skip rebuild: content unchanged (echo at client version ${td.version})`, 'debug');
527
469
  return;
528
470
  }
529
471
  }
530
- this.log(document.uri, `Update to version ${document.version} by ${clientId}${changed ? '' : ' (content unchanged)'}`);
472
+ // Diagnosis: one comes with every keystroke.
473
+ this.logUri(
474
+ document.uri,
475
+ `Update to version ${document.version} by ${this.formatClientId(clientId)}${committed.changed ? '' : ' (content unchanged)'}`,
476
+ 'debug'
477
+ );
531
478
  this.__onDidChangeContent.fire(Object.freeze({ document, clientId }));
532
479
  }
533
480
  }
@@ -544,73 +491,183 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
544
491
  * A content-identical write still fires the change event (rebuild): the
545
492
  * authored write's server-side rebuild is correctness-bearing, it just
546
493
  * mints no new version — nothing observable changed, so watchers'
547
- * `baseVersion` pointers stay valid.
494
+ * base versions stay valid.
548
495
  *
549
496
  * Returns the resulting shared version. Throws when the document is not
550
497
  * open — callers (`AstDocumentManager.update`) open first.
551
498
  */
552
- applyContentChange(uri: DocumentUri, text: string, clientId: string): number {
499
+ applyContentChange(uri: DocumentUri, text: string, clientId: string): TextVersion {
553
500
  const key = this.documentKey(uri);
554
- let document = this.__syncedDocuments.get(key);
555
- if (document === undefined) {
501
+ const synced = this.__syncedDocuments.get(key);
502
+ if (synced === undefined) {
556
503
  throw new Error(`Document ${uri} is not open for content changes`);
557
504
  }
558
- const changed = document.getText() !== text;
559
- if (changed) {
560
- document = this.configuration.update(document, [{ text }], document.version + 1);
561
- this.__syncedDocuments.set(key, document);
562
- this.setAuthor(key, document.version, clientId);
563
- }
564
- this.log(document.uri, `Update to version ${document.version} by ${clientId}${changed ? '' : ' (content unchanged)'}`);
505
+ // Unchanged text calls no update: a configuration may return a new document for one.
506
+ const { document, changed } =
507
+ synced.getText() === text ? { document: synced, changed: false } : this.commitChange(key, synced, [{ text }], clientId);
508
+ this.logUri(
509
+ document.uri,
510
+ `Update to version ${document.version} by ${this.formatClientId(clientId)}${changed ? '' : ' (content unchanged)'}`,
511
+ 'debug'
512
+ );
565
513
  this.__onDidChangeContent.fire(Object.freeze({ document, clientId }));
566
514
  return document.version;
567
515
  }
568
516
 
569
- public notifyDidCloseTextDocument(event: DidCloseTextDocumentParams, clientId = LANGUAGE_CLIENT_ID): void {
517
+ /**
518
+ * Close `clientId`'s open of the document. When it was the last open, the
519
+ * document is released, at once or, for a `'lost'`
520
+ * close, after {@link HydraniumTextDocumentsOptions.releaseGraceMs}.
521
+ */
522
+ public notifyDidCloseTextDocument(
523
+ event: DidCloseTextDocumentParams,
524
+ clientId = LANGUAGE_CLIENT_ID,
525
+ cause: SessionEndCause = 'closed'
526
+ ): void {
570
527
  const uri = this.documentKey(event.textDocument.uri);
571
- if (!this.isOpenInClient(uri, clientId)) {
528
+ if (clientId === LANGUAGE_CLIENT_ID) {
529
+ const clientUri = this.toLanguageClientUri(event.textDocument.uri);
530
+ // A close under a URI the editor never opened the document under ends its hold.
531
+ if (this.languageClientShadow.isOpen(uri, clientUri)) {
532
+ this.languageClientShadow.removeOpen(uri, clientUri);
533
+ } else {
534
+ this.languageClientShadow.removeAllOpens(uri);
535
+ }
536
+ // Another URI still holds the document, so only this one's buffer goes.
537
+ if (this.languageClientShadow.isOpen(uri)) {
538
+ return;
539
+ }
540
+ }
541
+ if (!this.__sessions.removeOpen(uri, clientId)) {
572
542
  return;
573
543
  }
574
- const closingRecord = this.__documents.get(uri);
575
- closingRecord?.clients.delete(clientId);
576
- closingRecord?.clientVersions.delete(clientId);
544
+ if (cause === 'lost') {
545
+ this.documentReleaseScheduler.recordLoss(uri, clientId);
546
+ }
577
547
  const syncedDocument = this.__syncedDocuments.get(uri);
578
548
  if (syncedDocument !== undefined) {
579
- this.log(syncedDocument.uri, `Closed synced document: ${syncedDocument.version} by ${clientId}`);
549
+ this.log(syncedDocument.uri, `Closed synced document: ${syncedDocument.version} by ${this.formatClientId(clientId)}`);
580
550
  this.__onDidClose.fire(Object.freeze({ document: syncedDocument, clientId }));
581
-
582
- if (clientId === LANGUAGE_CLIENT_ID) {
583
- // Monaco closed the document; drop the URI it held and the shadow
584
- // baselined under it. (If this was the last URI/client the whole record
585
- // is deleted below, clearing the set anyway.)
586
- const droppedUri = this.toLanguageClientUri(event.textDocument.uri);
587
- this.__documents.get(uri)?.languageClientUris?.delete(droppedUri);
588
- this.__shadow.invalidate(droppedUri);
589
- this.__pendingPushes.delete(droppedUri);
551
+ if (!this.isOpenInAnyClient(uri)) {
552
+ if (cause === 'lost') {
553
+ this.deferRelease(uri);
554
+ } else {
555
+ this.releaseDocument(uri);
556
+ }
590
557
  }
591
- if (!this.__documents.get(uri)?.clients.size) {
592
- // Last client closed the document; delete sync state. The downstream
593
- // "rebuild from disk for file URIs / drop from index for ephemeral
594
- // URIs" decision lives in `HydraniumDocumentUpdateHandler.didCloseDocument`,
595
- // which subscribes to `onDidClose` and consults `isOpenInAnyClient`
596
- // to detect the last-close transition.
597
- this.log(syncedDocument.uri, `Remove synced document: ${syncedDocument.version} (no client left)`);
598
- // Persist where the shared version sequence left off (version +
599
- // content hash) so the next open CONTINUES the sequence instead of
600
- // restarting at the reopening client's declared id. Hashed once
601
- // here at close, not on every change.
602
- this.__versionSequences.set(uri, {
603
- version: syncedDocument.version,
604
- contentHash: contentHash(syncedDocument.getText())
605
- });
606
- this.__syncedDocuments.delete(uri);
607
- // One delete clears every per-URI axis (version history + any staged
608
- // pending content) so a future open with the same URI starts fresh.
609
- this.__documents.delete(uri);
558
+ }
559
+ }
560
+
561
+ /**
562
+ * Keep the document, text and all, for the release grace, then release it.
563
+ * The document stays in the store meanwhile, so a lost client that opens it
564
+ * again within its own grace attaches to it and finds its unsaved text
565
+ * rather than reading disk; see {@link resolveDeferredRelease} for any other
566
+ * open.
567
+ */
568
+ protected deferRelease(uri: CanonicalUri): void {
569
+ this.documentReleaseScheduler.defer(uri, () => {
570
+ if (!this.isOpenInAnyClient(uri)) {
571
+ this.releaseDocument(uri);
610
572
  }
573
+ });
574
+ if (this.documentReleaseScheduler.isDeferred(uri)) {
575
+ this.log(uri, `No client left; release deferred for ${this.documentReleaseScheduler.graceMs} ms (connection lost)`);
576
+ }
577
+ }
578
+
579
+ /** Resolve a deferred release of `uri` for an open by `clientId`: a release the scheduler decides on runs now. */
580
+ protected resolveDeferredRelease(uri: CanonicalUri, clientId: string): void {
581
+ if (this.documentReleaseScheduler.resolveOpen(uri, clientId) === 'release') {
582
+ this.releaseDocument(uri);
611
583
  }
612
584
  }
613
585
 
586
+ /**
587
+ * Drop the document no client has open any more, announce it on
588
+ * {@link onDidReleaseDocument}, then hand it to the
589
+ * `DocumentReleaseHandler` slot: its listeners, such as the update
590
+ * handler dropping a change it still holds back, act before any build the
591
+ * handler runs.
592
+ */
593
+ protected releaseDocument(uri: CanonicalUri): void {
594
+ const syncedDocument = this.__syncedDocuments.get(uri);
595
+ if (syncedDocument === undefined) {
596
+ return;
597
+ }
598
+ this.log(syncedDocument.uri, `Remove synced document: ${syncedDocument.version} (no client left)`);
599
+ // The next open continues the sequence instead of restarting at the
600
+ // reopening client's declared id.
601
+ this.textLedger.record(uri, syncedDocument);
602
+ this.textLedger.clearAuthors(uri);
603
+ // Before the tracker's release, which forgets whether a file was behind it.
604
+ const released = this.toReleasedDocument(uri);
605
+ const cleanAnnouncement = this.dirtyStateTracker.release(uri);
606
+ this.__syncedDocuments.delete(uri);
607
+ this.__openedVersions.delete(uri);
608
+ this.__sessions.forgetClientVersions(uri);
609
+ // A stage is for a first open; one released unconsumed is stale.
610
+ this.__pendingContent.delete(uri);
611
+ this.documentReleaseScheduler.clearLosses(uri);
612
+ this.documentReleasedEmitter.fire(Object.freeze({ uri }));
613
+ this.handOverRelease(released, cleanAnnouncement);
614
+ }
615
+
616
+ /**
617
+ * Call the `DocumentReleaseHandler` slot, and announce a document released
618
+ * dirty clean once the promise it returns settles, which is after the
619
+ * release event. A failure is logged rather than thrown: the store has let
620
+ * go of the document by now, and a throw would abort the transition that
621
+ * released it, a session's close of its other documents included.
622
+ */
623
+ protected handOverRelease(released: ReleasedDocument, cleanAnnouncement: CleanAnnouncement | undefined): void {
624
+ let settled: Promise<void>;
625
+ try {
626
+ // Read here: a lazily built slot whose factory throws throws on this read.
627
+ const handler = this.services.workspace.DocumentReleaseHandler;
628
+ settled =
629
+ handler === undefined
630
+ ? Promise.reject(new Error('no workspace.DocumentReleaseHandler bound'))
631
+ : Promise.resolve(handler.didReleaseDocument(released));
632
+ } catch (err: unknown) {
633
+ settled = Promise.reject(err);
634
+ }
635
+ // Names the text the build holds at the settle, so it follows anything a
636
+ // release listener did meanwhile: none when its build failed or it no
637
+ // longer has the document, since a removal leaves the record on the
638
+ // discarded text.
639
+ const announceClean = (built: boolean): void => {
640
+ if (cleanAnnouncement?.isOwed()) {
641
+ const inBuild = built && this.services.workspace.LangiumDocuments.getDocument(UriUtils.toUri(released.uri)) !== undefined;
642
+ cleanAnnouncement.announce(inBuild ? this.textState(released.uri) : undefined);
643
+ }
644
+ };
645
+ settled.then(
646
+ () => announceClean(true),
647
+ (err: unknown) => {
648
+ // A release skipped at teardown, its peer or its workspace gone, is
649
+ // routine, not a fault to investigate.
650
+ if (isDocumentReleaseSkippedError(err)) {
651
+ this.tracer.with(released.uri).debug(err.message);
652
+ } else {
653
+ this.tracer.with(released.uri).error(`Release handler failed. ${describeErrorWithStack(err)}`);
654
+ }
655
+ // Left unsettled, a watcher keeps the document dirty though the store answers clean.
656
+ announceClean(false);
657
+ }
658
+ );
659
+ }
660
+
661
+ /** `uri` as the `DocumentReleaseHandler` slot receives it. */
662
+ protected toReleasedDocument(uri: CanonicalUri): ReleasedDocument {
663
+ return {
664
+ uri,
665
+ wasOnDisk: this.dirtyStateTracker.hasDiskBaseline(uri),
666
+ isFor: other => this.documentKey(other) === uri,
667
+ isReclaimed: () => this.isOpenInAnyClient(uri) || this.__syncedDocuments.has(uri)
668
+ };
669
+ }
670
+
614
671
  public notifyWillSaveTextDocument(event: WillSaveTextDocumentParams): void {
615
672
  const syncedDocument = this.__syncedDocuments.get(this.documentKey(event.textDocument.uri));
616
673
  if (syncedDocument !== undefined) {
@@ -630,93 +687,176 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
630
687
  }
631
688
  }
632
689
 
690
+ /**
691
+ * Handle a save the language client reports: fire
692
+ * {@link onDidSaveInLanguageClient}, then announce it on {@link onDidSave}
693
+ * only once the file read back from disk holds the store's current text.
694
+ */
695
+ protected async notifyLanguageClientSave(event: DidSaveTextDocumentParams): Promise<void> {
696
+ const syncedDocument = this.__syncedDocuments.get(this.documentKey(event.textDocument.uri));
697
+ if (syncedDocument === undefined) {
698
+ return;
699
+ }
700
+ const uri = syncedDocument.uri;
701
+ this.languageClientSavedEmitter.fire(Object.freeze({ uri }));
702
+ // `onDidSave` tells its listeners that the shared document is on disk.
703
+ // The editor wrote its own buffer, which lags the store while another
704
+ // client's edit is still on its way to it, so only the file says
705
+ // whether that holds. Read it rather than trust the editor: `didSave`
706
+ // carries text only for a client that honours `includeText`, and asking
707
+ // for it means rewriting Langium's initialize answer, which advertises
708
+ // `save` as a Boolean. The read goes through the disk queue and waits on
709
+ // nothing but the provider, so it follows a server save queued
710
+ // meanwhile. A file changed again between the editor's write and this
711
+ // read compares unequal, and the save goes unannounced.
712
+ let onDisk: string | undefined;
713
+ try {
714
+ onDisk = await this.services.workspace.FileSystemTaskQueue.enqueue(uri, () =>
715
+ this.services.workspace.FileSystemProvider.readFile(UriUtils.toUri(uri))
716
+ );
717
+ } catch (err: unknown) {
718
+ this.tracer.with(uri).debug(`Editor save not announced: reading the file back failed. ${describeError(err)}`);
719
+ return;
720
+ }
721
+ // What the file holds, not what the editor meant to write: an editor
722
+ // that saved older text leaves the document dirty.
723
+ this.setDiskBaseline(uri, onDisk);
724
+ // An editor that saves and then closes releases the document while the
725
+ // read is under way; its save is still a save of the text it held.
726
+ const document = this.__syncedDocuments.get(this.documentKey(uri)) ?? syncedDocument;
727
+ if (onDisk !== document.getText()) {
728
+ this.tracer.with(uri).debug(`Editor save not announced: the file does not hold the text of version ${document.version}`);
729
+ return;
730
+ }
731
+ this.announceSave(document, LANGUAGE_CLIENT_ID);
732
+ }
733
+
734
+ /**
735
+ * Announce a save the server made. `event.text`, when given, is what the
736
+ * file now holds, written or found there, and becomes the disk baseline
737
+ * before the save is announced. It lags the store when an edit landed
738
+ * after the save took its text, and the document then stays dirty.
739
+ */
633
740
  public notifyDidSaveTextDocument(event: DidSaveTextDocumentParams, clientId = LANGUAGE_CLIENT_ID): void {
634
741
  const syncedDocument = this.__syncedDocuments.get(this.documentKey(event.textDocument.uri));
635
742
  if (syncedDocument !== undefined) {
636
- this.log(syncedDocument.uri, `Saved synced document: ${syncedDocument.version} by ${clientId}`);
637
- this.__onDidSave.fire(Object.freeze({ document: syncedDocument, clientId }));
743
+ if (event.text !== undefined) {
744
+ this.setDiskBaseline(syncedDocument.uri, event.text);
745
+ }
746
+ this.announceSave(syncedDocument, clientId);
638
747
  }
639
748
  }
640
749
 
750
+ /** Fire {@link onDidSave} for `document`, which need not be synced any more. */
751
+ protected announceSave(document: T, clientId: string): void {
752
+ this.log(document.uri, `Saved synced document: ${document.version} by ${this.formatClientId(clientId)}`);
753
+ this.__onDidSave.fire(Object.freeze({ document, clientId }));
754
+ }
755
+
641
756
  public notifyDidOpenTextDocument(event: DidOpenTextDocumentParams, clientId = LANGUAGE_CLIENT_ID): void {
642
757
  const td = event.textDocument;
643
758
  const uri = this.documentKey(td.uri);
644
- if (this.isOpenInClient(uri, clientId)) {
645
- // Already open for this client under this canonical identity. If this is a
646
- // NEW client-facing URI for the same file (a second tab reached via a
647
- // divergent path, e.g. a symlink and its real path), record it and baseline
648
- // its shadow so outbound edits reach this tab too — but do NOT re-fire
649
- // open/rebuild; the document is already live.
650
- if (clientId === LANGUAGE_CLIENT_ID) {
651
- const clientFacing = this.toLanguageClientUri(td.uri);
652
- const record = this.__documents.get(uri);
653
- if (record && !record.languageClientUris?.has(clientFacing)) {
654
- (record.languageClientUris ??= new Set<LanguageClientUri>()).add(clientFacing);
655
- const open = this.__syncedDocuments.get(uri);
656
- if (open) {
657
- this.__shadow.set(clientFacing, open.getText());
658
- }
659
- }
660
- }
661
- return;
759
+ // Before the deferred release is resolved: refused after it, the open
760
+ // would leave a document whose grace it ended with no holder and no timer.
761
+ // A repeat open stays a no-op.
762
+ if (!this.__sessions.isOpenIn(uri, clientId)) {
763
+ this.__sessions.assertCanOpen(clientId);
662
764
  }
765
+ this.resolveDeferredRelease(uri, clientId);
663
766
  let document = this.__syncedDocuments.get(uri);
664
- const record = this.trackingFor(uri);
665
- const existingClients = [...record.clients];
666
- record.clients.add(clientId);
667
- // Baseline the per-client staleness guard at the version id the client
668
- // declared for its own buffer (client-owned per LSP).
669
- record.clientVersions.set(clientId, td.version);
767
+ // The client's declared text, never the synced document: staged
768
+ // content this open consumes leaves the two different, and a baseline
769
+ // asserting the client already holds it suppresses the one sync that
770
+ // would deliver it. On an attach, another client may already have
771
+ // changed the synced text, so the baseline is equality-only; a refresh
772
+ // pushing the full text would dirty the file on open.
670
773
  if (clientId === LANGUAGE_CLIENT_ID) {
671
- // Remember the URI Monaco opened under (may differ from the canonical key)
672
- // so outbound applyEditToLanguageClient can address the URI it actually holds.
673
- (record.languageClientUris ??= new Set<LanguageClientUri>()).add(this.toLanguageClientUri(td.uri));
774
+ this.languageClientShadow.addOpen(uri, this.toLanguageClientUri(td.uri), td.version, td.text, document === undefined);
674
775
  }
776
+ if (this.isOpenInClient(uri, clientId)) {
777
+ // A repeat open, or the editor's second URI for the file, e.g. a
778
+ // symlink and its real path: the shadow records it so pushes reach it,
779
+ // and nothing re-fires.
780
+ return;
781
+ }
782
+ const existingClients = this.__sessions.clientsOf(uri);
783
+ this.__sessions.addOpen(uri, clientId);
784
+ this.__sessions.setClientVersion(uri, clientId, td.version);
675
785
  if (!document) {
676
786
  // Use integrity-staged content if available, otherwise the client-provided (disk) text.
677
787
  const pendingText = this.consumePendingContent(uri);
678
788
  const text = pendingText ?? td.text;
679
789
  const source = pendingText ? ', source=pending' : '';
680
- // The SHARED version is server-assigned: continue the persisted
681
- // sequence — same version when the content is unchanged since the
682
- // last close (so watchers' `baseVersion` pointers stay valid), one
683
- // step when it changed (so no stale pointer can coincidentally pass
684
- // the optimistic gate). Only a first-ever open adopts the client's
685
- // declared id as the sequence seed.
686
- const sequence = this.__versionSequences.get(uri);
687
- const version =
688
- sequence === undefined ? td.version : sequence.contentHash === contentHash(text) ? sequence.version : sequence.version + 1;
689
- this.log(uri, `Open document: Version ${version} by ${clientId} [first client${source}]`);
690
- document = this.configuration.create(uri, td.languageId, version, text);
691
- this.__syncedDocuments.set(uri, document);
692
- this.setAuthor(uri, version, clientId);
693
- if (clientId === LANGUAGE_CLIENT_ID) {
694
- // Baseline the shadow to what Monaco just opened so the next outbound
695
- // applyEditToLanguageClient diffs against the right starting point. Keyed by the
696
- // language-client URI (what Monaco holds), not the canonical document key.
697
- this.__shadow.set(this.toLanguageClientUri(td.uri), document.getText());
698
- }
790
+ const version = this.textLedger.openingVersion(uri, text) ?? this.builtRootOpeningVersion(uri, text) ?? td.version;
791
+ this.log(uri, `Open document: Version ${version} by ${this.formatClientId(clientId)} [first client${source}]`);
792
+ document = this.create(uri, td.languageId, version, text);
793
+ this.commitText(uri, document, clientId);
794
+ this.__openedVersions.set(uri, version);
795
+ // The opener's text, not the staged content: a session's open read
796
+ // it from the file, and an editor opened its buffer from there. An
797
+ // editor that opens a buffer it never saved is taken as clean.
798
+ this.dirtyStateTracker.track(uri, document, td.text);
699
799
  const toFire = Object.freeze({ document, clientId });
700
800
  this.__onDidOpen.fire(toFire);
701
801
  this.__onDidChangeContent.fire(toFire);
702
802
  } else {
703
803
  // An additional client attaches to a document already open by another client.
704
- this.log(
705
- uri,
706
- `Attach client: ${clientId} joined existing document (version ${document.version}, ` +
707
- `now open in: ${[...existingClients, clientId].join(', ')})`
708
- );
804
+ this.logClientJoined(uri, clientId, document.version, existingClients);
709
805
  this.refreshContent(uri, clientId);
710
806
  }
711
807
  }
712
808
 
809
+ /**
810
+ * Record `clientId` as an additional holder of a document another client
811
+ * already has open.
812
+ *
813
+ * Unlike the attach branch of {@link notifyDidOpenTextDocument} this does
814
+ * not refresh. That branch re-renders an attaching TEXTUAL view; a client
815
+ * reaching a document through a non-textual route has nothing to re-render,
816
+ * and refreshing per attach turns each into a Langium rebuild and dependent
817
+ * relink cascade.
818
+ *
819
+ * Returns whether a hold was added — `false` when `uri` is not open,
820
+ * `clientId` already holds it, or the document was waiting out the release
821
+ * grace for other clients and was released instead (see
822
+ * {@link resolveDeferredRelease}); the caller then opens it anew.
823
+ */
824
+ attachClient(uri: DocumentUri, clientId: string): boolean {
825
+ const key = this.documentKey(uri);
826
+ if (!this.__syncedDocuments.has(key) || this.isOpenInClient(key, clientId)) {
827
+ return false;
828
+ }
829
+ // Before the deferred release is resolved, as for an open.
830
+ this.__sessions.assertCanOpen(clientId);
831
+ this.resolveDeferredRelease(key, clientId);
832
+ const document = this.__syncedDocuments.get(key);
833
+ if (!document) {
834
+ return false;
835
+ }
836
+ const existingClients = this.__sessions.clientsOf(key);
837
+ this.__sessions.addOpen(key, clientId);
838
+ // A client arriving this way holds no buffer of its own, so its guard
839
+ // starts at the synced version.
840
+ this.__sessions.setClientVersion(key, clientId, document.version);
841
+ this.logClientJoined(key, clientId, document.version, existingClients);
842
+ return true;
843
+ }
844
+
845
+ protected logClientJoined(uri: DocumentUri, clientId: string, version: number, existingClients: readonly string[]): void {
846
+ this.log(
847
+ uri,
848
+ `Attach client: ${this.formatClientId(clientId)} joined existing document (version ${version}, ` +
849
+ `now open in: ${[...existingClients, clientId].map(id => this.formatClientId(id)).join(', ')})`
850
+ );
851
+ }
852
+
713
853
  refreshContent(uri: DocumentUri, clientId: string): void {
714
854
  const syncedDocument = this.__syncedDocuments.get(this.documentKey(uri));
715
855
  if (syncedDocument) {
716
856
  // Trigger a (re-)build by firing a change event.
717
857
  const timer = this.startTimerForUri(
718
858
  syncedDocument.uri,
719
- `Refresh synced document: Version ${syncedDocument.version} by ${clientId}`
859
+ `Refresh synced document: Version ${syncedDocument.version} by ${this.formatClientId(clientId)}`
720
860
  );
721
861
  this.__onDidChangeContent.fire(Object.freeze({ document: syncedDocument, clientId }));
722
862
  timer.dispose();
@@ -730,7 +870,7 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
730
870
  * two URIs for one physical file (a symlink path and its real path) into a
731
871
  * single registration — dedup at the editor layer, not just in
732
872
  * `LangiumDocuments`. The URI the client opened under is preserved separately
733
- * for egress addressing (see {@link DocumentTracking.languageClientUris}). The
873
+ * for egress addressing, by the {@link LanguageClientShadow}. The
734
874
  * policy is always bound (the framework defaults it to
735
875
  * `DefaultDocumentUriPolicy`, where canonical ≡ syntactic normalize).
736
876
  */
@@ -750,18 +890,8 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
750
890
  return asLanguageClientUri(UriUtils.normalize(uri));
751
891
  }
752
892
 
753
- /** Get-or-create the per-URI tracking record. `uri` must already be a {@link documentKey}. */
754
- protected trackingFor(uri: CanonicalUri): DocumentTracking {
755
- let record = this.__documents.get(uri);
756
- if (!record) {
757
- record = { clients: new Set(), versionAuthors: [], clientVersions: new Map() };
758
- this.__documents.set(uri, record);
759
- }
760
- return record;
761
- }
762
-
763
893
  setAuthor(uri: DocumentUri, version: number, author: string): void {
764
- this.trackingFor(this.documentKey(uri)).versionAuthors[version] = author;
894
+ this.textLedger.setAuthor(this.documentKey(uri), version, author);
765
895
  }
766
896
 
767
897
  /**
@@ -786,57 +916,148 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
786
916
 
787
917
  /**
788
918
  * Current SHARED version of the document at `uri`: the open document's
789
- * version, else where the persisted sequence left off at last close, else
790
- * `0` for a URI this store has never seen. The shared sequence is
919
+ * version, else where its persisted sequence left off, else `0` for a URI
920
+ * this store has never seen. The shared sequence is
791
921
  * server-owned and monotonic across close/reopen cycles, and advances
792
922
  * exactly when the synced content changes — which is what makes it a sound
793
- * optimistic-concurrency token (`baseVersion` gates): version unchanged ⇔
923
+ * optimistic-concurrency token (base-version gates): version unchanged ⇔
794
924
  * content unchanged.
795
925
  */
796
- version(uri: DocumentUri): number {
797
- return this.get(uri)?.version ?? this.__versionSequences.get(this.documentKey(uri))?.version ?? 0;
926
+ version(uri: DocumentUri): TextVersion {
927
+ return this.get(uri)?.version ?? this.textLedger.recordOf(this.documentKey(uri))?.version ?? 0;
928
+ }
929
+
930
+ /**
931
+ * The version the document at `uri` was opened at, which a client's write
932
+ * or an integrity repair steps past; `undefined` while it is not open.
933
+ */
934
+ openedVersion(uri: DocumentUri): TextVersion | undefined {
935
+ return this.__openedVersions.get(this.documentKey(uri));
936
+ }
937
+
938
+ /**
939
+ * The text the store holds for `uri`: an open document's, or for a closed
940
+ * one, the clean text its version sequence left off at, which for a deleted
941
+ * document is its last text. `undefined` for a URI no build and no client
942
+ * gave the store.
943
+ */
944
+ textState(uri: DocumentUri): TextState | undefined {
945
+ const document = this.get(uri);
946
+ if (document) {
947
+ return { version: document.version, hash: this.textLedger.hashOf(document), dirty: this.isDirty(uri) };
948
+ }
949
+ const recorded = this.textLedger.recordOf(this.documentKey(uri));
950
+ return recorded && { version: recorded.version, hash: recorded.hash, dirty: false };
951
+ }
952
+
953
+ /**
954
+ * The built root's recorded version for a first open of `key` with `text`,
955
+ * one on when the text differs from the root's; `undefined` when the root
956
+ * records no store version. Seeded from the opener's declared version
957
+ * instead, a write based on the built root passes the gate over other text,
958
+ * and the same text looks newer than its model. A built root records none
959
+ * only under a `LangiumDocuments` that does not reconcile at registration.
960
+ */
961
+ protected builtRootOpeningVersion(key: CanonicalUri, text: string): TextVersion | undefined {
962
+ const built = this.services.workspace.LangiumDocuments.getDocument(UriUtils.toUri(key));
963
+ if (built === undefined) {
964
+ return undefined;
965
+ }
966
+ const ledger = this.services.workspace.ModelLedger;
967
+ const root = built.parseResult.value;
968
+ const recorded = ledger.versionOf(root);
969
+ if (recorded === UNRECORDED_VERSION || recorded === STALE_VERSION) {
970
+ return undefined;
971
+ }
972
+ return (ledger.textOf(root) ?? built.textDocument.getText()) === text ? recorded : recorded + 1;
798
973
  }
799
974
 
800
975
  /**
801
976
  * Reconcile the persisted version sequence with content that reached the
802
977
  * build OUTSIDE the store's write paths — a closed document rebuilt from
803
- * disk (last-close revert) or replaced by a watched-file change. Steps the
978
+ * disk after its release, or replaced by a watched-file change. Steps the
804
979
  * sequence iff `text` differs from the sequence's last-known content and
805
980
  * returns the resulting sequence version so the caller can re-stamp the
806
- * rebuilt document (see the `AstDocumentManager` Parsed-phase listener) —
981
+ * rebuilt document (`VersionSyncService.modelProduced`) —
807
982
  * keeping the "version advances iff content changes" invariant for
808
983
  * documents no client currently holds.
809
984
  *
810
- * Returns `undefined` — and does nothing — when the document is open (the
811
- * store's own content is authoritative; external transitions never reach
812
- * the Langium factory for open documents) or was never tracked (no gate
813
- * holder can hold a version pointer for it, and the early exit keeps
814
- * workspace-wide builds from hashing every untouched document).
985
+ * For an open document, its version when it holds `text`, since a build
986
+ * that read the file while the document was closed can finish after an
987
+ * open; else `undefined`, and the caller has to build the document again.
988
+ *
989
+ * A document without a sequence starts one at `0` with `text`: snapshots
990
+ * hand out versions for documents no client opened, so an uncounted change
991
+ * would let a write based on the old text pass the gate.
815
992
  */
816
993
  reconcileExternalContent(uri: DocumentUri, text: string): number | undefined {
817
994
  const key = this.documentKey(uri);
818
- if (this.__syncedDocuments.has(key)) {
819
- return undefined;
995
+ const open = this.__syncedDocuments.get(key);
996
+ if (open !== undefined) {
997
+ return open.getText() === text ? open.version : undefined;
820
998
  }
821
- const sequence = this.__versionSequences.get(key);
822
- if (sequence === undefined) {
823
- return undefined;
999
+ const before = this.textLedger.recordOf(key)?.version;
1000
+ const version = this.textLedger.reconcile(key, text);
1001
+ if (before !== undefined && version !== before) {
1002
+ this.logUri(key, `External content change while closed: sequence stepped to version ${version}`, 'debug');
824
1003
  }
825
- const hash = contentHash(text);
826
- if (hash === sequence.contentHash) {
827
- return sequence.version;
1004
+ return version;
1005
+ }
1006
+
1007
+ /**
1008
+ * Commit an integrity repair into the OPEN document for `uri`, returning the
1009
+ * document that now holds it, or `undefined` when there was nothing here to
1010
+ * commit into.
1011
+ *
1012
+ * The one thing this exists to do is address the store BY URI. A repair
1013
+ * reaches the resync as a text-document object, and that object is the
1014
+ * store's own only on the LSP path; a document built for an already-open URI
1015
+ * through `LangiumDocumentFactory.fromString` carries its own, so writing the
1016
+ * repair into it corrects a copy the store does not know about and the editor
1017
+ * never sees.
1018
+ *
1019
+ * `parsedFrom` is the text the repaired AST was parsed from, and a mismatch
1020
+ * against the current content REFUSES the commit: the store has moved on,
1021
+ * which means an editor change landed after that parse, and committing would
1022
+ * overwrite a newer edit with a repair computed against text the user has
1023
+ * already replaced. The build that change provokes recomputes the repair.
1024
+ *
1025
+ * Deliberately NOT compared by version. A separately created document seeds
1026
+ * its own numbering, so requiring the two to agree would refuse every commit
1027
+ * on the path this exists for. Content is the thing both sides can be held to.
1028
+ *
1029
+ * A changed text is a new version authored by {@link INTEGRITY_CLIENT_ID}.
1030
+ * Kept at the old version, the repair is invisible to every reader keyed on
1031
+ * versions: a write based on the unrepaired version passes the base-version gate
1032
+ * and replaces the repair, and an echo filter credits the repair to the
1033
+ * client whose edit it corrected. No change event is fired: the repair
1034
+ * rides the build already under way, and an event would re-enter it.
1035
+ */
1036
+ commitRepair(uri: DocumentUri, parsedFrom: string, repaired: string): RepairCommit<T> {
1037
+ const key = this.documentKey(uri);
1038
+ const document = this.__syncedDocuments.get(key);
1039
+ if (document === undefined) {
1040
+ return { status: 'not-open' };
1041
+ }
1042
+ if (document.getText() !== parsedFrom) {
1043
+ this.logUri(key, 'Refuse repair commit: the open document moved on from the text the AST was parsed from', 'debug');
1044
+ return { status: 'stale' };
828
1045
  }
829
- const stepped: VersionSequence = { version: sequence.version + 1, contentHash: hash };
830
- this.__versionSequences.set(key, stepped);
831
- this.logUri(key, `External content change while closed: sequence stepped to version ${stepped.version}`, 'debug');
832
- return stepped.version;
1046
+ if (repaired === parsedFrom) {
1047
+ return { status: 'committed', document };
1048
+ }
1049
+ // Reassigned rather than mutated in place: the default configuration
1050
+ // updates and returns the SAME instance, but an adopter-supplied one may
1051
+ // return a new object, and the store must end up holding whichever it is.
1052
+ const updated = this.commitChange(key, document, [{ text: repaired }], INTEGRITY_CLIENT_ID).document;
1053
+ this.log(updated.uri, `Update to version ${updated.version} by ${this.formatClientId(INTEGRITY_CLIENT_ID)} (repair)`);
1054
+ return { status: 'committed', document: updated };
833
1055
  }
834
1056
 
835
1057
  getAuthor(uri: DocumentUri, version?: number): string | undefined {
836
- const history = this.__documents.get(this.documentKey(uri))?.versionAuthors;
837
- // Either the requested version, or the latest. `version !== undefined` so we treat 0 correctly.
838
- const clientId = version !== undefined ? history?.[version] : history?.at(-1);
839
- if (!clientId && history) {
1058
+ const key = this.documentKey(uri);
1059
+ const clientId = this.textLedger.authorOf(key, version);
1060
+ if (!clientId && this.textLedger.authorOf(key) !== undefined) {
840
1061
  // Only warn when there IS a history but the specific version is missing; no history at all
841
1062
  // means the document was rebuilt internally (e.g. by a project manager), not an error.
842
1063
  this.log(uri, `Could not detect author of version ${version}.`);
@@ -852,17 +1073,19 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
852
1073
  * True iff any client still holds `uri` open. Distinct from {@link isOpen},
853
1074
  * which reads `__syncedDocuments` — that map is cleared only AFTER the
854
1075
  * `onDidClose` event fires for the last client, so `isOpen` returns `true`
855
- * during the close event itself. `isOpenInAnyClient` reads the tracking
856
- * record's `clients` set, which is updated BEFORE the fire, so an `onDidClose`
857
- * subscriber that finds this `false` knows the last client just closed and a
858
- * disk re-read / rebuild can proceed.
1076
+ * during the close event itself. `isOpenInAnyClient` reads the open table
1077
+ * ({@link __sessions}), which is updated BEFORE the fire, so an `onDidClose`
1078
+ * subscriber that finds this `false` knows the last client just closed.
1079
+ * What the build keeps is the release's: a subscriber that re-read or
1080
+ * rebuilt the document would race the `DocumentReleaseHandler`, and after a
1081
+ * lost connection the release waits out its grace.
859
1082
  */
860
1083
  isOpenInAnyClient(uri: DocumentUri): boolean {
861
- return (this.__documents.get(this.documentKey(uri))?.clients.size ?? 0) > 0;
1084
+ return this.__sessions.isOpen(this.documentKey(uri));
862
1085
  }
863
1086
 
864
1087
  isOpenInClient(uri: DocumentUri, client: string): boolean {
865
- return !!this.__documents.get(this.documentKey(uri))?.clients.has(client);
1088
+ return this.__sessions.isOpenIn(this.documentKey(uri), client);
866
1089
  }
867
1090
 
868
1091
  isOpenInLanguageClient(uri: DocumentUri): boolean {
@@ -872,15 +1095,20 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
872
1095
  return this.isOpenInClient(uri, LANGUAGE_CLIENT_ID);
873
1096
  }
874
1097
 
1098
+ /** The clients that have `uri` open, in the order they opened it. */
1099
+ clientsOf(uri: DocumentUri): string[] {
1100
+ return this.__sessions.clientsOf(this.documentKey(uri));
1101
+ }
1102
+
875
1103
  isOnlyOpenInClient(uri: DocumentUri, client: string): boolean {
876
- const key = this.documentKey(uri);
877
- return this.__documents.get(key)?.clients.size === 1 && this.isOpenInClient(key, client);
1104
+ const clients = this.__sessions.clientsOf(this.documentKey(uri));
1105
+ return clients.length === 1 && clients[0] === client;
878
1106
  }
879
1107
 
880
1108
  /**
881
1109
  * Every document currently held open by at least one client, with the client
882
- * ids holding it. Reads the same per-URI tracking records as
883
- * {@link isOpenInAnyClient}, so it reflects a last-client close immediately.
1110
+ * ids holding it. Reads the same open table as {@link isOpenInAnyClient}, so
1111
+ * it reflects a last-client close immediately.
884
1112
  *
885
1113
  * Diagnostics-oriented — the server-state snapshot lists these so an operator
886
1114
  * can see WHY a document is pinned: a document that lingers here after its
@@ -888,31 +1116,244 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
888
1116
  * under a shedding policy, explains why its CST is never shed).
889
1117
  */
890
1118
  openDocuments(): OpenDocument[] {
891
- const result: OpenDocument[] = [];
892
- for (const [uri, tracking] of this.__documents) {
893
- if (tracking.clients.size > 0) {
894
- result.push({ uri, clients: [...tracking.clients] });
1119
+ return this.__sessions.openDocuments();
1120
+ }
1121
+
1122
+ /** Fires once a client session has ended, after every document it had open was closed. */
1123
+ get onDidCloseSession(): Event<ClientSessionClosedEvent> {
1124
+ return this.__sessions.onDidCloseSession;
1125
+ }
1126
+
1127
+ /**
1128
+ * Fires once a document no client has open is released: at its last close,
1129
+ * or, for a lost client's last close, when its release grace runs out,
1130
+ * another client opens it, or it is deleted, before the
1131
+ * `DocumentReleaseHandler` slot is handed the document.
1132
+ */
1133
+ get onDidReleaseDocument(): Event<DocumentReleasedEvent> {
1134
+ return this.documentReleasedEmitter.event;
1135
+ }
1136
+
1137
+ /**
1138
+ * Fires for every save the language client reports of a document it has
1139
+ * open: the editor has written the file. {@link onDidSave} follows only
1140
+ * when the file holds the store's text.
1141
+ */
1142
+ get onDidSaveInLanguageClient(): Event<LanguageClientSavedEvent> {
1143
+ return this.languageClientSavedEmitter.event;
1144
+ }
1145
+
1146
+ /**
1147
+ * Whether `uri` is waiting out the release grace: its last open closed with a
1148
+ * lost connection, and it still holds its unsaved text. Such a document is
1149
+ * open for no client, yet not closed either, so a caller that would persist
1150
+ * a closed document's text to disk treats it as open.
1151
+ */
1152
+ isReleaseDeferred(uri: DocumentUri): boolean {
1153
+ return this.documentReleaseScheduler.isDeferred(this.documentKey(uri));
1154
+ }
1155
+
1156
+ /**
1157
+ * Whether the store holds `uri` with text that differs from its disk
1158
+ * baseline: what the server last knew the file to hold. `false` for a URI
1159
+ * the store does not hold; a document waiting out the release grace is still
1160
+ * held.
1161
+ *
1162
+ * The baseline is the text a first open brought, or what the server wrote,
1163
+ * or read back after an editor's save or a watched-file change, so it can
1164
+ * trail a change to the file that none of these has seen yet. A check that
1165
+ * must know the file reads it instead.
1166
+ */
1167
+ isDirty(uri: DocumentUri): boolean {
1168
+ return this.dirtyStateTracker.isDirty(this.documentKey(uri));
1169
+ }
1170
+
1171
+ /**
1172
+ * Fires each time the answer of {@link isDirty} changes. For a document
1173
+ * released dirty it fires once the `DocumentReleaseHandler` slot reports the
1174
+ * release settled: at the version of the text the build then holds, or
1175
+ * without text when the document is gone or the handler failed, though
1176
+ * {@link isDirty} answers clean from the release on.
1177
+ */
1178
+ get onDidChangeDirty(): Event<DocumentDirtyChangedEvent> {
1179
+ return this.dirtyStateTracker.onDidChangeDirty;
1180
+ }
1181
+
1182
+ /**
1183
+ * Record that the file behind `uri` holds `text`, or no file at all for
1184
+ * `undefined`. A no-op for a URI the store does not hold: the next first
1185
+ * open sets the baseline from its own text.
1186
+ */
1187
+ setDiskBaseline(uri: DocumentUri, text: string | undefined): void {
1188
+ const key = this.documentKey(uri);
1189
+ const document = this.__syncedDocuments.get(key);
1190
+ if (document !== undefined) {
1191
+ this.dirtyStateTracker.setDiskBaseline(key, document, text);
1192
+ }
1193
+ }
1194
+
1195
+ /**
1196
+ * Read the file behind `uri` through its disk queue and take it as the
1197
+ * baseline. A file that cannot be read counts as none, the side that
1198
+ * leaves the document dirty, once `existsSettled` confirms it gone: a file
1199
+ * it finds is read again. That wait runs outside the queue, so it holds up
1200
+ * no write to the file.
1201
+ */
1202
+ async reloadDiskBaseline(uri: DocumentUri): Promise<void> {
1203
+ const key = this.documentKey(uri);
1204
+ if (!this.__syncedDocuments.has(key)) {
1205
+ return;
1206
+ }
1207
+ const workspace = this.services.workspace;
1208
+ const fileSystem = workspace.FileSystemProvider;
1209
+ const target = UriUtils.toUri(key);
1210
+ const read = async (): Promise<string | undefined> => {
1211
+ try {
1212
+ return await workspace.FileSystemTaskQueue.enqueue(key, () => fileSystem.readFile(target));
1213
+ } catch (err: unknown) {
1214
+ this.tracer.with(key).debug(`Disk baseline: the file cannot be read. ${describeError(err)}`);
1215
+ return undefined;
1216
+ }
1217
+ };
1218
+ let onDisk = await read();
1219
+ if (onDisk === undefined && (await (fileSystem.existsSettled?.(target) ?? fileSystem.exists(target)))) {
1220
+ onDisk = await read();
1221
+ }
1222
+ this.setDiskBaseline(key, onDisk);
1223
+ }
1224
+
1225
+ /**
1226
+ * Start a client session under `clientId`. Throws where
1227
+ * {@link ClientSessionRegistry.register} refuses the id.
1228
+ */
1229
+ registerSession(clientId: string): void {
1230
+ this.__sessions.register(clientId);
1231
+ this.tracer.info(`Session started: ${this.formatClientId(clientId)}`);
1232
+ this.tracer.trace(`Session started: ${clientId}`);
1233
+ }
1234
+
1235
+ /**
1236
+ * End the client session `clientId`: close every document it has open, then
1237
+ * free the id. Immediate — each close runs the ordinary close path before
1238
+ * this returns, with `cause` as its cause. A no-op for an id that is not a
1239
+ * registered session.
1240
+ */
1241
+ closeSession(clientId: string, cause: SessionEndCause = 'closed'): void {
1242
+ if (!this.__sessions.isRegistered(clientId)) {
1243
+ return;
1244
+ }
1245
+ try {
1246
+ for (const uri of this.__sessions.beginClose(clientId)) {
1247
+ this.notifyDidCloseTextDocument({ textDocument: { uri } }, clientId, cause);
895
1248
  }
1249
+ } finally {
1250
+ this.__sessions.unregister(clientId, cause);
1251
+ this.tracer.info(`Session closed: ${this.formatClientId(clientId)}`);
1252
+ this.tracer.trace(`Session closed: ${clientId}`);
896
1253
  }
897
- return result;
898
1254
  }
899
1255
 
900
1256
  /**
901
- * Stages integrity-updated content for a closed document.
1257
+ * Close every document the language client has open, as a `didClose` for
1258
+ * each would, so each last close releases its document. For a host whose editor connection
1259
+ * can end while the process lives on, such as a worker whose port's peer
1260
+ * closed: the language client is no session, so nothing else closes them.
902
1261
  *
903
- * When `workspace/applyEdit` targets a closed file, the client opens it from
904
- * disk (stale) and sends `didOpen` before applying the edit. This staged
905
- * content is consumed by {@link notifyDidOpenTextDocument} to replace the
906
- * stale disk text, preventing a brief revert of the integrity update.
1262
+ * It first waits for the workspace initialization the open handler waits
1263
+ * for, so an open that arrived before the close is closed too; closing at
1264
+ * once would leave that open to land afterwards, held by a client that is
1265
+ * gone.
1266
+ */
1267
+ async closeLanguageClientDocuments(): Promise<void> {
1268
+ await this.initialBuildFinished();
1269
+ for (const uri of this.__sessions.opensOf(LANGUAGE_CLIENT_ID)) {
1270
+ // A close for one URI while others remain keeps the client's hold.
1271
+ this.languageClientShadow.removeAllOpens(uri);
1272
+ this.notifyDidCloseTextDocument({ textDocument: { uri } });
1273
+ }
1274
+ }
1275
+
1276
+ /**
1277
+ * Settles once the initial workspace build has finished, whether it
1278
+ * completed, was cancelled or failed. Awaiting `workspaceInitialized` itself
1279
+ * throws after a cancelled build, which any write during startup causes, and
1280
+ * every open and close gated on it is then dropped for the process lifetime.
1281
+ * The workspace manager logs a failed build.
1282
+ */
1283
+ protected async initialBuildFinished(): Promise<void> {
1284
+ await this.services.workspace.WorkspaceManager.workspaceInitialized.catch(() => undefined);
1285
+ }
1286
+
1287
+ /**
1288
+ * The file behind `uri` was deleted: close every open of it except the
1289
+ * language client's.
907
1290
  *
908
- * Not cleared on close: pending content is only staged for already-closed
909
- * documents (the integrity service checks `isOpenInLanguageClient` first), so
910
- * a close → stage → open cycle cannot occur. The only scenario where an
911
- * entry lingers is if `workspace/applyEdit` fails and the file is never
912
- * opened — the memory cost is one serialised string per URI.
1291
+ * The editor's open is left alone because the editor owns it: it keeps the
1292
+ * buffer of a deleted file and goes on sending changes for it, and a store
1293
+ * that had closed the document would drop every one of them until the editor
1294
+ * reopened.
1295
+ */
1296
+ notifyDocumentDeleted(uri: DocumentUri): void {
1297
+ const key = this.documentKey(uri);
1298
+ for (const clientId of this.__sessions.clientsOf(key)) {
1299
+ if (clientId !== LANGUAGE_CLIENT_ID) {
1300
+ this.notifyDidCloseTextDocument({ textDocument: { uri: key } }, clientId);
1301
+ }
1302
+ }
1303
+ }
1304
+
1305
+ /**
1306
+ * Remove the document for `uri`, closing every open of it first — the
1307
+ * editor's included, since the document it would keep editing is gone.
1308
+ *
1309
+ * The base removes the synced document without consulting the open table,
1310
+ * which leaves every open recorded against a document that no longer exists:
1311
+ * the store then answers that the URI is open, and the next open attaches to
1312
+ * nothing.
1313
+ */
1314
+ override delete(uri: string | URI | T): void {
1315
+ const key = this.documentKey((typeof uri === 'object' && 'uri' in uri ? uri.uri : uri).toString());
1316
+ this.languageClientShadow.removeAllOpens(key);
1317
+ for (const clientId of this.__sessions.clientsOf(key)) {
1318
+ this.notifyDidCloseTextDocument({ textDocument: { uri: key } }, clientId);
1319
+ }
1320
+ // A document waiting out the grace has no client left to close, and is
1321
+ // released now as its last close would have released it.
1322
+ if (this.documentReleaseScheduler.isDeferred(key)) {
1323
+ this.documentReleaseScheduler.cancel(key);
1324
+ this.releaseDocument(key);
1325
+ }
1326
+ super.delete(key);
1327
+ }
1328
+
1329
+ /**
1330
+ * A client id as log lines print it. An id containing `#` is cut eight
1331
+ * characters after its last `#`, which leaves a minted `label#uuid` as the
1332
+ * label and enough of the UUID to tell sessions apart; an id without `#`
1333
+ * prints whole. The full id goes out at trace level wherever a session
1334
+ * starts or ends.
1335
+ */
1336
+ protected formatClientId(clientId: string): string {
1337
+ const separator = clientId.lastIndexOf('#');
1338
+ return separator < 0 ? clientId : clientId.slice(0, separator + 9);
1339
+ }
1340
+
1341
+ /**
1342
+ * Stages integrity-updated content for a document no client holds.
1343
+ *
1344
+ * Nothing is pushed to a file no client holds. The next open of it reads
1345
+ * disk, which lacks the update; {@link notifyDidOpenTextDocument} takes this
1346
+ * staged content in place of that text, and the open's sync then delivers
1347
+ * it to an editor as an unsaved change.
1348
+ *
1349
+ * Only a FIRST open consumes it, so stage only for a URI no client holds
1350
+ * ({@link isOpenInAnyClient} is `false`). A URI held only through another
1351
+ * head is not closed: an editor attaching to it joins the existing entry and
1352
+ * never reads the stage, and the release discards it. An entry waits for
1353
+ * that first open, at one serialised string per URI.
913
1354
  */
914
1355
  stagePendingContent(uri: DocumentUri, text: string): void {
915
- this.trackingFor(this.documentKey(uri)).pendingContent = text;
1356
+ this.__pendingContent.set(this.documentKey(uri), text);
916
1357
  }
917
1358
 
918
1359
  /**
@@ -924,29 +1365,34 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
924
1365
  * - The shared services have no LSP {@link Connection} bound (non-LSP
925
1366
  * hosts like CLI / tests).
926
1367
  * - The shadow already matches `newText` (no edits needed; quiet skip).
1368
+ * - The language client has not opened the document. A client applies an
1369
+ * edit to a closed file by opening it, and that open races the edit;
1370
+ * the document's own open delivers its text instead.
927
1371
  *
928
1372
  * On `applyEdit` rejection (`result.applied === false`) or RPC failure the
929
- * shadow is invalidated so the next call sends a full-replace baseline.
1373
+ * shadow is invalidated so the next call sends a full replace, or nothing
1374
+ * when the client was last heard to hold that text.
930
1375
  * Errors are re-thrown — callers wrap with their own retry / coalescing
931
1376
  * policy as needed.
932
1377
  *
933
1378
  * The diff path is apply-verify-safe: the shadow internally checks that
934
1379
  * `TextDocument.applyEdits(old, edits) === newText` and falls back to a
935
- * full replace on mismatch (logged via the warn-callback wired in the
936
- * constructor), so a diff regression becomes log noise, not data loss.
1380
+ * full replace on mismatch, logged, so a diff regression becomes log noise,
1381
+ * not data loss.
937
1382
  *
938
1383
  * That safety net verifies the diff against the SHADOW, which is what the
939
1384
  * client is *believed* to hold — so it cannot see the client's buffer moving
940
1385
  * underneath a push. A line-keyed edit is position-dependent: if a genuine
941
- * client keystroke lands between {@link LanguageClientTextShadow.computeEdits}
942
- * and the client applying, the ranges address the wrong lines and splice the
943
- * buffer (observed as a duplicated declaration, which the integrity tier then
1386
+ * client keystroke lands between computing the edits and the client
1387
+ * applying them, the ranges address the wrong lines and splice the buffer
1388
+ * (observed as a duplicated declaration, which the integrity tier then
944
1389
  * "repairs" into a suffixed name and persists). The edit is therefore
945
- * addressed at the language client's LAST DECLARED VERSION rather than at
946
- * `null` ("version intentionally unknown"), which is what lets the client
947
- * reject a push its buffer has outrun. On rejection the shadow is invalidated,
1390
+ * addressed at the language client's last known version for that URI rather
1391
+ * than at `null` ("version intentionally unknown"), which is what lets the
1392
+ * client reject a push its buffer has outrun. On rejection the shadow is invalidated,
948
1393
  * so the caller's retry is a full-range replace — position-independent, and
949
- * safe to apply to whatever the client now holds.
1394
+ * safe to apply to whatever the client now holds — or nothing when the
1395
+ * client was last heard to hold that text.
950
1396
  */
951
1397
  async applyEditToLanguageClient(
952
1398
  uri: DocumentUri,
@@ -957,46 +1403,43 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
957
1403
  if (!connection) {
958
1404
  return undefined;
959
1405
  }
960
- // The document is keyed by its canonical identity, but Monaco holds it under
961
- // the URI(s) it opened. Address each of those language-client URIs — the one
962
- // R→S translation, kept here at the egress. Usually one; more than one only
963
- // when the same file was opened under a symlink and its real path. Falls back
964
- // to the normalized URI when nothing is tracked. The shadow is keyed by each
965
- // URI, so every diff is against the right baseline.
966
- const recorded = this.__documents.get(this.documentKey(uri))?.languageClientUris;
967
- const targets: Iterable<LanguageClientUri> = recorded && recorded.size > 0 ? recorded : [this.toLanguageClientUri(uri)];
1406
+ // The document is keyed by its canonical identity, but the client holds it
1407
+ // under each URI it opened, and each is diffed against its own baseline.
1408
+ const key = this.documentKey(uri);
968
1409
  let lastResult: ApplyWorkspaceEditResult | undefined;
969
- for (const targetUri of targets) {
970
- // Read BEFORE computeEdits, which overwrites it. This is the text the
971
- // edits below are keyed to, and therefore the only text the client's
972
- // echo of them can be reconstructed against.
973
- const before = this.__shadow.get(targetUri);
974
- const edits = this.__shadow.computeEdits(targetUri, newText);
975
- if (edits.length === 0) {
1410
+ for (const clientUri of this.languageClientShadow.pushTargets(key)) {
1411
+ // Prepared per target, after the previous target's reply: prepared up
1412
+ // front, a later target is diffed against what it held before a change
1413
+ // that arrived meanwhile.
1414
+ const push = this.languageClientShadow.preparePush(key, clientUri, newText);
1415
+ if (push === undefined) {
976
1416
  continue;
977
1417
  }
978
- // Record the push for echo correlation BEFORE the RPC — the client's
979
- // echo can race the applyEdit response. See `__pendingPushes`.
980
- this.recordPendingPush(targetUri, before, newText);
981
1418
  try {
982
- // Version the push only when it is position-DEPENDENT. A full-range
983
- // replace lands correctly on any buffer, so gating it would turn a
984
- // stale-by-one version into a refused update for no safety gain — and
985
- // it is exactly what the caller retries with after a rejection, so
986
- // gating it there would refuse the recovery too.
987
- const version = isFullReplace(edits) ? UNKNOWN_CLIENT_VERSION : this.languageClientVersion(uri);
1419
+ // A full `ApplyWorkspaceEditParams`, `edit` and all — NOT a bare
1420
+ // `WorkspaceEdit` with a `label` beside it. `applyEdit` takes
1421
+ // `ApplyWorkspaceEditParams | WorkspaceEdit` and discriminates on
1422
+ // `!!value.edit`, so `{ label, documentChanges }` is wrapped as
1423
+ // `{ edit: { label, documentChanges } }` — putting the label inside
1424
+ // the edit, where LSP defines no such field and no client reads it.
1425
+ // The union is also what hides it at compile time: excess-property
1426
+ // checking admits a property present in EITHER member, so an object
1427
+ // matching neither type-checks against the union.
1428
+ const version = push.version ?? UNKNOWN_CLIENT_VERSION;
988
1429
  const result = await connection.workspace.applyEdit({
989
1430
  label: options?.label,
990
- documentChanges: [TextDocumentEdit.create(OptionalVersionedTextDocumentIdentifier.create(targetUri, version), edits)]
1431
+ edit: {
1432
+ documentChanges: [TextDocumentEdit.create(OptionalVersionedTextDocumentIdentifier.create(clientUri, version), push.edits)]
1433
+ }
991
1434
  });
992
1435
  if (result && result.applied === false) {
993
- this.__shadow.invalidate(targetUri);
994
- this.__pendingPushes.delete(targetUri);
1436
+ push.notifyOutcome('refused');
1437
+ } else if (result?.applied) {
1438
+ push.notifyOutcome('applied');
995
1439
  }
996
1440
  lastResult = result;
997
- } catch (err) {
998
- this.__shadow.invalidate(targetUri);
999
- this.__pendingPushes.delete(targetUri);
1441
+ } catch (err: unknown) {
1442
+ push.notifyOutcome('failed');
1000
1443
  throw err;
1001
1444
  }
1002
1445
  }
@@ -1004,125 +1447,31 @@ export class HydraniumTextDocuments<T extends TextDocument = TextDocument> exten
1004
1447
  }
1005
1448
 
1006
1449
  /**
1007
- * The version the LSP textual language client last declared for `uri`, for
1008
- * addressing an outgoing `workspace/applyEdit`.
1009
- *
1010
- * Client version ids are CLIENT-owned per LSP, so this is the id the client
1011
- * itself stamped on its last `didOpen` / `didChange` — never the shared
1012
- * server version, which advances on authored writes the client knows nothing
1013
- * about and would therefore reject every push.
1014
- *
1015
- * Falls back to {@link UNKNOWN_CLIENT_VERSION} when the client has never
1016
- * declared one, which is the honest answer for a document it has not opened.
1017
- * That is also the case in which there is no shadow, so the push is already a
1018
- * position-independent full replace and has nothing to gain from a gate.
1019
- */
1020
- protected languageClientVersion(uri: DocumentUri): number {
1021
- return this.__documents.get(this.documentKey(uri))?.clientVersions.get(LANGUAGE_CLIENT_ID) ?? UNKNOWN_CLIENT_VERSION;
1022
- }
1023
-
1024
- /**
1025
- * Append a push to the in-flight queue for `targetUri`
1026
- * (see {@link __pendingPushes}). Bounded: beyond
1027
- * {@link PENDING_ECHO_CAP} the oldest entry drops with a debug log — an
1028
- * echo that far outstanding means the client is not echoing at all, and
1029
- * an unbounded queue must not become the leak.
1030
- */
1031
- protected recordPendingPush(targetUri: LanguageClientUri, before: string | undefined, newText: string): void {
1032
- let pending = this.__pendingPushes.get(targetUri);
1033
- if (!pending) {
1034
- pending = [];
1035
- this.__pendingPushes.set(targetUri, pending);
1036
- }
1037
- pending.push({ before, afterHash: contentHash(newText) });
1038
- if (pending.length > PENDING_ECHO_CAP) {
1039
- pending.shift();
1040
- this.logUri(targetUri, `Pending-echo queue exceeded ${PENDING_ECHO_CAP} entries; dropped the oldest`, 'debug');
1041
- }
1042
- }
1043
-
1044
- /**
1045
- * Decide what an incoming language-client change actually is, by
1046
- * reconstructing the client's resulting buffer against the OLDEST push still
1047
- * in flight for `clientFacing`.
1048
- *
1049
- * `undefined` when nothing of ours is in flight, which is the ordinary path:
1050
- * the client's ranges then address the synced text and the caller applies
1051
- * them to it directly.
1052
- *
1053
- * **Why the oldest, and why reconstruct at all.** The client applies our
1054
- * pushes in order and echoes each against the buffer it held before that
1055
- * push, so the first echo to arrive belongs to the oldest entry — a FIFO
1056
- * correspondence the queue preserves by consuming from the front. Comparing
1057
- * the reconstruction against every pending hash, not only the oldest, is
1058
- * what recognises an echo that a newer write already superseded: a rapid
1059
- * write sequence can deliver the echo of push N after the store applied
1060
- * push N+1, and everything older is then accounted for too.
1061
- *
1062
- * A reconstruction matching NO pending push means the client's buffer went
1063
- * somewhere we did not send it — it coalesced a keystroke into the echo, or
1064
- * typed before the push landed. That text is authoritative, and the queue
1065
- * drops: the client has stopped being a pure mirror, so no outstanding echo
1066
- * can match again. (A push still in flight at that point will be refused by
1067
- * the client's own version gate, which invalidates the shadow and makes the
1068
- * next sync a position-independent full replace.)
1069
- *
1070
- * Content equality is a sound echo proof because entries live only between a
1071
- * push and its echo — a milliseconds window, never history — and the
1072
- * client's `didChange` stream is ordered, so every buffer state arrives in
1073
- * mutation order. An UNDO returning the buffer to previously-pushed text is
1074
- * therefore never swallowed: the edit that preceded it already emptied the
1075
- * queue, so undo revisits PAST states while the queue holds IN-FLIGHT ones.
1450
+ * Explicitly baseline the language-client shadow for a URI the client has
1451
+ * open, for an adopter that knows what the client holds without a
1452
+ * `didChange` saying so (e.g. after a sideband save). Normal didOpen /
1453
+ * didChange paths from the LSP language client already auto-track the
1454
+ * shadow. A seed for a URI the client has not opened is kept but changes no
1455
+ * push, since nothing is pushed there; its open replaces it with the text it
1456
+ * declares.
1076
1457
  */
1077
- protected classifyLanguageClientChange(
1078
- clientFacing: LanguageClientUri,
1079
- document: T,
1080
- changes: TextDocumentContentChangeEvent[]
1081
- ): LanguageClientChangeOrigin | undefined {
1082
- const pending = this.__pendingPushes.get(clientFacing);
1083
- if (pending === undefined || pending.length === 0) {
1084
- return undefined;
1085
- }
1086
- // Through the configured factories, not `TextDocument` directly, so an
1087
- // adopter's custom text-document type governs how the ranges are applied
1088
- // here exactly as it does on the synced document.
1089
- const probe = this.create(clientFacing, document.languageId, 0, pending[0].before ?? document.getText());
1090
- const clientText = this.update(probe, changes, 0).getText();
1091
- const matchIndex = pending.findIndex(push => push.afterHash === contentHash(clientText));
1092
- if (matchIndex >= 0) {
1093
- pending.splice(0, matchIndex + 1);
1094
- return { kind: 'echo' };
1095
- }
1096
- pending.length = 0;
1097
- return { kind: 'divergent', text: clientText };
1458
+ setLanguageClientText(uri: DocumentUri, text: string): void {
1459
+ this.languageClientShadow.setLanguageClientText(this.toLanguageClientUri(uri), text);
1098
1460
  }
1099
1461
 
1100
1462
  /**
1101
- * Explicitly baseline the language-client text shadow for a URI. Useful in
1102
- * tests and for adopters that need to seed the shadow without going through
1103
- * a `didOpen` event (e.g. after a sideband save). Normal didOpen / didChange
1104
- * paths from the LSP language client already auto-track the shadow.
1463
+ * Drop the shadow baseline for a URI; the next applyEditToLanguageClient
1464
+ * sends a full replace, or nothing when the client was last heard to hold
1465
+ * that text.
1105
1466
  */
1106
- setLanguageClientText(uri: DocumentUri, text: string): void {
1107
- const clientFacing = this.toLanguageClientUri(uri);
1108
- this.__shadow.set(clientFacing, text);
1109
- // An explicit rebaseline supersedes whatever was in flight.
1110
- this.__pendingPushes.delete(clientFacing);
1111
- }
1112
-
1113
- /** Drop the shadow baseline for a URI; the next applyEditToLanguageClient sends a full replace. */
1114
1467
  invalidateLanguageClientText(uri: DocumentUri): void {
1115
- const clientFacing = this.toLanguageClientUri(uri);
1116
- this.__shadow.invalidate(clientFacing);
1117
- this.__pendingPushes.delete(clientFacing);
1468
+ this.languageClientShadow.invalidateLanguageClientText(this.toLanguageClientUri(uri));
1118
1469
  }
1119
1470
 
1120
1471
  protected consumePendingContent(uri: DocumentUri): string | undefined {
1121
- const record = this.__documents.get(this.documentKey(uri));
1122
- const content = record?.pendingContent;
1123
- if (record) {
1124
- record.pendingContent = undefined;
1125
- }
1472
+ const key = this.documentKey(uri);
1473
+ const content = this.__pendingContent.get(key);
1474
+ this.__pendingContent.delete(key);
1126
1475
  return content;
1127
1476
  }
1128
1477