@hydranium/core 1.0.0-next.37 → 1.0.0-next.370

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 (787) hide show
  1. package/README.md +78 -82
  2. package/lib/browser/host-heads-in-worker.d.ts +77 -0
  3. package/lib/browser/host-heads-in-worker.d.ts.map +1 -0
  4. package/lib/browser/host-heads-in-worker.js +169 -0
  5. package/lib/browser/host-heads-in-worker.js.map +1 -0
  6. package/lib/browser/index.d.ts +12 -0
  7. package/lib/browser/index.d.ts.map +1 -0
  8. package/lib/browser/index.js +17 -0
  9. package/lib/browser/index.js.map +1 -0
  10. package/lib/browser/indexeddb-file-system-store.d.ts +82 -0
  11. package/lib/browser/indexeddb-file-system-store.d.ts.map +1 -0
  12. package/lib/browser/indexeddb-file-system-store.js +181 -0
  13. package/lib/browser/indexeddb-file-system-store.js.map +1 -0
  14. package/lib/browser/start-language-server-in-worker.d.ts +32 -0
  15. package/lib/browser/start-language-server-in-worker.d.ts.map +1 -0
  16. package/lib/browser/start-language-server-in-worker.js +40 -0
  17. package/lib/browser/start-language-server-in-worker.js.map +1 -0
  18. package/lib/documents/ast-document-manager.d.ts +254 -140
  19. package/lib/documents/ast-document-manager.d.ts.map +1 -1
  20. package/lib/documents/ast-document-manager.js +311 -127
  21. package/lib/documents/ast-document-manager.js.map +1 -1
  22. package/lib/documents/client-ids.d.ts +5 -19
  23. package/lib/documents/client-ids.d.ts.map +1 -1
  24. package/lib/documents/client-ids.js +5 -19
  25. package/lib/documents/client-ids.js.map +1 -1
  26. package/lib/documents/client-session-errors.d.ts +15 -0
  27. package/lib/documents/client-session-errors.d.ts.map +1 -0
  28. package/lib/documents/client-session-errors.js +15 -0
  29. package/lib/documents/client-session-errors.js.map +1 -0
  30. package/lib/documents/client-session-registry.d.ts +146 -0
  31. package/lib/documents/client-session-registry.d.ts.map +1 -0
  32. package/lib/documents/client-session-registry.js +207 -0
  33. package/lib/documents/client-session-registry.js.map +1 -0
  34. package/lib/documents/dirty-state-tracker.d.ts +101 -0
  35. package/lib/documents/dirty-state-tracker.d.ts.map +1 -0
  36. package/lib/documents/dirty-state-tracker.js +85 -0
  37. package/lib/documents/dirty-state-tracker.js.map +1 -0
  38. package/lib/documents/document-release-handler.d.ts +204 -0
  39. package/lib/documents/document-release-handler.d.ts.map +1 -0
  40. package/lib/documents/document-release-handler.js +317 -0
  41. package/lib/documents/document-release-handler.js.map +1 -0
  42. package/lib/documents/document-release-scheduler.d.ts +67 -0
  43. package/lib/documents/document-release-scheduler.d.ts.map +1 -0
  44. package/lib/documents/document-release-scheduler.js +80 -0
  45. package/lib/documents/document-release-scheduler.js.map +1 -0
  46. package/lib/documents/file-system-task-queue.d.ts +52 -0
  47. package/lib/documents/file-system-task-queue.d.ts.map +1 -0
  48. package/lib/documents/file-system-task-queue.js +37 -0
  49. package/lib/documents/file-system-task-queue.js.map +1 -0
  50. package/lib/documents/hydranium-text-documents.d.ts +445 -282
  51. package/lib/documents/hydranium-text-documents.d.ts.map +1 -1
  52. package/lib/documents/hydranium-text-documents.js +903 -483
  53. package/lib/documents/hydranium-text-documents.js.map +1 -1
  54. package/lib/documents/index.d.ts +10 -2
  55. package/lib/documents/index.d.ts.map +1 -1
  56. package/lib/documents/index.js +10 -2
  57. package/lib/documents/index.js.map +1 -1
  58. package/lib/documents/language-client-shadow.d.ts +234 -0
  59. package/lib/documents/language-client-shadow.d.ts.map +1 -0
  60. package/lib/documents/language-client-shadow.js +306 -0
  61. package/lib/documents/language-client-shadow.js.map +1 -0
  62. package/lib/documents/model-ledger.d.ts +47 -0
  63. package/lib/documents/model-ledger.d.ts.map +1 -0
  64. package/lib/documents/model-ledger.js +30 -0
  65. package/lib/documents/model-ledger.js.map +1 -0
  66. package/lib/documents/text-ledger.d.ts +64 -0
  67. package/lib/documents/text-ledger.d.ts.map +1 -0
  68. package/lib/documents/text-ledger.js +63 -0
  69. package/lib/documents/text-ledger.js.map +1 -0
  70. package/lib/documents/version-sync-service.d.ts +138 -0
  71. package/lib/documents/version-sync-service.d.ts.map +1 -0
  72. package/lib/documents/version-sync-service.js +173 -0
  73. package/lib/documents/version-sync-service.js.map +1 -0
  74. package/lib/index.d.ts +3 -0
  75. package/lib/index.d.ts.map +1 -1
  76. package/lib/index.js +3 -0
  77. package/lib/index.js.map +1 -1
  78. package/lib/langium/ast-extension/ast-extension-service.d.ts +42 -31
  79. package/lib/langium/ast-extension/ast-extension-service.d.ts.map +1 -1
  80. package/lib/langium/ast-extension/ast-extension-service.js +45 -19
  81. package/lib/langium/ast-extension/ast-extension-service.js.map +1 -1
  82. package/lib/langium/ast-extension/ast-node-builder.d.ts +12 -7
  83. package/lib/langium/ast-extension/ast-node-builder.d.ts.map +1 -1
  84. package/lib/langium/ast-extension/ast-node-builder.js +25 -9
  85. package/lib/langium/ast-extension/ast-node-builder.js.map +1 -1
  86. package/lib/langium/bootstrap.d.ts +49 -36
  87. package/lib/langium/bootstrap.d.ts.map +1 -1
  88. package/lib/langium/bootstrap.js +75 -36
  89. package/lib/langium/bootstrap.js.map +1 -1
  90. package/lib/langium/build-phase-pass/build-phase-pass-service.d.ts +9 -9
  91. package/lib/langium/build-phase-pass/build-phase-pass-service.d.ts.map +1 -1
  92. package/lib/langium/build-phase-pass/build-phase-pass-service.js +25 -16
  93. package/lib/langium/build-phase-pass/build-phase-pass-service.js.map +1 -1
  94. package/lib/langium/build-phase-pass/build-phase-pass.d.ts +20 -8
  95. package/lib/langium/build-phase-pass/build-phase-pass.d.ts.map +1 -1
  96. package/lib/langium/build-phase-pass/build-phase-pass.js +20 -0
  97. package/lib/langium/build-phase-pass/build-phase-pass.js.map +1 -1
  98. package/lib/langium/composite-ast-reflection.d.ts +46 -0
  99. package/lib/langium/composite-ast-reflection.d.ts.map +1 -0
  100. package/lib/langium/composite-ast-reflection.js +97 -0
  101. package/lib/langium/composite-ast-reflection.js.map +1 -0
  102. package/lib/langium/config/configuration-provider.d.ts +81 -0
  103. package/lib/langium/config/configuration-provider.d.ts.map +1 -0
  104. package/lib/langium/config/configuration-provider.js +112 -0
  105. package/lib/langium/config/configuration-provider.js.map +1 -0
  106. package/lib/langium/config/index.d.ts +1 -0
  107. package/lib/langium/config/index.d.ts.map +1 -1
  108. package/lib/langium/config/index.js +1 -0
  109. package/lib/langium/config/index.js.map +1 -1
  110. package/lib/langium/config/settings.js.map +1 -1
  111. package/lib/langium/diagnostics/console-tee.d.ts +27 -0
  112. package/lib/langium/diagnostics/console-tee.d.ts.map +1 -0
  113. package/lib/langium/diagnostics/console-tee.js +141 -0
  114. package/lib/langium/diagnostics/console-tee.js.map +1 -0
  115. package/lib/langium/diagnostics/hydranium-langium-profiler.d.ts +9 -20
  116. package/lib/langium/diagnostics/hydranium-langium-profiler.d.ts.map +1 -1
  117. package/lib/langium/diagnostics/hydranium-langium-profiler.js +15 -24
  118. package/lib/langium/diagnostics/hydranium-langium-profiler.js.map +1 -1
  119. package/lib/langium/diagnostics/log-preamble.js +1 -1
  120. package/lib/langium/diagnostics/log-preamble.js.map +1 -1
  121. package/lib/langium/diagnostics/logger.d.ts +25 -6
  122. package/lib/langium/diagnostics/logger.d.ts.map +1 -1
  123. package/lib/langium/diagnostics/logger.js +49 -17
  124. package/lib/langium/diagnostics/logger.js.map +1 -1
  125. package/lib/langium/diagnostics/lsp-logger.d.ts +25 -0
  126. package/lib/langium/diagnostics/lsp-logger.d.ts.map +1 -1
  127. package/lib/langium/diagnostics/lsp-logger.js +81 -46
  128. package/lib/langium/diagnostics/lsp-logger.js.map +1 -1
  129. package/lib/langium/diagnostics/server-tracer.d.ts.map +1 -1
  130. package/lib/langium/diagnostics/server-tracer.js.map +1 -1
  131. package/lib/langium/document-builder/build-pipeline-integration.d.ts +21 -1
  132. package/lib/langium/document-builder/build-pipeline-integration.d.ts.map +1 -1
  133. package/lib/langium/document-builder/build-pipeline-integration.js +43 -30
  134. package/lib/langium/document-builder/build-pipeline-integration.js.map +1 -1
  135. package/lib/langium/document-builder/build-session.d.ts +6 -5
  136. package/lib/langium/document-builder/build-session.d.ts.map +1 -1
  137. package/lib/langium/document-builder/build-session.js +5 -5
  138. package/lib/langium/document-builder/build-session.js.map +1 -1
  139. package/lib/langium/document-builder/document-builder.d.ts +308 -39
  140. package/lib/langium/document-builder/document-builder.d.ts.map +1 -1
  141. package/lib/langium/document-builder/document-builder.js +490 -79
  142. package/lib/langium/document-builder/document-builder.js.map +1 -1
  143. package/lib/langium/documentation/comment-provider.d.ts.map +1 -1
  144. package/lib/langium/documentation/comment-provider.js.map +1 -1
  145. package/lib/langium/integration-services.d.ts +39 -23
  146. package/lib/langium/integration-services.d.ts.map +1 -1
  147. package/lib/langium/integration-services.js +7 -4
  148. package/lib/langium/integration-services.js.map +1 -1
  149. package/lib/langium/integrity/integrity-rule.d.ts +17 -8
  150. package/lib/langium/integrity/integrity-rule.d.ts.map +1 -1
  151. package/lib/langium/integrity/integrity-rule.js.map +1 -1
  152. package/lib/langium/integrity/integrity-service.d.ts +95 -27
  153. package/lib/langium/integrity/integrity-service.d.ts.map +1 -1
  154. package/lib/langium/integrity/integrity-service.js +303 -63
  155. package/lib/langium/integrity/integrity-service.js.map +1 -1
  156. package/lib/langium/keys/containment.d.ts +3 -2
  157. package/lib/langium/keys/containment.d.ts.map +1 -1
  158. package/lib/langium/keys/containment.js.map +1 -1
  159. package/lib/langium/keys/name-based-key-provider.d.ts +17 -10
  160. package/lib/langium/keys/name-based-key-provider.d.ts.map +1 -1
  161. package/lib/langium/keys/name-based-key-provider.js +24 -12
  162. package/lib/langium/keys/name-based-key-provider.js.map +1 -1
  163. package/lib/langium/keys/positional-key-provider.d.ts.map +1 -1
  164. package/lib/langium/keys/positional-key-provider.js.map +1 -1
  165. package/lib/langium/labeling/label-provider.d.ts.map +1 -1
  166. package/lib/langium/labeling/label-provider.js.map +1 -1
  167. package/lib/langium/language-module.d.ts +30 -5
  168. package/lib/langium/language-module.d.ts.map +1 -1
  169. package/lib/langium/language-module.js +21 -5
  170. package/lib/langium/language-module.js.map +1 -1
  171. package/lib/langium/model-service/client-session.d.ts +383 -0
  172. package/lib/langium/model-service/client-session.d.ts.map +1 -0
  173. package/lib/langium/model-service/client-session.js +455 -0
  174. package/lib/langium/model-service/client-session.js.map +1 -0
  175. package/lib/langium/model-service/index.d.ts +2 -0
  176. package/lib/langium/model-service/index.d.ts.map +1 -1
  177. package/lib/langium/model-service/index.js +2 -0
  178. package/lib/langium/model-service/index.js.map +1 -1
  179. package/lib/langium/model-service/model-events.d.ts +68 -0
  180. package/lib/langium/model-service/model-events.d.ts.map +1 -0
  181. package/lib/langium/model-service/model-events.js +10 -0
  182. package/lib/langium/model-service/model-events.js.map +1 -0
  183. package/lib/langium/model-service/model-service.d.ts +440 -323
  184. package/lib/langium/model-service/model-service.d.ts.map +1 -1
  185. package/lib/langium/model-service/model-service.js +601 -397
  186. package/lib/langium/model-service/model-service.js.map +1 -1
  187. package/lib/langium/module.d.ts +89 -30
  188. package/lib/langium/module.d.ts.map +1 -1
  189. package/lib/langium/module.js +39 -27
  190. package/lib/langium/module.js.map +1 -1
  191. package/lib/langium/naming/name-provider.d.ts +32 -7
  192. package/lib/langium/naming/name-provider.d.ts.map +1 -1
  193. package/lib/langium/naming/name-provider.js +10 -4
  194. package/lib/langium/naming/name-provider.js.map +1 -1
  195. package/lib/langium/naming/name-separator-validation.d.ts.map +1 -1
  196. package/lib/langium/project/abstract-project-manager.d.ts.map +1 -1
  197. package/lib/langium/project/abstract-project-manager.js +13 -6
  198. package/lib/langium/project/abstract-project-manager.js.map +1 -1
  199. package/lib/langium/project/project-change-event.d.ts +2 -2
  200. package/lib/langium/project/single-project-manager.d.ts.map +1 -1
  201. package/lib/langium/project/single-project-manager.js.map +1 -1
  202. package/lib/langium/residency/cst-residency-service.d.ts +15 -11
  203. package/lib/langium/residency/cst-residency-service.d.ts.map +1 -1
  204. package/lib/langium/residency/cst-residency-service.js +15 -3
  205. package/lib/langium/residency/cst-residency-service.js.map +1 -1
  206. package/lib/langium/scope/ast-node-description-provider.d.ts +46 -10
  207. package/lib/langium/scope/ast-node-description-provider.d.ts.map +1 -1
  208. package/lib/langium/scope/ast-node-description-provider.js +88 -15
  209. package/lib/langium/scope/ast-node-description-provider.js.map +1 -1
  210. package/lib/langium/scope/built-local-symbols.d.ts +12 -0
  211. package/lib/langium/scope/built-local-symbols.d.ts.map +1 -0
  212. package/lib/langium/scope/built-local-symbols.js +11 -0
  213. package/lib/langium/scope/built-local-symbols.js.map +1 -0
  214. package/lib/langium/scope/fallback-scope.d.ts +27 -0
  215. package/lib/langium/scope/fallback-scope.d.ts.map +1 -0
  216. package/lib/langium/scope/fallback-scope.js +35 -0
  217. package/lib/langium/scope/fallback-scope.js.map +1 -0
  218. package/lib/langium/scope/hydranium-scope-computation.d.ts +21 -18
  219. package/lib/langium/scope/hydranium-scope-computation.d.ts.map +1 -1
  220. package/lib/langium/scope/hydranium-scope-computation.js +38 -39
  221. package/lib/langium/scope/hydranium-scope-computation.js.map +1 -1
  222. package/lib/langium/scope/hydranium-scope-provider.d.ts +122 -32
  223. package/lib/langium/scope/hydranium-scope-provider.d.ts.map +1 -1
  224. package/lib/langium/scope/hydranium-scope-provider.js +217 -39
  225. package/lib/langium/scope/hydranium-scope-provider.js.map +1 -1
  226. package/lib/langium/scope/index.d.ts +1 -0
  227. package/lib/langium/scope/index.d.ts.map +1 -1
  228. package/lib/langium/scope/index.js +1 -0
  229. package/lib/langium/scope/index.js.map +1 -1
  230. package/lib/langium/scope/reference-builder.d.ts.map +1 -1
  231. package/lib/langium/scope/reference-builder.js.map +1 -1
  232. package/lib/langium/scope/reference-candidate-provider.d.ts +6 -5
  233. package/lib/langium/scope/reference-candidate-provider.d.ts.map +1 -1
  234. package/lib/langium/scope/reference-candidate-provider.js +3 -2
  235. package/lib/langium/scope/reference-candidate-provider.js.map +1 -1
  236. package/lib/langium/scope/scope-extension-service.d.ts +69 -37
  237. package/lib/langium/scope/scope-extension-service.d.ts.map +1 -1
  238. package/lib/langium/scope/scope-extension-service.js +102 -29
  239. package/lib/langium/scope/scope-extension-service.js.map +1 -1
  240. package/lib/langium/scope/scoped-ast-node-description.d.ts +1 -3
  241. package/lib/langium/scope/scoped-ast-node-description.d.ts.map +1 -1
  242. package/lib/langium/scope/scoped-ast-node-description.js +1 -3
  243. package/lib/langium/scope/scoped-ast-node-description.js.map +1 -1
  244. package/lib/langium/serialization/abstract-serializer.d.ts +38 -27
  245. package/lib/langium/serialization/abstract-serializer.d.ts.map +1 -1
  246. package/lib/langium/serialization/abstract-serializer.js +54 -30
  247. package/lib/langium/serialization/abstract-serializer.js.map +1 -1
  248. package/lib/langium/serialization/json-serializer.d.ts +8 -1
  249. package/lib/langium/serialization/json-serializer.d.ts.map +1 -1
  250. package/lib/langium/serialization/json-serializer.js +13 -3
  251. package/lib/langium/serialization/json-serializer.js.map +1 -1
  252. package/lib/langium/serialization/serializer.d.ts +1 -1
  253. package/lib/langium/serialization/yaml-serializer.d.ts +12 -0
  254. package/lib/langium/serialization/yaml-serializer.d.ts.map +1 -1
  255. package/lib/langium/serialization/yaml-serializer.js +24 -4
  256. package/lib/langium/serialization/yaml-serializer.js.map +1 -1
  257. package/lib/langium/service-registry.d.ts +29 -1
  258. package/lib/langium/service-registry.d.ts.map +1 -1
  259. package/lib/langium/service-registry.js +37 -0
  260. package/lib/langium/service-registry.js.map +1 -1
  261. package/lib/langium/shared-services.d.ts +10 -4
  262. package/lib/langium/shared-services.d.ts.map +1 -1
  263. package/lib/langium/shared-services.js.map +1 -1
  264. package/lib/langium/single-langium-copy.d.ts +22 -0
  265. package/lib/langium/single-langium-copy.d.ts.map +1 -0
  266. package/lib/langium/single-langium-copy.js +36 -0
  267. package/lib/langium/single-langium-copy.js.map +1 -0
  268. package/lib/langium/transfer/transfer-encoder.d.ts +60 -39
  269. package/lib/langium/transfer/transfer-encoder.d.ts.map +1 -1
  270. package/lib/langium/transfer/transfer-encoder.js +35 -24
  271. package/lib/langium/transfer/transfer-encoder.js.map +1 -1
  272. package/lib/langium/trivia/comment-preserver.d.ts +543 -0
  273. package/lib/langium/trivia/comment-preserver.d.ts.map +1 -0
  274. package/lib/langium/trivia/comment-preserver.js +1164 -0
  275. package/lib/langium/trivia/comment-preserver.js.map +1 -0
  276. package/lib/langium/trivia/document-ending-preserver.d.ts +51 -0
  277. package/lib/langium/trivia/document-ending-preserver.d.ts.map +1 -0
  278. package/lib/langium/trivia/document-ending-preserver.js +62 -0
  279. package/lib/langium/trivia/document-ending-preserver.js.map +1 -0
  280. package/lib/langium/trivia/index.d.ts +14 -0
  281. package/lib/langium/trivia/index.d.ts.map +1 -0
  282. package/lib/langium/trivia/index.js +14 -0
  283. package/lib/langium/trivia/index.js.map +1 -0
  284. package/lib/langium/trivia/trivia-contribution.d.ts +37 -0
  285. package/lib/langium/trivia/trivia-contribution.d.ts.map +1 -0
  286. package/lib/langium/trivia/trivia-contribution.js +10 -0
  287. package/lib/langium/trivia/trivia-contribution.js.map +1 -0
  288. package/lib/langium/trivia/trivia-preserver.d.ts +52 -0
  289. package/lib/langium/trivia/trivia-preserver.d.ts.map +1 -0
  290. package/lib/langium/trivia/trivia-preserver.js +10 -0
  291. package/lib/langium/trivia/trivia-preserver.js.map +1 -0
  292. package/lib/langium/trivia/trivia-service.d.ts +70 -0
  293. package/lib/langium/trivia/trivia-service.d.ts.map +1 -0
  294. package/lib/langium/trivia/trivia-service.js +56 -0
  295. package/lib/langium/trivia/trivia-service.js.map +1 -0
  296. package/lib/langium/update-rewrite/normalize-empty-strings.d.ts.map +1 -1
  297. package/lib/langium/update-rewrite/update-rewrite-service.d.ts +1 -1
  298. package/lib/langium/update-rewrite/update-rewrite-service.d.ts.map +1 -1
  299. package/lib/langium/update-rewrite/update-rewrite-service.js.map +1 -1
  300. package/lib/langium/update-rewrite/update-rewrite.d.ts +1 -1
  301. package/lib/langium/validation/document-validator.d.ts +168 -23
  302. package/lib/langium/validation/document-validator.d.ts.map +1 -1
  303. package/lib/langium/validation/document-validator.js +264 -26
  304. package/lib/langium/validation/document-validator.js.map +1 -1
  305. package/lib/langium/validation/validation-contribution-collector.d.ts +9 -1
  306. package/lib/langium/validation/validation-contribution-collector.d.ts.map +1 -1
  307. package/lib/langium/validation/validation-contribution-collector.js +1 -1
  308. package/lib/langium/validation/validation-contribution-collector.js.map +1 -1
  309. package/lib/langium/workspace/ast-node-locator.d.ts +24 -0
  310. package/lib/langium/workspace/ast-node-locator.d.ts.map +1 -0
  311. package/lib/langium/workspace/ast-node-locator.js +32 -0
  312. package/lib/langium/workspace/ast-node-locator.js.map +1 -0
  313. package/lib/langium/workspace/document-uri-policy.d.ts +24 -15
  314. package/lib/langium/workspace/document-uri-policy.d.ts.map +1 -1
  315. package/lib/langium/workspace/document-uri-policy.js +22 -13
  316. package/lib/langium/workspace/document-uri-policy.js.map +1 -1
  317. package/lib/langium/workspace/file-not-found.d.ts +23 -0
  318. package/lib/langium/workspace/file-not-found.d.ts.map +1 -0
  319. package/lib/langium/workspace/file-not-found.js +31 -0
  320. package/lib/langium/workspace/file-not-found.js.map +1 -0
  321. package/lib/langium/workspace/file-system-provider.d.ts +167 -8
  322. package/lib/langium/workspace/file-system-provider.d.ts.map +1 -1
  323. package/lib/langium/workspace/file-system-provider.js +115 -13
  324. package/lib/langium/workspace/file-system-provider.js.map +1 -1
  325. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts +31 -1
  326. package/lib/langium/workspace/hydranium-langium-document-factory.d.ts.map +1 -1
  327. package/lib/langium/workspace/hydranium-langium-document-factory.js +54 -0
  328. package/lib/langium/workspace/hydranium-langium-document-factory.js.map +1 -1
  329. package/lib/langium/workspace/hydranium-workspace-lock.d.ts +43 -1
  330. package/lib/langium/workspace/hydranium-workspace-lock.d.ts.map +1 -1
  331. package/lib/langium/workspace/hydranium-workspace-lock.js +58 -1
  332. package/lib/langium/workspace/hydranium-workspace-lock.js.map +1 -1
  333. package/lib/langium/workspace/hydranium-workspace-manager.d.ts +103 -21
  334. package/lib/langium/workspace/hydranium-workspace-manager.d.ts.map +1 -1
  335. package/lib/langium/workspace/hydranium-workspace-manager.js +184 -31
  336. package/lib/langium/workspace/hydranium-workspace-manager.js.map +1 -1
  337. package/lib/langium/workspace/in-memory-file-system-provider.d.ts +26 -9
  338. package/lib/langium/workspace/in-memory-file-system-provider.d.ts.map +1 -1
  339. package/lib/langium/workspace/in-memory-file-system-provider.js +45 -22
  340. package/lib/langium/workspace/in-memory-file-system-provider.js.map +1 -1
  341. package/lib/langium/workspace/index-manager.d.ts.map +1 -1
  342. package/lib/langium/workspace/index-manager.js.map +1 -1
  343. package/lib/langium/workspace/index.d.ts +2 -0
  344. package/lib/langium/workspace/index.d.ts.map +1 -1
  345. package/lib/langium/workspace/index.js +2 -0
  346. package/lib/langium/workspace/index.js.map +1 -1
  347. package/lib/langium/workspace/initialize-workspace.d.ts +40 -3
  348. package/lib/langium/workspace/initialize-workspace.d.ts.map +1 -1
  349. package/lib/langium/workspace/initialize-workspace.js +68 -3
  350. package/lib/langium/workspace/initialize-workspace.js.map +1 -1
  351. package/lib/langium/workspace/langium-documents.d.ts +7 -0
  352. package/lib/langium/workspace/langium-documents.d.ts.map +1 -1
  353. package/lib/langium/workspace/langium-documents.js +18 -1
  354. package/lib/langium/workspace/langium-documents.js.map +1 -1
  355. package/lib/langium/workspace/persistent-file-system-provider.d.ts +16 -10
  356. package/lib/langium/workspace/persistent-file-system-provider.d.ts.map +1 -1
  357. package/lib/langium/workspace/persistent-file-system-provider.js +25 -13
  358. package/lib/langium/workspace/persistent-file-system-provider.js.map +1 -1
  359. package/lib/{documents → langium/workspace}/self-save-registry.d.ts +7 -9
  360. package/lib/langium/workspace/self-save-registry.d.ts.map +1 -0
  361. package/lib/{documents → langium/workspace}/self-save-registry.js +9 -11
  362. package/lib/langium/workspace/self-save-registry.js.map +1 -0
  363. package/lib/langium/workspace/virtual-document.d.ts +55 -21
  364. package/lib/langium/workspace/virtual-document.d.ts.map +1 -1
  365. package/lib/langium/workspace/virtual-document.js +87 -24
  366. package/lib/langium/workspace/virtual-document.js.map +1 -1
  367. package/lib/langium/workspace/write-lock-scope.d.ts +22 -10
  368. package/lib/langium/workspace/write-lock-scope.d.ts.map +1 -1
  369. package/lib/langium/workspace/write-lock-scope.js +15 -5
  370. package/lib/langium/workspace/write-lock-scope.js.map +1 -1
  371. package/lib/launcher/integrated-server.d.ts +3 -1
  372. package/lib/launcher/integrated-server.d.ts.map +1 -1
  373. package/lib/locale/server-locale.d.ts +6 -6
  374. package/lib/locale/server-locale.d.ts.map +1 -1
  375. package/lib/locale/server-locale.js.map +1 -1
  376. package/lib/lsp/completion/hydranium-completion-provider.d.ts +44 -2
  377. package/lib/lsp/completion/hydranium-completion-provider.d.ts.map +1 -1
  378. package/lib/lsp/completion/hydranium-completion-provider.js +68 -0
  379. package/lib/lsp/completion/hydranium-completion-provider.js.map +1 -1
  380. package/lib/lsp/connection-features.d.ts +23 -0
  381. package/lib/lsp/connection-features.d.ts.map +1 -0
  382. package/lib/lsp/connection-features.js +60 -0
  383. package/lib/lsp/connection-features.js.map +1 -0
  384. package/lib/lsp/diagnostics-connection.d.ts +27 -0
  385. package/lib/lsp/diagnostics-connection.d.ts.map +1 -0
  386. package/lib/lsp/diagnostics-connection.js +53 -0
  387. package/lib/lsp/diagnostics-connection.js.map +1 -0
  388. package/lib/lsp/edit-requests-guard.d.ts +31 -0
  389. package/lib/lsp/edit-requests-guard.d.ts.map +1 -0
  390. package/lib/lsp/edit-requests-guard.js +125 -0
  391. package/lib/lsp/edit-requests-guard.js.map +1 -0
  392. package/lib/lsp/hydranium-document-update-handler.d.ts +126 -82
  393. package/lib/lsp/hydranium-document-update-handler.d.ts.map +1 -1
  394. package/lib/lsp/hydranium-document-update-handler.js +234 -101
  395. package/lib/lsp/hydranium-document-update-handler.js.map +1 -1
  396. package/lib/lsp/index.d.ts +6 -2
  397. package/lib/lsp/index.d.ts.map +1 -1
  398. package/lib/lsp/index.js +6 -2
  399. package/lib/lsp/index.js.map +1 -1
  400. package/lib/lsp/lsp-latency.d.ts +39 -0
  401. package/lib/lsp/lsp-latency.d.ts.map +1 -0
  402. package/lib/lsp/lsp-latency.js +58 -0
  403. package/lib/lsp/lsp-latency.js.map +1 -0
  404. package/lib/lsp/save-text-document.d.ts +31 -0
  405. package/lib/lsp/save-text-document.d.ts.map +1 -0
  406. package/lib/lsp/save-text-document.js +52 -0
  407. package/lib/lsp/save-text-document.js.map +1 -0
  408. package/lib/lsp/semantic-token-provider.d.ts +58 -2
  409. package/lib/lsp/semantic-token-provider.d.ts.map +1 -1
  410. package/lib/lsp/semantic-token-provider.js +98 -9
  411. package/lib/lsp/semantic-token-provider.js.map +1 -1
  412. package/lib/lsp/shared-module.d.ts +4 -8
  413. package/lib/lsp/shared-module.d.ts.map +1 -1
  414. package/lib/lsp/shared-module.js.map +1 -1
  415. package/lib/lsp/start-language-server.d.ts +12 -7
  416. package/lib/lsp/start-language-server.d.ts.map +1 -1
  417. package/lib/lsp/start-language-server.js +21 -7
  418. package/lib/lsp/start-language-server.js.map +1 -1
  419. package/lib/messages/carriers.d.ts +4 -6
  420. package/lib/messages/carriers.d.ts.map +1 -1
  421. package/lib/messages/carriers.js +4 -6
  422. package/lib/messages/carriers.js.map +1 -1
  423. package/lib/messages/index.d.ts +2 -2
  424. package/lib/messages/index.d.ts.map +1 -1
  425. package/lib/messages/index.js +2 -2
  426. package/lib/messages/index.js.map +1 -1
  427. package/lib/messages/renderer.d.ts +10 -4
  428. package/lib/messages/renderer.d.ts.map +1 -1
  429. package/lib/messages/renderer.js +6 -0
  430. package/lib/messages/renderer.js.map +1 -1
  431. package/lib/node/event-loop-monitor.d.ts.map +1 -1
  432. package/lib/node/event-loop-monitor.js +2 -1
  433. package/lib/node/event-loop-monitor.js.map +1 -1
  434. package/lib/node/heap-ceiling.d.ts +61 -0
  435. package/lib/node/heap-ceiling.d.ts.map +1 -0
  436. package/lib/node/heap-ceiling.js +72 -0
  437. package/lib/node/heap-ceiling.js.map +1 -0
  438. package/lib/node/index.d.ts +1 -1
  439. package/lib/node/index.d.ts.map +1 -1
  440. package/lib/node/index.js +5 -1
  441. package/lib/node/index.js.map +1 -1
  442. package/lib/node/latency-from-env.d.ts +1 -1
  443. package/lib/node/latency-from-env.js +1 -1
  444. package/lib/node/lint-grammar.js.map +1 -1
  445. package/lib/node/log-file-sink.d.ts +3 -2
  446. package/lib/node/log-file-sink.d.ts.map +1 -1
  447. package/lib/node/log-file-sink.js +6 -2
  448. package/lib/node/log-file-sink.js.map +1 -1
  449. package/lib/node/log-preamble-node.d.ts +5 -3
  450. package/lib/node/log-preamble-node.d.ts.map +1 -1
  451. package/lib/node/log-preamble-node.js +13 -10
  452. package/lib/node/log-preamble-node.js.map +1 -1
  453. package/lib/node/measure-memory.d.ts.map +1 -1
  454. package/lib/node/measure-memory.js +5 -4
  455. package/lib/node/measure-memory.js.map +1 -1
  456. package/lib/node/memory-monitor.d.ts +2 -2
  457. package/lib/node/memory-monitor.d.ts.map +1 -1
  458. package/lib/node/memory-monitor.js +9 -10
  459. package/lib/node/memory-monitor.js.map +1 -1
  460. package/lib/node/node-file-system-provider.d.ts +67 -9
  461. package/lib/node/node-file-system-provider.d.ts.map +1 -1
  462. package/lib/node/node-file-system-provider.js +198 -53
  463. package/lib/node/node-file-system-provider.js.map +1 -1
  464. package/lib/node/profile-capture.d.ts +12 -4
  465. package/lib/node/profile-capture.d.ts.map +1 -1
  466. package/lib/node/profile-capture.js +8 -6
  467. package/lib/node/profile-capture.js.map +1 -1
  468. package/lib/node/profile-digest.js.map +1 -1
  469. package/lib/node/profiling-run.d.ts +13 -3
  470. package/lib/node/profiling-run.d.ts.map +1 -1
  471. package/lib/node/profiling-run.js +17 -8
  472. package/lib/node/profiling-run.js.map +1 -1
  473. package/lib/node/rename-over-open-readers.d.ts +61 -0
  474. package/lib/node/rename-over-open-readers.d.ts.map +1 -0
  475. package/lib/node/rename-over-open-readers.js +80 -0
  476. package/lib/node/rename-over-open-readers.js.map +1 -0
  477. package/lib/node/server-diagnostics.js +1 -1
  478. package/lib/node/server-diagnostics.js.map +1 -1
  479. package/lib/node/server-state-snapshot.js +4 -4
  480. package/lib/node/server-state-snapshot.js.map +1 -1
  481. package/lib/node/socket-launcher.d.ts +43 -7
  482. package/lib/node/socket-launcher.d.ts.map +1 -1
  483. package/lib/node/socket-launcher.js +42 -7
  484. package/lib/node/socket-launcher.js.map +1 -1
  485. package/lib/node/startup-cpu-profile.d.ts +29 -0
  486. package/lib/node/startup-cpu-profile.d.ts.map +1 -0
  487. package/lib/node/startup-cpu-profile.js +91 -0
  488. package/lib/node/startup-cpu-profile.js.map +1 -0
  489. package/lib/node/stdio-launcher.d.ts +13 -13
  490. package/lib/node/stdio-launcher.d.ts.map +1 -1
  491. package/lib/node/stdio-launcher.js +21 -11
  492. package/lib/node/stdio-launcher.js.map +1 -1
  493. package/lib/node/validate-workspace.d.ts +1 -1
  494. package/lib/node/validate-workspace.d.ts.map +1 -1
  495. package/lib/node/validate-workspace.js +5 -1
  496. package/lib/node/validate-workspace.js.map +1 -1
  497. package/lib/testing/document-uri-policy-conformance.js +1 -1
  498. package/lib/testing/document-uri-policy-conformance.js.map +1 -1
  499. package/lib/testing/fake-description.js.map +1 -1
  500. package/lib/testing/fake-document.d.ts +2 -1
  501. package/lib/testing/fake-document.d.ts.map +1 -1
  502. package/lib/testing/fake-document.js.map +1 -1
  503. package/lib/testing/index.d.ts +1 -1
  504. package/lib/testing/index.d.ts.map +1 -1
  505. package/lib/testing/index.js +2 -1
  506. package/lib/testing/index.js.map +1 -1
  507. package/lib/testing/langium-test-helpers.d.ts.map +1 -1
  508. package/lib/testing/langium-test-helpers.js +1 -0
  509. package/lib/testing/langium-test-helpers.js.map +1 -1
  510. package/lib/testing/make-noop-language-services.js.map +1 -1
  511. package/lib/testing/make-noop-shared-services.js.map +1 -1
  512. package/lib/testing/make-test-services.d.ts +45 -14
  513. package/lib/testing/make-test-services.d.ts.map +1 -1
  514. package/lib/testing/make-test-services.js +23 -7
  515. package/lib/testing/make-test-services.js.map +1 -1
  516. package/lib/testing/make-test-tracer.d.ts +12 -0
  517. package/lib/testing/make-test-tracer.d.ts.map +1 -1
  518. package/lib/testing/make-test-tracer.js +13 -0
  519. package/lib/testing/make-test-tracer.js.map +1 -1
  520. package/lib/testing/node/applied-edit-capture.d.ts +29 -0
  521. package/lib/testing/node/applied-edit-capture.d.ts.map +1 -0
  522. package/lib/testing/node/applied-edit-capture.js +117 -0
  523. package/lib/testing/node/applied-edit-capture.js.map +1 -0
  524. package/lib/testing/node/golden-corpus.js.map +1 -1
  525. package/lib/testing/node/index.d.ts +1 -0
  526. package/lib/testing/node/index.d.ts.map +1 -1
  527. package/lib/testing/node/index.js +1 -0
  528. package/lib/testing/node/index.js.map +1 -1
  529. package/lib/testing/node/lsp-harness.d.ts.map +1 -1
  530. package/lib/testing/node/lsp-harness.js +2 -0
  531. package/lib/testing/node/lsp-harness.js.map +1 -1
  532. package/lib/testing/node/lsp-server-connection.d.ts +21 -6
  533. package/lib/testing/node/lsp-server-connection.d.ts.map +1 -1
  534. package/lib/testing/node/lsp-server-connection.js +49 -106
  535. package/lib/testing/node/lsp-server-connection.js.map +1 -1
  536. package/lib/testing/node/scratch-workspace.d.ts.map +1 -1
  537. package/lib/testing/node/scratch-workspace.js +10 -5
  538. package/lib/testing/node/scratch-workspace.js.map +1 -1
  539. package/lib/testing/node/spawned-server.d.ts +30 -1
  540. package/lib/testing/node/spawned-server.d.ts.map +1 -1
  541. package/lib/testing/node/spawned-server.js +39 -2
  542. package/lib/testing/node/spawned-server.js.map +1 -1
  543. package/lib/testing/node/unhandled-rejections.d.ts +20 -0
  544. package/lib/testing/node/unhandled-rejections.d.ts.map +1 -0
  545. package/lib/testing/node/unhandled-rejections.js +32 -0
  546. package/lib/testing/node/unhandled-rejections.js.map +1 -0
  547. package/lib/testing/playwright/browser-capture-bridge.js.map +1 -1
  548. package/lib/testing/playwright/e2e-profiling.js.map +1 -1
  549. package/lib/testing/playwright/flaky-network-proxy.d.ts +76 -0
  550. package/lib/testing/playwright/flaky-network-proxy.d.ts.map +1 -0
  551. package/lib/testing/playwright/flaky-network-proxy.js +164 -0
  552. package/lib/testing/playwright/flaky-network-proxy.js.map +1 -0
  553. package/lib/testing/playwright/index.d.ts +1 -0
  554. package/lib/testing/playwright/index.d.ts.map +1 -1
  555. package/lib/testing/playwright/index.js +1 -0
  556. package/lib/testing/playwright/index.js.map +1 -1
  557. package/lib/testing/playwright/server-log-capture.d.ts +46 -16
  558. package/lib/testing/playwright/server-log-capture.d.ts.map +1 -1
  559. package/lib/testing/playwright/server-log-capture.js +111 -40
  560. package/lib/testing/playwright/server-log-capture.js.map +1 -1
  561. package/lib/testing/playwright/server-log-fixture.d.ts +16 -0
  562. package/lib/testing/playwright/server-log-fixture.d.ts.map +1 -1
  563. package/lib/testing/playwright/server-log-fixture.js +25 -6
  564. package/lib/testing/playwright/server-log-fixture.js.map +1 -1
  565. package/lib/testing/playwright/server-log-region.d.ts +15 -0
  566. package/lib/testing/playwright/server-log-region.d.ts.map +1 -0
  567. package/lib/testing/playwright/server-log-region.js +30 -0
  568. package/lib/testing/playwright/server-log-region.js.map +1 -0
  569. package/lib/testing/playwright/server-log-rename-reporter.d.ts.map +1 -1
  570. package/lib/testing/playwright/server-log-rename-reporter.js +4 -3
  571. package/lib/testing/playwright/server-log-rename-reporter.js.map +1 -1
  572. package/lib/testing/run-update-pipeline.d.ts +8 -5
  573. package/lib/testing/run-update-pipeline.d.ts.map +1 -1
  574. package/lib/testing/run-update-pipeline.js.map +1 -1
  575. package/lib/testing/stub-ast-document-manager.d.ts +11 -51
  576. package/lib/testing/stub-ast-document-manager.d.ts.map +1 -1
  577. package/lib/testing/stub-ast-document-manager.js +31 -59
  578. package/lib/testing/stub-ast-document-manager.js.map +1 -1
  579. package/lib/testing/stub-document-builder.d.ts +33 -11
  580. package/lib/testing/stub-document-builder.d.ts.map +1 -1
  581. package/lib/testing/stub-document-builder.js +103 -5
  582. package/lib/testing/stub-document-builder.js.map +1 -1
  583. package/lib/testing/stub-hydranium-text-documents.d.ts +33 -10
  584. package/lib/testing/stub-hydranium-text-documents.d.ts.map +1 -1
  585. package/lib/testing/stub-hydranium-text-documents.js +132 -16
  586. package/lib/testing/stub-hydranium-text-documents.js.map +1 -1
  587. package/lib/testing/stub-index-manager.js.map +1 -1
  588. package/lib/testing/stub-langium-documents.d.ts +3 -2
  589. package/lib/testing/stub-langium-documents.d.ts.map +1 -1
  590. package/lib/testing/stub-langium-documents.js.map +1 -1
  591. package/lib/testing/stub-model-service.d.ts +8 -7
  592. package/lib/testing/stub-model-service.d.ts.map +1 -1
  593. package/lib/testing/stub-model-service.js +4 -4
  594. package/lib/testing/stub-model-service.js.map +1 -1
  595. package/lib/testing/stub-project-manager.js.map +1 -1
  596. package/lib/testing/stub-self-save-registry.d.ts +1 -1
  597. package/lib/testing/stub-self-save-registry.d.ts.map +1 -1
  598. package/lib/testing/stub-service-registry.d.ts +1 -1
  599. package/lib/testing/stub-service-registry.js.map +1 -1
  600. package/lib/testing/stub-writable-file-system.d.ts +1 -1
  601. package/lib/testing/stub-writable-file-system.d.ts.map +1 -1
  602. package/lib/testing/stub-writable-file-system.js +2 -1
  603. package/lib/testing/stub-writable-file-system.js.map +1 -1
  604. package/lib/util/connection-liveness.d.ts +22 -6
  605. package/lib/util/connection-liveness.d.ts.map +1 -1
  606. package/lib/util/connection-liveness.js +75 -15
  607. package/lib/util/connection-liveness.js.map +1 -1
  608. package/lib/util/environment.d.ts +7 -0
  609. package/lib/util/environment.d.ts.map +1 -1
  610. package/lib/util/environment.js +15 -1
  611. package/lib/util/environment.js.map +1 -1
  612. package/lib/util/registry.d.ts.map +1 -1
  613. package/package.json +41 -60
  614. package/src/browser/host-heads-in-worker.ts +218 -0
  615. package/src/browser/index.ts +17 -0
  616. package/src/browser/indexeddb-file-system-store.ts +192 -0
  617. package/src/browser/start-language-server-in-worker.ts +56 -0
  618. package/src/documents/ast-document-manager.ts +477 -249
  619. package/src/documents/client-ids.ts +5 -22
  620. package/src/documents/client-session-errors.ts +24 -0
  621. package/src/documents/client-session-registry.ts +262 -0
  622. package/src/documents/dirty-state-tracker.ts +167 -0
  623. package/src/documents/document-release-handler.ts +404 -0
  624. package/src/documents/document-release-scheduler.ts +121 -0
  625. package/src/documents/file-system-task-queue.ts +74 -0
  626. package/src/documents/hydranium-text-documents.ts +1029 -595
  627. package/src/documents/index.ts +10 -2
  628. package/src/documents/language-client-shadow.ts +501 -0
  629. package/src/documents/model-ledger.ts +66 -0
  630. package/src/documents/text-ledger.ts +112 -0
  631. package/src/documents/version-sync-service.ts +275 -0
  632. package/src/index.ts +3 -0
  633. package/src/langium/ast-extension/ast-extension-service.ts +77 -41
  634. package/src/langium/ast-extension/ast-node-builder.ts +35 -13
  635. package/src/langium/bootstrap.ts +79 -43
  636. package/src/langium/build-phase-pass/build-phase-pass-service.ts +29 -19
  637. package/src/langium/build-phase-pass/build-phase-pass.ts +37 -8
  638. package/src/langium/composite-ast-reflection.ts +112 -0
  639. package/src/langium/config/configuration-provider.ts +119 -0
  640. package/src/langium/config/index.ts +1 -0
  641. package/src/langium/diagnostics/console-tee.ts +150 -0
  642. package/src/langium/diagnostics/hydranium-langium-profiler.ts +15 -39
  643. package/src/langium/diagnostics/log-preamble.ts +1 -1
  644. package/src/langium/diagnostics/logger.ts +51 -17
  645. package/src/langium/diagnostics/lsp-logger.ts +83 -45
  646. package/src/langium/document-builder/build-pipeline-integration.ts +57 -32
  647. package/src/langium/document-builder/build-session.ts +4 -3
  648. package/src/langium/document-builder/document-builder.ts +613 -77
  649. package/src/langium/integration-services.ts +58 -27
  650. package/src/langium/integrity/integrity-rule.ts +17 -8
  651. package/src/langium/integrity/integrity-service.ts +332 -69
  652. package/src/langium/keys/containment.ts +3 -2
  653. package/src/langium/keys/name-based-key-provider.ts +24 -12
  654. package/src/langium/language-module.ts +52 -9
  655. package/src/langium/model-service/client-session.ts +726 -0
  656. package/src/langium/model-service/index.ts +2 -0
  657. package/src/langium/model-service/model-events.ts +82 -0
  658. package/src/langium/model-service/model-service.ts +887 -522
  659. package/src/langium/module.ts +132 -56
  660. package/src/langium/naming/name-provider.ts +34 -8
  661. package/src/langium/project/abstract-project-manager.ts +13 -5
  662. package/src/langium/project/project-change-event.ts +2 -2
  663. package/src/langium/residency/cst-residency-service.ts +30 -14
  664. package/src/langium/scope/ast-node-description-provider.ts +111 -16
  665. package/src/langium/scope/built-local-symbols.ts +13 -0
  666. package/src/langium/scope/fallback-scope.ts +38 -0
  667. package/src/langium/scope/hydranium-scope-computation.ts +45 -44
  668. package/src/langium/scope/hydranium-scope-provider.ts +245 -41
  669. package/src/langium/scope/index.ts +1 -0
  670. package/src/langium/scope/reference-candidate-provider.ts +6 -5
  671. package/src/langium/scope/scope-extension-service.ts +148 -56
  672. package/src/langium/scope/scoped-ast-node-description.ts +1 -3
  673. package/src/langium/serialization/abstract-serializer.ts +57 -41
  674. package/src/langium/serialization/json-serializer.ts +14 -3
  675. package/src/langium/serialization/serializer.ts +1 -1
  676. package/src/langium/serialization/yaml-serializer.ts +26 -4
  677. package/src/langium/service-registry.ts +41 -2
  678. package/src/langium/shared-services.ts +13 -4
  679. package/src/langium/single-langium-copy.ts +42 -0
  680. package/src/langium/transfer/transfer-encoder.ts +76 -50
  681. package/src/langium/trivia/comment-preserver.ts +1409 -0
  682. package/src/langium/trivia/document-ending-preserver.ts +71 -0
  683. package/src/langium/trivia/index.ts +14 -0
  684. package/src/langium/trivia/trivia-contribution.ts +39 -0
  685. package/src/langium/trivia/trivia-preserver.ts +56 -0
  686. package/src/langium/trivia/trivia-service.ts +99 -0
  687. package/src/langium/update-rewrite/update-rewrite-service.ts +1 -1
  688. package/src/langium/update-rewrite/update-rewrite.ts +1 -1
  689. package/src/langium/validation/document-validator.ts +312 -31
  690. package/src/langium/validation/validation-contribution-collector.ts +10 -1
  691. package/src/langium/workspace/ast-node-locator.ts +33 -0
  692. package/src/langium/workspace/document-uri-policy.ts +32 -18
  693. package/src/langium/workspace/file-not-found.ts +35 -0
  694. package/src/langium/workspace/file-system-provider.ts +258 -16
  695. package/src/langium/workspace/hydranium-langium-document-factory.ts +83 -0
  696. package/src/langium/workspace/hydranium-workspace-lock.ts +86 -2
  697. package/src/langium/workspace/hydranium-workspace-manager.ts +212 -35
  698. package/src/langium/workspace/in-memory-file-system-provider.ts +54 -23
  699. package/src/langium/workspace/index.ts +2 -0
  700. package/src/langium/workspace/initialize-workspace.ts +96 -4
  701. package/src/langium/workspace/langium-documents.ts +19 -1
  702. package/src/langium/workspace/persistent-file-system-provider.ts +27 -15
  703. package/src/{documents → langium/workspace}/self-save-registry.ts +12 -14
  704. package/src/langium/workspace/virtual-document.ts +106 -25
  705. package/src/langium/workspace/write-lock-scope.ts +27 -12
  706. package/src/launcher/integrated-server.ts +3 -1
  707. package/src/locale/server-locale.ts +6 -6
  708. package/src/lsp/completion/hydranium-completion-provider.ts +82 -2
  709. package/src/lsp/connection-features.ts +67 -0
  710. package/src/lsp/diagnostics-connection.ts +56 -0
  711. package/src/lsp/edit-requests-guard.ts +152 -0
  712. package/src/lsp/hydranium-document-update-handler.ts +284 -110
  713. package/src/lsp/index.ts +6 -2
  714. package/src/lsp/lsp-latency.ts +62 -0
  715. package/src/lsp/save-text-document.ts +63 -0
  716. package/src/lsp/semantic-token-provider.ts +146 -8
  717. package/src/lsp/shared-module.ts +4 -8
  718. package/src/lsp/start-language-server.ts +21 -7
  719. package/src/messages/carriers.ts +4 -6
  720. package/src/messages/index.ts +11 -2
  721. package/src/messages/renderer.ts +11 -3
  722. package/src/node/event-loop-monitor.ts +2 -1
  723. package/src/node/heap-ceiling.ts +108 -0
  724. package/src/node/index.ts +5 -1
  725. package/src/node/latency-from-env.ts +1 -1
  726. package/src/node/log-file-sink.ts +6 -2
  727. package/src/node/log-preamble-node.ts +20 -10
  728. package/src/node/measure-memory.ts +5 -4
  729. package/src/node/memory-monitor.ts +10 -10
  730. package/src/node/node-file-system-provider.ts +214 -57
  731. package/src/node/profile-capture.ts +16 -15
  732. package/src/node/profiling-run.ts +30 -8
  733. package/src/node/rename-over-open-readers.ts +94 -0
  734. package/src/node/server-diagnostics.ts +1 -1
  735. package/src/node/server-state-snapshot.ts +5 -5
  736. package/src/node/socket-launcher.ts +78 -14
  737. package/src/node/startup-cpu-profile.ts +94 -0
  738. package/src/node/stdio-launcher.ts +29 -19
  739. package/src/node/validate-workspace.ts +8 -2
  740. package/src/testing/document-uri-policy-conformance.ts +1 -1
  741. package/src/testing/fake-document.ts +2 -1
  742. package/src/testing/index.ts +2 -1
  743. package/src/testing/langium-test-helpers.ts +1 -0
  744. package/src/testing/make-test-services.ts +83 -31
  745. package/src/testing/make-test-tracer.ts +26 -0
  746. package/src/testing/node/applied-edit-capture.ts +141 -0
  747. package/src/testing/node/index.ts +1 -0
  748. package/src/testing/node/lsp-harness.ts +2 -0
  749. package/src/testing/node/lsp-server-connection.ts +83 -119
  750. package/src/testing/node/scratch-workspace.ts +10 -5
  751. package/src/testing/node/spawned-server.ts +57 -3
  752. package/src/testing/node/unhandled-rejections.ts +31 -0
  753. package/src/testing/parse-semantic-root.ts +1 -1
  754. package/src/testing/playwright/flaky-network-proxy.ts +240 -0
  755. package/src/testing/playwright/index.ts +1 -0
  756. package/src/testing/playwright/server-log-capture.ts +137 -47
  757. package/src/testing/playwright/server-log-fixture.ts +46 -6
  758. package/src/testing/playwright/server-log-region.ts +32 -0
  759. package/src/testing/playwright/server-log-rename-reporter.ts +4 -3
  760. package/src/testing/run-update-pipeline.ts +8 -5
  761. package/src/testing/stub-ast-document-manager.ts +47 -123
  762. package/src/testing/stub-document-builder.ts +138 -18
  763. package/src/testing/stub-hydranium-text-documents.ts +184 -27
  764. package/src/testing/stub-langium-documents.ts +3 -2
  765. package/src/testing/stub-model-service.ts +9 -8
  766. package/src/testing/stub-self-save-registry.ts +1 -1
  767. package/src/testing/stub-service-registry.ts +1 -1
  768. package/src/testing/stub-writable-file-system.ts +3 -2
  769. package/src/util/connection-liveness.ts +81 -15
  770. package/src/util/environment.ts +24 -2
  771. package/lib/documents/language-client-text-shadow.d.ts +0 -101
  772. package/lib/documents/language-client-text-shadow.d.ts.map +0 -1
  773. package/lib/documents/language-client-text-shadow.js +0 -156
  774. package/lib/documents/language-client-text-shadow.js.map +0 -1
  775. package/lib/documents/self-save-registry.d.ts.map +0 -1
  776. package/lib/documents/self-save-registry.js.map +0 -1
  777. package/lib/lsp/instrument-connection.d.ts +0 -36
  778. package/lib/lsp/instrument-connection.d.ts.map +0 -1
  779. package/lib/lsp/instrument-connection.js +0 -62
  780. package/lib/lsp/instrument-connection.js.map +0 -1
  781. package/lib/node/process-memory.d.ts +0 -66
  782. package/lib/node/process-memory.d.ts.map +0 -1
  783. package/lib/node/process-memory.js +0 -252
  784. package/lib/node/process-memory.js.map +0 -1
  785. package/src/documents/language-client-text-shadow.ts +0 -175
  786. package/src/lsp/instrument-connection.ts +0 -66
  787. package/src/node/process-memory.ts +0 -299
