@domainlang/language 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -102
- package/out/domain-lang-module.d.ts +2 -2
- package/out/domain-lang-module.js +2 -2
- package/out/domain-lang-module.js.map +1 -1
- package/out/index.d.ts +4 -0
- package/out/index.js +4 -0
- package/out/index.js.map +1 -1
- package/out/lsp/domain-lang-completion.js +1 -1
- package/out/lsp/domain-lang-completion.js.map +1 -1
- package/out/lsp/domain-lang-index-manager.d.ts +149 -5
- package/out/lsp/domain-lang-index-manager.js +388 -52
- package/out/lsp/domain-lang-index-manager.js.map +1 -1
- package/out/lsp/domain-lang-refresh.d.ts +35 -0
- package/out/lsp/domain-lang-refresh.js +129 -0
- package/out/lsp/domain-lang-refresh.js.map +1 -0
- package/out/lsp/domain-lang-workspace-manager.d.ts +10 -0
- package/out/lsp/domain-lang-workspace-manager.js +35 -0
- package/out/lsp/domain-lang-workspace-manager.js.map +1 -1
- package/out/lsp/explain.d.ts +18 -0
- package/out/lsp/explain.js +138 -0
- package/out/lsp/explain.js.map +1 -0
- package/out/lsp/tool-handlers.d.ts +113 -0
- package/out/lsp/tool-handlers.js +297 -0
- package/out/lsp/tool-handlers.js.map +1 -0
- package/out/main.js +33 -190
- package/out/main.js.map +1 -1
- package/out/sdk/index.d.ts +2 -0
- package/out/sdk/index.js +2 -0
- package/out/sdk/index.js.map +1 -1
- package/out/sdk/loader-node.js +1 -1
- package/out/sdk/loader-node.js.map +1 -1
- package/out/sdk/serializers.d.ts +110 -0
- package/out/sdk/serializers.js +158 -0
- package/out/sdk/serializers.js.map +1 -0
- package/out/sdk/validator.js +17 -14
- package/out/sdk/validator.js.map +1 -1
- package/out/services/import-resolver.d.ts +67 -17
- package/out/services/import-resolver.js +146 -65
- package/out/services/import-resolver.js.map +1 -1
- package/out/services/lsp-logger.d.ts +42 -0
- package/out/services/lsp-logger.js +50 -0
- package/out/services/lsp-logger.js.map +1 -0
- package/out/services/lsp-runtime-settings.d.ts +20 -0
- package/out/services/lsp-runtime-settings.js +20 -0
- package/out/services/lsp-runtime-settings.js.map +1 -0
- package/out/services/performance-optimizer.d.ts +9 -9
- package/out/services/performance-optimizer.js +17 -41
- package/out/services/performance-optimizer.js.map +1 -1
- package/out/services/workspace-manager.d.ts +22 -1
- package/out/services/workspace-manager.js +57 -9
- package/out/services/workspace-manager.js.map +1 -1
- package/out/utils/import-utils.js +6 -6
- package/out/utils/import-utils.js.map +1 -1
- package/out/validation/constants.d.ts +6 -0
- package/out/validation/constants.js +7 -0
- package/out/validation/constants.js.map +1 -1
- package/out/validation/import.d.ts +13 -3
- package/out/validation/import.js +54 -10
- package/out/validation/import.js.map +1 -1
- package/package.json +1 -1
- package/src/domain-lang-module.ts +3 -3
- package/src/index.ts +4 -0
- package/src/lsp/domain-lang-completion.ts +3 -3
- package/src/lsp/domain-lang-index-manager.ts +438 -56
- package/src/lsp/domain-lang-refresh.ts +205 -0
- package/src/lsp/domain-lang-workspace-manager.ts +45 -0
- package/src/lsp/explain.ts +172 -0
- package/src/lsp/tool-handlers.ts +443 -0
- package/src/main.ts +40 -244
- package/src/sdk/index.ts +11 -0
- package/src/sdk/loader-node.ts +1 -1
- package/src/sdk/serializers.ts +213 -0
- package/src/sdk/validator.ts +17 -13
- package/src/services/import-resolver.ts +196 -89
- package/src/services/lsp-logger.ts +89 -0
- package/src/services/lsp-runtime-settings.ts +34 -0
- package/src/services/performance-optimizer.ts +18 -57
- package/src/services/workspace-manager.ts +62 -10
- package/src/utils/import-utils.ts +6 -6
- package/src/validation/constants.ts +9 -0
- package/src/validation/import.ts +67 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-node.js","sourceRoot":"","sources":["../../src/sdk/loader-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAC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jC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AST Serialization Utilities
|
|
3
|
+
*
|
|
4
|
+
* Converts Langium AST nodes to plain JSON objects suitable for:
|
|
5
|
+
* - LSP custom requests (JSON-RPC transport)
|
|
6
|
+
* - MCP tool responses (stdio JSON)
|
|
7
|
+
* - CLI output (JSON/YAML formats)
|
|
8
|
+
*
|
|
9
|
+
* ## Strategy
|
|
10
|
+
*
|
|
11
|
+
* Rather than maintaining a parallel DTO type hierarchy (DomainDto, BoundedContextDto, etc.),
|
|
12
|
+
* we use a **generic serializer** that:
|
|
13
|
+
* - Strips Langium internal properties ($container, $cstNode, $document)
|
|
14
|
+
* - Preserves $type for discriminated output
|
|
15
|
+
* - Resolves Reference<T> to referenced name strings
|
|
16
|
+
* - Resolves MultiReference<T> to arrays of names
|
|
17
|
+
* - Recursively serializes child AstNodes
|
|
18
|
+
* - Adds FQN for named elements via Query
|
|
19
|
+
*
|
|
20
|
+
* For types with SDK-augmented properties (computed values not on raw AST),
|
|
21
|
+
* use augmentation functions that enrich the generic output.
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
import type { AstNode, Reference } from 'langium';
|
|
26
|
+
import type { Query, RelationshipView } from './types.js';
|
|
27
|
+
/**
|
|
28
|
+
* Canonical entity types that can be queried.
|
|
29
|
+
* Moved from CLI to SDK for sharing with LSP tools.
|
|
30
|
+
*/
|
|
31
|
+
export type QueryEntityType = 'domains' | 'bcs' | 'teams' | 'classifications' | 'relationships' | 'context-maps' | 'domain-maps';
|
|
32
|
+
/**
|
|
33
|
+
* All accepted entity type names, including aliases.
|
|
34
|
+
* Aliases are normalized to canonical types before query execution.
|
|
35
|
+
*/
|
|
36
|
+
export type QueryEntityInput = QueryEntityType | 'bounded-contexts' | 'contexts' | 'rels' | 'cmaps' | 'dmaps';
|
|
37
|
+
/**
|
|
38
|
+
* Query filter options.
|
|
39
|
+
* Moved from CLI to SDK for sharing with LSP tools.
|
|
40
|
+
*/
|
|
41
|
+
export interface QueryFilters {
|
|
42
|
+
/** Filter by name (string or regex) */
|
|
43
|
+
name?: string;
|
|
44
|
+
/** Filter by fully qualified name */
|
|
45
|
+
fqn?: string;
|
|
46
|
+
/** Filter BCs by domain */
|
|
47
|
+
domain?: string;
|
|
48
|
+
/** Filter BCs by team */
|
|
49
|
+
team?: string;
|
|
50
|
+
/** Filter BCs by classification */
|
|
51
|
+
classification?: string;
|
|
52
|
+
/** Filter BCs by metadata key=value */
|
|
53
|
+
metadata?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Map of entity type aliases to their canonical form.
|
|
57
|
+
*/
|
|
58
|
+
export declare const ENTITY_ALIASES: Record<string, QueryEntityType>;
|
|
59
|
+
/**
|
|
60
|
+
* Normalize an entity type input (which may be an alias) to its canonical form.
|
|
61
|
+
*/
|
|
62
|
+
export declare function normalizeEntityType(input: string): QueryEntityType;
|
|
63
|
+
/**
|
|
64
|
+
* Serialize any Langium AST node to a plain JSON object.
|
|
65
|
+
*
|
|
66
|
+
* - Strips $-prefixed internal properties ($container, $cstNode, $document)
|
|
67
|
+
* - Preserves $type for discriminated output
|
|
68
|
+
* - Resolves Reference<T> to the referenced name (string)
|
|
69
|
+
* - Resolves MultiReference<T> to an array of names
|
|
70
|
+
* - Recursively serializes child AstNode properties
|
|
71
|
+
* - Serializes arrays of AstNodes/values
|
|
72
|
+
* - Adds FQN for named elements
|
|
73
|
+
*
|
|
74
|
+
* @param node - AST node to serialize
|
|
75
|
+
* @param query - Query instance for FQN resolution
|
|
76
|
+
* @returns Plain JSON object
|
|
77
|
+
*/
|
|
78
|
+
export declare function serializeNode(node: AstNode, query: Query): Record<string, unknown>;
|
|
79
|
+
/**
|
|
80
|
+
* Augment a serialized RelationshipView with computed properties.
|
|
81
|
+
*
|
|
82
|
+
* RelationshipView is already a clean DTO (not an AstNode), but we format it
|
|
83
|
+
* consistently with other serialized types.
|
|
84
|
+
*
|
|
85
|
+
* @param view - RelationshipView from query.relationships()
|
|
86
|
+
* @returns Serialized relationship object
|
|
87
|
+
*/
|
|
88
|
+
export declare function serializeRelationship(view: RelationshipView): Record<string, unknown>;
|
|
89
|
+
/**
|
|
90
|
+
* Resolve a Reference<T> to its name string.
|
|
91
|
+
* Returns undefined if reference is unresolved.
|
|
92
|
+
*
|
|
93
|
+
* @param ref - Reference to resolve
|
|
94
|
+
* @returns Referenced name or undefined
|
|
95
|
+
*/
|
|
96
|
+
export declare function resolveName<T extends AstNode & {
|
|
97
|
+
name?: string;
|
|
98
|
+
}>(ref: Reference<T> | undefined): string | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Resolve a MultiReference (array of items with refs) to an array of names.
|
|
101
|
+
* Filters out unresolved references.
|
|
102
|
+
*
|
|
103
|
+
* @param multiRef - Array of items with ref property
|
|
104
|
+
* @returns Array of resolved names
|
|
105
|
+
*/
|
|
106
|
+
export declare function resolveMultiReference<T extends {
|
|
107
|
+
ref?: Reference<AstNode & {
|
|
108
|
+
name?: string;
|
|
109
|
+
}>;
|
|
110
|
+
}>(multiRef: T[] | undefined): string[];
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AST Serialization Utilities
|
|
3
|
+
*
|
|
4
|
+
* Converts Langium AST nodes to plain JSON objects suitable for:
|
|
5
|
+
* - LSP custom requests (JSON-RPC transport)
|
|
6
|
+
* - MCP tool responses (stdio JSON)
|
|
7
|
+
* - CLI output (JSON/YAML formats)
|
|
8
|
+
*
|
|
9
|
+
* ## Strategy
|
|
10
|
+
*
|
|
11
|
+
* Rather than maintaining a parallel DTO type hierarchy (DomainDto, BoundedContextDto, etc.),
|
|
12
|
+
* we use a **generic serializer** that:
|
|
13
|
+
* - Strips Langium internal properties ($container, $cstNode, $document)
|
|
14
|
+
* - Preserves $type for discriminated output
|
|
15
|
+
* - Resolves Reference<T> to referenced name strings
|
|
16
|
+
* - Resolves MultiReference<T> to arrays of names
|
|
17
|
+
* - Recursively serializes child AstNodes
|
|
18
|
+
* - Adds FQN for named elements via Query
|
|
19
|
+
*
|
|
20
|
+
* For types with SDK-augmented properties (computed values not on raw AST),
|
|
21
|
+
* use augmentation functions that enrich the generic output.
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
import { isAstNode, isReference } from 'langium';
|
|
26
|
+
/**
|
|
27
|
+
* Map of entity type aliases to their canonical form.
|
|
28
|
+
*/
|
|
29
|
+
export const ENTITY_ALIASES = {
|
|
30
|
+
'bounded-contexts': 'bcs',
|
|
31
|
+
'contexts': 'bcs',
|
|
32
|
+
'rels': 'relationships',
|
|
33
|
+
'cmaps': 'context-maps',
|
|
34
|
+
'dmaps': 'domain-maps',
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Normalize an entity type input (which may be an alias) to its canonical form.
|
|
38
|
+
*/
|
|
39
|
+
export function normalizeEntityType(input) {
|
|
40
|
+
if (input in ENTITY_ALIASES) {
|
|
41
|
+
return ENTITY_ALIASES[input];
|
|
42
|
+
}
|
|
43
|
+
return input;
|
|
44
|
+
}
|
|
45
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
46
|
+
// Generic AST Serialization
|
|
47
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
48
|
+
/**
|
|
49
|
+
* Serialize any Langium AST node to a plain JSON object.
|
|
50
|
+
*
|
|
51
|
+
* - Strips $-prefixed internal properties ($container, $cstNode, $document)
|
|
52
|
+
* - Preserves $type for discriminated output
|
|
53
|
+
* - Resolves Reference<T> to the referenced name (string)
|
|
54
|
+
* - Resolves MultiReference<T> to an array of names
|
|
55
|
+
* - Recursively serializes child AstNode properties
|
|
56
|
+
* - Serializes arrays of AstNodes/values
|
|
57
|
+
* - Adds FQN for named elements
|
|
58
|
+
*
|
|
59
|
+
* @param node - AST node to serialize
|
|
60
|
+
* @param query - Query instance for FQN resolution
|
|
61
|
+
* @returns Plain JSON object
|
|
62
|
+
*/
|
|
63
|
+
export function serializeNode(node, query) {
|
|
64
|
+
const result = { $type: node.$type };
|
|
65
|
+
for (const [key, value] of Object.entries(node)) {
|
|
66
|
+
// Skip Langium internals (but preserve $type)
|
|
67
|
+
if (key.startsWith('$') && key !== '$type') {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (isReference(value)) {
|
|
71
|
+
// Reference<T> → name string
|
|
72
|
+
const ref = value.ref;
|
|
73
|
+
result[key] = (ref && 'name' in ref) ? ref.name : value.$refText;
|
|
74
|
+
}
|
|
75
|
+
else if (isAstNode(value)) {
|
|
76
|
+
// Nested AstNode → recurse
|
|
77
|
+
result[key] = serializeNode(value, query);
|
|
78
|
+
}
|
|
79
|
+
else if (Array.isArray(value)) {
|
|
80
|
+
// Array → map each item
|
|
81
|
+
result[key] = value.map(item => {
|
|
82
|
+
if (isReference(item)) {
|
|
83
|
+
const itemRef = item.ref;
|
|
84
|
+
return (itemRef && 'name' in itemRef) ? itemRef.name : item.$refText;
|
|
85
|
+
}
|
|
86
|
+
else if (isAstNode(item)) {
|
|
87
|
+
return serializeNode(item, query);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
return item; // primitive
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Primitives pass through
|
|
96
|
+
result[key] = value;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Always include FQN for named elements
|
|
100
|
+
if ('name' in node && typeof node.name === 'string') {
|
|
101
|
+
result.fqn = query.fqn(node);
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Augment a serialized RelationshipView with computed properties.
|
|
107
|
+
*
|
|
108
|
+
* RelationshipView is already a clean DTO (not an AstNode), but we format it
|
|
109
|
+
* consistently with other serialized types.
|
|
110
|
+
*
|
|
111
|
+
* @param view - RelationshipView from query.relationships()
|
|
112
|
+
* @returns Serialized relationship object
|
|
113
|
+
*/
|
|
114
|
+
export function serializeRelationship(view) {
|
|
115
|
+
// RelationshipView.left and .right are BoundedContext (which have name property)
|
|
116
|
+
const leftName = view.left.name;
|
|
117
|
+
const rightName = view.right.name;
|
|
118
|
+
return {
|
|
119
|
+
$type: 'Relationship',
|
|
120
|
+
name: `${leftName} ${view.arrow} ${rightName}`,
|
|
121
|
+
left: leftName,
|
|
122
|
+
right: rightName,
|
|
123
|
+
arrow: view.arrow,
|
|
124
|
+
leftPatterns: view.leftPatterns,
|
|
125
|
+
rightPatterns: view.rightPatterns,
|
|
126
|
+
inferredType: view.inferredType,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
130
|
+
// Helper: Resolve Reference
|
|
131
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
132
|
+
/**
|
|
133
|
+
* Resolve a Reference<T> to its name string.
|
|
134
|
+
* Returns undefined if reference is unresolved.
|
|
135
|
+
*
|
|
136
|
+
* @param ref - Reference to resolve
|
|
137
|
+
* @returns Referenced name or undefined
|
|
138
|
+
*/
|
|
139
|
+
export function resolveName(ref) {
|
|
140
|
+
if (!ref)
|
|
141
|
+
return undefined;
|
|
142
|
+
return ref.ref?.name ?? ref.$refText;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Resolve a MultiReference (array of items with refs) to an array of names.
|
|
146
|
+
* Filters out unresolved references.
|
|
147
|
+
*
|
|
148
|
+
* @param multiRef - Array of items with ref property
|
|
149
|
+
* @returns Array of resolved names
|
|
150
|
+
*/
|
|
151
|
+
export function resolveMultiReference(multiRef) {
|
|
152
|
+
if (!multiRef)
|
|
153
|
+
return [];
|
|
154
|
+
return multiRef
|
|
155
|
+
.map(item => item.ref?.ref?.name)
|
|
156
|
+
.filter((name) => name !== undefined);
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=serializ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M,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAChC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IAClC,OAAO;QACH,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE,GAAG,QAAQ,IAAI,IAAI,CAAC,KAAK,IAAI,SAAS,EAAE;QAC9C,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,YAAY,EAAE,IAAI,CAAC,YAAY;KAClC,CAAC;AACN,CAAC;AAED,gFAAgF;AAChF,4BAA4B;AAC5B,gFAAgF;AAEhF;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAwC,GAA6B;IAC5F,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAC3B,OAAO,GAAG,CAAC,GAAG,EAAE,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC;AACzC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACjC,QAAyB;IAEzB,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,CAAC;IACzB,OAAO,QAAQ;SACV,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC;SAChC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;AAC9D,CAAC"}
|
package/out/sdk/validator.js
CHANGED
|
@@ -75,8 +75,8 @@ export async function validateFile(filePath, options = {}) {
|
|
|
75
75
|
}
|
|
76
76
|
// Initialize workspace with the specified directory or file's directory
|
|
77
77
|
const workspaceDir = options.workspaceDir ?? dirname(absolutePath);
|
|
78
|
-
const
|
|
79
|
-
await
|
|
78
|
+
const manifestManager = services.imports.ManifestManager;
|
|
79
|
+
await manifestManager.initialize(workspaceDir);
|
|
80
80
|
// Load and parse the document
|
|
81
81
|
const uri = URI.file(absolutePath);
|
|
82
82
|
const document = await shared.workspace.LangiumDocuments.getOrCreateDocument(uri);
|
|
@@ -88,17 +88,20 @@ export async function validateFile(filePath, options = {}) {
|
|
|
88
88
|
// Build all documents with validation enabled
|
|
89
89
|
const allDocuments = Array.from(shared.workspace.LangiumDocuments.all);
|
|
90
90
|
await shared.workspace.DocumentBuilder.build(allDocuments, { validation: true });
|
|
91
|
-
// Collect diagnostics from
|
|
92
|
-
const diagnostics = document.diagnostics ?? [];
|
|
91
|
+
// Collect diagnostics from all loaded documents (entry + imports)
|
|
93
92
|
const errors = [];
|
|
94
93
|
const warnings = [];
|
|
95
|
-
for (const
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
for (const doc of allDocuments) {
|
|
95
|
+
const diagnostics = doc.diagnostics ?? [];
|
|
96
|
+
const diagnosticFile = doc.uri.fsPath;
|
|
97
|
+
for (const diagnostic of diagnostics) {
|
|
98
|
+
const validationDiag = toValidationDiagnostic(diagnostic, diagnosticFile);
|
|
99
|
+
if (diagnostic.severity === 1) {
|
|
100
|
+
errors.push(validationDiag);
|
|
101
|
+
}
|
|
102
|
+
else if (diagnostic.severity === 2) {
|
|
103
|
+
warnings.push(validationDiag);
|
|
104
|
+
}
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
// Count model elements across all documents
|
|
@@ -171,17 +174,17 @@ export async function validateWorkspace(workspaceDir) {
|
|
|
171
174
|
const servicesObj = createDomainLangServices(NodeFileSystem);
|
|
172
175
|
const shared = servicesObj.shared;
|
|
173
176
|
const services = servicesObj.DomainLang;
|
|
174
|
-
const
|
|
177
|
+
const manifestManager = services.imports.ManifestManager;
|
|
175
178
|
try {
|
|
176
179
|
// Initialize workspace - this will find and load model.yaml
|
|
177
|
-
await
|
|
180
|
+
await manifestManager.initialize(absolutePath);
|
|
178
181
|
}
|
|
179
182
|
catch (error) {
|
|
180
183
|
const message = error instanceof Error ? error.message : String(error);
|
|
181
184
|
throw new Error(`Failed to initialize workspace at ${workspaceDir}: ${message}`);
|
|
182
185
|
}
|
|
183
186
|
// Get the manifest to find the entry file
|
|
184
|
-
const manifest = await
|
|
187
|
+
const manifest = await manifestManager.getManifest();
|
|
185
188
|
let entryFile = 'index.dlang';
|
|
186
189
|
if (manifest?.model?.entry) {
|
|
187
190
|
entryFile = manifest.model.entry;
|
package/out/sdk/validator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/sdk/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AA4CrC;;GAEG;AACH,SAAS,sBAAsB,CAC3B,UAAyG,EACzG,IAAY;IAEZ,OAAO;QACH,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,CAAC;QAClC,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,IAAI;QACJ,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC;QACrC,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC;KAC/C,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MA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B,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAChC,CAAC;iBAAM,IAAI,UAAU,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;gBACnC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAClC,CAAC;QACL,CAAC;IACL,CAAC;IAED,4CAA4C;IAC5C,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC;QACrC,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACjB,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAC;gBACzC,IAAI,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;oBAC7B,WAAW,EAAE,CAAC;gBAClB,CAAC;qBAAM,IAAI,OAAO,CAAC,KAAK,KAAK,gBAAgB,EAAE,CAAC;oBAC5C,OAAO,EAAE,CAAC;gBACd,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO;QACH,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,SAAS,EAAE,YAAY,CAAC,MAAM;QAC9B,WAAW;QACX,OAAO;QACP,MAAM;QACN,QAAQ;QACR,gBAAgB,EAAE,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM;KACpD,CAAC;AACN,CAAC"}
|
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import { URI, type LangiumDocument } from 'langium';
|
|
2
2
|
import type { DomainLangServices } from '../domain-lang-module.js';
|
|
3
3
|
import type { LockFile } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Resolution failure reason codes for programmatic handling.
|
|
6
|
+
*/
|
|
7
|
+
export type ImportResolutionReason = 'file-not-found' | 'unknown-alias' | 'missing-manifest' | 'not-installed' | 'dependency-not-found' | 'missing-entry' | 'unresolvable';
|
|
8
|
+
/**
|
|
9
|
+
* Structured error for import resolution failures.
|
|
10
|
+
*
|
|
11
|
+
* Carries the specifier, attempted paths, a reason code, and
|
|
12
|
+
* a human-readable hint so callers can build precise diagnostics
|
|
13
|
+
* without parsing error message strings.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ImportResolutionError extends Error {
|
|
16
|
+
/** The import specifier that failed to resolve. */
|
|
17
|
+
readonly specifier: string;
|
|
18
|
+
/** Paths that were tried during resolution (in order). */
|
|
19
|
+
readonly attemptedPaths: readonly string[];
|
|
20
|
+
/** Machine-readable failure reason. */
|
|
21
|
+
readonly reason: ImportResolutionReason;
|
|
22
|
+
/** Human-readable suggestion for fixing the problem. */
|
|
23
|
+
readonly hint: string;
|
|
24
|
+
constructor(opts: {
|
|
25
|
+
specifier: string;
|
|
26
|
+
attemptedPaths?: string[];
|
|
27
|
+
reason: ImportResolutionReason;
|
|
28
|
+
hint: string;
|
|
29
|
+
message?: string;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
4
32
|
/**
|
|
5
33
|
* ImportResolver resolves import statements using manifest-centric rules (PRS-010).
|
|
6
34
|
*
|
|
@@ -13,45 +41,62 @@ import type { LockFile } from './types.js';
|
|
|
13
41
|
* - ./types → ./types/index.dlang → ./types.dlang
|
|
14
42
|
* - Module entry defaults to index.dlang (no model.yaml required)
|
|
15
43
|
*
|
|
16
|
-
* Caching Strategy (uses Langium standard infrastructure):
|
|
17
|
-
* - LSP mode: Uses `
|
|
18
|
-
*
|
|
44
|
+
* Caching Strategy (PRS-017 R1 — uses Langium standard infrastructure):
|
|
45
|
+
* - LSP mode: Uses `DocumentCache` keyed by importing document URI
|
|
46
|
+
* Each document's import resolutions are cached independently.
|
|
47
|
+
* When a document changes, only ITS cache entries are auto-cleared.
|
|
48
|
+
* Cross-document invalidation (when an imported file moves/deletes) is
|
|
49
|
+
* handled by DomainLangIndexManager calling `invalidateForDocuments()`
|
|
50
|
+
* with the reverse dependency graph.
|
|
19
51
|
* - Standalone mode: Uses `SimpleCache` - manual invalidation via clearCache()
|
|
20
52
|
*
|
|
21
|
-
* Why
|
|
22
|
-
* -
|
|
23
|
-
* -
|
|
24
|
-
* -
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* WorkspaceCache clears on ANY change, ensuring correct re-resolution
|
|
53
|
+
* Why DocumentCache with manual cross-invalidation (not WorkspaceCache)?
|
|
54
|
+
* - WorkspaceCache clears the ENTIRE cache on ANY document change
|
|
55
|
+
* - In a 50-file workspace, editing one file caused ~50 redundant re-resolutions
|
|
56
|
+
* - DocumentCache + targeted invalidation via reverse dep graph only clears
|
|
57
|
+
* the changed file and its direct/transitive importers
|
|
58
|
+
* - This matches gopls' per-package invalidation strategy
|
|
28
59
|
*
|
|
29
60
|
* @see https://langium.org/docs/recipes/caching/ for Langium caching patterns
|
|
30
61
|
*/
|
|
31
62
|
export declare class ImportResolver {
|
|
32
63
|
private readonly workspaceManager;
|
|
33
64
|
/**
|
|
34
|
-
*
|
|
35
|
-
* In LSP mode:
|
|
36
|
-
*
|
|
65
|
+
* Per-document cache for resolved import URIs.
|
|
66
|
+
* In LSP mode: DocumentCache - clears only the changed document's entries.
|
|
67
|
+
* Cross-document invalidation handled by DomainLangIndexManager.
|
|
68
|
+
* In standalone mode: SimpleCache - manual invalidation via clearCache().
|
|
37
69
|
*/
|
|
38
70
|
private readonly resolverCache;
|
|
71
|
+
/**
|
|
72
|
+
* Whether the cache is a DocumentCache (LSP mode) for targeted invalidation.
|
|
73
|
+
*/
|
|
74
|
+
private readonly isDocumentCache;
|
|
39
75
|
/**
|
|
40
76
|
* Creates an ImportResolver.
|
|
41
77
|
*
|
|
42
|
-
* @param services - DomainLang services. If `services.shared` is present, uses
|
|
43
|
-
* for
|
|
78
|
+
* @param services - DomainLang services. If `services.shared` is present, uses DocumentCache
|
|
79
|
+
* for per-document invalidation. Otherwise uses SimpleCache for standalone mode.
|
|
44
80
|
*/
|
|
45
81
|
constructor(services: DomainLangServices);
|
|
46
82
|
/**
|
|
47
83
|
* Clears the entire import resolution cache.
|
|
48
|
-
* In LSP mode, this is also triggered automatically by WorkspaceCache on any document change.
|
|
49
84
|
* Call explicitly when model.yaml or model.lock changes.
|
|
50
85
|
*/
|
|
51
86
|
clearCache(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Invalidates cached import resolutions for specific documents (PRS-017 R1).
|
|
89
|
+
*
|
|
90
|
+
* Called by DomainLangIndexManager when files change, using the reverse
|
|
91
|
+
* dependency graph to determine which documents' caches need clearing.
|
|
92
|
+
* This provides targeted invalidation instead of clearing the entire cache.
|
|
93
|
+
*
|
|
94
|
+
* @param uris - Document URIs whose import resolution caches should be cleared
|
|
95
|
+
*/
|
|
96
|
+
invalidateForDocuments(uris: Iterable<string>): void;
|
|
52
97
|
/**
|
|
53
98
|
* Resolve an import specifier relative to a Langium document.
|
|
54
|
-
* Results are cached using
|
|
99
|
+
* Results are cached per-document using DocumentCache (PRS-017 R1).
|
|
55
100
|
*/
|
|
56
101
|
resolveForDocument(document: LangiumDocument, specifier: string): Promise<URI>;
|
|
57
102
|
/**
|
|
@@ -111,4 +156,9 @@ export declare class ImportResolver {
|
|
|
111
156
|
* Get the current lock file (if loaded).
|
|
112
157
|
*/
|
|
113
158
|
getLockFile(): Promise<LockFile | undefined>;
|
|
159
|
+
/**
|
|
160
|
+
* Logs an import resolution trace message when `domainlang.lsp.traceImports` is enabled.
|
|
161
|
+
* Output goes to stderr so it's visible in the LSP output channel.
|
|
162
|
+
*/
|
|
163
|
+
private trace;
|
|
114
164
|
}
|