@hydranium/protocol 1.0.0-next.38 → 1.0.0-next.380

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 (298) hide show
  1. package/README.md +44 -83
  2. package/lib/abstract-logger.d.ts +11 -0
  3. package/lib/abstract-logger.d.ts.map +1 -1
  4. package/lib/abstract-logger.js +16 -0
  5. package/lib/abstract-logger.js.map +1 -1
  6. package/lib/client/data-connection.d.ts +303 -0
  7. package/lib/client/data-connection.d.ts.map +1 -0
  8. package/lib/client/data-connection.js +534 -0
  9. package/lib/client/data-connection.js.map +1 -0
  10. package/lib/client/data-events.d.ts +18 -1
  11. package/lib/client/data-events.d.ts.map +1 -1
  12. package/lib/client/data-events.js +26 -0
  13. package/lib/client/data-events.js.map +1 -1
  14. package/lib/client/data-port.d.ts +34 -24
  15. package/lib/client/data-port.d.ts.map +1 -1
  16. package/lib/client/data-session.d.ts +694 -89
  17. package/lib/client/data-session.d.ts.map +1 -1
  18. package/lib/client/data-session.js +1158 -115
  19. package/lib/client/data-session.js.map +1 -1
  20. package/lib/client/index.d.ts +15 -9
  21. package/lib/client/index.d.ts.map +1 -1
  22. package/lib/client/index.js +15 -9
  23. package/lib/client/index.js.map +1 -1
  24. package/lib/client/message-relay.d.ts +6 -4
  25. package/lib/client/message-relay.d.ts.map +1 -1
  26. package/lib/client/message-relay.js +4 -4
  27. package/lib/client/message-relay.js.map +1 -1
  28. package/lib/client/post-message-transport.d.ts +69 -3
  29. package/lib/client/post-message-transport.d.ts.map +1 -1
  30. package/lib/client/post-message-transport.js +175 -1
  31. package/lib/client/post-message-transport.js.map +1 -1
  32. package/lib/client/rpc-connection.d.ts +173 -0
  33. package/lib/client/rpc-connection.d.ts.map +1 -0
  34. package/lib/client/rpc-connection.js +225 -0
  35. package/lib/client/rpc-connection.js.map +1 -0
  36. package/lib/client/worker-handshake.d.ts +94 -0
  37. package/lib/client/worker-handshake.d.ts.map +1 -0
  38. package/lib/client/worker-handshake.js +51 -0
  39. package/lib/client/worker-handshake.js.map +1 -0
  40. package/lib/client-ids.d.ts +45 -0
  41. package/lib/client-ids.d.ts.map +1 -0
  42. package/lib/client-ids.js +48 -0
  43. package/lib/client-ids.js.map +1 -0
  44. package/lib/clock.d.ts +50 -10
  45. package/lib/clock.d.ts.map +1 -1
  46. package/lib/clock.js +36 -1
  47. package/lib/clock.js.map +1 -1
  48. package/lib/console-logger.d.ts +23 -0
  49. package/lib/console-logger.d.ts.map +1 -0
  50. package/lib/console-logger.js +39 -0
  51. package/lib/console-logger.js.map +1 -0
  52. package/lib/data/data-protocol-methods.d.ts +4 -4
  53. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  54. package/lib/data/data-protocol-methods.js +13 -1
  55. package/lib/data/data-protocol-methods.js.map +1 -1
  56. package/lib/data/data-server-protocol.d.ts +176 -49
  57. package/lib/data/data-server-protocol.d.ts.map +1 -1
  58. package/lib/data/events.d.ts +144 -33
  59. package/lib/data/events.d.ts.map +1 -1
  60. package/lib/data/requests.d.ts +84 -11
  61. package/lib/data/requests.d.ts.map +1 -1
  62. package/lib/debouncer.d.ts +7 -4
  63. package/lib/debouncer.d.ts.map +1 -1
  64. package/lib/debouncer.js +10 -10
  65. package/lib/debouncer.js.map +1 -1
  66. package/lib/errors.d.ts +243 -41
  67. package/lib/errors.d.ts.map +1 -1
  68. package/lib/errors.js +400 -55
  69. package/lib/errors.js.map +1 -1
  70. package/lib/format-log-arg.d.ts +33 -0
  71. package/lib/format-log-arg.d.ts.map +1 -0
  72. package/lib/format-log-arg.js +158 -0
  73. package/lib/format-log-arg.js.map +1 -0
  74. package/lib/glsp-edits-settled-actions.d.ts +54 -0
  75. package/lib/glsp-edits-settled-actions.d.ts.map +1 -0
  76. package/lib/glsp-edits-settled-actions.js +28 -0
  77. package/lib/glsp-edits-settled-actions.js.map +1 -0
  78. package/lib/glsp-request-model-args.d.ts +16 -0
  79. package/lib/glsp-request-model-args.d.ts.map +1 -0
  80. package/lib/glsp-request-model-args.js +19 -0
  81. package/lib/glsp-request-model-args.js.map +1 -0
  82. package/lib/glsp-save-model-actions.d.ts +55 -0
  83. package/lib/glsp-save-model-actions.d.ts.map +1 -0
  84. package/lib/glsp-save-model-actions.js +28 -0
  85. package/lib/glsp-save-model-actions.js.map +1 -0
  86. package/lib/index.d.ts +11 -0
  87. package/lib/index.d.ts.map +1 -1
  88. package/lib/index.js +11 -0
  89. package/lib/index.js.map +1 -1
  90. package/lib/latency-collector.d.ts +10 -4
  91. package/lib/latency-collector.d.ts.map +1 -1
  92. package/lib/latency-collector.js +2 -0
  93. package/lib/latency-collector.js.map +1 -1
  94. package/lib/logger.d.ts +38 -7
  95. package/lib/logger.d.ts.map +1 -1
  96. package/lib/logger.js +42 -4
  97. package/lib/logger.js.map +1 -1
  98. package/lib/messages/index.d.ts +4 -2
  99. package/lib/messages/index.d.ts.map +1 -1
  100. package/lib/messages/index.js +17 -4
  101. package/lib/messages/index.js.map +1 -1
  102. package/lib/messages/primitives.d.ts +59 -4
  103. package/lib/messages/primitives.d.ts.map +1 -1
  104. package/lib/messages/primitives.js +97 -4
  105. package/lib/messages/primitives.js.map +1 -1
  106. package/lib/model-server.d.ts +60 -13
  107. package/lib/model-server.d.ts.map +1 -1
  108. package/lib/model-server.js +4 -2
  109. package/lib/model-server.js.map +1 -1
  110. package/lib/model-service/base-version.d.ts +67 -0
  111. package/lib/model-service/base-version.d.ts.map +1 -0
  112. package/lib/model-service/base-version.js +44 -0
  113. package/lib/model-service/base-version.js.map +1 -0
  114. package/lib/model-service/index.d.ts +1 -1
  115. package/lib/model-service/index.d.ts.map +1 -1
  116. package/lib/model-service/index.js +4 -5
  117. package/lib/model-service/index.js.map +1 -1
  118. package/lib/model-service/reference-candidate.d.ts +5 -3
  119. package/lib/model-service/reference-candidate.d.ts.map +1 -1
  120. package/lib/node/index.d.ts +10 -0
  121. package/lib/node/index.d.ts.map +1 -0
  122. package/lib/node/index.js +29 -0
  123. package/lib/node/index.js.map +1 -0
  124. package/lib/node/process-memory.d.ts +66 -0
  125. package/lib/node/process-memory.d.ts.map +1 -0
  126. package/lib/node/process-memory.js +291 -0
  127. package/lib/node/process-memory.js.map +1 -0
  128. package/lib/noop-logger.d.ts.map +1 -1
  129. package/lib/noop-logger.js.map +1 -1
  130. package/lib/observable-value.js.map +1 -1
  131. package/lib/patch-merge.d.ts +63 -35
  132. package/lib/patch-merge.d.ts.map +1 -1
  133. package/lib/patch-merge.js +171 -25
  134. package/lib/patch-merge.js.map +1 -1
  135. package/lib/pending-work-tracker.d.ts +30 -0
  136. package/lib/pending-work-tracker.d.ts.map +1 -0
  137. package/lib/pending-work-tracker.js +47 -0
  138. package/lib/pending-work-tracker.js.map +1 -0
  139. package/lib/profile-session.d.ts +24 -8
  140. package/lib/profile-session.d.ts.map +1 -1
  141. package/lib/profile-session.js +13 -4
  142. package/lib/profile-session.js.map +1 -1
  143. package/lib/profiling.d.ts +15 -2
  144. package/lib/profiling.d.ts.map +1 -1
  145. package/lib/profiling.js.map +1 -1
  146. package/lib/project.d.ts +6 -2
  147. package/lib/project.d.ts.map +1 -1
  148. package/lib/project.js.map +1 -1
  149. package/lib/random-uuid.d.ts +14 -0
  150. package/lib/random-uuid.d.ts.map +1 -0
  151. package/lib/random-uuid.js +24 -0
  152. package/lib/random-uuid.js.map +1 -0
  153. package/lib/reconcile-write.d.ts +70 -0
  154. package/lib/reconcile-write.d.ts.map +1 -0
  155. package/lib/reconcile-write.js +69 -0
  156. package/lib/reconcile-write.js.map +1 -0
  157. package/lib/rpc/bind-rpc-methods.d.ts +6 -2
  158. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  159. package/lib/rpc/bind-rpc-methods.js +17 -7
  160. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  161. package/lib/rpc/create-rpc-proxy.d.ts +3 -0
  162. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  163. package/lib/rpc/create-rpc-proxy.js +6 -1
  164. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  165. package/lib/rpc/index.d.ts +1 -0
  166. package/lib/rpc/index.d.ts.map +1 -1
  167. package/lib/rpc/index.js +1 -0
  168. package/lib/rpc/index.js.map +1 -1
  169. package/lib/rpc/send-by-method-name.d.ts +76 -0
  170. package/lib/rpc/send-by-method-name.d.ts.map +1 -0
  171. package/lib/rpc/send-by-method-name.js +120 -0
  172. package/lib/rpc/send-by-method-name.js.map +1 -0
  173. package/lib/rpc/wire-prefix.js.map +1 -1
  174. package/lib/save-text-document.d.ts +40 -0
  175. package/lib/save-text-document.d.ts.map +1 -0
  176. package/lib/save-text-document.js +34 -0
  177. package/lib/save-text-document.js.map +1 -0
  178. package/lib/testing/catalogue-audit.js.map +1 -1
  179. package/lib/testing/data-doubles.d.ts +41 -12
  180. package/lib/testing/data-doubles.d.ts.map +1 -1
  181. package/lib/testing/data-doubles.js +56 -8
  182. package/lib/testing/data-doubles.js.map +1 -1
  183. package/lib/testing/fake-clock.d.ts +17 -2
  184. package/lib/testing/fake-clock.d.ts.map +1 -1
  185. package/lib/testing/fake-clock.js +61 -46
  186. package/lib/testing/fake-clock.js.map +1 -1
  187. package/lib/testing/index.d.ts +1 -0
  188. package/lib/testing/index.d.ts.map +1 -1
  189. package/lib/testing/index.js +4 -3
  190. package/lib/testing/index.js.map +1 -1
  191. package/lib/testing/node/duplex-connection.d.ts.map +1 -1
  192. package/lib/testing/node/duplex-connection.js +3 -2
  193. package/lib/testing/node/duplex-connection.js.map +1 -1
  194. package/lib/testing/node/duplex-stream.js.map +1 -1
  195. package/lib/testing/node/index.d.ts +1 -0
  196. package/lib/testing/node/index.d.ts.map +1 -1
  197. package/lib/testing/node/index.js +2 -2
  198. package/lib/testing/node/index.js.map +1 -1
  199. package/lib/testing/node/message-port-pair.d.ts +25 -0
  200. package/lib/testing/node/message-port-pair.d.ts.map +1 -0
  201. package/lib/testing/node/message-port-pair.js +26 -0
  202. package/lib/testing/node/message-port-pair.js.map +1 -0
  203. package/lib/testing/transfer-node-builder.d.ts +81 -0
  204. package/lib/testing/transfer-node-builder.d.ts.map +1 -0
  205. package/lib/testing/transfer-node-builder.js +47 -0
  206. package/lib/testing/transfer-node-builder.js.map +1 -0
  207. package/lib/testing/wait-for.d.ts +9 -3
  208. package/lib/testing/wait-for.d.ts.map +1 -1
  209. package/lib/testing/wait-for.js +57 -11
  210. package/lib/testing/wait-for.js.map +1 -1
  211. package/lib/tracer.d.ts.map +1 -1
  212. package/lib/tracer.js +5 -9
  213. package/lib/tracer.js.map +1 -1
  214. package/lib/transfer-diagnostic.d.ts +11 -0
  215. package/lib/transfer-diagnostic.d.ts.map +1 -1
  216. package/lib/transfer-diagnostic.js +17 -0
  217. package/lib/transfer-diagnostic.js.map +1 -1
  218. package/lib/transfer-document.d.ts +96 -32
  219. package/lib/transfer-document.d.ts.map +1 -1
  220. package/lib/transfer-document.js +17 -9
  221. package/lib/transfer-document.js.map +1 -1
  222. package/lib/transfer-element.d.ts +4 -4
  223. package/lib/types.d.ts +32 -0
  224. package/lib/types.d.ts.map +1 -0
  225. package/lib/{model-service/args.js → types.js} +2 -2
  226. package/lib/types.js.map +1 -0
  227. package/lib/uri.d.ts.map +1 -1
  228. package/lib/uri.js.map +1 -1
  229. package/lib/util.d.ts +8 -2
  230. package/lib/util.d.ts.map +1 -1
  231. package/lib/util.js +32 -4
  232. package/lib/util.js.map +1 -1
  233. package/package.json +24 -40
  234. package/src/abstract-logger.ts +18 -0
  235. package/src/client/data-connection.ts +654 -0
  236. package/src/client/data-events.ts +38 -1
  237. package/src/client/data-port.ts +36 -25
  238. package/src/client/data-session.ts +1479 -137
  239. package/src/client/index.ts +15 -9
  240. package/src/client/message-relay.ts +6 -4
  241. package/src/client/post-message-transport.ts +224 -4
  242. package/src/client/rpc-connection.ts +302 -0
  243. package/src/client/worker-handshake.ts +121 -0
  244. package/src/client-ids.ts +49 -0
  245. package/src/clock.ts +68 -10
  246. package/src/console-logger.ts +39 -0
  247. package/src/data/data-protocol-methods.ts +14 -4
  248. package/src/data/data-server-protocol.ts +203 -49
  249. package/src/data/events.ts +150 -33
  250. package/src/data/requests.ts +90 -11
  251. package/src/debouncer.ts +11 -11
  252. package/src/errors.ts +500 -65
  253. package/src/format-log-arg.ts +176 -0
  254. package/src/glsp-edits-settled-actions.ts +62 -0
  255. package/src/glsp-request-model-args.ts +16 -0
  256. package/src/glsp-save-model-actions.ts +64 -0
  257. package/src/index.ts +11 -0
  258. package/src/latency-collector.ts +10 -3
  259. package/src/logger.ts +44 -8
  260. package/src/messages/index.ts +12 -2
  261. package/src/messages/primitives.ts +129 -5
  262. package/src/model-server.ts +64 -19
  263. package/src/model-service/base-version.ts +75 -0
  264. package/src/model-service/index.ts +4 -5
  265. package/src/model-service/reference-candidate.ts +5 -3
  266. package/src/node/index.ts +14 -0
  267. package/src/node/process-memory.ts +299 -0
  268. package/src/patch-merge.ts +230 -45
  269. package/src/pending-work-tracker.ts +47 -0
  270. package/src/profile-session.ts +31 -11
  271. package/src/profiling.ts +15 -2
  272. package/src/project.ts +6 -2
  273. package/src/random-uuid.ts +21 -0
  274. package/src/reconcile-write.ts +131 -0
  275. package/src/rpc/README.md +6 -6
  276. package/src/rpc/bind-rpc-methods.ts +18 -8
  277. package/src/rpc/create-rpc-proxy.ts +6 -1
  278. package/src/rpc/index.ts +1 -0
  279. package/src/rpc/send-by-method-name.ts +140 -0
  280. package/src/save-text-document.ts +39 -0
  281. package/src/testing/data-doubles.ts +141 -19
  282. package/src/testing/fake-clock.ts +76 -48
  283. package/src/testing/index.ts +4 -3
  284. package/src/testing/node/duplex-connection.ts +3 -2
  285. package/src/testing/node/index.ts +2 -2
  286. package/src/testing/node/message-port-pair.ts +40 -0
  287. package/src/testing/transfer-node-builder.ts +107 -0
  288. package/src/testing/wait-for.ts +61 -13
  289. package/src/tracer.ts +5 -9
  290. package/src/transfer-diagnostic.ts +17 -0
  291. package/src/transfer-document.ts +116 -34
  292. package/src/transfer-element.ts +4 -4
  293. package/src/types.ts +30 -0
  294. package/src/util.ts +33 -6
  295. package/lib/model-service/args.d.ts +0 -64
  296. package/lib/model-service/args.d.ts.map +0 -1
  297. package/lib/model-service/args.js.map +0 -1
  298. package/src/model-service/args.ts +0 -67