@@ -0,0 +1,1164 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+ import { AstUtils, GrammarAST, GrammarUtils, IndentationAwareTokenBuilder, isAstNode } from '@hydranium/langium';
10
+ function isComposite(node) {
11
+ return 'content' in node;
12
+ }
13
+ function tokenNameOf(node) {
14
+ return 'tokenType' in node ? node.tokenType.name : undefined;
15
+ }
16
+ /**
17
+ * Carries a document's comments across a write that re-serializes it from the
18
+ * AST: extract against the node each comment hangs off, then splice into the
19
+ * serializer's output, located by re-parsing it.
20
+ *
21
+ * **Emitting comments from inside a serializer instead drops them silently for
22
+ * most nodes.** A hand-written concrete-syntax serializer reaches its children
23
+ * through its own per-`$type` emitters, not through
24
+ * `AbstractSerializer.serializeNode`, so a hook on that seam is reached by some
25
+ * nodes and bypassed by the rest — and the ones it misses fail as absence,
26
+ * which no test notices unless it asserts on exact text.
27
+ */
28
+ export class CommentPreserver {
29
+ services;
30
+ /**
31
+ * **Registering a second preserver under this id throws.** A subclass added
32
+ * ALONGSIDE the framework's — rather than replacing it by rebinding the
33
+ * `comments` contribution sub-key — collides here, and the throw surfaces
34
+ * from the first write rather than from server start, because the service is
35
+ * constructed lazily. Pass an `id` to run both.
36
+ */
37
+ id;
38
+ label = 'Comments';
39
+ /** Default {@link CommentPreserverOptions.maxIsolatedEdits}. */
40
+ static DEFAULT_ISOLATED_EDITS = 24;
41
+ tracer;
42
+ maxIsolatedEdits;
43
+ commentTokenNames;
44
+ indentationTokenNames;
45
+ /**
46
+ * Set for the duration of one {@link extract}: the run
47
+ * {@link resolveCommentRun} resolved last, so the run's next comment reuses
48
+ * it.
49
+ */
50
+ commentRun;
51
+ /**
52
+ * Set for the duration of one {@link extract}: {@link syntaxSpan} per node,
53
+ * as a block a run is lifted out of would otherwise be measured once per
54
+ * comment.
55
+ */
56
+ spanMemo;
57
+ /** Set for the duration of one {@link apply}; see {@link cachedAnchorKey}. */
58
+ keyMemo;
59
+ /** Set for the duration of one {@link apply}; see {@link ambiguousRetainedKey}. */
60
+ listVerdicts;
61
+ /** Set for the duration of one {@link apply}; see {@link parse}. */
62
+ lastParse;
63
+ constructor(services, options = {}) {
64
+ this.services = services;
65
+ this.id = options.id ?? 'comments';
66
+ this.maxIsolatedEdits = options.maxIsolatedEdits ?? CommentPreserver.DEFAULT_ISOLATED_EDITS;
67
+ this.tracer = services.shared.Tracer.for(options.logName ?? 'CommentPreserver');
68
+ }
69
+ /**
70
+ * Every comment terminal the grammar declares, by token name.
71
+ *
72
+ * Deliberately NOT `GrammarConfig.multilineCommentRules`, which Langium
73
+ * populates only with terminals whose regex spans lines — so a grammar that
74
+ * comments with `//` answers an empty list there and every one of its
75
+ * comments would be invisible to a capture keyed on it.
76
+ */
77
+ getCommentTokenNames() {
78
+ if (!this.commentTokenNames) {
79
+ this.commentTokenNames = this.services.Grammar.rules
80
+ .filter(GrammarAST.isTerminalRule)
81
+ .filter(rule => GrammarUtils.isCommentTerminal(rule))
82
+ .map(rule => rule.name);
83
+ }
84
+ return this.commentTokenNames;
85
+ }
86
+ /**
87
+ * The names of the INDENT and DEDENT tokens the language's
88
+ * `IndentationAwareTokenBuilder` emits, `undefined` for a lexer that emits
89
+ * none. Override it for a lexer of your own that emits such tokens.
90
+ *
91
+ * They are syntax to the parser only. A DEDENT is zero-width at the start of
92
+ * the line after its block, and an INDENT covers the whitespace in front of
93
+ * the block's first line, so a comment line beside either reads as sharing a
94
+ * line with the block, and moves onto the block's last line or its header.
95
+ */
96
+ getIndentationTokenNames() {
97
+ if (this.indentationTokenNames === undefined) {
98
+ const builder = this.services.parser.TokenBuilder;
99
+ this.indentationTokenNames =
100
+ builder instanceof IndentationAwareTokenBuilder
101
+ ? { indent: builder.indentTokenType.name, dedent: builder.dedentTokenType.name }
102
+ : null;
103
+ }
104
+ return this.indentationTokenNames ?? undefined;
105
+ }
106
+ isIndentation(node) {
107
+ const names = this.getIndentationTokenNames();
108
+ const name = tokenNameOf(node);
109
+ return names !== undefined && (name === names.indent || name === names.dedent);
110
+ }
111
+ /**
112
+ * Where the syntax of `node` begins and ends without the indentation tokens
113
+ * at its edges.
114
+ */
115
+ syntaxSpan(node) {
116
+ if (this.getIndentationTokenNames() === undefined) {
117
+ return node;
118
+ }
119
+ if (this.spanMemo?.has(node)) {
120
+ return this.spanMemo.get(node);
121
+ }
122
+ const first = this.edgeToken(node, 1);
123
+ const last = this.edgeToken(node, -1);
124
+ const span = first && last && { offset: first.offset, end: last.end };
125
+ this.spanMemo?.set(node, span);
126
+ return span;
127
+ }
128
+ /** The first token of `node` for a `step` of 1, the last for -1, that is neither hidden nor indentation. */
129
+ edgeToken(node, step) {
130
+ if (!isComposite(node)) {
131
+ return node.hidden || this.isIndentation(node) ? undefined : node;
132
+ }
133
+ const content = node.content;
134
+ for (let index = step > 0 ? 0 : content.length - 1; index >= 0 && index < content.length; index += step) {
135
+ const found = this.edgeToken(content[index], step);
136
+ if (found !== undefined) {
137
+ return found;
138
+ }
139
+ }
140
+ return undefined;
141
+ }
142
+ /**
143
+ * Stable identity for one AST node, used to find it again in the
144
+ * re-serialized text — or `undefined` when no stable identity exists.
145
+ *
146
+ * **Read through the `NameProvider`, so the anchor is what the grammar treats
147
+ * as IDENTITY rather than whatever sits on `name`.** A grammar whose `name`
148
+ * is a display label, carrying its identifier on another property, would
149
+ * otherwise anchor comments to a value users retitle freely. A simple
150
+ * retitle can be matched, but the real identifier remains the safer key.
151
+ * `NameProviderOptions.nameProperties` names that property.
152
+ *
153
+ * **Whatever an override returns must survive a sibling being inserted into
154
+ * the same list.** A positional key does not: every comment after the
155
+ * insertion point is then written against the following declaration — a move,
156
+ * which reads as text the author wrote there and which nothing downstream can
157
+ * detect. That is why an unidentified node answers `undefined` here rather
158
+ * than falling back to a container index, and why this cannot delegate to
159
+ * `ElementKeyProvider`, whose name-based strategy makes exactly that fallback:
160
+ * its keys are derived and consumed within one snapshot, where no position can
161
+ * have shifted underneath them.
162
+ *
163
+ * Overriding is the supported route for a grammar that identifies some nodes
164
+ * outside the naming surface altogether — by a cross-reference that is unique
165
+ * among its siblings, say. Capture and lookup both read this one definition,
166
+ * so an override cannot make those two disagree.
167
+ *
168
+ * **Matching a rename does not read it.** That comparison asks the
169
+ * `NameProvider` what changed, so a node identified only by an override is
170
+ * carried across a write that leaves its identity alone and dropped by one
171
+ * that rewrites it — never misplaced, but never followed either.
172
+ */
173
+ anchorKey(node) {
174
+ const nameProvider = this.services.references.NameProvider;
175
+ const segments = [];
176
+ let current = node;
177
+ while (current?.$container) {
178
+ const name = nameProvider.getOwnName(current);
179
+ if (name === undefined || name.length === 0) {
180
+ return undefined;
181
+ }
182
+ segments.unshift(`${current.$type}#${this.escapeKeySegment(name)}`);
183
+ current = current.$container;
184
+ }
185
+ return segments.length === 0 ? `@root:${node.$type}` : segments.join('/');
186
+ }
187
+ /**
188
+ * Escape the characters {@link anchorKey} builds its keys out of, so a name
189
+ * containing one cannot spell a key another node also answers to — which
190
+ * would make two distinct nodes indistinguishable to the lookup.
191
+ */
192
+ escapeKeySegment(name) {
193
+ return name.replace(/[\\#/]/g, character => `\\${character}`);
194
+ }
195
+ /**
196
+ * Collect every comment in `document`, each bound to the node it hangs off.
197
+ *
198
+ * Call this BEFORE the mutation that prompts the write. The anchors are AST
199
+ * objects, so a rule that renames one in place is reflected automatically;
200
+ * capturing afterwards would work too, but capturing first is what keeps the
201
+ * CST and the comments describing the same state.
202
+ */
203
+ extract(document) {
204
+ // The capture reads the CST, which a residency policy may have shed.
205
+ // Restored rather than skipped: skipping would lose the whole file's
206
+ // comments for a document that had gone idle, silently and only under a
207
+ // shedding strategy.
208
+ this.services.shared.workspace.CstResidencyService.rehydrate(document);
209
+ const root = document.parseResult.value.$cstNode;
210
+ const commentTokens = this.getCommentTokenNames();
211
+ if (!root || commentTokens.length === 0) {
212
+ return { comments: [], sourceRoot: document.parseResult.value };
213
+ }
214
+ const source = document.textDocument.getText();
215
+ const comments = [];
216
+ this.commentRun = undefined;
217
+ this.spanMemo = new Map();
218
+ try {
219
+ this.captureFrom(root, source, commentTokens, comments);
220
+ }
221
+ finally {
222
+ this.commentRun = undefined;
223
+ this.spanMemo = undefined;
224
+ }
225
+ return { comments, sourceRoot: document.parseResult.value };
226
+ }
227
+ /** Recursive half of {@link extract}: one composite node's content, then its children. */
228
+ captureFrom(node, source, commentTokens, into) {
229
+ if (!isComposite(node)) {
230
+ return;
231
+ }
232
+ const content = node.content;
233
+ content.forEach((child, index) => {
234
+ const tokenName = tokenNameOf(child);
235
+ if (child.hidden && tokenName !== undefined && commentTokens.includes(tokenName)) {
236
+ into.push(this.classify(child, index, node, source));
237
+ }
238
+ this.captureFrom(child, source, commentTokens, into);
239
+ });
240
+ }
241
+ /**
242
+ * Decide which node a comment belongs to, and how it sat against it.
243
+ *
244
+ * A comment on the same line the previous node ENDED on is that node's
245
+ * trailing comment — checked first, because by source order it also precedes
246
+ * whatever comes next, and reading it as the NEXT node's leading comment is
247
+ * what relocates an end-of-line note onto the following declaration.
248
+ */
249
+ classify(comment, index, container, source) {
250
+ const placed = this.placeAmongSyntax(comment, index, container, source);
251
+ const owner = placed.container;
252
+ const content = placed.content;
253
+ const at = placed.index;
254
+ const ownsOwnNode = (candidate) => candidate?.astNode !== undefined && candidate.astNode !== owner.astNode;
255
+ const realSibling = (from, step) => {
256
+ for (let scan = from; scan >= 0 && scan < content.length; scan += step) {
257
+ if (!content[scan].hidden) {
258
+ return content[scan];
259
+ }
260
+ }
261
+ return undefined;
262
+ };
263
+ const offsetOf = (node) => this.syntaxSpan(node)?.offset ?? node.offset;
264
+ const endOf = (node) => this.syntaxSpan(node)?.end ?? node.end;
265
+ const previous = realSibling(at - 1, -1);
266
+ const next = realSibling(at + 1, 1);
267
+ // Measured to whatever comes NEXT IN SOURCE, comment or not — never to the
268
+ // next real node, which would skip the rest of a comment block and make
269
+ // every line of it re-emit the whole gap that follows the block.
270
+ const following = content[at + 1];
271
+ const blankLinesAfter = following === undefined ? 0 : this.countBlankLines(source.slice(comment.end, offsetOf(following)));
272
+ const preceding = at > 0 ? content[at - 1] : undefined;
273
+ // From the last text before the comment: a block it is lifted out of can
274
+ // end with comment lines of its own, after the block's syntax.
275
+ const precedingEnd = preceding === undefined ? comment.offset : endOf(preceding);
276
+ let gapStart = comment.offset;
277
+ while (gapStart > precedingEnd && /\s/.test(source[gapStart - 1])) {
278
+ gapStart--;
279
+ }
280
+ const blankLinesBefore = preceding === undefined ? 0 : this.countBlankLines(source.slice(gapStart, comment.offset));
281
+ // Only a comment that OWNS its line can be reindented — one sharing a line
282
+ // with code keeps whatever spacing that line gives it.
283
+ const lineStart = source.lastIndexOf('\n', comment.offset - 1) + 1;
284
+ const beforeOnLine = source.slice(lineStart, comment.offset);
285
+ const sourceIndent = beforeOnLine.trim().length === 0 ? beforeOnLine : undefined;
286
+ const text = this.normalizeLineEndings(comment.text);
287
+ const sharesLineWithPrevious = previous !== undefined && !this.breaksLine(source, endOf(previous), comment.offset);
288
+ if (sharesLineWithPrevious) {
289
+ // On the same line as whatever precedes it, so it annotates that line.
290
+ // When the preceding sibling is the CONTAINER's own syntax — an opening
291
+ // brace, a name token, a keyword — the line is the container's header
292
+ // and the comment belongs to the container, NOT to the first member
293
+ // that happens to follow. Reading it as that member's leading comment
294
+ // moves a note about the declaration onto its first child.
295
+ return ownsOwnNode(previous)
296
+ ? { text, anchor: previous.astNode, placement: 'trailing', blankLinesAfter: 0, blankLinesBefore: 0 }
297
+ : { text, anchor: owner.astNode, placement: 'trailingOnContainer', blankLinesAfter: 0, blankLinesBefore: 0 };
298
+ }
299
+ if (ownsOwnNode(next)) {
300
+ return { text, anchor: next.astNode, placement: 'leading', blankLinesAfter, blankLinesBefore: 0, sourceIndent };
301
+ }
302
+ if (ownsOwnNode(previous)) {
303
+ return { text, anchor: previous.astNode, placement: 'afterNode', blankLinesAfter: 0, blankLinesBefore, sourceIndent };
304
+ }
305
+ if (previous === undefined) {
306
+ return { text, anchor: owner.astNode, placement: 'atContainerStart', blankLinesAfter, blankLinesBefore: 0, sourceIndent };
307
+ }
308
+ // Surrounded by the container's own syntax on both sides. A further
309
+ // sibling after it means the comment sits INSIDE the construct — between
310
+ // the braces of an empty body, or partway through a header — so it stays
311
+ // with the container rather than being pushed past its closing syntax,
312
+ // which would move it out to the enclosing scope. Only a comment with
313
+ // nothing after it at all actually trails the container.
314
+ const placement = next === undefined ? 'atContainerEnd' : 'trailingOnContainer';
315
+ return { text, anchor: owner.astNode, placement, blankLinesAfter, blankLinesBefore, sourceIndent };
316
+ }
317
+ /**
318
+ * Resolves the container {@link classify} anchors `comment` in, and the
319
+ * comment's adjacent siblings there and the nearest syntax on each side,
320
+ * without INDENT and DEDENT tokens. The content is that window, not all of
321
+ * the container's siblings.
322
+ *
323
+ * An indentation-aware lexer can emit a block's DEDENT after the comment
324
+ * lines that follow the block, so the parser nests them in it. An own-line
325
+ * comment left of the column a block's INDENT opened is lifted out of each
326
+ * block that ends right after it, with its adjacent hidden nodes, and placed
327
+ * after that block in the enclosing container.
328
+ */
329
+ placeAmongSyntax(comment, index, container, source) {
330
+ const content = container.content;
331
+ const run = this.resolveCommentRun(index, container, source);
332
+ let placed = 0;
333
+ if (run.targets.length > 1 && (run.previous === undefined || this.breaksLine(source, run.previous.end, comment.offset))) {
334
+ const column = this.columnAt(source, comment.offset);
335
+ while (placed + 1 < run.targets.length && column < (run.targets[placed + 1].liftBelow ?? 0)) {
336
+ placed++;
337
+ }
338
+ }
339
+ const { container: parent, closed } = run.targets[placed];
340
+ const before = closed ? [closed] : run.before;
341
+ const around = content.slice(Math.max(index - 1, run.start), Math.min(index + 1, run.end) + 1);
342
+ const view = [...before, ...around, ...run.after[placed]];
343
+ return { container: parent, content: view, index: before.length + (index > run.start ? 1 : 0) };
344
+ }
345
+ /**
346
+ * The run of hidden nodes around `container.content[index]`, and the blocks
347
+ * it can be lifted out of: each that ends right after the run and whose
348
+ * INDENT opened a column, up to the first that does not.
349
+ */
350
+ resolveCommentRun(index, container, source) {
351
+ const content = container.content;
352
+ const cached = this.commentRun;
353
+ // Resolved once per run, not per comment: a run of k comment lines would
354
+ // otherwise cost k scans of the run.
355
+ if (cached?.content === content && index >= cached.start && index <= cached.end) {
356
+ return cached;
357
+ }
358
+ let start = index;
359
+ while (start > 0 && content[start - 1].hidden) {
360
+ start--;
361
+ }
362
+ let end = index;
363
+ while (end + 1 < content.length && content[end + 1].hidden) {
364
+ end++;
365
+ }
366
+ let previous;
367
+ const targets = [{ container, last: end }];
368
+ if (this.getIndentationTokenNames() !== undefined) {
369
+ for (let scan = start - 1; scan >= 0 && previous === undefined; scan--) {
370
+ previous = content[scan].hidden ? undefined : this.syntaxSpan(content[scan]);
371
+ }
372
+ let target = targets[0];
373
+ while (target.container.container && this.closesAfter(target.container.content, target.last)) {
374
+ const opened = this.openedColumn(target.container.content, target.closed ? target.last : start, source) ?? 0;
375
+ if (opened === 0) {
376
+ break;
377
+ }
378
+ const parent = target.container.container;
379
+ target = {
380
+ container: parent,
381
+ last: this.indexIn(parent.content, target.container),
382
+ closed: target.container,
383
+ liftBelow: opened
384
+ };
385
+ targets.push(target);
386
+ }
387
+ }
388
+ const before = this.neighbours(content, start - 1, -1).reverse();
389
+ const after = targets.map(target => this.neighbours(target.container.content, target.last + 1, 1));
390
+ return (this.commentRun = { content, start, end, previous, targets, before, after });
391
+ }
392
+ /** The nodes of `content` from `from` in `step` direction up to the first that is syntax, without indentation tokens. */
393
+ neighbours(content, from, step) {
394
+ const found = [];
395
+ for (let scan = from; scan >= 0 && scan < content.length; scan += step) {
396
+ const node = content[scan];
397
+ if (!this.isIndentation(node)) {
398
+ found.push(node);
399
+ if (!node.hidden) {
400
+ break;
401
+ }
402
+ }
403
+ }
404
+ return found;
405
+ }
406
+ /** Whether only hidden and indentation tokens follow `index` in `content`. */
407
+ closesAfter(content, index) {
408
+ for (let scan = index + 1; scan < content.length; scan++) {
409
+ if (!content[scan].hidden && !this.isIndentation(content[scan])) {
410
+ return false;
411
+ }
412
+ }
413
+ return true;
414
+ }
415
+ /** The column the last INDENT before `content[index]` opens, `undefined` without one. */
416
+ openedColumn(content, index, source) {
417
+ const indent = this.getIndentationTokenNames()?.indent;
418
+ for (let scan = index - 1; scan >= 0; scan--) {
419
+ if (tokenNameOf(content[scan]) === indent) {
420
+ return this.columnAt(source, content[scan].end);
421
+ }
422
+ }
423
+ return undefined;
424
+ }
425
+ /**
426
+ * The index of `node` in `content`, found by offset: `indexOf` per lifted
427
+ * block makes extraction quadratic in a block's siblings.
428
+ */
429
+ indexIn(content, node) {
430
+ let low = 0;
431
+ let high = content.length;
432
+ while (low < high) {
433
+ const middle = (low + high) >> 1;
434
+ if (content[middle].offset < node.offset) {
435
+ low = middle + 1;
436
+ }
437
+ else {
438
+ high = middle;
439
+ }
440
+ }
441
+ // Zero-width tokens can share the node's offset.
442
+ for (let index = low; index < content.length && content[index].offset === node.offset; index++) {
443
+ if (content[index] === node) {
444
+ return index;
445
+ }
446
+ }
447
+ return content.indexOf(node);
448
+ }
449
+ /** Whether `text` has a line break from `from` up to `to`, without copying the span. */
450
+ breaksLine(text, from, to) {
451
+ // Not indexOf, which scans on to the next line break past `to`.
452
+ for (let offset = from; offset < to; offset++) {
453
+ if (text.charCodeAt(offset) === 10) {
454
+ return true;
455
+ }
456
+ }
457
+ return false;
458
+ }
459
+ /** The column of `offset` in `text`. */
460
+ columnAt(text, offset) {
461
+ return offset - (text.lastIndexOf('\n', offset - 1) + 1);
462
+ }
463
+ /**
464
+ * Comment text with CRLF reduced to LF.
465
+ *
466
+ * Serializers emit LF, so splicing a comment captured from a CRLF document
467
+ * verbatim puts lone CR bytes in the middle of LF-terminated lines.
468
+ */
469
+ normalizeLineEndings(text) {
470
+ return text.includes('\r') ? text.replace(/\r\n/g, '\n') : text;
471
+ }
472
+ /** Blank lines in a run of whitespace — one fewer than its newlines. */
473
+ countBlankLines(gap) {
474
+ return Math.max(0, (gap.match(/\n/g)?.length ?? 0) - 1);
475
+ }
476
+ /**
477
+ * Splice the captured comments back into `serialized`.
478
+ *
479
+ * A comment whose anchor the write deleted, or whose anchor has no stable
480
+ * key, is dropped — counted at `debug`, because a silent drop is the failure
481
+ * this preserver exists to remove and an unexplained one just moves it.
482
+ */
483
+ apply(serialized, trivia, uri) {
484
+ if (trivia.comments.length === 0) {
485
+ return serialized;
486
+ }
487
+ // The memos are scoped to this call and not to the instance, because an
488
+ // in-place write changes what a node's key IS: a repair that renames a
489
+ // node between two writes would otherwise be answered from the first.
490
+ this.keyMemo = new Map();
491
+ this.listVerdicts = new Map();
492
+ this.lastParse = {};
493
+ try {
494
+ return this.applyComments(serialized, trivia, uri);
495
+ }
496
+ finally {
497
+ this.keyMemo = undefined;
498
+ this.listVerdicts = undefined;
499
+ this.lastParse = undefined;
500
+ }
501
+ }
502
+ /** {@link apply}'s body, inside the per-write memos it sets up. */
503
+ applyComments(serialized, trivia, uri) {
504
+ const spliced = this.spliceComments(serialized, trivia, uri);
505
+ // **Never hand back text the grammar cannot read.** A splice edits syntax
506
+ // it did not produce, and a line comment in particular ends whatever
507
+ // shares its line — so a placement that is merely wrong becomes a file
508
+ // that no longer parses, written to disk by an integrity repair with no
509
+ // user gesture. Dropping the comments is recoverable; corrupting the
510
+ // document is not.
511
+ if (spliced !== serialized && this.parse(spliced, uri) === undefined) {
512
+ this.tracer.withUri(uri.toString()).warn('Reattaching comments produced text that does not parse; writing without them');
513
+ return serialized;
514
+ }
515
+ return spliced;
516
+ }
517
+ /**
518
+ * {@link anchorKey}, answered once per node per write.
519
+ *
520
+ * The key walks `$container` to the root building a segment each step, and
521
+ * every stage of a write asks about the same nodes — locating spans, matching
522
+ * a rename, judging a key the output kept. Recomputing makes each of those
523
+ * stages cost nodes × depth, and the stages that scan a sibling list do it
524
+ * once per comment.
525
+ */
526
+ cachedAnchorKey(node) {
527
+ const memo = this.keyMemo;
528
+ if (memo === undefined) {
529
+ return this.anchorKey(node);
530
+ }
531
+ if (!memo.has(node)) {
532
+ memo.set(node, this.anchorKey(node));
533
+ }
534
+ return memo.get(node);
535
+ }
536
+ /**
537
+ * Parse `text` as an unregistered document, or `undefined` when it is not
538
+ * readable — by reported error, or by a throw from a URI that routes to no
539
+ * services. Does NOT register the result, so `LangiumDocuments` is untouched.
540
+ *
541
+ * Within one {@link apply}, the text and URI parsed last are answered with
542
+ * the same document rather than parsed again, so a caller must not change
543
+ * it. One entry, so no document outlives the next parse.
544
+ */
545
+ parse(text, uri) {
546
+ const memo = this.lastParse;
547
+ if (memo !== undefined && memo.text === text && memo.uri === uri.toString()) {
548
+ return memo.document;
549
+ }
550
+ let document;
551
+ try {
552
+ document = this.services.shared.workspace.LangiumDocumentFactory.fromString(text, uri);
553
+ }
554
+ catch {
555
+ document = undefined;
556
+ }
557
+ if (document !== undefined && (document.parseResult.parserErrors.length > 0 || document.parseResult.lexerErrors.length > 0)) {
558
+ document = undefined;
559
+ }
560
+ if (memo !== undefined) {
561
+ memo.text = text;
562
+ memo.uri = uri.toString();
563
+ memo.document = document;
564
+ }
565
+ return document;
566
+ }
567
+ /** The splice itself, run before {@link apply}'s parse check. */
568
+ spliceComments(serialized, trivia, uri) {
569
+ const located = this.locate(serialized, uri);
570
+ if (located === undefined) {
571
+ return serialized;
572
+ }
573
+ const sourceOwners = new Map();
574
+ const sourceCollisions = new Set();
575
+ const liveAnchors = new Set();
576
+ for (const node of [trivia.sourceRoot, ...AstUtils.streamAllContents(trivia.sourceRoot)]) {
577
+ liveAnchors.add(node);
578
+ const key = this.cachedAnchorKey(node);
579
+ if (key === undefined) {
580
+ continue;
581
+ }
582
+ const owner = sourceOwners.get(key);
583
+ if (owner !== undefined && owner !== node) {
584
+ sourceCollisions.add(key);
585
+ }
586
+ else {
587
+ sourceOwners.set(key, node);
588
+ }
589
+ }
590
+ const needsRename = trivia.comments.some(comment => {
591
+ const key = this.cachedAnchorKey(comment.anchor);
592
+ return key !== undefined && !located.has(key);
593
+ });
594
+ const renamed = needsRename
595
+ ? this.matchRenamedAnchors(trivia.sourceRoot, serialized, uri, located, sourceOwners, sourceCollisions)
596
+ : new Map();
597
+ const edits = [];
598
+ let dropped = 0;
599
+ trivia.comments.forEach((comment, order) => {
600
+ const key = this.cachedAnchorKey(comment.anchor);
601
+ const destination = key === undefined ? undefined : located.has(key) ? key : this.renamedKey(comment.anchor, key, renamed);
602
+ const retained = destination === key ? located.get(key) : undefined;
603
+ const span = key === undefined ||
604
+ !liveAnchors.has(comment.anchor) ||
605
+ sourceCollisions.has(key) ||
606
+ destination === undefined ||
607
+ (retained !== undefined && this.ambiguousRetainedKey(comment.anchor, retained.owner))
608
+ ? undefined
609
+ : located.get(destination);
610
+ if (span === undefined) {
611
+ dropped++;
612
+ return;
613
+ }
614
+ const edit = this.editFor(comment, span, serialized);
615
+ edits.push({
616
+ ...edit,
617
+ order,
618
+ inline: this.needsReadBack(comment, span, serialized) ? { text: comment.text, key: destination } : undefined
619
+ });
620
+ });
621
+ if (dropped > 0) {
622
+ this.tracer.withUri(uri.toString()).debug(`Dropped ${dropped} comment(s): anchor deleted by the write, or carrying no stable key`);
623
+ }
624
+ // Stable by offset, then by capture order, so several comments landing on
625
+ // one anchor keep the order the author wrote them in.
626
+ edits.sort((left, right) => left.at - right.at || left.order - right.order);
627
+ // **This is what licenses the mid-line split** `editFor` makes for a
628
+ // `leading` comment whose anchor does not start its line. Parsing alone
629
+ // cannot license it: text can parse perfectly well having handed the
630
+ // comment to the following declaration instead. Re-extracting and
631
+ // requiring the same anchor back is the only evidence the comment still
632
+ // belongs where its author put it.
633
+ //
634
+ // A failed edit is dropped and the rest reassembled, since removing one
635
+ // changes what the others land in; two rounds, then the inline edits go
636
+ // as a set rather than iterating towards a text nothing has verified.
637
+ let remaining = edits;
638
+ let result = this.assembleComments(serialized, remaining);
639
+ for (let attempt = 0; attempt < 2; attempt++) {
640
+ const failed = this.unverifiedInlineEdits(result, remaining, uri, serialized);
641
+ if (failed.size === 0) {
642
+ return result;
643
+ }
644
+ remaining = remaining.filter(edit => !failed.has(edit));
645
+ result = this.assembleComments(serialized, remaining);
646
+ }
647
+ return this.assembleComments(serialized, remaining.filter(edit => edit.inline === undefined));
648
+ }
649
+ /**
650
+ * Whether this comment's edit has to be read back before it can be trusted.
651
+ *
652
+ * Both cases are the serializer having put the anchor on a line it shares.
653
+ * A comment that wants the line above has to open one mid-construct; a
654
+ * comment that wants the end of the anchor's line gets the end of a line that
655
+ * may belong to a later sibling, and a second such comment lands inside the
656
+ * first one's text and stops being a comment at all. Neither can be judged
657
+ * from the offsets alone — only from what the text says once re-read.
658
+ */
659
+ needsReadBack(comment, span, serialized) {
660
+ if (comment.placement === 'leading' || comment.placement === 'atContainerStart') {
661
+ return !this.startOfLineIsBlank(serialized, span.offset);
662
+ }
663
+ return comment.placement === 'trailing' && this.endOfLineAt(serialized, span.end) !== span.end;
664
+ }
665
+ /**
666
+ * Splice `edits` into `serialized`, in the order given.
667
+ *
668
+ * Two inline edits landing on one offset collapse into a single opened line,
669
+ * so a stack of comments above one inline member comes back as a stack rather
670
+ * than with a blank line between each pair.
671
+ */
672
+ assembleComments(serialized, edits) {
673
+ let result = '';
674
+ let cursor = 0;
675
+ let previousInlineAt;
676
+ for (const edit of edits) {
677
+ const text = edit.inline !== undefined && edit.at === previousInlineAt ? edit.text.replace(/^\n[ \t]*/, '') : edit.text;
678
+ result += serialized.slice(cursor, edit.at) + text;
679
+ cursor = edit.at;
680
+ previousInlineAt = edit.inline !== undefined ? edit.at : undefined;
681
+ }
682
+ return result + serialized.slice(cursor);
683
+ }
684
+ /**
685
+ * Whether the output node now answering to `source`'s key is too likely to be
686
+ * a DIFFERENT node for the comment to follow it.
687
+ *
688
+ * A key surviving the write normally means the node did. It can also mean a
689
+ * sibling took the name over, which reads as the author having written the
690
+ * comment about a declaration they never saw.
691
+ *
692
+ * **What is detectable is a list whose members changed places; what is not is
693
+ * a payload that renames a node and gives its old name to another.** Those
694
+ * two writes produce the same text and the same keys, and the node carrying
695
+ * the old name afterwards is byte-identical under both readings, so no rule
696
+ * over this evidence separates them. A caller that knows which node it
697
+ * renamed is the only thing that could, and the transfer model carries no
698
+ * such record.
699
+ *
700
+ * **The evidence is the ORDER of the keys the two lists share.** Adding or
701
+ * removing siblings shifts the rest but leaves them in the same relative
702
+ * order; only names changing places can put two shared keys out of order. A
703
+ * list whose shared keys invert is therefore read as exchanged identities and
704
+ * those siblings lose their comments — which costs a deliberate reorder its
705
+ * comments, the conservative half of a trade whose other half is that a bare
706
+ * swap cannot move one.
707
+ *
708
+ * **Comparing counts or key SETS instead misses cases each way.** A swap
709
+ * alongside an insertion leaves the counts differing and the key set whole,
710
+ * so neither test sees it; a deletion alongside an insertion leaves the counts
711
+ * equal while every surviving sibling is still itself, so a count test drops
712
+ * comments that were never in doubt.
713
+ */
714
+ ambiguousRetainedKey(source, output) {
715
+ const sourceParent = source.$container;
716
+ const outputParent = output.$container;
717
+ if (!sourceParent || !outputParent) {
718
+ return false;
719
+ }
720
+ const parentKey = this.cachedAnchorKey(sourceParent);
721
+ if (parentKey !== this.cachedAnchorKey(outputParent) || source.$containerProperty !== output.$containerProperty) {
722
+ return true;
723
+ }
724
+ if (source.$containerIndex === output.$containerIndex) {
725
+ return false;
726
+ }
727
+ const property = source.$containerProperty;
728
+ if (property === undefined) {
729
+ return true;
730
+ }
731
+ // Answered once per list rather than once per comment. One insertion moves
732
+ // every later sibling, so each of their comments asks the same question of
733
+ // the same two lists — and scanning both per comment costs the list's
734
+ // length squared.
735
+ //
736
+ // Memoised against the parent NODE rather than its key, because two
737
+ // same-named parents answer to one key and would otherwise share a verdict
738
+ // about lists that have nothing to do with each other.
739
+ const cached = this.listVerdicts?.get(sourceParent)?.get(property);
740
+ if (cached !== undefined) {
741
+ return cached;
742
+ }
743
+ const verdict = this.reidentifiedList(sourceParent, outputParent, property);
744
+ if (this.listVerdicts !== undefined) {
745
+ const byProperty = this.listVerdicts.get(sourceParent) ?? new Map();
746
+ byProperty.set(property, verdict);
747
+ this.listVerdicts.set(sourceParent, byProperty);
748
+ }
749
+ return verdict;
750
+ }
751
+ /**
752
+ * Whether the two lists differ in a way a plain insertion or deletion cannot
753
+ * explain — the expensive half of {@link ambiguousRetainedKey}, split out so
754
+ * it can be answered once per list.
755
+ *
756
+ * What says the members may have swapped names rather than moved:
757
+ *
758
+ * - **The lists are the same length.** Every rename chain over a fixed set of
759
+ * slots looks exactly like the shift a deletion plus an insertion produces,
760
+ * and for members carrying nothing but a name the properties match under
761
+ * both readings. Neither this nor anything downstream can separate them.
762
+ * - **Keys present on both sides have changed places.** Adding or removing
763
+ * siblings shifts the rest but never reorders them, so an inversion is
764
+ * evidence no insertion or deletion can account for — and it is evidence
765
+ * the lengths alone miss, since a swap alongside an insertion leaves the
766
+ * counts differing and the key set whole.
767
+ */
768
+ reidentifiedList(sourceParent, outputParent, property) {
769
+ const before = sourceParent[property];
770
+ const after = outputParent[property];
771
+ if (!Array.isArray(before) || !Array.isArray(after)) {
772
+ return true;
773
+ }
774
+ if (before.length === after.length) {
775
+ return true;
776
+ }
777
+ const positions = new Map();
778
+ after.filter(isAstNode).forEach((node, index) => {
779
+ const key = this.cachedAnchorKey(node);
780
+ if (key !== undefined && !positions.has(key)) {
781
+ positions.set(key, index);
782
+ }
783
+ });
784
+ let furthest = -1;
785
+ for (const node of before.filter(isAstNode)) {
786
+ const key = this.cachedAnchorKey(node);
787
+ const position = key === undefined ? undefined : positions.get(key);
788
+ if (position === undefined) {
789
+ continue;
790
+ }
791
+ if (position < furthest) {
792
+ return true;
793
+ }
794
+ furthest = position;
795
+ }
796
+ return false;
797
+ }
798
+ /**
799
+ * The inline edits `candidate` did not round-trip: each one whose comment came
800
+ * back on a different anchor, and — when `candidate` does not parse at all —
801
+ * each one that cannot be put back beside the others without breaking it
802
+ * again. `serialized` is the unspliced text those trials are rebuilt from,
803
+ * since finding the single edit at fault means assembling the rest without it.
804
+ *
805
+ * Costs a parse and an extract, so it answers empty without either when
806
+ * nothing was spliced inline — which is every write into a document the
807
+ * serializer lays out one declaration per line.
808
+ */
809
+ unverifiedInlineEdits(candidate, edits, uri, serialized) {
810
+ const inlineEdits = edits.filter(edit => edit.inline !== undefined);
811
+ if (inlineEdits.length === 0) {
812
+ return new Set();
813
+ }
814
+ const reparsed = this.parse(candidate, uri);
815
+ if (reparsed === undefined) {
816
+ if (inlineEdits.length > this.maxIsolatedEdits) {
817
+ this.tracer
818
+ .withUri(uri.toString())
819
+ .debug(`Spliced text did not parse; dropping ${inlineEdits.length} shared-line comments without isolating`);
820
+ return new Set(inlineEdits);
821
+ }
822
+ const retained = edits.filter(edit => edit.inline === undefined);
823
+ const failed = new Set();
824
+ for (const edit of inlineEdits) {
825
+ const trial = [...retained, edit].sort((left, right) => left.at - right.at || left.order - right.order);
826
+ const text = this.assembleComments(serialized, trial);
827
+ if (this.parse(text, uri) !== undefined && this.unverifiedInlineEdits(text, trial, uri, serialized).size === 0) {
828
+ retained.push(edit);
829
+ }
830
+ else {
831
+ failed.add(edit);
832
+ }
833
+ }
834
+ return failed;
835
+ }
836
+ // Counted rather than scanned per edit: several comments can share an
837
+ // anchor and a text, and each edit must consume one of them.
838
+ const captured = new Map();
839
+ for (const comment of this.extract(reparsed).comments) {
840
+ const seen = `${this.cachedAnchorKey(comment.anchor) ?? ''}\u0000${comment.text}`;
841
+ captured.set(seen, (captured.get(seen) ?? 0) + 1);
842
+ }
843
+ const failed = new Set();
844
+ for (const edit of inlineEdits) {
845
+ const expected = edit.inline;
846
+ const wanted = `${expected.key}\u0000${expected.text}`;
847
+ const remaining = captured.get(wanted) ?? 0;
848
+ if (remaining === 0) {
849
+ failed.add(edit);
850
+ }
851
+ else {
852
+ captured.set(wanted, remaining - 1);
853
+ }
854
+ }
855
+ return failed;
856
+ }
857
+ renamedKey(anchor, oldKey, renamed) {
858
+ let current = anchor;
859
+ while (current !== undefined) {
860
+ const newPrefix = renamed.get(current);
861
+ const oldPrefix = this.cachedAnchorKey(current);
862
+ if (newPrefix !== undefined && oldPrefix !== undefined && (oldKey === oldPrefix || oldKey.startsWith(`${oldPrefix}/`))) {
863
+ return newPrefix + oldKey.slice(oldPrefix.length);
864
+ }
865
+ current = current.$container;
866
+ }
867
+ return undefined;
868
+ }
869
+ matchRenamedAnchors(sourceRoot, serialized, uri, located, sourceOwners, sourceCollisions) {
870
+ const matches = new Map();
871
+ const output = this.parse(serialized, uri);
872
+ if (output === undefined) {
873
+ return matches;
874
+ }
875
+ const outputNodes = [output.parseResult.value, ...AstUtils.streamAllContents(output.parseResult.value)];
876
+ const unmatchedBySlot = new Map();
877
+ for (const node of outputNodes) {
878
+ const key = this.cachedAnchorKey(node);
879
+ const parent = node.$container && this.cachedAnchorKey(node.$container);
880
+ if (key === undefined || !located.has(key) || sourceOwners.has(key) || parent === undefined) {
881
+ continue;
882
+ }
883
+ const slot = JSON.stringify([parent, node.$containerProperty, node.$containerIndex, node.$type]);
884
+ const candidates = unmatchedBySlot.get(slot) ?? [];
885
+ candidates.push(node);
886
+ unmatchedBySlot.set(slot, candidates);
887
+ }
888
+ const claimed = new Map();
889
+ const ambiguous = new Set();
890
+ for (const source of [sourceRoot, ...AstUtils.streamAllContents(sourceRoot)]) {
891
+ const key = this.cachedAnchorKey(source);
892
+ if (key === undefined || sourceCollisions.has(key) || located.has(key) || !source.$container) {
893
+ continue;
894
+ }
895
+ const parentKey = this.cachedAnchorKey(source.$container);
896
+ if (parentKey === undefined) {
897
+ continue;
898
+ }
899
+ const slot = JSON.stringify([parentKey, source.$containerProperty, source.$containerIndex, source.$type]);
900
+ const candidates = (unmatchedBySlot.get(slot) ?? []).filter(candidate => this.sameAsideFromName(source, candidate));
901
+ if (candidates.length === 1) {
902
+ const candidate = candidates[0];
903
+ if (ambiguous.has(candidate)) {
904
+ continue;
905
+ }
906
+ if (claimed.has(candidate)) {
907
+ matches.delete(claimed.get(candidate));
908
+ ambiguous.add(candidate);
909
+ }
910
+ else {
911
+ matches.set(source, this.cachedAnchorKey(candidate));
912
+ }
913
+ claimed.set(candidate, source);
914
+ }
915
+ }
916
+ return matches;
917
+ }
918
+ sameAsideFromName(source, target) {
919
+ const nameProvider = this.services.references.NameProvider;
920
+ const before = nameProvider.getOwnName(source);
921
+ const after = nameProvider.getOwnName(target);
922
+ if (before === undefined || after === undefined || before === after) {
923
+ return false;
924
+ }
925
+ let renamed = false;
926
+ for (const key of this.comparableProperties(source.$type)) {
927
+ const oldValue = source[key];
928
+ const newValue = target[key];
929
+ if (oldValue === before && newValue === after) {
930
+ renamed = true;
931
+ }
932
+ else if (!this.sameValue(oldValue, newValue)) {
933
+ return false;
934
+ }
935
+ }
936
+ return renamed;
937
+ }
938
+ /**
939
+ * The properties `type` declares in the grammar — everything a rename match
940
+ * may compare, and nothing else.
941
+ *
942
+ * **Comparing own keys instead compares derived state, and matches nothing.**
943
+ * A built document carries whatever `ast.extensions` computed onto its nodes;
944
+ * the re-parsed serializer output is never built and carries none of it. Every
945
+ * candidate then differs on a property the grammar never mentioned, so no
946
+ * rename is ever matched — on the real write path only, because a document a
947
+ * test parses from a string has no computed state to disagree about.
948
+ */
949
+ comparableProperties(type) {
950
+ return Object.keys(this.services.shared.AstReflection.getTypeMetaData(type).properties);
951
+ }
952
+ sameValue(left, right) {
953
+ if (left === right) {
954
+ return true;
955
+ }
956
+ if (Array.isArray(left) && Array.isArray(right)) {
957
+ return left.length === right.length && left.every((value, index) => this.sameValue(value, right[index]));
958
+ }
959
+ if (isAstNode(left) && isAstNode(right)) {
960
+ if (left.$type !== right.$type) {
961
+ return false;
962
+ }
963
+ return this.comparableProperties(left.$type).every(key => this.sameValue(left[key], right[key]));
964
+ }
965
+ if (left !== null && right !== null && typeof left === 'object' && typeof right === 'object') {
966
+ if ('$refText' in left && '$refText' in right) {
967
+ return left.$refText === right.$refText;
968
+ }
969
+ }
970
+ return false;
971
+ }
972
+ /** The insertion this comment's placement implies, against its anchor's span. */
973
+ editFor(comment, span, serialized) {
974
+ const blanks = '\n'.repeat(comment.blankLinesAfter);
975
+ const blanksBefore = '\n'.repeat(comment.blankLinesBefore);
976
+ switch (comment.placement) {
977
+ case 'trailing':
978
+ return { at: this.endOfLineAt(serialized, span.end), text: ` ${comment.text}` };
979
+ // Appended to the container's FIRST line, which is its header. The
980
+ // comment may have sat further along that line in the source — mid
981
+ // header, or between braces the serializer has since collapsed to `{}`
982
+ // — and the exact column is not recoverable from a re-emitted
983
+ // document. The line is, and that is what keeps it on its own
984
+ // declaration instead of on a neighbour.
985
+ case 'trailingOnContainer':
986
+ return { at: this.endOfLineAt(serialized, span.offset), text: ` ${comment.text}` };
987
+ // Both of these open a NEW line after the anchor, which is only safe
988
+ // while nothing else shares the anchor's line. When the serializer put
989
+ // the anchor and its container's closing syntax together — an inline
990
+ // enum body, say — splitting there pushes that syntax onto the comment's
991
+ // line, and a line comment then ends the construct. Appending to the
992
+ // line instead keeps the comment on the same declaration and the
993
+ // document readable.
994
+ case 'afterNode': {
995
+ if (!this.restOfLineIsBlank(serialized, span.end)) {
996
+ return { at: this.endOfLineAt(serialized, span.end), text: ` ${comment.text}` };
997
+ }
998
+ const indent = this.indentAt(serialized, span.offset);
999
+ return { at: span.end, text: `\n${blanksBefore}${indent}${this.reindent(comment, indent)}` };
1000
+ }
1001
+ case 'atContainerEnd':
1002
+ return this.restOfLineIsBlank(serialized, span.end)
1003
+ ? { at: span.end, text: `\n${blanksBefore}${comment.text}` }
1004
+ : { at: this.endOfLineAt(serialized, span.end), text: ` ${comment.text}` };
1005
+ case 'atContainerStart':
1006
+ case 'leading':
1007
+ default: {
1008
+ // `leading` means "on the line above", and the anchor may sit
1009
+ // mid-line — a member of a body the serializer emitted inline.
1010
+ // **Opening a line there is sound only because the caller reads the
1011
+ // result back and requires this comment on this same anchor**,
1012
+ // dropping the edit when it is not. Unguarded, the split strands the
1013
+ // rest of the construct at column zero and lands somewhere different
1014
+ // again on the next write.
1015
+ if (!this.startOfLineIsBlank(serialized, span.offset)) {
1016
+ const indent = comment.sourceIndent ?? this.indentAt(serialized, span.offset);
1017
+ return { at: span.offset, text: `\n${indent}${this.reindent(comment, indent)}\n${blanks}${indent}` };
1018
+ }
1019
+ const indent = this.indentAt(serialized, span.offset);
1020
+ return { at: span.offset, text: `${this.reindent(comment, indent)}\n${blanks}${indent}` };
1021
+ }
1022
+ }
1023
+ }
1024
+ /**
1025
+ * A multi-line comment's continuation lines, shifted by the same delta its
1026
+ * first line moves — so a block emitted at a new indentation stays square
1027
+ * instead of trailing its original column.
1028
+ *
1029
+ * **Only the leading whitespace run is touched, and an outdent removes at
1030
+ * most what is there** — shifting further would eat the comment's own text.
1031
+ *
1032
+ * Single-line comments and ones sharing a line with code are returned
1033
+ * unchanged.
1034
+ */
1035
+ reindent(comment, targetIndent) {
1036
+ if (comment.sourceIndent === undefined || !comment.text.includes('\n')) {
1037
+ return comment.text;
1038
+ }
1039
+ // Indentation is compared as characters, which only means anything while
1040
+ // both sides use the SAME whitespace character. A tab-indented source
1041
+ // re-emitted with spaces has no meaningful delta, and shifting by one
1042
+ // anyway prepends spaces in front of tabs.
1043
+ const sourceUnit = /^\t*$/.test(comment.sourceIndent) ? '\t' : ' ';
1044
+ const targetUnit = /^\t*$/.test(targetIndent) ? '\t' : ' ';
1045
+ const delta = targetIndent.length - comment.sourceIndent.length;
1046
+ if (delta === 0 || sourceUnit !== targetUnit) {
1047
+ return comment.text;
1048
+ }
1049
+ const [first, ...rest] = comment.text.split('\n');
1050
+ const shifted = rest.map(line => {
1051
+ if (delta > 0) {
1052
+ return targetUnit.repeat(delta) + line;
1053
+ }
1054
+ const removable = /^[ \t]*/.exec(line)?.[0].length ?? 0;
1055
+ return line.slice(Math.min(-delta, removable));
1056
+ });
1057
+ return [first, ...shifted].join('\n');
1058
+ }
1059
+ /** Whether everything from `offset` to the end of its line is whitespace. */
1060
+ restOfLineIsBlank(text, offset) {
1061
+ return text.slice(offset, this.endOfLineAt(text, offset)).trim().length === 0;
1062
+ }
1063
+ /** Whether `offset` is preceded on its own line by whitespace alone. */
1064
+ startOfLineIsBlank(text, offset) {
1065
+ return text.slice(text.lastIndexOf('\n', offset - 1) + 1, offset).trim().length === 0;
1066
+ }
1067
+ /**
1068
+ * End of the line `offset` sits on, as an insertion point for a trailing
1069
+ * comment. Stops before a CR so an insertion into CRLF text lands inside the
1070
+ * line rather than between its two terminator bytes.
1071
+ */
1072
+ endOfLineAt(text, offset) {
1073
+ const newline = text.indexOf('\n', offset);
1074
+ const lineEnd = newline < 0 ? text.length : newline;
1075
+ return lineEnd > 0 && text[lineEnd - 1] === '\r' ? lineEnd - 1 : lineEnd;
1076
+ }
1077
+ /** Leading whitespace of the line `offset` sits on, so an insertion lines up with it. */
1078
+ indentAt(text, offset) {
1079
+ const lineStart = text.lastIndexOf('\n', offset - 1) + 1;
1080
+ return /^\s*/.exec(text.slice(lineStart, offset))?.[0] ?? '';
1081
+ }
1082
+ /**
1083
+ * Where every node landed in the serializer's output, keyed by
1084
+ * {@link anchorKey}.
1085
+ *
1086
+ * Re-parses `serialized` through the document factory, which does NOT
1087
+ * register the result, so this leaves `LangiumDocuments` alone. Output the
1088
+ * grammar cannot read, by reported error or by a throw from a URI that
1089
+ * routes to no services, yields `undefined`: the caller then writes the
1090
+ * serializer's text unchanged rather than splicing into text already wrong.
1091
+ *
1092
+ * **A key claimed by two DIFFERENT nodes is removed, not merged.** A repeated
1093
+ * identity is exactly what the integrity tier exists to repair, so collisions
1094
+ * reach this method routinely; merging their spans puts every one of their
1095
+ * comments on whichever came first. Removing the key drops those instead,
1096
+ * which is the only outcome here that keeps a comment off a declaration its
1097
+ * author did not write it on.
1098
+ */
1099
+ locate(serialized, uri) {
1100
+ const document = this.parse(serialized, uri);
1101
+ if (document === undefined) {
1102
+ this.tracer.withUri(uri.toString()).warn('Serialized output did not re-parse; writing it without comments');
1103
+ return undefined;
1104
+ }
1105
+ const root = document.parseResult.value.$cstNode;
1106
+ if (!root) {
1107
+ return undefined;
1108
+ }
1109
+ const found = new Map();
1110
+ // One AST node owns many CST nodes — its composite plus every token under
1111
+ // it — so a repeated key is only a collision when a DIFFERENT node claims
1112
+ // it. Tracking the owner is what separates the two.
1113
+ const owners = new Map();
1114
+ const collided = new Set();
1115
+ // One AST node owns every CST node beneath it, so this asks for the same
1116
+ // key once per token; `cachedAnchorKey` is what keeps the pass from
1117
+ // costing nodes x depth.
1118
+ const visit = (node) => {
1119
+ const key = node.astNode !== undefined && !node.hidden ? this.cachedAnchorKey(node.astNode) : undefined;
1120
+ // Without the indentation tokens, whose DEDENT would end a block at
1121
+ // the start of the line after it.
1122
+ const span = key === undefined ? undefined : this.syntaxSpan(node);
1123
+ if (key !== undefined && span !== undefined) {
1124
+ const owner = owners.get(key);
1125
+ if (owner === undefined) {
1126
+ owners.set(key, node.astNode);
1127
+ found.set(key, { offset: span.offset, end: span.end, owner: node.astNode });
1128
+ }
1129
+ else if (owner === node.astNode) {
1130
+ // Widest span per node: its first CST node gives the start, a
1131
+ // later token contributing to the same node extends the end.
1132
+ const existing = found.get(key);
1133
+ found.set(key, {
1134
+ offset: Math.min(existing.offset, span.offset),
1135
+ end: Math.max(existing.end, span.end),
1136
+ owner: existing.owner
1137
+ });
1138
+ }
1139
+ else {
1140
+ collided.add(key);
1141
+ }
1142
+ }
1143
+ if (isComposite(node)) {
1144
+ node.content.forEach(visit);
1145
+ }
1146
+ };
1147
+ visit(root);
1148
+ for (const key of collided) {
1149
+ found.delete(key);
1150
+ }
1151
+ return found;
1152
+ }
1153
+ }
1154
+ /** Registers {@link CommentPreserver}; bound at `trivia.preservers.comments`. */
1155
+ export class CommentPreserverContribution {
1156
+ services;
1157
+ constructor(services) {
1158
+ this.services = services;
1159
+ }
1160
+ registerTriviaPreservers(registry) {
1161
+ registry.register(new CommentPreserver(this.services));
1162
+ }
1163
+ }
1164
+ //# sourceMappingURL=comment-preserver.js.map