@domainlang/language 0.6.0 → 0.8.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 +1 -1
- package/out/domain-lang-module.d.ts +2 -0
- package/out/domain-lang-module.js +23 -2
- package/out/domain-lang-module.js.map +1 -1
- package/out/lsp/domain-lang-completion.d.ts +142 -1
- package/out/lsp/domain-lang-completion.js +620 -22
- package/out/lsp/domain-lang-completion.js.map +1 -1
- package/out/lsp/domain-lang-document-symbol-provider.d.ts +79 -0
- package/out/lsp/domain-lang-document-symbol-provider.js +210 -0
- package/out/lsp/domain-lang-document-symbol-provider.js.map +1 -0
- package/out/lsp/domain-lang-index-manager.d.ts +98 -1
- package/out/lsp/domain-lang-index-manager.js +214 -7
- package/out/lsp/domain-lang-index-manager.js.map +1 -1
- package/out/lsp/domain-lang-node-kind-provider.d.ts +27 -0
- package/out/lsp/domain-lang-node-kind-provider.js +87 -0
- package/out/lsp/domain-lang-node-kind-provider.js.map +1 -0
- package/out/lsp/domain-lang-scope-provider.d.ts +100 -0
- package/out/lsp/domain-lang-scope-provider.js +170 -0
- package/out/lsp/domain-lang-scope-provider.js.map +1 -0
- package/out/lsp/domain-lang-workspace-manager.d.ts +46 -0
- package/out/lsp/domain-lang-workspace-manager.js +148 -4
- package/out/lsp/domain-lang-workspace-manager.js.map +1 -1
- package/out/lsp/hover/domain-lang-hover.d.ts +16 -6
- package/out/lsp/hover/domain-lang-hover.js +160 -134
- package/out/lsp/hover/domain-lang-hover.js.map +1 -1
- package/out/lsp/hover/hover-builders.d.ts +57 -0
- package/out/lsp/hover/hover-builders.js +171 -0
- package/out/lsp/hover/hover-builders.js.map +1 -0
- package/out/main.js +116 -20
- package/out/main.js.map +1 -1
- package/out/sdk/index.d.ts +2 -1
- package/out/sdk/index.js +1 -1
- 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/loader.d.ts +55 -2
- package/out/sdk/loader.js +87 -28
- package/out/sdk/loader.js.map +1 -1
- package/out/sdk/query.js +14 -11
- package/out/sdk/query.js.map +1 -1
- package/out/services/import-resolver.d.ts +29 -6
- package/out/services/import-resolver.js +48 -9
- package/out/services/import-resolver.js.map +1 -1
- package/out/services/package-boundary-detector.d.ts +101 -0
- package/out/services/package-boundary-detector.js +211 -0
- package/out/services/package-boundary-detector.js.map +1 -0
- package/out/services/performance-optimizer.js +6 -2
- package/out/services/performance-optimizer.js.map +1 -1
- package/out/services/types.d.ts +24 -0
- package/out/services/types.js.map +1 -1
- package/out/services/workspace-manager.d.ts +73 -6
- package/out/services/workspace-manager.js +210 -57
- package/out/services/workspace-manager.js.map +1 -1
- package/out/utils/import-utils.d.ts +9 -6
- package/out/utils/import-utils.js +26 -15
- package/out/utils/import-utils.js.map +1 -1
- package/out/validation/constants.d.ts +20 -0
- package/out/validation/constants.js +39 -3
- package/out/validation/constants.js.map +1 -1
- package/out/validation/import.d.ts +22 -1
- package/out/validation/import.js +104 -16
- package/out/validation/import.js.map +1 -1
- package/out/validation/maps.js +101 -3
- package/out/validation/maps.js.map +1 -1
- package/package.json +5 -5
- package/src/domain-lang-module.ts +26 -3
- package/src/lsp/domain-lang-completion.ts +736 -27
- package/src/lsp/domain-lang-document-symbol-provider.ts +254 -0
- package/src/lsp/domain-lang-index-manager.ts +250 -7
- package/src/lsp/domain-lang-node-kind-provider.ts +119 -0
- package/src/lsp/domain-lang-scope-provider.ts +250 -0
- package/src/lsp/domain-lang-workspace-manager.ts +187 -4
- package/src/lsp/hover/domain-lang-hover.ts +189 -131
- package/src/lsp/hover/hover-builders.ts +208 -0
- package/src/main.ts +156 -23
- package/src/sdk/index.ts +2 -1
- package/src/sdk/loader-node.ts +2 -1
- package/src/sdk/loader.ts +125 -34
- package/src/sdk/query.ts +15 -11
- package/src/services/import-resolver.ts +60 -9
- package/src/services/package-boundary-detector.ts +238 -0
- package/src/services/performance-optimizer.ts +6 -2
- package/src/services/types.ts +25 -0
- package/src/services/workspace-manager.ts +259 -62
- package/src/utils/import-utils.ts +27 -15
- package/src/validation/constants.ts +47 -6
- package/src/validation/import.ts +124 -16
- package/src/validation/maps.ts +118 -4
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package Boundary Detector
|
|
3
|
+
*
|
|
4
|
+
* Determines package boundaries for import scoping.
|
|
5
|
+
* Per ADR-003, package boundaries are defined by:
|
|
6
|
+
* - External packages: Files within .dlang/packages/ sharing the same model.yaml
|
|
7
|
+
* - Local files: Each file is its own boundary (non-transitive)
|
|
8
|
+
*
|
|
9
|
+
* Used by DomainLangScopeProvider to enable transitive imports within
|
|
10
|
+
* package boundaries while keeping local file imports non-transitive.
|
|
11
|
+
*/
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
import * as fs from 'node:fs/promises';
|
|
14
|
+
import { URI } from 'langium';
|
|
15
|
+
/**
|
|
16
|
+
* Detects and caches package boundaries for efficient scope resolution.
|
|
17
|
+
*/
|
|
18
|
+
export class PackageBoundaryDetector {
|
|
19
|
+
constructor() {
|
|
20
|
+
/**
|
|
21
|
+
* Cache mapping document URI to its package root path.
|
|
22
|
+
* - External packages: path to directory containing model.yaml
|
|
23
|
+
* - Local files: null (no package boundary)
|
|
24
|
+
*/
|
|
25
|
+
this.packageRootCache = new Map();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Determines if a document is part of an external package.
|
|
29
|
+
*
|
|
30
|
+
* External packages are stored in .dlang/packages/owner/repo/commit/
|
|
31
|
+
*
|
|
32
|
+
* @param documentUri - The URI of the document to check
|
|
33
|
+
* @returns true if document is in an external package
|
|
34
|
+
*/
|
|
35
|
+
isExternalPackage(documentUri) {
|
|
36
|
+
const fsPath = this.toFsPath(documentUri);
|
|
37
|
+
const normalized = fsPath.split(path.sep);
|
|
38
|
+
// Check if path contains .dlang/packages/
|
|
39
|
+
const dlangIndex = normalized.indexOf('.dlang');
|
|
40
|
+
if (dlangIndex === -1) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return dlangIndex + 1 < normalized.length &&
|
|
44
|
+
normalized[dlangIndex + 1] === 'packages';
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the package root for a document.
|
|
48
|
+
*
|
|
49
|
+
* For external packages (.dlang/packages/), walks up from the document
|
|
50
|
+
* to find the nearest model.yaml file within the package structure.
|
|
51
|
+
*
|
|
52
|
+
* For local files, returns null (no package boundary).
|
|
53
|
+
*
|
|
54
|
+
* @param documentUri - The URI of the document
|
|
55
|
+
* @returns Absolute path to package root, or null if not in a package
|
|
56
|
+
*/
|
|
57
|
+
async getPackageRoot(documentUri) {
|
|
58
|
+
const uriString = documentUri.toString();
|
|
59
|
+
// Check cache first
|
|
60
|
+
if (this.packageRootCache.has(uriString)) {
|
|
61
|
+
return this.packageRootCache.get(uriString) ?? null;
|
|
62
|
+
}
|
|
63
|
+
// If not an external package, it has no package boundary
|
|
64
|
+
if (!this.isExternalPackage(documentUri)) {
|
|
65
|
+
this.packageRootCache.set(uriString, null);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const fsPath = this.toFsPath(documentUri);
|
|
69
|
+
const packageRoot = await this.findPackageRootForExternal(fsPath);
|
|
70
|
+
this.packageRootCache.set(uriString, packageRoot);
|
|
71
|
+
return packageRoot;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Checks if two documents are in the same package (synchronous heuristic).
|
|
75
|
+
*
|
|
76
|
+
* This is a fast, synchronous check that compares package commit directories
|
|
77
|
+
* without filesystem access. Documents are in the same package if:
|
|
78
|
+
* - Both are in .dlang/packages/ AND
|
|
79
|
+
* - They share the same owner/repo/commit path
|
|
80
|
+
*
|
|
81
|
+
* This is used by the scope provider which needs synchronous access.
|
|
82
|
+
*
|
|
83
|
+
* Structure: .dlang/packages/owner/repo/commit/...
|
|
84
|
+
*
|
|
85
|
+
* @param doc1Uri - URI of first document
|
|
86
|
+
* @param doc2Uri - URI of second document
|
|
87
|
+
* @returns true if both are in the same package commit directory
|
|
88
|
+
*/
|
|
89
|
+
areInSamePackageSync(doc1Uri, doc2Uri) {
|
|
90
|
+
// Both must be external packages
|
|
91
|
+
if (!this.isExternalPackage(doc1Uri) || !this.isExternalPackage(doc2Uri)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const path1 = this.toFsPath(doc1Uri);
|
|
95
|
+
const path2 = this.toFsPath(doc2Uri);
|
|
96
|
+
const root1 = this.getPackageCommitDirectory(path1);
|
|
97
|
+
const root2 = this.getPackageCommitDirectory(path2);
|
|
98
|
+
return root1 !== null && root1 === root2;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets the package commit directory (owner/repo/commit) from a path.
|
|
102
|
+
*
|
|
103
|
+
* @param fsPath - Filesystem path
|
|
104
|
+
* @returns Commit directory path or null
|
|
105
|
+
*/
|
|
106
|
+
getPackageCommitDirectory(fsPath) {
|
|
107
|
+
const normalized = fsPath.split(path.sep);
|
|
108
|
+
const dlangIndex = normalized.indexOf('.dlang');
|
|
109
|
+
if (dlangIndex === -1) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const packagesIndex = dlangIndex + 1;
|
|
113
|
+
if (packagesIndex >= normalized.length || normalized[packagesIndex] !== 'packages') {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
// Commit directory is at: .dlang/packages/owner/repo/commit
|
|
117
|
+
const commitIndex = packagesIndex + 3;
|
|
118
|
+
if (commitIndex >= normalized.length) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
// Return the path up to and including the commit directory
|
|
122
|
+
return normalized.slice(0, commitIndex + 1).join(path.sep);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Checks if two documents are in the same package.
|
|
126
|
+
*
|
|
127
|
+
* Documents are in the same package if:
|
|
128
|
+
* - Both are external packages AND
|
|
129
|
+
* - They share the same package root (model.yaml location)
|
|
130
|
+
*
|
|
131
|
+
* Local files are never in the same package (each is isolated).
|
|
132
|
+
*
|
|
133
|
+
* @param doc1Uri - URI of first document
|
|
134
|
+
* @param doc2Uri - URI of second document
|
|
135
|
+
* @returns true if both documents are in the same package
|
|
136
|
+
*/
|
|
137
|
+
async areInSamePackage(doc1Uri, doc2Uri) {
|
|
138
|
+
const root1 = await this.getPackageRoot(doc1Uri);
|
|
139
|
+
const root2 = await this.getPackageRoot(doc2Uri);
|
|
140
|
+
// If either is not in a package, they can't be in the same package
|
|
141
|
+
if (!root1 || !root2) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return root1 === root2;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Finds the package root for an external package by walking up to find model.yaml.
|
|
148
|
+
*
|
|
149
|
+
* External packages have structure: .dlang/packages/owner/repo/commit/...
|
|
150
|
+
* The model.yaml should be at the commit level or just below it.
|
|
151
|
+
*
|
|
152
|
+
* @param fsPath - Filesystem path of the document
|
|
153
|
+
* @returns Path to directory containing model.yaml, or null
|
|
154
|
+
*/
|
|
155
|
+
async findPackageRootForExternal(fsPath) {
|
|
156
|
+
const normalized = fsPath.split(path.sep);
|
|
157
|
+
const dlangIndex = normalized.indexOf('.dlang');
|
|
158
|
+
if (dlangIndex === -1) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
// Find the packages directory
|
|
162
|
+
const packagesIndex = dlangIndex + 1;
|
|
163
|
+
if (packagesIndex >= normalized.length || normalized[packagesIndex] !== 'packages') {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
// Start from the commit directory level
|
|
167
|
+
// Structure: .dlang/packages/owner/repo/commit/
|
|
168
|
+
const commitIndex = packagesIndex + 3;
|
|
169
|
+
if (commitIndex >= normalized.length) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
// Walk up from the document path to the commit directory
|
|
173
|
+
let currentPath = path.dirname(fsPath);
|
|
174
|
+
const commitPath = normalized.slice(0, commitIndex + 1).join(path.sep);
|
|
175
|
+
// Search upward for model.yaml, but don't go above the commit directory
|
|
176
|
+
while (currentPath.length >= commitPath.length) {
|
|
177
|
+
const manifestPath = path.join(currentPath, 'model.yaml');
|
|
178
|
+
try {
|
|
179
|
+
await fs.access(manifestPath);
|
|
180
|
+
return currentPath;
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// model.yaml not found at this level, continue upward
|
|
184
|
+
}
|
|
185
|
+
const parent = path.dirname(currentPath);
|
|
186
|
+
if (parent === currentPath) {
|
|
187
|
+
// Reached filesystem root without finding model.yaml
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
currentPath = parent;
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Converts a URI to a filesystem path.
|
|
196
|
+
*/
|
|
197
|
+
toFsPath(uri) {
|
|
198
|
+
if (typeof uri === 'string') {
|
|
199
|
+
uri = URI.parse(uri);
|
|
200
|
+
}
|
|
201
|
+
return uri.fsPath;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Clears the package root cache.
|
|
205
|
+
* Call this when packages are installed/removed.
|
|
206
|
+
*/
|
|
207
|
+
clearCache() {
|
|
208
|
+
this.packageRootCache.clear();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=package-boundary-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-boundary-detector.js","sourceRoot":"","sources":["../../src/services/package-boundary-detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAE9B;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAApC;QACI;;;;WAIG;QACc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C,OAAO,CAAC,MAAM,CAAC,CAAC;QACvC,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEvE,wEAAwE;QACxE,OAAO,WAAW,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;YAC7C,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;YAC1D,IAAI,CAAC;gBACD,MAAM,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBAC9B,OAAO,WAAW,CAAC;YACvB,CAAC;YAAC,MAAM,CAAC;gBACL,sDAAsD;YAC1D,CAAC;YAED,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YACzC,IAAI,MAAM,KAAK,WAAW,EAAE,CAAC;gBACzB,qDAAqD;gBACrD,MAAM;YACV,CAAC;YACD,WAAW,GAAG,MAAM,CAAC;QACzB,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACK,QAAQ,CAAC,GAAiB;QAC9B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC1B,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;QACD,OAAO,GAAG,CAAC,MAAM,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,UAAU;QACN,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IAClC,CAAC;CACJ"}
|
|
@@ -56,7 +56,8 @@ export class PerformanceOptimizer {
|
|
|
56
56
|
}
|
|
57
57
|
try {
|
|
58
58
|
const content = await fs.readFile(manifestPath, 'utf-8');
|
|
59
|
-
const
|
|
59
|
+
const { parse } = await import('yaml');
|
|
60
|
+
const manifest = parse(content);
|
|
60
61
|
this.manifestCache.set(cacheKey, {
|
|
61
62
|
value: manifest,
|
|
62
63
|
timestamp: Date.now(),
|
|
@@ -100,7 +101,10 @@ export class PerformanceOptimizer {
|
|
|
100
101
|
try {
|
|
101
102
|
const stat = await fs.stat(lockPath);
|
|
102
103
|
const cached = this.lockFileCache.get(workspaceRoot);
|
|
103
|
-
|
|
104
|
+
// Floor mtimeMs to integer precision to match Date.now() —
|
|
105
|
+
// some filesystems (e.g. APFS) report sub-millisecond mtime,
|
|
106
|
+
// which can exceed the integer timestamp from Date.now().
|
|
107
|
+
if (cached && Math.floor(stat.mtimeMs) > cached.timestamp) {
|
|
104
108
|
stale.push(workspaceRoot);
|
|
105
109
|
}
|
|
106
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performance-optimizer.js","sourceRoot":"","sources":["../../src/services/performance-optimizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAUlC;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAK7B,YAAY,UAAiC,EAAE;QAJvC,kBAAa,GAAG,IAAI,GAAG,EAAgC,CAAC;QACxD,kBAAa,GAAG,IAAI,GAAG,EAA+B,CAAC;QAI3D,yBAAyB;QACzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAAiB,CAAC,aAAqB;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAEhD,gCAAgC;QAChC,IAAI,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1D,OAAO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|
|
39
39
|
*/
|
|
40
|
+
/**
|
|
41
|
+
* Information about an import statement tracked during indexing.
|
|
42
|
+
*
|
|
43
|
+
* Used by IndexManager to track both the import's resolved location
|
|
44
|
+
* and its alias (if any) for scope resolution.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // import "larsbaunwall/ddd-types" as ddd
|
|
49
|
+
* const info: ImportInfo = {
|
|
50
|
+
* specifier: "larsbaunwall/ddd-types",
|
|
51
|
+
* alias: "ddd",
|
|
52
|
+
* resolvedUri: "file:///.dlang/packages/larsbaunwall/ddd-types/abc123/index.dlang"
|
|
53
|
+
* };
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export interface ImportInfo {
|
|
57
|
+
/** The import specifier as written in source (e.g., "./file.dlang", "owner/repo") */
|
|
58
|
+
readonly specifier: string;
|
|
59
|
+
/** Optional alias from 'as' clause (e.g., "ddd" in 'import "pkg" as ddd') */
|
|
60
|
+
readonly alias?: string;
|
|
61
|
+
/** Resolved absolute URI of the imported document */
|
|
62
|
+
readonly resolvedUri: string;
|
|
63
|
+
}
|
|
40
64
|
/**
|
|
41
65
|
* Type of git reference for version pinning.
|
|
42
66
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/services/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/services/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAwIH;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAmB;IACxD,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,CAAC;AACnD,CAAC"}
|
|
@@ -2,6 +2,11 @@ import type { LockFile, ModelManifest, DependencySpec, ExtendedDependencySpec, P
|
|
|
2
2
|
/**
|
|
3
3
|
* Coordinates workspace discovery and manifest/lock file reading.
|
|
4
4
|
*
|
|
5
|
+
* **Multi-Root Support:**
|
|
6
|
+
* Maintains separate contexts for each workspace root (directory with model.yaml).
|
|
7
|
+
* This enables correct resolution in multi-project setups where sub-projects
|
|
8
|
+
* have their own model.yaml files.
|
|
9
|
+
*
|
|
5
10
|
* This is a read-only service for the LSP - it does NOT:
|
|
6
11
|
* - Generate lock files (use CLI: `dlang install`)
|
|
7
12
|
* - Download packages (use CLI: `dlang install`)
|
|
@@ -15,16 +20,41 @@ import type { LockFile, ModelManifest, DependencySpec, ExtendedDependencySpec, P
|
|
|
15
20
|
export declare class WorkspaceManager {
|
|
16
21
|
private readonly manifestFiles;
|
|
17
22
|
private readonly lockFiles;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Cache of workspace contexts by resolved workspace root path.
|
|
25
|
+
* Supports multiple independent workspaces in a single session.
|
|
26
|
+
*/
|
|
27
|
+
private readonly workspaceContexts;
|
|
28
|
+
/**
|
|
29
|
+
* Cache mapping start paths to their resolved workspace roots.
|
|
30
|
+
* Avoids repeated directory tree walking for the same paths.
|
|
31
|
+
*/
|
|
32
|
+
private readonly pathToRootCache;
|
|
33
|
+
/**
|
|
34
|
+
* The currently active workspace root (set by last initialize() call).
|
|
35
|
+
* Used by methods like getWorkspaceRoot(), getManifest(), etc.
|
|
36
|
+
*/
|
|
37
|
+
private activeRoot;
|
|
22
38
|
constructor(options?: WorkspaceManagerOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Returns the active workspace context, or undefined if not initialized.
|
|
41
|
+
* All methods that need context should call this after ensureInitialized().
|
|
42
|
+
*/
|
|
43
|
+
private getActiveContext;
|
|
23
44
|
/**
|
|
24
45
|
* Finds the workspace root and loads any existing lock file.
|
|
25
|
-
*
|
|
46
|
+
*
|
|
47
|
+
* **Multi-Root Support:**
|
|
48
|
+
* Each call may switch to a different workspace context based on the startPath.
|
|
49
|
+
* The workspace root is the nearest ancestor directory containing model.yaml.
|
|
50
|
+
*
|
|
51
|
+
* @param startPath - Directory to start searching from (usually document directory)
|
|
26
52
|
*/
|
|
27
53
|
initialize(startPath: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Initializes a workspace context by loading its lock file.
|
|
56
|
+
*/
|
|
57
|
+
private initializeContext;
|
|
28
58
|
/**
|
|
29
59
|
* Returns the absolute path of the workspace root.
|
|
30
60
|
* @throws Error if {@link initialize} has not completed successfully.
|
|
@@ -33,8 +63,19 @@ export declare class WorkspaceManager {
|
|
|
33
63
|
/**
|
|
34
64
|
* Returns the project-local package cache directory.
|
|
35
65
|
* Per PRS-010: .dlang/packages/
|
|
66
|
+
*
|
|
67
|
+
* If the current workspace root is inside a cached package,
|
|
68
|
+
* walks up to find the actual project root's cache directory.
|
|
36
69
|
*/
|
|
37
70
|
getCacheDir(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Finds the actual project root when inside a cached package.
|
|
73
|
+
*
|
|
74
|
+
* Cached packages are stored in: <project>/.dlang/packages/<owner>/<repo>/<commit>/
|
|
75
|
+
* If workspaceRoot is inside this structure, returns <project>
|
|
76
|
+
* Otherwise returns workspaceRoot unchanged.
|
|
77
|
+
*/
|
|
78
|
+
private findProjectRootFromCache;
|
|
38
79
|
/**
|
|
39
80
|
* Resolves the manifest file path within the workspace, if present.
|
|
40
81
|
*/
|
|
@@ -44,6 +85,20 @@ export declare class WorkspaceManager {
|
|
|
44
85
|
* Uses cached contents when unchanged on disk.
|
|
45
86
|
*/
|
|
46
87
|
getManifest(): Promise<ModelManifest | undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* Returns the cached manifest synchronously (if available).
|
|
90
|
+
* Used by LSP features that need synchronous access (like completion).
|
|
91
|
+
* Returns undefined if manifest hasn't been loaded yet.
|
|
92
|
+
*/
|
|
93
|
+
getCachedManifest(): ModelManifest | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Ensures the manifest is loaded and returns it.
|
|
96
|
+
* Use this over getCachedManifest() when you need to guarantee the manifest
|
|
97
|
+
* is available (e.g., in async LSP operations like completions).
|
|
98
|
+
*
|
|
99
|
+
* @returns The manifest or undefined if no model.yaml exists
|
|
100
|
+
*/
|
|
101
|
+
ensureManifestLoaded(): Promise<ModelManifest | undefined>;
|
|
47
102
|
/**
|
|
48
103
|
* Gets the currently cached lock file.
|
|
49
104
|
* Returns undefined if no lock file exists (run `dlang install` to create one).
|
|
@@ -94,11 +149,23 @@ export declare class WorkspaceManager {
|
|
|
94
149
|
* Reads the entry point from a cached package's model.yaml.
|
|
95
150
|
*/
|
|
96
151
|
private readPackageEntry;
|
|
97
|
-
private performInitialization;
|
|
98
152
|
private ensureInitialized;
|
|
99
153
|
private loadLockFileFromDisk;
|
|
100
154
|
private tryReadLockFile;
|
|
101
155
|
private loadManifest;
|
|
156
|
+
/**
|
|
157
|
+
* Reads, validates, and caches a manifest file.
|
|
158
|
+
*/
|
|
159
|
+
private readAndCacheManifest;
|
|
160
|
+
/**
|
|
161
|
+
* Handles errors from manifest loading, distinguishing recoverable
|
|
162
|
+
* errors (missing file, parse errors) from unexpected ones.
|
|
163
|
+
*/
|
|
164
|
+
private handleManifestError;
|
|
165
|
+
/**
|
|
166
|
+
* Clears the manifest cache on the given context, if available.
|
|
167
|
+
*/
|
|
168
|
+
private clearManifestCache;
|
|
102
169
|
/**
|
|
103
170
|
* Validates manifest structure and dependency configurations.
|
|
104
171
|
* Throws detailed errors for invalid manifests.
|