@hydranium/core 1.0.0-next.356 → 1.0.0-next.357
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/langium/residency/cst-residency-service.d.ts +5 -3
- package/lib/langium/residency/cst-residency-service.d.ts.map +1 -1
- package/lib/langium/residency/cst-residency-service.js +4 -1
- package/lib/langium/residency/cst-residency-service.js.map +1 -1
- package/lib/langium/scope/ast-node-description-provider.d.ts +46 -10
- package/lib/langium/scope/ast-node-description-provider.d.ts.map +1 -1
- package/lib/langium/scope/ast-node-description-provider.js +88 -15
- package/lib/langium/scope/ast-node-description-provider.js.map +1 -1
- package/package.json +5 -5
- package/src/langium/residency/cst-residency-service.ts +9 -4
- package/src/langium/scope/ast-node-description-provider.ts +111 -16
|
@@ -90,8 +90,9 @@ export declare function isCstShed(document: LangiumDocument): boolean;
|
|
|
90
90
|
* the idle window of the documents in its batch; when a closed, sheddable
|
|
91
91
|
* document's window elapses, every AST node's `$cstNode` and every reference's
|
|
92
92
|
* `$refNode` are nulled, and the CST becomes unreachable with the `Range`s
|
|
93
|
-
* and `Position`s only it holds.
|
|
94
|
-
*
|
|
93
|
+
* and `Position`s only it holds. The reference index's segments, and a
|
|
94
|
+
* description's segments once read, share the CST's `Range` objects, so
|
|
95
|
+
* those stay.
|
|
95
96
|
*
|
|
96
97
|
* **Terminology.** *Residency* is the state axis (is the CST in memory? —
|
|
97
98
|
* `resident` vs `shed`); *shed* is both the act and the policy vocabulary (drop
|
|
@@ -142,7 +143,8 @@ export interface CstResidencyService {
|
|
|
142
143
|
/**
|
|
143
144
|
* Node-level convenience over {@link rehydrate}, cheap enough for an
|
|
144
145
|
* unconditional call: a node whose `$cstNode` is already set returns
|
|
145
|
-
* without resolving its document
|
|
146
|
+
* without resolving its document, and a node outside any document, such as
|
|
147
|
+
* a detached synthetic node, has nothing to restore and returns too.
|
|
146
148
|
*/
|
|
147
149
|
rehydrateNode(node: AstNode): void;
|
|
148
150
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;IAC/E,iBAAiB,IAAI,IAAI,CAKxB;IAED;;;;;;;OAOG;IACH,SAAS,CAAC,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAExD;IAED;;;;OAIG;IACH,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CA8BhD;IAED;;;;OAIG;IACH,SAAS,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAElD;CACH"}
|
|
@@ -191,7 +191,10 @@ export class DefaultCstResidencyService {
|
|
|
191
191
|
if (node.$cstNode !== undefined) {
|
|
192
192
|
return;
|
|
193
193
|
}
|
|
194
|
-
|
|
194
|
+
const document = AstUtils.findRootNode(node).$document;
|
|
195
|
+
if (document) {
|
|
196
|
+
this.rehydrate(document);
|
|
197
|
+
}
|
|
195
198
|
}
|
|
196
199
|
/**
|
|
197
200
|
* After each build, refresh the idle timer of every document in the batch: an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cst-residency-service.js","sourceRoot":"","sources":["../../../src/langium/residency/cst-residency-service.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,SAAS,EAAc,SAAS,EAAE,MAAM,EAAe,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAChH,OAAO,EAEJ,QAAQ,EACR,aAAa,EAIb,GAAG,EACL,MAAM,oBAAoB,CAAC;AAK5B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,SAAS,CAAC;AAuCrD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAkB,aAAa,CAAC,OAAO,CAAC;AAEhF;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,QAAyB;IAChD,OAAO,CACJ,QAAQ,CAAC,KAAK,IAAI,aAAa,CAAC,MAAM;QACtC,QAAQ,CAAC,WAAW,EAAE,KAAK,KAAK,SAAS;QACzC,QAAQ,CAAC,WAAW,CAAC,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,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,OAAO,KAAK,kBAAkB,EAAE,CAAC;YAClC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACrD,CAAC;QACD,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3C,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAChB,IAA+B,CAAC,QAAQ,GAAG,SAAS,CAAC;gBACtD,OAAO,EAAE,CAAC;YACb,CAAC;QACJ,CAAC;QACD,KAAK,MAAM,SAAS,IAAI,QAAQ,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;YACjD,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC;gBACrB,SAAoC,CAAC,QAAQ,GAAG,SAAS,CAAC;YAC9D,CAAC;QACJ,CAAC;QACD,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,OAAO,SAAS,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAChH,CAAC;QACD,OAAO,OAAO,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACO,cAAc,CAAC,SAAiB;QACvC,OAAO,IAAI,CAAC,yBAAyB,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC;IACrI,CAAC;CACH"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
import { type Tracer } from '@hydranium/protocol';
|
|
10
|
-
import { type AstNode, type
|
|
10
|
+
import { type AstNode, DefaultAstNodeDescriptionProvider, type DocumentSegment, type LangiumDocument, type URI } from '@hydranium/langium';
|
|
11
11
|
import type { LogNameOptions } from '../diagnostics/logger.js';
|
|
12
12
|
import type { HydraniumLanguageServices } from '../language-module.js';
|
|
13
13
|
import { type DescriptionTier, type TieredAstNodeDescription } from './scoped-ast-node-description.js';
|
|
@@ -30,6 +30,7 @@ import { type DescriptionTier, type TieredAstNodeDescription } from './scoped-as
|
|
|
30
30
|
*/
|
|
31
31
|
export declare class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescriptionProvider {
|
|
32
32
|
protected readonly tracer: Tracer;
|
|
33
|
+
protected readonly services: HydraniumLanguageServices;
|
|
33
34
|
constructor(services: HydraniumLanguageServices, options?: LogNameOptions);
|
|
34
35
|
/**
|
|
35
36
|
* Overrides the Langium base to stamp `tier: 'local'` on every plain
|
|
@@ -37,11 +38,10 @@ export declare class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeD
|
|
|
37
38
|
* filter pipeline. Callers that need a different tier must use
|
|
38
39
|
* {@link createProject}, {@link createPublic}, or {@link createUniversal}.
|
|
39
40
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* correct tier — so there is no create-then-overwrite cost.
|
|
41
|
+
* Langium's own `createDescription` is not called: every factory builds
|
|
42
|
+
* through {@link createTiered}.
|
|
43
43
|
*/
|
|
44
|
-
createDescription(node: AstNode, name: string, document
|
|
44
|
+
createDescription(node: AstNode, name: string | undefined, document?: LangiumDocument): TieredAstNodeDescription;
|
|
45
45
|
/**
|
|
46
46
|
* Build a {@link TieredAstNodeDescription} for a symbol visible only
|
|
47
47
|
* inside its document. Goes into the per-document local-symbols map
|
|
@@ -112,11 +112,47 @@ export declare class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeD
|
|
|
112
112
|
readonly document: LangiumDocument;
|
|
113
113
|
}): TieredAstNodeDescription;
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* just-constructed and not aliased elsewhere.
|
|
115
|
+
* Resolve the fields of the description every factory returns and build it
|
|
116
|
+
* through {@link newDescription}. Mirrors Langium's `createDescription`:
|
|
117
|
+
* the name defaults to the name provider's, and a node without one throws.
|
|
119
118
|
*/
|
|
120
|
-
protected
|
|
119
|
+
protected createTiered(node: AstNode, name: string | undefined, document: LangiumDocument | undefined, tier: DescriptionTier, projectId?: string): TieredAstNodeDescription;
|
|
120
|
+
/** Construct the description from resolved fields; override to build a subclass of {@link DefaultTieredAstNodeDescription}. */
|
|
121
|
+
protected newDescription(node: AstNode, name: string, documentUri: URI, path: string, tier: DescriptionTier, projectId: string | undefined): TieredAstNodeDescription;
|
|
122
|
+
/**
|
|
123
|
+
* The segment of `node`'s name, or of the whole node when the name
|
|
124
|
+
* provider finds no name node, restoring a shed CST first: a name provider
|
|
125
|
+
* need not restore it, and an absent segment is not computed again.
|
|
126
|
+
*/
|
|
127
|
+
nameSegmentOf(node: AstNode): DocumentSegment | undefined;
|
|
128
|
+
/** The segment of the whole node, restoring a shed CST first. */
|
|
129
|
+
selectionSegmentOf(node: AstNode): DocumentSegment | undefined;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The description {@link HydraniumAstNodeDescriptionProvider} builds. Every
|
|
133
|
+
* field is set in the constructor, so all descriptions share one V8 hidden
|
|
134
|
+
* class; Langium's object literal with a `nameSegment` accessor is kept in
|
|
135
|
+
* dictionary mode and carries two closures, several times the bytes.
|
|
136
|
+
*
|
|
137
|
+
* `nameSegment` and `selectionSegment` are prototype getters, not own
|
|
138
|
+
* properties: a spread, `Object.keys`, a JSON round trip or `structuredClone`
|
|
139
|
+
* of a description drops them. Each is computed on its first read, from the
|
|
140
|
+
* node the description was built for, restoring a shed CST first; an eager
|
|
141
|
+
* `selectionSegment` would keep a segment per description that nothing reads.
|
|
142
|
+
*/
|
|
143
|
+
export declare class DefaultTieredAstNodeDescription implements TieredAstNodeDescription {
|
|
144
|
+
protected readonly provider: HydraniumAstNodeDescriptionProvider;
|
|
145
|
+
readonly node: AstNode;
|
|
146
|
+
readonly name: string;
|
|
147
|
+
readonly documentUri: URI;
|
|
148
|
+
readonly path: string;
|
|
149
|
+
readonly tier: DescriptionTier;
|
|
150
|
+
readonly projectId: string | undefined;
|
|
151
|
+
readonly type: string;
|
|
152
|
+
protected nameSegmentCache: DocumentSegment | null | undefined;
|
|
153
|
+
protected selectionSegmentCache: DocumentSegment | null | undefined;
|
|
154
|
+
constructor(provider: HydraniumAstNodeDescriptionProvider, node: AstNode, name: string, documentUri: URI, path: string, tier: DescriptionTier, projectId: string | undefined);
|
|
155
|
+
get nameSegment(): DocumentSegment | undefined;
|
|
156
|
+
get selectionSegment(): DocumentSegment | undefined;
|
|
121
157
|
}
|
|
122
158
|
//# sourceMappingURL=ast-node-description-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-node-description-provider.d.ts","sourceRoot":"","sources":["../../../src/langium/scope/ast-node-description-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"ast-node-description-provider.d.ts","sourceRoot":"","sources":["../../../src/langium/scope/ast-node-description-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EACJ,KAAK,OAAO,EAGZ,iCAAiC,EACjC,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,GAAG,EACV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE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AqB,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC;IAEpE,YACsB,QAAQ,EAAE,mCAAmC,EACvD,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,GAAG,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,eAAe,EACrB,SAAS,EAAE,MAAM,GAAG,SAAS,EAGxC;IAED,IAAI,WAAW,IAAI,eAAe,GAAG,SAAS,CAK7C;IAED,IAAI,gBAAgB,IAAI,eAAe,GAAG,SAAS,CAKlD;CACH"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
|
-
import { DefaultAstNodeDescriptionProvider } from '@hydranium/langium';
|
|
9
|
+
import { AstUtils, CstUtils, DefaultAstNodeDescriptionProvider } from '@hydranium/langium';
|
|
10
10
|
/**
|
|
11
11
|
* Framework `AstNodeDescriptionProvider` extension. Adds four typed
|
|
12
12
|
* factory methods aligned with the {@link TieredAstNodeDescription} four-
|
|
@@ -26,8 +26,10 @@ import { DefaultAstNodeDescriptionProvider } from '@hydranium/langium';
|
|
|
26
26
|
*/
|
|
27
27
|
export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescriptionProvider {
|
|
28
28
|
tracer;
|
|
29
|
+
services;
|
|
29
30
|
constructor(services, options = {}) {
|
|
30
31
|
super(services);
|
|
32
|
+
this.services = services;
|
|
31
33
|
this.tracer = services.shared.Tracer.for(options.logName ?? 'AstNodeDescriptionProvider').trace('instantiated');
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
@@ -36,12 +38,11 @@ export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescripti
|
|
|
36
38
|
* filter pipeline. Callers that need a different tier must use
|
|
37
39
|
* {@link createProject}, {@link createPublic}, or {@link createUniversal}.
|
|
38
40
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* correct tier — so there is no create-then-overwrite cost.
|
|
41
|
+
* Langium's own `createDescription` is not called: every factory builds
|
|
42
|
+
* through {@link createTiered}.
|
|
42
43
|
*/
|
|
43
44
|
createDescription(node, name, document) {
|
|
44
|
-
return this.
|
|
45
|
+
return this.createTiered(node, name, document, 'local');
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Build a {@link TieredAstNodeDescription} for a symbol visible only
|
|
@@ -53,7 +54,7 @@ export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescripti
|
|
|
53
54
|
* never sees them, so a project tag would be unused.
|
|
54
55
|
*/
|
|
55
56
|
createLocal(options) {
|
|
56
|
-
return this.
|
|
57
|
+
return this.createTiered(options.node, options.name, options.document, 'local');
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
59
60
|
* Build a {@link TieredAstNodeDescription} for a symbol visible inside
|
|
@@ -69,7 +70,7 @@ export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescripti
|
|
|
69
70
|
* `ProjectManager.getProject(document.uri)?.id` once per document.
|
|
70
71
|
*/
|
|
71
72
|
createProject(options) {
|
|
72
|
-
return this.
|
|
73
|
+
return this.createTiered(options.node, options.name, options.document, 'project', options.projectId);
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
75
76
|
* Build a {@link TieredAstNodeDescription} at `tier: 'public'` — the
|
|
@@ -87,7 +88,7 @@ export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescripti
|
|
|
87
88
|
* one and a workspace-qualified one.
|
|
88
89
|
*/
|
|
89
90
|
createPublic(options) {
|
|
90
|
-
return this.
|
|
91
|
+
return this.createTiered(options.node, options.name, options.document, 'public', options.projectId);
|
|
91
92
|
}
|
|
92
93
|
/**
|
|
93
94
|
* Build a {@link TieredAstNodeDescription} at `tier: 'universal'` —
|
|
@@ -100,16 +101,88 @@ export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescripti
|
|
|
100
101
|
* {@link createPublic} instead.
|
|
101
102
|
*/
|
|
102
103
|
createUniversal(options) {
|
|
103
|
-
return this.
|
|
104
|
+
return this.createTiered(options.node, options.name, options.document, 'universal');
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* just-constructed and not aliased elsewhere.
|
|
107
|
+
* Resolve the fields of the description every factory returns and build it
|
|
108
|
+
* through {@link newDescription}. Mirrors Langium's `createDescription`:
|
|
109
|
+
* the name defaults to the name provider's, and a node without one throws.
|
|
110
110
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
createTiered(node, name, document, tier, projectId) {
|
|
112
|
+
const path = this.astNodeLocator.getAstNodePath(node);
|
|
113
|
+
const resolvedName = name ?? this.nameProvider.getName(node);
|
|
114
|
+
if (!resolvedName) {
|
|
115
|
+
throw new Error(`Node at path ${path} has no name.`);
|
|
116
|
+
}
|
|
117
|
+
const documentUri = (document ?? AstUtils.getDocument(node)).uri;
|
|
118
|
+
return this.newDescription(node, resolvedName, documentUri, path, tier, projectId);
|
|
119
|
+
}
|
|
120
|
+
/** Construct the description from resolved fields; override to build a subclass of {@link DefaultTieredAstNodeDescription}. */
|
|
121
|
+
newDescription(node, name, documentUri, path, tier, projectId) {
|
|
122
|
+
return new DefaultTieredAstNodeDescription(this, node, name, documentUri, path, tier, projectId);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The segment of `node`'s name, or of the whole node when the name
|
|
126
|
+
* provider finds no name node, restoring a shed CST first: a name provider
|
|
127
|
+
* need not restore it, and an absent segment is not computed again.
|
|
128
|
+
*/
|
|
129
|
+
nameSegmentOf(node) {
|
|
130
|
+
this.services.shared.workspace.CstResidencyService.rehydrateNode(node);
|
|
131
|
+
return CstUtils.toDocumentSegment(this.nameProvider.getNameNode(node) ?? node.$cstNode);
|
|
132
|
+
}
|
|
133
|
+
/** The segment of the whole node, restoring a shed CST first. */
|
|
134
|
+
selectionSegmentOf(node) {
|
|
135
|
+
this.services.shared.workspace.CstResidencyService.rehydrateNode(node);
|
|
136
|
+
return CstUtils.toDocumentSegment(node.$cstNode);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The description {@link HydraniumAstNodeDescriptionProvider} builds. Every
|
|
141
|
+
* field is set in the constructor, so all descriptions share one V8 hidden
|
|
142
|
+
* class; Langium's object literal with a `nameSegment` accessor is kept in
|
|
143
|
+
* dictionary mode and carries two closures, several times the bytes.
|
|
144
|
+
*
|
|
145
|
+
* `nameSegment` and `selectionSegment` are prototype getters, not own
|
|
146
|
+
* properties: a spread, `Object.keys`, a JSON round trip or `structuredClone`
|
|
147
|
+
* of a description drops them. Each is computed on its first read, from the
|
|
148
|
+
* node the description was built for, restoring a shed CST first; an eager
|
|
149
|
+
* `selectionSegment` would keep a segment per description that nothing reads.
|
|
150
|
+
*/
|
|
151
|
+
export class DefaultTieredAstNodeDescription {
|
|
152
|
+
provider;
|
|
153
|
+
node;
|
|
154
|
+
name;
|
|
155
|
+
documentUri;
|
|
156
|
+
path;
|
|
157
|
+
tier;
|
|
158
|
+
projectId;
|
|
159
|
+
type;
|
|
160
|
+
// `null` records a segment computed while the node had no CST. It is
|
|
161
|
+
// recomputed only once the node has one again: retrying without one would
|
|
162
|
+
// attempt a restore, a re-parse, on every read.
|
|
163
|
+
nameSegmentCache;
|
|
164
|
+
selectionSegmentCache;
|
|
165
|
+
constructor(provider, node, name, documentUri, path, tier, projectId) {
|
|
166
|
+
this.provider = provider;
|
|
167
|
+
this.node = node;
|
|
168
|
+
this.name = name;
|
|
169
|
+
this.documentUri = documentUri;
|
|
170
|
+
this.path = path;
|
|
171
|
+
this.tier = tier;
|
|
172
|
+
this.projectId = projectId;
|
|
173
|
+
this.type = node.$type;
|
|
174
|
+
}
|
|
175
|
+
get nameSegment() {
|
|
176
|
+
if (this.nameSegmentCache === undefined || (this.nameSegmentCache === null && this.node.$cstNode !== undefined)) {
|
|
177
|
+
this.nameSegmentCache = this.provider.nameSegmentOf(this.node) ?? null;
|
|
178
|
+
}
|
|
179
|
+
return this.nameSegmentCache ?? undefined;
|
|
180
|
+
}
|
|
181
|
+
get selectionSegment() {
|
|
182
|
+
if (this.selectionSegmentCache === undefined || (this.selectionSegmentCache === null && this.node.$cstNode !== undefined)) {
|
|
183
|
+
this.selectionSegmentCache = this.provider.selectionSegmentOf(this.node) ?? null;
|
|
184
|
+
}
|
|
185
|
+
return this.selectionSegmentCache ?? undefined;
|
|
113
186
|
}
|
|
114
187
|
}
|
|
115
188
|
//# sourceMappingURL=ast-node-description-provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-node-description-provider.js","sourceRoot":"","sources":["../../../src/langium/scope/ast-node-description-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAGlF,OAAO,
|
|
1
|
+
{"version":3,"file":"ast-node-description-provider.js","sourceRoot":"","sources":["../../../src/langium/scope/ast-node-description-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAGlF,OAAO,EAEJ,QAAQ,EACR,QAAQ,EACR,iCAAiC,EAInC,MAAM,oBAAoB,CAAC;AAK5B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,mCAAoC,SAAQ,iCAAiC;IACpE,MAAM,CAAS;IACf,QAAQ,CAA4B;IAEvD,YAAY,QAAmC,EAAE,OAAO,GAAmB,EAAE;QAC1E,KAAK,CAAC,QAAQ,CAAC,CAAC;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,4BAA4B,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IACnH,CAAC;IAED;;;;;;;;OAQG;IACM,iBAAiB,CAAC,IAAa,EAAE,IAAwB,EAAE,QAA0B;QAC3F,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,IAA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Z,WAAgB,EAChB,IAAY,EACZ,IAAqB,EACrB,SAA6B;wBANnB,QAAQ;oBAClB,IAAI;oBACJ,IAAI;2BACJ,WAAW;oBACX,IAAI;oBACJ,IAAI;yBACJ,SAAS;QAElB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;IAED,IAAI,WAAW;QACZ,IAAI,IAAI,CAAC,gBAAgB,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,gBAAgB,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,EAAE,CAAC;YAC/G,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;QAC1E,CAAC;QACD,OAAO,IAAI,CAAC,gBAAgB,IAAI,SAAS,CAAC;IAC7C,CAAC;IAED,IAAI,gBAAgB;QACjB,IAAI,IAAI,CAAC,qBAAqB,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,qBAAqB,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,EAAE,CAAC;YACzH,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;QACpF,CAAC;QACD,OAAO,IAAI,CAAC,qBAAqB,IAAI,SAAS,CAAC;IAClD,CAAC;CACH"}
|
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.357",
|
|
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.357",
|
|
91
|
+
"@hydranium/protocol": "1.0.0-next.357",
|
|
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.357",
|
|
105
|
+
"@hydranium/protocol": "1.0.0-next.357",
|
|
106
106
|
"@playwright/test": "^1.40.0",
|
|
107
107
|
"vscode-jsonrpc": "^9.0.0",
|
|
108
108
|
"vscode-languageserver": "~10.0.1",
|
|
@@ -195,8 +195,9 @@ function rehydrateCst(document: LangiumDocument, factory: LangiumDocumentFactory
|
|
|
195
195
|
* the idle window of the documents in its batch; when a closed, sheddable
|
|
196
196
|
* document's window elapses, every AST node's `$cstNode` and every reference's
|
|
197
197
|
* `$refNode` are nulled, and the CST becomes unreachable with the `Range`s
|
|
198
|
-
* and `Position`s only it holds.
|
|
199
|
-
*
|
|
198
|
+
* and `Position`s only it holds. The reference index's segments, and a
|
|
199
|
+
* description's segments once read, share the CST's `Range` objects, so
|
|
200
|
+
* those stay.
|
|
200
201
|
*
|
|
201
202
|
* **Terminology.** *Residency* is the state axis (is the CST in memory? —
|
|
202
203
|
* `resident` vs `shed`); *shed* is both the act and the policy vocabulary (drop
|
|
@@ -248,7 +249,8 @@ export interface CstResidencyService {
|
|
|
248
249
|
/**
|
|
249
250
|
* Node-level convenience over {@link rehydrate}, cheap enough for an
|
|
250
251
|
* unconditional call: a node whose `$cstNode` is already set returns
|
|
251
|
-
* without resolving its document
|
|
252
|
+
* without resolving its document, and a node outside any document, such as
|
|
253
|
+
* a detached synthetic node, has nothing to restore and returns too.
|
|
252
254
|
*/
|
|
253
255
|
rehydrateNode(node: AstNode): void;
|
|
254
256
|
}
|
|
@@ -317,7 +319,10 @@ export class DefaultCstResidencyService implements CstResidencyService {
|
|
|
317
319
|
if (node.$cstNode !== undefined) {
|
|
318
320
|
return;
|
|
319
321
|
}
|
|
320
|
-
|
|
322
|
+
const document = AstUtils.findRootNode(node).$document;
|
|
323
|
+
if (document) {
|
|
324
|
+
this.rehydrate(document);
|
|
325
|
+
}
|
|
321
326
|
}
|
|
322
327
|
|
|
323
328
|
/**
|
|
@@ -8,7 +8,15 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import { type Tracer } from '@hydranium/protocol';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
type AstNode,
|
|
13
|
+
AstUtils,
|
|
14
|
+
CstUtils,
|
|
15
|
+
DefaultAstNodeDescriptionProvider,
|
|
16
|
+
type DocumentSegment,
|
|
17
|
+
type LangiumDocument,
|
|
18
|
+
type URI
|
|
19
|
+
} from '@hydranium/langium';
|
|
12
20
|
import type { LogNameOptions } from '../diagnostics/logger.js';
|
|
13
21
|
import type { HydraniumLanguageServices } from '../language-module.js';
|
|
14
22
|
import { type DescriptionTier, type TieredAstNodeDescription } from './scoped-ast-node-description.js';
|
|
@@ -32,9 +40,11 @@ import { type DescriptionTier, type TieredAstNodeDescription } from './scoped-as
|
|
|
32
40
|
*/
|
|
33
41
|
export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescriptionProvider {
|
|
34
42
|
protected readonly tracer: Tracer;
|
|
43
|
+
protected readonly services: HydraniumLanguageServices;
|
|
35
44
|
|
|
36
45
|
constructor(services: HydraniumLanguageServices, options: LogNameOptions = {}) {
|
|
37
46
|
super(services);
|
|
47
|
+
this.services = services;
|
|
38
48
|
this.tracer = services.shared.Tracer.for(options.logName ?? 'AstNodeDescriptionProvider').trace('instantiated');
|
|
39
49
|
}
|
|
40
50
|
|
|
@@ -44,12 +54,11 @@ export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescripti
|
|
|
44
54
|
* filter pipeline. Callers that need a different tier must use
|
|
45
55
|
* {@link createProject}, {@link createPublic}, or {@link createUniversal}.
|
|
46
56
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* correct tier — so there is no create-then-overwrite cost.
|
|
57
|
+
* Langium's own `createDescription` is not called: every factory builds
|
|
58
|
+
* through {@link createTiered}.
|
|
50
59
|
*/
|
|
51
|
-
override createDescription(node: AstNode, name: string, document
|
|
52
|
-
return this.
|
|
60
|
+
override createDescription(node: AstNode, name: string | undefined, document?: LangiumDocument): TieredAstNodeDescription {
|
|
61
|
+
return this.createTiered(node, name, document, 'local');
|
|
53
62
|
}
|
|
54
63
|
|
|
55
64
|
/**
|
|
@@ -62,7 +71,7 @@ export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescripti
|
|
|
62
71
|
* never sees them, so a project tag would be unused.
|
|
63
72
|
*/
|
|
64
73
|
createLocal(options: { readonly node: AstNode; readonly name: string; readonly document: LangiumDocument }): TieredAstNodeDescription {
|
|
65
|
-
return this.
|
|
74
|
+
return this.createTiered(options.node, options.name, options.document, 'local');
|
|
66
75
|
}
|
|
67
76
|
|
|
68
77
|
/**
|
|
@@ -84,7 +93,7 @@ export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescripti
|
|
|
84
93
|
readonly document: LangiumDocument;
|
|
85
94
|
readonly projectId: string;
|
|
86
95
|
}): TieredAstNodeDescription {
|
|
87
|
-
return this.
|
|
96
|
+
return this.createTiered(options.node, options.name, options.document, 'project', options.projectId);
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
/**
|
|
@@ -108,7 +117,7 @@ export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescripti
|
|
|
108
117
|
readonly document: LangiumDocument;
|
|
109
118
|
readonly projectId: string;
|
|
110
119
|
}): TieredAstNodeDescription {
|
|
111
|
-
return this.
|
|
120
|
+
return this.createTiered(options.node, options.name, options.document, 'public', options.projectId);
|
|
112
121
|
}
|
|
113
122
|
|
|
114
123
|
/**
|
|
@@ -126,16 +135,102 @@ export class HydraniumAstNodeDescriptionProvider extends DefaultAstNodeDescripti
|
|
|
126
135
|
readonly name: string;
|
|
127
136
|
readonly document: LangiumDocument;
|
|
128
137
|
}): TieredAstNodeDescription {
|
|
129
|
-
return this.
|
|
138
|
+
return this.createTiered(options.node, options.name, options.document, 'universal');
|
|
130
139
|
}
|
|
131
140
|
|
|
132
141
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* just-constructed and not aliased elsewhere.
|
|
142
|
+
* Resolve the fields of the description every factory returns and build it
|
|
143
|
+
* through {@link newDescription}. Mirrors Langium's `createDescription`:
|
|
144
|
+
* the name defaults to the name provider's, and a node without one throws.
|
|
137
145
|
*/
|
|
138
|
-
protected
|
|
139
|
-
|
|
146
|
+
protected createTiered(
|
|
147
|
+
node: AstNode,
|
|
148
|
+
name: string | undefined,
|
|
149
|
+
document: LangiumDocument | undefined,
|
|
150
|
+
tier: DescriptionTier,
|
|
151
|
+
projectId?: string
|
|
152
|
+
): TieredAstNodeDescription {
|
|
153
|
+
const path = this.astNodeLocator.getAstNodePath(node);
|
|
154
|
+
const resolvedName = name ?? this.nameProvider.getName(node);
|
|
155
|
+
if (!resolvedName) {
|
|
156
|
+
throw new Error(`Node at path ${path} has no name.`);
|
|
157
|
+
}
|
|
158
|
+
const documentUri = (document ?? AstUtils.getDocument(node)).uri;
|
|
159
|
+
return this.newDescription(node, resolvedName, documentUri, path, tier, projectId);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Construct the description from resolved fields; override to build a subclass of {@link DefaultTieredAstNodeDescription}. */
|
|
163
|
+
protected newDescription(
|
|
164
|
+
node: AstNode,
|
|
165
|
+
name: string,
|
|
166
|
+
documentUri: URI,
|
|
167
|
+
path: string,
|
|
168
|
+
tier: DescriptionTier,
|
|
169
|
+
projectId: string | undefined
|
|
170
|
+
): TieredAstNodeDescription {
|
|
171
|
+
return new DefaultTieredAstNodeDescription(this, node, name, documentUri, path, tier, projectId);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The segment of `node`'s name, or of the whole node when the name
|
|
176
|
+
* provider finds no name node, restoring a shed CST first: a name provider
|
|
177
|
+
* need not restore it, and an absent segment is not computed again.
|
|
178
|
+
*/
|
|
179
|
+
nameSegmentOf(node: AstNode): DocumentSegment | undefined {
|
|
180
|
+
this.services.shared.workspace.CstResidencyService.rehydrateNode(node);
|
|
181
|
+
return CstUtils.toDocumentSegment(this.nameProvider.getNameNode(node) ?? node.$cstNode);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The segment of the whole node, restoring a shed CST first. */
|
|
185
|
+
selectionSegmentOf(node: AstNode): DocumentSegment | undefined {
|
|
186
|
+
this.services.shared.workspace.CstResidencyService.rehydrateNode(node);
|
|
187
|
+
return CstUtils.toDocumentSegment(node.$cstNode);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The description {@link HydraniumAstNodeDescriptionProvider} builds. Every
|
|
193
|
+
* field is set in the constructor, so all descriptions share one V8 hidden
|
|
194
|
+
* class; Langium's object literal with a `nameSegment` accessor is kept in
|
|
195
|
+
* dictionary mode and carries two closures, several times the bytes.
|
|
196
|
+
*
|
|
197
|
+
* `nameSegment` and `selectionSegment` are prototype getters, not own
|
|
198
|
+
* properties: a spread, `Object.keys`, a JSON round trip or `structuredClone`
|
|
199
|
+
* of a description drops them. Each is computed on its first read, from the
|
|
200
|
+
* node the description was built for, restoring a shed CST first; an eager
|
|
201
|
+
* `selectionSegment` would keep a segment per description that nothing reads.
|
|
202
|
+
*/
|
|
203
|
+
export class DefaultTieredAstNodeDescription implements TieredAstNodeDescription {
|
|
204
|
+
readonly type: string;
|
|
205
|
+
// `null` records a segment computed while the node had no CST. It is
|
|
206
|
+
// recomputed only once the node has one again: retrying without one would
|
|
207
|
+
// attempt a restore, a re-parse, on every read.
|
|
208
|
+
protected nameSegmentCache: DocumentSegment | null | undefined;
|
|
209
|
+
protected selectionSegmentCache: DocumentSegment | null | undefined;
|
|
210
|
+
|
|
211
|
+
constructor(
|
|
212
|
+
protected readonly provider: HydraniumAstNodeDescriptionProvider,
|
|
213
|
+
readonly node: AstNode,
|
|
214
|
+
readonly name: string,
|
|
215
|
+
readonly documentUri: URI,
|
|
216
|
+
readonly path: string,
|
|
217
|
+
readonly tier: DescriptionTier,
|
|
218
|
+
readonly projectId: string | undefined
|
|
219
|
+
) {
|
|
220
|
+
this.type = node.$type;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
get nameSegment(): DocumentSegment | undefined {
|
|
224
|
+
if (this.nameSegmentCache === undefined || (this.nameSegmentCache === null && this.node.$cstNode !== undefined)) {
|
|
225
|
+
this.nameSegmentCache = this.provider.nameSegmentOf(this.node) ?? null;
|
|
226
|
+
}
|
|
227
|
+
return this.nameSegmentCache ?? undefined;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
get selectionSegment(): DocumentSegment | undefined {
|
|
231
|
+
if (this.selectionSegmentCache === undefined || (this.selectionSegmentCache === null && this.node.$cstNode !== undefined)) {
|
|
232
|
+
this.selectionSegmentCache = this.provider.selectionSegmentOf(this.node) ?? null;
|
|
233
|
+
}
|
|
234
|
+
return this.selectionSegmentCache ?? undefined;
|
|
140
235
|
}
|
|
141
236
|
}
|