@hydranium/glsp-server 1.0.0-next.10
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/LICENSE +21 -0
- package/README.md +97 -0
- package/lib/browser/index.d.ts +10 -0
- package/lib/browser/index.d.ts.map +1 -0
- package/lib/browser/index.js +15 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/start-glsp-server-in-worker.d.ts +121 -0
- package/lib/browser/start-glsp-server-in-worker.d.ts.map +1 -0
- package/lib/browser/start-glsp-server-in-worker.js +102 -0
- package/lib/browser/start-glsp-server-in-worker.js.map +1 -0
- package/lib/command/hydranium-glsp-recording-command.d.ts +132 -0
- package/lib/command/hydranium-glsp-recording-command.d.ts.map +1 -0
- package/lib/command/hydranium-glsp-recording-command.js +159 -0
- package/lib/command/hydranium-glsp-recording-command.js.map +1 -0
- package/lib/command/index.d.ts +10 -0
- package/lib/command/index.d.ts.map +1 -0
- package/lib/command/index.js +10 -0
- package/lib/command/index.js.map +1 -0
- package/lib/computed-bounds/hydranium-glsp-computed-bounds-action-handler.d.ts +61 -0
- package/lib/computed-bounds/hydranium-glsp-computed-bounds-action-handler.d.ts.map +1 -0
- package/lib/computed-bounds/hydranium-glsp-computed-bounds-action-handler.js +93 -0
- package/lib/computed-bounds/hydranium-glsp-computed-bounds-action-handler.js.map +1 -0
- package/lib/computed-bounds/index.d.ts +10 -0
- package/lib/computed-bounds/index.d.ts.map +1 -0
- package/lib/computed-bounds/index.js +10 -0
- package/lib/computed-bounds/index.js.map +1 -0
- package/lib/dispatcher/index.d.ts +10 -0
- package/lib/dispatcher/index.d.ts.map +1 -0
- package/lib/dispatcher/index.js +10 -0
- package/lib/dispatcher/index.js.map +1 -0
- package/lib/dispatcher/server-action-dispatcher.d.ts +52 -0
- package/lib/dispatcher/server-action-dispatcher.d.ts.map +1 -0
- package/lib/dispatcher/server-action-dispatcher.js +79 -0
- package/lib/dispatcher/server-action-dispatcher.js.map +1 -0
- package/lib/index.d.ts +19 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +20 -0
- package/lib/index.js.map +1 -0
- package/lib/launcher/abstract-hydranium-glsp-diagram-module.d.ts +75 -0
- package/lib/launcher/abstract-hydranium-glsp-diagram-module.d.ts.map +1 -0
- package/lib/launcher/abstract-hydranium-glsp-diagram-module.js +100 -0
- package/lib/launcher/abstract-hydranium-glsp-diagram-module.js.map +1 -0
- package/lib/launcher/glsp-app-module.d.ts +87 -0
- package/lib/launcher/glsp-app-module.d.ts.map +1 -0
- package/lib/launcher/glsp-app-module.js +71 -0
- package/lib/launcher/glsp-app-module.js.map +1 -0
- package/lib/launcher/glsp-framework-overrides.d.ts +32 -0
- package/lib/launcher/glsp-framework-overrides.d.ts.map +1 -0
- package/lib/launcher/glsp-framework-overrides.js +49 -0
- package/lib/launcher/glsp-framework-overrides.js.map +1 -0
- package/lib/launcher/glsp-server-overrides.d.ts +39 -0
- package/lib/launcher/glsp-server-overrides.d.ts.map +1 -0
- package/lib/launcher/glsp-server-overrides.js +45 -0
- package/lib/launcher/glsp-server-overrides.js.map +1 -0
- package/lib/launcher/hydranium-glsp-server.d.ts +62 -0
- package/lib/launcher/hydranium-glsp-server.d.ts.map +1 -0
- package/lib/launcher/hydranium-glsp-server.js +101 -0
- package/lib/launcher/hydranium-glsp-server.js.map +1 -0
- package/lib/launcher/index.d.ts +12 -0
- package/lib/launcher/index.d.ts.map +1 -0
- package/lib/launcher/index.js +22 -0
- package/lib/launcher/index.js.map +1 -0
- package/lib/logging/glsp-client-logger.d.ts +110 -0
- package/lib/logging/glsp-client-logger.d.ts.map +1 -0
- package/lib/logging/glsp-client-logger.js +151 -0
- package/lib/logging/glsp-client-logger.js.map +1 -0
- package/lib/logging/index.d.ts +10 -0
- package/lib/logging/index.d.ts.map +1 -0
- package/lib/logging/index.js +10 -0
- package/lib/logging/index.js.map +1 -0
- package/lib/node/index.d.ts +10 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +13 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/start-glsp-server.d.ts +122 -0
- package/lib/node/start-glsp-server.d.ts.map +1 -0
- package/lib/node/start-glsp-server.js +103 -0
- package/lib/node/start-glsp-server.js.map +1 -0
- package/lib/state/abstract-hydranium-glsp-state.d.ts +333 -0
- package/lib/state/abstract-hydranium-glsp-state.d.ts.map +1 -0
- package/lib/state/abstract-hydranium-glsp-state.js +451 -0
- package/lib/state/abstract-hydranium-glsp-state.js.map +1 -0
- package/lib/state/full-text-hydranium-glsp-state.d.ts +43 -0
- package/lib/state/full-text-hydranium-glsp-state.d.ts.map +1 -0
- package/lib/state/full-text-hydranium-glsp-state.js +60 -0
- package/lib/state/full-text-hydranium-glsp-state.js.map +1 -0
- package/lib/state/hydranium-glsp-index.d.ts +220 -0
- package/lib/state/hydranium-glsp-index.d.ts.map +1 -0
- package/lib/state/hydranium-glsp-index.js +320 -0
- package/lib/state/hydranium-glsp-index.js.map +1 -0
- package/lib/state/hydranium-shared-core-services.d.ts +90 -0
- package/lib/state/hydranium-shared-core-services.d.ts.map +1 -0
- package/lib/state/hydranium-shared-core-services.js +89 -0
- package/lib/state/hydranium-shared-core-services.js.map +1 -0
- package/lib/state/index.d.ts +17 -0
- package/lib/state/index.d.ts.map +1 -0
- package/lib/state/index.js +17 -0
- package/lib/state/index.js.map +1 -0
- package/lib/state/model-ready-timeout-error.d.ts +28 -0
- package/lib/state/model-ready-timeout-error.d.ts.map +1 -0
- package/lib/state/model-ready-timeout-error.js +36 -0
- package/lib/state/model-ready-timeout-error.js.map +1 -0
- package/lib/state/reconcile-source-model-write.d.ts +43 -0
- package/lib/state/reconcile-source-model-write.d.ts.map +1 -0
- package/lib/state/reconcile-source-model-write.js +47 -0
- package/lib/state/reconcile-source-model-write.js.map +1 -0
- package/lib/state/reconciling-multi-document-glsp-state.d.ts +164 -0
- package/lib/state/reconciling-multi-document-glsp-state.d.ts.map +1 -0
- package/lib/state/reconciling-multi-document-glsp-state.js +222 -0
- package/lib/state/reconciling-multi-document-glsp-state.js.map +1 -0
- package/lib/state/reconciling-transfer-hydranium-glsp-state.d.ts +91 -0
- package/lib/state/reconciling-transfer-hydranium-glsp-state.d.ts.map +1 -0
- package/lib/state/reconciling-transfer-hydranium-glsp-state.js +129 -0
- package/lib/state/reconciling-transfer-hydranium-glsp-state.js.map +1 -0
- package/lib/storage/hydranium-glsp-storage.d.ts +348 -0
- package/lib/storage/hydranium-glsp-storage.d.ts.map +1 -0
- package/lib/storage/hydranium-glsp-storage.js +634 -0
- package/lib/storage/hydranium-glsp-storage.js.map +1 -0
- package/lib/storage/index.d.ts +11 -0
- package/lib/storage/index.d.ts.map +1 -0
- package/lib/storage/index.js +11 -0
- package/lib/storage/index.js.map +1 -0
- package/lib/storage/save-conflict-policy.d.ts +56 -0
- package/lib/storage/save-conflict-policy.d.ts.map +1 -0
- package/lib/storage/save-conflict-policy.js +19 -0
- package/lib/storage/save-conflict-policy.js.map +1 -0
- package/lib/submission/hydranium-glsp-submission-handler.d.ts +109 -0
- package/lib/submission/hydranium-glsp-submission-handler.d.ts.map +1 -0
- package/lib/submission/hydranium-glsp-submission-handler.js +157 -0
- package/lib/submission/hydranium-glsp-submission-handler.js.map +1 -0
- package/lib/submission/index.d.ts +10 -0
- package/lib/submission/index.d.ts.map +1 -0
- package/lib/submission/index.js +10 -0
- package/lib/submission/index.js.map +1 -0
- package/lib/testing/glsp-harness.d.ts +170 -0
- package/lib/testing/glsp-harness.d.ts.map +1 -0
- package/lib/testing/glsp-harness.js +231 -0
- package/lib/testing/glsp-harness.js.map +1 -0
- package/lib/testing/index.d.ts +11 -0
- package/lib/testing/index.d.ts.map +1 -0
- package/lib/testing/index.js +13 -0
- package/lib/testing/index.js.map +1 -0
- package/lib/testing/make-noop-glsp-logger.d.ts +42 -0
- package/lib/testing/make-noop-glsp-logger.d.ts.map +1 -0
- package/lib/testing/make-noop-glsp-logger.js +47 -0
- package/lib/testing/make-noop-glsp-logger.js.map +1 -0
- package/lib/util/index.d.ts +10 -0
- package/lib/util/index.d.ts.map +1 -0
- package/lib/util/index.js +10 -0
- package/lib/util/index.js.map +1 -0
- package/lib/util/service-identifier.d.ts +46 -0
- package/lib/util/service-identifier.d.ts.map +1 -0
- package/lib/util/service-identifier.js +47 -0
- package/lib/util/service-identifier.js.map +1 -0
- package/lib/validation/diagnostic-markers.d.ts +48 -0
- package/lib/validation/diagnostic-markers.d.ts.map +1 -0
- package/lib/validation/diagnostic-markers.js +68 -0
- package/lib/validation/diagnostic-markers.js.map +1 -0
- package/lib/validation/hydranium-glsp-model-validator.d.ts +51 -0
- package/lib/validation/hydranium-glsp-model-validator.d.ts.map +1 -0
- package/lib/validation/hydranium-glsp-model-validator.js +118 -0
- package/lib/validation/hydranium-glsp-model-validator.js.map +1 -0
- package/lib/validation/index.d.ts +11 -0
- package/lib/validation/index.d.ts.map +1 -0
- package/lib/validation/index.js +11 -0
- package/lib/validation/index.js.map +1 -0
- package/package.json +111 -0
- package/src/browser/index.ts +15 -0
- package/src/browser/start-glsp-server-in-worker.ts +202 -0
- package/src/command/hydranium-glsp-recording-command.ts +183 -0
- package/src/command/index.ts +10 -0
- package/src/computed-bounds/hydranium-glsp-computed-bounds-action-handler.ts +103 -0
- package/src/computed-bounds/index.ts +10 -0
- package/src/dispatcher/index.ts +10 -0
- package/src/dispatcher/server-action-dispatcher.ts +72 -0
- package/src/index.ts +20 -0
- package/src/launcher/abstract-hydranium-glsp-diagram-module.ts +117 -0
- package/src/launcher/glsp-app-module.ts +106 -0
- package/src/launcher/glsp-framework-overrides.ts +51 -0
- package/src/launcher/glsp-server-overrides.ts +46 -0
- package/src/launcher/hydranium-glsp-server.ts +104 -0
- package/src/launcher/index.ts +22 -0
- package/src/logging/glsp-client-logger.ts +184 -0
- package/src/logging/index.ts +10 -0
- package/src/node/index.ts +13 -0
- package/src/node/start-glsp-server.ts +214 -0
- package/src/state/abstract-hydranium-glsp-state.ts +503 -0
- package/src/state/full-text-hydranium-glsp-state.ts +63 -0
- package/src/state/hydranium-glsp-index.ts +337 -0
- package/src/state/hydranium-shared-core-services.ts +92 -0
- package/src/state/index.ts +17 -0
- package/src/state/model-ready-timeout-error.ts +33 -0
- package/src/state/reconcile-source-model-write.ts +77 -0
- package/src/state/reconciling-multi-document-glsp-state.ts +248 -0
- package/src/state/reconciling-transfer-hydranium-glsp-state.ts +132 -0
- package/src/storage/hydranium-glsp-storage.ts +660 -0
- package/src/storage/index.ts +11 -0
- package/src/storage/save-conflict-policy.ts +52 -0
- package/src/submission/hydranium-glsp-submission-handler.ts +170 -0
- package/src/submission/index.ts +10 -0
- package/src/testing/glsp-harness.ts +422 -0
- package/src/testing/index.ts +14 -0
- package/src/testing/make-noop-glsp-logger.ts +66 -0
- package/src/util/index.ts +10 -0
- package/src/util/service-identifier.ts +49 -0
- package/src/validation/diagnostic-markers.ts +93 -0
- package/src/validation/hydranium-glsp-model-validator.ts +105 -0
- package/src/validation/index.ts +11 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
import { type Marker } from '@eclipse-glsp/protocol';
|
|
10
|
+
import { type GModelElement, type ModelValidator } from '@eclipse-glsp/server';
|
|
11
|
+
import { type AstNode } from '@hydranium/langium';
|
|
12
|
+
import { type ServerSharedServices } from '@hydranium/core';
|
|
13
|
+
import { type AbstractHydraniumGlspState } from '../state/abstract-hydranium-glsp-state.js';
|
|
14
|
+
/**
|
|
15
|
+
* Framework {@link ModelValidator} that surfaces the model server's LSP
|
|
16
|
+
* diagnostics as GLSP diagram markers. Bound per diagram via
|
|
17
|
+
* `DiagramModule.bindModelValidator()`; the framework submission handler also
|
|
18
|
+
* pushes its output as a `SetMarkersAction` after every model submit so
|
|
19
|
+
* markers refresh live (the GLSP client otherwise only re-requests markers on
|
|
20
|
+
* the tool-palette validate command).
|
|
21
|
+
*
|
|
22
|
+
* The translation itself ({@link diagnosticsToMarkers}) is pure; this class
|
|
23
|
+
* supplies its model-shaped lookups from the live services: the per-language
|
|
24
|
+
* `AstNodeLocator` resolves a diagnostic's `element` path back to its AST node,
|
|
25
|
+
* and the GModel index assigns the node's diagram id and reports whether that
|
|
26
|
+
* id is currently drawn.
|
|
27
|
+
*
|
|
28
|
+
* **Cross-document.** A diagram routinely renders elements defined in *other*
|
|
29
|
+
* documents, and their validation errors are published on those documents, not
|
|
30
|
+
* on the diagram's own. The validator therefore scans the diagnostics of every
|
|
31
|
+
* document the index reports as contributing a rendered element (the index's
|
|
32
|
+
* `renderedDocumentUris`: the diagram's own document plus those reached via
|
|
33
|
+
* reference projections) and lets the index's rendered-check keep only those
|
|
34
|
+
* that map to an element drawn on this diagram; the rest fall away. The
|
|
35
|
+
* `elements` argument of {@link validate} is ignored — the diagnostic set is
|
|
36
|
+
* the source of truth, and the default `RequestMarkersAction` requests the
|
|
37
|
+
* whole diagram anyway.
|
|
38
|
+
*/
|
|
39
|
+
export declare class HydraniumGlspModelValidator<TRoot extends AstNode = AstNode> implements ModelValidator {
|
|
40
|
+
protected readonly sharedServices: ServerSharedServices;
|
|
41
|
+
protected readonly modelState: AbstractHydraniumGlspState<TRoot>;
|
|
42
|
+
validate(_elements: GModelElement[], _reason?: string): Marker[];
|
|
43
|
+
/**
|
|
44
|
+
* Markers for everything drawn on this diagram, gathered from the
|
|
45
|
+
* diagnostics of every document the index reports as contributing a
|
|
46
|
+
* rendered element. Empty before the source model is loaded, and for any
|
|
47
|
+
* diagnostic whose element is not rendered here.
|
|
48
|
+
*/
|
|
49
|
+
markers(): Marker[];
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=hydranium-glsp-model-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydranium-glsp-model-validator.d.ts","sourceRoot":"","sources":["../../src/validation/hydranium-glsp-model-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,KAAK,aAAa,EAAc,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3F,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,KAAK,oBAAoB,EAA8B,MAAM,iBAAiB,CAAC;AACxF,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AAI5F;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBACa,2BAA2B,CAAC,KAAK,SAAS,OAAO,GAAG,OAAO,CAAE,YAAW,cAAc;IACrD,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAG,oBAAoB,CAAC;IAChF,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAG,0BAA0B,CAAC,KAAK,CAAC,CAAC;IAEtF,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAIhE;;;;;OAKG;IACH,OAAO,IAAI,MAAM,EAAE;CA6CrB"}
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
10
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
12
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
|
+
};
|
|
15
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
16
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
17
|
+
};
|
|
18
|
+
import { ModelState } from '@eclipse-glsp/server';
|
|
19
|
+
import { inject, injectable } from 'inversify';
|
|
20
|
+
import { URI } from '@hydranium/langium';
|
|
21
|
+
import { HydraniumTypes } from '../state/hydranium-shared-core-services.js';
|
|
22
|
+
import { diagnosticsToMarkers } from './diagnostic-markers.js';
|
|
23
|
+
/**
|
|
24
|
+
* Framework {@link ModelValidator} that surfaces the model server's LSP
|
|
25
|
+
* diagnostics as GLSP diagram markers. Bound per diagram via
|
|
26
|
+
* `DiagramModule.bindModelValidator()`; the framework submission handler also
|
|
27
|
+
* pushes its output as a `SetMarkersAction` after every model submit so
|
|
28
|
+
* markers refresh live (the GLSP client otherwise only re-requests markers on
|
|
29
|
+
* the tool-palette validate command).
|
|
30
|
+
*
|
|
31
|
+
* The translation itself ({@link diagnosticsToMarkers}) is pure; this class
|
|
32
|
+
* supplies its model-shaped lookups from the live services: the per-language
|
|
33
|
+
* `AstNodeLocator` resolves a diagnostic's `element` path back to its AST node,
|
|
34
|
+
* and the GModel index assigns the node's diagram id and reports whether that
|
|
35
|
+
* id is currently drawn.
|
|
36
|
+
*
|
|
37
|
+
* **Cross-document.** A diagram routinely renders elements defined in *other*
|
|
38
|
+
* documents, and their validation errors are published on those documents, not
|
|
39
|
+
* on the diagram's own. The validator therefore scans the diagnostics of every
|
|
40
|
+
* document the index reports as contributing a rendered element (the index's
|
|
41
|
+
* `renderedDocumentUris`: the diagram's own document plus those reached via
|
|
42
|
+
* reference projections) and lets the index's rendered-check keep only those
|
|
43
|
+
* that map to an element drawn on this diagram; the rest fall away. The
|
|
44
|
+
* `elements` argument of {@link validate} is ignored — the diagnostic set is
|
|
45
|
+
* the source of truth, and the default `RequestMarkersAction` requests the
|
|
46
|
+
* whole diagram anyway.
|
|
47
|
+
*/
|
|
48
|
+
let HydraniumGlspModelValidator = class HydraniumGlspModelValidator {
|
|
49
|
+
sharedServices;
|
|
50
|
+
modelState;
|
|
51
|
+
validate(_elements, _reason) {
|
|
52
|
+
return this.markers();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Markers for everything drawn on this diagram, gathered from the
|
|
56
|
+
* diagnostics of every document the index reports as contributing a
|
|
57
|
+
* rendered element. Empty before the source model is loaded, and for any
|
|
58
|
+
* diagnostic whose element is not rendered here.
|
|
59
|
+
*/
|
|
60
|
+
markers() {
|
|
61
|
+
// `sourceUri` is a definite-assignment field — undefined until the
|
|
62
|
+
// storage load flow calls `setSourceRoot`. Guard so a marker request that
|
|
63
|
+
// races initial load returns empty rather than scanning an empty index.
|
|
64
|
+
if (!this.modelState.sourceUri) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const index = this.modelState.index;
|
|
68
|
+
const markers = [];
|
|
69
|
+
// Scan only the documents that contribute rendered elements, not every
|
|
70
|
+
// loaded document. The rendered-check below still keeps only what is
|
|
71
|
+
// drawn here.
|
|
72
|
+
for (const uri of index.renderedDocumentUris()) {
|
|
73
|
+
const document = this.sharedServices.workspace.LangiumDocuments.getDocument(URI.parse(uri));
|
|
74
|
+
if (!document) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// Diagnostics are produced by the framework's `HydraniumDocumentValidator`,
|
|
78
|
+
// which emits `TransferLspDiagnostic` (LSP `Diagnostic` + `element` path).
|
|
79
|
+
// Parser/lexer diagnostics carry no `element`; the lookup drops them.
|
|
80
|
+
const diagnostics = document.diagnostics;
|
|
81
|
+
if (!diagnostics || diagnostics.length === 0) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const root = document.parseResult.value;
|
|
85
|
+
const locator = this.sharedServices.ServiceRegistry.getServices(document.uri).workspace.AstNodeLocator;
|
|
86
|
+
const lookups = {
|
|
87
|
+
resolveElement: path => (path ? locator.getAstNode(root, path) : undefined),
|
|
88
|
+
renderedIdsFor: astNode => {
|
|
89
|
+
// A node renders as: every GModel element explicitly registered as
|
|
90
|
+
// representing it (reference projections, possibly several), plus its
|
|
91
|
+
// own stable id, for an element keyed directly by it. Keep only the
|
|
92
|
+
// ids actually drawn on this diagram.
|
|
93
|
+
const candidates = new Set(index.findElementIds(astNode));
|
|
94
|
+
const stableId = index.findId(astNode);
|
|
95
|
+
if (stableId !== undefined) {
|
|
96
|
+
candidates.add(stableId);
|
|
97
|
+
}
|
|
98
|
+
return [...candidates].filter(id => index.find(id) !== undefined);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
markers.push(...diagnosticsToMarkers(diagnostics, lookups));
|
|
102
|
+
}
|
|
103
|
+
return markers;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
__decorate([
|
|
107
|
+
inject(HydraniumTypes.SharedCoreServices),
|
|
108
|
+
__metadata("design:type", Object)
|
|
109
|
+
], HydraniumGlspModelValidator.prototype, "sharedServices", void 0);
|
|
110
|
+
__decorate([
|
|
111
|
+
inject(ModelState),
|
|
112
|
+
__metadata("design:type", Function)
|
|
113
|
+
], HydraniumGlspModelValidator.prototype, "modelState", void 0);
|
|
114
|
+
HydraniumGlspModelValidator = __decorate([
|
|
115
|
+
injectable()
|
|
116
|
+
], HydraniumGlspModelValidator);
|
|
117
|
+
export { HydraniumGlspModelValidator };
|
|
118
|
+
//# sourceMappingURL=hydranium-glsp-model-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydranium-glsp-model-validator.js","sourceRoot":"","sources":["../../src/validation/hydranium-glsp-model-validator.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
export * from './diagnostic-markers.js';
|
|
10
|
+
export * from './hydranium-glsp-model-validator.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,cAAc,yBAAyB,CAAC;AACxC,cAAc,qCAAqC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
export * from './diagnostic-markers.js';
|
|
10
|
+
export * from './hydranium-glsp-model-validator.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,cAAc,yBAAyB,CAAC;AACxC,cAAc,qCAAqC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hydranium/glsp-server",
|
|
3
|
+
"version": "1.0.0-next.10",
|
|
4
|
+
"description": "GLSP protocol head for the hydranium framework. Peer of @hydranium/core/lsp and @hydranium/data-server; built on @hydranium/core.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"hydranium",
|
|
7
|
+
"langium",
|
|
8
|
+
"language-server",
|
|
9
|
+
"lsp",
|
|
10
|
+
"glsp",
|
|
11
|
+
"diagram"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/eclipse-emfcloud/hydranium/tree/main/packages/glsp-server",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/eclipse-emfcloud/hydranium/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/eclipse-emfcloud/hydranium.git",
|
|
20
|
+
"directory": "packages/glsp-server"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "Hydranium Team"
|
|
25
|
+
},
|
|
26
|
+
"sideEffects": [
|
|
27
|
+
"./lib/testing/glsp-harness.js"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./lib/index.d.ts",
|
|
33
|
+
"default": "./lib/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./browser": {
|
|
36
|
+
"types": "./lib/browser/index.d.ts",
|
|
37
|
+
"default": "./lib/browser/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./lib/browser": {
|
|
40
|
+
"types": "./lib/browser/index.d.ts",
|
|
41
|
+
"default": "./lib/browser/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./node": {
|
|
44
|
+
"types": "./lib/node/index.d.ts",
|
|
45
|
+
"default": "./lib/node/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./lib/node": {
|
|
48
|
+
"types": "./lib/node/index.d.ts",
|
|
49
|
+
"default": "./lib/node/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./testing": {
|
|
52
|
+
"types": "./lib/testing/index.d.ts",
|
|
53
|
+
"default": "./lib/testing/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./lib/testing": {
|
|
56
|
+
"types": "./lib/testing/index.d.ts",
|
|
57
|
+
"default": "./lib/testing/index.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"main": "lib/index.js",
|
|
61
|
+
"types": "lib/index.d.ts",
|
|
62
|
+
"files": [
|
|
63
|
+
"lib",
|
|
64
|
+
"src",
|
|
65
|
+
"!lib/**/*.tsbuildinfo"
|
|
66
|
+
],
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "tsc -b",
|
|
69
|
+
"clean": "rimraf lib tsconfig.tsbuildinfo",
|
|
70
|
+
"lint": "eslint src test --max-warnings 0",
|
|
71
|
+
"prepack": "node -e \"const m=require('./package.json'),fs=require('node:fs');const missing=[m.main,...Object.values(m.bin||{})].filter(entry=>entry&&!fs.existsSync(entry));if(missing.length){console.error('prepack '+m.name+': not built ('+missing.join(', ')+' missing). Run the build before packing: a files entry that matches nothing is skipped silently, so the tarball would ship src only.');process.exit(1);}\"",
|
|
72
|
+
"test": "npm run typecheck:test && vitest run",
|
|
73
|
+
"typecheck:test": "tsc --noEmit -p tsconfig.test.json",
|
|
74
|
+
"watch": "tsc -b -w --preserveWatchOutput"
|
|
75
|
+
},
|
|
76
|
+
"dependencies": {
|
|
77
|
+
"uuid": "^10.0.0"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@eclipse-glsp/protocol": "2.7.0",
|
|
81
|
+
"@eclipse-glsp/server": "2.7.0",
|
|
82
|
+
"@hydranium/core": "1.0.0-next.10",
|
|
83
|
+
"@hydranium/langium": "1.0.0-next.10",
|
|
84
|
+
"@hydranium/protocol": "1.0.0-next.10",
|
|
85
|
+
"inversify": "6.2.2",
|
|
86
|
+
"reflect-metadata": "0.2.2",
|
|
87
|
+
"rimraf": "^5.0.0",
|
|
88
|
+
"typescript": "^5.8.0",
|
|
89
|
+
"vscode-jsonrpc": "9.0.1",
|
|
90
|
+
"vscode-languageserver-types": "^3.17.5"
|
|
91
|
+
},
|
|
92
|
+
"peerDependencies": {
|
|
93
|
+
"@eclipse-glsp/protocol": "^2.6.0",
|
|
94
|
+
"@eclipse-glsp/server": "^2.6.0",
|
|
95
|
+
"@hydranium/core": "1.0.0-next.10",
|
|
96
|
+
"@hydranium/langium": "1.0.0-next.10",
|
|
97
|
+
"@hydranium/protocol": "1.0.0-next.10",
|
|
98
|
+
"inversify": "^6.0.0",
|
|
99
|
+
"reflect-metadata": "^0.2.2",
|
|
100
|
+
"vscode-jsonrpc": "^8.0.0 || ^9.0.0",
|
|
101
|
+
"vscode-languageserver-types": "^3.17.5"
|
|
102
|
+
},
|
|
103
|
+
"engines": {
|
|
104
|
+
"node": ">=22.13"
|
|
105
|
+
},
|
|
106
|
+
"publishConfig": {
|
|
107
|
+
"access": "public"
|
|
108
|
+
},
|
|
109
|
+
"//prepack": "The publish guard, and it deliberately is NOT a `prepare`: npm runs a workspace `prepare` BEFORE the root `postinstall` that applies patches/vscode-jsonrpc+9.0.1.patch, so building there fails on a cold clone and npm rolls the entire install back. `prepack` runs only when a tarball is made (`npm pack`, `npm publish`) and never on install, so it cannot break the install it has no business touching. It FAILS rather than rebuilds, because the rebuild is exactly the part that ordering defeats. What it defends against: `files` lists `lib`, `lib` is gitignored, and a `files` entry matching nothing is skipped SILENTLY — so `npm publish` from an unbuilt tree emits a tarball of `src` and nothing else, with no error.",
|
|
110
|
+
"//sideEffects": "The harness bare-imports `reflect-metadata`, which installs a global `Reflect` polyfill the inversify decorators in this package need before any container is built. That effect is invisible from the module's exports, so a bundler that treats the file as pure may reorder or drop the import and every `@injectable` resolution then fails at runtime. The rest of the package constructs no module-level state beyond frozen constants and DI symbols."
|
|
111
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
// Browser-only entry (`@hydranium/glsp-server/browser`). Holds the worker
|
|
11
|
+
// launcher, which binds GLSP's `WorkerServerLauncher` from
|
|
12
|
+
// `@eclipse-glsp/server/browser`. The portable `.` entry stays free of that
|
|
13
|
+
// import for the same reason it stays free of the node one: it must resolve
|
|
14
|
+
// under both platforms, and a build that names one has picked.
|
|
15
|
+
export * from './start-glsp-server-in-worker.js';
|
|
@@ -0,0 +1,202 @@
|
|
|
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 {
|
|
11
|
+
type Logger as GlspLogger,
|
|
12
|
+
type ServerModule,
|
|
13
|
+
type WorkerLaunchOptions,
|
|
14
|
+
WorkerServerLauncher,
|
|
15
|
+
createAppModule
|
|
16
|
+
} from '@eclipse-glsp/server/browser.js';
|
|
17
|
+
import { Container, type ContainerModule } from 'inversify';
|
|
18
|
+
import type { Logger } from '@hydranium/protocol';
|
|
19
|
+
import type { IntegratedServer } from '@hydranium/core';
|
|
20
|
+
import { createGlspFrameworkOverrides } from '../launcher/glsp-framework-overrides.js';
|
|
21
|
+
import { createGlspServerOverrides } from '../launcher/glsp-server-overrides.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A `MessagePort` the host transferred into the worker, described structurally.
|
|
25
|
+
*
|
|
26
|
+
* This package inherits `tsconfig.base.json`'s `lib: ["ES2022"]` and so compiles
|
|
27
|
+
* without the DOM lib, which is what keeps `document` / `window` compile errors
|
|
28
|
+
* here — so `MessagePort` has no name either and the contract has to be spelled
|
|
29
|
+
* out.
|
|
30
|
+
*
|
|
31
|
+
* **The member set is chosen to admit a `MessagePort` and REJECT a `Worker` or
|
|
32
|
+
* the worker global**, both of which the launcher's own reader would otherwise
|
|
33
|
+
* accept. Only a port needs starting, so `start` is what tells the three apart,
|
|
34
|
+
* and naming it here turns "never bind a head to the global" from a rule in a
|
|
35
|
+
* document into a compile error at the call site.
|
|
36
|
+
*
|
|
37
|
+
* **That compile error happens at the ADOPTER, not here.** This project resolves
|
|
38
|
+
* neither `MessagePort` nor `Worker` as a type, so nothing in this package can
|
|
39
|
+
* demonstrate the rejection; a host compiling its worker against `lib.webworker`
|
|
40
|
+
* (or a page against `lib.dom`) is where the names resolve and the guard bites.
|
|
41
|
+
* Measured there: passing the worker global fails with `Property 'start' is
|
|
42
|
+
* missing in type 'DedicatedWorkerGlobalScope'`.
|
|
43
|
+
*
|
|
44
|
+
* `addEventListener` is not a discriminator — `postMessage` plus `start` already
|
|
45
|
+
* excludes the other two — and nothing in this module calls any of the three
|
|
46
|
+
* (the reader assigns `onmessage`, which starts a port implicitly). It is listed
|
|
47
|
+
* because it is part of what the reader uses, so the interface reads as the
|
|
48
|
+
* contract rather than as a minimal trick.
|
|
49
|
+
*/
|
|
50
|
+
export interface TransferredMessagePort {
|
|
51
|
+
postMessage(message: unknown): void;
|
|
52
|
+
addEventListener(type: 'message', listener: (event: unknown) => void, options?: unknown): void;
|
|
53
|
+
start(): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Options for {@link startGlspServerInWorker}.
|
|
58
|
+
*
|
|
59
|
+
* The socket variant's options have no counterpart here and are deliberately
|
|
60
|
+
* absent rather than ignored: there is no port to bind, none to discover, and
|
|
61
|
+
* so nothing to publish over an LSP connection.
|
|
62
|
+
*
|
|
63
|
+
* @see {@link startGlspServerInWorker} for the lifecycle semantics.
|
|
64
|
+
*/
|
|
65
|
+
export interface BrowserGlspServerOptions {
|
|
66
|
+
/**
|
|
67
|
+
* The port the host transferred into the worker for this head.
|
|
68
|
+
*
|
|
69
|
+
* **Required, and that is the whole point.** GLSP's
|
|
70
|
+
* `WorkerServerLauncher.createConnection` falls back to the worker global
|
|
71
|
+
* when it is omitted, and a head on the global receives every other head's
|
|
72
|
+
* traffic — `BrowserMessageReader` filters nothing, so this is not a race
|
|
73
|
+
* under load but every message delivered to the wrong reader. The global is
|
|
74
|
+
* unusable even for a single head, because the launcher posts its startup
|
|
75
|
+
* string through the global `postMessage` regardless of the connection it
|
|
76
|
+
* was given, and no JSON-RPC reader can parse that.
|
|
77
|
+
*/
|
|
78
|
+
readonly context: TransferredMessagePort;
|
|
79
|
+
/**
|
|
80
|
+
* Adopter-supplied logger factory. Called once per Inversify resolution
|
|
81
|
+
* (with `caller` set to the requesting parent's class name) AND once
|
|
82
|
+
* per `LoggerFactory` invocation.
|
|
83
|
+
*
|
|
84
|
+
* The GLSP log threshold is a property of the logger this returns, and there
|
|
85
|
+
* is deliberately no launcher-level `logLevel` beside it — see the socket
|
|
86
|
+
* variant's note on the same member.
|
|
87
|
+
*/
|
|
88
|
+
readonly createLogger: (caller?: string) => GlspLogger;
|
|
89
|
+
/**
|
|
90
|
+
* The GLSP {@link ServerModule} with per-diagram modules pre-configured via
|
|
91
|
+
* `new ServerModule().configureDiagramModule(...)`.
|
|
92
|
+
*/
|
|
93
|
+
readonly serverModule: ServerModule;
|
|
94
|
+
/**
|
|
95
|
+
* Additional Inversify modules to load on the app container AFTER GLSP's
|
|
96
|
+
* own app module and the framework overrides. Adopters wire language-services
|
|
97
|
+
* bindings (e.g. their own shared-services symbol) here.
|
|
98
|
+
*/
|
|
99
|
+
readonly appModules?: ReadonlyArray<ContainerModule>;
|
|
100
|
+
/**
|
|
101
|
+
* Optional framework-lifecycle logger, for the launcher's own bringup and
|
|
102
|
+
* failure lines. The GLSP container's logger handles application-level logs.
|
|
103
|
+
*/
|
|
104
|
+
readonly logger?: Logger;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Start a GLSP head on a transferred `MessagePort` inside a web worker, with no
|
|
109
|
+
* Node runtime and no backend process.
|
|
110
|
+
*
|
|
111
|
+
* The worker counterpart of `startGlspServer`,
|
|
112
|
+
* and deliberately a separate function rather than a mode of it. The two share
|
|
113
|
+
* a shape — app module, framework overrides, adopter modules, resolve launcher,
|
|
114
|
+
* configure the {@link ServerModule}, start — and almost nothing else: a
|
|
115
|
+
* different launcher, a different upstream `createAppModule` whose options carry
|
|
116
|
+
* no `fileLog`, and no `'listening'` event to resolve readiness on. Over half of
|
|
117
|
+
* the socket options are meaningless here, so threading a flag would leave a
|
|
118
|
+
* function whose contract depends on which branch the caller is in.
|
|
119
|
+
*
|
|
120
|
+
* Returns an {@link IntegratedServer} — the socket variant's `port` is the one
|
|
121
|
+
* member a worker head has no answer for, so it is absent rather than
|
|
122
|
+
* `undefined`.
|
|
123
|
+
*
|
|
124
|
+
* - `started` resolves once the launcher has built its connection and the
|
|
125
|
+
* server instance behind it, which is CHECKED rather than assumed — see
|
|
126
|
+
* below. There is no transport handshake to wait on: the port arrived live,
|
|
127
|
+
* and the launcher's own readiness signal is a string it posts on the worker
|
|
128
|
+
* global, which nothing here reads.
|
|
129
|
+
* - `stopped` resolves when the connection closes, and rejects on a connection
|
|
130
|
+
* error.
|
|
131
|
+
*/
|
|
132
|
+
export function startGlspServerInWorker(options: BrowserGlspServerOptions): IntegratedServer {
|
|
133
|
+
const lifecycle = options.logger;
|
|
134
|
+
|
|
135
|
+
// GLSP's own app module first, as on Node, so the framework tracks the
|
|
136
|
+
// resolved GLSP version's app bindings instead of re-deriving them. This is
|
|
137
|
+
// the BROWSER build's `createAppModule`, whose options are `LoggerConfigOptions`
|
|
138
|
+
// — no `fileLog`, because there is no file to log to. `consoleLog` is forced
|
|
139
|
+
// off so GLSP binds a throwaway NullLogger; the overrides below replace it
|
|
140
|
+
// with the adopter's, which is also why no log level is passed here: with
|
|
141
|
+
// `consoleLog` off, GLSP discards it, and the binding it would have
|
|
142
|
+
// configured is unbound a line later.
|
|
143
|
+
const glspAppModule = createAppModule({ consoleLog: false });
|
|
144
|
+
|
|
145
|
+
const appContainer = new Container();
|
|
146
|
+
appContainer.load(glspAppModule, createGlspFrameworkOverrides(options.createLogger), ...(options.appModules ?? []));
|
|
147
|
+
|
|
148
|
+
const launcher = appContainer.resolve<WorkerServerLauncher>(WorkerServerLauncher);
|
|
149
|
+
// Additional module rather than an app-container binding, as on Node: the
|
|
150
|
+
// launcher loads these into the per-connection SERVER container, the only
|
|
151
|
+
// tier where the adopter's `ServerModule` binding of `GLSPServer` is
|
|
152
|
+
// rebindable.
|
|
153
|
+
launcher.configure(options.serverModule, createGlspServerOverrides());
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
// Upstream declares `WorkerLaunchOptions.context` as `Worker`, narrower
|
|
157
|
+
// than the `MessagePort | Worker | DedicatedWorkerGlobalScope` its own
|
|
158
|
+
// `BrowserMessageReader` accepts — so the value that is CORRECT here is
|
|
159
|
+
// the one the declaration names as wrong.
|
|
160
|
+
//
|
|
161
|
+
// **The cast is currently redundant, and is kept deliberately.** `Worker`
|
|
162
|
+
// does not resolve under this package's `lib`, so `skipLibCheck` leaves
|
|
163
|
+
// the option an error type and the assignment compiles without it —
|
|
164
|
+
// measured, not assumed. Removing it would mean this file type-checks by
|
|
165
|
+
// the same accident that let upstream's own `?? self` default pass, and
|
|
166
|
+
// would break the day the name resolves. The cast states the intent
|
|
167
|
+
// instead, and costs one line to do so.
|
|
168
|
+
const launchOptions = { context: options.context } as unknown as WorkerLaunchOptions;
|
|
169
|
+
// `start` resolves only when the connection closes, so it is the `stopped`
|
|
170
|
+
// promise. The launcher builds the connection and the server instance
|
|
171
|
+
// synchronously before returning it, which is what makes "we got here"
|
|
172
|
+
// equal to "accepting traffic".
|
|
173
|
+
const stoppedPromise = Promise.resolve(launcher.start(launchOptions));
|
|
174
|
+
// Attached here and not left to the caller: a worker has no console
|
|
175
|
+
// anyone is watching, so a connection error on a `stopped` nobody awaits
|
|
176
|
+
// becomes an unhandled rejection that reaches no one. The handler also
|
|
177
|
+
// marks the promise handled, which the caller's own `await` still sees.
|
|
178
|
+
stoppedPromise.catch((error: unknown) => lifecycle?.error('[GlspServer] Worker connection error:', error));
|
|
179
|
+
|
|
180
|
+
// The `started`-equals-synchronous-construction assumption above is
|
|
181
|
+
// upstream's, so it is verified rather than trusted: `run` awaiting
|
|
182
|
+
// anything before building the connection would leave `started` resolving
|
|
183
|
+
// on a head that cannot yet answer, and a client's first request would
|
|
184
|
+
// hang with nothing logged. The field is `protected`, reached by property
|
|
185
|
+
// indexing as the socket launcher's `netServer` is.
|
|
186
|
+
const connection = (launcher as unknown as { connection?: unknown }).connection;
|
|
187
|
+
if (connection === undefined) {
|
|
188
|
+
const error = new Error(
|
|
189
|
+
'startGlspServerInWorker: the launcher built no connection synchronously — ' +
|
|
190
|
+
'WorkerServerLauncher.run has become asynchronous and readiness now needs a real signal'
|
|
191
|
+
);
|
|
192
|
+
lifecycle?.error(`[GlspServer] ${error.message}`);
|
|
193
|
+
return { started: Promise.reject(error), stopped: stoppedPromise };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
lifecycle?.info('[GlspServer] Ready to accept client requests on the transferred port');
|
|
197
|
+
return { started: Promise.resolve(), stopped: stoppedPromise };
|
|
198
|
+
} catch (error) {
|
|
199
|
+
lifecycle?.error('Error in GLSP server worker launcher:', error);
|
|
200
|
+
return { started: Promise.reject(error), stopped: Promise.resolve() };
|
|
201
|
+
}
|
|
202
|
+
}
|