@prisma/orm-toolchain 8.0.0-rc.14-dev.17 → 8.0.0-rc.14-dev.19
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.
|
@@ -604,20 +604,25 @@ function classifyFieldAttribute(input) {
|
|
|
604
604
|
...position,
|
|
605
605
|
...owner
|
|
606
606
|
}),
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
607
|
+
arguments: (attributeName) => ({
|
|
608
|
+
namedKey: (position) => ({
|
|
609
|
+
kind: "fieldAttributeNamedKey",
|
|
610
|
+
...position,
|
|
611
|
+
...owner,
|
|
612
|
+
attributeName
|
|
613
|
+
}),
|
|
614
|
+
argumentSlot: (position) => ({
|
|
615
|
+
kind: "fieldAttributeArgumentSlot",
|
|
616
|
+
...position,
|
|
617
|
+
...owner,
|
|
618
|
+
attributeName
|
|
619
|
+
}),
|
|
620
|
+
value: (position) => ({
|
|
621
|
+
kind: "fieldAttributeValue",
|
|
622
|
+
...position,
|
|
623
|
+
...owner,
|
|
624
|
+
attributeName
|
|
625
|
+
})
|
|
621
626
|
})
|
|
622
627
|
});
|
|
623
628
|
}
|
|
@@ -638,20 +643,25 @@ function classifyGenericBlockAttribute(input) {
|
|
|
638
643
|
...position,
|
|
639
644
|
...owner
|
|
640
645
|
}),
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
646
|
+
arguments: (attributeName) => ({
|
|
647
|
+
namedKey: (position) => ({
|
|
648
|
+
kind: "blockAttributeNamedKey",
|
|
649
|
+
...position,
|
|
650
|
+
...owner,
|
|
651
|
+
attributeName
|
|
652
|
+
}),
|
|
653
|
+
argumentSlot: (position) => ({
|
|
654
|
+
kind: "blockAttributeArgumentSlot",
|
|
655
|
+
...position,
|
|
656
|
+
...owner,
|
|
657
|
+
attributeName
|
|
658
|
+
}),
|
|
659
|
+
value: (position) => ({
|
|
660
|
+
kind: "blockAttributeValue",
|
|
661
|
+
...position,
|
|
662
|
+
...owner,
|
|
663
|
+
attributeName
|
|
664
|
+
})
|
|
655
665
|
})
|
|
656
666
|
});
|
|
657
667
|
}
|
|
@@ -670,20 +680,25 @@ function classifyModelAttribute(input) {
|
|
|
670
680
|
...position,
|
|
671
681
|
...owner
|
|
672
682
|
}),
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
683
|
+
arguments: (attributeName) => ({
|
|
684
|
+
namedKey: (position) => ({
|
|
685
|
+
kind: "modelAttributeNamedKey",
|
|
686
|
+
...position,
|
|
687
|
+
...owner,
|
|
688
|
+
attributeName
|
|
689
|
+
}),
|
|
690
|
+
argumentSlot: (position) => ({
|
|
691
|
+
kind: "modelAttributeArgumentSlot",
|
|
692
|
+
...position,
|
|
693
|
+
...owner,
|
|
694
|
+
attributeName
|
|
695
|
+
}),
|
|
696
|
+
value: (position) => ({
|
|
697
|
+
kind: "modelAttributeValue",
|
|
698
|
+
...position,
|
|
699
|
+
...owner,
|
|
700
|
+
attributeName
|
|
701
|
+
})
|
|
687
702
|
})
|
|
688
703
|
});
|
|
689
704
|
}
|
|
@@ -706,25 +721,27 @@ function classifyAttributePosition(attribute, input, factory) {
|
|
|
706
721
|
});
|
|
707
722
|
const attributeName = attribute.name()?.identifier()?.name();
|
|
708
723
|
if (attributeName === void 0) return UNSUPPORTED;
|
|
709
|
-
const at = attribute.syntax.tokenAtOffset(input.offset);
|
|
710
|
-
const right = at.rightBiased();
|
|
711
|
-
const token = isValueToken(right) ? right : at.leftBiased();
|
|
712
|
-
const replaceToken = isValueToken(token);
|
|
713
724
|
return classifyAttributeArguments({
|
|
714
|
-
offset
|
|
715
|
-
replacementStartOffset: replaceToken ? token.offset : input.offset,
|
|
716
|
-
replacementEndOffset: replaceToken ? token.endOffset : input.offset,
|
|
717
|
-
attributeName,
|
|
725
|
+
...valueReplacement(attribute.syntax.tokenAtOffset(input.offset), input.offset),
|
|
718
726
|
preceding: attributeCursor(attribute, input.offset).preceding,
|
|
719
|
-
factory
|
|
727
|
+
factory: factory.arguments(attributeName)
|
|
720
728
|
}, args, []);
|
|
721
729
|
}
|
|
730
|
+
function valueReplacement(at, offset) {
|
|
731
|
+
const right = at.rightBiased();
|
|
732
|
+
const token = isValueToken(right) ? right : at.leftBiased();
|
|
733
|
+
const replaceToken = isValueToken(token);
|
|
734
|
+
return {
|
|
735
|
+
offset,
|
|
736
|
+
replacementStartOffset: replaceToken ? token.offset : offset,
|
|
737
|
+
replacementEndOffset: replaceToken ? token.endOffset : offset
|
|
738
|
+
};
|
|
739
|
+
}
|
|
722
740
|
function argumentPosition(cursor, path) {
|
|
723
741
|
return {
|
|
724
742
|
offset: cursor.offset,
|
|
725
743
|
replacementStartOffset: cursor.replacementStartOffset,
|
|
726
744
|
replacementEndOffset: cursor.replacementEndOffset,
|
|
727
|
-
attributeName: cursor.attributeName,
|
|
728
745
|
path
|
|
729
746
|
};
|
|
730
747
|
}
|
|
@@ -767,7 +784,8 @@ function classifyAttributeArguments(cursor, args, path) {
|
|
|
767
784
|
function classifyAttributeExpression(cursor, expression, path) {
|
|
768
785
|
if (expression === void 0) return cursor.factory.value({
|
|
769
786
|
...argumentPosition(cursor, path),
|
|
770
|
-
syntax: "scalar"
|
|
787
|
+
syntax: "scalar",
|
|
788
|
+
qualifier: void 0
|
|
771
789
|
});
|
|
772
790
|
if (expression instanceof ArrayLiteralAst) {
|
|
773
791
|
if (!betweenDelimiters(cursor.offset, expression.lbracket(), expression.rbracket())) return UNSUPPORTED;
|
|
@@ -792,12 +810,25 @@ function classifyAttributeExpression(cursor, expression, path) {
|
|
|
792
810
|
}
|
|
793
811
|
return expression.name()?.syntax.isInside(cursor.offset) === true ? cursor.factory.value({
|
|
794
812
|
...argumentPosition(cursor, path),
|
|
795
|
-
syntax: "functionName"
|
|
813
|
+
syntax: "functionName",
|
|
814
|
+
qualifier: void 0
|
|
796
815
|
}) : UNSUPPORTED;
|
|
797
816
|
}
|
|
798
|
-
|
|
817
|
+
if (expression.syntax.isOutside(cursor.offset)) return UNSUPPORTED;
|
|
818
|
+
if (expression instanceof PathExprAst) return classifyQualifiedValue(cursor, expression, path);
|
|
819
|
+
return cursor.factory.value({
|
|
820
|
+
...argumentPosition(cursor, path),
|
|
821
|
+
syntax: "scalar",
|
|
822
|
+
qualifier: void 0
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
function classifyQualifiedValue(cursor, expression, path) {
|
|
826
|
+
const qualifier = [...expression.segments()].filter((segment) => segment.syntax.endOffset < cursor.replacementStartOffset);
|
|
827
|
+
if (qualifier.length > 1) return UNSUPPORTED;
|
|
828
|
+
return cursor.factory.value({
|
|
799
829
|
...argumentPosition(cursor, path),
|
|
800
|
-
syntax: "scalar"
|
|
830
|
+
syntax: "scalar",
|
|
831
|
+
qualifier: qualifier[0]?.name()
|
|
801
832
|
});
|
|
802
833
|
}
|
|
803
834
|
function isValueToken(token) {
|
|
@@ -815,14 +846,8 @@ function classifyGenericBlockParameter(input) {
|
|
|
815
846
|
if ((node?.findAncestor(FieldDeclarationAst.cast))?.syntax.isInside(input.offset)) return UNSUPPORTED;
|
|
816
847
|
const keyword = block.keyword()?.text;
|
|
817
848
|
if (keyword === void 0 || keyword.length === 0) return UNSUPPORTED;
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
offset: input.offset,
|
|
821
|
-
blockKeyword: keyword,
|
|
822
|
-
replacementStartOffset: input.replacementStartOffset
|
|
823
|
-
};
|
|
824
|
-
const activePair = activeKeyValuePair(node, input.offset);
|
|
825
|
-
if (activePair !== void 0 && isAfterEquals(activePair, input.offset)) return UNSUPPORTED;
|
|
849
|
+
const valuePair = valuePairAtCursor(node, input.precedingToken, input.offset);
|
|
850
|
+
if (valuePair !== void 0) return classifyBlockValue(valuePair, block, keyword, input);
|
|
826
851
|
return {
|
|
827
852
|
kind: "genericBlockKey",
|
|
828
853
|
offset: input.offset,
|
|
@@ -831,6 +856,43 @@ function classifyGenericBlockParameter(input) {
|
|
|
831
856
|
block
|
|
832
857
|
};
|
|
833
858
|
}
|
|
859
|
+
function valuePairAtCursor(node, preceding, offset) {
|
|
860
|
+
if (preceding?.kind === "Equals") return preceding.parent.findAncestor(KeyValuePairAst.cast);
|
|
861
|
+
const pair = activeKeyValuePair(node, offset);
|
|
862
|
+
return pair !== void 0 && isAfterEquals(pair, offset) ? pair : void 0;
|
|
863
|
+
}
|
|
864
|
+
function classifyBlockValue(pair, block, blockKeyword, input) {
|
|
865
|
+
const key = pair.key()?.name();
|
|
866
|
+
if (key === void 0) return UNSUPPORTED;
|
|
867
|
+
const owner = {
|
|
868
|
+
ownerKind: "blockValue",
|
|
869
|
+
block,
|
|
870
|
+
blockKeyword,
|
|
871
|
+
key
|
|
872
|
+
};
|
|
873
|
+
const anchor = input.at.leftBiased();
|
|
874
|
+
return classifyAttributeExpression({
|
|
875
|
+
...valueReplacement(input.at, input.offset),
|
|
876
|
+
preceding: anchor === void 0 ? void 0 : skipTriviaToken(anchor, "prev"),
|
|
877
|
+
factory: {
|
|
878
|
+
namedKey: (position) => ({
|
|
879
|
+
kind: "blockValueNamedKey",
|
|
880
|
+
...position,
|
|
881
|
+
...owner
|
|
882
|
+
}),
|
|
883
|
+
argumentSlot: (position) => ({
|
|
884
|
+
kind: "blockValueArgumentSlot",
|
|
885
|
+
...position,
|
|
886
|
+
...owner
|
|
887
|
+
}),
|
|
888
|
+
value: (position) => ({
|
|
889
|
+
kind: "blockValue",
|
|
890
|
+
...position,
|
|
891
|
+
...owner
|
|
892
|
+
})
|
|
893
|
+
}
|
|
894
|
+
}, pair.value(), []);
|
|
895
|
+
}
|
|
834
896
|
function activeKeyValuePair(node, offset) {
|
|
835
897
|
const pair = node?.findAncestor(KeyValuePairAst.cast);
|
|
836
898
|
if (pair === void 0 || pair.syntax.isOutside(offset)) return;
|
|
@@ -856,19 +918,29 @@ function cursorIdentifier(at, offset) {
|
|
|
856
918
|
const left = at.leftBiased();
|
|
857
919
|
if (left?.kind === "Ident" && left.endOffset === offset) return left;
|
|
858
920
|
}
|
|
921
|
+
function argumentRootGrammar(owner, source) {
|
|
922
|
+
switch (owner.ownerKind) {
|
|
923
|
+
case "field":
|
|
924
|
+
case "model":
|
|
925
|
+
case "block": return attributeSpecResolver(owner, source)(owner.attributeName);
|
|
926
|
+
case "blockValue": return blockValueGrammar(owner, source);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
function blockValueGrammar(owner, source) {
|
|
930
|
+
const descriptor = findBlockDescriptor(source.pslBlockDescriptors, owner.blockKeyword);
|
|
931
|
+
if (descriptor === void 0) return void 0;
|
|
932
|
+
const spec = blockSpecFactoryOf(descriptor)({ symbols: source.symbolTable });
|
|
933
|
+
if (spec.mode === "map") return spec.value.type;
|
|
934
|
+
return Object.hasOwn(spec.parameters, owner.key) ? spec.parameters[owner.key]?.type : void 0;
|
|
935
|
+
}
|
|
859
936
|
function attributeSpecResolver(context, source) {
|
|
860
937
|
switch (context.ownerKind) {
|
|
861
938
|
case "block": {
|
|
862
939
|
const descriptor = findBlockDescriptor(source.pslBlockDescriptors, context.blockKeyword);
|
|
863
|
-
const block = source.binder.declaredSymbol(context.block.syntax);
|
|
864
|
-
if (block?.kind !== "block") return () => void 0;
|
|
865
940
|
return (name) => {
|
|
866
941
|
const factory = descriptor?.attributes?.[name];
|
|
867
942
|
if (factory === void 0) return void 0;
|
|
868
|
-
return blindCast(factory)({
|
|
869
|
-
symbols: source.symbolTable,
|
|
870
|
-
block
|
|
871
|
-
});
|
|
943
|
+
return blindCast(factory)({ symbols: source.symbolTable });
|
|
872
944
|
};
|
|
873
945
|
}
|
|
874
946
|
case "model": {
|
|
@@ -960,12 +1032,11 @@ function refinesScalarType(symbol, binder) {
|
|
|
960
1032
|
const node = typeReferenceNode(symbol);
|
|
961
1033
|
return !symbol.isConstructor && symbol.node.typeAnnotation()?.name()?.namespace() === void 0 && node !== void 0 && binder.symbolForNode(node)?.kind === "contributedType";
|
|
962
1034
|
}
|
|
963
|
-
function scopeCompletionItems(entries, binder, range, capabilities,
|
|
1035
|
+
function scopeCompletionItems(entries, binder, range, capabilities, selection) {
|
|
964
1036
|
const items = [];
|
|
965
1037
|
for (const [name, resolution] of entries) {
|
|
966
|
-
if (
|
|
967
|
-
|
|
968
|
-
if (reference === void 0 || !matchesSelector(reference, selector)) continue;
|
|
1038
|
+
if (selection !== void 0) {
|
|
1039
|
+
if (!offersEntity(resolution, selection)) continue;
|
|
969
1040
|
} else if (resolution.kind === "block") continue;
|
|
970
1041
|
const item = {
|
|
971
1042
|
label: name,
|
|
@@ -1031,8 +1102,20 @@ function scopeCompletionItems(entries, binder, range, capabilities, selector) {
|
|
|
1031
1102
|
}
|
|
1032
1103
|
return items;
|
|
1033
1104
|
}
|
|
1105
|
+
function offersEntity(resolution, selection) {
|
|
1106
|
+
if (isNamespaceLike(resolution)) {
|
|
1107
|
+
if (!selection.namespaces) return false;
|
|
1108
|
+
for (const [, member] of memberEntries(resolution)) if (matchesEntity(member, selection.selector)) return true;
|
|
1109
|
+
return false;
|
|
1110
|
+
}
|
|
1111
|
+
return matchesEntity(resolution, selection.selector);
|
|
1112
|
+
}
|
|
1113
|
+
function matchesEntity(resolution, selector) {
|
|
1114
|
+
const reference = entityReference(resolution);
|
|
1115
|
+
return reference !== void 0 && matchesSelector(reference, selector);
|
|
1116
|
+
}
|
|
1034
1117
|
function localFieldNames(context, binder) {
|
|
1035
|
-
if (context.ownerKind === "block") return [];
|
|
1118
|
+
if (context.ownerKind === "block" || context.ownerKind === "blockValue") return [];
|
|
1036
1119
|
const model = binder.declaredSymbol(context.model.syntax);
|
|
1037
1120
|
return scalarFieldNames(model?.kind === "model" ? model : void 0, binder);
|
|
1038
1121
|
}
|
|
@@ -1057,8 +1140,8 @@ function isScalarReference(symbol, binder) {
|
|
|
1057
1140
|
const name = annotation?.name();
|
|
1058
1141
|
return name !== void 0 && binder.symbolForNode(name.syntax)?.kind === "contributedType" && (annotation?.isConstructor() === true || name.namespace() === void 0);
|
|
1059
1142
|
}
|
|
1060
|
-
function resolveGrammar(
|
|
1061
|
-
let grammars = [
|
|
1143
|
+
function resolveGrammar(root, path) {
|
|
1144
|
+
let grammars = [root];
|
|
1062
1145
|
for (const step of path) grammars = grammars.flatMap((grammar) => advanceGrammar(grammar, step));
|
|
1063
1146
|
return grammars;
|
|
1064
1147
|
}
|
|
@@ -1081,18 +1164,18 @@ function advanceGrammar(grammar, step) {
|
|
|
1081
1164
|
case "functionCall": return type?.kind === "funcCall" && type.name === step.name ? [type.signature] : [];
|
|
1082
1165
|
}
|
|
1083
1166
|
}
|
|
1084
|
-
function provideAttributeNamedKeyCompletionItems(input,
|
|
1085
|
-
return orderedItems(resolveGrammar(
|
|
1167
|
+
function provideAttributeNamedKeyCompletionItems(input, root) {
|
|
1168
|
+
return orderedItems(resolveGrammar(root, input.context.path).flatMap((grammar) => "kind" in grammar ? [] : namedKeyItems(input, grammar)));
|
|
1086
1169
|
}
|
|
1087
|
-
function provideAttributeArgumentSlotCompletionItems(input,
|
|
1088
|
-
return orderedItems(resolveGrammar(
|
|
1170
|
+
function provideAttributeArgumentSlotCompletionItems(input, root) {
|
|
1171
|
+
return orderedItems(resolveGrammar(root, input.context.path).flatMap((grammar) => {
|
|
1089
1172
|
if ("kind" in grammar) return [];
|
|
1090
1173
|
const param = grammar.positional?.[input.context.positionalIndex]?.type;
|
|
1091
|
-
return [...valueItems(input, param, "scalar"), ...namedKeyItems(input, grammar)];
|
|
1174
|
+
return [...valueItems(input, param, "scalar", void 0), ...namedKeyItems(input, grammar)];
|
|
1092
1175
|
}));
|
|
1093
1176
|
}
|
|
1094
|
-
function provideAttributeValueCompletionItems(input,
|
|
1095
|
-
return orderedItems(resolveGrammar(
|
|
1177
|
+
function provideAttributeValueCompletionItems(input, root) {
|
|
1178
|
+
return orderedItems(resolveGrammar(root, input.context.path).flatMap((grammar) => "kind" in grammar ? valueItems(input, grammar, input.context.syntax, input.context.qualifier) : []));
|
|
1096
1179
|
}
|
|
1097
1180
|
function namedKeyItems(input, signature) {
|
|
1098
1181
|
return Object.entries(signature.named ?? {}).filter(([name]) => !input.context.existingNamedKeys.includes(name)).map(([name, param]) => {
|
|
@@ -1107,9 +1190,9 @@ function namedKeyItems(input, signature) {
|
|
|
1107
1190
|
};
|
|
1108
1191
|
});
|
|
1109
1192
|
}
|
|
1110
|
-
function valueItems(input, type, syntax) {
|
|
1193
|
+
function valueItems(input, type, syntax, qualifier) {
|
|
1111
1194
|
if (type === void 0) return [];
|
|
1112
|
-
if (type.kind === "oneOf") return type.alternatives.flatMap((alternative) => valueItems(input, alternative, syntax));
|
|
1195
|
+
if (type.kind === "oneOf") return type.alternatives.flatMap((alternative) => valueItems(input, alternative, syntax, qualifier));
|
|
1113
1196
|
if (type.kind === "funcCall") {
|
|
1114
1197
|
const snippet = input.clientSupportsSnippets && syntax !== "functionName";
|
|
1115
1198
|
const hasParameters = (type.signature.positional?.length ?? 0) > 0 || Object.keys(type.signature.named ?? {}).length > 0;
|
|
@@ -1124,6 +1207,7 @@ function valueItems(input, type, syntax) {
|
|
|
1124
1207
|
}];
|
|
1125
1208
|
}
|
|
1126
1209
|
if (syntax === "functionName") return [];
|
|
1210
|
+
if (qualifier !== void 0) return qualifiedItems(input, type, qualifier);
|
|
1127
1211
|
if (type.kind === "taggedLiteral") return type.tags.map((tag) => ({
|
|
1128
1212
|
...completionItem(input, tag, input.clientSupportsSnippets ? `${tag}\`$1\`` : tag, CompletionItemKind.Value, input.clientSupportsSnippets),
|
|
1129
1213
|
detail: type.documentation
|
|
@@ -1136,10 +1220,10 @@ function valueItems(input, type, syntax) {
|
|
|
1136
1220
|
case "null": return scalarItems(input, ["null"]);
|
|
1137
1221
|
case "fieldRef":
|
|
1138
1222
|
case "referencedFieldRef": return scalarItems(input, input.fieldNames(type.kind));
|
|
1139
|
-
case "entityRef": return
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
}
|
|
1223
|
+
case "entityRef": return entityItems(input, input.scope.entries(), {
|
|
1224
|
+
selector: type.expected,
|
|
1225
|
+
namespaces: true
|
|
1226
|
+
});
|
|
1143
1227
|
case "list":
|
|
1144
1228
|
case "record":
|
|
1145
1229
|
case "int":
|
|
@@ -1147,6 +1231,21 @@ function valueItems(input, type, syntax) {
|
|
|
1147
1231
|
case "rejecting": return [];
|
|
1148
1232
|
}
|
|
1149
1233
|
}
|
|
1234
|
+
function qualifiedItems(input, type, qualifier) {
|
|
1235
|
+
if (type.kind !== "entityRef") return [];
|
|
1236
|
+
const namespace = input.scope.lookup(qualifier);
|
|
1237
|
+
if (namespace === void 0 || !isNamespaceLike(namespace)) return [];
|
|
1238
|
+
return entityItems(input, memberEntries(namespace), {
|
|
1239
|
+
selector: type.expected,
|
|
1240
|
+
namespaces: false
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
function entityItems(input, entries, selection) {
|
|
1244
|
+
return scopeCompletionItems(entries, input.binder, {
|
|
1245
|
+
start: input.sourceFile.positionAt(input.context.replacementStartOffset),
|
|
1246
|
+
end: input.sourceFile.positionAt(input.context.replacementEndOffset)
|
|
1247
|
+
}, input, selection);
|
|
1248
|
+
}
|
|
1150
1249
|
function scalarItems(input, labels, documentation) {
|
|
1151
1250
|
return labels.map((label) => completionItem(input, label, label, CompletionItemKind.Value, false, documentation));
|
|
1152
1251
|
}
|
|
@@ -1199,56 +1298,70 @@ function providePslCompletionItems(input) {
|
|
|
1199
1298
|
switch (context.kind) {
|
|
1200
1299
|
case "unsupported": return [];
|
|
1201
1300
|
case "spaceMember": return [];
|
|
1202
|
-
case "genericBlockValue": return [];
|
|
1203
1301
|
case "fieldAttributeName":
|
|
1204
1302
|
case "modelAttributeName":
|
|
1205
1303
|
case "blockAttributeName": return provideAttributeNameCompletionItems(context, input.sourceFile, input.candidates, input.clientSupportsSnippets, input.clientSupportsTriggerParameterHintsCommand === true);
|
|
1206
1304
|
case "fieldAttributeNamedKey":
|
|
1207
1305
|
case "modelAttributeNamedKey":
|
|
1208
|
-
case "blockAttributeNamedKey":
|
|
1209
|
-
|
|
1210
|
-
|
|
1306
|
+
case "blockAttributeNamedKey":
|
|
1307
|
+
case "blockValueNamedKey": {
|
|
1308
|
+
const root = argumentRootGrammar(context, input.candidates);
|
|
1309
|
+
return root === void 0 ? [] : provideAttributeNamedKeyCompletionItems({
|
|
1211
1310
|
context,
|
|
1212
1311
|
sourceFile: input.sourceFile,
|
|
1213
1312
|
clientSupportsSnippets: input.clientSupportsSnippets,
|
|
1214
1313
|
clientSupportsTriggerSuggestCommand: input.clientSupportsTriggerSuggestCommand === true
|
|
1215
|
-
},
|
|
1314
|
+
}, root);
|
|
1216
1315
|
}
|
|
1217
1316
|
case "fieldAttributeArgumentSlot":
|
|
1218
1317
|
case "modelAttributeArgumentSlot":
|
|
1219
|
-
case "blockAttributeArgumentSlot":
|
|
1220
|
-
|
|
1221
|
-
|
|
1318
|
+
case "blockAttributeArgumentSlot":
|
|
1319
|
+
case "blockValueArgumentSlot": {
|
|
1320
|
+
const root = argumentRootGrammar(context, input.candidates);
|
|
1321
|
+
return root === void 0 ? [] : provideAttributeArgumentSlotCompletionItems({
|
|
1222
1322
|
context,
|
|
1223
1323
|
binder: input.candidates.binder,
|
|
1224
|
-
scope: input.candidates.binder.scopeAt(
|
|
1324
|
+
scope: input.candidates.binder.scopeAt(ownerSyntax(context)),
|
|
1225
1325
|
sourceFile: input.sourceFile,
|
|
1226
1326
|
clientSupportsSnippets: input.clientSupportsSnippets,
|
|
1227
1327
|
clientSupportsTriggerSuggestCommand: input.clientSupportsTriggerSuggestCommand === true,
|
|
1228
1328
|
clientSupportsTriggerParameterHintsCommand: input.clientSupportsTriggerParameterHintsCommand === true,
|
|
1229
1329
|
fieldNames: (kind) => kind === "fieldRef" ? localFieldNames(context, input.candidates.binder) : referencedFieldNames(context, input.candidates.binder)
|
|
1230
|
-
},
|
|
1330
|
+
}, root);
|
|
1231
1331
|
}
|
|
1232
1332
|
case "fieldAttributeValue":
|
|
1233
1333
|
case "modelAttributeValue":
|
|
1234
|
-
case "blockAttributeValue":
|
|
1235
|
-
|
|
1236
|
-
|
|
1334
|
+
case "blockAttributeValue":
|
|
1335
|
+
case "blockValue": {
|
|
1336
|
+
const root = argumentRootGrammar(context, input.candidates);
|
|
1337
|
+
return root === void 0 ? [] : provideAttributeValueCompletionItems({
|
|
1237
1338
|
context,
|
|
1238
1339
|
binder: input.candidates.binder,
|
|
1239
|
-
scope: input.candidates.binder.scopeAt(
|
|
1340
|
+
scope: input.candidates.binder.scopeAt(ownerSyntax(context)),
|
|
1240
1341
|
sourceFile: input.sourceFile,
|
|
1241
1342
|
clientSupportsSnippets: input.clientSupportsSnippets,
|
|
1343
|
+
clientSupportsTriggerSuggestCommand: input.clientSupportsTriggerSuggestCommand === true,
|
|
1242
1344
|
clientSupportsTriggerParameterHintsCommand: input.clientSupportsTriggerParameterHintsCommand === true,
|
|
1243
1345
|
fieldNames: (kind) => kind === "fieldRef" ? localFieldNames(context, input.candidates.binder) : referencedFieldNames(context, input.candidates.binder)
|
|
1244
|
-
},
|
|
1346
|
+
}, root);
|
|
1245
1347
|
}
|
|
1246
1348
|
case "declarationKeyword": return provideDeclarationKeywordCompletionItems(context, input.sourceFile, input.candidates, input.clientSupportsSnippets);
|
|
1247
|
-
case "genericBlockKey": return provideGenericBlockKeyCompletionItems(context, input.sourceFile, input.candidates
|
|
1349
|
+
case "genericBlockKey": return provideGenericBlockKeyCompletionItems(context, input.sourceFile, input.candidates, {
|
|
1350
|
+
clientSupportsSnippets: input.clientSupportsSnippets,
|
|
1351
|
+
clientSupportsTriggerSuggestCommand: input.clientSupportsTriggerSuggestCommand === true
|
|
1352
|
+
});
|
|
1248
1353
|
case "modelType": return provideModelTypeCompletionItems(context, input.sourceFile, input.candidates, input);
|
|
1249
1354
|
case "namespaceMember": return provideNamespaceMemberCompletionItems(context, input.sourceFile, input.candidates, input);
|
|
1250
1355
|
}
|
|
1251
1356
|
}
|
|
1357
|
+
function ownerSyntax(owner) {
|
|
1358
|
+
switch (owner.ownerKind) {
|
|
1359
|
+
case "field": return owner.field.syntax;
|
|
1360
|
+
case "model": return owner.model.syntax;
|
|
1361
|
+
case "block":
|
|
1362
|
+
case "blockValue": return owner.block.syntax;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1252
1365
|
function provideAttributeNameCompletionItems(context, sourceFile, source, clientSupportsSnippets, clientSupportsTriggerParameterHintsCommand) {
|
|
1253
1366
|
const names = attributeNames(context, source);
|
|
1254
1367
|
const replacementRange = {
|
|
@@ -1320,7 +1433,7 @@ function provideDeclarationKeywordCompletionItems(context, sourceFile, source, c
|
|
|
1320
1433
|
}));
|
|
1321
1434
|
}
|
|
1322
1435
|
function declarationKeywordCandidates(scope, source) {
|
|
1323
|
-
return [...scope === "namespace" ? namespaceNativeDeclarationKeywords : documentNativeDeclarationKeywords, ...genericBlockDeclarationKeywordCandidates(source.pslBlockDescriptors)];
|
|
1436
|
+
return [...scope === "namespace" ? namespaceNativeDeclarationKeywords : documentNativeDeclarationKeywords, ...genericBlockDeclarationKeywordCandidates(source.pslBlockDescriptors, source.symbolTable)];
|
|
1324
1437
|
}
|
|
1325
1438
|
function nativeDeclarationKeyword(label, insertText, snippetText, documentation) {
|
|
1326
1439
|
return {
|
|
@@ -1332,26 +1445,35 @@ function nativeDeclarationKeyword(label, insertText, snippetText, documentation)
|
|
|
1332
1445
|
kind: CompletionItemKind.Keyword
|
|
1333
1446
|
};
|
|
1334
1447
|
}
|
|
1335
|
-
function genericBlockDeclarationKeywordCandidates(descriptors) {
|
|
1448
|
+
function genericBlockDeclarationKeywordCandidates(descriptors, symbols) {
|
|
1336
1449
|
return descriptorBlockKeywords(descriptors).map((keyword) => {
|
|
1337
1450
|
const descriptor = findBlockDescriptor(descriptors, keyword);
|
|
1338
1451
|
return {
|
|
1339
1452
|
category: "genericBlock",
|
|
1340
1453
|
label: keyword,
|
|
1341
1454
|
insertText: `${keyword} `,
|
|
1342
|
-
snippetText: genericBlockSnippet(keyword),
|
|
1455
|
+
snippetText: genericBlockSnippet(keyword, descriptor === void 0 ? void 0 : blockSpecFactoryOf(descriptor)({ symbols })),
|
|
1343
1456
|
detail: descriptor?.documentation || "Generic block keyword",
|
|
1344
1457
|
kind: CompletionItemKind.Keyword
|
|
1345
1458
|
};
|
|
1346
1459
|
});
|
|
1347
1460
|
}
|
|
1348
|
-
function genericBlockSnippet(keyword) {
|
|
1461
|
+
function genericBlockSnippet(keyword, spec) {
|
|
1462
|
+
const lines = (spec?.mode === "struct" ? Object.entries(spec.parameters).filter(([, parameter]) => !isOptionalType(parameter.type)) : []).map(([name, parameter], index) => {
|
|
1463
|
+
const placeholder = `\${${index + 2}:${name}}`;
|
|
1464
|
+
return ` ${name} = ${parameter.type.kind === "list" ? `[${placeholder}]` : placeholder}`;
|
|
1465
|
+
});
|
|
1466
|
+
const cursor = lines.length === 0 ? "${0:// Block keys and attributes}" : "$0";
|
|
1349
1467
|
return [
|
|
1350
1468
|
`${keyword} ${nameSnippetPlaceholder} {`,
|
|
1351
|
-
|
|
1469
|
+
...lines,
|
|
1470
|
+
` ${cursor}`,
|
|
1352
1471
|
"}"
|
|
1353
1472
|
].join("\n");
|
|
1354
1473
|
}
|
|
1474
|
+
function isOptionalType(type) {
|
|
1475
|
+
return "optional" in type && type.optional === true;
|
|
1476
|
+
}
|
|
1355
1477
|
function descriptorBlockKeywords(descriptors) {
|
|
1356
1478
|
const keywords = [];
|
|
1357
1479
|
collectDescriptorBlockKeywords(descriptors, keywords);
|
|
@@ -1369,32 +1491,41 @@ function collectDescriptorBlockKeywords(descriptors, keywords) {
|
|
|
1369
1491
|
function declarationKeywordSortText(candidate) {
|
|
1370
1492
|
return `${declarationKeywordCategoryOrder[candidate.category]}:${candidate.label}`;
|
|
1371
1493
|
}
|
|
1372
|
-
function provideGenericBlockKeyCompletionItems(context, sourceFile, source) {
|
|
1494
|
+
function provideGenericBlockKeyCompletionItems(context, sourceFile, source, capabilities) {
|
|
1373
1495
|
const descriptor = findBlockDescriptor(source.pslBlockDescriptors, context.blockKeyword);
|
|
1374
1496
|
if (descriptor === void 0) return [];
|
|
1375
|
-
const
|
|
1376
|
-
if (block?.kind !== "block") return [];
|
|
1377
|
-
const spec = blockSpecFactoryOf(descriptor)({
|
|
1378
|
-
symbols: source.symbolTable,
|
|
1379
|
-
block
|
|
1380
|
-
});
|
|
1497
|
+
const spec = blockSpecFactoryOf(descriptor)({ symbols: source.symbolTable });
|
|
1381
1498
|
if (spec.mode !== "struct") return [];
|
|
1382
1499
|
const existing = existingGenericBlockParameterNames(context.block, context.offset);
|
|
1500
|
+
const hasEquals = editedKeyHasEquals(context.block, context.offset);
|
|
1383
1501
|
const replacementRange = {
|
|
1384
1502
|
start: sourceFile.positionAt(context.replacementStartOffset),
|
|
1385
1503
|
end: sourceFile.positionAt(context.offset)
|
|
1386
1504
|
};
|
|
1387
|
-
return Object.entries(spec.parameters).filter(([parameterName]) => !existing.has(parameterName)).map(([parameterName, parameter], index) =>
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1505
|
+
return Object.entries(spec.parameters).filter(([parameterName]) => !existing.has(parameterName)).map(([parameterName, parameter], index) => {
|
|
1506
|
+
const snippet = !hasEquals && capabilities.clientSupportsSnippets && parameter.type.kind === "list";
|
|
1507
|
+
const newText = hasEquals ? parameterName : snippet ? `${parameterName} = [$1]` : `${parameterName} = `;
|
|
1508
|
+
return {
|
|
1509
|
+
label: parameterName,
|
|
1510
|
+
kind: CompletionItemKind.Property,
|
|
1511
|
+
detail: parameter.documentation || "Generic block parameter",
|
|
1512
|
+
sortText: genericBlockParameterSortText(index, parameterName),
|
|
1513
|
+
filterText: parameterName,
|
|
1514
|
+
textEdit: {
|
|
1515
|
+
range: replacementRange,
|
|
1516
|
+
newText
|
|
1517
|
+
},
|
|
1518
|
+
...snippet ? { insertTextFormat: InsertTextFormat.Snippet } : {},
|
|
1519
|
+
...!hasEquals && capabilities.clientSupportsTriggerSuggestCommand === true ? { command: {
|
|
1520
|
+
title: "Suggest argument values",
|
|
1521
|
+
command: "editor.action.triggerSuggest"
|
|
1522
|
+
} } : {}
|
|
1523
|
+
};
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
function editedKeyHasEquals(block, cursorOffset) {
|
|
1527
|
+
for (const entry of block.entries()) if (!entry.syntax.isOutside(cursorOffset)) return entry.equals() !== void 0;
|
|
1528
|
+
return false;
|
|
1398
1529
|
}
|
|
1399
1530
|
function existingGenericBlockParameterNames(block, cursorOffset) {
|
|
1400
1531
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -1998,7 +2129,7 @@ function tokenTypeIndex(tokenType) {
|
|
|
1998
2129
|
}
|
|
1999
2130
|
function classifyPslSignatureContext(input) {
|
|
2000
2131
|
const syntax = locateAttributeSyntax(input);
|
|
2001
|
-
if (syntax === void 0) return
|
|
2132
|
+
if (syntax === void 0) return blockValueSignatureContext(input);
|
|
2002
2133
|
const attributeName = syntax.attribute.name()?.identifier()?.name();
|
|
2003
2134
|
const args = syntax.attribute.argList();
|
|
2004
2135
|
const position = args === void 0 ? void 0 : signatureArguments(syntax, args, []);
|
|
@@ -2009,6 +2140,30 @@ function classifyPslSignatureContext(input) {
|
|
|
2009
2140
|
attributeName
|
|
2010
2141
|
};
|
|
2011
2142
|
}
|
|
2143
|
+
function blockValueSignatureContext(input) {
|
|
2144
|
+
const offset = input.sourceFile.offsetAt(input.position);
|
|
2145
|
+
const anchor = input.document.syntax.tokenAtOffset(offset).leftBiased();
|
|
2146
|
+
if (anchor === void 0 || anchor.kind === "Comment") return void 0;
|
|
2147
|
+
const preceding = skipTriviaToken(anchor, "prev");
|
|
2148
|
+
const pair = preceding?.parent.findAncestor(KeyValuePairAst.cast);
|
|
2149
|
+
const equals = pair?.equals();
|
|
2150
|
+
if (pair === void 0 || equals === void 0 || offset <= equals.offset) return void 0;
|
|
2151
|
+
const block = pair.syntax.findAncestor(GenericBlockDeclarationAst.cast);
|
|
2152
|
+
const blockKeyword = block?.keyword()?.text;
|
|
2153
|
+
const key = pair.key()?.name();
|
|
2154
|
+
if (block === void 0 || blockKeyword === void 0 || key === void 0) return void 0;
|
|
2155
|
+
const position = signatureExpression({
|
|
2156
|
+
offset,
|
|
2157
|
+
preceding
|
|
2158
|
+
}, pair.value(), []);
|
|
2159
|
+
return position === void 0 ? void 0 : {
|
|
2160
|
+
ownerKind: "blockValue",
|
|
2161
|
+
block,
|
|
2162
|
+
blockKeyword,
|
|
2163
|
+
key,
|
|
2164
|
+
...position
|
|
2165
|
+
};
|
|
2166
|
+
}
|
|
2012
2167
|
function signatureOwner(attribute) {
|
|
2013
2168
|
if (attribute instanceof FieldAttributeAst) {
|
|
2014
2169
|
const field = attribute.syntax.findAncestor(FieldDeclarationAst.cast);
|
|
@@ -2107,16 +2262,25 @@ function signatureExpression(context, expression, path) {
|
|
|
2107
2262
|
function providePslSignatureHelp(input) {
|
|
2108
2263
|
const context = classifyPslSignatureContext(input);
|
|
2109
2264
|
if (context === void 0) return null;
|
|
2110
|
-
const
|
|
2111
|
-
if (
|
|
2112
|
-
return signatureHelp(context,
|
|
2265
|
+
const root = argumentRootGrammar(context, input.candidates);
|
|
2266
|
+
if (root === void 0) return null;
|
|
2267
|
+
return signatureHelp(context, root, input.clientSupportsLabelOffsets === true);
|
|
2268
|
+
}
|
|
2269
|
+
function rootSignatureName(owner) {
|
|
2270
|
+
switch (owner.ownerKind) {
|
|
2271
|
+
case "field": return `@${owner.attributeName}`;
|
|
2272
|
+
case "model":
|
|
2273
|
+
case "block": return `@@${owner.attributeName}`;
|
|
2274
|
+
case "blockValue": return;
|
|
2275
|
+
}
|
|
2113
2276
|
}
|
|
2114
|
-
function signatureHelp(context,
|
|
2277
|
+
function signatureHelp(context, root, labelOffsets) {
|
|
2115
2278
|
const callIndex = context.path.reduce((last, step, index) => step.kind === "functionCall" ? index : last, -1);
|
|
2116
2279
|
const call = context.path[callIndex];
|
|
2117
2280
|
const signaturePath = context.path.slice(0, callIndex + 1);
|
|
2118
|
-
const name = call?.kind === "functionCall" ? call.name :
|
|
2119
|
-
|
|
2281
|
+
const name = call?.kind === "functionCall" ? call.name : rootSignatureName(context);
|
|
2282
|
+
if (name === void 0) return null;
|
|
2283
|
+
const signatures = resolveGrammar(root, signaturePath).flatMap((grammar) => {
|
|
2120
2284
|
if ("kind" in grammar) return [];
|
|
2121
2285
|
const active = context.path[callIndex + 1];
|
|
2122
2286
|
const params = parameters(grammar, active?.kind === "namedArgument" ? active.name : void 0);
|
|
@@ -3048,4 +3212,4 @@ function startServer(streams) {
|
|
|
3048
3212
|
//#endregion
|
|
3049
3213
|
export { startServer };
|
|
3050
3214
|
|
|
3051
|
-
//# sourceMappingURL=exports-
|
|
3215
|
+
//# sourceMappingURL=exports-uCZMBtq-.mjs.map
|