@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
|
@@ -7,6 +7,9 @@ import type { ImportInfo } from '../services/types.js';
|
|
|
7
7
|
* Custom IndexManager that extends Langium's default to:
|
|
8
8
|
* 1. Automatically load imported documents during indexing
|
|
9
9
|
* 2. Track import dependencies for cross-file revalidation
|
|
10
|
+
* 3. Export-signature diffing to prevent unnecessary cascading (PRS-017 R2)
|
|
11
|
+
* 4. Import cycle detection with diagnostics (PRS-017 R3)
|
|
12
|
+
* 5. Targeted ImportResolver cache invalidation (PRS-017 R1)
|
|
10
13
|
*
|
|
11
14
|
* **Why this exists:**
|
|
12
15
|
* Langium's `DefaultIndexManager.isAffected()` only checks cross-references
|
|
@@ -46,6 +49,31 @@ export declare class DomainLangIndexManager extends DefaultIndexManager {
|
|
|
46
49
|
* Cleared on workspace config changes.
|
|
47
50
|
*/
|
|
48
51
|
private readonly importsLoaded;
|
|
52
|
+
/**
|
|
53
|
+
* Per-cycle cache for the transitive affected set computation.
|
|
54
|
+
* Uses `changedUris` Set identity as cache key — Langium creates a fresh Set
|
|
55
|
+
* for each `DocumentBuilder.update()` cycle, so reference equality naturally
|
|
56
|
+
* invalidates the cache between cycles.
|
|
57
|
+
*/
|
|
58
|
+
private transitiveAffectedCache;
|
|
59
|
+
/**
|
|
60
|
+
* Export snapshot cache (PRS-017 R2): maps document URI to its exported symbol
|
|
61
|
+
* signatures. Used to detect whether a document's public interface actually
|
|
62
|
+
* changed, preventing cascading revalidation for implementation-only changes.
|
|
63
|
+
* Signature = "nodeType:qualifiedName" for each exported symbol.
|
|
64
|
+
*/
|
|
65
|
+
private readonly exportSnapshots;
|
|
66
|
+
/**
|
|
67
|
+
* Tracks which URIs had their exports actually change during the current
|
|
68
|
+
* update cycle. Reset before each updateContent() call. Used by isAffected()
|
|
69
|
+
* to skip transitive invalidation when exports are unchanged.
|
|
70
|
+
*/
|
|
71
|
+
private readonly changedExports;
|
|
72
|
+
/**
|
|
73
|
+
* Detected import cycles (PRS-017 R3): maps document URI to the cycle path.
|
|
74
|
+
* Populated during trackImportDependencies(). Consumed by ImportValidator.
|
|
75
|
+
*/
|
|
76
|
+
private readonly detectedCycles;
|
|
49
77
|
/**
|
|
50
78
|
* Reference to shared services for accessing LangiumDocuments.
|
|
51
79
|
*/
|
|
@@ -72,8 +100,12 @@ export declare class DomainLangIndexManager extends DefaultIndexManager {
|
|
|
72
100
|
private resolveImport;
|
|
73
101
|
/**
|
|
74
102
|
* Extends the default content update to:
|
|
75
|
-
* 1.
|
|
76
|
-
* 2.
|
|
103
|
+
* 1. Capture export snapshot before update (PRS-017 R2)
|
|
104
|
+
* 2. Ensure all imported documents are loaded
|
|
105
|
+
* 3. Track import dependencies for change propagation
|
|
106
|
+
* 4. Compare export snapshot to detect interface changes (PRS-017 R2)
|
|
107
|
+
* 5. Detect import cycles (PRS-017 R3)
|
|
108
|
+
* 6. Trigger targeted ImportResolver cache invalidation (PRS-017 R1)
|
|
77
109
|
*
|
|
78
110
|
* Called by Langium during the IndexedContent build phase.
|
|
79
111
|
* This is BEFORE linking/validation, so imports are available for resolution.
|
|
@@ -88,13 +120,42 @@ export declare class DomainLangIndexManager extends DefaultIndexManager {
|
|
|
88
120
|
*/
|
|
89
121
|
removeContent(uri: URI): void;
|
|
90
122
|
/**
|
|
91
|
-
* Extends `isAffected` to
|
|
123
|
+
* Extends `isAffected` to check import dependencies — direct, transitive,
|
|
124
|
+
* and specifier-sensitive.
|
|
92
125
|
*
|
|
93
126
|
* A document is affected if:
|
|
94
127
|
* 1. It has cross-references to any changed document (default Langium behavior)
|
|
95
|
-
* 2. It imports any
|
|
128
|
+
* 2. It directly or transitively imports any changed document whose exports
|
|
129
|
+
* actually changed (PRS-017 R2 — export-signature diffing)
|
|
130
|
+
* 3. Its import specifiers match changed file paths (handles renames/moves)
|
|
131
|
+
*
|
|
132
|
+
* The transitive affected set is computed once per `update()` cycle and cached
|
|
133
|
+
* using `changedUris` Set identity (Langium creates a fresh Set per cycle).
|
|
134
|
+
* This avoids redundant BFS walks when `isAffected()` is called for every
|
|
135
|
+
* loaded document in the workspace.
|
|
96
136
|
*/
|
|
97
137
|
isAffected(document: LangiumDocument, changedUris: Set<string>): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Computes the full set of document URIs affected by changes.
|
|
140
|
+
* Cached per `changedUris` identity to avoid recomputation across multiple
|
|
141
|
+
* `isAffected()` calls within the same `DocumentBuilder.update()` cycle.
|
|
142
|
+
*
|
|
143
|
+
* Combines two dependency strategies:
|
|
144
|
+
* 1. **Reverse graph walk** — direct and transitive importers via `importDependencies`
|
|
145
|
+
* 2. **Specifier matching** — documents whose import specifiers match changed file
|
|
146
|
+
* paths (handles file renames/moves that change how imports resolve)
|
|
147
|
+
*/
|
|
148
|
+
private computeAffectedSet;
|
|
149
|
+
/**
|
|
150
|
+
* BFS through the reverse dependency graph to find all transitive importers.
|
|
151
|
+
* If C changes and B imports C and A imports B, both A and B are added.
|
|
152
|
+
*/
|
|
153
|
+
private addTransitiveDependents;
|
|
154
|
+
/**
|
|
155
|
+
* Finds documents whose import specifiers fuzzy-match changed file paths.
|
|
156
|
+
* Handles file renames/moves where the resolved URI hasn't been updated yet.
|
|
157
|
+
*/
|
|
158
|
+
private addSpecifierMatches;
|
|
98
159
|
/**
|
|
99
160
|
* Tracks import dependencies for a document.
|
|
100
161
|
* For each import in the document, records:
|
|
@@ -102,6 +163,15 @@ export declare class DomainLangIndexManager extends DefaultIndexManager {
|
|
|
102
163
|
* 2. The import specifier and alias (for scope resolution)
|
|
103
164
|
*/
|
|
104
165
|
private trackImportDependencies;
|
|
166
|
+
/**
|
|
167
|
+
* Resolves a single import and registers it in the reverse dependency graph.
|
|
168
|
+
* Falls back to searching loaded documents when the filesystem resolver fails.
|
|
169
|
+
*/
|
|
170
|
+
private resolveAndTrackImport;
|
|
171
|
+
/**
|
|
172
|
+
* Adds an edge to the reverse dependency graph: importedUri → importingUri.
|
|
173
|
+
*/
|
|
174
|
+
private addToDependencyGraph;
|
|
105
175
|
/**
|
|
106
176
|
* Ensures all imported documents are loaded and available.
|
|
107
177
|
* This is called during indexing, BEFORE linking/validation,
|
|
@@ -125,6 +195,12 @@ export declare class DomainLangIndexManager extends DefaultIndexManager {
|
|
|
125
195
|
* Call this when workspace configuration changes.
|
|
126
196
|
*/
|
|
127
197
|
clearImportDependencies(): void;
|
|
198
|
+
/**
|
|
199
|
+
* Fallback for import resolution: searches loaded documents for one whose
|
|
200
|
+
* URI path matches the import specifier. Used when the filesystem-based
|
|
201
|
+
* resolver fails (e.g., unsaved files, EmptyFileSystem in tests).
|
|
202
|
+
*/
|
|
203
|
+
private findLoadedDocumentByPath;
|
|
128
204
|
/**
|
|
129
205
|
* Marks a document as needing import re-loading.
|
|
130
206
|
* Called when a document's content changes.
|
|
@@ -186,7 +262,11 @@ export declare class DomainLangIndexManager extends DefaultIndexManager {
|
|
|
186
262
|
*/
|
|
187
263
|
private findDocumentsMatchingPaths;
|
|
188
264
|
/**
|
|
189
|
-
* Checks if any specifier OR its resolved URI matches the changed paths.
|
|
265
|
+
* Checks if any specifier OR its resolved URI matches the changed paths (PRS-017 R4).
|
|
266
|
+
*
|
|
267
|
+
* Uses exact filename matching instead of substring matching to prevent
|
|
268
|
+
* false positives (e.g., changing `sales.dlang` should NOT trigger
|
|
269
|
+
* revalidation of a file importing `pre-sales.dlang`).
|
|
190
270
|
*
|
|
191
271
|
* This handles both regular imports and path aliases:
|
|
192
272
|
* - Regular: `./domains/sales.dlang` matches path `sales.dlang`
|
|
@@ -196,4 +276,68 @@ export declare class DomainLangIndexManager extends DefaultIndexManager {
|
|
|
196
276
|
* We check both to ensure moves of aliased imports trigger revalidation.
|
|
197
277
|
*/
|
|
198
278
|
private hasMatchingSpecifierOrResolvedUri;
|
|
279
|
+
/**
|
|
280
|
+
* Checks if a single import info matches any of the changed paths.
|
|
281
|
+
* Extracted to reduce cognitive complexity of hasMatchingSpecifierOrResolvedUri.
|
|
282
|
+
*/
|
|
283
|
+
private matchesAnyChangedPath;
|
|
284
|
+
/**
|
|
285
|
+
* Checks if a single import info matches a single changed path.
|
|
286
|
+
*/
|
|
287
|
+
private matchesChangedPath;
|
|
288
|
+
/**
|
|
289
|
+
* Checks if a resolved URI matches a changed path by exact filename comparison.
|
|
290
|
+
*/
|
|
291
|
+
private matchesResolvedUri;
|
|
292
|
+
/**
|
|
293
|
+
* Checks if an import specifier matches a changed path by exact filename comparison.
|
|
294
|
+
*/
|
|
295
|
+
private matchesSpecifier;
|
|
296
|
+
/**
|
|
297
|
+
* Extracts the filename (without extension) from a path or URI string.
|
|
298
|
+
*/
|
|
299
|
+
private extractFileName;
|
|
300
|
+
/**
|
|
301
|
+
* Checks if longPath ends with shortPath, comparing path segments.
|
|
302
|
+
* Prevents substring false positives (e.g., "pre-sales" matching "sales").
|
|
303
|
+
*/
|
|
304
|
+
private pathEndsWith;
|
|
305
|
+
/**
|
|
306
|
+
* Captures a snapshot of exported symbol signatures for a document.
|
|
307
|
+
* Signature = "nodeType:qualifiedName" for each exported symbol.
|
|
308
|
+
* Used to detect whether a document's public interface actually changed.
|
|
309
|
+
*/
|
|
310
|
+
private captureExportSnapshot;
|
|
311
|
+
/**
|
|
312
|
+
* Checks if two sets of strings are equal (same size and same elements).
|
|
313
|
+
*/
|
|
314
|
+
private setsEqual;
|
|
315
|
+
/**
|
|
316
|
+
* Returns true if any of the changed URIs had their exports actually change.
|
|
317
|
+
* Used by isAffected() to skip transitive invalidation when only
|
|
318
|
+
* implementation details changed (e.g., editing a vision string).
|
|
319
|
+
*/
|
|
320
|
+
private anyExportsChanged;
|
|
321
|
+
/**
|
|
322
|
+
* Detects import cycles starting from a given document URI.
|
|
323
|
+
* Uses DFS with a recursion stack to find back-edges in the import graph.
|
|
324
|
+
* Stores detected cycles for reporting by ImportValidator.
|
|
325
|
+
*/
|
|
326
|
+
private detectAndStoreCycles;
|
|
327
|
+
/**
|
|
328
|
+
* DFS to find a cycle in the forward import graph starting from startUri.
|
|
329
|
+
* Returns the cycle path (e.g., [A, B, C, A]) if found, undefined otherwise.
|
|
330
|
+
*/
|
|
331
|
+
private findCycle;
|
|
332
|
+
/**
|
|
333
|
+
* Gets the detected import cycle for a document, if any.
|
|
334
|
+
* Returns the cycle path as an array of URIs, or undefined if no cycle.
|
|
335
|
+
* Used by ImportValidator to report cycle diagnostics (PRS-017 R3).
|
|
336
|
+
*/
|
|
337
|
+
getCycleForDocument(uri: string): string[] | undefined;
|
|
338
|
+
/**
|
|
339
|
+
* Invalidates the ImportResolver cache for the changed document and its dependents.
|
|
340
|
+
* This provides surgical cache invalidation instead of clearing the entire cache.
|
|
341
|
+
*/
|
|
342
|
+
private invalidateImportResolverCache;
|
|
199
343
|
}
|