@hydranium/data-server 1.0.0-next.27 → 1.0.0-next.270
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.
- package/README.md +53 -73
- package/lib/data-server.d.ts +400 -290
- package/lib/data-server.d.ts.map +1 -1
- package/lib/data-server.js +646 -490
- package/lib/data-server.js.map +1 -1
- package/lib/messages/index.d.ts +1 -1
- package/lib/messages/index.d.ts.map +1 -1
- package/lib/messages/index.js +1 -1
- package/lib/messages/index.js.map +1 -1
- package/lib/node/node-diagnostics-provider.d.ts.map +1 -1
- package/lib/node/node-diagnostics-provider.js +2 -1
- package/lib/node/node-diagnostics-provider.js.map +1 -1
- package/lib/testing/data-server-harness.d.ts +31 -14
- package/lib/testing/data-server-harness.d.ts.map +1 -1
- package/lib/testing/data-server-harness.js +8 -3
- package/lib/testing/data-server-harness.js.map +1 -1
- package/lib/testing/index.d.ts +1 -0
- package/lib/testing/index.d.ts.map +1 -1
- package/lib/testing/index.js.map +1 -1
- package/package.json +32 -44
- package/src/data-server.ts +792 -531
- package/src/messages/index.ts +8 -1
- package/src/node/node-diagnostics-provider.ts +2 -8
- package/src/testing/data-server-harness.ts +55 -26
- package/src/testing/index.ts +5 -2
package/lib/data-server.d.ts
CHANGED
|
@@ -6,28 +6,42 @@
|
|
|
6
6
|
*
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
|
-
import { DisposableCollection, ReferenceSource, type CloseModelArgs, type HydraniumResponseError, type Disposable, type ElementSource, type FindNextNameArgs, type LatencyCollector, type LatencyReport, type OpenModelArgs, type Project, type ReferenceCandidate, type ReferenceContext, type ReferenceRequest, type ReferenceTarget, type Tracer, type TransferDiagnostic, type
|
|
10
|
-
import { type DataClientProtocol, type DataServerDiagnosticsProtocol, type DataServerProtocol, type DumpServerStateArgs, type StartProfilingArgs, type StopProfilingArgs, type WriteServerHeapSnapshotArgs, type GetModelDocumentArgs, type GetProjectForUriArgs, type TransferSaveDocumentArgs, type WatchModelDocumentArgs, type
|
|
9
|
+
import { DisposableCollection, ReferenceSource, type CloseModelArgs, type HydraniumMessageData, type HydraniumResponseError, type CanonicalUri, type Disposable, type ElementSource, type FindNextNameArgs, type LatencyCollector, type LatencyReport, type OpenModelArgs, type Project, type ReferenceCandidate, type ReferenceContext, type ReferenceRequest, type ReferenceTarget, type ModelVersion, type TextState, type Tracer, type TransferDiagnostic, TransferDocument, type TransferSavedDocument, type TransferElement } from '@hydranium/protocol';
|
|
10
|
+
import { type DataClientProtocol, type DataServerDiagnosticsProtocol, type DataServerProtocol, type DumpServerStateArgs, type StartProfilingArgs, type StopProfilingArgs, type WriteServerHeapSnapshotArgs, type CloseSessionArgs, type CreateModelDocumentArgs, type CreateSessionArgs, type GetModelDocumentArgs, type GetProjectForUriArgs, type TransferPersistDocumentArgs, type TransferSaveDocumentArgs, type WatchModelDocumentArgs, type TransferUpdateDocumentArgs, type TransferUpdateDocumentsArgs } from '@hydranium/protocol/data';
|
|
11
11
|
/**
|
|
12
12
|
* Raised when a profiling command arrives with no capture running.
|
|
13
13
|
*
|
|
14
|
-
* A `ResponseError` rather than a plain `Error` so the identity survives the
|
|
15
|
-
*
|
|
16
|
-
* internal error
|
|
17
|
-
*
|
|
14
|
+
* A `ResponseError` rather than a plain `Error` so the identity survives to the
|
|
15
|
+
* response boundary, which is where the message is rendered. An unwrapped throw
|
|
16
|
+
* reaches the client as a generic internal error instead: no code for a caller
|
|
17
|
+
* to switch on, and nothing for the boundary to render from.
|
|
18
18
|
*/
|
|
19
19
|
export declare const NO_ACTIVE_PROFILE: import("@hydranium/protocol").MessageDefinition<"No profiling capture is active; call startProfiling first.">;
|
|
20
20
|
/**
|
|
21
21
|
* The JSON-RPC code, unrelated to the catalogue code above: this one is numeric,
|
|
22
22
|
* survives reconstruction and is what a caller switches on.
|
|
23
23
|
*/
|
|
24
|
-
export declare const NO_ACTIVE_PROFILE_CODE
|
|
24
|
+
export declare const NO_ACTIVE_PROFILE_CODE: 42002;
|
|
25
25
|
export declare const noActiveProfileError: () => HydraniumResponseError;
|
|
26
|
+
/**
|
|
27
|
+
* Raised when a reference question's wait for the build exceeds
|
|
28
|
+
* {@link DataServerOptions.referenceSettleTimeoutMs}.
|
|
29
|
+
*
|
|
30
|
+
* A `ResponseError` because a class name does not cross RPC: without the code a
|
|
31
|
+
* wire client cannot tell a wedged build from a reference that resolves to
|
|
32
|
+
* nothing, which is the distinction the wait exists to keep.
|
|
33
|
+
*/
|
|
34
|
+
export declare const REFERENCE_SETTLE_TIMEOUT: import("@hydranium/protocol").MessageDefinition<"The model is still being processed; try again in a moment.">;
|
|
35
|
+
/** See {@link NO_ACTIVE_PROFILE_CODE} for why this is separate from the catalogue code. */
|
|
36
|
+
export declare const REFERENCE_SETTLE_TIMEOUT_CODE: 42003;
|
|
37
|
+
/** The wait's length rides in `data` as `elapsedMs`, for the code that reacts rather than the reader. */
|
|
38
|
+
export declare const referenceSettleTimeoutError: (elapsedMs: number) => ResponseError<HydraniumMessageData & {
|
|
39
|
+
readonly elapsedMs: number;
|
|
40
|
+
}>;
|
|
26
41
|
import type { DataServerDiagnosticsProvider, DataServerProfileCapture } from './diagnostics-provider.js';
|
|
27
|
-
import type {
|
|
28
|
-
import type
|
|
29
|
-
import { type
|
|
30
|
-
import type { CancellationToken, MessageConnection } from 'vscode-jsonrpc';
|
|
42
|
+
import type { ClientSession, ClientSessionWriteArgs, HydraniumLanguageServices, LogNameOptions, AstDiagnostic, AstDocument, AstDocumentSavedEvent, EncodedTransferDocument, ModelDeletedEvent, ModelDirtyChangedEvent, ModelService, ModelUpdatedEvent, ProjectChangeEvent, ServerSharedServices, SessionEndCause, TransferEncoder } from '@hydranium/core';
|
|
43
|
+
import { type AstNode, DocumentState, type URI } from '@hydranium/langium';
|
|
44
|
+
import { type MessageConnection, ResponseError } from 'vscode-jsonrpc';
|
|
31
45
|
/**
|
|
32
46
|
* Which observable state {@link DataServer.computeDocumentFingerprint} hashes to
|
|
33
47
|
* de-dup `onDocumentUpdated` emissions.
|
|
@@ -39,9 +53,9 @@ import type { CancellationToken, MessageConnection } from 'vscode-jsonrpc';
|
|
|
39
53
|
* folded in on a cascade rebuild that leaves the document's own text
|
|
40
54
|
* untouched. Safe for any adopter whose AST extensions fold derived state
|
|
41
55
|
* into the transfer projection (the framework norm).
|
|
42
|
-
* - `'text-diagnostics'` — the cheaper
|
|
43
|
-
* opt-DOWN for adopters that fold no derived state and want to avoid
|
|
44
|
-
* transfer
|
|
56
|
+
* - `'text-diagnostics'` — the cheaper parsed-text + diagnostics hash. An
|
|
57
|
+
* opt-DOWN for adopters that fold no derived state and want to avoid
|
|
58
|
+
* stringifying the transfer root per phase event.
|
|
45
59
|
*/
|
|
46
60
|
export type FingerprintStrategy = 'transfer-document' | 'text-diagnostics';
|
|
47
61
|
/**
|
|
@@ -54,12 +68,13 @@ export interface DataServerOptions extends LogNameOptions {
|
|
|
54
68
|
* (`DataClientProtocol.onDocumentUpdated`).
|
|
55
69
|
*
|
|
56
70
|
* **Subscription dispatch only** — distinct from the synchronous RPC
|
|
57
|
-
* response phase.
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* controls only the async notification
|
|
71
|
+
* response phase. A read (`getModelDocument`) settles at the
|
|
72
|
+
* integrity-settled landmark (`IntegrityService.SettledState`), or at
|
|
73
|
+
* `Validated` when {@link GetModelDocumentArgs.includeDiagnostics} is set.
|
|
74
|
+
* A write (`updateModelDocument` / `updateModelDocuments` /
|
|
75
|
+
* `saveModelDocument`) answers once its document is validated, as a
|
|
76
|
+
* session's write does. This option controls only the async notification
|
|
77
|
+
* phase.
|
|
63
78
|
*
|
|
64
79
|
* Default: `DocumentState.Validated` — validation is the last builder
|
|
65
80
|
* phase and produces the full diagnostic set, so subscription events fired
|
|
@@ -97,6 +112,21 @@ export interface DataServerOptions extends LogNameOptions {
|
|
|
97
112
|
* state included). See {@link FingerprintStrategy}.
|
|
98
113
|
*/
|
|
99
114
|
readonly fingerprintStrategy?: FingerprintStrategy;
|
|
115
|
+
/**
|
|
116
|
+
* How long a reference question waits for the build to reach `Linked` before
|
|
117
|
+
* failing with {@link REFERENCE_SETTLE_TIMEOUT_CODE}. Bounded because the
|
|
118
|
+
* wait resolves off a build-phase notification, so a build cancelled below
|
|
119
|
+
* `Linked` with nothing after it leaves the request unanswered for the life
|
|
120
|
+
* of the server.
|
|
121
|
+
*
|
|
122
|
+
* Expiry rejects rather than reading the index anyway: the unsettled index
|
|
123
|
+
* is what the wait keeps the caller away from, so falling through to it on a
|
|
124
|
+
* slow build reinstates the fault — and on a name proposal persists it.
|
|
125
|
+
*
|
|
126
|
+
* Default {@link DataServer.DEFAULT_OPTIONS}, sized for a cold workspace
|
|
127
|
+
* still reaching `Linked` for the first time.
|
|
128
|
+
*/
|
|
129
|
+
readonly referenceSettleTimeoutMs?: number;
|
|
100
130
|
/**
|
|
101
131
|
* Wire-method namespace for both inbound request handlers and the
|
|
102
132
|
* outbound notification client proxy. Defaults to
|
|
@@ -151,14 +181,19 @@ export interface DataServerOptions extends LogNameOptions {
|
|
|
151
181
|
* When supplied, every inbound data-server RPC is timed into this collector
|
|
152
182
|
* (via the `createRpcProxy` binding) and exposed through
|
|
153
183
|
* {@link DataServerDiagnosticsProtocol.getLatency}. A head that also runs an
|
|
154
|
-
* LSP connection can pass the SAME collector to
|
|
155
|
-
*
|
|
156
|
-
*
|
|
184
|
+
* LSP connection can pass the SAME collector through `lspLatencyOptions` to
|
|
185
|
+
* that connection, so one report covers both heads. Absent by default (no
|
|
186
|
+
* timing overhead).
|
|
157
187
|
*/
|
|
158
188
|
readonly latency?: LatencyCollector;
|
|
159
189
|
}
|
|
160
|
-
/**
|
|
161
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Fully-resolved variant of {@link DataServerOptions} — every field set, after
|
|
192
|
+
* merging defaults. Returned by the `protected`
|
|
193
|
+
* {@link DataServer.resolveOptions} and held on {@link DataServer.options}, so
|
|
194
|
+
* an adopter changing how defaults resolve has to name it.
|
|
195
|
+
*/
|
|
196
|
+
export interface ResolvedDataServerOptions {
|
|
162
197
|
readonly subscriptionPhase: DocumentState;
|
|
163
198
|
readonly fingerprintStrategy: FingerprintStrategy;
|
|
164
199
|
readonly methodNamespace: string;
|
|
@@ -166,6 +201,40 @@ interface ResolvedDataServerOptions {
|
|
|
166
201
|
readonly excludedMethods: readonly string[];
|
|
167
202
|
/** Always resolved — to the caller's, or to the platform default. */
|
|
168
203
|
readonly diagnostics: DataServerDiagnosticsProvider;
|
|
204
|
+
readonly referenceSettleTimeoutMs: number;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* What a {@link DataServer} keeps per canonical URI, in the `protected`
|
|
208
|
+
* {@link DataServer.uriWatchRecords}. A record lives while it has a watcher
|
|
209
|
+
* or a release mark; {@link DataServer.pruneUriWatchRecord} enforces that on
|
|
210
|
+
* every path that removes either, so a record with no watcher has a release
|
|
211
|
+
* broadcast pending. Test the size of {@link DataServerUriWatchRecord.watchers}, not the
|
|
212
|
+
* record's presence, for "watched".
|
|
213
|
+
*/
|
|
214
|
+
export interface DataServerUriWatchRecord {
|
|
215
|
+
/** The client ids watching the URI; save, dirty and phase events go out only while it is non-empty, a pending release mark aside. */
|
|
216
|
+
readonly watchers: Set<string>;
|
|
217
|
+
/** Digest of the last emitted state, or of the state a first watch found; see {@link DataServer.dispatchPhaseEvent} for why it de-duplicates, {@link DataServer.computeDocumentFingerprint} for its inputs. */
|
|
218
|
+
fingerprint?: string;
|
|
219
|
+
/**
|
|
220
|
+
* The version {@link DataServerUriWatchRecord.fingerprint} was taken at; an
|
|
221
|
+
* event goes out when either moves. Not {@link DataServerUriWatchRecord.sentVersion}:
|
|
222
|
+
* a first watch sets this and sends nothing, so the next event at its
|
|
223
|
+
* version still carries the manager's attribution.
|
|
224
|
+
*/
|
|
225
|
+
fingerprintVersion?: ModelVersion;
|
|
226
|
+
/** Set by {@link DataServer.subscribeToModelReleases} once a release happened: its broadcast, the next phase event, goes out even without a watcher. */
|
|
227
|
+
releaseBroadcastPending?: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* The version of an open document the last event sent was built at. The
|
|
230
|
+
* version sent again goes out as `'rebuilt'` from no client: the manager
|
|
231
|
+
* counts a version delivered only once its `Validated` listeners ran, so a
|
|
232
|
+
* build cancelled after the subscription phase would send it as a change
|
|
233
|
+
* twice. Only while the store has the document open: without it, a
|
|
234
|
+
* document can keep one version through changes of its file, so its events
|
|
235
|
+
* keep the manager's attribution.
|
|
236
|
+
*/
|
|
237
|
+
sentVersion?: number;
|
|
169
238
|
}
|
|
170
239
|
/**
|
|
171
240
|
* Typed-RPC protocol head for the hydranium framework. The data-server
|
|
@@ -188,13 +257,19 @@ interface ResolvedDataServerOptions {
|
|
|
188
257
|
* adopters subclass ONLY when they need to decorate wire returns or
|
|
189
258
|
* notifications. The usual adoption path is DI rebinds alone.
|
|
190
259
|
*
|
|
260
|
+
* **`TTransfer` is not checked.** It declares the union of the transfer roots
|
|
261
|
+
* the workspace's languages produce. Which root a document has is known only
|
|
262
|
+
* at runtime, from its language, so a `TTransfer` missing a language compiles.
|
|
263
|
+
*
|
|
191
264
|
* Lifecycle: the constructor registers framework request handlers (plus
|
|
192
265
|
* any names supplied via {@link DataServerOptions.additionalMethods}) and
|
|
193
266
|
* builds the {@link DataClientProtocol} notification proxy on the same
|
|
194
267
|
* connection in one {@link createRpcProxy} call (binding `this` as its
|
|
195
|
-
* `localTarget`) under the configured namespace, and
|
|
196
|
-
* `
|
|
197
|
-
* dispatches
|
|
268
|
+
* `localTarget`) under the configured namespace, and follows documents
|
|
269
|
+
* through `ModelService`'s events: at the configured phase, `onModelUpdated`
|
|
270
|
+
* dispatches per-document `clientProxy.onDocumentUpdated` for watched URIs and
|
|
271
|
+
* `onModelsBuilt` a single `clientProxy.onDocumentsBuilt` naming the batch's
|
|
272
|
+
* unwatched documents.
|
|
198
273
|
*
|
|
199
274
|
* The data-server requires the full {@link ServerSharedServices}
|
|
200
275
|
* shape — `HydraniumTextDocuments` for client-attributed updates,
|
|
@@ -213,92 +288,31 @@ interface ResolvedDataServerOptions {
|
|
|
213
288
|
*/
|
|
214
289
|
export declare class DataServer<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic, TProject extends Project = Project> implements DataServerProtocol<TTransfer, TDiagnostic, TProject>, DataServerDiagnosticsProtocol, Disposable {
|
|
215
290
|
protected readonly connection: MessageConnection;
|
|
216
|
-
protected readonly services: ServerSharedServices<TProject>;
|
|
291
|
+
protected readonly services: ServerSharedServices<TProject, TDiagnostic>;
|
|
217
292
|
/**
|
|
218
293
|
* Framework defaults, exposed so an adopter can spread them when
|
|
219
294
|
* extending rather than restate a value the framework may change.
|
|
220
295
|
*/
|
|
221
|
-
static readonly DEFAULT_OPTIONS: Required<Pick<DataServerOptions, 'subscriptionPhase'>>;
|
|
296
|
+
static readonly DEFAULT_OPTIONS: Required<Pick<DataServerOptions, 'subscriptionPhase' | 'referenceSettleTimeoutMs'>>;
|
|
222
297
|
protected readonly options: ResolvedDataServerOptions;
|
|
223
|
-
/**
|
|
224
|
-
protected readonly
|
|
298
|
+
/** This connection's {@link DataServerUriWatchRecord} per canonical URI; see there for when a record lives. */
|
|
299
|
+
protected readonly uriWatchRecords: Map<string, DataServerUriWatchRecord>;
|
|
225
300
|
/**
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
*
|
|
234
|
-
*
|
|
301
|
+
* The live client sessions this connection registered, by client id. A
|
|
302
|
+
* document request carrying one of these ids acts as that session; one
|
|
303
|
+
* carrying any other id fails. A session leaves once it ends, so a
|
|
304
|
+
* connection that registers many over its life does not accumulate them.
|
|
305
|
+
*/
|
|
306
|
+
protected readonly clientSessions: Map<string, ClientSession<AstNode, AstDiagnostic, TTransfer, object>>;
|
|
307
|
+
/**
|
|
308
|
+
* Typed client proxy — sends `data-server/on*` notifications back over the same wire.
|
|
309
|
+
* The proxy sends any `on[A-Z]*` name other than `onDidOpenConnection` and
|
|
310
|
+
* `onDidCloseConnection`, for which it returns its own events, so a subclass
|
|
311
|
+
* with notifications of its own narrows only the type:
|
|
312
|
+
* `declare protected readonly clientProxy: TheirClient`.
|
|
235
313
|
*/
|
|
236
|
-
protected readonly openedDocuments: Map<string, Set<string>>;
|
|
237
|
-
/** Typed client proxy — sends `data-server/on*` notifications back over the same wire. */
|
|
238
314
|
protected readonly clientProxy: DataClientProtocol<TTransfer, TDiagnostic, TProject>;
|
|
239
315
|
protected readonly disposables: DisposableCollection;
|
|
240
|
-
/**
|
|
241
|
-
* Snapshot of the most recent `DocumentBuilder.onUpdate` event. Drives
|
|
242
|
-
* `reason` discrimination on outbound `onDocumentUpdated` notifications:
|
|
243
|
-
* a URI in the `changed` list emits `'changed'`, in `deleted` emits
|
|
244
|
-
* `'deleted'`, otherwise `'rebuilt'` (cascade rebuild from a dependent
|
|
245
|
-
* URI's change). The same mechanism `AstDocumentManager.onUpdate` uses on
|
|
246
|
-
* the LSP side, so reason fidelity stays consistent between heads.
|
|
247
|
-
*/
|
|
248
|
-
protected lastBuildUpdate?: {
|
|
249
|
-
changed: readonly URI[];
|
|
250
|
-
deleted: readonly URI[];
|
|
251
|
-
};
|
|
252
|
-
/**
|
|
253
|
-
* Per-URI hash of the last emitted (text + diagnostics) state,
|
|
254
|
-
* used by {@link dispatchPhaseEvent} to suppress duplicate
|
|
255
|
-
* `onDocumentUpdated` notifications for rebuilds that produce no
|
|
256
|
-
* observable change since the last emit.
|
|
257
|
-
*
|
|
258
|
-
* Two scenarios routinely produce such rebuilds:
|
|
259
|
-
* 1. **Refresh-triggered rebuilds.** When a second client attaches to a
|
|
260
|
-
* document already open in another client,
|
|
261
|
-
* `HydraniumTextDocuments.refreshContent` fires `onDidChangeContent`
|
|
262
|
-
* purely to re-trigger the build pipeline — the text and diagnostics
|
|
263
|
-
* are identical to the prior emit.
|
|
264
|
-
* 2. **Cascade rebuilds with no diagnostic delta.** Langium rebuilds a
|
|
265
|
-
* document when a dependency changes; if the rebuild produces the
|
|
266
|
-
* same diagnostics, there is nothing new to communicate to subscribers.
|
|
267
|
-
*
|
|
268
|
-
* Without this filter, both scenarios reach subscribers as wire-side
|
|
269
|
-
* `'changed'` events. A subscriber that interprets `'changed'` as
|
|
270
|
-
* "another client wrote new content" and resets its in-memory root to
|
|
271
|
-
* the server view then misreads the spurious event as a concurrent
|
|
272
|
-
* third-party write and loses the user's edits.
|
|
273
|
-
*
|
|
274
|
-
* Initialised on {@link watchModelDocument} to the current
|
|
275
|
-
* document fingerprint so the FIRST phase event after a fresh
|
|
276
|
-
* subscription is also de-duplicated against the state subscribers
|
|
277
|
-
* obtained via `getModelDocument` — they do not need a redundant phase
|
|
278
|
-
* notification for the state they just fetched.
|
|
279
|
-
*
|
|
280
|
-
* Cleared in {@link unwatchModelDocument} when the last
|
|
281
|
-
* subscriber for a URI leaves so memory does not accumulate.
|
|
282
|
-
*
|
|
283
|
-
* Stored as a cyrb53 hex digest (16 chars per URI) rather than the raw
|
|
284
|
-
* text + diagnostics serialisation so the memory cost is constant in
|
|
285
|
-
* document size. See {@link computeDocumentFingerprint} for the inputs.
|
|
286
|
-
*/
|
|
287
|
-
protected readonly lastEmittedFingerprint: Map<string, string>;
|
|
288
|
-
/**
|
|
289
|
-
* URIs whose LAST client just closed. The update handler rebuilds such a
|
|
290
|
-
* document from its disk content (discarding unsaved in-session edits),
|
|
291
|
-
* but {@link dispatchPhaseEvent} gates on the subscription map — and the
|
|
292
|
-
* last close typically also removed the last watcher, so consumers that
|
|
293
|
-
* only ever fetch via `getModelDocument` would keep showing the
|
|
294
|
-
* discarded state forever. Marked on the last-close transition (see
|
|
295
|
-
* {@link subscribeToTextDocumentCloses}) and consumed by
|
|
296
|
-
* {@link dispatchPhaseEvent}, which broadcasts the following rebuild's
|
|
297
|
-
* phase event even without a subscription — de-duplicated against
|
|
298
|
-
* {@link lastEmittedFingerprint} where an entry survives, so a close
|
|
299
|
-
* whose disk state equals the last emitted state stays silent.
|
|
300
|
-
*/
|
|
301
|
-
protected readonly pendingRevertBroadcasts: Set<string>;
|
|
302
316
|
protected readonly tracer: Tracer;
|
|
303
317
|
/** The in-flight interactive profile capture, held between {@link startProfiling} and {@link stopProfiling}. */
|
|
304
318
|
protected activeProfile?: DataServerProfileCapture;
|
|
@@ -307,88 +321,100 @@ export declare class DataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
307
321
|
/** Per-method RPC latency collector, when the head opted in via {@link DataServerOptions.latency}. */
|
|
308
322
|
protected readonly latency?: LatencyCollector;
|
|
309
323
|
/** Encoder pulled from DI. Adopters rebind `services.model.TransferEncoder` to a typed-overlay subclass. */
|
|
310
|
-
protected readonly encoder: TransferEncoder<
|
|
324
|
+
protected readonly encoder: TransferEncoder<TDiagnostic>;
|
|
311
325
|
/**
|
|
312
326
|
* In-process workspace facade — the lifecycle delegate `get` / `update` / `save` go through.
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* while the wire shape stays `TDiagnostic extends TransferDiagnostic`. The encoder's
|
|
316
|
-
* `astDocumentToTransferDocument` accepts both shapes (wire-shape or LSP-shape) and projects
|
|
317
|
-
* to wire shape on the return — see `TransferEncoder.astDocumentToTransferDocument`.
|
|
327
|
+
* Its documents carry the AST-layer {@link AstDiagnostic}, never the wire `TDiagnostic`:
|
|
328
|
+
* {@link encoder} converts one into the other on the way out.
|
|
318
329
|
*/
|
|
319
|
-
protected readonly modelService: ModelService<AstNode,
|
|
320
|
-
constructor(connection: MessageConnection, services: ServerSharedServices<TProject>, options?: DataServerOptions);
|
|
330
|
+
protected readonly modelService: ModelService<AstNode, AstDiagnostic, TTransfer>;
|
|
331
|
+
constructor(connection: MessageConnection, services: ServerSharedServices<TProject, TDiagnostic>, options?: DataServerOptions);
|
|
321
332
|
/**
|
|
322
333
|
* Release everything the constructor wired up — the bound protocol
|
|
323
|
-
* handlers and every listener — and clear
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
334
|
+
* handlers and every listener — and clear {@link uriWatchRecords}, so a
|
|
335
|
+
* long-lived shared services bundle does not retain per-connection memory
|
|
336
|
+
* after the connection closes. Also ends every session this connection registered, which closes
|
|
337
|
+
* every document it has open: the SHARED store's state rather than this
|
|
338
|
+
* server's, which outlives the connection unless released here.
|
|
339
|
+
*
|
|
340
|
+
* Idempotent: subsequent calls are no-ops. Runs by itself when the
|
|
341
|
+
* connection closes, so adopters who don't hold a reference still get
|
|
342
|
+
* per-connection cleanup; adopters that DO hold a reference may call
|
|
343
|
+
* `dispose()` directly for early teardown. The sessions end with `cause`:
|
|
344
|
+
* `'closed'` releases every document whose last open they close at once,
|
|
345
|
+
* and `'lost'`, the connection's own close, lets each wait out the release
|
|
346
|
+
* grace.
|
|
347
|
+
*/
|
|
348
|
+
dispose(cause?: SessionEndCause): void;
|
|
349
|
+
createSession(args: CreateSessionArgs): Promise<void>;
|
|
350
|
+
/** End a session this connection registered. */
|
|
351
|
+
closeSession(args: CloseSessionArgs): Promise<void>;
|
|
352
|
+
/** End `session`, registered here under `clientId`, with `cause`, and drop its watches on this connection. */
|
|
353
|
+
protected endSession(clientId: string, session: ClientSession<AstNode, AstDiagnostic, TTransfer>, cause?: SessionEndCause): void;
|
|
354
|
+
protected dropWatches(clientId: string): void;
|
|
355
|
+
createModelDocument(args: CreateModelDocumentArgs): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
356
|
+
updateModelDocuments(args: TransferUpdateDocumentsArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>[]>;
|
|
357
|
+
/**
|
|
358
|
+
* The session write a wire write request carries. Only the fields a session
|
|
359
|
+
* takes: a field an adopter adds to a request reaches the session only
|
|
360
|
+
* through an override of this.
|
|
361
|
+
*/
|
|
362
|
+
protected toSessionWrite(request: Omit<TransferUpdateDocumentArgs<TTransfer>, 'clientId'>): ClientSessionWriteArgs<TTransfer>;
|
|
363
|
+
/**
|
|
364
|
+
* The session this connection registered under `clientId`, which every
|
|
365
|
+
* document request acts as. An id that is not one fails with the
|
|
366
|
+
* closed-session code: opening or writing under it would leave an open that
|
|
367
|
+
* no session end ever closes.
|
|
368
|
+
*/
|
|
369
|
+
protected requireSession(clientId: string): ClientSession<AstNode, AstDiagnostic, TTransfer>;
|
|
370
|
+
openModelDocument(args: Pick<OpenModelArgs, 'uri' | 'clientId' | 'options'>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
371
|
+
/**
|
|
372
|
+
* The snapshot a session's open or create answers with. When the read
|
|
373
|
+
* fails, `rollback` undoes the open this call made before the failure is
|
|
374
|
+
* rethrown: the caller sees no open, so nothing on its side would ever close
|
|
375
|
+
* it.
|
|
376
|
+
*/
|
|
377
|
+
protected openedSnapshot(uri: string, rollback?: () => Promise<void>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
337
378
|
closeModelDocument(args: CloseModelArgs): Promise<void>;
|
|
338
|
-
/**
|
|
339
|
-
* Drop the recorded hold for `(uri, clientId)` so {@link dispose} does not
|
|
340
|
-
* close it a second time. Idempotent.
|
|
341
|
-
*/
|
|
342
|
-
protected forgetOpenDocument(uri: string, clientId: string): void;
|
|
343
|
-
/**
|
|
344
|
-
* Close every document still open over this connection, for the clients that
|
|
345
|
-
* opened it here.
|
|
346
|
-
*
|
|
347
|
-
* The document store releases a per-URI hold only from an explicit close, so
|
|
348
|
-
* without this a client that dies mid-session keeps its documents open for the
|
|
349
|
-
* lifetime of the process: `isOpenInAnyClient` stays true, the document stays
|
|
350
|
-
* resident, and the last-close revert never runs. A long-lived multi-client
|
|
351
|
-
* head is the configuration where a dead client is normal rather than
|
|
352
|
-
* exceptional, so the leak accumulates there.
|
|
353
|
-
*
|
|
354
|
-
* Runs from {@link dispose}, which is synchronous, so each close is fired and
|
|
355
|
-
* its failure swallowed — a teardown must not reject, and a URI whose close
|
|
356
|
-
* fails is no worse off than it was before this drain existed.
|
|
357
|
-
*/
|
|
358
|
-
protected closeOpenDocuments(): void;
|
|
359
379
|
getModelDocument(args: GetModelDocumentArgs): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
360
380
|
updateModelDocument(args: TransferUpdateDocumentArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
361
|
-
saveModelDocument(args: TransferSaveDocumentArgs<TTransfer>): Promise<
|
|
381
|
+
saveModelDocument(args: TransferSaveDocumentArgs<TTransfer>): Promise<TransferSavedDocument<TTransfer, TDiagnostic>>;
|
|
382
|
+
persistModelDocument(args: TransferPersistDocumentArgs): Promise<TransferSavedDocument<TTransfer, TDiagnostic>>;
|
|
362
383
|
/**
|
|
363
384
|
* Record a watch for `(uri, clientId)`. Subsequent phase events on `uri`
|
|
364
385
|
* fan out to the wired `clientProxy.onDocumentUpdated`. The
|
|
365
386
|
* bidirectional pattern means the event channel is the client
|
|
366
387
|
* notification surface, not a returned handle — this method only
|
|
367
|
-
* registers the
|
|
388
|
+
* registers the watcher in {@link uriWatchRecords}.
|
|
368
389
|
*
|
|
369
|
-
* Also baselines the
|
|
370
|
-
* {@link
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
* redundant phase notification for that same state.
|
|
390
|
+
* Also baselines the URI's emission fingerprint (see
|
|
391
|
+
* {@link dispatchPhaseEvent}) to the document's current state when the
|
|
392
|
+
* first watcher for the URI registers. This guarantees that any phase event firing immediately after
|
|
393
|
+
* the watch with no observable change is suppressed — watchers obtain
|
|
394
|
+
* initial state via `getModelDocument` (or {@link openModelDocument}) and
|
|
395
|
+
* do not need a redundant phase notification for that same state.
|
|
376
396
|
*/
|
|
377
397
|
watchModelDocument(args: WatchModelDocumentArgs): Promise<void>;
|
|
378
398
|
/**
|
|
379
399
|
* Remove a watch for `(uri, clientId)` previously created by
|
|
380
400
|
* {@link watchModelDocument}. Idempotent — unwatching twice is a no-op.
|
|
381
|
-
* Dispatch for `uri` stops once no watchers remain,
|
|
382
|
-
*
|
|
383
|
-
* re-baselines against the then-current document state rather than a
|
|
384
|
-
* stale snapshot from the previous watch.
|
|
401
|
+
* Dispatch for `uri` stops once no watchers remain, and the emission
|
|
402
|
+
* fingerprint goes with the last watcher (see {@link pruneUriWatchRecord}).
|
|
385
403
|
*/
|
|
386
404
|
unwatchModelDocument(args: WatchModelDocumentArgs): Promise<void>;
|
|
387
405
|
/**
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
406
|
+
* Drop what `uri` no longer needs: the
|
|
407
|
+
* {@link DataServerUriWatchRecord.fingerprint} once no client watches it,
|
|
408
|
+
* and the whole record once it holds no
|
|
409
|
+
* {@link DataServerUriWatchRecord.releaseBroadcastPending} mark either.
|
|
410
|
+
* Every path that removes a watcher or consumes a mark ends here.
|
|
411
|
+
*/
|
|
412
|
+
protected pruneUriWatchRecord(uri: string): void;
|
|
413
|
+
/**
|
|
414
|
+
* Canonicalise a URI string for use as a {@link uriWatchRecords} key, via the
|
|
415
|
+
* shared `DocumentUriPolicy`. Callers may send non-canonical URIs
|
|
416
|
+
* (drive-letter casing, percent-encoding differences, or a symlink path)
|
|
417
|
+
* over the wire; the dispatch side keys by
|
|
392
418
|
* `document.uri.toString()` from `LangiumDocuments`, so writer keys must
|
|
393
419
|
* canonicalise to the same form or events silently fail to deliver.
|
|
394
420
|
* Routing through the seam (rather than a bare `UriUtils.normalize`)
|
|
@@ -398,6 +424,7 @@ export declare class DataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
398
424
|
* LSP head resolves.
|
|
399
425
|
*
|
|
400
426
|
* Adopters can still override for head-specific URI policy by subclassing.
|
|
427
|
+
* The result keys watches only; a document is looked up by its own URI.
|
|
401
428
|
*/
|
|
402
429
|
protected canonicalKey(uri: string): string;
|
|
403
430
|
getProjects(): Promise<readonly TProject[]>;
|
|
@@ -410,8 +437,25 @@ export declare class DataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
410
437
|
* subclass.
|
|
411
438
|
*/
|
|
412
439
|
waitForReady(): Promise<void>;
|
|
440
|
+
/**
|
|
441
|
+
* Settle the build before a reference question is answered from the index.
|
|
442
|
+
*
|
|
443
|
+
* A query issued right after a model update otherwise races the rebuild and
|
|
444
|
+
* reads an index missing the symbols it asks about. The cost is not confined
|
|
445
|
+
* to this call: a scope built inside that window is cached, and the build's
|
|
446
|
+
* remaining documents link against it.
|
|
447
|
+
*
|
|
448
|
+
* Waits the source document specifically, but ONLY when one is loaded at
|
|
449
|
+
* that URI: a synthetic source can address a URI with no document (a
|
|
450
|
+
* directory URI, typically), where a per-URI `waitUntil` throws "No document
|
|
451
|
+
* found". Falls back to a global settle, matching the id-based
|
|
452
|
+
* `ElementSource` path.
|
|
453
|
+
*
|
|
454
|
+
* Bounded by {@link DataServerOptions.referenceSettleTimeoutMs}.
|
|
455
|
+
*/
|
|
456
|
+
protected awaitReferencesLinked(source: ReferenceSource): Promise<void>;
|
|
413
457
|
findReferenceCandidates(ctx: ReferenceContext): Promise<ReferenceCandidate[]>;
|
|
414
|
-
resolveReference(ref: ReferenceRequest): Promise<ReferenceTarget<
|
|
458
|
+
resolveReference<TElement extends TransferElement = TransferElement>(ref: ReferenceRequest): Promise<ReferenceTarget<TElement> | undefined>;
|
|
415
459
|
findNextName(args: FindNextNameArgs): Promise<string>;
|
|
416
460
|
/**
|
|
417
461
|
* Resolve the per-language `references` services for a reference source.
|
|
@@ -422,38 +466,17 @@ export declare class DataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
422
466
|
*/
|
|
423
467
|
protected resolveReferenceServices(source: ReferenceSource): HydraniumLanguageServices['references'];
|
|
424
468
|
/**
|
|
425
|
-
* Pick the language that owns a reference source
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
* single-language adopters never reach the steps below, and never pay
|
|
431
|
-
* for them.
|
|
432
|
-
* 3. An {@link isElementSource} source carries no URI, so in a
|
|
433
|
-
* multi-language workspace it is routed via the document that holds the
|
|
434
|
-
* element (see {@link findElementDocumentUri}).
|
|
435
|
-
* 4. A source carrying an AST type is routed by that type when exactly one
|
|
436
|
-
* registered grammar can produce it (see
|
|
437
|
-
* {@link resolveReferenceLanguageByType}, over the registry's own type
|
|
438
|
-
* index). This is what resolves a create-element flow's synthetic source
|
|
439
|
-
* on a bare directory URI without asking the adopter.
|
|
440
|
-
* 5. Anything still unresolved falls to {@link fallbackReferenceLanguage},
|
|
441
|
-
* which is adopter policy.
|
|
442
|
-
*/
|
|
443
|
-
protected resolveReferenceLanguage(source: ReferenceSource): HydraniumLanguageServices | undefined;
|
|
444
|
-
/**
|
|
445
|
-
* Route a reference source by the AST type it carries — a
|
|
446
|
-
* {@link isSyntheticSource}'s `type` (the transient node being created) or an
|
|
447
|
-
* {@link isElementSource}'s optional narrowing `type`.
|
|
469
|
+
* Pick the language that owns a reference source: the registry's
|
|
470
|
+
* `getLanguageFor` over the source's declared language, URI and AST type,
|
|
471
|
+
* with an {@link isElementSource} routed by the document that holds the
|
|
472
|
+
* element (see {@link findElementDocumentUri}) before its type, and
|
|
473
|
+
* {@link fallbackReferenceLanguage}, adopter policy, last.
|
|
448
474
|
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
* adopter policy, not a coin toss. Note this asks which grammar can *produce*
|
|
453
|
-
* the type, not which mentions it: a grammar that merely cross-references a
|
|
454
|
-
* type can never hold a node of it.
|
|
475
|
+
* An unregistered declared language falls through rather than failing: the
|
|
476
|
+
* id crosses the wire, so a client built against a head with one more
|
|
477
|
+
* grammar would otherwise lose queries the other signals answer.
|
|
455
478
|
*/
|
|
456
|
-
protected
|
|
479
|
+
protected resolveReferenceLanguage(source: ReferenceSource): HydraniumLanguageServices | undefined;
|
|
457
480
|
/**
|
|
458
481
|
* Locate the document that holds the element an {@link ElementSource}
|
|
459
482
|
* addresses, via the index's O(1) name lookup — `name` is the qualified
|
|
@@ -461,15 +484,14 @@ export declare class DataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
461
484
|
* disambiguates names that repeat across types (honouring grammar
|
|
462
485
|
* subtyping through `AstReflection.isSubtype`).
|
|
463
486
|
*
|
|
464
|
-
* Only reached
|
|
465
|
-
*
|
|
466
|
-
* step 2.
|
|
487
|
+
* Only reached in a multi-language workspace, once the declared language
|
|
488
|
+
* and the URI have abstained.
|
|
467
489
|
*
|
|
468
490
|
* Abstains when the name matches elements in more than one DOCUMENT — the
|
|
469
491
|
* index spans every language and is filled in build order, so "the
|
|
470
|
-
* first match" would be file-watch order rather than an answer.
|
|
471
|
-
* then falls through to the type
|
|
472
|
-
*
|
|
492
|
+
* first match" would be file-watch order rather than an answer. Routing
|
|
493
|
+
* then falls through to the element's type, which abstains on ties in the
|
|
494
|
+
* same way, and finally to adopter policy.
|
|
473
495
|
*/
|
|
474
496
|
protected findElementDocumentUri(source: ElementSource): URI | undefined;
|
|
475
497
|
/**
|
|
@@ -485,33 +507,85 @@ export declare class DataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
485
507
|
*/
|
|
486
508
|
protected fallbackReferenceLanguage(_source: ReferenceSource): HydraniumLanguageServices | undefined;
|
|
487
509
|
/**
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
* `
|
|
494
|
-
* adopter supplying a typed-overlay encoder narrows the runtime shape to
|
|
495
|
-
* its wire types. The cast on the return is where that invariant — the
|
|
496
|
-
* adopter's `TTransfer` matches its encoder's overlay — is asserted, at a
|
|
497
|
-
* single boundary point rather than spread across the callers.
|
|
510
|
+
* Whether `error`, from waiting on `uri`'s document, means that `uri` has
|
|
511
|
+
* no document: a URI with neither a file nor text builds nothing, and
|
|
512
|
+
* Langium's wait after the build rejects for want of one, with a
|
|
513
|
+
* `ServerCancelled` response error. Any other failure, such as a read
|
|
514
|
+
* that fails before a document is registered, a cancelled wait or a
|
|
515
|
+
* `ReentrantWriteLockError`, is the caller's to see.
|
|
498
516
|
*/
|
|
499
|
-
protected
|
|
517
|
+
protected isMissingDocument(error: unknown, uri: string): boolean;
|
|
500
518
|
/**
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
|
|
514
|
-
|
|
519
|
+
* Build a {@link TransferDocument} envelope from the current document state,
|
|
520
|
+
* delegating root + diagnostic encoding to {@link encoder} (see
|
|
521
|
+
* `TransferEncoder.toTransferDocument` for the walk). `fingerprint` is the
|
|
522
|
+
* caller's {@link computeDocumentFingerprint} of that same state, which
|
|
523
|
+
* spares hashing it twice.
|
|
524
|
+
*/
|
|
525
|
+
protected envelope(uri: URI, fingerprint?: string): TransferDocument<TTransfer, TDiagnostic>;
|
|
526
|
+
/**
|
|
527
|
+
* The transfer document a request answers with for `astDocument`, its model
|
|
528
|
+
* hashed and the text stamped on it by {@link withServerState}. Every
|
|
529
|
+
* document a request answers with goes through here, so none goes out
|
|
530
|
+
* without them.
|
|
531
|
+
*/
|
|
532
|
+
protected encodeDocument(astDocument: AstDocument<AstNode, AstDiagnostic>): TransferDocument<TTransfer, TDiagnostic>;
|
|
533
|
+
/**
|
|
534
|
+
* `encoded` with `hash` on its model and the text the server holds for it:
|
|
535
|
+
* the store's while it holds the document, the build's otherwise. The text
|
|
536
|
+
* is read when the document is sent rather than kept with the build: a save
|
|
537
|
+
* changes `text.dirty` without a rebuild, and the store's text moves on before
|
|
538
|
+
* the build that follows it.
|
|
539
|
+
*/
|
|
540
|
+
protected withServerState(encoded: EncodedTransferDocument<TransferElement, TDiagnostic>, hash: string): TransferDocument<TTransfer, TDiagnostic>;
|
|
541
|
+
/**
|
|
542
|
+
* The text a build read for a document the store never held, which is
|
|
543
|
+
* clean: the store holds every text a client gave it.
|
|
544
|
+
*/
|
|
545
|
+
protected builtTextState(uri: string): TextState | undefined;
|
|
546
|
+
/**
|
|
547
|
+
* Follow every document at the configured
|
|
548
|
+
* {@link DataServerOptions.subscriptionPhase}, once per connection rather
|
|
549
|
+
* than once per watch, so the cost stays flat in the number of watches.
|
|
550
|
+
*/
|
|
551
|
+
protected subscribeToModelUpdates(): void;
|
|
552
|
+
/**
|
|
553
|
+
* Report the documents that reached {@link DataServerOptions.subscriptionPhase}
|
|
554
|
+
* and that NOBODY on this
|
|
555
|
+
* connection is watching — the ones a client was not told about through
|
|
556
|
+
* {@link dispatchPhaseEvent}, which is gated per URI.
|
|
557
|
+
*
|
|
558
|
+
* **The gap this closes is the one no other source can observe.** A document
|
|
559
|
+
* the client watches, it hears about already. A file changed on disk, the
|
|
560
|
+
* host's own filesystem watcher reports — and on a browser host, where the
|
|
561
|
+
* workspace lives behind this head, an external change cannot happen at all.
|
|
562
|
+
* What is left, and what nothing outside the server can see, is a document
|
|
563
|
+
* rebuilt because something it DEPENDS ON changed: its file never changed, so
|
|
564
|
+
* a filesystem watcher is silent by construction, and it has no subscriber, so
|
|
565
|
+
* the update channel is silent by design. A consumer displaying data derived
|
|
566
|
+
* from that document — a tree label, a decorator — otherwise goes stale with
|
|
567
|
+
* no signal from any source, and repairs itself the moment someone opens the
|
|
568
|
+
* file to investigate, which is what makes it expensive to diagnose later.
|
|
569
|
+
*
|
|
570
|
+
* Payload-free on purpose: URIs only, so a client re-reads what it displays
|
|
571
|
+
* rather than being handed transfer documents it did not ask for. That is the
|
|
572
|
+
* property the watcher gate protects, and it is preserved here by
|
|
573
|
+
* carrying no document rather than by gating the message.
|
|
574
|
+
*
|
|
575
|
+
* Quiet in the common case. Editing a document that an editor has open leaves
|
|
576
|
+
* that URI watched and therefore out of this set, so a build with no
|
|
577
|
+
* dependents produces nothing at all, and workspace initialisation produces
|
|
578
|
+
* nothing because it does not build to this phase. The ceiling is a
|
|
579
|
+
* whole-workspace rebuild at the subscription phase: one message, URIs only.
|
|
580
|
+
*/
|
|
581
|
+
protected dispatchBuiltEvent(built: readonly CanonicalUri[]): void;
|
|
582
|
+
/**
|
|
583
|
+
* Follow every save so a single `onDocumentSaved` wire notification fires
|
|
584
|
+
* for ANY save of a subscribed URI — regardless of whether the save
|
|
585
|
+
* originated from the data-server's RPC `saveModelDocument`, the LSP head's
|
|
586
|
+
* text-editor save, or any other client.
|
|
587
|
+
*
|
|
588
|
+
* Architectural symmetry with {@link subscribeToModelUpdates}: every
|
|
515
589
|
* subscribed client sees every state change to documents they care about,
|
|
516
590
|
* regardless of which client triggered it. Firing `onDocumentSaved` only
|
|
517
591
|
* from the data-server's own RPC path is a bug, not an optimisation: an
|
|
@@ -519,15 +593,71 @@ export declare class DataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
519
593
|
* clients, which never clear their dirty state.
|
|
520
594
|
*/
|
|
521
595
|
protected subscribeToTextDocumentSaves(): void;
|
|
522
|
-
/**
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
596
|
+
/** Relay each change of a document's dirty state; see {@link dispatchDirtyEvent}. */
|
|
597
|
+
protected subscribeToDirtyChanges(): void;
|
|
598
|
+
/**
|
|
599
|
+
* Send a dirty flip to the connection, gated on the URI's watchers as
|
|
600
|
+
* {@link dispatchSaveEvent} is: the answer at any one moment travels on
|
|
601
|
+
* every document sent, so a client that watches nothing reads it there.
|
|
602
|
+
*/
|
|
603
|
+
protected dispatchDirtyEvent(event: ModelDirtyChangedEvent): void;
|
|
604
|
+
/**
|
|
605
|
+
* Mark each document the store releases, so {@link dispatchPhaseEvent}
|
|
606
|
+
* broadcasts the build that follows even without a watcher. By default
|
|
607
|
+
* that build reverts the document to its disk content, discarding unsaved
|
|
608
|
+
* in-session edits, and the last close typically also
|
|
609
|
+
* removed the last watcher: without the broadcast, a consumer that only
|
|
610
|
+
* ever fetches via `getModelDocument` keeps showing the discarded state.
|
|
611
|
+
* The broadcast is de-duplicated against the fingerprint while a watcher
|
|
612
|
+
* holds one, so a close whose disk state equals the last emitted state
|
|
613
|
+
* stays silent; with no watcher there is no fingerprint, and every release
|
|
614
|
+
* build is sent. The first build after the release consumes the mark, and
|
|
615
|
+
* goes out as the release unless it is stamped past the version a client
|
|
616
|
+
* opened the document at again: a client's write or an integrity repair
|
|
617
|
+
* that rides it keeps its author.
|
|
618
|
+
*
|
|
619
|
+
* A release, not the close itself: a document whose last client lost its
|
|
620
|
+
* connection is released only once the release grace runs out, or when
|
|
621
|
+
* another client opens it meanwhile, and not at all when a client lost
|
|
622
|
+
* from it opens it again within its own grace.
|
|
623
|
+
*/
|
|
624
|
+
protected subscribeToModelReleases(): void;
|
|
625
|
+
/**
|
|
626
|
+
* Fan out a deletion for each removed URI, to EVERY client on the connection
|
|
627
|
+
* rather than only to the ones watching that URI.
|
|
628
|
+
*
|
|
629
|
+
* **Deliberately ungated, where {@link dispatchPhaseEvent} and
|
|
630
|
+
* {@link dispatchSaveEvent} are gated.** Those two carry a built document and
|
|
631
|
+
* fire on every build, so the watcher gate is what keeps bandwidth
|
|
632
|
+
* proportional to what a client asked for. A deletion is neither: it is one
|
|
633
|
+
* URI, it is rare, and it reports the workspace's STRUCTURE rather than a
|
|
634
|
+
* document's content. Gating it forces any consumer that displays the
|
|
635
|
+
* workspace — a model tree, a file decorator — to learn about disappearances
|
|
636
|
+
* from a filesystem watcher instead, which a client hosted in a browser has
|
|
637
|
+
* no way to run: its workspace lives behind the head. A client that does not
|
|
638
|
+
* care filters on the URI, which costs it a comparison.
|
|
639
|
+
*
|
|
640
|
+
* The precedent is the release broadcast (see
|
|
641
|
+
* {@link subscribeToModelReleases}), where the same judgement was already made
|
|
642
|
+
* in the other direction: a transition that matters enough is delivered
|
|
643
|
+
* without a subscription.
|
|
644
|
+
*
|
|
645
|
+
* A deletion is announced before the build that follows it, so this goes
|
|
646
|
+
* out ahead of the `'rebuilt'` events for the dependents whose references
|
|
647
|
+
* the deletion just broke.
|
|
648
|
+
*
|
|
649
|
+
* The URI's fingerprint and release mark are dropped: they describe a
|
|
650
|
+
* document that no longer exists. A kept fingerprint is adopted as the
|
|
651
|
+
* baseline and suppresses the first emit after the file returns with its
|
|
652
|
+
* previous content.
|
|
653
|
+
*
|
|
654
|
+
* The watchers SURVIVE: a recreated file resumes delivering to them with no
|
|
655
|
+
* re-subscription, and a client that answers the deletion by closing
|
|
656
|
+
* releases the watch through `closeModelDocument` anyway.
|
|
657
|
+
*/
|
|
658
|
+
protected dispatchDeleteEvent(event: ModelDeletedEvent): void;
|
|
659
|
+
/** Fan out a save event for the document's URI, gated on the URI's watchers. */
|
|
660
|
+
protected dispatchSaveEvent(event: AstDocumentSavedEvent<AstNode>): void;
|
|
531
661
|
/**
|
|
532
662
|
* Fan out a phase event for the document's URI by calling
|
|
533
663
|
* `clientProxy.onDocumentUpdated`. The proxy lowers the call to a
|
|
@@ -537,52 +667,43 @@ export declare class DataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
537
667
|
* out to multiple local subscribers with an `Emitter<T>` — the
|
|
538
668
|
* framework deliberately does NOT promise multi-listener semantics.
|
|
539
669
|
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
670
|
+
* An event for a URI no client watches is NOT sent over the wire, so
|
|
671
|
+
* bandwidth scales with watched URIs rather than with phase events; a
|
|
672
|
+
* pending release mark is the exception (see
|
|
673
|
+
* {@link subscribeToModelReleases}).
|
|
674
|
+
*
|
|
675
|
+
* An event for a rebuild with no observable change since the last emit is
|
|
676
|
+
* suppressed against the URI's fingerprint and the version it was taken at;
|
|
677
|
+
* a new version with the same fingerprint goes out with the same
|
|
678
|
+
* `model.hash`, so a watcher still learns the version. Such rebuilds are routine: a
|
|
679
|
+
* second client attaching to an open document makes
|
|
680
|
+
* `HydraniumTextDocuments.refreshContent` fire `onDidChangeContent` purely
|
|
681
|
+
* to re-trigger the build, and Langium rebuilds a document when a
|
|
682
|
+
* dependency changes even if its diagnostics come out the same. Sent at a
|
|
683
|
+
* version this head has not sent, they reach watchers as `'changed'`, and a
|
|
684
|
+
* watcher that reads `'changed'` as another client's write and resets its
|
|
685
|
+
* root to the server view loses the user's edits. The first {@link watchModelDocument} baselines the
|
|
686
|
+
* fingerprint, so the first event after a watch is de-duplicated against
|
|
687
|
+
* the state the watcher just fetched; it goes with the last watcher, so the
|
|
688
|
+
* next first watch re-baselines rather than adopting a stale digest. A
|
|
689
|
+
* digest keeps its memory constant in document size; see
|
|
690
|
+
* {@link computeDocumentFingerprint} for the inputs.
|
|
691
|
+
*/
|
|
692
|
+
protected dispatchPhaseEvent(event: ModelUpdatedEvent<AstNode>): void;
|
|
693
|
+
/**
|
|
694
|
+
* Fingerprint of the snapshot `root` and its encoding `encoded`, used to
|
|
695
|
+
* de-dup `onDocumentUpdated` emissions and sent as every document's
|
|
696
|
+
* `model.hash`, so it must not depend on the version or on live state. The
|
|
697
|
+
* {@link FingerprintStrategy} option selects what is hashed (default
|
|
698
|
+
* `'transfer-document'` — see the type).
|
|
699
|
+
*
|
|
700
|
+
* {@link TransferEncoder.toTransferDocument} is cached per build, so within
|
|
701
|
+
* one phase event the fingerprint and the subsequently-emitted `envelope`
|
|
702
|
+
* share a single encode walk.
|
|
559
703
|
*
|
|
560
704
|
* Wrapped in {@link Tracer.time} against {@link FINGERPRINT_LOG_AFTER_MS}.
|
|
561
705
|
*/
|
|
562
|
-
protected computeDocumentFingerprint(
|
|
563
|
-
/**
|
|
564
|
-
* Extra inputs folded into {@link computeDocumentFingerprint} alongside the
|
|
565
|
-
* chosen {@link FingerprintStrategy}. Default: none. Override to contribute a
|
|
566
|
-
* signal that lives outside the document's text / root / diagnostics — each
|
|
567
|
-
* entry need only be stable across equivalent emissions and
|
|
568
|
-
* JSON-serialisable.
|
|
569
|
-
*/
|
|
570
|
-
protected additionalFingerprintInputs(_document: LangiumDocument): readonly unknown[];
|
|
571
|
-
/**
|
|
572
|
-
* Discriminate the reason for a phase-event-driven update notification.
|
|
573
|
-
* Uses the most recent `DocumentBuilder.onUpdate` snapshot:
|
|
574
|
-
* - URI in the `deleted` list → `'deleted'`
|
|
575
|
-
* - URI in the `changed` list → `'changed'` (the URI was passed to
|
|
576
|
-
* `documentBuilder.update(changed, deleted)`, which spans `didChange`
|
|
577
|
-
* text-document events and programmatic `update([uri], [])` calls).
|
|
578
|
-
* - Otherwise → `'rebuilt'` (cascade re-derivation: this URI was rebuilt
|
|
579
|
-
* because something it depends on changed; its own text wasn't flagged).
|
|
580
|
-
*
|
|
581
|
-
* `'saved'` is NOT emitted from this code path — saves take the dedicated
|
|
582
|
-
* `DataClientProtocol.onDocumentSaved` channel; adopters that want a
|
|
583
|
-
* unified update stream synthesise `'saved'` in their bridge layer.
|
|
584
|
-
*/
|
|
585
|
-
protected resolveUpdateReason(uri: URI): TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>['reason'];
|
|
706
|
+
protected computeDocumentFingerprint(root: AstNode, encoded: EncodedTransferDocument<TransferElement, TDiagnostic>): string;
|
|
586
707
|
/**
|
|
587
708
|
* Subscribe to the project tier's change channel and re-fan registry
|
|
588
709
|
* diffs into per-project wire notifications. The internal
|
|
@@ -606,16 +727,6 @@ export declare class DataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
606
727
|
* snapshot needed for the `'removed'` wire payload.
|
|
607
728
|
*/
|
|
608
729
|
protected dispatchProjectChangeEvent(event: ProjectChangeEvent<TProject>): void;
|
|
609
|
-
/**
|
|
610
|
-
* Resolve the wire-level `sourceClientId` for `document`'s events — the client
|
|
611
|
-
* that authored its current version, from the version-author history on
|
|
612
|
-
* `HydraniumTextDocuments`. The protocol-level counterpart of the internal
|
|
613
|
-
* `AstDocumentManager.getAuthor`: a framework-internal rebuild has no author,
|
|
614
|
-
* so this surfaces the {@link UNKNOWN_CLIENT_ID} presentation default. Adopters
|
|
615
|
-
* that rebuild through non-text-document channels override to derive a
|
|
616
|
-
* source id of their own.
|
|
617
|
-
*/
|
|
618
|
-
protected resolveSourceClientId(document: LangiumDocument): string;
|
|
619
730
|
dumpServerState(args: DumpServerStateArgs): Promise<string>;
|
|
620
731
|
writeHeapSnapshot(args: WriteServerHeapSnapshotArgs): Promise<string>;
|
|
621
732
|
dumpPodMemory(): Promise<string>;
|
|
@@ -625,5 +736,4 @@ export declare class DataServer<TTransfer extends TransferElement, TDiagnostic e
|
|
|
625
736
|
/** Resolve a partial options object into a fully-defaulted form. */
|
|
626
737
|
protected resolveOptions(partial: DataServerOptions): ResolvedDataServerOptions;
|
|
627
738
|
}
|
|
628
|
-
export {};
|
|
629
739
|
//# sourceMappingURL=data-server.d.ts.map
|