@hydranium/glsp-server 1.0.0-next.28 → 1.0.0-next.280
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 +77 -88
- package/lib/browser/start-glsp-server-in-worker.d.ts +43 -42
- package/lib/browser/start-glsp-server-in-worker.d.ts.map +1 -1
- package/lib/browser/start-glsp-server-in-worker.js +62 -13
- package/lib/browser/start-glsp-server-in-worker.js.map +1 -1
- package/lib/command/diagram-edit-dropped-error.d.ts +31 -0
- package/lib/command/diagram-edit-dropped-error.d.ts.map +1 -0
- package/lib/command/diagram-edit-dropped-error.js +48 -0
- package/lib/command/diagram-edit-dropped-error.js.map +1 -0
- package/lib/command/hydranium-glsp-command-stack.d.ts +33 -0
- package/lib/command/hydranium-glsp-command-stack.d.ts.map +1 -0
- package/lib/command/hydranium-glsp-command-stack.js +63 -0
- package/lib/command/hydranium-glsp-command-stack.js.map +1 -0
- package/lib/command/hydranium-glsp-operation-action-handler.d.ts +64 -0
- package/lib/command/hydranium-glsp-operation-action-handler.d.ts.map +1 -0
- package/lib/command/hydranium-glsp-operation-action-handler.js +142 -0
- package/lib/command/hydranium-glsp-operation-action-handler.js.map +1 -0
- package/lib/command/hydranium-glsp-operation-command.d.ts +249 -0
- package/lib/command/hydranium-glsp-operation-command.d.ts.map +1 -0
- package/lib/command/hydranium-glsp-operation-command.js +486 -0
- package/lib/command/hydranium-glsp-operation-command.js.map +1 -0
- package/lib/command/hydranium-glsp-recording-command.d.ts +26 -87
- package/lib/command/hydranium-glsp-recording-command.d.ts.map +1 -1
- package/lib/command/hydranium-glsp-recording-command.js +40 -117
- package/lib/command/hydranium-glsp-recording-command.js.map +1 -1
- package/lib/command/hydranium-glsp-undo-redo-action-handler.d.ts +23 -0
- package/lib/command/hydranium-glsp-undo-redo-action-handler.d.ts.map +1 -0
- package/lib/command/hydranium-glsp-undo-redo-action-handler.js +41 -0
- package/lib/command/hydranium-glsp-undo-redo-action-handler.js.map +1 -0
- package/lib/command/index.d.ts +5 -0
- package/lib/command/index.d.ts.map +1 -1
- package/lib/command/index.js +5 -0
- package/lib/command/index.js.map +1 -1
- package/lib/computed-bounds/hydranium-glsp-computed-bounds-action-handler.d.ts +1 -1
- package/lib/computed-bounds/hydranium-glsp-computed-bounds-action-handler.d.ts.map +1 -1
- package/lib/computed-bounds/hydranium-glsp-computed-bounds-action-handler.js +2 -2
- package/lib/computed-bounds/hydranium-glsp-computed-bounds-action-handler.js.map +1 -1
- package/lib/dispatcher/server-action-dispatcher.d.ts +25 -24
- package/lib/dispatcher/server-action-dispatcher.d.ts.map +1 -1
- package/lib/dispatcher/server-action-dispatcher.js +38 -26
- package/lib/dispatcher/server-action-dispatcher.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/launcher/abstract-hydranium-glsp-diagram-module.d.ts +35 -59
- package/lib/launcher/abstract-hydranium-glsp-diagram-module.d.ts.map +1 -1
- package/lib/launcher/abstract-hydranium-glsp-diagram-module.js +60 -71
- package/lib/launcher/abstract-hydranium-glsp-diagram-module.js.map +1 -1
- package/lib/launcher/drop-notifications-to-gone-client.d.ts +23 -0
- package/lib/launcher/drop-notifications-to-gone-client.d.ts.map +1 -0
- package/lib/launcher/drop-notifications-to-gone-client.js +43 -0
- package/lib/launcher/drop-notifications-to-gone-client.js.map +1 -0
- package/lib/launcher/glsp-app-module.d.ts +1 -2
- package/lib/launcher/glsp-app-module.d.ts.map +1 -1
- package/lib/launcher/glsp-app-module.js.map +1 -1
- package/lib/launcher/glsp-connection-logger.d.ts +19 -0
- package/lib/launcher/glsp-connection-logger.d.ts.map +1 -0
- package/lib/launcher/glsp-connection-logger.js +24 -0
- package/lib/launcher/glsp-connection-logger.js.map +1 -0
- package/lib/launcher/glsp-server-overrides.d.ts +10 -8
- package/lib/launcher/glsp-server-overrides.d.ts.map +1 -1
- package/lib/launcher/glsp-server-overrides.js +25 -11
- package/lib/launcher/glsp-server-overrides.js.map +1 -1
- package/lib/launcher/hydranium-glsp-server.d.ts +60 -15
- package/lib/launcher/hydranium-glsp-server.d.ts.map +1 -1
- package/lib/launcher/hydranium-glsp-server.js +145 -22
- package/lib/launcher/hydranium-glsp-server.js.map +1 -1
- package/lib/launcher/index.d.ts +2 -0
- package/lib/launcher/index.d.ts.map +1 -1
- package/lib/launcher/index.js +5 -4
- package/lib/launcher/index.js.map +1 -1
- package/lib/logging/glsp-client-logger.d.ts +10 -6
- package/lib/logging/glsp-client-logger.d.ts.map +1 -1
- package/lib/logging/glsp-client-logger.js +14 -7
- package/lib/logging/glsp-client-logger.js.map +1 -1
- package/lib/messages/index.d.ts +11 -6
- package/lib/messages/index.d.ts.map +1 -1
- package/lib/messages/index.js +11 -6
- package/lib/messages/index.js.map +1 -1
- package/lib/node/start-glsp-server.d.ts +30 -8
- package/lib/node/start-glsp-server.d.ts.map +1 -1
- package/lib/node/start-glsp-server.js +49 -10
- package/lib/node/start-glsp-server.js.map +1 -1
- package/lib/state/abstract-hydranium-glsp-state.d.ts +312 -102
- package/lib/state/abstract-hydranium-glsp-state.d.ts.map +1 -1
- package/lib/state/abstract-hydranium-glsp-state.js +505 -139
- package/lib/state/abstract-hydranium-glsp-state.js.map +1 -1
- package/lib/state/diagram-status.d.ts +38 -0
- package/lib/state/diagram-status.d.ts.map +1 -0
- package/lib/state/diagram-status.js +27 -0
- package/lib/state/diagram-status.js.map +1 -0
- package/lib/state/full-text-hydranium-glsp-state.d.ts +15 -8
- package/lib/state/full-text-hydranium-glsp-state.d.ts.map +1 -1
- package/lib/state/full-text-hydranium-glsp-state.js +26 -16
- package/lib/state/full-text-hydranium-glsp-state.js.map +1 -1
- package/lib/state/hydranium-glsp-index.d.ts +40 -29
- package/lib/state/hydranium-glsp-index.d.ts.map +1 -1
- package/lib/state/hydranium-glsp-index.js +82 -45
- package/lib/state/hydranium-glsp-index.js.map +1 -1
- package/lib/state/hydranium-shared-core-services.d.ts +16 -29
- package/lib/state/hydranium-shared-core-services.d.ts.map +1 -1
- package/lib/state/hydranium-shared-core-services.js +15 -28
- package/lib/state/hydranium-shared-core-services.js.map +1 -1
- package/lib/state/index.d.ts +1 -0
- package/lib/state/index.d.ts.map +1 -1
- package/lib/state/index.js +1 -0
- package/lib/state/index.js.map +1 -1
- package/lib/state/model-ready-timeout-error.d.ts.map +1 -1
- package/lib/state/model-ready-timeout-error.js.map +1 -1
- package/lib/state/reconcile-source-model-write.d.ts +10 -27
- package/lib/state/reconcile-source-model-write.d.ts.map +1 -1
- package/lib/state/reconcile-source-model-write.js +39 -32
- package/lib/state/reconcile-source-model-write.js.map +1 -1
- package/lib/state/reconciling-multi-document-glsp-state.d.ts +123 -69
- package/lib/state/reconciling-multi-document-glsp-state.d.ts.map +1 -1
- package/lib/state/reconciling-multi-document-glsp-state.js +239 -100
- package/lib/state/reconciling-multi-document-glsp-state.js.map +1 -1
- package/lib/state/reconciling-transfer-hydranium-glsp-state.d.ts +35 -27
- package/lib/state/reconciling-transfer-hydranium-glsp-state.d.ts.map +1 -1
- package/lib/state/reconciling-transfer-hydranium-glsp-state.js +57 -41
- package/lib/state/reconciling-transfer-hydranium-glsp-state.js.map +1 -1
- package/lib/status/diagram-status-reporter.d.ts +44 -0
- package/lib/status/diagram-status-reporter.d.ts.map +1 -0
- package/lib/status/diagram-status-reporter.js +88 -0
- package/lib/status/diagram-status-reporter.js.map +1 -0
- package/lib/status/hydranium-glsp-request-model-action-handler.d.ts +27 -0
- package/lib/status/hydranium-glsp-request-model-action-handler.d.ts.map +1 -0
- package/lib/status/hydranium-glsp-request-model-action-handler.js +52 -0
- package/lib/status/hydranium-glsp-request-model-action-handler.js.map +1 -0
- package/lib/status/hydranium-glsp-set-edit-mode-action-handler.d.ts +27 -0
- package/lib/status/hydranium-glsp-set-edit-mode-action-handler.d.ts.map +1 -0
- package/lib/status/hydranium-glsp-set-edit-mode-action-handler.js +53 -0
- package/lib/status/hydranium-glsp-set-edit-mode-action-handler.js.map +1 -0
- package/lib/status/index.d.ts +12 -0
- package/lib/status/index.d.ts.map +1 -0
- package/lib/status/index.js +12 -0
- package/lib/status/index.js.map +1 -0
- package/lib/storage/hydranium-glsp-request-save-model-action-handler.d.ts +30 -0
- package/lib/storage/hydranium-glsp-request-save-model-action-handler.d.ts.map +1 -0
- package/lib/storage/hydranium-glsp-request-save-model-action-handler.js +47 -0
- package/lib/storage/hydranium-glsp-request-save-model-action-handler.js.map +1 -0
- package/lib/storage/hydranium-glsp-storage.d.ts +322 -143
- package/lib/storage/hydranium-glsp-storage.d.ts.map +1 -1
- package/lib/storage/hydranium-glsp-storage.js +563 -213
- package/lib/storage/hydranium-glsp-storage.js.map +1 -1
- package/lib/storage/index.d.ts +2 -1
- package/lib/storage/index.d.ts.map +1 -1
- package/lib/storage/index.js +2 -1
- package/lib/storage/index.js.map +1 -1
- package/lib/storage/save-delivery-policy.d.ts +46 -0
- package/lib/storage/save-delivery-policy.d.ts.map +1 -0
- package/lib/storage/{save-conflict-policy.js → save-delivery-policy.js} +7 -8
- package/lib/storage/save-delivery-policy.js.map +1 -0
- package/lib/submission/hydranium-glsp-submission-handler.d.ts +44 -4
- package/lib/submission/hydranium-glsp-submission-handler.d.ts.map +1 -1
- package/lib/submission/hydranium-glsp-submission-handler.js +82 -6
- package/lib/submission/hydranium-glsp-submission-handler.js.map +1 -1
- package/lib/testing/glsp-harness.d.ts +29 -7
- package/lib/testing/glsp-harness.d.ts.map +1 -1
- package/lib/testing/glsp-harness.js +47 -19
- package/lib/testing/glsp-harness.js.map +1 -1
- package/lib/validation/diagnostic-markers.d.ts +3 -3
- package/lib/validation/diagnostic-markers.d.ts.map +1 -1
- package/lib/validation/diagnostic-markers.js +1 -1
- package/lib/validation/diagnostic-markers.js.map +1 -1
- package/lib/validation/hydranium-glsp-model-validator.d.ts +1 -2
- package/lib/validation/hydranium-glsp-model-validator.d.ts.map +1 -1
- package/lib/validation/hydranium-glsp-model-validator.js +1 -1
- package/lib/validation/hydranium-glsp-model-validator.js.map +1 -1
- package/package.json +31 -52
- package/src/browser/start-glsp-server-in-worker.ts +79 -51
- package/src/command/diagram-edit-dropped-error.ts +51 -0
- package/src/command/hydranium-glsp-command-stack.ts +47 -0
- package/src/command/hydranium-glsp-operation-action-handler.ts +141 -0
- package/src/command/hydranium-glsp-operation-command.ts +598 -0
- package/src/command/hydranium-glsp-recording-command.ts +40 -121
- package/src/command/hydranium-glsp-undo-redo-action-handler.ts +29 -0
- package/src/command/index.ts +10 -0
- package/src/computed-bounds/hydranium-glsp-computed-bounds-action-handler.ts +2 -2
- package/src/dispatcher/server-action-dispatcher.ts +39 -31
- package/src/index.ts +1 -0
- package/src/launcher/abstract-hydranium-glsp-diagram-module.ts +79 -91
- package/src/launcher/drop-notifications-to-gone-client.ts +47 -0
- package/src/launcher/glsp-app-module.ts +1 -2
- package/src/launcher/glsp-connection-logger.ts +27 -0
- package/src/launcher/glsp-server-overrides.ts +27 -11
- package/src/launcher/hydranium-glsp-server.ts +153 -23
- package/src/launcher/index.ts +5 -4
- package/src/logging/glsp-client-logger.ts +16 -9
- package/src/messages/index.ts +16 -6
- package/src/node/start-glsp-server.ts +60 -14
- package/src/state/abstract-hydranium-glsp-state.ts +584 -154
- package/src/state/diagram-status.ts +41 -0
- package/src/state/full-text-hydranium-glsp-state.ts +27 -17
- package/src/state/hydranium-glsp-index.ts +85 -41
- package/src/state/hydranium-shared-core-services.ts +16 -29
- package/src/state/index.ts +1 -0
- package/src/state/reconcile-source-model-write.ts +44 -53
- package/src/state/reconciling-multi-document-glsp-state.ts +273 -102
- package/src/state/reconciling-transfer-hydranium-glsp-state.ts +65 -44
- package/src/status/diagram-status-reporter.ts +106 -0
- package/src/status/hydranium-glsp-request-model-action-handler.ts +43 -0
- package/src/status/hydranium-glsp-set-edit-mode-action-handler.ts +38 -0
- package/src/status/index.ts +12 -0
- package/src/storage/hydranium-glsp-request-save-model-action-handler.ts +40 -0
- package/src/storage/hydranium-glsp-storage.ts +639 -223
- package/src/storage/index.ts +2 -1
- package/src/storage/save-delivery-policy.ts +44 -0
- package/src/submission/hydranium-glsp-submission-handler.ts +91 -5
- package/src/testing/glsp-harness.ts +62 -25
- package/src/validation/diagnostic-markers.ts +3 -3
- package/src/validation/hydranium-glsp-model-validator.ts +4 -5
- package/lib/storage/save-conflict-policy.d.ts +0 -56
- package/lib/storage/save-conflict-policy.d.ts.map +0 -1
- package/lib/storage/save-conflict-policy.js.map +0 -1
- package/src/storage/save-conflict-policy.ts +0 -52
|
@@ -16,10 +16,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
16
16
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
17
17
|
};
|
|
18
18
|
var AbstractHydraniumGlspState_1;
|
|
19
|
-
import { DefaultModelState, SOURCE_URI_ARG } from '@eclipse-glsp/server';
|
|
19
|
+
import { DefaultModelState, EditMode, SOURCE_URI_ARG } from '@eclipse-glsp/server';
|
|
20
20
|
import { Emitter } from 'vscode-jsonrpc';
|
|
21
|
-
import { inject, injectable
|
|
22
|
-
import { DocumentState, URI } from '@hydranium/langium';
|
|
21
|
+
import { inject, injectable } from 'inversify';
|
|
22
|
+
import { AstUtils, DocumentState, isAstNode, URI } from '@hydranium/langium';
|
|
23
|
+
import { buildAstNode } from '@hydranium/core';
|
|
24
|
+
import { asModelVersion, TIMED_OUT, UNRECORDED_VERSION, describeError, describeErrorWithStack } from '@hydranium/protocol';
|
|
25
|
+
import { openOperationOf } from '../command/hydranium-glsp-operation-command.js';
|
|
23
26
|
import { HydraniumTypes } from './hydranium-shared-core-services.js';
|
|
24
27
|
import { ModelReadyTimeoutError } from './model-ready-timeout-error.js';
|
|
25
28
|
/**
|
|
@@ -47,7 +50,7 @@ import { ModelReadyTimeoutError } from './model-ready-timeout-error.js';
|
|
|
47
50
|
* override only to change the error shape (richer per-adopter output comes
|
|
48
51
|
* from overriding `wsRelativePath` / `formatBuildStatus`).
|
|
49
52
|
* - logging — see {@link baseTracer}. Adopters wanting a different label
|
|
50
|
-
* override `
|
|
53
|
+
* override `captureSourceRoot` and derive via
|
|
51
54
|
* `this.baseTracer.for('Name').withUri(uri)`.
|
|
52
55
|
*
|
|
53
56
|
* **Lifecycle ordering.** Reading {@link sourceUri} or {@link sourceRoot}
|
|
@@ -56,7 +59,7 @@ import { ModelReadyTimeoutError } from './model-ready-timeout-error.js';
|
|
|
56
59
|
* (typically from the storage `loadSourceModel` flow) before reading them.
|
|
57
60
|
* The {@link logger}/{@link tracer} are the exception: the injected
|
|
58
61
|
* {@link baseTracer} is always available, so the getters fall back to it
|
|
59
|
-
* before {@link
|
|
62
|
+
* before {@link captureSourceRoot} derives the URI-tagged {@link _tracer} —
|
|
60
63
|
* logging is never `undefined`.
|
|
61
64
|
*/
|
|
62
65
|
let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends DefaultModelState {
|
|
@@ -72,18 +75,71 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
72
75
|
* `updateSourceModel` implementations.
|
|
73
76
|
*/
|
|
74
77
|
conflictResolver;
|
|
78
|
+
/**
|
|
79
|
+
* Writes of one diagram edit, the first included, that may conflict before
|
|
80
|
+
* the edit is dropped with a warning; each further write reconciles again.
|
|
81
|
+
*/
|
|
82
|
+
maxSourceModelWrites = 3;
|
|
75
83
|
/**
|
|
76
84
|
* Per-class tracer, caller-tagged with this state's runtime subclass name by
|
|
77
|
-
* the `HydraniumTypes.Tracer` binding. {@link
|
|
85
|
+
* the `HydraniumTypes.Tracer` binding. {@link captureSourceRoot} derives the
|
|
78
86
|
* URI-tagged {@link _tracer} from it; the {@link tracer}/{@link logger}
|
|
79
87
|
* getters fall back to it before then, so logging is never `undefined`.
|
|
80
88
|
*/
|
|
81
89
|
baseTracer;
|
|
90
|
+
/**
|
|
91
|
+
* The client session this diagram works as, registered under `clientId` by
|
|
92
|
+
* the source-model storage's load and ended with the GLSP client session,
|
|
93
|
+
* or by a resume that takes it over. `undefined` before the load, for
|
|
94
|
+
* GLSP's placeholder client, and when another participant held the id, in
|
|
95
|
+
* which case the diagram does not load.
|
|
96
|
+
*
|
|
97
|
+
* Every write of the diagram goes through this session, which writes only a
|
|
98
|
+
* document it has open and opens nothing. A one-shot write to a document
|
|
99
|
+
* outside the write set goes through
|
|
100
|
+
* {@link ClientSession.withOpen}, and a document the diagram brings into
|
|
101
|
+
* existence through {@link ClientSession.create}.
|
|
102
|
+
*/
|
|
103
|
+
modelSession;
|
|
104
|
+
/**
|
|
105
|
+
* {@link modelSession}, or a throw without one: the diagram never loaded or
|
|
106
|
+
* has ended. Looking `clientId` up through `ModelService.getSession` instead
|
|
107
|
+
* would write as whichever participant holds that id.
|
|
108
|
+
*/
|
|
109
|
+
requireModelSession() {
|
|
110
|
+
if (!this.modelSession) {
|
|
111
|
+
throw new Error(`No client session is registered for ${this.clientId}; the diagram cannot write`);
|
|
112
|
+
}
|
|
113
|
+
return this.modelSession;
|
|
114
|
+
}
|
|
82
115
|
_sourceUri;
|
|
116
|
+
/**
|
|
117
|
+
* The language {@link _sourceUri} routed to at the last capture, or
|
|
118
|
+
* `undefined` when it routes nowhere. Captured rather than looked up on
|
|
119
|
+
* each {@link diagramLanguage} read, which a GModel factory may make once
|
|
120
|
+
* per element, because the lookup parses the URI and walks the registry.
|
|
121
|
+
*/
|
|
122
|
+
_sourceLanguage;
|
|
123
|
+
/**
|
|
124
|
+
* The root the last capture took, which every reader of the document
|
|
125
|
+
* shares. A projection that must see an operation's edits reads
|
|
126
|
+
* {@link sourceRoot}, which is a copy of it during an operation.
|
|
127
|
+
*/
|
|
83
128
|
_sourceRoot;
|
|
129
|
+
/** Settles when the last {@link runExclusive} call queued so far has. */
|
|
130
|
+
exclusiveTail = Promise.resolve();
|
|
84
131
|
_tracer;
|
|
85
|
-
|
|
86
|
-
/**
|
|
132
|
+
_baseVersion = asModelVersion(0);
|
|
133
|
+
/**
|
|
134
|
+
* The built root each secondary's version was read from, keyed by
|
|
135
|
+
* canonical URI, and during an operation the root of any other document it
|
|
136
|
+
* first reached. An operation copies a secondary from here, so the copy,
|
|
137
|
+
* the base a conflict reconciles from and the version its write is gated
|
|
138
|
+
* on describe one revision; the registry's current root can be a later
|
|
139
|
+
* build's.
|
|
140
|
+
*/
|
|
141
|
+
capturedRoots = new Map();
|
|
142
|
+
/** Model versions of the secondary write set, keyed by URI. See {@link trackSecondaryDocument}. */
|
|
87
143
|
_secondaryVersions = new Map();
|
|
88
144
|
/** Backing emitter for {@link onSecondaryUrisChanged}; fired only on a membership change. */
|
|
89
145
|
secondaryUrisChangedEmitter = new Emitter();
|
|
@@ -92,29 +148,54 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
92
148
|
/** Maximum wait inside {@link readyWithTimeout} before raising {@link ModelReadyTimeoutError}. */
|
|
93
149
|
readyTimeoutMs = AbstractHydraniumGlspState_1.DEFAULT_READY_TIMEOUT_MS;
|
|
94
150
|
/**
|
|
95
|
-
* Capture a freshly built source root alongside its URI
|
|
96
|
-
*
|
|
97
|
-
*
|
|
151
|
+
* Capture a freshly built source root alongside its URI through
|
|
152
|
+
* {@link captureSourceRoot}, and index the AST so downstream GModel
|
|
153
|
+
* projection can resolve elements back to nodes.
|
|
98
154
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
155
|
+
* Capturing the document already captured keeps what the last GModel build
|
|
156
|
+
* registered in the index, which only the next build makes again, and drops
|
|
157
|
+
* an id added through `indexSemanticElement` whose node a rebuild replaced.
|
|
158
|
+
*
|
|
159
|
+
* Throws during an operation: a capture there swaps the root out from under
|
|
160
|
+
* the nodes a handler resolved, and the operation captures when it ends.
|
|
102
161
|
*/
|
|
103
162
|
setSourceRoot(uri, root) {
|
|
163
|
+
if (openOperationOf(this)) {
|
|
164
|
+
throw new Error(`setSourceRoot(${uri}) during an operation: the operation captures the source root when it ends`);
|
|
165
|
+
}
|
|
166
|
+
const recapture = uri === this._sourceUri;
|
|
167
|
+
this.captureSourceRoot(uri, root);
|
|
168
|
+
if (recapture) {
|
|
169
|
+
this.index.reindexSemanticElements(root, uri);
|
|
170
|
+
this.index.remapSemanticAliases(node => (this.isCurrentBuiltNode(node) ? node : undefined));
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
this.index.indexSourceRoot(root, uri);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Take `root` as the source root and read everything derived from it: the
|
|
178
|
+
* base version, every tracked secondary version, the URI mirrored into the
|
|
179
|
+
* inherited properties map under {@link SOURCE_URI_ARG}, and the
|
|
180
|
+
* URI-labelled logger. Everything but the index, which
|
|
181
|
+
* {@link setSourceRoot} sets. Override to derive more from a capture.
|
|
182
|
+
*/
|
|
183
|
+
captureSourceRoot(uri, root) {
|
|
104
184
|
this._sourceUri = uri;
|
|
185
|
+
this._sourceLanguage = this.sharedServices.ServiceRegistry.getServicesFor(uri);
|
|
105
186
|
this._sourceRoot = root;
|
|
106
|
-
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
//
|
|
111
|
-
//
|
|
187
|
+
// The root's own version: the registry's current root can be a later
|
|
188
|
+
// build's, and a write based on its version passes the gate over edits
|
|
189
|
+
// `root` never saw.
|
|
190
|
+
this._baseVersion = this.sharedServices.workspace.ModelLedger.versionOf(root);
|
|
191
|
+
// Re-read the secondary write set: the write that brought us here
|
|
192
|
+
// advanced their versions too, and a stale base version would gate the
|
|
193
|
+
// NEXT command against a superseded number — reporting a conflict that is
|
|
194
|
+
// really this state's own last write.
|
|
112
195
|
this.refreshSecondaryVersions();
|
|
113
196
|
this.set(SOURCE_URI_ARG, uri);
|
|
114
197
|
this._tracer = this.baseTracer.withUri(uri);
|
|
115
|
-
this.tracer.debug(`Captured source root at doc.version=v${this.
|
|
116
|
-
this.checkDeclaredLanguage(uri);
|
|
117
|
-
this.index.indexSourceRoot(root, uri);
|
|
198
|
+
this.tracer.debug(`Captured source root at doc.version=v${this._baseVersion}`);
|
|
118
199
|
}
|
|
119
200
|
/**
|
|
120
201
|
* Typed override of {@link DefaultModelState.sourceUri}. Narrows the
|
|
@@ -124,32 +205,202 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
124
205
|
get sourceUri() {
|
|
125
206
|
return this._sourceUri;
|
|
126
207
|
}
|
|
208
|
+
/** The root operation handlers edit: during an operation a copy of the built root, outside one the built root. */
|
|
127
209
|
get sourceRoot() {
|
|
128
|
-
return this._sourceRoot;
|
|
210
|
+
return openOperationOf(this) && this._sourceRoot !== undefined ? this.workingRootOf(this._sourceUri) : this._sourceRoot;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Run `run` once every earlier call has settled, thrown or not: the
|
|
214
|
+
* boundary that orders operations, undo and redo, and the storage's capture
|
|
215
|
+
* and render. Code running inside it never calls this again, since the
|
|
216
|
+
* call would wait for the section it runs in.
|
|
217
|
+
*/
|
|
218
|
+
runExclusive(run) {
|
|
219
|
+
const result = this.exclusiveTail.then(() => run());
|
|
220
|
+
this.exclusiveTail = result.catch(() => undefined);
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* The root of `uri` that operation handlers edit: during an operation a
|
|
225
|
+
* copy made on the first request and returned for the rest of it, outside
|
|
226
|
+
* one the root itself. The root is the built root of `uri`, or `orElse()`
|
|
227
|
+
* when `uri` has no document; `undefined` when neither gives one.
|
|
228
|
+
*
|
|
229
|
+
* A handler that edits another document than the source reaches its root
|
|
230
|
+
* through this, or the edit lands on the root every reader shares. An id
|
|
231
|
+
* added through `indexSemanticElement` for a node of that root names the
|
|
232
|
+
* node's copy from then on.
|
|
233
|
+
*/
|
|
234
|
+
workingRootOf(uri, orElse) {
|
|
235
|
+
const key = this.workingKey(uri);
|
|
236
|
+
const primary = this._sourceUri !== undefined && key === this.workingKey(this._sourceUri);
|
|
237
|
+
const operation = openOperationOf(this);
|
|
238
|
+
if (!operation) {
|
|
239
|
+
return primary ? this._sourceRoot : (this.sharedServices.model.ModelService.getDocument(uri)?.parseResult.value ?? orElse?.());
|
|
240
|
+
}
|
|
241
|
+
let built = primary ? this._sourceRoot : this.capturedRoots.get(key);
|
|
242
|
+
if (built === undefined) {
|
|
243
|
+
// First reached during the operation: frozen now, for the rest of it.
|
|
244
|
+
built = this.readBuiltRoot(uri);
|
|
245
|
+
if (built !== undefined) {
|
|
246
|
+
this.capturedRoots.set(key, built);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
built ??= orElse?.();
|
|
250
|
+
return built === undefined ? undefined : operation.workingRootOf(key, built);
|
|
251
|
+
}
|
|
252
|
+
/** The copy of `uri` the open operation made, without making one. */
|
|
253
|
+
existingWorkingRootOf(uri) {
|
|
254
|
+
return openOperationOf(this)?.existingWorkingRootOf(this.workingKey(uri));
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* The key of `uri` among an operation's copies: its canonical form, so two
|
|
258
|
+
* spellings of one document share one copy.
|
|
259
|
+
*/
|
|
260
|
+
workingKey(uri) {
|
|
261
|
+
return this.sharedServices.workspace.DocumentUriPolicy.canonicalUri(uri);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* The built node `node` was copied from during an operation; `node` itself
|
|
265
|
+
* for a built node, for a node the operation created, and outside one.
|
|
266
|
+
*
|
|
267
|
+
* A copy has no `$document`, so a lookup that reads its document, scope or
|
|
268
|
+
* project throws or answers for no document. Handlers pass the built node
|
|
269
|
+
* there and keep editing the copy. A candidate query takes
|
|
270
|
+
* {@link referenceInfoOf} instead, since a created node has no built node.
|
|
271
|
+
*/
|
|
272
|
+
builtNodeOf(node) {
|
|
273
|
+
return openOperationOf(this)?.builtNodeOf(node) ?? node;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* A reference to `target` whose `ref` is `target` itself, a copy node
|
|
277
|
+
* included, so an identity comparison later in the operation finds it.
|
|
278
|
+
* `undefined` when no reference can be formed. Outside an operation the
|
|
279
|
+
* nodes are built ones and this is the `ReferenceBuilder`'s answer as is.
|
|
280
|
+
*
|
|
281
|
+
* With `tier: 'own'` the `$refText` is the target's own name as
|
|
282
|
+
* `toOwnReference` gives it, read off `target` itself, so a name the
|
|
283
|
+
* operation edited is the one written; the builder is the target's
|
|
284
|
+
* language's, which a copy node, having no `$document`, would not otherwise
|
|
285
|
+
* reach. `source` plays no part in that tier.
|
|
286
|
+
*
|
|
287
|
+
* By default it is `getReferenceName` from `source`'s context, with the
|
|
288
|
+
* builder of `source`'s language, since `$refText` encoding follows the
|
|
289
|
+
* grammar writing it. That call reads both nodes' projects, to pick the
|
|
290
|
+
* qualification and to refuse a reference across projects the target's is
|
|
291
|
+
* not visible to, and a copy node has none; so it is asked about the built
|
|
292
|
+
* target, which names a target as built, before any rename in the
|
|
293
|
+
* operation, and about {@link builtContextOf} the source. A target the
|
|
294
|
+
* operation created has no built node, and is asked about without a
|
|
295
|
+
* project.
|
|
296
|
+
*/
|
|
297
|
+
referenceTo(target, source, options = {}) {
|
|
298
|
+
const refText = options.tier === 'own'
|
|
299
|
+
? this.languageServicesFor(target)?.references.ReferenceBuilder.toOwnReference(target)?.$refText
|
|
300
|
+
: this.languageServicesFor(source ?? target)?.references.ReferenceBuilder.getReferenceName(this.builtNodeOf(target), source === undefined ? undefined : this.builtContextOf(source));
|
|
301
|
+
return refText === undefined ? undefined : { ref: target, $refText: refText };
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* A candidate query for `property` of `node`, to pass to
|
|
305
|
+
* `candidateProviderFor(node)?.find`. It is asked from the built node, and
|
|
306
|
+
* for a node the operation created from a stand-in of its type under the
|
|
307
|
+
* built containers it sits in, one per created level: a scope reads local
|
|
308
|
+
* names off every container up the chain, so anchoring higher drops them.
|
|
309
|
+
* A protocol context cannot express this: an element source resolves only
|
|
310
|
+
* through a `resolveElementByName` override, and through the index only
|
|
311
|
+
* for the nodes it exports. `undefined` for a node in no document and no
|
|
312
|
+
* copy, such as one not attached yet.
|
|
313
|
+
*/
|
|
314
|
+
referenceInfoOf(node, property) {
|
|
315
|
+
let container = this.builtContextOf(node);
|
|
316
|
+
if (!AstUtils.findRootNode(container).$document) {
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
const created = [];
|
|
320
|
+
for (let level = node; level && this.builtNodeOf(level) !== container; level = level.$container) {
|
|
321
|
+
created.unshift(level);
|
|
322
|
+
}
|
|
323
|
+
for (const level of created) {
|
|
324
|
+
container = buildAstNode(this.sharedServices.AstReflection, level.$type, {
|
|
325
|
+
$container: container,
|
|
326
|
+
$containerProperty: level.$containerProperty,
|
|
327
|
+
$containerIndex: level.$containerIndex
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
return { reference: { $refText: '', ref: undefined }, container, property };
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* The built node of `node`, or of its nearest container that has one: a
|
|
334
|
+
* node the operation created has no built node, but its container's
|
|
335
|
+
* document and project are its own.
|
|
336
|
+
*/
|
|
337
|
+
builtContextOf(node) {
|
|
338
|
+
const operation = openOperationOf(this);
|
|
339
|
+
for (let current = node; current; current = current.$container) {
|
|
340
|
+
const built = this.builtNodeOf(current);
|
|
341
|
+
if (built !== current || operation?.workingUriOf(current) === undefined) {
|
|
342
|
+
return built;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return node;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Take `root`, which a write of this state's own produced, as the source
|
|
349
|
+
* root; during an operation the operation takes it and captures it when it
|
|
350
|
+
* ends.
|
|
351
|
+
*/
|
|
352
|
+
captureWrittenRoot(root) {
|
|
353
|
+
const operation = openOperationOf(this);
|
|
354
|
+
if (operation) {
|
|
355
|
+
operation.recordWrittenRoot(root);
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
this.setSourceRoot(this._sourceUri, root);
|
|
359
|
+
}
|
|
129
360
|
}
|
|
130
361
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
362
|
+
* Resync after a write whose reconcile dropped the edit: during an
|
|
363
|
+
* operation the operation undoes its side effects, pushes nothing, and
|
|
364
|
+
* captures the document's current root when it ends.
|
|
365
|
+
*/
|
|
366
|
+
writeDropped() {
|
|
367
|
+
const operation = openOperationOf(this);
|
|
368
|
+
if (operation) {
|
|
369
|
+
operation.recordDropped(this.sharedServices.model.ModelService.getDocument(this._sourceUri)?.parseResult.value);
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
this.refreshSourceRoot();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Whether `node` belongs to the root its document is built to now, or to no
|
|
377
|
+
* document; a root a rebuild replaced holds only stale nodes.
|
|
378
|
+
*/
|
|
379
|
+
isCurrentBuiltNode(node) {
|
|
380
|
+
const root = AstUtils.findRootNode(node);
|
|
381
|
+
const document = root.$document;
|
|
382
|
+
return (document === undefined || this.sharedServices.model.ModelService.getDocument(document.uri.toString())?.parseResult.value === root);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* The language services of the diagram document: the language
|
|
386
|
+
* {@link sourceUri} routed to at the last {@link setSourceRoot}.
|
|
133
387
|
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* {@link languageServicesFor}. Making that choice explicit at the call site
|
|
138
|
-
* is the point; a neutral-looking `languageServices` invites the diagram's
|
|
139
|
-
* grammar to be applied to a foreign node, which is the defect this whole
|
|
140
|
-
* seam exists to prevent.
|
|
388
|
+
* `undefined` until a document is loaded, as GLSP builds a session's
|
|
389
|
+
* handlers at `InitializeClientSession`, before `RequestModelAction`
|
|
390
|
+
* supplies the URI: read it when called, not at construction.
|
|
141
391
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* `@optional()` so a harness that binds no diagram module still resolves;
|
|
146
|
-
* `undefined` then means no diagram module declared a grammar.
|
|
392
|
+
* Reach for it only when the thing you are asking about lives in the
|
|
393
|
+
* diagram document itself. Anything reached through a reference is decided
|
|
394
|
+
* by its own document: use {@link languageServicesFor}.
|
|
147
395
|
*/
|
|
148
|
-
diagramLanguage
|
|
396
|
+
get diagramLanguage() {
|
|
397
|
+
return this._sourceLanguage;
|
|
398
|
+
}
|
|
149
399
|
/**
|
|
150
400
|
* The language services owning `target` — an AST node (routed by its
|
|
151
|
-
* document), a URI, or a URI string — falling back to
|
|
152
|
-
*
|
|
401
|
+
* document), a URI, or a URI string — falling back, for a node, to the
|
|
402
|
+
* language the index read from the diagram's root, and otherwise to
|
|
403
|
+
* {@link diagramLanguage}, when `target` routes nowhere.
|
|
153
404
|
*
|
|
154
405
|
* Use this wherever the thing being named, keyed or completed may live in
|
|
155
406
|
* another document than the diagram. Two registered languages are free to
|
|
@@ -159,8 +410,14 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
159
410
|
* diagnostic. The fallback covers the genuinely unroutable case, a synthetic
|
|
160
411
|
* node not yet attached to a document, where the diagram's own language is
|
|
161
412
|
* the only defensible answer.
|
|
413
|
+
*
|
|
414
|
+
* A node routes through {@link HydraniumGlspIndex.languageServicesFor}, so
|
|
415
|
+
* an override of the index's routing applies here too.
|
|
162
416
|
*/
|
|
163
417
|
languageServicesFor(target) {
|
|
418
|
+
if (isAstNode(target)) {
|
|
419
|
+
return this.index.languageServicesFor(target) ?? this.diagramLanguage;
|
|
420
|
+
}
|
|
164
421
|
return this.sharedServices.ServiceRegistry.getServicesFor(target) ?? this.diagramLanguage;
|
|
165
422
|
}
|
|
166
423
|
/**
|
|
@@ -186,64 +443,46 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
186
443
|
candidateProviderFor(target) {
|
|
187
444
|
return this.languageServicesFor(target)?.references.CandidateProvider;
|
|
188
445
|
}
|
|
189
|
-
/**
|
|
190
|
-
* Warn when the loaded document does not route to the grammar this diagram
|
|
191
|
-
* module declared.
|
|
192
|
-
*
|
|
193
|
-
* The declared language is the one fact the module states that the grammar
|
|
194
|
-
* itself does not, so it is the one that can drift — a diagram type pointed
|
|
195
|
-
* at the wrong `LanguageMetaData`, or a file extension reassigned. Both
|
|
196
|
-
* would otherwise surface much later as references resolving against the
|
|
197
|
-
* wrong scope. Only a warning, not a throw: the document is loaded and
|
|
198
|
-
* usable either way, and a hard failure here would take out a diagram over
|
|
199
|
-
* a mismatch that may be intentional in an adopter serving one diagram type
|
|
200
|
-
* over several grammars.
|
|
201
|
-
*/
|
|
202
|
-
checkDeclaredLanguage(uri) {
|
|
203
|
-
const declared = this.diagramLanguage?.LanguageMetaData.languageId;
|
|
204
|
-
if (declared === undefined) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
const actual = this.sharedServices.ServiceRegistry.getServicesFor(uri)?.LanguageMetaData.languageId;
|
|
208
|
-
if (actual !== undefined && actual !== declared) {
|
|
209
|
-
this.tracer.warn(`Diagram module declares language '${declared}' but this document routes to '${actual}'`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
446
|
/** The observability handle as a plain {@link Logger} (a {@link Tracer} is-a Logger). */
|
|
213
447
|
get logger() {
|
|
214
448
|
return this.tracer;
|
|
215
449
|
}
|
|
216
|
-
/** URI-tagged once
|
|
450
|
+
/** URI-tagged once a source root is captured; the class-tagged injected {@link baseTracer} before that. */
|
|
217
451
|
get tracer() {
|
|
218
452
|
return this._tracer ?? this.baseTracer;
|
|
219
453
|
}
|
|
220
454
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* at that point in time — frozen until the next `setSourceRoot`, then
|
|
224
|
-
* re-read from `LangiumDocuments`.
|
|
455
|
+
* Model version of the root the last {@link captureSourceRoot} took,
|
|
456
|
+
* frozen until the next one.
|
|
225
457
|
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* conflict gate against the captured based-on version. See
|
|
458
|
+
* The base an operation's write is gated on, taken when the operation
|
|
459
|
+
* opens; nothing captures during an operation, so it is the version of the
|
|
460
|
+
* root the operation's copies were made from. See
|
|
230
461
|
* `@hydranium/protocol#ConflictError` for the detection contract.
|
|
231
462
|
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
|
|
236
|
-
|
|
463
|
+
* **This, not a number read at write time, is what a write must be gated
|
|
464
|
+
* on.** A version read when the write is issued is the store's current one,
|
|
465
|
+
* so it matches by construction and the gate can never fire.
|
|
466
|
+
*/
|
|
467
|
+
get baseVersion() {
|
|
468
|
+
return this._baseVersion;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* {@link baseVersion} as a plain number: the store's version of the text the
|
|
472
|
+
* root was parsed from.
|
|
473
|
+
*
|
|
474
|
+
* `UNRECORDED_VERSION` when the document was not built when the snapshot
|
|
475
|
+
* was taken, which no write matches.
|
|
237
476
|
*/
|
|
238
477
|
get version() {
|
|
239
|
-
return this.
|
|
478
|
+
return this._baseVersion;
|
|
240
479
|
}
|
|
241
480
|
// ============================================================
|
|
242
481
|
// Secondary documents — the write set beyond the primary
|
|
243
482
|
// ============================================================
|
|
244
483
|
/**
|
|
245
|
-
* Register `uri` as a document this state also writes,
|
|
246
|
-
* text-document version.
|
|
484
|
+
* Register `uri` as a document this state also writes, snapshotting its
|
|
485
|
+
* current text-document version.
|
|
247
486
|
*
|
|
248
487
|
* A diagram whose layout lives in its own file, or whose canvas creates
|
|
249
488
|
* elements in a referenced semantic document, writes more than the document
|
|
@@ -256,7 +495,7 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
256
495
|
* identified once the operation names the node. What the framework supplies
|
|
257
496
|
* is the part an adopter cannot reconstruct after the fact — the version each
|
|
258
497
|
* document was at BEFORE the command mutated anything (see
|
|
259
|
-
* {@link
|
|
498
|
+
* {@link baseVersionOf}). Idempotent; registering the primary is ignored,
|
|
260
499
|
* since {@link version} already tracks it. Registering a URI not already in
|
|
261
500
|
* the set fires {@link onSecondaryUrisChanged}.
|
|
262
501
|
*/
|
|
@@ -265,7 +504,10 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
265
504
|
return;
|
|
266
505
|
}
|
|
267
506
|
const added = !this._secondaryVersions.has(uri);
|
|
268
|
-
|
|
507
|
+
const key = this.workingKey(uri);
|
|
508
|
+
// During an operation, the root the operation copied or first reached, not a later build's.
|
|
509
|
+
const root = (openOperationOf(this) ? this.capturedRoots.get(key) : undefined) ?? this.readBuiltRoot(uri);
|
|
510
|
+
this.recordSecondary(uri, root);
|
|
269
511
|
if (added) {
|
|
270
512
|
this.secondaryUrisChangedEmitter.fire();
|
|
271
513
|
}
|
|
@@ -283,14 +525,15 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
283
525
|
}
|
|
284
526
|
/**
|
|
285
527
|
* Fires whenever the secondary write set gains or loses a URI — never when a
|
|
286
|
-
* tracked document's
|
|
287
|
-
* every {@link
|
|
528
|
+
* tracked document's model version is merely refreshed, which happens on
|
|
529
|
+
* every {@link captureSourceRoot} and changes nothing a subscriber cares about.
|
|
288
530
|
*
|
|
289
531
|
* **This exists so no caller has to know when the set can change.** The set is
|
|
290
532
|
* usually discovered rather than known, and the discovery point is an
|
|
291
|
-
* operation handler naming a node — not a
|
|
292
|
-
* re-derived the set after each
|
|
293
|
-
* it silently: the document would simply never be
|
|
533
|
+
* operation handler naming a node — not a read of the source root. A
|
|
534
|
+
* subscriber that instead re-derived the set after each such read would miss
|
|
535
|
+
* exactly that case, and miss it silently: the document would simply never be
|
|
536
|
+
* watched, with nothing logged.
|
|
294
537
|
* Announcing the change here moves the obligation to the one place that can
|
|
295
538
|
* always discharge it.
|
|
296
539
|
*
|
|
@@ -306,37 +549,104 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
306
549
|
get secondaryUris() {
|
|
307
550
|
return [...this._secondaryVersions.keys()];
|
|
308
551
|
}
|
|
552
|
+
/** Active statuses, least recently set first. See {@link setStatus}. */
|
|
553
|
+
statuses = new Map();
|
|
554
|
+
/** Backing emitter for {@link onStatusChanged}. */
|
|
555
|
+
statusChangedEmitter = new Emitter();
|
|
556
|
+
/**
|
|
557
|
+
* Set `status`'s entry, or withdraw it with `undefined`, and recompute
|
|
558
|
+
* {@link currentStatus} and {@link editMode} from every active entry.
|
|
559
|
+
*
|
|
560
|
+
* `editMode` is derived here and nowhere else: a writer that assigns it
|
|
561
|
+
* directly is overwritten by the next status change, and its write is not
|
|
562
|
+
* announced on {@link onStatusChanged}.
|
|
563
|
+
*/
|
|
564
|
+
setStatus(status, entry) {
|
|
565
|
+
const previousEntry = this.statuses.get(status);
|
|
566
|
+
if (previousEntry === undefined && entry === undefined) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
const previousStatus = this.currentStatus;
|
|
570
|
+
const previousEditMode = this.editMode;
|
|
571
|
+
// Re-inserted so iteration order is recency, which breaks a severity tie.
|
|
572
|
+
this.statuses.delete(status);
|
|
573
|
+
if (entry !== undefined) {
|
|
574
|
+
this.statuses.set(status, entry);
|
|
575
|
+
}
|
|
576
|
+
this.editMode = [...this.statuses.values()].some(active => active.readonly) ? EditMode.READONLY : EditMode.EDITABLE;
|
|
577
|
+
this.logger.debug(`Status ${status}: ${describeStatusEntry(previousEntry)} → ${describeStatusEntry(entry)}`);
|
|
578
|
+
if (this.currentStatus !== previousStatus || this.editMode !== previousEditMode) {
|
|
579
|
+
this.statusChangedEmitter.fire();
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
/** The active entry whose message the client shows: highest severity, then most recently set. */
|
|
583
|
+
get currentStatus() {
|
|
584
|
+
let winner;
|
|
585
|
+
for (const entry of this.statuses.values()) {
|
|
586
|
+
if (entry.message !== undefined && (!winner || severityRank(entry) >= severityRank(winner))) {
|
|
587
|
+
winner = entry;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return winner;
|
|
591
|
+
}
|
|
592
|
+
/** The active statuses that block editing; empty while the diagram is editable. */
|
|
593
|
+
get readonlyStatuses() {
|
|
594
|
+
return [...this.statuses].filter(([, entry]) => entry.readonly).map(([status]) => status);
|
|
595
|
+
}
|
|
596
|
+
/** The status that supplies {@link currentStatus}, for a log line naming it. */
|
|
597
|
+
get currentStatusSource() {
|
|
598
|
+
const current = this.currentStatus;
|
|
599
|
+
return [...this.statuses].find(([, entry]) => entry === current)?.[0];
|
|
600
|
+
}
|
|
601
|
+
/** Fires when {@link currentStatus} or {@link editMode} changes. */
|
|
602
|
+
get onStatusChanged() {
|
|
603
|
+
return this.statusChangedEmitter.event;
|
|
604
|
+
}
|
|
309
605
|
/**
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
* {@link
|
|
606
|
+
* The base version of a write of `uri`: {@link baseVersion} for the primary,
|
|
607
|
+
* the version taken at {@link trackSecondaryDocument} (refreshed by
|
|
608
|
+
* {@link captureSourceRoot}) for a secondary, `undefined` for anything untracked.
|
|
313
609
|
*
|
|
314
|
-
* `undefined` rather than
|
|
610
|
+
* `undefined` rather than v0 for an untracked URI deliberately: `0` is a real
|
|
315
611
|
* version meaning "present but never edited", so collapsing the two would let
|
|
316
|
-
* a caller gate a write against a document
|
|
612
|
+
* a caller gate a write against a document this state never read.
|
|
317
613
|
*/
|
|
318
|
-
|
|
614
|
+
baseVersionOf(uri) {
|
|
319
615
|
if (uri === this._sourceUri) {
|
|
320
|
-
return this.
|
|
616
|
+
return this._baseVersion;
|
|
321
617
|
}
|
|
322
618
|
return this._secondaryVersions.get(uri);
|
|
323
619
|
}
|
|
620
|
+
/** Re-take every registered secondary's built root and the model version of that root. */
|
|
621
|
+
refreshSecondaryVersions() {
|
|
622
|
+
this.capturedRoots.clear();
|
|
623
|
+
for (const uri of [...this._secondaryVersions.keys()]) {
|
|
624
|
+
this.recordSecondary(uri, this.readBuiltRoot(uri));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
324
627
|
/**
|
|
325
|
-
*
|
|
326
|
-
* canonicalizing gateway
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
628
|
+
* The built root of `uri`, looked up through the model service's
|
|
629
|
+
* canonicalizing gateway so a symlinked URI does not strand without one;
|
|
630
|
+
* `undefined` for a URI with no parsed document, whose version is then
|
|
631
|
+
* `UNRECORDED_VERSION`, which no write matches. The store counts a file it
|
|
632
|
+
* has not built at `0`, and so does the placeholder the builder registers
|
|
633
|
+
* before its parse, and a write based on `0` overwrites text this state
|
|
634
|
+
* never read.
|
|
331
635
|
*/
|
|
332
|
-
|
|
333
|
-
|
|
636
|
+
readBuiltRoot(uri) {
|
|
637
|
+
const root = this.sharedServices.model.ModelService.getDocument(uri)?.parseResult.value;
|
|
638
|
+
return root && !this.sharedServices.workspace.ModelLedger.isPlaceholder(root) ? root : undefined;
|
|
334
639
|
}
|
|
335
|
-
/**
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
this.
|
|
640
|
+
/** Take `root` as the secondary `uri` was read at, and its version, `UNRECORDED_VERSION` without one. */
|
|
641
|
+
recordSecondary(uri, root) {
|
|
642
|
+
if (root !== undefined) {
|
|
643
|
+
this.capturedRoots.set(this.workingKey(uri), root);
|
|
339
644
|
}
|
|
645
|
+
this._secondaryVersions.set(uri, root ? this.sharedServices.workspace.ModelLedger.versionOf(root) : UNRECORDED_VERSION);
|
|
646
|
+
}
|
|
647
|
+
/** The root the secondary `uri` was read at; see {@link capturedRoots}. */
|
|
648
|
+
capturedRootOf(uri) {
|
|
649
|
+
return this.capturedRoots.get(this.workingKey(uri));
|
|
340
650
|
}
|
|
341
651
|
/**
|
|
342
652
|
* Re-capture the source root from the current Langium document,
|
|
@@ -346,7 +656,8 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
346
656
|
* handlers) must see the root the freshly built document carries.
|
|
347
657
|
*/
|
|
348
658
|
refreshSourceRoot() {
|
|
349
|
-
|
|
659
|
+
// The operation captures when it ends.
|
|
660
|
+
if (!this._sourceUri || openOperationOf(this)) {
|
|
350
661
|
return;
|
|
351
662
|
}
|
|
352
663
|
const document = this.sharedServices.model.ModelService.getDocument(this._sourceUri);
|
|
@@ -359,48 +670,81 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
359
670
|
this.setSourceRoot(this._sourceUri, root);
|
|
360
671
|
}
|
|
361
672
|
}
|
|
673
|
+
/**
|
|
674
|
+
* The root that `uri`'s text parses to (the text store's, or the built
|
|
675
|
+
* document's when the store holds none) and the store's version of that
|
|
676
|
+
* text, read once the document has validated; `undefined` when it cannot be
|
|
677
|
+
* read. The version is read in the tick the text is, so a write based on it
|
|
678
|
+
* conflicts with any edit made after.
|
|
679
|
+
*
|
|
680
|
+
* **Parsed afresh, never the built root.** The built root can lag the
|
|
681
|
+
* store, and a root behind the text it is versioned with makes the replay
|
|
682
|
+
* drop the edits it lacks. The root is parsed, not linked: an encoder hook
|
|
683
|
+
* reading a reference's `ref` sees `undefined` on it.
|
|
684
|
+
*/
|
|
685
|
+
async readCurrentRoot(uri) {
|
|
686
|
+
const modelService = this.sharedServices.model.ModelService;
|
|
687
|
+
// Unreadable here is the conflict the caller then raises, which is logged where it ends; the reason is diagnosis.
|
|
688
|
+
const validated = await modelService.validated(uri).catch((error) => {
|
|
689
|
+
this.logger.debug(`The current text of ${uri} cannot be read: ${describeError(error)}`);
|
|
690
|
+
return undefined;
|
|
691
|
+
});
|
|
692
|
+
if (!validated) {
|
|
693
|
+
return undefined;
|
|
694
|
+
}
|
|
695
|
+
const store = this.sharedServices.workspace.TextDocuments;
|
|
696
|
+
const text = store.get(uri)?.getText() ?? modelService.getDocument(uri)?.textDocument.getText();
|
|
697
|
+
if (text === undefined) {
|
|
698
|
+
return undefined;
|
|
699
|
+
}
|
|
700
|
+
const version = asModelVersion(store.version(uri));
|
|
701
|
+
return { root: this.sharedServices.workspace.LangiumDocumentFactory.fromString(text, URI.parse(uri)).parseResult.value, version };
|
|
702
|
+
}
|
|
362
703
|
/**
|
|
363
704
|
* Wait until the captured document reaches `state`, then run
|
|
364
705
|
* {@link onReadyRefreshed} so consumers see a fresh AST. Wraps the
|
|
365
706
|
* wait in {@link Tracer.time} for observability.
|
|
707
|
+
*
|
|
708
|
+
* A source not in the document registry is built first, through
|
|
709
|
+
* `ModelService.rebuild`. For a source with neither a file nor text, that
|
|
710
|
+
* build leaves no document, and this rejects rather than timing out.
|
|
366
711
|
*/
|
|
367
712
|
async ready(state) {
|
|
368
713
|
await this.tracer.time(`Wait for state '${DocumentState[state]}'`, () => this.readyWithTimeout(state), 'debug');
|
|
369
714
|
await this.onReadyRefreshed();
|
|
370
715
|
}
|
|
371
716
|
/**
|
|
372
|
-
* Race `ModelService.
|
|
373
|
-
* {@link readyTimeoutMs}. If the timeout fires but the
|
|
374
|
-
* already reached `state
|
|
375
|
-
*
|
|
376
|
-
* {@link ModelReadyTimeoutError} via {@link buildReadyTimeoutError}.
|
|
717
|
+
* Race `ModelService.ensureDocumentState`, which builds a root behind its
|
|
718
|
+
* text, against {@link readyTimeoutMs}. If the timeout fires but the
|
|
719
|
+
* document has already reached `state`, log a warning naming the cause, a
|
|
720
|
+
* root behind its text or a missed phase event, and resolve; otherwise
|
|
721
|
+
* raise {@link ModelReadyTimeoutError} via {@link buildReadyTimeoutError}.
|
|
377
722
|
*/
|
|
378
723
|
async readyWithTimeout(state) {
|
|
379
724
|
const uri = this._sourceUri;
|
|
380
725
|
const stopwatch = this.sharedServices.Clock.stopwatch();
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const elapsed = Math.round(stopwatch.elapsedMs);
|
|
385
|
-
// Via the canonicalizing gateway (see `readDocumentVersion`), so a
|
|
386
|
-
// symlinked `_sourceUri` is not reported as a hard timeout.
|
|
387
|
-
const doc = this.sharedServices.model.ModelService.getDocument(uri);
|
|
388
|
-
if (doc && doc.state >= state) {
|
|
389
|
-
this.logger.warn(`Missed '${DocumentState[state]}' notification after ${elapsed}ms; document is already at state ` +
|
|
390
|
-
`'${DocumentState[doc.state]}'. Likely a Langium build-phase event race.`);
|
|
391
|
-
resolve();
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
reject(this.buildReadyTimeoutError(state, elapsed));
|
|
395
|
-
}
|
|
396
|
-
}, this.readyTimeoutMs);
|
|
397
|
-
});
|
|
398
|
-
try {
|
|
399
|
-
await Promise.race([this.sharedServices.model.ModelService.waitForDocumentState(uri, state), timeout]);
|
|
726
|
+
const reached = this.sharedServices.model.ModelService.ensureDocumentState(uri, state);
|
|
727
|
+
if ((await this.sharedServices.Clock.raceTimer(reached, this.readyTimeoutMs)) !== TIMED_OUT) {
|
|
728
|
+
return;
|
|
400
729
|
}
|
|
401
|
-
|
|
402
|
-
|
|
730
|
+
// The race has settled, so a later failure of the wait, such as a given-up sync build, reaches no one else.
|
|
731
|
+
void reached.catch((error) => this.logger.error(`The wait for '${DocumentState[state]}' failed after it timed out: ${describeErrorWithStack(error)}`));
|
|
732
|
+
const elapsed = Math.round(stopwatch.elapsedMs);
|
|
733
|
+
// Through the model service's canonicalizing gateway, so a symlinked
|
|
734
|
+
// `_sourceUri` is not reported as a hard timeout.
|
|
735
|
+
const doc = this.sharedServices.model.ModelService.getDocument(uri);
|
|
736
|
+
if (!doc || doc.state < state) {
|
|
737
|
+
throw this.buildReadyTimeoutError(state, elapsed);
|
|
738
|
+
}
|
|
739
|
+
const built = this.sharedServices.workspace.ModelLedger.versionOf(doc.parseResult.value);
|
|
740
|
+
const text = this.sharedServices.workspace.TextDocuments.version(uri);
|
|
741
|
+
if (built !== UNRECORDED_VERSION && built < text) {
|
|
742
|
+
this.logger.warn(`No build caught the root up after ${elapsed}ms: the document is at state '${DocumentState[doc.state]}', ` +
|
|
743
|
+
`but its root was parsed from v${built} and the text is at v${text}.`);
|
|
744
|
+
return;
|
|
403
745
|
}
|
|
746
|
+
this.logger.warn(`Missed '${DocumentState[state]}' notification after ${elapsed}ms; document is already at state ` +
|
|
747
|
+
`'${DocumentState[doc.state]}'. Likely a Langium build-phase event race.`);
|
|
404
748
|
}
|
|
405
749
|
/**
|
|
406
750
|
* Hook for post-{@link ready} work. Default refreshes the captured
|
|
@@ -426,6 +770,20 @@ let AbstractHydraniumGlspState = class AbstractHydraniumGlspState extends Defaul
|
|
|
426
770
|
const status = workspace.DocumentBuilder.formatBuildStatus(URI.parse(this._sourceUri));
|
|
427
771
|
return new ModelReadyTimeoutError(shortPath, DocumentState[state], elapsed, status);
|
|
428
772
|
}
|
|
773
|
+
/**
|
|
774
|
+
* `transition` as the documents would hold both ends after a write. A
|
|
775
|
+
* serializer may normalize what it writes, provided normalizing again
|
|
776
|
+
* changes nothing; an end left as recorded makes an undo or redo conflict
|
|
777
|
+
* with the write it follows. Default: unchanged.
|
|
778
|
+
*/
|
|
779
|
+
async normalizeTransition(transition) {
|
|
780
|
+
return transition;
|
|
781
|
+
}
|
|
782
|
+
/** The root `model` parses back to once serialized for `uri`, as a write would leave it; nothing is written. */
|
|
783
|
+
async roundTrip(uri, model) {
|
|
784
|
+
const text = await this.sharedServices.model.ModelService.modelToText(uri, model);
|
|
785
|
+
return this.sharedServices.workspace.LangiumDocumentFactory.fromString(text, URI.parse(uri)).parseResult.value;
|
|
786
|
+
}
|
|
429
787
|
};
|
|
430
788
|
__decorate([
|
|
431
789
|
inject(HydraniumTypes.SharedCoreServices),
|
|
@@ -439,13 +797,21 @@ __decorate([
|
|
|
439
797
|
inject(HydraniumTypes.Tracer),
|
|
440
798
|
__metadata("design:type", Object)
|
|
441
799
|
], AbstractHydraniumGlspState.prototype, "baseTracer", void 0);
|
|
442
|
-
__decorate([
|
|
443
|
-
inject(HydraniumTypes.DiagramLanguage),
|
|
444
|
-
optional(),
|
|
445
|
-
__metadata("design:type", Object)
|
|
446
|
-
], AbstractHydraniumGlspState.prototype, "diagramLanguage", void 0);
|
|
447
800
|
AbstractHydraniumGlspState = AbstractHydraniumGlspState_1 = __decorate([
|
|
448
801
|
injectable()
|
|
449
802
|
], AbstractHydraniumGlspState);
|
|
450
803
|
export { AbstractHydraniumGlspState };
|
|
804
|
+
const SEVERITY_RANK = { INFO: 0, WARNING: 1, ERROR: 2, FATAL: 3 };
|
|
805
|
+
/** A message without a severity ranks as `INFO`. */
|
|
806
|
+
function severityRank(entry) {
|
|
807
|
+
return SEVERITY_RANK[entry.severity ?? 'INFO'];
|
|
808
|
+
}
|
|
809
|
+
function describeStatusEntry(entry) {
|
|
810
|
+
if (entry === undefined) {
|
|
811
|
+
return 'inactive';
|
|
812
|
+
}
|
|
813
|
+
const flags = [entry.message === undefined ? undefined : (entry.severity ?? 'INFO'), entry.readonly ? 'readonly' : undefined];
|
|
814
|
+
const message = entry.message === undefined ? '' : ` "${entry.message}"`;
|
|
815
|
+
return `${flags.filter(flag => flag !== undefined).join(' ') || 'active'}${message}`;
|
|
816
|
+
}
|
|
451
817
|
//# sourceMappingURL=abstract-hydranium-glsp-state.js.map
|