@atscript/core 0.1.93 → 0.1.95
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/dist/index.cjs +199 -74
- package/dist/index.d.ts +74 -9
- package/dist/index.mjs +198 -75
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1417,19 +1417,25 @@ async function loadConfig(configPath, forceFormat) {
|
|
|
1417
1417
|
}
|
|
1418
1418
|
|
|
1419
1419
|
//#endregion
|
|
1420
|
-
//#region packages/core/src/
|
|
1420
|
+
//#region packages/core/src/lsp/legacy-db-query-scope.ts
|
|
1421
1421
|
/**
|
|
1422
|
-
*
|
|
1423
|
-
*
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1422
|
+
* @deprecated Built-in editor scopes for the `@db.view.filter`, `@db.view.joins` and
|
|
1423
|
+
* `@db.rel.filter` query arguments. They are a fallback for DB plugin versions whose
|
|
1424
|
+
* argument specs do not declare a `fieldScope` hook yet — the DB plugin owns these
|
|
1425
|
+
* rules now. Scheduled for removal in `@atscript/core` 0.2.0 (next minor).
|
|
1426
|
+
*/
|
|
1427
|
+
/**
|
|
1428
|
+
* @deprecated Query scope of a built-in `@db.*` query argument (see the module note);
|
|
1429
|
+
* `undefined` for any other annotation.
|
|
1430
|
+
*/ function getLegacyDbQueryScope(queryArgToken) {
|
|
1427
1431
|
const owner = queryArgToken.parentNode;
|
|
1428
1432
|
if (!owner) return;
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
+
switch (queryArgToken.annotationRef?.text.slice(1)) {
|
|
1434
|
+
case "db.view.filter": return getViewFilterScope(owner);
|
|
1435
|
+
case "db.view.joins": return getViewJoinsScope(owner, queryArgToken);
|
|
1436
|
+
case "db.rel.filter": return getRelFilterScope(owner);
|
|
1437
|
+
default: return;
|
|
1438
|
+
}
|
|
1433
1439
|
}
|
|
1434
1440
|
function getViewFilterScope(owner) {
|
|
1435
1441
|
const entryTypeName = (owner.annotations?.filter((a) => a.name === "db.view.for"))?.[0]?.args[0]?.text;
|
|
@@ -1467,35 +1473,159 @@ function getRelFilterScope(owner) {
|
|
|
1467
1473
|
unqualifiedTarget: targetTypeName
|
|
1468
1474
|
};
|
|
1469
1475
|
}
|
|
1476
|
+
|
|
1477
|
+
//#endregion
|
|
1478
|
+
//#region packages/core/src/lsp/field-refs.ts
|
|
1479
|
+
function getArgSpec(argToken, doc) {
|
|
1480
|
+
const annotationRef = argToken.annotationRef;
|
|
1481
|
+
if (!annotationRef || typeof argToken.index !== "number") return;
|
|
1482
|
+
return doc.resolveAnnotation(annotationRef.text.slice(1))?.arguments[argToken.index];
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Field scope of an annotation argument: the answer of the argument spec's `fieldScope`
|
|
1486
|
+
* hook when it declares one, otherwise the deprecated built-in `@db.*` query rules.
|
|
1487
|
+
*/ function getQueryScope(argToken, doc) {
|
|
1488
|
+
const argSpec = getArgSpec(argToken, doc);
|
|
1489
|
+
return argSpec?.fieldScope ? argSpec.fieldScope(argToken, doc) : getLegacyDbQueryScope(argToken);
|
|
1490
|
+
}
|
|
1491
|
+
/**
|
|
1492
|
+
* Type a field-path `string` argument names a field of: the `unqualifiedTarget` of the
|
|
1493
|
+
* argument spec's `fieldScope`. `undefined` for any other token.
|
|
1494
|
+
*/ function getFieldPathTarget(argToken, doc) {
|
|
1495
|
+
if (argToken.type !== "text") return;
|
|
1496
|
+
const argSpec = getArgSpec(argToken, doc);
|
|
1497
|
+
if (argSpec?.type !== "string" || !argSpec.fieldScope) return;
|
|
1498
|
+
return argSpec.fieldScope(argToken, doc)?.unqualifiedTarget ?? void 0;
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Resolve a (possibly dotted) field path of a type to the property it names and the
|
|
1502
|
+
* document that declares that property.
|
|
1503
|
+
*/ function resolveFieldPath(doc, typeName, segment) {
|
|
1504
|
+
const chain = segment.path.split(".");
|
|
1505
|
+
const [name] = chain.splice(-1);
|
|
1506
|
+
const parent = doc.unwindType(typeName, chain);
|
|
1507
|
+
if (!parent || !(isStructure(parent.def) || isInterface(parent.def))) return;
|
|
1508
|
+
const prop = parent.def.props.get(name);
|
|
1509
|
+
return prop && {
|
|
1510
|
+
typeName,
|
|
1511
|
+
range: segment.range,
|
|
1512
|
+
prop,
|
|
1513
|
+
doc: parent.doc
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Segments of a field-path string argument (`'address.city'` → `address`, `city`), with
|
|
1518
|
+
* ranges that exclude the quotes. A string spanning several lines is a single segment.
|
|
1519
|
+
*/ function fieldPathSegments(argToken) {
|
|
1520
|
+
const { text, range } = argToken;
|
|
1521
|
+
if (range.start.line !== range.end.line) return [{
|
|
1522
|
+
path: text,
|
|
1523
|
+
range
|
|
1524
|
+
}];
|
|
1525
|
+
const line = range.start.line;
|
|
1526
|
+
const contentStart = range.start.character + 1;
|
|
1527
|
+
const segments = [];
|
|
1528
|
+
let start = 0;
|
|
1529
|
+
for (const part of text.split(".")) {
|
|
1530
|
+
const end = start + part.length;
|
|
1531
|
+
segments.push({
|
|
1532
|
+
path: text.slice(0, end),
|
|
1533
|
+
range: {
|
|
1534
|
+
start: {
|
|
1535
|
+
line,
|
|
1536
|
+
character: contentStart + start
|
|
1537
|
+
},
|
|
1538
|
+
end: {
|
|
1539
|
+
line,
|
|
1540
|
+
character: contentStart + end
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
start = end + 1;
|
|
1545
|
+
}
|
|
1546
|
+
return segments;
|
|
1547
|
+
}
|
|
1548
|
+
/** The segment under `character`, or the last segment when `character` is omitted. */ function fieldPathSegmentAt(argToken, character) {
|
|
1549
|
+
const segments = fieldPathSegments(argToken);
|
|
1550
|
+
return (character === void 0 ? void 0 : segments.find((s) => s.range.end.character >= character)) ?? segments[segments.length - 1];
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Resolve a field reference token to the property it names:
|
|
1554
|
+
* - a field ref inside a `query` argument (`amount`, `Customer.name` in backticks);
|
|
1555
|
+
* - a `string` argument whose spec declares `fieldScope`: a (dotted) field path of the
|
|
1556
|
+
* scope's `unqualifiedTarget`. With `character` (a cursor column), the path resolves
|
|
1557
|
+
* only up to the segment under the cursor — `'address.city'` with the cursor on
|
|
1558
|
+
* `address` resolves `address` — and `range` is that segment's range.
|
|
1559
|
+
*
|
|
1560
|
+
* Returns `undefined` for any other token, or when the scope or the path does not resolve.
|
|
1561
|
+
*/ function resolveFieldRefAt(token, doc, character) {
|
|
1562
|
+
if (isQueryFieldRef(token.parentNode)) {
|
|
1563
|
+
const { fieldRef, typeRef, queryArgToken } = token.parentNode;
|
|
1564
|
+
const scope = token === fieldRef && queryArgToken ? getQueryScope(queryArgToken, doc) : void 0;
|
|
1565
|
+
const typeName = scope && (typeRef?.text ?? scope.unqualifiedTarget);
|
|
1566
|
+
return typeName ? resolveFieldPath(doc, typeName, {
|
|
1567
|
+
path: token.text,
|
|
1568
|
+
range: token.range
|
|
1569
|
+
}) : void 0;
|
|
1570
|
+
}
|
|
1571
|
+
const typeName = getFieldPathTarget(token, doc);
|
|
1572
|
+
return typeName ? resolveFieldPath(doc, typeName, fieldPathSegmentAt(token, character)) : void 0;
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Resolve the segments named `fieldName` of a field-path `string` argument
|
|
1576
|
+
* (`'address.city'` has the segments `address` and `city`). Supports find-references.
|
|
1577
|
+
*/ function resolveFieldPathArgSegments(argToken, doc, fieldName) {
|
|
1578
|
+
const segments = fieldPathSegments(argToken).filter((s) => s.path === fieldName || s.path.endsWith(`.${fieldName}`));
|
|
1579
|
+
const typeName = segments.length > 0 ? getFieldPathTarget(argToken, doc) : void 0;
|
|
1580
|
+
if (!typeName) return [];
|
|
1581
|
+
const targets = [];
|
|
1582
|
+
for (const segment of segments) {
|
|
1583
|
+
const target = resolveFieldPath(doc, typeName, segment);
|
|
1584
|
+
if (target) targets.push(target);
|
|
1585
|
+
}
|
|
1586
|
+
return targets;
|
|
1587
|
+
}
|
|
1470
1588
|
/**
|
|
1471
1589
|
* Resolve a query field ref node to a property definition.
|
|
1472
1590
|
*/ function resolveQueryFieldRef(fieldRefNode, doc, scope) {
|
|
1473
1591
|
const typeName = fieldRefNode.typeRef?.text ?? scope.unqualifiedTarget;
|
|
1474
|
-
|
|
1475
|
-
const
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
targetUri: parentUnwound.doc.id,
|
|
1484
|
-
doc: parentUnwound.doc,
|
|
1485
|
-
prop
|
|
1592
|
+
const { fieldRef } = fieldRefNode;
|
|
1593
|
+
const resolved = typeName ? resolveFieldPath(doc, typeName, {
|
|
1594
|
+
path: fieldRef.text,
|
|
1595
|
+
range: fieldRef.range
|
|
1596
|
+
}) : void 0;
|
|
1597
|
+
return resolved && {
|
|
1598
|
+
targetUri: resolved.doc.id,
|
|
1599
|
+
doc: resolved.doc,
|
|
1600
|
+
prop: resolved.prop
|
|
1486
1601
|
};
|
|
1487
1602
|
}
|
|
1488
1603
|
/**
|
|
1489
1604
|
* Get fields available for a type (resolving extends/intersections).
|
|
1490
|
-
|
|
1491
|
-
|
|
1605
|
+
* With `chain`, returns the fields of the nested object that field path leads to.
|
|
1606
|
+
*/ function getFieldsForType(doc, typeName, chain = []) {
|
|
1607
|
+
const unwound = doc.unwindType(typeName, chain);
|
|
1492
1608
|
if (!unwound?.def) return [];
|
|
1493
|
-
let def = doc.mergeIntersection(unwound.def);
|
|
1494
|
-
if (isInterface(def)) def = doc.resolveInterfaceExtends(def) || def.getDefinition() || def;
|
|
1609
|
+
let def = unwound.doc.mergeIntersection(unwound.def);
|
|
1610
|
+
if (isInterface(def)) def = unwound.doc.resolveInterfaceExtends(def) || def.getDefinition() || def;
|
|
1495
1611
|
if (isStructure(def) || isInterface(def)) return Array.from(def.props.values());
|
|
1496
1612
|
return [];
|
|
1497
1613
|
}
|
|
1498
1614
|
/**
|
|
1615
|
+
* Completion scope of a field-path `string` argument (spec declares `fieldScope`) at the
|
|
1616
|
+
* cursor column `character`: the fields of the level being typed — `'address.ci'` offers
|
|
1617
|
+
* the fields of `address` (`chain` = `['address']`).
|
|
1618
|
+
*/ function getFieldPathCompletionScope(argToken, doc, character) {
|
|
1619
|
+
const typeName = getFieldPathTarget(argToken, doc);
|
|
1620
|
+
if (!typeName) return;
|
|
1621
|
+
const chain = fieldPathSegmentAt(argToken, character).path.split(".").slice(0, -1);
|
|
1622
|
+
return {
|
|
1623
|
+
typeName,
|
|
1624
|
+
chain,
|
|
1625
|
+
fields: getFieldsForType(doc, typeName, chain)
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1499
1629
|
* Get completion scope data for a query context.
|
|
1500
1630
|
*/ function getQueryCompletionScope(queryArgToken, doc) {
|
|
1501
1631
|
const scope = getQueryScope(queryArgToken, doc);
|
|
@@ -3417,6 +3547,7 @@ var AtscriptDoc = class {
|
|
|
3417
3547
|
this.messages = [];
|
|
3418
3548
|
this.referred = [];
|
|
3419
3549
|
this.queryFieldRefs = [];
|
|
3550
|
+
this.fieldPathArgs = [];
|
|
3420
3551
|
this.imports.clear();
|
|
3421
3552
|
this.resolvedImports.clear();
|
|
3422
3553
|
this._allMessages = void 0;
|
|
@@ -3463,6 +3594,7 @@ var AtscriptDoc = class {
|
|
|
3463
3594
|
}
|
|
3464
3595
|
}
|
|
3465
3596
|
if (argSpec?.type === "query" && args?.[i]?.queryNode) args[i].queryNode.registerAtDocument(this);
|
|
3597
|
+
if (argSpec?.type === "string" && argSpec.fieldScope && args?.[i]) this.fieldPathArgs.push(args[i]);
|
|
3466
3598
|
}
|
|
3467
3599
|
} else {
|
|
3468
3600
|
let severity = 1;
|
|
@@ -3561,7 +3693,7 @@ var AtscriptDoc = class {
|
|
|
3561
3693
|
}
|
|
3562
3694
|
getUsageListAt(line, character) {
|
|
3563
3695
|
const token = this.tokensIndex.at(line, character);
|
|
3564
|
-
if (token) return this.usageListFor(token);
|
|
3696
|
+
if (token) return this.usageListFor(token, character);
|
|
3565
3697
|
}
|
|
3566
3698
|
evalAnnotationsForNode(givenNode) {
|
|
3567
3699
|
let right = givenNode.annotations;
|
|
@@ -3742,7 +3874,10 @@ var AtscriptDoc = class {
|
|
|
3742
3874
|
newStruct.annotations = struct.annotations;
|
|
3743
3875
|
return newStruct;
|
|
3744
3876
|
}
|
|
3745
|
-
|
|
3877
|
+
/**
|
|
3878
|
+
* Usages of the symbol `token` stands for. `character` (the cursor column)
|
|
3879
|
+
* narrows a dotted field-path string argument to the segment under the cursor.
|
|
3880
|
+
*/ usageListFor(token, character) {
|
|
3746
3881
|
if (token.isDefinition) {
|
|
3747
3882
|
const refs = this.referred.filter((t) => t.text === token.text).map((r) => ({
|
|
3748
3883
|
uri: this.id,
|
|
@@ -3758,6 +3893,9 @@ var AtscriptDoc = class {
|
|
|
3758
3893
|
}
|
|
3759
3894
|
return refs;
|
|
3760
3895
|
}
|
|
3896
|
+
const fieldRef = resolveFieldRefAt(token, this, character);
|
|
3897
|
+
const fieldRefProp = fieldRef?.prop.token("identifier");
|
|
3898
|
+
if (fieldRef && fieldRefProp) return fieldRef.doc.usageListFor(fieldRefProp);
|
|
3761
3899
|
if (isProp(token.parentNode)) {
|
|
3762
3900
|
const propName = token.parentNode.id;
|
|
3763
3901
|
if (!propName) return;
|
|
@@ -3790,15 +3928,18 @@ var AtscriptDoc = class {
|
|
|
3790
3928
|
}
|
|
3791
3929
|
}
|
|
3792
3930
|
for (const qfr of doc.queryFieldRefs) {
|
|
3793
|
-
if (
|
|
3794
|
-
|
|
3795
|
-
if (!scope) continue;
|
|
3796
|
-
if ((qfr.typeRef?.text ?? scope.unqualifiedTarget) === parentName) refs.push({
|
|
3931
|
+
if (qfr.fieldRef.text !== propName) continue;
|
|
3932
|
+
if (resolveFieldRefAt(qfr.fieldRef, doc)?.prop === token.parentNode) refs.push({
|
|
3797
3933
|
uri,
|
|
3798
3934
|
range: qfr.fieldRef.range,
|
|
3799
3935
|
token: qfr.fieldRef
|
|
3800
3936
|
});
|
|
3801
3937
|
}
|
|
3938
|
+
for (const arg of doc.fieldPathArgs) for (const target of resolveFieldPathArgSegments(arg, doc, propName)) if (target.prop === token.parentNode) refs.push({
|
|
3939
|
+
uri,
|
|
3940
|
+
range: target.range,
|
|
3941
|
+
token: arg
|
|
3942
|
+
});
|
|
3802
3943
|
};
|
|
3803
3944
|
searchDoc(this, this.id);
|
|
3804
3945
|
if (this.registry.definitions.get(parentName)?.exported) {
|
|
@@ -3807,21 +3948,6 @@ var AtscriptDoc = class {
|
|
|
3807
3948
|
}
|
|
3808
3949
|
return refs;
|
|
3809
3950
|
}
|
|
3810
|
-
if (isQueryFieldRef(token.parentNode) && token === token.parentNode.fieldRef) {
|
|
3811
|
-
const fieldRefNode = token.parentNode;
|
|
3812
|
-
const queryArgToken = fieldRefNode.queryArgToken;
|
|
3813
|
-
if (queryArgToken) {
|
|
3814
|
-
const scope = getQueryScope(queryArgToken, this);
|
|
3815
|
-
if (scope) {
|
|
3816
|
-
const resolved = resolveQueryFieldRef(fieldRefNode, this, scope);
|
|
3817
|
-
if (resolved?.prop) {
|
|
3818
|
-
const propToken = resolved.prop.token("identifier");
|
|
3819
|
-
if (propToken) return resolved.doc.usageListFor(propToken);
|
|
3820
|
-
}
|
|
3821
|
-
}
|
|
3822
|
-
}
|
|
3823
|
-
return;
|
|
3824
|
-
}
|
|
3825
3951
|
{
|
|
3826
3952
|
const defForToken = this.getDefinitionFor(token);
|
|
3827
3953
|
if (defForToken?.token?.isDefinition && defForToken.doc) return defForToken.doc.usageListFor(defForToken.token);
|
|
@@ -3895,34 +4021,26 @@ var AtscriptDoc = class {
|
|
|
3895
4021
|
}];
|
|
3896
4022
|
return;
|
|
3897
4023
|
}
|
|
4024
|
+
const fieldRef = resolveFieldRefAt(token, this, character);
|
|
4025
|
+
if (fieldRef) {
|
|
4026
|
+
const propRange = fieldRef.prop.token("identifier")?.range ?? zeroRange;
|
|
4027
|
+
return [{
|
|
4028
|
+
targetUri: fieldRef.doc.id,
|
|
4029
|
+
targetRange: propRange,
|
|
4030
|
+
targetSelectionRange: propRange,
|
|
4031
|
+
originSelectionRange: fieldRef.range
|
|
4032
|
+
}];
|
|
4033
|
+
}
|
|
3898
4034
|
if (isQueryFieldRef(token.parentNode)) {
|
|
3899
|
-
const
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
targetRange: result.token?.range ?? zeroRange,
|
|
3909
|
-
targetSelectionRange: result.token?.range ?? zeroRange,
|
|
3910
|
-
originSelectionRange: token.range
|
|
3911
|
-
}] : void 0;
|
|
3912
|
-
}
|
|
3913
|
-
if (token === fieldRefNode.fieldRef) {
|
|
3914
|
-
const resolved = resolveQueryFieldRef(fieldRefNode, this, scope);
|
|
3915
|
-
if (resolved?.prop) {
|
|
3916
|
-
const propToken = resolved.prop.token("identifier");
|
|
3917
|
-
return [{
|
|
3918
|
-
targetUri: resolved.targetUri,
|
|
3919
|
-
targetRange: propToken?.range ?? zeroRange,
|
|
3920
|
-
targetSelectionRange: propToken?.range ?? zeroRange,
|
|
3921
|
-
originSelectionRange: token.range
|
|
3922
|
-
}];
|
|
3923
|
-
}
|
|
3924
|
-
}
|
|
3925
|
-
}
|
|
4035
|
+
const { typeRef, queryArgToken } = token.parentNode;
|
|
4036
|
+
if (token === typeRef && queryArgToken && getQueryScope(queryArgToken, this)) {
|
|
4037
|
+
const result = this.getDefinitionFor(token);
|
|
4038
|
+
return result ? [{
|
|
4039
|
+
targetUri: result.uri,
|
|
4040
|
+
targetRange: result.token?.range ?? zeroRange,
|
|
4041
|
+
targetSelectionRange: result.token?.range ?? zeroRange,
|
|
4042
|
+
originSelectionRange: token.range
|
|
4043
|
+
}] : void 0;
|
|
3926
4044
|
}
|
|
3927
4045
|
return;
|
|
3928
4046
|
}
|
|
@@ -4391,6 +4509,10 @@ var AtscriptDoc = class {
|
|
|
4391
4509
|
* List of query field ref nodes (for find-references support)
|
|
4392
4510
|
*/ _define_property$3(this, "queryFieldRefs", void 0);
|
|
4393
4511
|
/**
|
|
4512
|
+
* Field-path `string` annotation arguments whose spec declares `fieldScope`
|
|
4513
|
+
* (for find-references support)
|
|
4514
|
+
*/ _define_property$3(this, "fieldPathArgs", void 0);
|
|
4515
|
+
/**
|
|
4394
4516
|
* Map of dependencies (documents) by URI
|
|
4395
4517
|
*/ _define_property$3(this, "dependenciesMap", void 0);
|
|
4396
4518
|
_define_property$3(this, "_annotationSpecCache", void 0);
|
|
@@ -4416,6 +4538,7 @@ var AtscriptDoc = class {
|
|
|
4416
4538
|
this.dependants = /* @__PURE__ */ new Set();
|
|
4417
4539
|
this.referred = [];
|
|
4418
4540
|
this.queryFieldRefs = [];
|
|
4541
|
+
this.fieldPathArgs = [];
|
|
4419
4542
|
this.dependenciesMap = /* @__PURE__ */ new Map();
|
|
4420
4543
|
this._annotationSpecCache = /* @__PURE__ */ new Map();
|
|
4421
4544
|
this.nodes = [];
|
|
@@ -5839,6 +5962,7 @@ exports.createAtscriptPlugin = createAtscriptPlugin;
|
|
|
5839
5962
|
exports.defineConfig = defineConfig;
|
|
5840
5963
|
exports.fileUriToPath = fileUriToPath;
|
|
5841
5964
|
exports.flattenInterfaceNode = flattenInterfaceNode;
|
|
5965
|
+
exports.getFieldPathCompletionScope = getFieldPathCompletionScope;
|
|
5842
5966
|
exports.getFieldsForType = getFieldsForType;
|
|
5843
5967
|
exports.getQueryCompletionScope = getQueryCompletionScope;
|
|
5844
5968
|
exports.getQueryScope = getQueryScope;
|
|
@@ -5871,4 +5995,5 @@ exports.resolveAnnotation = resolveAnnotation;
|
|
|
5871
5995
|
exports.resolveAtscriptFromPath = resolveAtscriptFromPath;
|
|
5872
5996
|
exports.resolveBareSpecifier = resolveBareSpecifier;
|
|
5873
5997
|
exports.resolveConfigFile = resolveConfigFile;
|
|
5998
|
+
exports.resolveFieldRefAt = resolveFieldRefAt;
|
|
5874
5999
|
exports.resolveQueryFieldRef = resolveQueryFieldRef;
|
package/dist/index.d.ts
CHANGED
|
@@ -492,6 +492,11 @@ declare class AtscriptDoc {
|
|
|
492
492
|
* List of query field ref nodes (for find-references support)
|
|
493
493
|
*/
|
|
494
494
|
queryFieldRefs: Array<SemanticQueryFieldRefNode>;
|
|
495
|
+
/**
|
|
496
|
+
* Field-path `string` annotation arguments whose spec declares `fieldScope`
|
|
497
|
+
* (for find-references support)
|
|
498
|
+
*/
|
|
499
|
+
fieldPathArgs: Token[];
|
|
495
500
|
/**
|
|
496
501
|
* Map of dependencies (documents) by URI
|
|
497
502
|
*/
|
|
@@ -601,7 +606,11 @@ declare class AtscriptDoc {
|
|
|
601
606
|
* `undefined` when nothing matched (so callers can reuse the original by reference).
|
|
602
607
|
*/
|
|
603
608
|
private foldAnnotationsIntoStructure;
|
|
604
|
-
|
|
609
|
+
/**
|
|
610
|
+
* Usages of the symbol `token` stands for. `character` (the cursor column)
|
|
611
|
+
* narrows a dotted field-path string argument to the segment under the cursor.
|
|
612
|
+
*/
|
|
613
|
+
usageListFor(token: Token, character?: number): Array<{
|
|
605
614
|
uri: string;
|
|
606
615
|
range: Token['range'];
|
|
607
616
|
token: Token;
|
|
@@ -911,12 +920,40 @@ declare function resolveConfigFile(docUri: string, _root?: string): Promise<stri
|
|
|
911
920
|
declare function loadTsConfig(configFile: string, forceFormat?: 'cjs' | 'esm'): Promise<TAtscriptConfig>;
|
|
912
921
|
declare function loadConfig(configPath: string, forceFormat?: 'cjs' | 'esm'): Promise<TAtscriptConfig>;
|
|
913
922
|
|
|
923
|
+
/**
|
|
924
|
+
* Field scope of an annotation argument (returned by the `fieldScope` hook): which types
|
|
925
|
+
* its field refs may name (`Type.field`) and which type an unqualified field belongs to.
|
|
926
|
+
*/
|
|
927
|
+
interface TQueryScope {
|
|
928
|
+
/** Type names a qualified field ref (`Type.field`) may use. Not used by `string` arguments. */
|
|
929
|
+
allowedTypes: string[];
|
|
930
|
+
/**
|
|
931
|
+
* Type an unqualified field ref resolves against — for a `string` argument, the type
|
|
932
|
+
* whose (dotted) field path the string names. `null` when unqualified refs are not allowed.
|
|
933
|
+
*/
|
|
934
|
+
unqualifiedTarget: string | null;
|
|
935
|
+
}
|
|
914
936
|
interface TAnnotationArgument {
|
|
915
937
|
optional?: boolean;
|
|
916
938
|
name: string;
|
|
917
939
|
type: 'string' | 'number' | 'boolean' | 'ref' | 'query';
|
|
918
940
|
description?: string;
|
|
919
941
|
values?: string[];
|
|
942
|
+
/**
|
|
943
|
+
* Editor field scope of a `query` or `string` argument. Called with the argument token
|
|
944
|
+
* and the document that holds it; return `undefined` when the scope cannot be determined.
|
|
945
|
+
* - `query`: the types the backtick expression may reference (drives completion, hover,
|
|
946
|
+
* go-to-definition, find-references and rename of its field refs).
|
|
947
|
+
* - `string`: the argument is a (dotted) field path of `unqualifiedTarget` (`'amount'`,
|
|
948
|
+
* `'address.city'`) — same editor features on the string; `allowedTypes` is unused.
|
|
949
|
+
*/
|
|
950
|
+
fieldScope?: (argToken: Token, doc: AtscriptDoc) => TQueryScope | undefined;
|
|
951
|
+
/**
|
|
952
|
+
* For a `ref` argument: filters the type names offered by completion.
|
|
953
|
+
* Called with each candidate declaration and the document that declares it;
|
|
954
|
+
* return `false` to hide the candidate. All declarations are offered when absent.
|
|
955
|
+
*/
|
|
956
|
+
refFilter?: (decl: SemanticNode, doc: AtscriptDoc) => boolean;
|
|
920
957
|
}
|
|
921
958
|
interface TAnnotationSpecConfig {
|
|
922
959
|
multiple?: boolean;
|
|
@@ -1080,15 +1117,32 @@ declare const DB_ENTITY_ANNOTATIONS: readonly ["db.table", "db.view", "db.view.f
|
|
|
1080
1117
|
declare function isDbEntityNode(node: SemanticNode): boolean;
|
|
1081
1118
|
declare function isPhantomNode(doc: AtscriptDoc, def?: SemanticNode): boolean;
|
|
1082
1119
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1120
|
+
/** A field reference resolved to the property it names. */
|
|
1121
|
+
interface TFieldRefTarget {
|
|
1122
|
+
/** Type the field path was resolved against. */
|
|
1123
|
+
typeName: string;
|
|
1124
|
+
/** Range of the referencing text: a query field ref, or one segment of a field-path string. */
|
|
1125
|
+
range: Token['range'];
|
|
1126
|
+
prop: SemanticPropNode;
|
|
1127
|
+
/** Document that declares `prop`. */
|
|
1128
|
+
doc: AtscriptDoc;
|
|
1086
1129
|
}
|
|
1087
1130
|
/**
|
|
1088
|
-
*
|
|
1089
|
-
*
|
|
1131
|
+
* Field scope of an annotation argument: the answer of the argument spec's `fieldScope`
|
|
1132
|
+
* hook when it declares one, otherwise the deprecated built-in `@db.*` query rules.
|
|
1090
1133
|
*/
|
|
1091
|
-
declare function getQueryScope(
|
|
1134
|
+
declare function getQueryScope(argToken: Token, doc: AtscriptDoc): TQueryScope | undefined;
|
|
1135
|
+
/**
|
|
1136
|
+
* Resolve a field reference token to the property it names:
|
|
1137
|
+
* - a field ref inside a `query` argument (`amount`, `Customer.name` in backticks);
|
|
1138
|
+
* - a `string` argument whose spec declares `fieldScope`: a (dotted) field path of the
|
|
1139
|
+
* scope's `unqualifiedTarget`. With `character` (a cursor column), the path resolves
|
|
1140
|
+
* only up to the segment under the cursor — `'address.city'` with the cursor on
|
|
1141
|
+
* `address` resolves `address` — and `range` is that segment's range.
|
|
1142
|
+
*
|
|
1143
|
+
* Returns `undefined` for any other token, or when the scope or the path does not resolve.
|
|
1144
|
+
*/
|
|
1145
|
+
declare function resolveFieldRefAt(token: Token, doc: AtscriptDoc, character?: number): TFieldRefTarget | undefined;
|
|
1092
1146
|
/**
|
|
1093
1147
|
* Resolve a query field ref node to a property definition.
|
|
1094
1148
|
*/
|
|
@@ -1099,8 +1153,19 @@ declare function resolveQueryFieldRef(fieldRefNode: SemanticQueryFieldRefNode, d
|
|
|
1099
1153
|
} | undefined;
|
|
1100
1154
|
/**
|
|
1101
1155
|
* Get fields available for a type (resolving extends/intersections).
|
|
1156
|
+
* With `chain`, returns the fields of the nested object that field path leads to.
|
|
1102
1157
|
*/
|
|
1103
|
-
declare function getFieldsForType(doc: AtscriptDoc, typeName: string): SemanticPropNode[];
|
|
1158
|
+
declare function getFieldsForType(doc: AtscriptDoc, typeName: string, chain?: string[]): SemanticPropNode[];
|
|
1159
|
+
/**
|
|
1160
|
+
* Completion scope of a field-path `string` argument (spec declares `fieldScope`) at the
|
|
1161
|
+
* cursor column `character`: the fields of the level being typed — `'address.ci'` offers
|
|
1162
|
+
* the fields of `address` (`chain` = `['address']`).
|
|
1163
|
+
*/
|
|
1164
|
+
declare function getFieldPathCompletionScope(argToken: Token, doc: AtscriptDoc, character: number): {
|
|
1165
|
+
typeName: string;
|
|
1166
|
+
chain: string[];
|
|
1167
|
+
fields: SemanticPropNode[];
|
|
1168
|
+
} | undefined;
|
|
1104
1169
|
/**
|
|
1105
1170
|
* Get completion scope data for a query context.
|
|
1106
1171
|
*/
|
|
@@ -1129,5 +1194,5 @@ type TQueryCursorContext = {
|
|
|
1129
1194
|
*/
|
|
1130
1195
|
declare function analyzeQueryCursorContext(textBeforeCursor: string): TQueryCursorContext;
|
|
1131
1196
|
|
|
1132
|
-
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DB_ENTITY_ANNOTATIONS, 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, fileUriToPath, flattenInterfaceNode, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveQueryFieldRef };
|
|
1197
|
+
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DB_ENTITY_ANNOTATIONS, 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, fileUriToPath, flattenInterfaceNode, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveQueryFieldRef };
|
|
1133
1198
|
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
|
@@ -1386,19 +1386,25 @@ async function loadConfig(configPath, forceFormat) {
|
|
|
1386
1386
|
}
|
|
1387
1387
|
|
|
1388
1388
|
//#endregion
|
|
1389
|
-
//#region packages/core/src/
|
|
1389
|
+
//#region packages/core/src/lsp/legacy-db-query-scope.ts
|
|
1390
1390
|
/**
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1391
|
+
* @deprecated Built-in editor scopes for the `@db.view.filter`, `@db.view.joins` and
|
|
1392
|
+
* `@db.rel.filter` query arguments. They are a fallback for DB plugin versions whose
|
|
1393
|
+
* argument specs do not declare a `fieldScope` hook yet — the DB plugin owns these
|
|
1394
|
+
* rules now. Scheduled for removal in `@atscript/core` 0.2.0 (next minor).
|
|
1395
|
+
*/
|
|
1396
|
+
/**
|
|
1397
|
+
* @deprecated Query scope of a built-in `@db.*` query argument (see the module note);
|
|
1398
|
+
* `undefined` for any other annotation.
|
|
1399
|
+
*/ function getLegacyDbQueryScope(queryArgToken) {
|
|
1396
1400
|
const owner = queryArgToken.parentNode;
|
|
1397
1401
|
if (!owner) return;
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
+
switch (queryArgToken.annotationRef?.text.slice(1)) {
|
|
1403
|
+
case "db.view.filter": return getViewFilterScope(owner);
|
|
1404
|
+
case "db.view.joins": return getViewJoinsScope(owner, queryArgToken);
|
|
1405
|
+
case "db.rel.filter": return getRelFilterScope(owner);
|
|
1406
|
+
default: return;
|
|
1407
|
+
}
|
|
1402
1408
|
}
|
|
1403
1409
|
function getViewFilterScope(owner) {
|
|
1404
1410
|
const entryTypeName = (owner.annotations?.filter((a) => a.name === "db.view.for"))?.[0]?.args[0]?.text;
|
|
@@ -1436,35 +1442,159 @@ function getRelFilterScope(owner) {
|
|
|
1436
1442
|
unqualifiedTarget: targetTypeName
|
|
1437
1443
|
};
|
|
1438
1444
|
}
|
|
1445
|
+
|
|
1446
|
+
//#endregion
|
|
1447
|
+
//#region packages/core/src/lsp/field-refs.ts
|
|
1448
|
+
function getArgSpec(argToken, doc) {
|
|
1449
|
+
const annotationRef = argToken.annotationRef;
|
|
1450
|
+
if (!annotationRef || typeof argToken.index !== "number") return;
|
|
1451
|
+
return doc.resolveAnnotation(annotationRef.text.slice(1))?.arguments[argToken.index];
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Field scope of an annotation argument: the answer of the argument spec's `fieldScope`
|
|
1455
|
+
* hook when it declares one, otherwise the deprecated built-in `@db.*` query rules.
|
|
1456
|
+
*/ function getQueryScope(argToken, doc) {
|
|
1457
|
+
const argSpec = getArgSpec(argToken, doc);
|
|
1458
|
+
return argSpec?.fieldScope ? argSpec.fieldScope(argToken, doc) : getLegacyDbQueryScope(argToken);
|
|
1459
|
+
}
|
|
1460
|
+
/**
|
|
1461
|
+
* Type a field-path `string` argument names a field of: the `unqualifiedTarget` of the
|
|
1462
|
+
* argument spec's `fieldScope`. `undefined` for any other token.
|
|
1463
|
+
*/ function getFieldPathTarget(argToken, doc) {
|
|
1464
|
+
if (argToken.type !== "text") return;
|
|
1465
|
+
const argSpec = getArgSpec(argToken, doc);
|
|
1466
|
+
if (argSpec?.type !== "string" || !argSpec.fieldScope) return;
|
|
1467
|
+
return argSpec.fieldScope(argToken, doc)?.unqualifiedTarget ?? void 0;
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Resolve a (possibly dotted) field path of a type to the property it names and the
|
|
1471
|
+
* document that declares that property.
|
|
1472
|
+
*/ function resolveFieldPath(doc, typeName, segment) {
|
|
1473
|
+
const chain = segment.path.split(".");
|
|
1474
|
+
const [name] = chain.splice(-1);
|
|
1475
|
+
const parent = doc.unwindType(typeName, chain);
|
|
1476
|
+
if (!parent || !(isStructure(parent.def) || isInterface(parent.def))) return;
|
|
1477
|
+
const prop = parent.def.props.get(name);
|
|
1478
|
+
return prop && {
|
|
1479
|
+
typeName,
|
|
1480
|
+
range: segment.range,
|
|
1481
|
+
prop,
|
|
1482
|
+
doc: parent.doc
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Segments of a field-path string argument (`'address.city'` → `address`, `city`), with
|
|
1487
|
+
* ranges that exclude the quotes. A string spanning several lines is a single segment.
|
|
1488
|
+
*/ function fieldPathSegments(argToken) {
|
|
1489
|
+
const { text, range } = argToken;
|
|
1490
|
+
if (range.start.line !== range.end.line) return [{
|
|
1491
|
+
path: text,
|
|
1492
|
+
range
|
|
1493
|
+
}];
|
|
1494
|
+
const line = range.start.line;
|
|
1495
|
+
const contentStart = range.start.character + 1;
|
|
1496
|
+
const segments = [];
|
|
1497
|
+
let start = 0;
|
|
1498
|
+
for (const part of text.split(".")) {
|
|
1499
|
+
const end = start + part.length;
|
|
1500
|
+
segments.push({
|
|
1501
|
+
path: text.slice(0, end),
|
|
1502
|
+
range: {
|
|
1503
|
+
start: {
|
|
1504
|
+
line,
|
|
1505
|
+
character: contentStart + start
|
|
1506
|
+
},
|
|
1507
|
+
end: {
|
|
1508
|
+
line,
|
|
1509
|
+
character: contentStart + end
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
});
|
|
1513
|
+
start = end + 1;
|
|
1514
|
+
}
|
|
1515
|
+
return segments;
|
|
1516
|
+
}
|
|
1517
|
+
/** The segment under `character`, or the last segment when `character` is omitted. */ function fieldPathSegmentAt(argToken, character) {
|
|
1518
|
+
const segments = fieldPathSegments(argToken);
|
|
1519
|
+
return (character === void 0 ? void 0 : segments.find((s) => s.range.end.character >= character)) ?? segments[segments.length - 1];
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Resolve a field reference token to the property it names:
|
|
1523
|
+
* - a field ref inside a `query` argument (`amount`, `Customer.name` in backticks);
|
|
1524
|
+
* - a `string` argument whose spec declares `fieldScope`: a (dotted) field path of the
|
|
1525
|
+
* scope's `unqualifiedTarget`. With `character` (a cursor column), the path resolves
|
|
1526
|
+
* only up to the segment under the cursor — `'address.city'` with the cursor on
|
|
1527
|
+
* `address` resolves `address` — and `range` is that segment's range.
|
|
1528
|
+
*
|
|
1529
|
+
* Returns `undefined` for any other token, or when the scope or the path does not resolve.
|
|
1530
|
+
*/ function resolveFieldRefAt(token, doc, character) {
|
|
1531
|
+
if (isQueryFieldRef(token.parentNode)) {
|
|
1532
|
+
const { fieldRef, typeRef, queryArgToken } = token.parentNode;
|
|
1533
|
+
const scope = token === fieldRef && queryArgToken ? getQueryScope(queryArgToken, doc) : void 0;
|
|
1534
|
+
const typeName = scope && (typeRef?.text ?? scope.unqualifiedTarget);
|
|
1535
|
+
return typeName ? resolveFieldPath(doc, typeName, {
|
|
1536
|
+
path: token.text,
|
|
1537
|
+
range: token.range
|
|
1538
|
+
}) : void 0;
|
|
1539
|
+
}
|
|
1540
|
+
const typeName = getFieldPathTarget(token, doc);
|
|
1541
|
+
return typeName ? resolveFieldPath(doc, typeName, fieldPathSegmentAt(token, character)) : void 0;
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Resolve the segments named `fieldName` of a field-path `string` argument
|
|
1545
|
+
* (`'address.city'` has the segments `address` and `city`). Supports find-references.
|
|
1546
|
+
*/ function resolveFieldPathArgSegments(argToken, doc, fieldName) {
|
|
1547
|
+
const segments = fieldPathSegments(argToken).filter((s) => s.path === fieldName || s.path.endsWith(`.${fieldName}`));
|
|
1548
|
+
const typeName = segments.length > 0 ? getFieldPathTarget(argToken, doc) : void 0;
|
|
1549
|
+
if (!typeName) return [];
|
|
1550
|
+
const targets = [];
|
|
1551
|
+
for (const segment of segments) {
|
|
1552
|
+
const target = resolveFieldPath(doc, typeName, segment);
|
|
1553
|
+
if (target) targets.push(target);
|
|
1554
|
+
}
|
|
1555
|
+
return targets;
|
|
1556
|
+
}
|
|
1439
1557
|
/**
|
|
1440
1558
|
* Resolve a query field ref node to a property definition.
|
|
1441
1559
|
*/ function resolveQueryFieldRef(fieldRefNode, doc, scope) {
|
|
1442
1560
|
const typeName = fieldRefNode.typeRef?.text ?? scope.unqualifiedTarget;
|
|
1443
|
-
|
|
1444
|
-
const
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
targetUri: parentUnwound.doc.id,
|
|
1453
|
-
doc: parentUnwound.doc,
|
|
1454
|
-
prop
|
|
1561
|
+
const { fieldRef } = fieldRefNode;
|
|
1562
|
+
const resolved = typeName ? resolveFieldPath(doc, typeName, {
|
|
1563
|
+
path: fieldRef.text,
|
|
1564
|
+
range: fieldRef.range
|
|
1565
|
+
}) : void 0;
|
|
1566
|
+
return resolved && {
|
|
1567
|
+
targetUri: resolved.doc.id,
|
|
1568
|
+
doc: resolved.doc,
|
|
1569
|
+
prop: resolved.prop
|
|
1455
1570
|
};
|
|
1456
1571
|
}
|
|
1457
1572
|
/**
|
|
1458
1573
|
* Get fields available for a type (resolving extends/intersections).
|
|
1459
|
-
|
|
1460
|
-
|
|
1574
|
+
* With `chain`, returns the fields of the nested object that field path leads to.
|
|
1575
|
+
*/ function getFieldsForType(doc, typeName, chain = []) {
|
|
1576
|
+
const unwound = doc.unwindType(typeName, chain);
|
|
1461
1577
|
if (!unwound?.def) return [];
|
|
1462
|
-
let def = doc.mergeIntersection(unwound.def);
|
|
1463
|
-
if (isInterface(def)) def = doc.resolveInterfaceExtends(def) || def.getDefinition() || def;
|
|
1578
|
+
let def = unwound.doc.mergeIntersection(unwound.def);
|
|
1579
|
+
if (isInterface(def)) def = unwound.doc.resolveInterfaceExtends(def) || def.getDefinition() || def;
|
|
1464
1580
|
if (isStructure(def) || isInterface(def)) return Array.from(def.props.values());
|
|
1465
1581
|
return [];
|
|
1466
1582
|
}
|
|
1467
1583
|
/**
|
|
1584
|
+
* Completion scope of a field-path `string` argument (spec declares `fieldScope`) at the
|
|
1585
|
+
* cursor column `character`: the fields of the level being typed — `'address.ci'` offers
|
|
1586
|
+
* the fields of `address` (`chain` = `['address']`).
|
|
1587
|
+
*/ function getFieldPathCompletionScope(argToken, doc, character) {
|
|
1588
|
+
const typeName = getFieldPathTarget(argToken, doc);
|
|
1589
|
+
if (!typeName) return;
|
|
1590
|
+
const chain = fieldPathSegmentAt(argToken, character).path.split(".").slice(0, -1);
|
|
1591
|
+
return {
|
|
1592
|
+
typeName,
|
|
1593
|
+
chain,
|
|
1594
|
+
fields: getFieldsForType(doc, typeName, chain)
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1468
1598
|
* Get completion scope data for a query context.
|
|
1469
1599
|
*/ function getQueryCompletionScope(queryArgToken, doc) {
|
|
1470
1600
|
const scope = getQueryScope(queryArgToken, doc);
|
|
@@ -3386,6 +3516,7 @@ var AtscriptDoc = class {
|
|
|
3386
3516
|
this.messages = [];
|
|
3387
3517
|
this.referred = [];
|
|
3388
3518
|
this.queryFieldRefs = [];
|
|
3519
|
+
this.fieldPathArgs = [];
|
|
3389
3520
|
this.imports.clear();
|
|
3390
3521
|
this.resolvedImports.clear();
|
|
3391
3522
|
this._allMessages = void 0;
|
|
@@ -3432,6 +3563,7 @@ var AtscriptDoc = class {
|
|
|
3432
3563
|
}
|
|
3433
3564
|
}
|
|
3434
3565
|
if (argSpec?.type === "query" && args?.[i]?.queryNode) args[i].queryNode.registerAtDocument(this);
|
|
3566
|
+
if (argSpec?.type === "string" && argSpec.fieldScope && args?.[i]) this.fieldPathArgs.push(args[i]);
|
|
3435
3567
|
}
|
|
3436
3568
|
} else {
|
|
3437
3569
|
let severity = 1;
|
|
@@ -3530,7 +3662,7 @@ var AtscriptDoc = class {
|
|
|
3530
3662
|
}
|
|
3531
3663
|
getUsageListAt(line, character) {
|
|
3532
3664
|
const token = this.tokensIndex.at(line, character);
|
|
3533
|
-
if (token) return this.usageListFor(token);
|
|
3665
|
+
if (token) return this.usageListFor(token, character);
|
|
3534
3666
|
}
|
|
3535
3667
|
evalAnnotationsForNode(givenNode) {
|
|
3536
3668
|
let right = givenNode.annotations;
|
|
@@ -3711,7 +3843,10 @@ var AtscriptDoc = class {
|
|
|
3711
3843
|
newStruct.annotations = struct.annotations;
|
|
3712
3844
|
return newStruct;
|
|
3713
3845
|
}
|
|
3714
|
-
|
|
3846
|
+
/**
|
|
3847
|
+
* Usages of the symbol `token` stands for. `character` (the cursor column)
|
|
3848
|
+
* narrows a dotted field-path string argument to the segment under the cursor.
|
|
3849
|
+
*/ usageListFor(token, character) {
|
|
3715
3850
|
if (token.isDefinition) {
|
|
3716
3851
|
const refs = this.referred.filter((t) => t.text === token.text).map((r) => ({
|
|
3717
3852
|
uri: this.id,
|
|
@@ -3727,6 +3862,9 @@ var AtscriptDoc = class {
|
|
|
3727
3862
|
}
|
|
3728
3863
|
return refs;
|
|
3729
3864
|
}
|
|
3865
|
+
const fieldRef = resolveFieldRefAt(token, this, character);
|
|
3866
|
+
const fieldRefProp = fieldRef?.prop.token("identifier");
|
|
3867
|
+
if (fieldRef && fieldRefProp) return fieldRef.doc.usageListFor(fieldRefProp);
|
|
3730
3868
|
if (isProp(token.parentNode)) {
|
|
3731
3869
|
const propName = token.parentNode.id;
|
|
3732
3870
|
if (!propName) return;
|
|
@@ -3759,15 +3897,18 @@ var AtscriptDoc = class {
|
|
|
3759
3897
|
}
|
|
3760
3898
|
}
|
|
3761
3899
|
for (const qfr of doc.queryFieldRefs) {
|
|
3762
|
-
if (
|
|
3763
|
-
|
|
3764
|
-
if (!scope) continue;
|
|
3765
|
-
if ((qfr.typeRef?.text ?? scope.unqualifiedTarget) === parentName) refs.push({
|
|
3900
|
+
if (qfr.fieldRef.text !== propName) continue;
|
|
3901
|
+
if (resolveFieldRefAt(qfr.fieldRef, doc)?.prop === token.parentNode) refs.push({
|
|
3766
3902
|
uri,
|
|
3767
3903
|
range: qfr.fieldRef.range,
|
|
3768
3904
|
token: qfr.fieldRef
|
|
3769
3905
|
});
|
|
3770
3906
|
}
|
|
3907
|
+
for (const arg of doc.fieldPathArgs) for (const target of resolveFieldPathArgSegments(arg, doc, propName)) if (target.prop === token.parentNode) refs.push({
|
|
3908
|
+
uri,
|
|
3909
|
+
range: target.range,
|
|
3910
|
+
token: arg
|
|
3911
|
+
});
|
|
3771
3912
|
};
|
|
3772
3913
|
searchDoc(this, this.id);
|
|
3773
3914
|
if (this.registry.definitions.get(parentName)?.exported) {
|
|
@@ -3776,21 +3917,6 @@ var AtscriptDoc = class {
|
|
|
3776
3917
|
}
|
|
3777
3918
|
return refs;
|
|
3778
3919
|
}
|
|
3779
|
-
if (isQueryFieldRef(token.parentNode) && token === token.parentNode.fieldRef) {
|
|
3780
|
-
const fieldRefNode = token.parentNode;
|
|
3781
|
-
const queryArgToken = fieldRefNode.queryArgToken;
|
|
3782
|
-
if (queryArgToken) {
|
|
3783
|
-
const scope = getQueryScope(queryArgToken, this);
|
|
3784
|
-
if (scope) {
|
|
3785
|
-
const resolved = resolveQueryFieldRef(fieldRefNode, this, scope);
|
|
3786
|
-
if (resolved?.prop) {
|
|
3787
|
-
const propToken = resolved.prop.token("identifier");
|
|
3788
|
-
if (propToken) return resolved.doc.usageListFor(propToken);
|
|
3789
|
-
}
|
|
3790
|
-
}
|
|
3791
|
-
}
|
|
3792
|
-
return;
|
|
3793
|
-
}
|
|
3794
3920
|
{
|
|
3795
3921
|
const defForToken = this.getDefinitionFor(token);
|
|
3796
3922
|
if (defForToken?.token?.isDefinition && defForToken.doc) return defForToken.doc.usageListFor(defForToken.token);
|
|
@@ -3864,34 +3990,26 @@ var AtscriptDoc = class {
|
|
|
3864
3990
|
}];
|
|
3865
3991
|
return;
|
|
3866
3992
|
}
|
|
3993
|
+
const fieldRef = resolveFieldRefAt(token, this, character);
|
|
3994
|
+
if (fieldRef) {
|
|
3995
|
+
const propRange = fieldRef.prop.token("identifier")?.range ?? zeroRange;
|
|
3996
|
+
return [{
|
|
3997
|
+
targetUri: fieldRef.doc.id,
|
|
3998
|
+
targetRange: propRange,
|
|
3999
|
+
targetSelectionRange: propRange,
|
|
4000
|
+
originSelectionRange: fieldRef.range
|
|
4001
|
+
}];
|
|
4002
|
+
}
|
|
3867
4003
|
if (isQueryFieldRef(token.parentNode)) {
|
|
3868
|
-
const
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
targetRange: result.token?.range ?? zeroRange,
|
|
3878
|
-
targetSelectionRange: result.token?.range ?? zeroRange,
|
|
3879
|
-
originSelectionRange: token.range
|
|
3880
|
-
}] : void 0;
|
|
3881
|
-
}
|
|
3882
|
-
if (token === fieldRefNode.fieldRef) {
|
|
3883
|
-
const resolved = resolveQueryFieldRef(fieldRefNode, this, scope);
|
|
3884
|
-
if (resolved?.prop) {
|
|
3885
|
-
const propToken = resolved.prop.token("identifier");
|
|
3886
|
-
return [{
|
|
3887
|
-
targetUri: resolved.targetUri,
|
|
3888
|
-
targetRange: propToken?.range ?? zeroRange,
|
|
3889
|
-
targetSelectionRange: propToken?.range ?? zeroRange,
|
|
3890
|
-
originSelectionRange: token.range
|
|
3891
|
-
}];
|
|
3892
|
-
}
|
|
3893
|
-
}
|
|
3894
|
-
}
|
|
4004
|
+
const { typeRef, queryArgToken } = token.parentNode;
|
|
4005
|
+
if (token === typeRef && queryArgToken && getQueryScope(queryArgToken, this)) {
|
|
4006
|
+
const result = this.getDefinitionFor(token);
|
|
4007
|
+
return result ? [{
|
|
4008
|
+
targetUri: result.uri,
|
|
4009
|
+
targetRange: result.token?.range ?? zeroRange,
|
|
4010
|
+
targetSelectionRange: result.token?.range ?? zeroRange,
|
|
4011
|
+
originSelectionRange: token.range
|
|
4012
|
+
}] : void 0;
|
|
3895
4013
|
}
|
|
3896
4014
|
return;
|
|
3897
4015
|
}
|
|
@@ -4360,6 +4478,10 @@ var AtscriptDoc = class {
|
|
|
4360
4478
|
* List of query field ref nodes (for find-references support)
|
|
4361
4479
|
*/ _define_property$3(this, "queryFieldRefs", void 0);
|
|
4362
4480
|
/**
|
|
4481
|
+
* Field-path `string` annotation arguments whose spec declares `fieldScope`
|
|
4482
|
+
* (for find-references support)
|
|
4483
|
+
*/ _define_property$3(this, "fieldPathArgs", void 0);
|
|
4484
|
+
/**
|
|
4363
4485
|
* Map of dependencies (documents) by URI
|
|
4364
4486
|
*/ _define_property$3(this, "dependenciesMap", void 0);
|
|
4365
4487
|
_define_property$3(this, "_annotationSpecCache", void 0);
|
|
@@ -4385,6 +4507,7 @@ var AtscriptDoc = class {
|
|
|
4385
4507
|
this.dependants = /* @__PURE__ */ new Set();
|
|
4386
4508
|
this.referred = [];
|
|
4387
4509
|
this.queryFieldRefs = [];
|
|
4510
|
+
this.fieldPathArgs = [];
|
|
4388
4511
|
this.dependenciesMap = /* @__PURE__ */ new Map();
|
|
4389
4512
|
this._annotationSpecCache = /* @__PURE__ */ new Map();
|
|
4390
4513
|
this.nodes = [];
|
|
@@ -5773,4 +5896,4 @@ function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack
|
|
|
5773
5896
|
}
|
|
5774
5897
|
|
|
5775
5898
|
//#endregion
|
|
5776
|
-
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DB_ENTITY_ANNOTATIONS, 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, fileUriToPath, flattenInterfaceNode, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveQueryFieldRef };
|
|
5899
|
+
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DB_ENTITY_ANNOTATIONS, 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, fileUriToPath, flattenInterfaceNode, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveQueryFieldRef };
|