@@ -10,16 +10,29 @@
10
10
  import type { TransferDiagnostic } from '../transfer-diagnostic';
11
11
  import type { TransferElement } from '../transfer-element';
12
12
  import type { Project } from '../project';
13
- import type { TransferDocument } from '../transfer-document';
13
+ import type { TransferCreatedDocument, TransferDocument, TransferSavedDocument, TransferWatchedDocument } from '../transfer-document';
14
14
  import type { CloseModelArgs, FindNextNameArgs, OpenModelArgs, ReferenceContext, ReferenceRequest } from '../model-server';
15
15
  import type { ReferenceCandidate, ReferenceTarget } from '../model-service/reference-candidate';
16
- import type { ProjectsChangedEvent, TransferDocumentSavedEvent, TransferDocumentUpdatedEvent } from './events';
17
16
  import type {
17
+ ProjectsChangedEvent,
18
+ TransferDocumentDeletedEvent,
19
+ TransferDocumentDirtyChangedEvent,
20
+ TransferDocumentSavedEvent,
21
+ TransferDocumentsBuiltEvent,
22
+ TransferDocumentUpdatedEvent
23
+ } from './events';
24
+ import type {
25
+ CloseSessionArgs,
26
+ CreateModelDocumentArgs,
27
+ CreateSessionArgs,
18
28
  GetModelDocumentArgs,
19
29
  GetProjectForUriArgs,
30
+ TransferDeleteDocumentArgs,
31
+ TransferPersistDocumentArgs,
20
32
  TransferSaveDocumentArgs,
21
33
  WatchModelDocumentArgs,
22
- TransferUpdateDocumentArgs
34
+ TransferUpdateDocumentArgs,
35
+ TransferUpdateDocumentsArgs
23
36
  } from './requests';
