@hydranium/core 1.0.0-next.385 → 1.0.0-next.387
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/lib/documents/model-ledger.d.ts +1 -1
- package/lib/documents/model-ledger.d.ts.map +1 -1
- package/lib/langium/document-builder/document-builder.d.ts +22 -1
- package/lib/langium/document-builder/document-builder.d.ts.map +1 -1
- package/lib/langium/document-builder/document-builder.js +45 -3
- package/lib/langium/document-builder/document-builder.js.map +1 -1
- package/lib/langium/module.js +3 -3
- package/lib/langium/module.js.map +1 -1
- package/lib/langium/residency/cst-residency-service.d.ts +13 -10
- package/lib/langium/residency/cst-residency-service.d.ts.map +1 -1
- package/lib/langium/residency/cst-residency-service.js +19 -19
- package/lib/langium/residency/cst-residency-service.js.map +1 -1
- package/lib/langium/workspace/hydranium-langium-document-factory.d.ts +44 -4
- package/lib/langium/workspace/hydranium-langium-document-factory.d.ts.map +1 -1
- package/lib/langium/workspace/hydranium-langium-document-factory.js +115 -9
- package/lib/langium/workspace/hydranium-langium-document-factory.js.map +1 -1
- package/lib/node/event-loop-monitor.d.ts.map +1 -1
- package/lib/node/event-loop-monitor.js +1 -1
- package/lib/node/event-loop-monitor.js.map +1 -1
- package/lib/node/server-state-snapshot.d.ts +5 -3
- package/lib/node/server-state-snapshot.d.ts.map +1 -1
- package/lib/node/server-state-snapshot.js +16 -13
- package/lib/node/server-state-snapshot.js.map +1 -1
- package/package.json +5 -5
- package/src/documents/model-ledger.ts +1 -1
- package/src/langium/document-builder/document-builder.ts +50 -3
- package/src/langium/module.ts +3 -3
- package/src/langium/residency/cst-residency-service.ts +20 -21
- package/src/langium/workspace/hydranium-langium-document-factory.ts +136 -8
- package/src/node/event-loop-monitor.ts +1 -3
- package/src/node/server-state-snapshot.ts +22 -13
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
|
-
import { type AstNode, DefaultLangiumDocumentFactory, type LangiumDocument, type Mutable, type ParseResult, type URI } from '@hydranium/langium';
|
|
9
|
+
import { type AstNode, type AstReflection, DefaultLangiumDocumentFactory, type LangiumDocument, type Linker, type MultiReference, type Mutable, type ParseResult, type Reference, type ReferenceInfo, type URI } from '@hydranium/langium';
|
|
10
10
|
import { type CancellationToken } from 'vscode-languageserver-protocol';
|
|
11
11
|
import { type TextDocument } from 'vscode-languageserver-textdocument';
|
|
12
12
|
import { type ModelLedger } from '../../documents/model-ledger.js';
|
|
@@ -27,10 +27,18 @@ import { type ServerSharedServicesMinimal } from '../shared-services.js';
|
|
|
27
27
|
* scope descriptions pointing at them, stay valid. A `fromString` document
|
|
28
28
|
* already carries its source, so only `fromModel` needs help.
|
|
29
29
|
*
|
|
30
|
+
* The first build grafts the CST of that text onto the model, as for a shed
|
|
31
|
+
* document, which gives every reference the `$refNode` the reference index
|
|
32
|
+
* needs. A model that does not pair node for node with its serialized text is
|
|
33
|
+
* re-parsed instead, and its nodes are replaced: from its file, or from the
|
|
34
|
+
* text it holds when no file is at its URI, since reading the URI would throw.
|
|
35
|
+
* While the document is open, the store's text wins.
|
|
36
|
+
*
|
|
30
37
|
* Degrades to Langium's text-less `fromModel` when no serializer is bound for
|
|
31
|
-
* the URI's language (the serializer throws or is absent)
|
|
32
|
-
*
|
|
33
|
-
*
|
|
38
|
+
* the URI's language (the serializer throws or is absent). Its first build
|
|
39
|
+
* re-reads it from the store or its file, replacing its nodes, as Langium
|
|
40
|
+
* does. With neither, it keeps its nodes but gets no CST, so its references
|
|
41
|
+
* stay out of the reference index and it is not relinked.
|
|
34
42
|
*
|
|
35
43
|
* Also links the model's container properties (`$container` /
|
|
36
44
|
* `$containerProperty` / `$containerIndex`), which Langium's parser sets via
|
|
@@ -53,6 +61,9 @@ export declare class HydraniumLangiumDocumentFactory extends DefaultLangiumDocum
|
|
|
53
61
|
protected readonly modelLedger: () => ModelLedger;
|
|
54
62
|
/** A thunk: the residency service resolves `LangiumDocuments`, which is built with this factory. */
|
|
55
63
|
protected readonly cstResidency: () => CstResidencyService;
|
|
64
|
+
/** The code-built documents, which are re-read from the text they hold when no file is at their URI. */
|
|
65
|
+
protected readonly codeBuiltDocuments: WeakSet<LangiumDocument<AstNode>>;
|
|
66
|
+
protected readonly astReflection: AstReflection;
|
|
56
67
|
constructor(services: ServerSharedServicesMinimal);
|
|
57
68
|
/**
|
|
58
69
|
* Parse `text` for `uri` under the grammar `languageId` names, instead of
|
|
@@ -73,6 +84,16 @@ export declare class HydraniumLangiumDocumentFactory extends DefaultLangiumDocum
|
|
|
73
84
|
*/
|
|
74
85
|
fromStringInLanguage<T extends AstNode = AstNode>(text: string, uri: URI, languageId: string): LangiumDocument<T>;
|
|
75
86
|
fromModel<T extends AstNode = AstNode>(model: T, uri: URI): LangiumDocument<T>;
|
|
87
|
+
/**
|
|
88
|
+
* Replace a code-set reference with one the linker built, holding the same
|
|
89
|
+
* target. A relink resets and the reference index reads only such
|
|
90
|
+
* references, and only those listed in `document.references`. The first
|
|
91
|
+
* build unlinks them before its link phase, which resolves and indexes them.
|
|
92
|
+
* The target is kept in the field Langium's references hold it in, so a
|
|
93
|
+
* linker whose references have no such field resolves it on first read.
|
|
94
|
+
* `undefined` when the reference has no slot to go back in.
|
|
95
|
+
*/
|
|
96
|
+
protected rebuildReference(linker: Linker, { reference, container, property, index }: ReferenceInfo): Reference | MultiReference | undefined;
|
|
76
97
|
protected createLangiumDocument<T extends AstNode = AstNode>(parseResult: ParseResult<T>, uri: URI, textDocument?: TextDocument, text?: string): LangiumDocument<T>;
|
|
77
98
|
/**
|
|
78
99
|
* The version is read before the parse, for the same reason as in
|
|
@@ -89,6 +110,25 @@ export declare class HydraniumLangiumDocumentFactory extends DefaultLangiumDocum
|
|
|
89
110
|
* a cancel skips, leaving the root on the version of its earlier text.
|
|
90
111
|
*/
|
|
91
112
|
update<T extends AstNode = AstNode>(document: Mutable<LangiumDocument<T>>, cancellationToken: CancellationToken): Promise<LangiumDocument<T>>;
|
|
113
|
+
/**
|
|
114
|
+
* The text a code-built document is read from when no file is at its URI:
|
|
115
|
+
* the store's while it is open, else the text it holds, serialized at
|
|
116
|
+
* creation or last read, as `VirtualFileSystemProvider` serves it.
|
|
117
|
+
* `undefined` for any other document, which is read as Langium reads it.
|
|
118
|
+
* The store's version is read with its text, since an edit can land
|
|
119
|
+
* before the caller resumes. Held text has no version.
|
|
120
|
+
*/
|
|
121
|
+
protected codeBuiltSource(document: LangiumDocument): Promise<{
|
|
122
|
+
text: string;
|
|
123
|
+
version: number | undefined;
|
|
124
|
+
} | undefined>;
|
|
125
|
+
/**
|
|
126
|
+
* Langium's `update` with `text` in place of the text it reads from the
|
|
127
|
+
* store or the URI. Mirrors `DefaultLangiumDocumentFactory.update` of
|
|
128
|
+
* Langium 4.3.1, so a Langium upgrade has to compare the two. From
|
|
129
|
+
* Langium 4.4, an override of `getUpdatedText` replaces it.
|
|
130
|
+
*/
|
|
131
|
+
protected reparse<T extends AstNode = AstNode>(document: Mutable<LangiumDocument<T>>, text: string, cancellationToken: CancellationToken): Promise<LangiumDocument<T>>;
|
|
92
132
|
/**
|
|
93
133
|
* `version`, or {@link STALE_VERSION} when the store holds `uri` open with
|
|
94
134
|
* other text than `parsed`: text read from the file while an open landed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydranium-langium-document-factory.d.ts","sourceRoot":"","sources":["../../../src/langium/workspace/hydranium-langium-document-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EACJ,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"hydranium-langium-document-factory.d.ts","sourceRoot":"","sources":["../../../src/langium/workspace/hydranium-langium-document-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EACJ,KAAK,OAAO,EACZ,KAAK,aAAa,EAElB,6BAA6B,EAI7B,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,cAAc,EAC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AAG,OAAO,EAChD,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EACrC,IAAI,EAAE,MAAM,EACZ,iBAAiB,EAAE,iBAAiB,GACpC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAa7B;IAED;;;OAGG;IACH,SAAS,CAAC,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG3F;IAED;;;;OAIG;IACH,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAQrE;CACH"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
|
-
import { AstUtils, DefaultLangiumDocumentFactory } from '@hydranium/langium';
|
|
9
|
+
import { AstUtils, DefaultLangiumDocumentFactory, DocumentState, isAstNode, isMultiReference } from '@hydranium/langium';
|
|
10
10
|
import { STALE_VERSION } from '@hydranium/protocol';
|
|
11
11
|
/**
|
|
12
12
|
* Framework `LangiumDocumentFactory` that fills in the one thing Langium
|
|
@@ -21,10 +21,18 @@ import { STALE_VERSION } from '@hydranium/protocol';
|
|
|
21
21
|
* scope descriptions pointing at them, stay valid. A `fromString` document
|
|
22
22
|
* already carries its source, so only `fromModel` needs help.
|
|
23
23
|
*
|
|
24
|
+
* The first build grafts the CST of that text onto the model, as for a shed
|
|
25
|
+
* document, which gives every reference the `$refNode` the reference index
|
|
26
|
+
* needs. A model that does not pair node for node with its serialized text is
|
|
27
|
+
* re-parsed instead, and its nodes are replaced: from its file, or from the
|
|
28
|
+
* text it holds when no file is at its URI, since reading the URI would throw.
|
|
29
|
+
* While the document is open, the store's text wins.
|
|
30
|
+
*
|
|
24
31
|
* Degrades to Langium's text-less `fromModel` when no serializer is bound for
|
|
25
|
-
* the URI's language (the serializer throws or is absent)
|
|
26
|
-
*
|
|
27
|
-
*
|
|
32
|
+
* the URI's language (the serializer throws or is absent). Its first build
|
|
33
|
+
* re-reads it from the store or its file, replacing its nodes, as Langium
|
|
34
|
+
* does. With neither, it keeps its nodes but gets no CST, so its references
|
|
35
|
+
* stay out of the reference index and it is not relinked.
|
|
28
36
|
*
|
|
29
37
|
* Also links the model's container properties (`$container` /
|
|
30
38
|
* `$containerProperty` / `$containerIndex`), which Langium's parser sets via
|
|
@@ -41,8 +49,12 @@ export class HydraniumLangiumDocumentFactory extends DefaultLangiumDocumentFacto
|
|
|
41
49
|
modelLedger;
|
|
42
50
|
/** A thunk: the residency service resolves `LangiumDocuments`, which is built with this factory. */
|
|
43
51
|
cstResidency;
|
|
52
|
+
/** The code-built documents, which are re-read from the text they hold when no file is at their URI. */
|
|
53
|
+
codeBuiltDocuments = new WeakSet();
|
|
54
|
+
astReflection;
|
|
44
55
|
constructor(services) {
|
|
45
56
|
super(services);
|
|
57
|
+
this.astReflection = services.AstReflection;
|
|
46
58
|
this.versionSyncService = () => services.workspace.VersionSyncService;
|
|
47
59
|
this.modelLedger = () => services.workspace.ModelLedger;
|
|
48
60
|
this.cstResidency = () => services.workspace.CstResidencyService;
|
|
@@ -76,19 +88,75 @@ export class HydraniumLangiumDocumentFactory extends DefaultLangiumDocumentFacto
|
|
|
76
88
|
// Make the code-built AST as structurally complete as a parsed one — the
|
|
77
89
|
// parser links containers, `fromModel` does not. In place (identity kept).
|
|
78
90
|
AstUtils.linkContentToContainer(model, { deep: true });
|
|
91
|
+
// The parser fills in the defaults a model built in code may leave out.
|
|
92
|
+
// Filled before serializing, since a serializer may read them, and
|
|
93
|
+
// without them the model does not pair with the parse of its text.
|
|
94
|
+
for (const node of AstUtils.streamAst(model)) {
|
|
95
|
+
AstUtils.assignMandatoryProperties(this.astReflection, node);
|
|
96
|
+
}
|
|
79
97
|
const text = this.serializeModel(model, uri);
|
|
80
98
|
if (text === undefined) {
|
|
81
99
|
return super.fromModel(model, uri);
|
|
82
100
|
}
|
|
83
101
|
const parseResult = { value: model, parserErrors: [], lexerErrors: [] };
|
|
84
|
-
|
|
102
|
+
const document = this.createLangiumDocument(parseResult, uri, undefined, text);
|
|
103
|
+
this.codeBuiltDocuments.add(document);
|
|
104
|
+
const linker = this.serviceRegistry.getServices(uri).references.Linker;
|
|
105
|
+
document.references = AstUtils.streamAst(model)
|
|
106
|
+
.flatMap(node => AstUtils.streamReferences(node))
|
|
107
|
+
.toArray()
|
|
108
|
+
.flatMap(info => this.rebuildReference(linker, info) ?? []);
|
|
109
|
+
return document;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Replace a code-set reference with one the linker built, holding the same
|
|
113
|
+
* target. A relink resets and the reference index reads only such
|
|
114
|
+
* references, and only those listed in `document.references`. The first
|
|
115
|
+
* build unlinks them before its link phase, which resolves and indexes them.
|
|
116
|
+
* The target is kept in the field Langium's references hold it in, so a
|
|
117
|
+
* linker whose references have no such field resolves it on first read.
|
|
118
|
+
* `undefined` when the reference has no slot to go back in.
|
|
119
|
+
*/
|
|
120
|
+
rebuildReference(linker, { reference, container, property, index }) {
|
|
121
|
+
const owner = Reflect.get(container, property);
|
|
122
|
+
if (index !== undefined && !Array.isArray(owner)) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
let rebuilt;
|
|
126
|
+
if (isMultiReference(reference)) {
|
|
127
|
+
// Read through the field, as `items` would resolve a linker-built reference.
|
|
128
|
+
const items = '_items' in reference ? reference._items : reference.items;
|
|
129
|
+
const multi = linker.buildMultiReference(container, property, reference.$refNode, reference.$refText);
|
|
130
|
+
if ('_items' in multi) {
|
|
131
|
+
multi._items = Array.isArray(items) ? [...items] : undefined;
|
|
132
|
+
}
|
|
133
|
+
rebuilt = multi;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const target = '_ref' in reference ? reference._ref : reference.ref;
|
|
137
|
+
const single = linker.buildReference(container, property, reference.$refNode, reference.$refText);
|
|
138
|
+
if ('_ref' in single) {
|
|
139
|
+
single._ref = isAstNode(target) ? target : undefined;
|
|
140
|
+
}
|
|
141
|
+
rebuilt = single;
|
|
142
|
+
}
|
|
143
|
+
if (Array.isArray(owner) && index !== undefined) {
|
|
144
|
+
owner[index] = rebuilt;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
Reflect.set(container, property, rebuilt);
|
|
148
|
+
}
|
|
149
|
+
return rebuilt;
|
|
85
150
|
}
|
|
86
151
|
createLangiumDocument(parseResult, uri, textDocument, text) {
|
|
87
152
|
const document = super.createLangiumDocument(parseResult, uri, textDocument, text);
|
|
88
153
|
// Without `textDocument` Langium creates one at version 0 on first read,
|
|
89
154
|
// which needs a language for `uri` that a folder URI does not have.
|
|
90
155
|
const parsed = parseResult.value.$cstNode?.root.fullText ?? text ?? textDocument?.getText();
|
|
91
|
-
|
|
156
|
+
const version = this.versionOfParsedText(uri, parsed, textDocument?.version ?? 0);
|
|
157
|
+
// A `fromModel` root has no CST to hold its serialized text. Recorded, it
|
|
158
|
+
// is the text a build grafts a CST from, keeping the model's nodes.
|
|
159
|
+
this.versionSyncService().modelProduced(document, { version, text: parseResult.value.$cstNode ? undefined : text });
|
|
92
160
|
return document;
|
|
93
161
|
}
|
|
94
162
|
/**
|
|
@@ -123,8 +191,11 @@ export class HydraniumLangiumDocumentFactory extends DefaultLangiumDocumentFacto
|
|
|
123
191
|
// documents, and a reset now would drop their build state.
|
|
124
192
|
const root = document.parseResult.value;
|
|
125
193
|
const parsedFrom = root.$cstNode === undefined ? this.modelLedger().textOf(root) : undefined;
|
|
194
|
+
const codeBuilt = await this.codeBuiltSource(document);
|
|
126
195
|
if (parsedFrom !== undefined) {
|
|
127
|
-
const text =
|
|
196
|
+
const text = codeBuilt?.text ??
|
|
197
|
+
this.textDocuments?.get(document.uri.toString())?.getText() ??
|
|
198
|
+
(await this.fileSystemProvider.readFile(document.uri));
|
|
128
199
|
if (text === parsedFrom) {
|
|
129
200
|
this.cstResidency().rehydrate(document);
|
|
130
201
|
if (root.$cstNode === undefined) {
|
|
@@ -132,13 +203,48 @@ export class HydraniumLangiumDocumentFactory extends DefaultLangiumDocumentFacto
|
|
|
132
203
|
}
|
|
133
204
|
}
|
|
134
205
|
}
|
|
135
|
-
const stored = this.textDocuments?.get(document.uri.toString())?.version;
|
|
136
|
-
const updated =
|
|
206
|
+
const stored = codeBuilt === undefined ? this.textDocuments?.get(document.uri.toString())?.version : codeBuilt.version;
|
|
207
|
+
const updated = codeBuilt === undefined
|
|
208
|
+
? await super.update(document, cancellationToken)
|
|
209
|
+
: await this.reparse(document, codeBuilt.text, cancellationToken);
|
|
137
210
|
const version = stored ??
|
|
138
211
|
this.versionOfParsedText(updated.uri, this.modelLedger().textOf(updated.parseResult.value) ?? updated.textDocument.getText(), updated.textDocument.version);
|
|
139
212
|
this.versionSyncService().modelProduced(updated, { version });
|
|
140
213
|
return updated;
|
|
141
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* The text a code-built document is read from when no file is at its URI:
|
|
217
|
+
* the store's while it is open, else the text it holds, serialized at
|
|
218
|
+
* creation or last read, as `VirtualFileSystemProvider` serves it.
|
|
219
|
+
* `undefined` for any other document, which is read as Langium reads it.
|
|
220
|
+
* The store's version is read with its text, since an edit can land
|
|
221
|
+
* before the caller resumes. Held text has no version.
|
|
222
|
+
*/
|
|
223
|
+
async codeBuiltSource(document) {
|
|
224
|
+
if (!this.codeBuiltDocuments.has(document) || (await this.fileSystemProvider.exists(document.uri))) {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
const open = this.textDocuments?.get(document.uri.toString());
|
|
228
|
+
return open === undefined
|
|
229
|
+
? { text: document.textDocument.getText(), version: undefined }
|
|
230
|
+
: { text: open.getText(), version: open.version };
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Langium's `update` with `text` in place of the text it reads from the
|
|
234
|
+
* store or the URI. Mirrors `DefaultLangiumDocumentFactory.update` of
|
|
235
|
+
* Langium 4.3.1, so a Langium upgrade has to compare the two. From
|
|
236
|
+
* Langium 4.4, an override of `getUpdatedText` replaces it.
|
|
237
|
+
*/
|
|
238
|
+
async reparse(document, text, cancellationToken) {
|
|
239
|
+
const textDocument = this.textDocuments?.get(document.uri.toString());
|
|
240
|
+
Object.defineProperty(document, 'textDocument', textDocument ? { value: textDocument } : { get: this.createTextDocumentGetter(document.uri, text) });
|
|
241
|
+
if (document.parseResult.value.$cstNode?.root.fullText !== text) {
|
|
242
|
+
document.parseResult = await this.parseAsync(document.uri, text, cancellationToken);
|
|
243
|
+
document.parseResult.value.$document = document;
|
|
244
|
+
}
|
|
245
|
+
document.state = DocumentState.Parsed;
|
|
246
|
+
return document;
|
|
247
|
+
}
|
|
142
248
|
/**
|
|
143
249
|
* `version`, or {@link STALE_VERSION} when the store holds `uri` open with
|
|
144
250
|
* other text than `parsed`: text read from the file while an open landed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydranium-langium-document-factory.js","sourceRoot":"","sources":["../../../src/langium/workspace/hydranium-langium-document-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,
|
|
1
|
+
{"version":3,"file":"hydranium-langium-document-factory.js","sourceRoot":"","sources":["../../../src/langium/workspace/hydranium-langium-document-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAGJ,QAAQ,EACR,6BAA6B,EAC7B,aAAa,EACb,SAAS,EACT,gBAAgB,EASlB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAapD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,OAAO,+BAAgC,SAAQ,6BAA6B;IAQ/E,uGAAuG;IACpF,kBAAkB,CAA2B;IAChE,yFAAyF;IACtE,WAAW,CAAoB;IAClD,oGAAoG;IACjF,YAAY,CAA4B;IAC3D,wG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version":3,"file":"event-loop-monitor.d.ts","sourceRoot":"","sources":["../../src/node/event-loop-monitor.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAKlF,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAGjF,eAAO,MAAM,+BAA+B,MAAM,CAAC;AACnD,eAAO,MAAM,8BAA8B,OAAO,CAAC;AACnD,eAAO,MAAM,oCAAoC,MAAM,CAAC;AAExD,MAAM,WAAW,uBAAuB;IACrC,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,2BAA2B,EAAE,OAAO,GAAE,uBAA4B,GAAG,MAAM,IAAI,CAyC5H"}
|
|
@@ -27,7 +27,7 @@ export function startEventLoopMonitor(shared, options = {}) {
|
|
|
27
27
|
const intervalMs = options.intervalMs ?? DEFAULT_EVENT_LOOP_INTERVAL_MS;
|
|
28
28
|
const snapshotAboveMs = options.snapshotAboveMs ?? DEFAULT_EVENT_LOOP_SNAPSHOT_ABOVE_MS;
|
|
29
29
|
const onStallSnapshot = options.onStallSnapshot ??
|
|
30
|
-
((maxMs) => shared.Logger.for('Process').info(formatServerState(shared.workspace
|
|
30
|
+
((maxMs) => shared.Logger.for('Process').info(formatServerState(shared.workspace, `auto: event-loop stall ${Math.round(maxMs)}ms`)));
|
|
31
31
|
const histogram = monitorEventLoopDelay({ resolution: 10 });
|
|
32
32
|
histogram.enable();
|
|
33
33
|
const interval = setInterval(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-loop-monitor.js","sourceRoot":"","sources":["../../src/node/event-loop-monitor.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,CAAC;AACnD,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AACnD,MAAM,CAAC,MAAM,oCAAoC,GAAG,GAAG,CAAC;AAqBxD;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAmC,EAAE,OAAO,GAA4B,EAAE;IAC7G,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,WAAW,CAAC,CAAC;IACjE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,+BAA+B,CAAC;IAC3E,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,8BAA8B,CAAC;IACxE,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,oCAAoC,CAAC;IACxF,MAAM,eAAe,GAClB,OAAO,CAAC,eAAe;QACvB,CAAC,CAAC,KAAa,EAAE,EAAE,CAChB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"event-loop-monitor.js","sourceRoot":"","sources":["../../src/node/event-loop-monitor.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,YAAY,E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AAM,MAAM,GAAG,SAAS,CAAC,IAAI,GAAG,GAAG,CAAC;YACpC,oFAAoF;YACpF,MAAM,CAAC,IAAI,CACR,0BAA0B,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK;gBAC7C,WAAW,UAAU,KAAK;gBAC1B,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM;gBAC/B,QAAQ,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;gBAC/B,GAAG,YAAY,EAAE,GAAG,CACzB,CAAC;YACF,IAAI,KAAK,IAAI,eAAe,EAAE,CAAC;gBAC5B,4EAA4E;gBAC5E,IAAI,CAAC;oBACF,eAAe,CAAC,KAAK,CAAC,CAAC;gBAC1B,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACd,MAAM,CAAC,IAAI,CAAC,0BAA0B,sBAAsB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBAC1E,CAAC;YACJ,CAAC;QACJ,CAAC;QACD,SAAS,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC,EAAE,UAAU,CAAC,CAAC;IACf,wDAAwD;IACxD,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC;IACnB,OAAO,GAAG,EAAE;QACT,aAAa,CAAC,QAAQ,CAAC,CAAC;QACxB,SAAS,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
|
-
import { type
|
|
9
|
+
import { type ServerSharedServicesMinimal } from '../langium/shared-services.js';
|
|
10
10
|
/**
|
|
11
11
|
* A document held open by one or more clients, as reported by
|
|
12
12
|
* `HydraniumTextDocuments.openDocuments()` (whose `OpenDocument` entries are
|
|
@@ -41,7 +41,9 @@ export interface ServerStateSnapshotOptions {
|
|
|
41
41
|
* logs the result, e.g. `tracer.info(formatServerState(...))`), matching
|
|
42
42
|
* `formatProcessMemory` / `formatPodMemory`. Tracks deltas across calls so
|
|
43
43
|
* subsequent snapshots show "since last snapshot" rates. Optional sections are
|
|
44
|
-
* requested via `options` ({@link ServerStateSnapshotOptions}).
|
|
44
|
+
* requested via `options` ({@link ServerStateSnapshotOptions}). `workspace`
|
|
45
|
+
* adds the document counts. Its ledger tells a shed document from one that
|
|
46
|
+
* never had a CST.
|
|
45
47
|
*/
|
|
46
|
-
export declare function formatServerState(
|
|
48
|
+
export declare function formatServerState(workspace?: Pick<ServerSharedServicesMinimal['workspace'], 'LangiumDocuments' | 'ModelLedger'>, label?: string, options?: ServerStateSnapshotOptions): string;
|
|
47
49
|
//# sourceMappingURL=server-state-snapshot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-state-snapshot.d.ts","sourceRoot":"","sources":["../../src/node/server-state-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;
|
|
1
|
+
{"version":3,"file":"server-state-snapshot.d.ts","sourceRoot":"","sources":["../../src/node/server-state-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAKlF,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAajF;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,2EAA2E;AAC3E,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAElD,yDAAyD;AACzD,MAAM,WAAW,0BAA0B;IACxC;;;;;;OAMG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACtD;;;OAGG;IACH,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CACzC;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC9B,SAAS,CAAC,EAAE,IAAI,CAAC,2BAA2B,CAAC,WAAW,CAAC,EAAE,kBAAkB,GAAG,aAAa,CAAC,EAC9F,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,0BAA0B,GACpC,MAAM,CAgFR"}
|
|
@@ -20,9 +20,11 @@ export const DEFAULT_OPEN_DOCUMENTS_LIST_CAP = 25;
|
|
|
20
20
|
* logs the result, e.g. `tracer.info(formatServerState(...))`), matching
|
|
21
21
|
* `formatProcessMemory` / `formatPodMemory`. Tracks deltas across calls so
|
|
22
22
|
* subsequent snapshots show "since last snapshot" rates. Optional sections are
|
|
23
|
-
* requested via `options` ({@link ServerStateSnapshotOptions}).
|
|
23
|
+
* requested via `options` ({@link ServerStateSnapshotOptions}). `workspace`
|
|
24
|
+
* adds the document counts. Its ledger tells a shed document from one that
|
|
25
|
+
* never had a CST.
|
|
24
26
|
*/
|
|
25
|
-
export function formatServerState(
|
|
27
|
+
export function formatServerState(workspace, label, options) {
|
|
26
28
|
const sinceSample = new SystemClock().stopwatch();
|
|
27
29
|
const mem = process.memoryUsage();
|
|
28
30
|
const heap = v8.getHeapStatistics();
|
|
@@ -60,7 +62,8 @@ export function formatServerState(documents, label, options) {
|
|
|
60
62
|
const eluPct = eluTotal > 0 ? Math.round((elu.active / eluTotal) * 100) : 0;
|
|
61
63
|
lines.push(` loop utilization ${eluPct}% (cumulative since process start)`);
|
|
62
64
|
}
|
|
63
|
-
if (
|
|
65
|
+
if (workspace) {
|
|
66
|
+
const { LangiumDocuments: documents, ModelLedger: ledger } = workspace;
|
|
64
67
|
const counts = countDocumentsByState(documents);
|
|
65
68
|
const total = Object.values(counts).reduce((sum, n) => sum + n, 0);
|
|
66
69
|
const breakdown = Object.entries(counts)
|
|
@@ -68,9 +71,9 @@ export function formatServerState(documents, label, options) {
|
|
|
68
71
|
.map(([state, n]) => `${state}: ${n}`)
|
|
69
72
|
.join(', ');
|
|
70
73
|
lines.push(` documents ${total} tracked${breakdown ? ` (${breakdown})` : ''}`);
|
|
71
|
-
// CST-residency breakdown
|
|
72
|
-
//
|
|
73
|
-
const residency = countCstResidency(documents);
|
|
74
|
+
// CST-residency breakdown, emitted once a document waits for a CST graft:
|
|
75
|
+
// shed by a residency policy, or built from code and not built yet.
|
|
76
|
+
const residency = countCstResidency(documents, ledger);
|
|
74
77
|
if (residency.shed > 0) {
|
|
75
78
|
lines.push(` cst ${residency.resident} resident, ${residency.shed} shed`);
|
|
76
79
|
}
|
|
@@ -91,17 +94,17 @@ export function formatServerState(documents, label, options) {
|
|
|
91
94
|
}
|
|
92
95
|
/**
|
|
93
96
|
* Count documents whose CST is resident vs. shed by a residency policy
|
|
94
|
-
* ({@link isCstShed}). A document can also be in neither bucket
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* on the preceding `documents` line.
|
|
97
|
+
* ({@link isCstShed}). A document can also be in neither bucket: a
|
|
98
|
+
* not-yet-parsed document, a synthetic placeholder, or a `fromModel` document
|
|
99
|
+
* without a serializer has no CST and no text to graft one from. So
|
|
100
|
+
* `resident + shed` is at most the total tracked, with the remainder explained
|
|
101
|
+
* by the state breakdown on the preceding `documents` line.
|
|
99
102
|
*/
|
|
100
|
-
function countCstResidency(documents) {
|
|
103
|
+
function countCstResidency(documents, ledger) {
|
|
101
104
|
let resident = 0;
|
|
102
105
|
let shed = 0;
|
|
103
106
|
for (const doc of documents.all) {
|
|
104
|
-
if (isCstShed(doc)) {
|
|
107
|
+
if (isCstShed(doc, ledger)) {
|
|
105
108
|
shed++;
|
|
106
109
|
}
|
|
107
110
|
else if (doc.parseResult?.value?.$cstNode !== undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-state-snapshot.js","sourceRoot":"","sources":["../../src/node/server-state-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,MAAM,EAAkB,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAyB,M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AM,GAAG,IAAI,SAAS,CAAC,GAAG,EAAE,CAAC;QAC/B,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,WAAW,GAAG,CAAC,KAAK,GAAG,CAAC;QACtE,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,MAAM,CAAC;AACjB,CAAC;AAED,SAAS,cAAc,CAAC,EAAU;IAC/B,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;QACb,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC;IAChC,CAAC;IACD,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,YAAY,GAAG,EAAE,CAAC;IAClC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,EAAE,CAAC,CAAC;IACnD,MAAM,OAAO,GAAG,YAAY,GAAG,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,EAAE,CAAC,CAAC;IAC5C,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACb,OAAO,GAAG,KAAK,KAAK,OAAO,KAAK,OAAO,GAAG,CAAC;IAC9C,CAAC;IACD,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QACf,OAAO,GAAG,OAAO,KAAK,OAAO,GAAG,CAAC;IACpC,CAAC;IACD,OAAO,GAAG,OAAO,GAAG,CAAC;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hydranium/core",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.387",
|
|
4
4
|
"description": "Foundational runtime of the hydranium framework: AST coordination layer (services, integrity, AST extension, serialization, multi-client documents) plus the LSP textual head at the /lsp subpath. Consumed by protocol-head packages (@hydranium/data-server, @hydranium/glsp-server).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast",
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"diff": "^5.2.0"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@hydranium/langium": "1.0.0-next.
|
|
91
|
-
"@hydranium/protocol": "1.0.0-next.
|
|
90
|
+
"@hydranium/langium": "1.0.0-next.387",
|
|
91
|
+
"@hydranium/protocol": "1.0.0-next.387",
|
|
92
92
|
"@playwright/test": "^1.55.0",
|
|
93
93
|
"@types/diff": "^5.2.0",
|
|
94
94
|
"fake-indexeddb": "^6.2.5",
|
|
@@ -101,8 +101,8 @@
|
|
|
101
101
|
"vscode-languageserver-types": "3.18.0"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
|
-
"@hydranium/langium": "1.0.0-next.
|
|
105
|
-
"@hydranium/protocol": "1.0.0-next.
|
|
104
|
+
"@hydranium/langium": "1.0.0-next.387",
|
|
105
|
+
"@hydranium/protocol": "1.0.0-next.387",
|
|
106
106
|
"@playwright/test": "^1.40.0",
|
|
107
107
|
"vscode-jsonrpc": "^9.0.0",
|
|
108
108
|
"vscode-languageserver": "~10.0.1",
|
|
@@ -13,7 +13,7 @@ import { asModelVersion, type ModelVersion, UNRECORDED_VERSION } from '@hydraniu
|
|
|
13
13
|
/** What {@link ModelLedger} holds for one root. */
|
|
14
14
|
export interface ModelRecord {
|
|
15
15
|
readonly version: ModelVersion;
|
|
16
|
-
/** For a root whose CST
|
|
16
|
+
/** For a root whose CST is not the text it describes: changed in place, shed, or built from code. */
|
|
17
17
|
readonly text?: string;
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
// restating it.
|
|
38
38
|
import { CancellationToken, Diagnostic, Disposable } from 'vscode-languageserver-protocol';
|
|
39
39
|
import type { HydraniumTextDocuments } from '../../documents/hydranium-text-documents.js';
|
|
40
|
+
import { type ModelLedger } from '../../documents/model-ledger.js';
|
|
40
41
|
import { type VersionSyncService } from '../../documents/version-sync-service.js';
|
|
41
42
|
import { type LogNameOptions } from '../diagnostics/logger.js';
|
|
42
43
|
import { IntegrityService } from '../integrity/integrity-service.js';
|
|
@@ -313,6 +314,7 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
313
314
|
protected readonly versionSyncService: () => VersionSyncService;
|
|
314
315
|
/** A thunk: a residency service whose constructor reads the builder would otherwise be a cycle. */
|
|
315
316
|
protected readonly cstResidency: () => CstResidencyService;
|
|
317
|
+
protected readonly modelLedger: ModelLedger;
|
|
316
318
|
|
|
317
319
|
constructor(services: ServerSharedServicesMinimal, options: DocumentBuilderOptions = {}) {
|
|
318
320
|
super(services);
|
|
@@ -323,6 +325,7 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
323
325
|
this.workspaceLock = services.workspace.WorkspaceLock;
|
|
324
326
|
this.versionSyncService = () => services.workspace.VersionSyncService;
|
|
325
327
|
this.cstResidency = () => services.workspace.CstResidencyService;
|
|
328
|
+
this.modelLedger = services.workspace.ModelLedger;
|
|
326
329
|
this.tracer = services.Tracer.for(options.logName ?? 'DocumentBuilder').trace('instantiated');
|
|
327
330
|
this.logLevel = options.logLevel ?? 'debug';
|
|
328
331
|
this.loggedPhases = options.loggedPhases ?? DEFAULT_LOGGED_PHASES;
|
|
@@ -933,6 +936,7 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
933
936
|
cancelToken: CancellationToken
|
|
934
937
|
): Promise<void> {
|
|
935
938
|
await this.rehydrateShedDocuments(documents, cancelToken);
|
|
939
|
+
this.unlinkPrelinkedReferences(documents);
|
|
936
940
|
await super.buildDocuments(documents, options, cancelToken);
|
|
937
941
|
this.notifyBuildEnded({ completed: true });
|
|
938
942
|
}
|
|
@@ -946,18 +950,61 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
946
950
|
* with a cancellation check between, as the parse phase does. A refused or
|
|
947
951
|
* diverged graft resets the document to `Changed`, so this build re-parses
|
|
948
952
|
* it, and asks for a build after this one, whose relink selection reaches
|
|
949
|
-
* its dependents as those of a changed document.
|
|
953
|
+
* its dependents as those of a changed document. A document without a CST
|
|
954
|
+
* or a text to graft one from is reset the same way when it can be re-read.
|
|
950
955
|
*/
|
|
951
956
|
protected async rehydrateShedDocuments(documents: LangiumDocument[], cancelToken: CancellationToken): Promise<void> {
|
|
952
957
|
for (const document of documents) {
|
|
953
|
-
if (document.state < DocumentState.Validated && isCstShed(document)) {
|
|
958
|
+
if (document.state < DocumentState.Validated && isCstShed(document, this.modelLedger)) {
|
|
954
959
|
await interruptAndCheck(cancelToken);
|
|
955
960
|
this.tracer.debug(`rehydrating CST of ${this.formatUri(document.uri)} (re-entered build while shed)`);
|
|
956
961
|
this.cstResidency().rehydrate(document);
|
|
957
|
-
if (isCstShed(document)) {
|
|
962
|
+
if (isCstShed(document, this.modelLedger)) {
|
|
958
963
|
this.resetToState(document, CST_REHYDRATION_RESET_STATE);
|
|
959
964
|
this.versionSyncService().rebuildWhileCurrent(document);
|
|
960
965
|
}
|
|
966
|
+
} else if (document.state < DocumentState.Validated && this.hasNoCstToGraft(document) && (await this.hasReadableText(document))) {
|
|
967
|
+
await interruptAndCheck(cancelToken);
|
|
968
|
+
this.tracer.debug(`re-reading ${this.formatUri(document.uri)} (re-entered build without a CST to graft)`);
|
|
969
|
+
this.resetToState(document, CST_REHYDRATION_RESET_STATE);
|
|
970
|
+
this.versionSyncService().rebuildWhileCurrent(document);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Whether `document` has an AST but no CST and no text to graft one from,
|
|
977
|
+
* as a `fromModel` document without a serializer has. Such a document is
|
|
978
|
+
* re-read when {@link hasReadableText}, so its references are indexed.
|
|
979
|
+
* Synchronous, so a build awaits nothing for a document with a CST.
|
|
980
|
+
*/
|
|
981
|
+
protected hasNoCstToGraft(document: LangiumDocument): boolean {
|
|
982
|
+
const root = document.parseResult?.value;
|
|
983
|
+
return (
|
|
984
|
+
document.state >= DocumentState.Parsed &&
|
|
985
|
+
root !== undefined &&
|
|
986
|
+
root.$cstNode === undefined &&
|
|
987
|
+
this.modelLedger.textOf(root) === undefined
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/** Whether the store or a file holds the text of `document`. Without either, reading it would fail. */
|
|
992
|
+
protected async hasReadableText(document: LangiumDocument): Promise<boolean> {
|
|
993
|
+
return this.textDocuments?.get(document.uri) !== undefined || (await this.fileSystemProvider.exists(document.uri));
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Unlink every document of the build that is below `Linked` but lists
|
|
998
|
+
* references, so the link phase resolves and indexes them. Such a document
|
|
999
|
+
* is mostly a code-built one, which holds the targets its code set until
|
|
1000
|
+
* its first build. Any other document had references resolved before its
|
|
1001
|
+
* link phase, by a cancelled build or a lazy read, and they are resolved
|
|
1002
|
+
* again.
|
|
1003
|
+
*/
|
|
1004
|
+
protected unlinkPrelinkedReferences(documents: LangiumDocument[]): void {
|
|
1005
|
+
for (const document of documents) {
|
|
1006
|
+
if (document.state < DocumentState.Linked && document.references.length > 0) {
|
|
1007
|
+
this.languageRegistry.getServices(document.uri).references.Linker.unlink(document);
|
|
961
1008
|
}
|
|
962
1009
|
}
|
|
963
1010
|
}
|
package/src/langium/module.ts
CHANGED
|
@@ -539,9 +539,9 @@ export function createServerSharedModule(
|
|
|
539
539
|
// language ids, so a section `lsp.configurationRoot` is bound to reads
|
|
540
540
|
// `undefined` forever with no request on the wire.
|
|
541
541
|
ConfigurationProvider: services => new HydraniumConfigurationProvider(services),
|
|
542
|
-
// Override Langium's factory so a `fromModel` (code-built)
|
|
543
|
-
//
|
|
544
|
-
//
|
|
542
|
+
// Override Langium's factory so a `fromModel` (code-built) document
|
|
543
|
+
// retains serialized text via the per-language Serializer, and is
|
|
544
|
+
// re-read from that text while no file is at its URI.
|
|
545
545
|
LangiumDocumentFactory: services => new HydraniumLangiumDocumentFactory(services),
|
|
546
546
|
// Langium's default routes through no identity seam and treats every
|
|
547
547
|
// failed load alike, so leaving this unbound opts a server out of both
|