@hydranium/glsp-client-theia 1.0.0-next.23 → 1.0.0-next.232
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 +59 -24
- package/lib/browser/action-dispatcher.d.ts +1 -1
- package/lib/browser/action-dispatcher.d.ts.map +1 -1
- package/lib/browser/action-dispatcher.js +1 -1
- package/lib/browser/action-dispatcher.js.map +1 -1
- package/lib/browser/client-contribution.d.ts +83 -25
- package/lib/browser/client-contribution.d.ts.map +1 -1
- package/lib/browser/client-contribution.js +225 -53
- package/lib/browser/client-contribution.js.map +1 -1
- package/lib/browser/diagram-loader.d.ts +16 -7
- package/lib/browser/diagram-loader.d.ts.map +1 -1
- package/lib/browser/diagram-loader.js +18 -10
- package/lib/browser/diagram-loader.js.map +1 -1
- package/lib/browser/diagram-only-marker-manager.d.ts.map +1 -1
- package/lib/browser/diagram-only-marker-manager.js.map +1 -1
- package/lib/browser/diagram-widget.d.ts +42 -24
- package/lib/browser/diagram-widget.d.ts.map +1 -1
- package/lib/browser/diagram-widget.js +74 -24
- package/lib/browser/diagram-widget.js.map +1 -1
- package/lib/browser/glsp-client-theia-module.d.ts +1 -1
- package/lib/browser/glsp-client-theia-module.d.ts.map +1 -1
- package/lib/browser/glsp-client-theia-module.js +3 -1
- package/lib/browser/glsp-client-theia-module.js.map +1 -1
- package/lib/browser/glsp-client.d.ts +17 -0
- package/lib/browser/glsp-client.d.ts.map +1 -0
- package/lib/browser/glsp-client.js +23 -0
- package/lib/browser/glsp-client.js.map +1 -0
- package/lib/browser/glsp-diagram-manager.d.ts +61 -0
- package/lib/browser/glsp-diagram-manager.d.ts.map +1 -1
- package/lib/browser/glsp-diagram-manager.js +126 -0
- package/lib/browser/glsp-diagram-manager.js.map +1 -1
- package/lib/browser/glsp-message-service.d.ts +8 -0
- package/lib/browser/glsp-message-service.d.ts.map +1 -1
- package/lib/browser/glsp-message-service.js +8 -0
- package/lib/browser/glsp-message-service.js.map +1 -1
- package/lib/browser/glsp-saveable.d.ts +66 -0
- package/lib/browser/glsp-saveable.d.ts.map +1 -0
- package/lib/browser/glsp-saveable.js +109 -0
- package/lib/browser/glsp-saveable.js.map +1 -0
- package/lib/browser/glsp-theia-frontend-module.d.ts.map +1 -1
- package/lib/browser/glsp-theia-frontend-module.js +4 -1
- package/lib/browser/glsp-theia-frontend-module.js.map +1 -1
- package/lib/browser/hidden-bounds-updater.d.ts +3 -5
- package/lib/browser/hidden-bounds-updater.d.ts.map +1 -1
- package/lib/browser/hidden-bounds-updater.js +8 -4
- package/lib/browser/hidden-bounds-updater.js.map +1 -1
- package/lib/browser/hydranium-glsp-diagram-configuration.d.ts.map +1 -1
- package/lib/browser/hydranium-glsp-diagram-configuration.js.map +1 -1
- package/lib/browser/index.d.ts +5 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +4 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/status-overlay.d.ts +23 -0
- package/lib/browser/status-overlay.d.ts.map +1 -0
- package/lib/browser/status-overlay.js +52 -0
- package/lib/browser/status-overlay.js.map +1 -0
- package/lib/browser/window-session.d.ts +57 -0
- package/lib/browser/window-session.d.ts.map +1 -0
- package/lib/browser/window-session.js +102 -0
- package/lib/browser/window-session.js.map +1 -0
- package/lib/node/connection-container-module.js.map +1 -1
- package/lib/node/glsp-server-connection-handler.d.ts +12 -11
- package/lib/node/glsp-server-connection-handler.d.ts.map +1 -1
- package/lib/node/glsp-server-connection-handler.js +12 -15
- package/lib/node/glsp-server-connection-handler.js.map +1 -1
- package/lib/testing/bind-recorder.js.map +1 -1
- package/package.json +34 -41
- package/src/browser/action-dispatcher.ts +1 -1
- package/src/browser/client-contribution.ts +250 -54
- package/src/browser/diagram-loader.ts +19 -12
- package/src/browser/diagram-widget.ts +79 -27
- package/src/browser/glsp-client-theia-module.ts +4 -2
- package/src/browser/glsp-client.ts +20 -0
- package/src/browser/glsp-diagram-manager.ts +140 -2
- package/src/browser/glsp-message-service.ts +8 -0
- package/src/browser/glsp-saveable.ts +110 -0
- package/src/browser/glsp-theia-frontend-module.ts +4 -1
- package/src/browser/hidden-bounds-updater.ts +6 -7
- package/src/browser/index.ts +9 -0
- package/src/browser/status-overlay.ts +43 -0
- package/src/browser/window-session.ts +114 -0
- package/src/node/glsp-server-connection-handler.ts +13 -15
- package/style/diagram-loading.css +2 -5
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import { DiagramLoader, type DiagramLoadingOptions, StatusAction } from '@eclipse-glsp/client';
|
|
11
|
-
import { ChannelLogger } from '@hydranium/client-theia/
|
|
11
|
+
import { ChannelLogger } from '@hydranium/client-theia/browser';
|
|
12
12
|
import { Deferred } from '@hydranium/protocol';
|
|
13
|
+
import { nls } from '@theia/core';
|
|
13
14
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -31,8 +32,7 @@ export interface DiagramLoadFailure {
|
|
|
31
32
|
readonly error: unknown;
|
|
32
33
|
/**
|
|
33
34
|
* Whether the `severity: 'ERROR'` {@link StatusAction} reached the action
|
|
34
|
-
* dispatcher
|
|
35
|
-
* failure.
|
|
35
|
+
* dispatcher. It says nothing about whether a status overlay shows it.
|
|
36
36
|
*
|
|
37
37
|
* `false` means the report itself failed, which happens when the action
|
|
38
38
|
* dispatcher is the thing that could not initialize. A consumer that covers
|
|
@@ -101,10 +101,7 @@ export class HydraniumDiagramLoader extends DiagramLoader {
|
|
|
101
101
|
await super.load(options);
|
|
102
102
|
this.settle({ status: 'loaded' });
|
|
103
103
|
} catch (err) {
|
|
104
|
-
// Report first, settle second, and carry whether the report landed
|
|
105
|
-
// consumer that uncovers the canvas on settle then finds the error
|
|
106
|
-
// already on the status overlay — or learns that it has to render the
|
|
107
|
-
// failure itself because nothing else can.
|
|
104
|
+
// Report first, settle second, and carry whether the report landed.
|
|
108
105
|
const surfaced = await this.reportLoadFailure(err);
|
|
109
106
|
this.settle({ status: 'failed', error: err, surfaced });
|
|
110
107
|
}
|
|
@@ -156,13 +153,23 @@ export class HydraniumDiagramLoader extends DiagramLoader {
|
|
|
156
153
|
|
|
157
154
|
/**
|
|
158
155
|
* The sentence a failed load is reported with, on every surface that reports
|
|
159
|
-
* it
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
156
|
+
* it. Public because the canvas overlay is one of those surfaces and lives in
|
|
157
|
+
* another class, where a second copy of the sentence would drift.
|
|
158
|
+
*
|
|
159
|
+
* **The seam and the catalogue key answer different questions, so it carries
|
|
160
|
+
* both.** Overriding this method changes the WORDING for every user of one
|
|
161
|
+
* adopter's product; the key is what gives a reader the sentence in their own
|
|
162
|
+
* language, and no override can supply that without an adopter writing a
|
|
163
|
+
* subclass per locale — which is the thing a catalogue exists to avoid. Two
|
|
164
|
+
* of the three surfaces this reaches are user-visible, so the audience
|
|
165
|
+
* triage answers it: a host-bound string a user sees takes an inline key.
|
|
166
|
+
*
|
|
167
|
+
* The Output-channel line is therefore localized too, which is deliberate
|
|
168
|
+
* rather than overlooked — the alternative is a second English copy of one
|
|
169
|
+
* sentence, and the reason for a single source here has not changed.
|
|
163
170
|
*/
|
|
164
171
|
loadFailureLabel(err: unknown): string {
|
|
165
|
-
return
|
|
172
|
+
return nls.localize('hydranium/glsp-client-theia/diagram-load-failed', 'Diagram failed to load: {0}', this.formatError(err));
|
|
166
173
|
}
|
|
167
174
|
|
|
168
175
|
/** Render a thrown value as a message. Shared so the channel line, the status
|
|
@@ -7,13 +7,17 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import { DiagramLoader } from '@eclipse-glsp/client';
|
|
11
|
-
import {
|
|
10
|
+
import { type Args, DiagramLoader, EditorContextService, GLSPActionDispatcher, SetViewportAction } from '@eclipse-glsp/client';
|
|
11
|
+
import { RESUME_TOKEN_ARG } from '@hydranium/protocol';
|
|
12
|
+
import { GLSPDiagramWidget, type GLSPDiagramWidgetOptions } from '@eclipse-glsp/theia-integration';
|
|
12
13
|
// Type-only: the `@theia/core/lib/browser` barrel touches DOM globals at module
|
|
13
14
|
// load, which the node-environment unit tests cannot provide.
|
|
14
15
|
import { type Message } from '@theia/core/lib/browser';
|
|
15
|
-
import {
|
|
16
|
+
import { Emitter, type Event, nls } from '@theia/core';
|
|
17
|
+
import { type Container, inject, injectable } from '@theia/core/shared/inversify';
|
|
16
18
|
import { type DiagramLoadOutcome, HydraniumDiagramLoader } from './diagram-loader';
|
|
19
|
+
import { HydraniumGlspSaveable } from './glsp-saveable';
|
|
20
|
+
import { WindowSessionService } from './window-session';
|
|
17
21
|
// Shipped by this package rather than left to adopters: an overlay whose
|
|
18
22
|
// stylesheet was forgotten is an unstyled div in normal flow, which is a silent
|
|
19
23
|
// failure. Adopters override individual rules from their own stylesheet.
|
|
@@ -35,31 +39,55 @@ export const DIAGRAM_LOADING_FAILED_CLASS = `${DIAGRAM_LOADING_CLASS}-failed`;
|
|
|
35
39
|
* model to read as a broken editor rather than a slow one.
|
|
36
40
|
*
|
|
37
41
|
* **How the pending state is sourced.** From {@link HydraniumDiagramLoader}, not
|
|
38
|
-
* from `actionDispatcher.onceModelInitialized()
|
|
39
|
-
* as well as on success,
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* the widget node, while GLSP's `StatusOverlay` — where the loader reports the
|
|
43
|
-
* failure — mounts *inside* the diagram's base div. Keyed on model
|
|
44
|
-
* initialization, a failed load would leave a spinner turning on top of the
|
|
45
|
-
* error message explaining it. Keyed on the loader, exactly one component decides
|
|
46
|
-
* whether the canvas is pending and the two mechanisms compose instead of
|
|
47
|
-
* competing.
|
|
42
|
+
* from `actionDispatcher.onceModelInitialized()`: the loader settles on failure
|
|
43
|
+
* as well as on success, even when its own error report throws, while
|
|
44
|
+
* `onceModelInitialized()` never settles on a failed load and would leave the
|
|
45
|
+
* spinner turning for good.
|
|
48
46
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* `StatusAction` — the action dispatcher was what failed — so the status overlay
|
|
52
|
-
* shows nothing. Uncovering the canvas would then leave a blank diagram whose only
|
|
53
|
-
* explanation is a line in the Output channel. In that case, and only that case,
|
|
54
|
-
* the overlay stays up and swaps the spinner for the error text.
|
|
47
|
+
* A failed load keeps the overlay up with the error and a Retry, which asks for
|
|
48
|
+
* a fresh widget through {@link onDidRequestReopen}.
|
|
55
49
|
*
|
|
56
50
|
* Bound unconditionally by `AbstractHydraniumGlspTheiaFrontendModule`. To opt out,
|
|
57
51
|
* override {@link showLoadingOverlay} to a no-op; to change what is rendered,
|
|
58
52
|
* override {@link createLoadingOverlay} or {@link loadingLabel}.
|
|
53
|
+
*
|
|
54
|
+
* Its saveable is a {@link HydraniumGlspSaveable}, which keeps a pending save
|
|
55
|
+
* dirty, so Theia's exit check still counts it; see {@link createSaveable}.
|
|
59
56
|
*/
|
|
60
57
|
@injectable()
|
|
61
58
|
export class HydraniumGlspDiagramWidget extends GLSPDiagramWidget {
|
|
59
|
+
@inject(WindowSessionService) protected readonly windowSessions!: WindowSessionService;
|
|
62
60
|
protected loadingOverlay?: HTMLElement;
|
|
61
|
+
protected readonly reopenRequestEmitter = new Emitter<void>();
|
|
62
|
+
|
|
63
|
+
/** Fires when this diagram asks to be replaced by a fresh widget, as its
|
|
64
|
+
* Retry does; `AbstractHydraniumGlspDiagramManager` reopens it. A load is
|
|
65
|
+
* not repeated in place, since GLSP's model source registers its handlers
|
|
66
|
+
* once per load. */
|
|
67
|
+
readonly onDidRequestReopen: Event<void> = this.reopenRequestEmitter.event;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Replaces the saveable GLSP's `configure` builds inline, with no factory
|
|
71
|
+
* seam. The widget factory calls `configure` before the widget reaches the
|
|
72
|
+
* shell, so Theia only ever tracks this one.
|
|
73
|
+
*/
|
|
74
|
+
override configure(options: GLSPDiagramWidgetOptions, diContainer: Container): void {
|
|
75
|
+
super.configure(options, diContainer);
|
|
76
|
+
this.saveable.dispose();
|
|
77
|
+
this.saveable = this.createSaveable();
|
|
78
|
+
this.toDispose.push(this.saveable);
|
|
79
|
+
this.toDispose.push(this.reopenRequestEmitter);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The widget's saveable. Override to change how saves and dirty state behave. */
|
|
83
|
+
protected createSaveable(): GLSPDiagramWidget['saveable'] {
|
|
84
|
+
return new HydraniumGlspSaveable(this.actionDispatcher, this.diContainer.get(EditorContextService));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Adds the window's resume token, so a reload or reconnect takes this diagram's session over. */
|
|
88
|
+
protected override getRequestModelOptions(): Args {
|
|
89
|
+
return { ...super.getRequestModelOptions(), [RESUME_TOKEN_ARG]: this.windowSessions.current().resumeToken };
|
|
90
|
+
}
|
|
63
91
|
|
|
64
92
|
protected override onAfterAttach(msg: Message): void {
|
|
65
93
|
// Before `super`, which is what starts the load on first attach — so the
|
|
@@ -73,6 +101,19 @@ export class HydraniumGlspDiagramWidget extends GLSPDiagramWidget {
|
|
|
73
101
|
super.dispose();
|
|
74
102
|
}
|
|
75
103
|
|
|
104
|
+
/**
|
|
105
|
+
* GLSP's restore with `animate: false`; compare the two on a GLSP upgrade.
|
|
106
|
+
* An animated restore holds back every later command, so a Delete right
|
|
107
|
+
* after a select-all typed as the diagram opens finds nothing selected.
|
|
108
|
+
*/
|
|
109
|
+
protected override async setViewportData(viewportData: Parameters<GLSPDiagramWidget['setViewportData']>[0]): Promise<void> {
|
|
110
|
+
if (this.actionDispatcher instanceof GLSPActionDispatcher) {
|
|
111
|
+
this.actionDispatcher.dispatchOnceModelInitialized(
|
|
112
|
+
SetViewportAction.create(viewportData.elementId, viewportData.viewportData, { animate: false })
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
76
117
|
/**
|
|
77
118
|
* Cover the canvas until the load settles.
|
|
78
119
|
*
|
|
@@ -100,15 +141,9 @@ export class HydraniumGlspDiagramWidget extends GLSPDiagramWidget {
|
|
|
100
141
|
);
|
|
101
142
|
}
|
|
102
143
|
|
|
103
|
-
/**
|
|
104
|
-
* Take the overlay down, or keep it as the failure's only reporter.
|
|
105
|
-
*
|
|
106
|
-
* The overlay is retained ONLY for a failure the loader could not surface;
|
|
107
|
-
* anything else uncovers the canvas, so a load that failed *and was reported*
|
|
108
|
-
* reveals GLSP's status overlay rather than double-reporting on top of it.
|
|
109
|
-
*/
|
|
144
|
+
/** Take the overlay down, or keep it as the failure's report. */
|
|
110
145
|
protected onLoadSettled(outcome: DiagramLoadOutcome): void {
|
|
111
|
-
if (outcome.status === 'failed'
|
|
146
|
+
if (outcome.status === 'failed') {
|
|
112
147
|
this.showLoadFailure(outcome.error);
|
|
113
148
|
return;
|
|
114
149
|
}
|
|
@@ -136,6 +171,23 @@ export class HydraniumGlspDiagramWidget extends GLSPDiagramWidget {
|
|
|
136
171
|
if (label) {
|
|
137
172
|
label.textContent = loader.loadFailureLabel(error);
|
|
138
173
|
}
|
|
174
|
+
overlay.appendChild(this.createRetryButton());
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Ask for a fresh widget, after a failed load. */
|
|
178
|
+
protected retryLoad(): void {
|
|
179
|
+
if (this.hydraniumDiagramLoader?.loadOutcome?.status === 'failed') {
|
|
180
|
+
this.reopenRequestEmitter.fire();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Build the failure overlay's Retry button, which calls {@link retryLoad}. */
|
|
185
|
+
protected createRetryButton(): HTMLElement {
|
|
186
|
+
const button = document.createElement('button');
|
|
187
|
+
button.className = `theia-button ${DIAGRAM_LOADING_CLASS}-retry`;
|
|
188
|
+
button.textContent = nls.localize('hydranium/glsp-client-theia/diagram-load-retry', 'Retry');
|
|
189
|
+
button.addEventListener('click', () => this.retryLoad());
|
|
190
|
+
return button;
|
|
139
191
|
}
|
|
140
192
|
|
|
141
193
|
protected hideLoadingOverlay(): void {
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import { bindChannelLogger, type ChannelLoggerOptions } from '@hydranium/client-theia/
|
|
11
|
-
import { type BindingContext, DiagramLoader, GLSPActionDispatcher, GLSPHiddenBoundsUpdater } from '@eclipse-glsp/client';
|
|
10
|
+
import { bindChannelLogger, type ChannelLoggerOptions } from '@hydranium/client-theia/browser';
|
|
11
|
+
import { type BindingContext, DiagramLoader, GLSPActionDispatcher, GLSPHiddenBoundsUpdater, StatusOverlay } from '@eclipse-glsp/client';
|
|
12
12
|
import { HydraniumGlspActionDispatcher } from './action-dispatcher';
|
|
13
13
|
import { HydraniumDiagramLoader } from './diagram-loader';
|
|
14
|
+
import { HydraniumStatusOverlay } from './status-overlay';
|
|
14
15
|
import { bindHydraniumGlspMessageService } from './glsp-message-service';
|
|
15
16
|
import { HydraniumHiddenBoundsUpdater } from './hidden-bounds-updater';
|
|
16
17
|
|
|
@@ -50,5 +51,6 @@ export function createGlspClientTheiaModule(context: BindingContext, options: Gl
|
|
|
50
51
|
rebind(GLSPActionDispatcher).toService(HydraniumGlspActionDispatcher);
|
|
51
52
|
rebind(DiagramLoader).to(HydraniumDiagramLoader).inSingletonScope();
|
|
52
53
|
rebind(GLSPHiddenBoundsUpdater).to(HydraniumHiddenBoundsUpdater).inSingletonScope();
|
|
54
|
+
rebind(StatusOverlay).to(HydraniumStatusOverlay).inSingletonScope();
|
|
53
55
|
bindHydraniumGlspMessageService(bind, isBound, rebind);
|
|
54
56
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import { BaseJsonrpcGLSPClient, type DisposeClientSessionParameters } from '@eclipse-glsp/client';
|
|
11
|
+
|
|
12
|
+
/** The GLSP client of `HydraniumGlspClientContribution`. */
|
|
13
|
+
export class HydraniumGlspClient extends BaseJsonrpcGLSPClient {
|
|
14
|
+
/** Resolves at once when the connection is gone: the session went with its
|
|
15
|
+
* server, and upstream would throw, which a diagram disposed after its
|
|
16
|
+
* client was lost logs as an error. */
|
|
17
|
+
override disposeClientSession(params: DisposeClientSessionParameters): Promise<void> {
|
|
18
|
+
return this.isConnectionActive() ? super.disposeClientSession(params) : Promise.resolve();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -7,10 +7,22 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import { codiconCSSString } from '@eclipse-glsp/client';
|
|
10
|
+
import { codiconCSSString, DiagramLoader, type IDiagramOptions } from '@eclipse-glsp/client';
|
|
11
11
|
import { GLSPDiagramManager } from '@eclipse-glsp/theia-integration';
|
|
12
12
|
import { type GLSPDiagramLanguage } from '@eclipse-glsp/theia-integration/lib/common';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
type GLSPDiagramWidget,
|
|
15
|
+
type GLSPDiagramWidgetOptions,
|
|
16
|
+
type GLSPWidgetOpenerOptions
|
|
17
|
+
} from '@eclipse-glsp/theia-integration/lib/browser';
|
|
18
|
+
import { type WidgetOpenerOptions } from '@theia/core/lib/browser';
|
|
19
|
+
import { type Disposable, DisposableCollection } from '@theia/core';
|
|
20
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
21
|
+
import { textHash } from '@hydranium/protocol';
|
|
22
|
+
import { HydraniumGlspClientContribution } from './client-contribution';
|
|
23
|
+
import { HydraniumDiagramLoader } from './diagram-loader';
|
|
24
|
+
import { HydraniumGlspDiagramWidget } from './diagram-widget';
|
|
25
|
+
import { WindowSessionService } from './window-session';
|
|
14
26
|
|
|
15
27
|
/**
|
|
16
28
|
* `GLSPDiagramManager` subclass that derives the language-correlated getters
|
|
@@ -45,6 +57,12 @@ export abstract class AbstractHydraniumGlspDiagramManager extends GLSPDiagramMan
|
|
|
45
57
|
/** Optional icon-class override; takes precedence over the language's `iconClass`. */
|
|
46
58
|
protected readonly customIconClass?: string;
|
|
47
59
|
|
|
60
|
+
@inject(WindowSessionService) protected readonly windowSessions!: WindowSessionService;
|
|
61
|
+
|
|
62
|
+
protected clientListeners?: Disposable;
|
|
63
|
+
/** The reopens asked for so far, which run one at a time. */
|
|
64
|
+
protected reopening: Promise<void> = Promise.resolve();
|
|
65
|
+
|
|
48
66
|
override get fileExtensions(): string[] {
|
|
49
67
|
return [...this.diagramLanguage.fileExtensions];
|
|
50
68
|
}
|
|
@@ -64,4 +82,124 @@ export abstract class AbstractHydraniumGlspDiagramManager extends GLSPDiagramMan
|
|
|
64
82
|
get label(): string {
|
|
65
83
|
return this.managerLabel;
|
|
66
84
|
}
|
|
85
|
+
|
|
86
|
+
override async createWidget(options?: unknown): Promise<GLSPDiagramWidget> {
|
|
87
|
+
this.listenToClient();
|
|
88
|
+
const widget = await super.createWidget(options);
|
|
89
|
+
if (widget instanceof HydraniumGlspDiagramWidget) {
|
|
90
|
+
widget.onDidRequestReopen(() => void this.reopen(widget));
|
|
91
|
+
}
|
|
92
|
+
return widget;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The same client id for the same diagram in this window, across a reload
|
|
97
|
+
* and a reopen after a lost client, so its load takes over the session the
|
|
98
|
+
* old connection left and keeps its unsaved text. A diagram closed by the
|
|
99
|
+
* user ends its session, and opening it again starts afresh.
|
|
100
|
+
*
|
|
101
|
+
* The widget options enter as a hash: GLSP makes the id an element id and
|
|
102
|
+
* finds it with an `#id` selector, which a URI's `:` and `/` break. The
|
|
103
|
+
* options identify the widget, so two widgets of one document, in two edit
|
|
104
|
+
* modes or set apart by an option an adopter adds, do not take each other's
|
|
105
|
+
* session over.
|
|
106
|
+
*/
|
|
107
|
+
protected override createDiagramOptions(options: GLSPDiagramWidgetOptions): IDiagramOptions {
|
|
108
|
+
const clientId = `${this.diagramType}_${this.windowSessions.current().id}_${textHash(JSON.stringify(options))}`;
|
|
109
|
+
return { ...super.createDiagramOptions(options), clientId };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Reopen every diagram once its client is lost, since none of them has a
|
|
114
|
+
* server behind it any more, and a failed one once a client starts.
|
|
115
|
+
*/
|
|
116
|
+
protected listenToClient(): void {
|
|
117
|
+
if (this.clientListeners) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const contribution = this.diagramServiceProvider.getGLSPClientContribution(this.contributionId);
|
|
121
|
+
this.clientListeners =
|
|
122
|
+
contribution instanceof HydraniumGlspClientContribution
|
|
123
|
+
? new DisposableCollection(
|
|
124
|
+
contribution.onDidLoseClient(() => this.reopenAll(() => true)),
|
|
125
|
+
contribution.onDidStartClient(() => this.reopenAll(widget => this.loadFailed(widget)))
|
|
126
|
+
)
|
|
127
|
+
: new DisposableCollection();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
protected reopenAll(which: (widget: GLSPDiagramWidget) => boolean): void {
|
|
131
|
+
for (const widget of this.all.filter(which)) {
|
|
132
|
+
void this.reopen(widget);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
protected loadFailed(widget: GLSPDiagramWidget): boolean {
|
|
137
|
+
const loader = widget.diContainer.get<DiagramLoader>(DiagramLoader);
|
|
138
|
+
return loader instanceof HydraniumDiagramLoader && loader.loadOutcome?.status === 'failed';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Replace `widget` with a fresh one for the same diagram, in the same tab
|
|
143
|
+
* position and with its viewport: a new container and load under the same
|
|
144
|
+
* client id, which takes over the session the old connection left.
|
|
145
|
+
* Reopens run one at a time, since each places its replacement next to a
|
|
146
|
+
* neighbour that a reopen running alongside could take out of the layout.
|
|
147
|
+
*/
|
|
148
|
+
reopen(widget: GLSPDiagramWidget): Promise<void> {
|
|
149
|
+
const reopened = this.reopening.then(() => this.replaceWidget(widget));
|
|
150
|
+
this.reopening = reopened.catch(() => undefined);
|
|
151
|
+
return reopened;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Taken down as a close does, but without its save prompt, since a dirty
|
|
155
|
+
* diagram whose server is gone has nothing to save to. */
|
|
156
|
+
protected async replaceWidget(widget: GLSPDiagramWidget): Promise<void> {
|
|
157
|
+
if (widget.isDisposed) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const tabBar = this.shell.getTabBarFor(widget);
|
|
161
|
+
const titles = tabBar?.titles ?? [];
|
|
162
|
+
const index = titles.indexOf(widget.title);
|
|
163
|
+
// ponytail: a diagram alone in its tab bar reopens where a new one opens,
|
|
164
|
+
// since its split closes with it; restore the dock layout if that matters.
|
|
165
|
+
const neighbour = index > 0 ? titles[index - 1].owner : titles[index + 1]?.owner;
|
|
166
|
+
const mode = this.shell.activeWidget === widget ? 'activate' : tabBar?.currentTitle === widget.title ? 'reveal' : 'open';
|
|
167
|
+
// Detached before the dispose, as a close does: the widget stores its
|
|
168
|
+
// viewport on detach, and its dispose empties the container it reads.
|
|
169
|
+
widget.parent = null;
|
|
170
|
+
widget.dispose();
|
|
171
|
+
const options: GLSPWidgetOpenerOptions = {
|
|
172
|
+
mode,
|
|
173
|
+
editMode: widget.options.editMode,
|
|
174
|
+
widgetOptions: neighbour ? { ref: neighbour, mode: index > 0 ? 'tab-after' : 'tab-before' } : undefined
|
|
175
|
+
};
|
|
176
|
+
await this.open(widget.uri, options);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Drops a `selection` key that is present but `undefined` before the base
|
|
181
|
+
* class reads it.
|
|
182
|
+
*
|
|
183
|
+
* Without this, opening a diagram from Theia's file picker throws and the
|
|
184
|
+
* editor never leaves "Loading diagram…". Upstream's
|
|
185
|
+
* `OptionsWithSelection.is` tests `'selection' in options`, which is true for
|
|
186
|
+
* a key explicitly set to `undefined`, and the branch it guards then calls
|
|
187
|
+
* `Object.keys` on that value. Theia's own `QuickFileOpenService` always sets
|
|
188
|
+
* the key — its `buildOpenerOptions` returns `{ selection: range }`, and
|
|
189
|
+
* `range` is `undefined` unless the query carried a `:line:column` suffix —
|
|
190
|
+
* so the crash is reached by the ordinary act of opening a diagram by name.
|
|
191
|
+
*
|
|
192
|
+
* Normalising the OPTIONS rather than rebinding
|
|
193
|
+
* `TheiaOpenerOptionsNavigationService`: the service is shared by every
|
|
194
|
+
* diagram type in the container, so replacing it would make one adopter's
|
|
195
|
+
* fix silently global, and the guard belongs where the value enters rather
|
|
196
|
+
* than where it is consumed. The base method stays the single implementation.
|
|
197
|
+
*/
|
|
198
|
+
protected override handleNavigations(widget: GLSPDiagramWidget, options?: WidgetOpenerOptions): boolean {
|
|
199
|
+
if (options && 'selection' in options && (options as { selection?: unknown }).selection === undefined) {
|
|
200
|
+
const { selection: _dropped, ...rest } = options as WidgetOpenerOptions & { selection?: unknown };
|
|
201
|
+
return super.handleNavigations(widget, rest);
|
|
202
|
+
}
|
|
203
|
+
return super.handleNavigations(widget, options);
|
|
204
|
+
}
|
|
67
205
|
}
|
|
@@ -24,6 +24,14 @@ import { type interfaces, injectable } from '@theia/core/shared/inversify';
|
|
|
24
24
|
* Matching an English literal fails silently — no error, no log line, just the
|
|
25
25
|
* duplicate progress popup back — so this needs keeping in step with
|
|
26
26
|
* `RequestModelActionHandler` on every GLSP bump.
|
|
27
|
+
*
|
|
28
|
+
* **Exported to be imported, and it must NOT be externalized.** An adopter
|
|
29
|
+
* subclassing the message service needs the same literal to match on, and a
|
|
30
|
+
* second copy of it is a second thing to keep in step across that bump. It is
|
|
31
|
+
* also the one user-visible string in the framework that is deliberately excluded
|
|
32
|
+
* from the message catalogue: it exists to equal an upstream English literal that
|
|
33
|
+
* lives in no catalogue, so giving it a code and a translation would break the
|
|
34
|
+
* match it exists for.
|
|
27
35
|
*/
|
|
28
36
|
export const MODEL_LOADING_PROGRESS_TITLE = 'Model loading in progress';
|
|
29
37
|
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import { RequestSaveModelAction } from '@hydranium/protocol';
|
|
11
|
+
// The module path, not the package root: the root also loads GLSP's diagram
|
|
12
|
+
// widget, which touches DOM globals at module load, and this module's unit tests
|
|
13
|
+
// load it in Node.
|
|
14
|
+
import { GLSPSaveable } from '@eclipse-glsp/theia-integration/lib/browser/diagram/glsp-saveable';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A `GLSPSaveable` whose every save is a request the server answers, and which
|
|
18
|
+
* stays dirty until that answer arrives.
|
|
19
|
+
*
|
|
20
|
+
* GLSP's sends a `SaveModelAction`, which the server does not answer. It takes
|
|
21
|
+
* the next dirty-state change to clean as the answer, but the editor context
|
|
22
|
+
* reports a change only when the dirty flag changes: the second of two saves
|
|
23
|
+
* gets no answer, and a failed save gets none either. Here each save sends a
|
|
24
|
+
* `RequestSaveModelAction` and settles on the response to that request only:
|
|
25
|
+
* it resolves when the server has saved, rejects when the server rejects it,
|
|
26
|
+
* and rejects when {@link saveTimeout} runs out. A save sent while another is
|
|
27
|
+
* pending is a request of its own, so an edit made between the two is saved.
|
|
28
|
+
*
|
|
29
|
+
* GLSP's also reports not dirty from the moment it sends a save. Theia's exit
|
|
30
|
+
* check asks only whether anything is dirty, so the window closes over a save
|
|
31
|
+
* the server has not finished, and a page reloaded right after Ctrl+S gives no
|
|
32
|
+
* warning. Here the saveable is dirty while any save is pending. GLSP's also
|
|
33
|
+
* gives up after 2 s, and Theia's Save All then counts the save as failed and
|
|
34
|
+
* closes the window anyway, so a slow save of a large model is cut off.
|
|
35
|
+
*
|
|
36
|
+
* The dirty flag still comes from the server. An edit whose dirty-state change
|
|
37
|
+
* has not arrived when Save All runs does not make the saveable dirty, so that
|
|
38
|
+
* edit is not saved.
|
|
39
|
+
*
|
|
40
|
+
* The server answers only where the diagram module registers the request's
|
|
41
|
+
* handler; `AbstractHydraniumGlspDiagramModule` does. A server without it does
|
|
42
|
+
* not advertise the request, and against such a server the saveable is GLSP's:
|
|
43
|
+
* it sends a `SaveModelAction` and reports dirty as GLSP's does. It does not
|
|
44
|
+
* keep only the dirty-while-pending half there, because GLSP's tracks one
|
|
45
|
+
* pending save and a second save overwrites it, so the first would never
|
|
46
|
+
* report clean.
|
|
47
|
+
*
|
|
48
|
+
* The answer means the server has done what its save does, which is not always
|
|
49
|
+
* the disk write: under the `fire-and-forget` `SaveDeliveryPolicy` the server
|
|
50
|
+
* answers before the write finishes and answers a failed write as saved, so a
|
|
51
|
+
* window closed on that answer can still lose the write.
|
|
52
|
+
*/
|
|
53
|
+
export class HydraniumGlspSaveable extends GLSPSaveable {
|
|
54
|
+
/**
|
|
55
|
+
* How long a save waits for the server's response before it rejects.
|
|
56
|
+
* Long, because the wait only runs out when the server hangs, and a save
|
|
57
|
+
* that rejects in Theia's Save All lets the window close over it.
|
|
58
|
+
*/
|
|
59
|
+
protected override saveTimeout = 10_000;
|
|
60
|
+
/** The saves sent and not yet settled. */
|
|
61
|
+
protected readonly pendingSaves = new Set<Promise<void>>();
|
|
62
|
+
|
|
63
|
+
override get dirty(): boolean {
|
|
64
|
+
if (!this.serverAnswersSaves()) {
|
|
65
|
+
return super.dirty;
|
|
66
|
+
}
|
|
67
|
+
return this.editorContextService.isDirty || this.pendingSaves.size > 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override save(): Promise<void> {
|
|
71
|
+
if (!this.serverAnswersSaves()) {
|
|
72
|
+
return super.save();
|
|
73
|
+
}
|
|
74
|
+
if (this.editorContextService.isDirty) {
|
|
75
|
+
return this.sendSave();
|
|
76
|
+
}
|
|
77
|
+
// Nothing new to save, but a save still pending has not finished.
|
|
78
|
+
return Promise.all(this.pendingSaves).then(() => undefined);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Whether the server answers a {@link RequestSaveModelAction}. GLSP's model
|
|
83
|
+
* source registers a handler for each kind the server advertises before it
|
|
84
|
+
* requests the model, so the dispatcher knows it from the first save on.
|
|
85
|
+
*/
|
|
86
|
+
protected serverAnswersSaves(): boolean {
|
|
87
|
+
return this.actionDispatcher.hasHandler(RequestSaveModelAction.create());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
protected sendSave(): Promise<void> {
|
|
91
|
+
// `request` with a bound of our own rather than GLSP's `requestUntil`:
|
|
92
|
+
// that one forgets a request when it times out, so a late response is
|
|
93
|
+
// dispatched as an action no client handler takes, which rejects.
|
|
94
|
+
// Here a late response settles the forgotten request and nothing else.
|
|
95
|
+
const response = this.actionDispatcher.request(RequestSaveModelAction.create());
|
|
96
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
97
|
+
const timedOut = new Promise<never>((_resolve, reject) => {
|
|
98
|
+
timer = setTimeout(() => reject(new Error('Save operation timed out')), this.saveTimeout);
|
|
99
|
+
});
|
|
100
|
+
const saving: Promise<void> = Promise.race([response, timedOut])
|
|
101
|
+
.then(() => undefined)
|
|
102
|
+
.finally(() => {
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
this.pendingSaves.delete(saving);
|
|
105
|
+
this.onDirtyChangedEmitter.fire(undefined);
|
|
106
|
+
});
|
|
107
|
+
this.pendingSaves.add(saving);
|
|
108
|
+
return saving;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -17,9 +17,10 @@ import {
|
|
|
17
17
|
registerDiagramManager
|
|
18
18
|
} from '@eclipse-glsp/theia-integration';
|
|
19
19
|
import { type GLSPDiagramLanguage } from '@eclipse-glsp/theia-integration/lib/common';
|
|
20
|
-
import { bindLogLevelPreference } from '@hydranium/client-theia/
|
|
20
|
+
import { bindConnectionReporter, bindLogLevelPreference } from '@hydranium/client-theia/browser';
|
|
21
21
|
import type { interfaces } from '@theia/core/shared/inversify';
|
|
22
22
|
import { HydraniumGlspDiagramWidget } from './diagram-widget';
|
|
23
|
+
import { bindWindowSessionService } from './window-session';
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Sentinel returned from {@link AbstractHydraniumGlspTheiaFrontendModule.bindClientContribution}
|
|
@@ -106,6 +107,8 @@ export abstract class AbstractHydraniumGlspTheiaFrontendModule extends GLSPTheia
|
|
|
106
107
|
*/
|
|
107
108
|
override initialize(context: ContainerContext): void {
|
|
108
109
|
super.initialize(context);
|
|
110
|
+
bindConnectionReporter(context.bind, context.isBound);
|
|
111
|
+
bindWindowSessionService(context.bind, context.isBound);
|
|
109
112
|
if (this.logLevelPreference) {
|
|
110
113
|
bindLogLevelPreference(context.bind, this.logLevelPreference);
|
|
111
114
|
}
|
|
@@ -19,9 +19,10 @@ import {
|
|
|
19
19
|
ServerAction,
|
|
20
20
|
isRoutable
|
|
21
21
|
} from '@eclipse-glsp/client';
|
|
22
|
-
import { ChannelLogger } from '@hydranium/client-theia/
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
22
|
+
import { ChannelLogger } from '@hydranium/client-theia/browser';
|
|
23
|
+
import { Clock } from '@hydranium/client-theia/common';
|
|
24
|
+
import { SystemClock } from '@hydranium/protocol';
|
|
25
|
+
import { inject, injectable, optional } from '@theia/core/shared/inversify';
|
|
25
26
|
import { type VNode } from 'snabbdom';
|
|
26
27
|
|
|
27
28
|
/** How many scoped element ids the log line names before summarising the rest.
|
|
@@ -71,10 +72,8 @@ const SCOPE_ID_CAP = 3;
|
|
|
71
72
|
export class HydraniumHiddenBoundsUpdater extends GLSPHiddenBoundsUpdater {
|
|
72
73
|
@inject(ChannelLogger) protected readonly channel!: ChannelLogger;
|
|
73
74
|
|
|
74
|
-
/**
|
|
75
|
-
|
|
76
|
-
* production. Overridden in tests for a deterministic elapsed value. */
|
|
77
|
-
protected readonly clock: Clock = new SystemClock();
|
|
75
|
+
/** The diagram container's {@link Clock}, or a `SystemClock`; it only measures. */
|
|
76
|
+
@inject(Clock) @optional() protected readonly clock: Clock = new SystemClock();
|
|
78
77
|
|
|
79
78
|
/**
|
|
80
79
|
* Scope description for the in-flight request, read from the `cause` in
|
package/src/browser/index.ts
CHANGED
|
@@ -14,9 +14,18 @@ export * from './client-contribution';
|
|
|
14
14
|
export * from './diagram-loader';
|
|
15
15
|
export * from './diagram-only-marker-manager';
|
|
16
16
|
export * from './diagram-widget';
|
|
17
|
+
export * from './glsp-client';
|
|
17
18
|
export * from './glsp-client-theia-module';
|
|
18
19
|
export * from './glsp-diagram-manager';
|
|
19
20
|
export * from './glsp-message-service';
|
|
21
|
+
export * from './glsp-saveable';
|
|
20
22
|
export * from './glsp-theia-frontend-module';
|
|
21
23
|
export * from './hidden-bounds-updater';
|
|
22
24
|
export * from './hydranium-glsp-diagram-configuration';
|
|
25
|
+
export * from './status-overlay';
|
|
26
|
+
export * from './window-session';
|
|
27
|
+
|
|
28
|
+
// Upstream's root entry is its browser tier and re-exports no `lib/common`, so the
|
|
29
|
+
// type our abstract `diagramLanguage` members are declared with has no bare-specifier
|
|
30
|
+
// path — without this line every adopter implementing one deep-imports it.
|
|
31
|
+
export type { GLSPDiagramLanguage } from '@eclipse-glsp/theia-integration/lib/common';
|