24
37
 
25
38
  /**
@@ -40,35 +53,81 @@ import type {
40
53
  */
41
54
  export interface DocumentServerProtocol<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic> {
42
55
  /**
43
- * Open a document for an editor session and return its current state.
44
- * Registers `(uri, clientId)` with the multi-client document manager
45
- * (so concurrent editors share one built document) and returns the
46
- * document at the server's configured target phase — the same shape
47
- * {@link getModelDocument} returns, except that `version` is taken from
48
- * the text-document store so the caller's first `baseVersion` write
49
- * cannot self-conflict. Idempotent in registration terms: opening an
50
- * already-open document refreshes the client registration. Note it does
51
- * NOT avoid a rebuild — a second client attaching triggers
52
- * `refreshContent`, which fires a change event, so mounting a form on a
53
- * document already open in a text editor rebuilds it.
56
+ * Register `args.clientId` as a client session owned by this connection.
57
+ * Rejects with a `DuplicateClientIdError` code when the id is live anywhere
58
+ * in the server process, and with a `ReservedClientIdError` code when the
59
+ * framework reserves it.
60
+ *
61
+ * A request carrying a registered id acts as that session: it writes only
62
+ * what the session has open, failing with a `DocumentNotOpenError` code
63
+ * otherwise, and opens nothing implicitly; its open reads the file and takes
64
+ * no `languageId`, `version` or `text` seed. The session ends with
65
+ * {@link closeSession} or when the connection closes, and either closes
66
+ * every document it has open.
54
67
  *
55
- * The default `DataServer` impl delegates to `ModelService.open` then
56
- * reads the built state. Pair with {@link watchModelDocument} to receive
57
- * subsequent build-phase events (open returns a one-shot snapshot;
58
- * later validation diagnostics arrive on the watch channel).
68
+ * A registration carrying the `resumeToken` an earlier registration of the
69
+ * same id carried ends that session first, from any connection, so a client
70
+ * whose connection dropped can register again before the server notices.
71
+ */
72
+ createSession(args: CreateSessionArgs): Promise<void>;
73
+
74
+ /**
75
+ * End a session this connection registered: close every document it has
76
+ * open, drop its watches, and free its id. A no-op for an id this
77
+ * connection did not register.
59
78
  */
60
- openModelDocument(args: OpenModelArgs): Promise<TransferDocument<TTransfer, TDiagnostic>>;
79
+ closeSession(args: CloseSessionArgs): Promise<void>;
61
80
 
62
81
  /**
63
- * Close an editor session for `(uri, clientId)`. Counterpart to
64
- * {@link openModelDocument}; the underlying document stays built until
65
- * every registered client has closed. The default `DataServer` impl
66
- * delegates to `ModelService.close` and ALSO releases any watch for the
67
- * same `(uri, clientId)` (closing a session frees its own watch — a
68
- * forgotten {@link unwatchModelDocument} would otherwise leak dispatch;
69
- * the implicit unwatch is idempotent). `watchModelDocument` is NOT
70
- * coupled the other way: opening does not force a watch, so a snapshot
71
- * reader can open without streaming.
82
+ * Create a document with `args.text`, open for the session, and return it
83
+ * as {@link openModelDocument} does, with the version the create made in
84
+ * `created`. The answer is read after the create, so it can already hold
85
+ * another client's write or an integrity repair; a write based on
86
+ * `created.version` then conflicts. It reaches disk with the first save.
87
+ * Fails when the file exists, any client has the URI open, or a lost
88
+ * client's unsaved text is held for it, and with a
89
+ * `SessionClosedError` code when `args.clientId` is not a session
90
+ * registered on this connection.
91
+ */
92
+ createModelDocument(args: CreateModelDocumentArgs): Promise<TransferCreatedDocument<TTransfer, TDiagnostic>>;
93
+
94
+ /**
95
+ * Write several documents the session has open, all or none: a conflict, a
96
+ * document not open, or a model for a document whose parse lacks some of
97
+ * its text fails the whole set before any text applies.
98
+ * Resolves to the documents in the order given, once the language client
99
+ * has answered the push of each, or the server-side bound on that wait
100
+ * passes, as {@link updateModelDocument} does. Only for a session
101
+ * registered on this connection.
102
+ */
103
+ updateModelDocuments(args: TransferUpdateDocumentsArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>[]>;
104
+
105
+ /**
106
+ * Open a document for the client session `clientId` and return its current
107
+ * state. `clientId` must be a session this connection registered with
108
+ * {@link createSession}; any other id fails with the closed-session code,
109
+ * as every document request here does. The document is read from disk
110
+ * unless a client has it open already, so the request carries no
111
+ * `languageId`, `version` or `text` seed. Returns the document at
112
+ * the server's configured target phase, as {@link getModelDocument} does.
113
+ * A repeat open changes nothing.
114
+ *
115
+ * Pair with {@link watchModelDocument} to receive subsequent build-phase
116
+ * events (open returns a one-shot snapshot; later validation diagnostics
117
+ * arrive on the watch channel).
118
+ */
119
+ openModelDocument(args: Pick<OpenModelArgs, 'uri' | 'clientId' | 'options'>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
120
+
121
+ /**
122
+ * Close the session's open of `uri`. Counterpart to
123
+ * {@link openModelDocument}; the document stays open until every client
124
+ * has closed it, and then the server releases it, by default reverting it
125
+ * to disk. The default
126
+ * `DataServer` impl ALSO releases any watch for the same
127
+ * `(uri, clientId)` (a forgotten {@link unwatchModelDocument} would
128
+ * otherwise leak dispatch; the implicit unwatch is idempotent).
129
+ * `watchModelDocument` is NOT coupled the other way: opening does not force
130
+ * a watch, so a snapshot reader can open without streaming.
72
131
  */
73
132
  closeModelDocument(args: CloseModelArgs): Promise<void>;
74
133
 
@@ -81,34 +140,75 @@ export interface DocumentServerProtocol<TTransfer extends TransferElement, TDiag
81
140
  getModelDocument(args: GetModelDocumentArgs): Promise<TransferDocument<TTransfer, TDiagnostic>>;
82
141
 
83
142
  /**
84
- * Update a document's content. The response carries the latest built
85
- * state including diagnostics; callers observe convergence via that
86
- * response.
143
+ * Update a document's content as the session `clientId`, which must have
144
+ * it open. The response carries the latest built state including
145
+ * diagnostics; callers observe convergence via that response. It is sent
146
+ * once the language client has answered the push of the text, or the
147
+ * server-side bound on that wait passes, as {@link saveModelDocument}'s
148
+ * is, so an editor already shows the write when it arrives. A model, not
149
+ * text, for a document whose parse lacks some of its text fails with a
150
+ * `DocumentSyntaxError` code, unless the write is a `restore`.
87
151
  */
88
152
  updateModelDocument(args: TransferUpdateDocumentArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
89
153
 
90
154
  /**
91
- * Persist a document to disk. The response is the post-save document
92
- * state (matches the file on disk). Save semantics depend on the
93
- * filesystem-provider wiring; rejection paths surface as awaited
94
- * promise rejections.
155
+ * Write a document as the session `clientId`, which must have it open, and
156
+ * persist it to disk. The response is the build of the text written, with
157
+ * its version in `persisted`, sent once the language client has answered
158
+ * the push of that text, applied or refused, or a server-side bound on
159
+ * that wait passes; it does not wait again for a push that wait already
160
+ * gave up on and the client has not answered since. Save semantics depend
161
+ * on the filesystem-provider wiring; rejection paths surface as awaited
162
+ * promise rejections, as a model for a document whose parse lacks some of
163
+ * its text does with a `DocumentSyntaxError` code.
95
164
  */
96
- saveModelDocument(args: TransferSaveDocumentArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
165
+ saveModelDocument(args: TransferSaveDocumentArgs<TTransfer>): Promise<TransferSavedDocument<TTransfer, TDiagnostic>>;
166
+
167
+ /**
168
+ * Persist the text the server holds for a document the session `clientId`
169
+ * has open, as it is: no update and no serialisation, so another client's
170
+ * unsaved text keeps its formatting. `baseVersion` is checked in the step
171
+ * that takes the text, so text that moved on fails with a `ConflictError`
172
+ * code. The saved event names this session, whoever wrote the text.
173
+ * Answers after the same language-client wait as {@link saveModelDocument},
174
+ * with the document's latest build, read after that wait, so another
175
+ * session's write during it shows; `persisted` carries the version written.
176
+ */
177
+ persistModelDocument(args: TransferPersistDocumentArgs): Promise<TransferSavedDocument<TTransfer, TDiagnostic>>;
178
+
179
+ /**
180
+ * Delete a document the session `clientId` has open, at once: its file,
181
+ * then the document, as a deletion a file watcher reports removes it. Every
182
+ * session's open of it closes and every client hears
183
+ * {@link DocumentClientProtocol.onDocumentDeleted} naming this session; the
184
+ * session's own watch is released, as {@link closeModelDocument} releases
185
+ * it. `baseVersion` is checked in the step that marks the document for
186
+ * deletion, so text that moved on fails with a `ConflictError` code. A file
187
+ * already gone deletes only the document; a file that cannot be removed
188
+ * fails the call and changes nothing. Resolves once the build that removes
189
+ * the document has run; a read then answers the URI without a model, unless
190
+ * an editor still has it open, whose buffer the document is built from.
191
+ */
192
+ deleteModelDocument(args: TransferDeleteDocumentArgs): Promise<void>;
97
193
 
98
194
  /**
99
195
  * Start watching `(uri, clientId)`. The server starts dispatching
100
196
  * {@link DocumentClientProtocol.onDocumentUpdated} on the paired wire
101
197
  * for every build-phase event on `uri`.
102
198
  *
103
- * Returns `Promise<void>` — the bidirectional pattern means the event
104
- * channel is the client interface, not a returned handle. Callers fan
105
- * out a single inbound `onDocumentUpdated` to multiple local listeners
106
- * with their own `Emitter<T>` (matching Theia's pattern). Pair every
107
- * `watchModelDocument` with {@link unwatchModelDocument} when no longer
108
- * needed; the server holds the watch record until the matching unwatch
109
- * lands.
199
+ * Answers with the key the watch's events name the document by, whether
200
+ * a document exists, taken once the watch is in place and the document
201
+ * is loaded as a read loads it, the text held at that moment, and the
202
+ * position of the last update or deletion event sent as of it, so an event
203
+ * the client heard while the watch was in flight tells by its own position
204
+ * whether it is newer than the answer. No handle: the event channel is the
205
+ * client interface. Callers fan out a single inbound `onDocumentUpdated` to
206
+ * multiple local listeners with their own `Emitter<T>` (matching Theia's
207
+ * pattern). Pair every `watchModelDocument` with
208
+ * {@link unwatchModelDocument} when no longer needed; the server holds the
209
+ * watch record until the matching unwatch lands.
110
210
  */
111
- watchModelDocument(args: WatchModelDocumentArgs): Promise<void>;
211
+ watchModelDocument(args: WatchModelDocumentArgs): Promise<TransferWatchedDocument>;
112
212
 
113
213
  /**
114
214
  * Stop watching `(uri, clientId)` previously started by
@@ -194,6 +294,22 @@ export interface DataServerProtocol<
194
294
  >
195
295
  extends DocumentServerProtocol<TTransfer, TDiagnostic>, ProjectServerProtocol<TProject> {}
196
296
 
297
+ /**
298
+ * The diagnostic shape a server answers with, read back off its own
299
+ * declaration.
300
+ *
301
+ * This is what lets a client tier stay generic over the server alone and still
302
+ * describe what it hands back. Both parameters must be inferred: naming
303
+ * {@link TransferElement} for the transfer instead fails to match while that
304
+ * parameter is still generic, and a default declared against the constraint
305
+ * then stops satisfying it.
306
+ */
307
+ export type DiagnosticOf<TServer> =
308
+ TServer extends DocumentServerProtocol<infer _TTransfer, infer TDiagnostic> ? TDiagnostic : TransferDiagnostic;
309
+
310
+ /** The project shape a server answers with, read back off its own declaration. */
311
+ export type ProjectOf<TServer> = TServer extends ProjectServerProtocol<infer TProject> ? TProject : Project;
312
+
197
313
  /**
198
314
  * Cross-reference / naming slice of the server surface — scope-aware
199
315
  * queries that resolve against the language's reference services. NOT part
@@ -204,11 +320,11 @@ export interface DataServerProtocol<
204
320
  * source/URI (an `ElementSource` with no URI resolves to the sole
205
321
  * registered language; a multi-language workspace overrides).
206
322
  *
207
- * Generic over the transfer root type only — the resolution result
208
- * ({@link ReferenceTarget}) carries the resolved node's encoded subtree;
209
- * candidates and names are diagnostic-free.
323
+ * Not generic over a server's root type: {@link resolveReference} answers with
324
+ * a node a reference names, which is no document root, and candidates and
325
+ * names are diagnostic-free.
210
326
  */
211
- export interface ReferenceServerProtocol<TTransfer extends TransferElement> {
327
+ export interface ReferenceServerProtocol {
212
328
  /**
213
329
  * List the reference candidates reachable for the property named in `ctx`
214
330
  * from its (possibly synthetic) source. Backed by the language's
@@ -221,8 +337,13 @@ export interface ReferenceServerProtocol<TTransfer extends TransferElement> {
221
337
  * target's document URI, display fields, and the resolved node's encoded
222
338
  * transfer subtree. Resolves via the language's reference services;
223
339
  * `undefined` when the reference does not resolve.
340
+ *
341
+ * `TElement` is the caller's claim about the target node's type; nothing
342
+ * checks it, so leave it at the default unless the reference names one type.
224
343
  */
225
- resolveReference(ref: ReferenceRequest): Promise<ReferenceTarget<TTransfer> | undefined>;
344
+ resolveReference<TElement extends TransferElement = TransferElement>(
345
+ ref: ReferenceRequest
346
+ ): Promise<ReferenceTarget<TElement> | undefined>;
226
347
 
227
348
  /**
228
349
  * Compute the next free name for a new element of `args.type` based on
@@ -262,6 +383,39 @@ export interface DocumentClientProtocol<TTransfer extends TransferElement, TDiag
262
383
  * codepath, not a subscription codepath).
263
384
  */
264
385
  onDocumentSaved(event: TransferDocumentSavedEvent<TTransfer, TDiagnostic>): void;
386
+
387
+ /**
388
+ * Delivered when a subscribed document's text starts or stops differing
389
+ * from its file, as the server last knew it. Gated like
390
+ * {@link onDocumentSaved}; the answer at any one moment is the `dirty` of
391
+ * the documents the server sends. After a reconnect, a `DataSession`
392
+ * delivers here the answer of each document it restored, when that differs
393
+ * from the last this client was told: the flips while the connection was
394
+ * down reached no one.
395
+ */
396
+ onDocumentDirtyChanged(event: TransferDocumentDirtyChangedEvent): void;
397
+
398
+ /**
399
+ * Delivered when a document's backing file was removed. Separate from
400
+ * {@link onDocumentUpdated} for the same reason as {@link onDocumentSaved},
401
+ * and more strongly: there is no built state to deliver, and the build-phase
402
+ * path cannot report a deletion at all.
403
+ *
404
+ * Ungated, because on a browser host — where the workspace lives behind the
405
+ * head — no other source can observe a file disappearing. Recipients that
406
+ * only care about their own documents filter by URI.
407
+ */
408
+ onDocumentDeleted(event: TransferDocumentDeletedEvent): void;
409
+
410
+ /**
411
+ * Delivered once per build, naming the documents that reached the
412
+ * subscription phase and that
413
+ * nobody on this connection watches — chiefly the ones rebuilt as a cascade
414
+ * from a dependency's change, which no filesystem watcher can see because
415
+ * their own files did not change. The complement of
416
+ * {@link onDocumentUpdated}; carries URIs and no documents.
417
+ */
418
+ onDocumentsBuilt(event: TransferDocumentsBuiltEvent): void;
265
419
  }
266
420
 
267
421
  /**
@@ -10,46 +10,63 @@
10
10
  import type { TransferDiagnostic } from '../transfer-diagnostic';
11
11
  import type { TransferElement } from '../transfer-element';
12
12
  import type { Project } from '../project';
13
- import type { TransferDocument } from '../transfer-document';
13
+ import type { TextState, TransferDocument } from '../transfer-document';
14
14
 
15
15
  /**
16
16
  * Why an update event fired. Subscribers filter on reason for behaviour
17
17
  * decisions (e.g. dirty-flag handling, undo-history grouping, telemetry):
18
18
  *
19
- * - `'changed'` — the URI appeared in `DocumentBuilder.onUpdate`'s
20
- * `changed` list. The framework's underlying primitive is "this URI was
21
- * passed to `documentBuilder.update(changed, deleted)`", which spans
22
- * `didChange` text-document events, `notifyDidChangeTextDocument` calls,
23
- * and any programmatic `documentBuilder.update([uri], [])` invocation.
24
- * The name matches Langium's own `changed` parameter — it's vague-on-
25
- * purpose because the underlying primitive is.
26
- * - `'rebuilt'` — the URI was rebuilt as a cascade from another URI's
27
- * build (dependency graph re-derivation), without itself being passed to
28
- * `documentBuilder.update`. The complement of `'changed'`.
19
+ * - `'changed'` — the server's first update event for the document's current
20
+ * version: its content changed since the last one. A write whose build a
21
+ * later write cancelled is still `'changed'` in the build that takes over.
22
+ * - `'rebuilt'` — a later event for a version the server already delivered,
23
+ * whether or not any client watched it then: something the document depends
24
+ * on changed, or the document was built again with the same content. The
25
+ * complement of `'changed'`.
29
26
  * - `'saved'` — emitted by adopters that synthesise a unified update stream
30
27
  * from both `onDocumentUpdated` and `onDocumentSaved`. The framework's own
31
28
  * `dispatchPhaseEvent` does NOT emit `'saved'` — saves take the dedicated
32
29
  * `DataClientProtocol.onDocumentSaved` channel.
33
- * - `'deleted'` — the URI appeared in `DocumentBuilder.onUpdate`'s
34
- * `deleted` list. The backing file was removed.
30
+ *
31
+ * The version rule needs a version the server keeps and builds that validate.
32
+ * For a document no client has opened, or when rebuilds do not validate,
33
+ * `'changed'` means the URI was passed to `DocumentBuilder.update` for this
34
+ * build. A document that a validating build skips is `'changed'` every time.
35
+ *
36
+ * Deletion is deliberately NOT a member. An update event carries a built
37
+ * document, which a deleted one has none of, and the phase-driven path that
38
+ * produces these events never runs for a deleted URI — the builder drops the
39
+ * document before deriving the rebuild set. It travels as
40
+ * {@link TransferDocumentDeletedEvent} on its own channel instead.
35
41
  */
36
- export type TransferDocumentUpdateReason = 'changed' | 'rebuilt' | 'saved' | 'deleted';
42
+ export type TransferDocumentUpdateReason = 'changed' | 'rebuilt' | 'saved';
37
43
 
38
44
  /**
39
45
  * Delivered on the data-server when a document's content (or existence)
40
46
  * changed. Subscribers receive this via `DocumentServerProtocol.watchModelDocument`.
41
- *
42
- * The `document` field carries the latest built state — diagnostics + root
43
- * are coherent with each other at the time the event fired.
44
47
  */
45
48
  export interface TransferDocumentUpdatedEvent<
46
49
  TTransfer extends TransferElement,
47
50
  TDiagnostic extends TransferDiagnostic = TransferDiagnostic
48
51
  > {
52
+ /** The latest built state: diagnostics and root are coherent with each other at the time the event fired. */
49
53
  document: TransferDocument<TTransfer, TDiagnostic>;
50
- /** Stable identifier of the client that triggered the update. */
54
+ /**
55
+ * The client whose write this event echoes: the author of the version on a
56
+ * `'changed'`, and the unknown-client id on a `'rebuilt'`, which echoes no
57
+ * write. A recipient compares it against its own id to recognise its echo.
58
+ * The build that follows a document's release names the release id
59
+ * instead.
60
+ */
51
61
  sourceClientId: string;
62
+ /** See {@link TransferDocumentUpdateReason} for which reasons the framework sends. */
52
63
  reason: TransferDocumentUpdateReason;
64
+ /**
65
+ * The position of this event among the update and deletion events the
66
+ * server sent on this connection, which a watch's answer carries as of
67
+ * the moment it was taken: a greater one was sent later.
68
+ */
69
+ sequence: number;
53
70
  }
54
71
 
55
72
  /** Callback shape for `DataClientProtocol.onDocumentUpdated`. */
@@ -59,28 +76,25 @@ export type TransferDocumentUpdatedListener<
59
76
  > = (event: TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>) => void;
60
77
 
61
78
  /**
62
- * Delivered on the data-server when a document was persisted to disk via
63
- * `DataServerProtocol.saveModelDocument`. Distinct from
64
- * {@link TransferDocumentUpdatedEvent}: subscribers that only care about
65
- * persistence (external sync, editor "saved" indicators, dirty-flag
66
- * clear) listen for this event family instead of filtering an update
67
- * stream for `reason: 'saved'`.
68
- *
69
- * The `document` field carries the post-save built state — same shape
70
- * the synchronous `saveModelDocument` RPC response returns, delivered
71
- * to subscribers (`DataClientProtocol.onDocumentSaved`) so non-caller
72
- * clients see the persistence event too.
79
+ * Delivered on the data-server when a subscribed document was saved to disk,
80
+ * whichever client saved it, an editor's save through the LSP head included.
81
+ * Distinct from {@link TransferDocumentUpdatedEvent}: subscribers that only
82
+ * care about persistence (external sync, editor "saved" indicators,
83
+ * dirty-flag clear) listen for this event family instead of filtering an
84
+ * update stream for `reason: 'saved'`.
73
85
  */
74
86
  export interface TransferDocumentSavedEvent<
75
87
  TTransfer extends TransferElement,
76
88
  TDiagnostic extends TransferDiagnostic = TransferDiagnostic
77
89
  > {
90
+ /** The latest built state, taken after the save. */
78
91
  document: TransferDocument<TTransfer, TDiagnostic>;
79
92
  /**
80
- * The client whose `saveModelDocument` call produced this. Every subscriber
81
- * receives the event including the originator, which already had the same
82
- * state as the RPC response — compare against your own id to drop the echo
83
- * rather than re-rendering from it.
93
+ * The client whose save produced this, also when another client wrote the
94
+ * persisted text: the caller of `saveModelDocument` or
95
+ * `persistModelDocument`, or `LANGUAGE_CLIENT_ID` for an editor's save
96
+ * through the LSP head. Every subscriber receives the event, the saving
97
+ * client included, so compare against your own id to drop the echo.
84
98
  */
85
99
  sourceClientId: string;
86
100
  }
@@ -91,6 +105,109 @@ export type TransferDocumentSavedListener<
91
105
  TDiagnostic extends TransferDiagnostic = TransferDiagnostic
92
106
  > = (event: TransferDocumentSavedEvent<TTransfer, TDiagnostic>) => void;
93
107
 
108
+ /**
109
+ * Delivered on the data-server when a watched document's text starts or stops
110
+ * differing from its file, as the server last knew the file. The current
111
+ * answer rides on every transfer document the server sends as `text.dirty`;
112
+ * this carries only its changes, so a client that follows it needs no rebuild
113
+ * to learn of a save.
114
+ */
115
+ export interface TransferDocumentDirtyChangedEvent {
116
+ /** Canonical URI, keyed as the subscription is. */
117
+ readonly uri: string;
118
+ /**
119
+ * The text the answer was decided on. It is sent before that text is
120
+ * built, so a `text.version` ahead of the model a client holds means an
121
+ * update at this version or a later one follows. Absent when the document
122
+ * no longer exists, or when the build that follows its release failed.
123
+ */
124
+ readonly text?: TextState;
125
+ }
126
+
127
+ /** Callback shape for `DataClientProtocol.onDocumentDirtyChanged`. */
128
+ export type TransferDocumentDirtyChangedListener = (event: TransferDocumentDirtyChangedEvent) => void;
129
+
130
+ /**
131
+ * Delivered on the data-server when a document's backing file was removed.
132
+ * Carries no document, and cannot: the state a
133
+ * {@link TransferDocumentUpdatedEvent} would have to carry no longer exists by
134
+ * the time anyone can be told. That is also why deletion is not a `reason` on
135
+ * the update stream — `DocumentBuilder.update` drops the document before
136
+ * deriving the rebuild set, so the phase-driven path that produces update
137
+ * events never runs for it.
138
+ *
139
+ * **Delivered for EVERY document, not only watched ones**, unlike
140
+ * `onDocumentUpdated` and `onDocumentSaved`. The test that decides which
141
+ * channels are gated is whether any OTHER source can observe the fact on the
142
+ * least capable host: a browser-hosted client's workspace lives behind the
143
+ * head, so nothing there can see a file disappear, and gating the notification
144
+ * would leave it blind. (A Theia frontend's filesystem watcher would cover it,
145
+ * which is why this is a host argument and not a structure-versus-content one.)
146
+ * A watcher is told about its own document's deletion here too, the update
147
+ * channel being silent for deletions by construction. Filter on {@link uri} if
148
+ * the receiver only cares about documents it opened.
149
+ *
150
+ * A watch survives the deletion, so a file that comes back resumes delivering
151
+ * `onDocumentUpdated` to the same subscribers with no re-subscription. A
152
+ * client that responds by closing its editor releases the watch through
153
+ * `closeModelDocument` as usual, and `deleteModelDocument` releases the
154
+ * deleting session's own.
155
+ */
156
+ export interface TransferDocumentDeletedEvent {
157
+ /** Canonical URI of the removed document, keyed as the subscription is. */
158
+ readonly uri: string;
159
+ /**
160
+ * The session whose `deleteModelDocument` removed the file, so it can tell
161
+ * its own deletion from another's; the unknown-client id for a file
162
+ * removed outside any session, as a file watcher reports one, and for one
163
+ * a `DataConnection` found gone after a reconnect, which no event named.
164
+ */
165
+ readonly sourceClientId: string;
166
+ /**
167
+ * The position of this event among the update and deletion events the
168
+ * server sent on this connection, as on an update; absent on a deletion a
169
+ * `DataConnection` found after a reconnect, which the server never sent.
170
+ */
171
+ readonly sequence?: number;
172
+ }
173
+
174
+ /** Callback shape for `DataClientProtocol.onDocumentDeleted`. */
175
+ export type TransferDocumentDeletedListener = (event: TransferDocumentDeletedEvent) => void;
176
+
177
+ /**
178
+ * Delivered on the data-server once per build, naming the documents that reached
179
+ * the configured subscription phase (`DataServerOptions.subscriptionPhase`,
180
+ * `Validated` by default) and that NO client on the connection is watching. Not
181
+ * the integrity-settled landmark, which is a different point and a different
182
+ * word in this framework.
183
+ *
184
+ * The complement of {@link TransferDocumentUpdatedEvent}, which is gated per
185
+ * URI: together the two cover every document a build touched. This one exists
186
+ * for the case no source outside the server can observe — a document rebuilt
187
+ * because something it DEPENDS ON changed. Its own file never changed, so a
188
+ * filesystem watcher cannot see it, and it has no subscriber, so the update
189
+ * channel does not report it. A consumer showing data derived from such a
190
+ * document (a tree label, a decorator) would otherwise hold a stale value with
191
+ * nothing to invalidate it.
192
+ *
193
+ * Carries URIs and no documents: a recipient re-reads what it displays, through
194
+ * `getModelDocument` or its own request. That keeps the bandwidth property the
195
+ * per-URI subscription exists for, without gating the message.
196
+ *
197
+ * Not sent when the set is empty, which is the normal case while editing — the
198
+ * document being edited is watched by its own editor and therefore excluded.
199
+ * Workspace initialisation sends nothing either: it does not build to the
200
+ * subscription phase. The largest message a workspace can produce is therefore
201
+ * a whole-workspace rebuild at that phase, which is one message of URIs.
202
+ */
203
+ export interface TransferDocumentsBuiltEvent {
204
+ /** Canonical URIs, keyed as subscriptions are. Never empty. */
205
+ readonly uris: readonly string[];
206
+ }
207
+
208
+ /** Callback shape for `DataClientProtocol.onDocumentsBuilt`. */
209
+ export type TransferDocumentsBuiltListener = (event: TransferDocumentsBuiltEvent) => void;
210
+
94
211
  /**
95
212
  * Why a project-change event fired. `added` — the project was newly
96
213
  * registered (descriptor discovered); `updated` — the project's