@atscript/core 0.1.39 → 0.1.41
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 +4 -4
- package/dist/index.cjs +208 -29
- package/dist/index.d.ts +61 -1
- package/dist/index.mjs +180 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://atscript.
|
|
2
|
+
<img src="https://atscript.dev/logo.svg" alt="Atscript" width="120" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<h1 align="center">@atscript/core</h1>
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
|
-
<a href="https://atscript.
|
|
12
|
+
<a href="https://atscript.dev">Documentation</a> · <a href="https://atscript.dev/plugin-development/">Plugin Development</a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
15
|
---
|
|
@@ -37,8 +37,8 @@ pnpm add @atscript/core
|
|
|
37
37
|
|
|
38
38
|
## Documentation
|
|
39
39
|
|
|
40
|
-
- [Plugin Development Guide](https://atscript.
|
|
41
|
-
- [Full Documentation](https://atscript.
|
|
40
|
+
- [Plugin Development Guide](https://atscript.dev/plugin-development/)
|
|
41
|
+
- [Full Documentation](https://atscript.dev)
|
|
42
42
|
|
|
43
43
|
## License
|
|
44
44
|
|
package/dist/index.cjs
CHANGED
|
@@ -2896,9 +2896,141 @@ var TSeverity = /*#__PURE__*/ function(TSeverity$1) {
|
|
|
2896
2896
|
return TSeverity$1;
|
|
2897
2897
|
}({});
|
|
2898
2898
|
|
|
2899
|
+
//#endregion
|
|
2900
|
+
//#region packages/core/src/resolve-bare.ts
|
|
2901
|
+
function isBareSpecifier(specifier) {
|
|
2902
|
+
return specifier[0] !== "." && specifier[0] !== "/";
|
|
2903
|
+
}
|
|
2904
|
+
function isBareId(id) {
|
|
2905
|
+
return id.startsWith("bare:");
|
|
2906
|
+
}
|
|
2907
|
+
function parseBareSpecifier(specifier) {
|
|
2908
|
+
if (specifier.startsWith("@")) {
|
|
2909
|
+
const firstSlash$1 = specifier.indexOf("/");
|
|
2910
|
+
if (firstSlash$1 === -1) return {
|
|
2911
|
+
packageName: specifier,
|
|
2912
|
+
subpath: "."
|
|
2913
|
+
};
|
|
2914
|
+
const secondSlash = specifier.indexOf("/", firstSlash$1 + 1);
|
|
2915
|
+
if (secondSlash === -1) return {
|
|
2916
|
+
packageName: specifier,
|
|
2917
|
+
subpath: "."
|
|
2918
|
+
};
|
|
2919
|
+
return {
|
|
2920
|
+
packageName: specifier.slice(0, secondSlash),
|
|
2921
|
+
subpath: `./${specifier.slice(secondSlash + 1)}`
|
|
2922
|
+
};
|
|
2923
|
+
}
|
|
2924
|
+
const firstSlash = specifier.indexOf("/");
|
|
2925
|
+
if (firstSlash === -1) return {
|
|
2926
|
+
packageName: specifier,
|
|
2927
|
+
subpath: "."
|
|
2928
|
+
};
|
|
2929
|
+
return {
|
|
2930
|
+
packageName: specifier.slice(0, firstSlash),
|
|
2931
|
+
subpath: `./${specifier.slice(firstSlash + 1)}`
|
|
2932
|
+
};
|
|
2933
|
+
}
|
|
2934
|
+
function resolvePackageExports(exports$1, subpath) {
|
|
2935
|
+
if (!exports$1 || typeof exports$1 !== "object") return undefined;
|
|
2936
|
+
const exportsMap = exports$1;
|
|
2937
|
+
const subpathWithExt = subpath === "." ? "." : `${subpath}.as`;
|
|
2938
|
+
const entry = exportsMap[subpathWithExt];
|
|
2939
|
+
if (entry) return resolveExportEntry(entry);
|
|
2940
|
+
for (const [pattern, value] of Object.entries(exportsMap)) {
|
|
2941
|
+
if (!pattern.includes("*")) continue;
|
|
2942
|
+
const match = matchSubpathPattern(pattern, subpathWithExt);
|
|
2943
|
+
if (match !== undefined) {
|
|
2944
|
+
const resolved = resolveExportEntry(value);
|
|
2945
|
+
if (resolved) return resolved.replaceAll("*", match);
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
return undefined;
|
|
2949
|
+
}
|
|
2950
|
+
/**
|
|
2951
|
+
* Resolve a single export entry, checking for `atscript` condition.
|
|
2952
|
+
*/ function resolveExportEntry(entry) {
|
|
2953
|
+
if (typeof entry === "string") return entry;
|
|
2954
|
+
if (entry && typeof entry === "object") {
|
|
2955
|
+
const obj = entry;
|
|
2956
|
+
if (typeof obj["atscript"] === "string") return obj["atscript"];
|
|
2957
|
+
if (typeof obj["default"] === "string") return obj["default"];
|
|
2958
|
+
}
|
|
2959
|
+
return undefined;
|
|
2960
|
+
}
|
|
2961
|
+
/**
|
|
2962
|
+
* Match a subpath against a pattern with a single `*` wildcard.
|
|
2963
|
+
* Returns the matched wildcard portion, or undefined if no match.
|
|
2964
|
+
*/ function matchSubpathPattern(pattern, subpath) {
|
|
2965
|
+
const starIdx = pattern.indexOf("*");
|
|
2966
|
+
if (starIdx === -1) return undefined;
|
|
2967
|
+
const prefix = pattern.slice(0, starIdx);
|
|
2968
|
+
const suffix = pattern.slice(starIdx + 1);
|
|
2969
|
+
if (subpath.startsWith(prefix) && subpath.endsWith(suffix) && subpath.length >= prefix.length + suffix.length) return subpath.slice(prefix.length, subpath.length - suffix.length);
|
|
2970
|
+
return undefined;
|
|
2971
|
+
}
|
|
2972
|
+
/**
|
|
2973
|
+
* Check if a file exists.
|
|
2974
|
+
*/ async function fileExists(filePath) {
|
|
2975
|
+
try {
|
|
2976
|
+
await (0, node_fs_promises.access)(filePath);
|
|
2977
|
+
return true;
|
|
2978
|
+
} catch {
|
|
2979
|
+
return false;
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
const resolveCache = new Map();
|
|
2983
|
+
function clearResolveBareCache() {
|
|
2984
|
+
resolveCache.clear();
|
|
2985
|
+
}
|
|
2986
|
+
async function resolveBareSpecifier(specifier, fromDir) {
|
|
2987
|
+
const cacheKey = `${fromDir}\0${specifier}`;
|
|
2988
|
+
if (resolveCache.has(cacheKey)) return resolveCache.get(cacheKey);
|
|
2989
|
+
const result = await _resolveBareSpecifier(specifier, fromDir);
|
|
2990
|
+
resolveCache.set(cacheKey, result);
|
|
2991
|
+
return result;
|
|
2992
|
+
}
|
|
2993
|
+
async function _resolveBareSpecifier(specifier, fromDir) {
|
|
2994
|
+
const { packageName, subpath } = parseBareSpecifier(specifier);
|
|
2995
|
+
let dir = fromDir;
|
|
2996
|
+
const root$1 = node_path.default.parse(dir).root;
|
|
2997
|
+
while (true) {
|
|
2998
|
+
const pkgDir = node_path.default.join(dir, "node_modules", packageName);
|
|
2999
|
+
const pkgJsonPath = node_path.default.join(pkgDir, "package.json");
|
|
3000
|
+
if (await fileExists(pkgJsonPath)) {
|
|
3001
|
+
try {
|
|
3002
|
+
const pkgJson = JSON.parse(await (0, node_fs_promises.readFile)(pkgJsonPath, "utf8"));
|
|
3003
|
+
if (pkgJson.exports) {
|
|
3004
|
+
const resolved = resolvePackageExports(pkgJson.exports, subpath);
|
|
3005
|
+
if (resolved) {
|
|
3006
|
+
const fullPath = node_path.default.resolve(pkgDir, resolved);
|
|
3007
|
+
if (await fileExists(fullPath)) return resolveRealPath(fullPath);
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
} catch {}
|
|
3011
|
+
const directPath = subpath === "." ? node_path.default.join(pkgDir, "index.as") : node_path.default.join(pkgDir, `${subpath.slice(2)}.as`);
|
|
3012
|
+
if (await fileExists(directPath)) return resolveRealPath(directPath);
|
|
3013
|
+
}
|
|
3014
|
+
const parentDir = node_path.default.dirname(dir);
|
|
3015
|
+
if (parentDir === dir || dir === root$1) break;
|
|
3016
|
+
dir = parentDir;
|
|
3017
|
+
}
|
|
3018
|
+
return undefined;
|
|
3019
|
+
}
|
|
3020
|
+
/**
|
|
3021
|
+
* Resolve symlinks to get the canonical path (important for pnpm).
|
|
3022
|
+
*/ async function resolveRealPath(filePath) {
|
|
3023
|
+
try {
|
|
3024
|
+
return await (0, node_fs_promises.realpath)(filePath);
|
|
3025
|
+
} catch {
|
|
3026
|
+
return filePath;
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
|
|
2899
3030
|
//#endregion
|
|
2900
3031
|
//#region packages/core/src/parser/utils.ts
|
|
2901
3032
|
function resolveAtscriptFromPath(from, id) {
|
|
3033
|
+
if (isBareSpecifier(from)) return `bare:${from}.as`;
|
|
2902
3034
|
return `file://${path.default.join(id.slice(7).split("/").slice(0, -1).join("/"), from)}.as`;
|
|
2903
3035
|
}
|
|
2904
3036
|
function getRelPath(fromUri, toUri) {
|
|
@@ -3099,6 +3231,21 @@ var AtscriptDoc = class {
|
|
|
3099
3231
|
resolveAnnotation(name) {
|
|
3100
3232
|
return resolveAnnotation(name, this.config.annotations);
|
|
3101
3233
|
}
|
|
3234
|
+
/**
|
|
3235
|
+
* Resolve a placeholder import ID (bare:xxx.as) to its actual file:// URI.
|
|
3236
|
+
* Returns the input unchanged if no resolution is cached.
|
|
3237
|
+
*/ resolveImportId(rawId) {
|
|
3238
|
+
return this.resolvedImports.get(rawId) ?? rawId;
|
|
3239
|
+
}
|
|
3240
|
+
/**
|
|
3241
|
+
* Re-key an entry in the imports map (e.g., from bare: placeholder to file:// URI).
|
|
3242
|
+
*/ rekeyImport(oldKey, newKey) {
|
|
3243
|
+
const entry = this.imports.get(oldKey);
|
|
3244
|
+
if (entry) {
|
|
3245
|
+
this.imports.delete(oldKey);
|
|
3246
|
+
this.imports.set(newKey, entry);
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3102
3249
|
updateDependencies(docs) {
|
|
3103
3250
|
const newDependencies = new Set(docs);
|
|
3104
3251
|
this.dependencies.forEach((d) => {
|
|
@@ -3140,6 +3287,7 @@ var AtscriptDoc = class {
|
|
|
3140
3287
|
this.referred = [];
|
|
3141
3288
|
this.queryFieldRefs = [];
|
|
3142
3289
|
this.imports.clear();
|
|
3290
|
+
this.resolvedImports.clear();
|
|
3143
3291
|
this._allMessages = undefined;
|
|
3144
3292
|
this.tokensIndex = new TokensIndex();
|
|
3145
3293
|
this.blocksIndex = new BlocksIndex();
|
|
@@ -3457,7 +3605,7 @@ else {
|
|
|
3457
3605
|
token
|
|
3458
3606
|
};
|
|
3459
3607
|
if (token.fromPath) {
|
|
3460
|
-
const absolutePath = resolveAtscriptFromPath(token.fromPath, this.id);
|
|
3608
|
+
const absolutePath = this.resolveImportId(resolveAtscriptFromPath(token.fromPath, this.id));
|
|
3461
3609
|
return {
|
|
3462
3610
|
uri: absolutePath,
|
|
3463
3611
|
doc: this.dependenciesMap.get(absolutePath),
|
|
@@ -3466,7 +3614,7 @@ else {
|
|
|
3466
3614
|
}
|
|
3467
3615
|
if ((token.isReference || token.imported) && this.importedDefs.has(token.text) && this.dependenciesMap.size > 0) {
|
|
3468
3616
|
const from = this.importedDefs.get(token.text).text;
|
|
3469
|
-
const absolutePath = resolveAtscriptFromPath(from, this.id);
|
|
3617
|
+
const absolutePath = this.resolveImportId(resolveAtscriptFromPath(from, this.id));
|
|
3470
3618
|
const targetDoc = this.dependenciesMap.get(absolutePath);
|
|
3471
3619
|
if (targetDoc) {
|
|
3472
3620
|
const target = targetDoc.registry.definitions.get(token.text);
|
|
@@ -3615,7 +3763,7 @@ else {
|
|
|
3615
3763
|
};
|
|
3616
3764
|
const def = this.registry.definitions.get(identifier$1);
|
|
3617
3765
|
if (def?.imported && def.fromPath) {
|
|
3618
|
-
const absolutePath = resolveAtscriptFromPath(def.fromPath, this.id);
|
|
3766
|
+
const absolutePath = this.resolveImportId(resolveAtscriptFromPath(def.fromPath, this.id));
|
|
3619
3767
|
const doc = this.dependenciesMap.get(absolutePath);
|
|
3620
3768
|
return doc?.getDeclarationOwnerNode(identifier$1);
|
|
3621
3769
|
} else if (!def?.imported) return def ? {
|
|
@@ -3975,6 +4123,10 @@ else {
|
|
|
3975
4123
|
* Imports map by URI, contains from Token and imports[] tokens
|
|
3976
4124
|
*/ _define_property$3(this, "imports", void 0);
|
|
3977
4125
|
/**
|
|
4126
|
+
* Maps bare specifier placeholder IDs (bare:xxx.as) to resolved file:// URIs.
|
|
4127
|
+
* Populated during checkImport in AtscriptRepo.
|
|
4128
|
+
*/ _define_property$3(this, "resolvedImports", void 0);
|
|
4129
|
+
/**
|
|
3978
4130
|
* Map of imported definitions by type/interface identifier
|
|
3979
4131
|
*/ _define_property$3(this, "importedDefs", void 0);
|
|
3980
4132
|
/**
|
|
@@ -4009,6 +4161,7 @@ else {
|
|
|
4009
4161
|
this.tokensIndex = new TokensIndex();
|
|
4010
4162
|
this.blocksIndex = new BlocksIndex();
|
|
4011
4163
|
this.imports = new Map();
|
|
4164
|
+
this.resolvedImports = new Map();
|
|
4012
4165
|
this.importedDefs = new Map();
|
|
4013
4166
|
this.exports = new Map();
|
|
4014
4167
|
this.dependencies = new Set();
|
|
@@ -5061,7 +5214,24 @@ else types.push({ type: "boolean" });
|
|
|
5061
5214
|
atscript.updateDependencies(results.filter(Boolean));
|
|
5062
5215
|
}
|
|
5063
5216
|
async checkImport(atscript, from, imports, checked) {
|
|
5064
|
-
|
|
5217
|
+
let forId = resolveAtscriptFromPath(from.text, atscript.id);
|
|
5218
|
+
if (isBareId(forId)) {
|
|
5219
|
+
const fromDir = atscript.id.slice(7).split("/").slice(0, -1).join("/");
|
|
5220
|
+
const resolved = await resolveBareSpecifier(from.text, fromDir);
|
|
5221
|
+
if (!resolved) {
|
|
5222
|
+
atscript.registerMessages([{
|
|
5223
|
+
severity: 1,
|
|
5224
|
+
message: `"${from.text}" not found`,
|
|
5225
|
+
range: from.range
|
|
5226
|
+
}]);
|
|
5227
|
+
return;
|
|
5228
|
+
}
|
|
5229
|
+
const resolvedUri = `file://${resolved}`;
|
|
5230
|
+
atscript.resolvedImports.set(forId, resolvedUri);
|
|
5231
|
+
atscript.rekeyImport(forId, resolvedUri);
|
|
5232
|
+
this.resolvedToBare.set(resolvedUri, from.text);
|
|
5233
|
+
forId = resolvedUri;
|
|
5234
|
+
}
|
|
5065
5235
|
if (forId === atscript.id) {
|
|
5066
5236
|
atscript.registerMessages([{
|
|
5067
5237
|
severity: 1,
|
|
@@ -5100,12 +5270,16 @@ else types.push({ type: "boolean" });
|
|
|
5100
5270
|
*/ _define_property$1(this, "atscripts", void 0);
|
|
5101
5271
|
_define_property$1(this, "sharedPluginManager", void 0);
|
|
5102
5272
|
/**
|
|
5273
|
+
* Maps resolved file:// URIs back to bare specifiers (for LSP auto-import).
|
|
5274
|
+
*/ _define_property$1(this, "resolvedToBare", void 0);
|
|
5275
|
+
/**
|
|
5103
5276
|
* cache for raw content of config files
|
|
5104
5277
|
*/ _define_property$1(this, "configFiles", void 0);
|
|
5105
5278
|
this.root = root$1;
|
|
5106
5279
|
this.sharedConfig = sharedConfig;
|
|
5107
5280
|
this.configs = new Map();
|
|
5108
5281
|
this.atscripts = new Map();
|
|
5282
|
+
this.resolvedToBare = new Map();
|
|
5109
5283
|
this.configFiles = new Map();
|
|
5110
5284
|
}
|
|
5111
5285
|
};
|
|
@@ -5259,18 +5433,18 @@ function resolveNode(doc, def) {
|
|
|
5259
5433
|
function isComplexNode(def) {
|
|
5260
5434
|
return isStructure(def) || isArray(def) || isGroup(def) && def.entity !== "tuple";
|
|
5261
5435
|
}
|
|
5262
|
-
function addToFlatMap(flatMap, path$
|
|
5263
|
-
const existing = flatMap.get(path$
|
|
5436
|
+
function addToFlatMap(flatMap, path$6, descriptor) {
|
|
5437
|
+
const existing = flatMap.get(path$6);
|
|
5264
5438
|
if (existing) {
|
|
5265
5439
|
const group$1 = new SemanticGroup([existing.def, descriptor.def], "|");
|
|
5266
|
-
flatMap.set(path$
|
|
5440
|
+
flatMap.set(path$6, {
|
|
5267
5441
|
def: group$1,
|
|
5268
5442
|
doc: existing.doc,
|
|
5269
5443
|
optional: existing.optional || descriptor.optional,
|
|
5270
5444
|
propNode: existing.propNode,
|
|
5271
5445
|
intermediate: existing.intermediate && descriptor.intermediate ? true : undefined
|
|
5272
5446
|
});
|
|
5273
|
-
} else flatMap.set(path$
|
|
5447
|
+
} else flatMap.set(path$6, descriptor);
|
|
5274
5448
|
}
|
|
5275
5449
|
function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, options) {
|
|
5276
5450
|
for (const [name, prop] of struct.props) {
|
|
@@ -5278,11 +5452,11 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
|
|
|
5278
5452
|
const propDef = prop.getDefinition();
|
|
5279
5453
|
if (isPhantomNode(doc, propDef)) continue;
|
|
5280
5454
|
if (options?.skipNavProps && hasNavPropAnnotation(prop)) continue;
|
|
5281
|
-
const path$
|
|
5455
|
+
const path$6 = prefix ? `${prefix}.${name}` : name;
|
|
5282
5456
|
const optional = parentOptional || !!prop.token("optional");
|
|
5283
5457
|
const dbJson = hasDbJsonAnnotation(prop);
|
|
5284
5458
|
if (!propDef) {
|
|
5285
|
-
addToFlatMap(flatMap, path$
|
|
5459
|
+
addToFlatMap(flatMap, path$6, {
|
|
5286
5460
|
def: prop,
|
|
5287
5461
|
doc,
|
|
5288
5462
|
optional,
|
|
@@ -5292,7 +5466,7 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
|
|
|
5292
5466
|
}
|
|
5293
5467
|
const resolved = resolveNode(doc, propDef);
|
|
5294
5468
|
if (!resolved) {
|
|
5295
|
-
addToFlatMap(flatMap, path$
|
|
5469
|
+
addToFlatMap(flatMap, path$6, {
|
|
5296
5470
|
def: propDef,
|
|
5297
5471
|
doc,
|
|
5298
5472
|
optional,
|
|
@@ -5301,7 +5475,7 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
|
|
|
5301
5475
|
continue;
|
|
5302
5476
|
}
|
|
5303
5477
|
if (dbJson) {
|
|
5304
|
-
addToFlatMap(flatMap, path$
|
|
5478
|
+
addToFlatMap(flatMap, path$6, {
|
|
5305
5479
|
def: resolved.def,
|
|
5306
5480
|
doc: resolved.doc,
|
|
5307
5481
|
optional,
|
|
@@ -5310,12 +5484,12 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
|
|
|
5310
5484
|
});
|
|
5311
5485
|
continue;
|
|
5312
5486
|
}
|
|
5313
|
-
walkNode(resolved.doc, resolved.def, path$
|
|
5487
|
+
walkNode(resolved.doc, resolved.def, path$6, optional, prop, flatMap, stack, options);
|
|
5314
5488
|
}
|
|
5315
5489
|
}
|
|
5316
|
-
function walkNode(doc, def, path$
|
|
5490
|
+
function walkNode(doc, def, path$6, optional, propNode, flatMap, stack, options) {
|
|
5317
5491
|
if (stack.has(def)) {
|
|
5318
|
-
addToFlatMap(flatMap, path$
|
|
5492
|
+
addToFlatMap(flatMap, path$6, {
|
|
5319
5493
|
def,
|
|
5320
5494
|
doc,
|
|
5321
5495
|
optional,
|
|
@@ -5326,28 +5500,28 @@ function walkNode(doc, def, path$5, optional, propNode, flatMap, stack, options)
|
|
|
5326
5500
|
stack.add(def);
|
|
5327
5501
|
try {
|
|
5328
5502
|
if (isStructure(def)) {
|
|
5329
|
-
addToFlatMap(flatMap, path$
|
|
5503
|
+
addToFlatMap(flatMap, path$6, {
|
|
5330
5504
|
def,
|
|
5331
5505
|
doc,
|
|
5332
5506
|
optional,
|
|
5333
5507
|
propNode,
|
|
5334
5508
|
intermediate: true
|
|
5335
5509
|
});
|
|
5336
|
-
walkStructure(doc, def, path$
|
|
5510
|
+
walkStructure(doc, def, path$6, optional, flatMap, stack, options);
|
|
5337
5511
|
} else if (isArray(def)) {
|
|
5338
5512
|
const elementDef = def.getDefinition();
|
|
5339
5513
|
const resolvedElement = elementDef ? resolveNode(doc, elementDef) : undefined;
|
|
5340
5514
|
const isComplexElement = resolvedElement && (isStructure(resolvedElement.def) || isGroup(resolvedElement.def) && resolvedElement.def.entity !== "tuple" || isArray(resolvedElement.def));
|
|
5341
5515
|
if (isComplexElement) {
|
|
5342
|
-
addToFlatMap(flatMap, path$
|
|
5516
|
+
addToFlatMap(flatMap, path$6, {
|
|
5343
5517
|
def,
|
|
5344
5518
|
doc,
|
|
5345
5519
|
optional,
|
|
5346
5520
|
propNode,
|
|
5347
5521
|
intermediate: true
|
|
5348
5522
|
});
|
|
5349
|
-
walkArrayElement(doc, def, path$
|
|
5350
|
-
} else addToFlatMap(flatMap, path$
|
|
5523
|
+
walkArrayElement(doc, def, path$6, optional, flatMap, stack, options);
|
|
5524
|
+
} else addToFlatMap(flatMap, path$6, {
|
|
5351
5525
|
def,
|
|
5352
5526
|
doc,
|
|
5353
5527
|
optional,
|
|
@@ -5358,15 +5532,15 @@ function walkNode(doc, def, path$5, optional, propNode, flatMap, stack, options)
|
|
|
5358
5532
|
if (group$1.op === "&") {
|
|
5359
5533
|
const merged = doc.mergeIntersection(def);
|
|
5360
5534
|
if (merged !== def && isStructure(merged)) {
|
|
5361
|
-
addToFlatMap(flatMap, path$
|
|
5535
|
+
addToFlatMap(flatMap, path$6, {
|
|
5362
5536
|
def: merged,
|
|
5363
5537
|
doc,
|
|
5364
5538
|
optional,
|
|
5365
5539
|
propNode,
|
|
5366
5540
|
intermediate: true
|
|
5367
5541
|
});
|
|
5368
|
-
walkStructure(doc, merged, path$
|
|
5369
|
-
} else addToFlatMap(flatMap, path$
|
|
5542
|
+
walkStructure(doc, merged, path$6, optional, flatMap, stack, options);
|
|
5543
|
+
} else addToFlatMap(flatMap, path$6, {
|
|
5370
5544
|
def,
|
|
5371
5545
|
doc,
|
|
5372
5546
|
optional,
|
|
@@ -5382,13 +5556,13 @@ function walkNode(doc, def, path$5, optional, propNode, flatMap, stack, options)
|
|
|
5382
5556
|
else hasLeafBranch = true;
|
|
5383
5557
|
}
|
|
5384
5558
|
if (hasComplexBranch) {
|
|
5385
|
-
if (hasLeafBranch) addToFlatMap(flatMap, path$
|
|
5559
|
+
if (hasLeafBranch) addToFlatMap(flatMap, path$6, {
|
|
5386
5560
|
def,
|
|
5387
5561
|
doc,
|
|
5388
5562
|
optional,
|
|
5389
5563
|
propNode
|
|
5390
5564
|
});
|
|
5391
|
-
else addToFlatMap(flatMap, path$
|
|
5565
|
+
else addToFlatMap(flatMap, path$6, {
|
|
5392
5566
|
def,
|
|
5393
5567
|
doc,
|
|
5394
5568
|
optional,
|
|
@@ -5397,21 +5571,21 @@ else addToFlatMap(flatMap, path$5, {
|
|
|
5397
5571
|
});
|
|
5398
5572
|
for (const branch of branches) {
|
|
5399
5573
|
const resolved = resolveNode(doc, branch);
|
|
5400
|
-
if (resolved) walkBranch(resolved.doc, resolved.def, path$
|
|
5574
|
+
if (resolved) walkBranch(resolved.doc, resolved.def, path$6, optional, flatMap, stack, options);
|
|
5401
5575
|
}
|
|
5402
|
-
} else addToFlatMap(flatMap, path$
|
|
5576
|
+
} else addToFlatMap(flatMap, path$6, {
|
|
5403
5577
|
def,
|
|
5404
5578
|
doc,
|
|
5405
5579
|
optional,
|
|
5406
5580
|
propNode
|
|
5407
5581
|
});
|
|
5408
|
-
} else addToFlatMap(flatMap, path$
|
|
5582
|
+
} else addToFlatMap(flatMap, path$6, {
|
|
5409
5583
|
def,
|
|
5410
5584
|
doc,
|
|
5411
5585
|
optional,
|
|
5412
5586
|
propNode
|
|
5413
5587
|
});
|
|
5414
|
-
} else addToFlatMap(flatMap, path$
|
|
5588
|
+
} else addToFlatMap(flatMap, path$6, {
|
|
5415
5589
|
def,
|
|
5416
5590
|
doc,
|
|
5417
5591
|
optional,
|
|
@@ -5476,6 +5650,7 @@ exports.SemanticTypeNode = SemanticTypeNode
|
|
|
5476
5650
|
exports.Token = Token
|
|
5477
5651
|
exports.analyzeQueryCursorContext = analyzeQueryCursorContext
|
|
5478
5652
|
exports.build = build
|
|
5653
|
+
exports.clearResolveBareCache = clearResolveBareCache
|
|
5479
5654
|
exports.createAtscriptPlugin = createAtscriptPlugin
|
|
5480
5655
|
exports.defineConfig = defineConfig
|
|
5481
5656
|
exports.flattenInterfaceNode = flattenInterfaceNode
|
|
@@ -5487,6 +5662,8 @@ exports.hasNavPropAnnotation = hasNavPropAnnotation
|
|
|
5487
5662
|
exports.isAnnotate = isAnnotate
|
|
5488
5663
|
exports.isAnnotationSpec = isAnnotationSpec
|
|
5489
5664
|
exports.isArray = isArray
|
|
5665
|
+
exports.isBareId = isBareId
|
|
5666
|
+
exports.isBareSpecifier = isBareSpecifier
|
|
5490
5667
|
exports.isConst = isConst
|
|
5491
5668
|
exports.isGroup = isGroup
|
|
5492
5669
|
exports.isImport = isImport
|
|
@@ -5503,7 +5680,9 @@ exports.isTuple = isTuple
|
|
|
5503
5680
|
exports.isType = isType
|
|
5504
5681
|
exports.loadConfig = loadConfig
|
|
5505
5682
|
exports.loadTsConfig = loadTsConfig
|
|
5683
|
+
exports.parseBareSpecifier = parseBareSpecifier
|
|
5506
5684
|
exports.resolveAnnotation = resolveAnnotation
|
|
5507
5685
|
exports.resolveAtscriptFromPath = resolveAtscriptFromPath
|
|
5686
|
+
exports.resolveBareSpecifier = resolveBareSpecifier
|
|
5508
5687
|
exports.resolveConfigFile = resolveConfigFile
|
|
5509
5688
|
exports.resolveQueryFieldRef = resolveQueryFieldRef
|
package/dist/index.d.ts
CHANGED
|
@@ -129,6 +129,10 @@ declare class AtscriptRepo {
|
|
|
129
129
|
*/
|
|
130
130
|
protected readonly atscripts: Map<string, Promise<AtscriptDoc>>;
|
|
131
131
|
sharedPluginManager: TPluginManagers | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Maps resolved file:// URIs back to bare specifiers (for LSP auto-import).
|
|
134
|
+
*/
|
|
135
|
+
readonly resolvedToBare: Map<string, string>;
|
|
132
136
|
/**
|
|
133
137
|
* cache for raw content of config files
|
|
134
138
|
*/
|
|
@@ -433,6 +437,11 @@ declare class AtscriptDoc {
|
|
|
433
437
|
from: Token;
|
|
434
438
|
imports: Token[];
|
|
435
439
|
}>;
|
|
440
|
+
/**
|
|
441
|
+
* Maps bare specifier placeholder IDs (bare:xxx.as) to resolved file:// URIs.
|
|
442
|
+
* Populated during checkImport in AtscriptRepo.
|
|
443
|
+
*/
|
|
444
|
+
resolvedImports: Map<string, string>;
|
|
436
445
|
/**
|
|
437
446
|
* Map of imported definitions by type/interface identifier
|
|
438
447
|
*/
|
|
@@ -464,6 +473,15 @@ declare class AtscriptDoc {
|
|
|
464
473
|
get primitives(): SemanticPrimitiveNode[];
|
|
465
474
|
render(format: TAtscriptRenderFormat): Promise<TOutputWithSource[] | undefined>;
|
|
466
475
|
resolveAnnotation(name: string): AnnotationSpec | undefined;
|
|
476
|
+
/**
|
|
477
|
+
* Resolve a placeholder import ID (bare:xxx.as) to its actual file:// URI.
|
|
478
|
+
* Returns the input unchanged if no resolution is cached.
|
|
479
|
+
*/
|
|
480
|
+
resolveImportId(rawId: string): string;
|
|
481
|
+
/**
|
|
482
|
+
* Re-key an entry in the imports map (e.g., from bare: placeholder to file:// URI).
|
|
483
|
+
*/
|
|
484
|
+
rekeyImport(oldKey: string, newKey: string): void;
|
|
467
485
|
updateDependencies(docs: AtscriptDoc[]): void;
|
|
468
486
|
nodes: SemanticNode[];
|
|
469
487
|
private _text;
|
|
@@ -845,6 +863,48 @@ declare function resolveAnnotation(name: string, annotationsTree?: TAnnotationsT
|
|
|
845
863
|
declare function resolveAtscriptFromPath(from: string, id: string): string;
|
|
846
864
|
declare function getRelPath(fromUri: string, toUri: string): string;
|
|
847
865
|
|
|
866
|
+
/**
|
|
867
|
+
* Returns true if the specifier is a bare specifier (not relative or absolute).
|
|
868
|
+
* Bare specifiers: 'my-lib/user', '@org/pkg/models'
|
|
869
|
+
* NOT bare: './user', '../shared', '/absolute/path'
|
|
870
|
+
*/
|
|
871
|
+
declare function isBareSpecifier(specifier: string): boolean;
|
|
872
|
+
/**
|
|
873
|
+
* Returns true if the document ID is a bare specifier placeholder.
|
|
874
|
+
*/
|
|
875
|
+
declare function isBareId(id: string): boolean;
|
|
876
|
+
/**
|
|
877
|
+
* Parse a bare specifier into package name and subpath.
|
|
878
|
+
*
|
|
879
|
+
* '@scope/pkg/sub/path' → { packageName: '@scope/pkg', subpath: './sub/path' }
|
|
880
|
+
* 'pkg/sub' → { packageName: 'pkg', subpath: './sub' }
|
|
881
|
+
* 'pkg' → { packageName: 'pkg', subpath: '.' }
|
|
882
|
+
*/
|
|
883
|
+
declare function parseBareSpecifier(specifier: string): {
|
|
884
|
+
packageName: string;
|
|
885
|
+
subpath: string;
|
|
886
|
+
};
|
|
887
|
+
/**
|
|
888
|
+
* Clear the bare specifier resolution cache.
|
|
889
|
+
* Call this when node_modules may have changed (e.g., after install).
|
|
890
|
+
*/
|
|
891
|
+
declare function clearResolveBareCache(): void;
|
|
892
|
+
/**
|
|
893
|
+
* Resolve a bare specifier to an absolute file path.
|
|
894
|
+
*
|
|
895
|
+
* Algorithm:
|
|
896
|
+
* 1. Parse specifier into packageName + subpath
|
|
897
|
+
* 2. Walk up from `fromDir` looking for `node_modules/<packageName>/package.json`
|
|
898
|
+
* 3. Check `exports` field for subpath with `atscript` condition
|
|
899
|
+
* 4. Fallback: check if file exists at `node_modules/<pkg>/<subpath>.as`
|
|
900
|
+
* 5. Resolve symlinks via `fs.realpath`
|
|
901
|
+
*
|
|
902
|
+
* @param specifier Bare specifier, e.g. 'my-lib/user' or '@org/pkg/models'
|
|
903
|
+
* @param fromDir Absolute directory of the importing file
|
|
904
|
+
* @returns Resolved absolute file path, or undefined if not found
|
|
905
|
+
*/
|
|
906
|
+
declare function resolveBareSpecifier(specifier: string, fromDir: string): Promise<string | undefined>;
|
|
907
|
+
|
|
848
908
|
/**
|
|
849
909
|
* Descriptor for a single field in the flattened interface map.
|
|
850
910
|
*/
|
|
@@ -945,5 +1005,5 @@ type TQueryCursorContext = {
|
|
|
945
1005
|
*/
|
|
946
1006
|
declare function analyzeQueryCursorContext(textBeforeCursor: string): TQueryCursorContext;
|
|
947
1007
|
|
|
948
|
-
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, createAtscriptPlugin, defineConfig, flattenInterfaceNode, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile, resolveQueryFieldRef };
|
|
1008
|
+
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, clearResolveBareCache, createAtscriptPlugin, defineConfig, flattenInterfaceNode, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBareId, isBareSpecifier, isConst, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveQueryFieldRef };
|
|
949
1009
|
export type { SemanticQueryExprNode, TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TDbConfig, TDbConfigDeclarative, TFlatFieldDescriptor, TFlattenOptions, TMessages, TNodeEntity, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TQueryCursorContext, TQueryLogicalOperator, TQueryOperator, TQueryScope, TSemanticToken };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import { readFile, readdir } from "node:fs/promises";
|
|
2
|
+
import { access, readFile, readdir, realpath } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { rolldown } from "rolldown";
|
|
@@ -2872,9 +2872,141 @@ var TSeverity = /*#__PURE__*/ function(TSeverity$1) {
|
|
|
2872
2872
|
return TSeverity$1;
|
|
2873
2873
|
}({});
|
|
2874
2874
|
|
|
2875
|
+
//#endregion
|
|
2876
|
+
//#region packages/core/src/resolve-bare.ts
|
|
2877
|
+
function isBareSpecifier(specifier) {
|
|
2878
|
+
return specifier[0] !== "." && specifier[0] !== "/";
|
|
2879
|
+
}
|
|
2880
|
+
function isBareId(id) {
|
|
2881
|
+
return id.startsWith("bare:");
|
|
2882
|
+
}
|
|
2883
|
+
function parseBareSpecifier(specifier) {
|
|
2884
|
+
if (specifier.startsWith("@")) {
|
|
2885
|
+
const firstSlash$1 = specifier.indexOf("/");
|
|
2886
|
+
if (firstSlash$1 === -1) return {
|
|
2887
|
+
packageName: specifier,
|
|
2888
|
+
subpath: "."
|
|
2889
|
+
};
|
|
2890
|
+
const secondSlash = specifier.indexOf("/", firstSlash$1 + 1);
|
|
2891
|
+
if (secondSlash === -1) return {
|
|
2892
|
+
packageName: specifier,
|
|
2893
|
+
subpath: "."
|
|
2894
|
+
};
|
|
2895
|
+
return {
|
|
2896
|
+
packageName: specifier.slice(0, secondSlash),
|
|
2897
|
+
subpath: `./${specifier.slice(secondSlash + 1)}`
|
|
2898
|
+
};
|
|
2899
|
+
}
|
|
2900
|
+
const firstSlash = specifier.indexOf("/");
|
|
2901
|
+
if (firstSlash === -1) return {
|
|
2902
|
+
packageName: specifier,
|
|
2903
|
+
subpath: "."
|
|
2904
|
+
};
|
|
2905
|
+
return {
|
|
2906
|
+
packageName: specifier.slice(0, firstSlash),
|
|
2907
|
+
subpath: `./${specifier.slice(firstSlash + 1)}`
|
|
2908
|
+
};
|
|
2909
|
+
}
|
|
2910
|
+
function resolvePackageExports(exports, subpath) {
|
|
2911
|
+
if (!exports || typeof exports !== "object") return undefined;
|
|
2912
|
+
const exportsMap = exports;
|
|
2913
|
+
const subpathWithExt = subpath === "." ? "." : `${subpath}.as`;
|
|
2914
|
+
const entry = exportsMap[subpathWithExt];
|
|
2915
|
+
if (entry) return resolveExportEntry(entry);
|
|
2916
|
+
for (const [pattern, value] of Object.entries(exportsMap)) {
|
|
2917
|
+
if (!pattern.includes("*")) continue;
|
|
2918
|
+
const match = matchSubpathPattern(pattern, subpathWithExt);
|
|
2919
|
+
if (match !== undefined) {
|
|
2920
|
+
const resolved = resolveExportEntry(value);
|
|
2921
|
+
if (resolved) return resolved.replaceAll("*", match);
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
return undefined;
|
|
2925
|
+
}
|
|
2926
|
+
/**
|
|
2927
|
+
* Resolve a single export entry, checking for `atscript` condition.
|
|
2928
|
+
*/ function resolveExportEntry(entry) {
|
|
2929
|
+
if (typeof entry === "string") return entry;
|
|
2930
|
+
if (entry && typeof entry === "object") {
|
|
2931
|
+
const obj = entry;
|
|
2932
|
+
if (typeof obj["atscript"] === "string") return obj["atscript"];
|
|
2933
|
+
if (typeof obj["default"] === "string") return obj["default"];
|
|
2934
|
+
}
|
|
2935
|
+
return undefined;
|
|
2936
|
+
}
|
|
2937
|
+
/**
|
|
2938
|
+
* Match a subpath against a pattern with a single `*` wildcard.
|
|
2939
|
+
* Returns the matched wildcard portion, or undefined if no match.
|
|
2940
|
+
*/ function matchSubpathPattern(pattern, subpath) {
|
|
2941
|
+
const starIdx = pattern.indexOf("*");
|
|
2942
|
+
if (starIdx === -1) return undefined;
|
|
2943
|
+
const prefix = pattern.slice(0, starIdx);
|
|
2944
|
+
const suffix = pattern.slice(starIdx + 1);
|
|
2945
|
+
if (subpath.startsWith(prefix) && subpath.endsWith(suffix) && subpath.length >= prefix.length + suffix.length) return subpath.slice(prefix.length, subpath.length - suffix.length);
|
|
2946
|
+
return undefined;
|
|
2947
|
+
}
|
|
2948
|
+
/**
|
|
2949
|
+
* Check if a file exists.
|
|
2950
|
+
*/ async function fileExists(filePath) {
|
|
2951
|
+
try {
|
|
2952
|
+
await access(filePath);
|
|
2953
|
+
return true;
|
|
2954
|
+
} catch {
|
|
2955
|
+
return false;
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
const resolveCache = new Map();
|
|
2959
|
+
function clearResolveBareCache() {
|
|
2960
|
+
resolveCache.clear();
|
|
2961
|
+
}
|
|
2962
|
+
async function resolveBareSpecifier(specifier, fromDir) {
|
|
2963
|
+
const cacheKey = `${fromDir}\0${specifier}`;
|
|
2964
|
+
if (resolveCache.has(cacheKey)) return resolveCache.get(cacheKey);
|
|
2965
|
+
const result = await _resolveBareSpecifier(specifier, fromDir);
|
|
2966
|
+
resolveCache.set(cacheKey, result);
|
|
2967
|
+
return result;
|
|
2968
|
+
}
|
|
2969
|
+
async function _resolveBareSpecifier(specifier, fromDir) {
|
|
2970
|
+
const { packageName, subpath } = parseBareSpecifier(specifier);
|
|
2971
|
+
let dir = fromDir;
|
|
2972
|
+
const root$1 = path.parse(dir).root;
|
|
2973
|
+
while (true) {
|
|
2974
|
+
const pkgDir = path.join(dir, "node_modules", packageName);
|
|
2975
|
+
const pkgJsonPath = path.join(pkgDir, "package.json");
|
|
2976
|
+
if (await fileExists(pkgJsonPath)) {
|
|
2977
|
+
try {
|
|
2978
|
+
const pkgJson = JSON.parse(await readFile(pkgJsonPath, "utf8"));
|
|
2979
|
+
if (pkgJson.exports) {
|
|
2980
|
+
const resolved = resolvePackageExports(pkgJson.exports, subpath);
|
|
2981
|
+
if (resolved) {
|
|
2982
|
+
const fullPath = path.resolve(pkgDir, resolved);
|
|
2983
|
+
if (await fileExists(fullPath)) return resolveRealPath(fullPath);
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
} catch {}
|
|
2987
|
+
const directPath = subpath === "." ? path.join(pkgDir, "index.as") : path.join(pkgDir, `${subpath.slice(2)}.as`);
|
|
2988
|
+
if (await fileExists(directPath)) return resolveRealPath(directPath);
|
|
2989
|
+
}
|
|
2990
|
+
const parentDir = path.dirname(dir);
|
|
2991
|
+
if (parentDir === dir || dir === root$1) break;
|
|
2992
|
+
dir = parentDir;
|
|
2993
|
+
}
|
|
2994
|
+
return undefined;
|
|
2995
|
+
}
|
|
2996
|
+
/**
|
|
2997
|
+
* Resolve symlinks to get the canonical path (important for pnpm).
|
|
2998
|
+
*/ async function resolveRealPath(filePath) {
|
|
2999
|
+
try {
|
|
3000
|
+
return await realpath(filePath);
|
|
3001
|
+
} catch {
|
|
3002
|
+
return filePath;
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
|
|
2875
3006
|
//#endregion
|
|
2876
3007
|
//#region packages/core/src/parser/utils.ts
|
|
2877
3008
|
function resolveAtscriptFromPath(from, id) {
|
|
3009
|
+
if (isBareSpecifier(from)) return `bare:${from}.as`;
|
|
2878
3010
|
return `file://${path$1.join(id.slice(7).split("/").slice(0, -1).join("/"), from)}.as`;
|
|
2879
3011
|
}
|
|
2880
3012
|
function getRelPath(fromUri, toUri) {
|
|
@@ -3075,6 +3207,21 @@ var AtscriptDoc = class {
|
|
|
3075
3207
|
resolveAnnotation(name) {
|
|
3076
3208
|
return resolveAnnotation(name, this.config.annotations);
|
|
3077
3209
|
}
|
|
3210
|
+
/**
|
|
3211
|
+
* Resolve a placeholder import ID (bare:xxx.as) to its actual file:// URI.
|
|
3212
|
+
* Returns the input unchanged if no resolution is cached.
|
|
3213
|
+
*/ resolveImportId(rawId) {
|
|
3214
|
+
return this.resolvedImports.get(rawId) ?? rawId;
|
|
3215
|
+
}
|
|
3216
|
+
/**
|
|
3217
|
+
* Re-key an entry in the imports map (e.g., from bare: placeholder to file:// URI).
|
|
3218
|
+
*/ rekeyImport(oldKey, newKey) {
|
|
3219
|
+
const entry = this.imports.get(oldKey);
|
|
3220
|
+
if (entry) {
|
|
3221
|
+
this.imports.delete(oldKey);
|
|
3222
|
+
this.imports.set(newKey, entry);
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3078
3225
|
updateDependencies(docs) {
|
|
3079
3226
|
const newDependencies = new Set(docs);
|
|
3080
3227
|
this.dependencies.forEach((d) => {
|
|
@@ -3116,6 +3263,7 @@ var AtscriptDoc = class {
|
|
|
3116
3263
|
this.referred = [];
|
|
3117
3264
|
this.queryFieldRefs = [];
|
|
3118
3265
|
this.imports.clear();
|
|
3266
|
+
this.resolvedImports.clear();
|
|
3119
3267
|
this._allMessages = undefined;
|
|
3120
3268
|
this.tokensIndex = new TokensIndex();
|
|
3121
3269
|
this.blocksIndex = new BlocksIndex();
|
|
@@ -3433,7 +3581,7 @@ else {
|
|
|
3433
3581
|
token
|
|
3434
3582
|
};
|
|
3435
3583
|
if (token.fromPath) {
|
|
3436
|
-
const absolutePath = resolveAtscriptFromPath(token.fromPath, this.id);
|
|
3584
|
+
const absolutePath = this.resolveImportId(resolveAtscriptFromPath(token.fromPath, this.id));
|
|
3437
3585
|
return {
|
|
3438
3586
|
uri: absolutePath,
|
|
3439
3587
|
doc: this.dependenciesMap.get(absolutePath),
|
|
@@ -3442,7 +3590,7 @@ else {
|
|
|
3442
3590
|
}
|
|
3443
3591
|
if ((token.isReference || token.imported) && this.importedDefs.has(token.text) && this.dependenciesMap.size > 0) {
|
|
3444
3592
|
const from = this.importedDefs.get(token.text).text;
|
|
3445
|
-
const absolutePath = resolveAtscriptFromPath(from, this.id);
|
|
3593
|
+
const absolutePath = this.resolveImportId(resolveAtscriptFromPath(from, this.id));
|
|
3446
3594
|
const targetDoc = this.dependenciesMap.get(absolutePath);
|
|
3447
3595
|
if (targetDoc) {
|
|
3448
3596
|
const target = targetDoc.registry.definitions.get(token.text);
|
|
@@ -3591,7 +3739,7 @@ else {
|
|
|
3591
3739
|
};
|
|
3592
3740
|
const def = this.registry.definitions.get(identifier$1);
|
|
3593
3741
|
if (def?.imported && def.fromPath) {
|
|
3594
|
-
const absolutePath = resolveAtscriptFromPath(def.fromPath, this.id);
|
|
3742
|
+
const absolutePath = this.resolveImportId(resolveAtscriptFromPath(def.fromPath, this.id));
|
|
3595
3743
|
const doc = this.dependenciesMap.get(absolutePath);
|
|
3596
3744
|
return doc?.getDeclarationOwnerNode(identifier$1);
|
|
3597
3745
|
} else if (!def?.imported) return def ? {
|
|
@@ -3951,6 +4099,10 @@ else {
|
|
|
3951
4099
|
* Imports map by URI, contains from Token and imports[] tokens
|
|
3952
4100
|
*/ _define_property$3(this, "imports", void 0);
|
|
3953
4101
|
/**
|
|
4102
|
+
* Maps bare specifier placeholder IDs (bare:xxx.as) to resolved file:// URIs.
|
|
4103
|
+
* Populated during checkImport in AtscriptRepo.
|
|
4104
|
+
*/ _define_property$3(this, "resolvedImports", void 0);
|
|
4105
|
+
/**
|
|
3954
4106
|
* Map of imported definitions by type/interface identifier
|
|
3955
4107
|
*/ _define_property$3(this, "importedDefs", void 0);
|
|
3956
4108
|
/**
|
|
@@ -3985,6 +4137,7 @@ else {
|
|
|
3985
4137
|
this.tokensIndex = new TokensIndex();
|
|
3986
4138
|
this.blocksIndex = new BlocksIndex();
|
|
3987
4139
|
this.imports = new Map();
|
|
4140
|
+
this.resolvedImports = new Map();
|
|
3988
4141
|
this.importedDefs = new Map();
|
|
3989
4142
|
this.exports = new Map();
|
|
3990
4143
|
this.dependencies = new Set();
|
|
@@ -5037,7 +5190,24 @@ else types.push({ type: "boolean" });
|
|
|
5037
5190
|
atscript.updateDependencies(results.filter(Boolean));
|
|
5038
5191
|
}
|
|
5039
5192
|
async checkImport(atscript, from, imports, checked) {
|
|
5040
|
-
|
|
5193
|
+
let forId = resolveAtscriptFromPath(from.text, atscript.id);
|
|
5194
|
+
if (isBareId(forId)) {
|
|
5195
|
+
const fromDir = atscript.id.slice(7).split("/").slice(0, -1).join("/");
|
|
5196
|
+
const resolved = await resolveBareSpecifier(from.text, fromDir);
|
|
5197
|
+
if (!resolved) {
|
|
5198
|
+
atscript.registerMessages([{
|
|
5199
|
+
severity: 1,
|
|
5200
|
+
message: `"${from.text}" not found`,
|
|
5201
|
+
range: from.range
|
|
5202
|
+
}]);
|
|
5203
|
+
return;
|
|
5204
|
+
}
|
|
5205
|
+
const resolvedUri = `file://${resolved}`;
|
|
5206
|
+
atscript.resolvedImports.set(forId, resolvedUri);
|
|
5207
|
+
atscript.rekeyImport(forId, resolvedUri);
|
|
5208
|
+
this.resolvedToBare.set(resolvedUri, from.text);
|
|
5209
|
+
forId = resolvedUri;
|
|
5210
|
+
}
|
|
5041
5211
|
if (forId === atscript.id) {
|
|
5042
5212
|
atscript.registerMessages([{
|
|
5043
5213
|
severity: 1,
|
|
@@ -5076,12 +5246,16 @@ else types.push({ type: "boolean" });
|
|
|
5076
5246
|
*/ _define_property$1(this, "atscripts", void 0);
|
|
5077
5247
|
_define_property$1(this, "sharedPluginManager", void 0);
|
|
5078
5248
|
/**
|
|
5249
|
+
* Maps resolved file:// URIs back to bare specifiers (for LSP auto-import).
|
|
5250
|
+
*/ _define_property$1(this, "resolvedToBare", void 0);
|
|
5251
|
+
/**
|
|
5079
5252
|
* cache for raw content of config files
|
|
5080
5253
|
*/ _define_property$1(this, "configFiles", void 0);
|
|
5081
5254
|
this.root = root$1;
|
|
5082
5255
|
this.sharedConfig = sharedConfig;
|
|
5083
5256
|
this.configs = new Map();
|
|
5084
5257
|
this.atscripts = new Map();
|
|
5258
|
+
this.resolvedToBare = new Map();
|
|
5085
5259
|
this.configFiles = new Map();
|
|
5086
5260
|
}
|
|
5087
5261
|
};
|
|
@@ -5423,4 +5597,4 @@ else if (isGroup(def) && def.entity !== "structure") {
|
|
|
5423
5597
|
}
|
|
5424
5598
|
|
|
5425
5599
|
//#endregion
|
|
5426
|
-
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, createAtscriptPlugin, defineConfig, flattenInterfaceNode, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile, resolveQueryFieldRef };
|
|
5600
|
+
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, clearResolveBareCache, createAtscriptPlugin, defineConfig, flattenInterfaceNode, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBareId, isBareSpecifier, isConst, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveQueryFieldRef };
|