@prisma/orm-toolchain 8.0.0-rc.14-dev.18 → 8.0.0-rc.14-dev.20

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
- namedKey: (position) => ({
608
- kind: "fieldAttributeNamedKey",
609
- ...position,
610
- ...owner
611
- }),
612
- argumentSlot: (position) => ({
613
- kind: "fieldAttributeArgumentSlot",
614
- ...position,
615
- ...owner
616
- }),
617
- value: (position) => ({
618
- kind: "fieldAttributeValue",
619
- ...position,
620
- ...owner
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
- namedKey: (position) => ({
642
- kind: "blockAttributeNamedKey",
643
- ...position,
644
- ...owner
645
- }),
646
- argumentSlot: (position) => ({
647
- kind: "blockAttributeArgumentSlot",
648
- ...position,
649
- ...owner
650
- }),
651
- value: (position) => ({
652
- kind: "blockAttributeValue",
653
- ...position,
654
- ...owner
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
- namedKey: (position) => ({
674
- kind: "modelAttributeNamedKey",
675
- ...position,
676
- ...owner
677
- }),
678
- argumentSlot: (position) => ({
679
- kind: "modelAttributeArgumentSlot",
680
- ...position,
681
- ...owner
682
- }),
683
- value: (position) => ({
684
- kind: "modelAttributeValue",
685
- ...position,
686
- ...owner
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: input.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
- return expression.syntax.isOutside(cursor.offset) ? UNSUPPORTED : cursor.factory.value({
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
- if (input.precedingToken?.kind === "Equals") return {
819
- kind: "genericBlockValue",
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, selector) {
1035
+ function scopeCompletionItems(entries, binder, range, capabilities, selection) {
964
1036
  const items = [];
965
1037
  for (const [name, resolution] of entries) {
966
- if (selector !== void 0) {
967
- const reference = entityReference(resolution);
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(signature, path) {
1061
- let grammars = [signature];
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, spec) {
1085
- return orderedItems(resolveGrammar(spec, input.context.path).flatMap((grammar) => "kind" in grammar ? [] : namedKeyItems(input, grammar)));
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, spec) {
1088
- return orderedItems(resolveGrammar(spec, input.context.path).flatMap((grammar) => {
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, spec) {
1095
- return orderedItems(resolveGrammar(spec, input.context.path).flatMap((grammar) => "kind" in grammar ? valueItems(input, grammar, input.context.syntax) : []));
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 scopeCompletionItems(input.scope.entries(), input.binder, {
1140
- start: input.sourceFile.positionAt(input.context.replacementStartOffset),
1141
- end: input.sourceFile.positionAt(input.context.replacementEndOffset)
1142
- }, input, type.expected);
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
- const spec = attributeSpecResolver(context, input.candidates)(context.attributeName);
1210
- return spec === void 0 ? [] : provideAttributeNamedKeyCompletionItems({
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
- }, spec);
1314
+ }, root);
1216
1315
  }
1217
1316
  case "fieldAttributeArgumentSlot":
1218
1317
  case "modelAttributeArgumentSlot":
1219
- case "blockAttributeArgumentSlot": {
1220
- const spec = attributeSpecResolver(context, input.candidates)(context.attributeName);
1221
- return spec === void 0 ? [] : provideAttributeArgumentSlotCompletionItems({
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("field" in context ? context.field.syntax : "model" in context ? context.model.syntax : context.block.syntax),
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
- }, spec);
1330
+ }, root);
1231
1331
  }
1232
1332
  case "fieldAttributeValue":
1233
1333
  case "modelAttributeValue":
1234
- case "blockAttributeValue": {
1235
- const spec = attributeSpecResolver(context, input.candidates)(context.attributeName);
1236
- return spec === void 0 ? [] : provideAttributeValueCompletionItems({
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("field" in context ? context.field.syntax : "model" in context ? context.model.syntax : context.block.syntax),
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
- }, spec);
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
- ` \${0:// Block keys and attributes}`,
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 block = source.binder.declaredSymbol(context.block.syntax);
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
- label: parameterName,
1389
- kind: CompletionItemKind.Property,
1390
- detail: parameter.documentation || "Generic block parameter",
1391
- sortText: genericBlockParameterSortText(index, parameterName),
1392
- filterText: parameterName,
1393
- textEdit: {
1394
- range: replacementRange,
1395
- newText: parameterName
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();
@@ -1467,6 +1598,364 @@ function addFoldingRange(declaration, sources, ranges) {
1467
1598
  kind: FoldingRangeKind.Region
1468
1599
  });
1469
1600
  }
1601
+ function classifyPslSignatureContext(input) {
1602
+ const syntax = locateAttributeSyntax(input);
1603
+ if (syntax === void 0) return blockValueSignatureContext(input);
1604
+ const attributeName = syntax.attribute.name()?.identifier()?.name();
1605
+ const args = syntax.attribute.argList();
1606
+ const position = args === void 0 ? void 0 : signatureArguments(syntax, args, []);
1607
+ const owner = signatureOwner(syntax.attribute);
1608
+ return attributeName === void 0 || position === void 0 || owner === void 0 ? void 0 : {
1609
+ ...owner,
1610
+ ...position,
1611
+ attributeName
1612
+ };
1613
+ }
1614
+ function blockValueSignatureContext(input) {
1615
+ const offset = input.sourceFile.offsetAt(input.position);
1616
+ const anchor = input.document.syntax.tokenAtOffset(offset).leftBiased();
1617
+ if (anchor === void 0 || anchor.kind === "Comment") return void 0;
1618
+ const preceding = skipTriviaToken(anchor, "prev");
1619
+ const pair = preceding?.parent.findAncestor(KeyValuePairAst.cast);
1620
+ const equals = pair?.equals();
1621
+ if (pair === void 0 || equals === void 0 || offset <= equals.offset) return void 0;
1622
+ const block = pair.syntax.findAncestor(GenericBlockDeclarationAst.cast);
1623
+ const blockKeyword = block?.keyword()?.text;
1624
+ const key = pair.key()?.name();
1625
+ if (block === void 0 || blockKeyword === void 0 || key === void 0) return void 0;
1626
+ const position = signatureExpression({
1627
+ offset,
1628
+ preceding
1629
+ }, pair.value(), []);
1630
+ return position === void 0 ? void 0 : {
1631
+ ownerKind: "blockValue",
1632
+ block,
1633
+ blockKeyword,
1634
+ key,
1635
+ ...position
1636
+ };
1637
+ }
1638
+ function signatureOwner(attribute) {
1639
+ if (attribute instanceof FieldAttributeAst) {
1640
+ const field = attribute.syntax.findAncestor(FieldDeclarationAst.cast);
1641
+ const model = attribute.syntax.findAncestor(ModelDeclarationAst.cast);
1642
+ return field === void 0 || model === void 0 ? void 0 : {
1643
+ ownerKind: "field",
1644
+ field,
1645
+ model
1646
+ };
1647
+ }
1648
+ const block = attribute.syntax.findAncestor(GenericBlockDeclarationAst.cast);
1649
+ if (block !== void 0) {
1650
+ const blockKeyword = block.keyword()?.text;
1651
+ return blockKeyword === void 0 || blockKeyword.length === 0 ? void 0 : {
1652
+ ownerKind: "block",
1653
+ block,
1654
+ blockKeyword
1655
+ };
1656
+ }
1657
+ const model = attribute.syntax.findAncestor(ModelDeclarationAst.cast);
1658
+ return model === void 0 ? void 0 : {
1659
+ ownerKind: "model",
1660
+ model
1661
+ };
1662
+ }
1663
+ function signatureArguments(context, args, path) {
1664
+ if (!betweenDelimiters(context.offset, args.lparen(), args.rparen())) return void 0;
1665
+ const containing = argumentAtCursor(context, args);
1666
+ const next = context.preceding?.kind === "Comma" ? nonTriviaSibling(context.preceding, "next") : void 0;
1667
+ const following = next instanceof SyntaxNode && next.parent?.offset === args.syntax.offset ? AttributeArgAst.cast(next) : void 0;
1668
+ const active = containing ?? following;
1669
+ const { precedingPositionalCount: positionalIndex, otherNamedKeys: existingNamedKeys } = argumentSiblings(args, active, context.offset);
1670
+ if (active === void 0) return ["LParen", "Comma"].includes(context.preceding?.kind ?? "") ? {
1671
+ path,
1672
+ argumentSlot: {
1673
+ positionalIndex,
1674
+ existingNamedKeys
1675
+ }
1676
+ } : void 0;
1677
+ if (active.colon() !== void 0) {
1678
+ const name = active.name()?.name();
1679
+ if (name === void 0) return void 0;
1680
+ const valuePath = [...path, {
1681
+ kind: "namedArgument",
1682
+ name
1683
+ }];
1684
+ return active === containing ? signatureExpression(context, active.value(), valuePath) : {
1685
+ path: valuePath,
1686
+ argumentSlot: void 0
1687
+ };
1688
+ }
1689
+ const value = active.value();
1690
+ if (value === void 0 || value instanceof IdentifierAst && value.syntax.isInside(context.offset)) return {
1691
+ path,
1692
+ argumentSlot: {
1693
+ positionalIndex,
1694
+ existingNamedKeys
1695
+ }
1696
+ };
1697
+ const valuePath = [...path, {
1698
+ kind: "positionalArgument",
1699
+ index: positionalIndex
1700
+ }];
1701
+ return active === containing ? signatureExpression(context, value, valuePath) : {
1702
+ path: valuePath,
1703
+ argumentSlot: void 0
1704
+ };
1705
+ }
1706
+ function signatureExpression(context, expression, path) {
1707
+ const position = {
1708
+ path,
1709
+ argumentSlot: void 0
1710
+ };
1711
+ if (expression === void 0 || context.offset <= expression.syntax.offset || context.offset >= expression.syntax.endOffset && !recoveredContainerContainsCursor(expression, context.offset)) return position;
1712
+ if (expression instanceof ArrayLiteralAst) return betweenDelimiters(context.offset, expression.lbracket(), expression.rbracket()) ? signatureExpression(context, listElementAtCursor(context, expression), [...path, { kind: "listElement" }]) : void 0;
1713
+ if (expression instanceof ObjectLiteralExprAst) {
1714
+ const closing = expression.rbrace();
1715
+ if (closing !== void 0 && context.offset >= closing.endOffset) return void 0;
1716
+ const field = recordFieldAtCursor(context, expression);
1717
+ return field !== void 0 ? signatureExpression(context, field.value(), [...path, { kind: "recordValue" }]) : position;
1718
+ }
1719
+ if (expression instanceof FunctionCallAst) {
1720
+ const opening = expression.lparen();
1721
+ if (opening !== void 0 && context.offset > opening.offset) {
1722
+ const name = expression.name();
1723
+ const identifier = name?.identifier()?.name();
1724
+ return identifier !== void 0 && name?.isSimpleName(identifier) === true ? signatureArguments(context, expression, [...path, {
1725
+ kind: "functionCall",
1726
+ name: identifier
1727
+ }]) : void 0;
1728
+ }
1729
+ return expression.name()?.syntax.isInside(context.offset) === true ? position : void 0;
1730
+ }
1731
+ return position;
1732
+ }
1733
+ function providePslSignatureHelp(input) {
1734
+ const context = classifyPslSignatureContext(input);
1735
+ if (context === void 0) return null;
1736
+ const root = argumentRootGrammar(context, input.candidates);
1737
+ if (root === void 0) return null;
1738
+ return signatureHelp(context, root, input.clientSupportsLabelOffsets === true);
1739
+ }
1740
+ function rootSignatureName(owner) {
1741
+ switch (owner.ownerKind) {
1742
+ case "field": return `@${owner.attributeName}`;
1743
+ case "model":
1744
+ case "block": return `@@${owner.attributeName}`;
1745
+ case "blockValue": return;
1746
+ }
1747
+ }
1748
+ function signatureHelp(context, root, labelOffsets) {
1749
+ const callIndex = context.path.reduce((last, step, index) => step.kind === "functionCall" ? index : last, -1);
1750
+ const call = context.path[callIndex];
1751
+ const signaturePath = context.path.slice(0, callIndex + 1);
1752
+ const name = call?.kind === "functionCall" ? call.name : rootSignatureName(context);
1753
+ if (name === void 0) return null;
1754
+ const signatures = resolveGrammar(root, signaturePath).flatMap((grammar) => {
1755
+ if ("kind" in grammar) return [];
1756
+ const active = context.path[callIndex + 1];
1757
+ const params = resolveSignatureParameters(grammar, active?.kind === "namedArgument" ? active.name : void 0);
1758
+ const index = parameterIndex(context, active, params);
1759
+ return [{
1760
+ signature: renderSignature(name, grammar, params, labelOffsets),
1761
+ index
1762
+ }];
1763
+ });
1764
+ if (signatures.length === 0) return null;
1765
+ const matched = signatures.findIndex(({ signature, index }) => index >= 0 && index < (signature.parameters?.length ?? 0));
1766
+ const activeSignature = matched < 0 ? 0 : matched;
1767
+ const activeParameter = signatures[activeSignature]?.index;
1768
+ return {
1769
+ signatures: signatures.map(({ signature }) => signature),
1770
+ activeSignature,
1771
+ ...matched >= 0 && activeParameter !== void 0 ? { activeParameter } : {}
1772
+ };
1773
+ }
1774
+ function parameterIndex(context, active, params) {
1775
+ if (active?.kind === "namedArgument") return params.findIndex((param) => param.key === active.name);
1776
+ if (active?.kind === "positionalArgument") return active.index;
1777
+ const slot = context.argumentSlot;
1778
+ if (slot !== void 0) return params.findIndex((param, index) => index >= slot.positionalIndex && !slot.existingNamedKeys.includes(param.key));
1779
+ return -1;
1780
+ }
1781
+ function resolveSignatureParameters(signature, activeName) {
1782
+ const positional = signature.positional ?? [];
1783
+ const keys = new Set(positional.map((param) => param.key));
1784
+ const namedAlias = activeName === void 0 ? void 0 : signature.named?.[activeName];
1785
+ return [...positional.map((param) => param.key === activeName && namedAlias !== void 0 ? {
1786
+ key: param.key,
1787
+ ...namedAlias
1788
+ } : param), ...Object.entries(signature.named ?? {}).flatMap(([key, param]) => keys.has(key) ? [] : [{
1789
+ key,
1790
+ ...param
1791
+ }])];
1792
+ }
1793
+ function renderSignatureLabel(name, signature, params) {
1794
+ let label = `${name}(`;
1795
+ const parts = params.map((param, index) => {
1796
+ if (index > 0) label += ", ";
1797
+ const positional = index < (signature.positional?.length ?? 0);
1798
+ const optional = "optional" in param.type && param.type.optional === true;
1799
+ const typeLabel = optional && param.type.label.includes(" | ") ? `(${param.type.label})` : param.type.label;
1800
+ const text = positional ? `${typeLabel}${optional ? "?" : ""}` : `${param.key}${optional ? "?" : ""}: ${param.type.label}`;
1801
+ const start = label.length;
1802
+ label += text;
1803
+ return {
1804
+ param,
1805
+ text,
1806
+ start,
1807
+ end: label.length,
1808
+ positional
1809
+ };
1810
+ });
1811
+ return {
1812
+ label: `${label})`,
1813
+ parts
1814
+ };
1815
+ }
1816
+ function renderSignature(name, signature, params, labelOffsets) {
1817
+ const { label, parts } = renderSignatureLabel(name, signature, params);
1818
+ const rendered = parts.map(({ param, text, start, end, positional }) => {
1819
+ const documentation = positional ? `**${param.key}**\n\n${param.documentation}${signature.named?.[param.key] === void 0 ? "" : `\n\nAccepted positionally or by \`${param.key}:\`.`}` : param.documentation;
1820
+ return {
1821
+ label: positional && labelOffsets ? [start, end] : text,
1822
+ documentation: {
1823
+ kind: MarkupKind.Markdown,
1824
+ value: documentation
1825
+ }
1826
+ };
1827
+ });
1828
+ return {
1829
+ label,
1830
+ documentation: {
1831
+ kind: MarkupKind.Markdown,
1832
+ value: signature.documentation
1833
+ },
1834
+ parameters: rendered
1835
+ };
1836
+ }
1837
+ function providePslHover(input) {
1838
+ const offset = input.sourceFile.offsetAt(input.position);
1839
+ const token = identTokenAt(input.document.syntax, offset);
1840
+ if (token === void 0) return null;
1841
+ const value = hoverValueAt(input.binder, token, input.pslBlockDescriptors);
1842
+ if (value === void 0) return null;
1843
+ return {
1844
+ contents: {
1845
+ kind: MarkupKind.Markdown,
1846
+ value
1847
+ },
1848
+ range: {
1849
+ start: input.sourceFile.positionAt(token.offset),
1850
+ end: input.sourceFile.positionAt(token.endOffset)
1851
+ }
1852
+ };
1853
+ }
1854
+ function hoverValueAt(binder, token, pslBlockDescriptors) {
1855
+ const result = resolveHoverResult(binder, token);
1856
+ if (result !== void 0) return renderHoverResult(result);
1857
+ return blockKeywordDocumentationAt(token, pslBlockDescriptors);
1858
+ }
1859
+ function identTokenAt(root, offset) {
1860
+ const at = root.tokenAtOffset(offset);
1861
+ const left = at.leftBiased();
1862
+ if (left?.kind === "Ident") return left;
1863
+ const right = at.rightBiased();
1864
+ return right?.kind === "Ident" ? right : void 0;
1865
+ }
1866
+ function resolveHoverResult(binder, token) {
1867
+ return token.parent.findAncestor((node) => narrowHoverResult(binder.symbolForNode(node)));
1868
+ }
1869
+ function narrowHoverResult(resolution) {
1870
+ switch (resolution?.kind) {
1871
+ case "model":
1872
+ case "compositeType":
1873
+ case "namedType":
1874
+ case "block":
1875
+ case "field": return {
1876
+ kind: "entity",
1877
+ symbol: resolution.symbol
1878
+ };
1879
+ case "attribute": return {
1880
+ kind: "attribute",
1881
+ symbol: resolution.symbol
1882
+ };
1883
+ case "contributedType": return {
1884
+ kind: "contributedType",
1885
+ symbol: resolution.symbol
1886
+ };
1887
+ default: return;
1888
+ }
1889
+ }
1890
+ function renderHoverResult(result) {
1891
+ if (result.kind === "entity") return renderEntityContent(result.symbol);
1892
+ if (result.kind === "attribute") return renderAttributeContent(result.symbol);
1893
+ return renderContributedTypeContent(result.symbol);
1894
+ }
1895
+ function renderEntityContent(entity) {
1896
+ return withDocumentation([
1897
+ "```prisma",
1898
+ renderDeclarationLine(entity),
1899
+ "```"
1900
+ ].join("\n"), entity.node.docComment());
1901
+ }
1902
+ function renderAttributeContent(symbol) {
1903
+ const name = `${symbol.level === "field" ? "@" : "@@"}${symbol.name}`;
1904
+ const params = resolveSignatureParameters(symbol.spec, void 0);
1905
+ const { label } = renderSignatureLabel(name, symbol.spec, params);
1906
+ return withDocumentation([
1907
+ "```prisma",
1908
+ label,
1909
+ "```"
1910
+ ].join("\n"), symbol.spec.documentation);
1911
+ }
1912
+ function renderContributedTypeContent(symbol) {
1913
+ return withDocumentation([
1914
+ "```prisma",
1915
+ renderContributedTypeLabel(symbol),
1916
+ "```"
1917
+ ].join("\n"), symbol.descriptor.kind === "typeConstructor" ? symbol.descriptor.documentation : void 0);
1918
+ }
1919
+ function withDocumentation(fence, documentation) {
1920
+ return documentation === void 0 || documentation === "" ? fence : `${fence}\n\n${documentation}`;
1921
+ }
1922
+ function renderContributedTypeLabel(symbol) {
1923
+ const path = symbol.path.join(".");
1924
+ const args = symbol.descriptor.args ?? [];
1925
+ if (args.length === 0) return path;
1926
+ return `${path}(${args.map((arg, index) => {
1927
+ return `${arg.name ?? `arg${index + 1}`}${arg.optional === true ? "?" : ""}: ${argumentTypeLabel(arg)}`;
1928
+ }).join(", ")})`;
1929
+ }
1930
+ function argumentTypeLabel(arg) {
1931
+ if (arg.kind === "string") return "string";
1932
+ if (arg.kind === "boolean") return "boolean";
1933
+ if (arg.kind === "number") return "number";
1934
+ if (arg.kind === "stringArray") return "string[]";
1935
+ if (arg.kind === "object") return "object";
1936
+ return arg.values.map((value) => `'${value}'`).join(" | ");
1937
+ }
1938
+ function blockKeywordDocumentationAt(token, pslBlockDescriptors) {
1939
+ const declaration = GenericBlockDeclarationAst.cast(token.parent);
1940
+ if (declaration === void 0 || declaration.keyword()?.offset !== token.offset) return void 0;
1941
+ return findBlockDescriptor(pslBlockDescriptors, token.text)?.documentation;
1942
+ }
1943
+ function renderDeclarationLine(entity) {
1944
+ if (entity.kind === "block") return `${entity.keyword} ${entity.name}`;
1945
+ if (entity.kind === "field" || entity.kind === "namedType") return collapseWhitespace(printSyntaxWithoutComments(entity.node.syntax));
1946
+ return `${entity.node.keyword()?.text ?? ""} ${entity.name}`;
1947
+ }
1948
+ function printSyntaxWithoutComments(node) {
1949
+ let text = "";
1950
+ for (const token of node.tokens()) {
1951
+ if (token.kind === "Comment") continue;
1952
+ text += token.text;
1953
+ }
1954
+ return text;
1955
+ }
1956
+ function collapseWhitespace(text) {
1957
+ return text.replace(/\s+/g, " ").trim();
1958
+ }
1470
1959
  function binderContextFromStack(stack) {
1471
1960
  return {
1472
1961
  authoringContributions: stack.authoringContributions ?? {
@@ -1996,193 +2485,6 @@ function createPendingSemanticToken(startOffset, endOffset, tokenType, modifierB
1996
2485
  function tokenTypeIndex(tokenType) {
1997
2486
  return semanticTokenTypes.indexOf(tokenType);
1998
2487
  }
1999
- function classifyPslSignatureContext(input) {
2000
- const syntax = locateAttributeSyntax(input);
2001
- if (syntax === void 0) return void 0;
2002
- const attributeName = syntax.attribute.name()?.identifier()?.name();
2003
- const args = syntax.attribute.argList();
2004
- const position = args === void 0 ? void 0 : signatureArguments(syntax, args, []);
2005
- const owner = signatureOwner(syntax.attribute);
2006
- return attributeName === void 0 || position === void 0 || owner === void 0 ? void 0 : {
2007
- ...owner,
2008
- ...position,
2009
- attributeName
2010
- };
2011
- }
2012
- function signatureOwner(attribute) {
2013
- if (attribute instanceof FieldAttributeAst) {
2014
- const field = attribute.syntax.findAncestor(FieldDeclarationAst.cast);
2015
- const model = attribute.syntax.findAncestor(ModelDeclarationAst.cast);
2016
- return field === void 0 || model === void 0 ? void 0 : {
2017
- ownerKind: "field",
2018
- field,
2019
- model
2020
- };
2021
- }
2022
- const block = attribute.syntax.findAncestor(GenericBlockDeclarationAst.cast);
2023
- if (block !== void 0) {
2024
- const blockKeyword = block.keyword()?.text;
2025
- return blockKeyword === void 0 || blockKeyword.length === 0 ? void 0 : {
2026
- ownerKind: "block",
2027
- block,
2028
- blockKeyword
2029
- };
2030
- }
2031
- const model = attribute.syntax.findAncestor(ModelDeclarationAst.cast);
2032
- return model === void 0 ? void 0 : {
2033
- ownerKind: "model",
2034
- model
2035
- };
2036
- }
2037
- function signatureArguments(context, args, path) {
2038
- if (!betweenDelimiters(context.offset, args.lparen(), args.rparen())) return void 0;
2039
- const containing = argumentAtCursor(context, args);
2040
- const next = context.preceding?.kind === "Comma" ? nonTriviaSibling(context.preceding, "next") : void 0;
2041
- const following = next instanceof SyntaxNode && next.parent?.offset === args.syntax.offset ? AttributeArgAst.cast(next) : void 0;
2042
- const active = containing ?? following;
2043
- const { precedingPositionalCount: positionalIndex, otherNamedKeys: existingNamedKeys } = argumentSiblings(args, active, context.offset);
2044
- if (active === void 0) return ["LParen", "Comma"].includes(context.preceding?.kind ?? "") ? {
2045
- path,
2046
- argumentSlot: {
2047
- positionalIndex,
2048
- existingNamedKeys
2049
- }
2050
- } : void 0;
2051
- if (active.colon() !== void 0) {
2052
- const name = active.name()?.name();
2053
- if (name === void 0) return void 0;
2054
- const valuePath = [...path, {
2055
- kind: "namedArgument",
2056
- name
2057
- }];
2058
- return active === containing ? signatureExpression(context, active.value(), valuePath) : {
2059
- path: valuePath,
2060
- argumentSlot: void 0
2061
- };
2062
- }
2063
- const value = active.value();
2064
- if (value === void 0 || value instanceof IdentifierAst && value.syntax.isInside(context.offset)) return {
2065
- path,
2066
- argumentSlot: {
2067
- positionalIndex,
2068
- existingNamedKeys
2069
- }
2070
- };
2071
- const valuePath = [...path, {
2072
- kind: "positionalArgument",
2073
- index: positionalIndex
2074
- }];
2075
- return active === containing ? signatureExpression(context, value, valuePath) : {
2076
- path: valuePath,
2077
- argumentSlot: void 0
2078
- };
2079
- }
2080
- function signatureExpression(context, expression, path) {
2081
- const position = {
2082
- path,
2083
- argumentSlot: void 0
2084
- };
2085
- if (expression === void 0 || context.offset <= expression.syntax.offset || context.offset >= expression.syntax.endOffset && !recoveredContainerContainsCursor(expression, context.offset)) return position;
2086
- if (expression instanceof ArrayLiteralAst) return betweenDelimiters(context.offset, expression.lbracket(), expression.rbracket()) ? signatureExpression(context, listElementAtCursor(context, expression), [...path, { kind: "listElement" }]) : void 0;
2087
- if (expression instanceof ObjectLiteralExprAst) {
2088
- const closing = expression.rbrace();
2089
- if (closing !== void 0 && context.offset >= closing.endOffset) return void 0;
2090
- const field = recordFieldAtCursor(context, expression);
2091
- return field !== void 0 ? signatureExpression(context, field.value(), [...path, { kind: "recordValue" }]) : position;
2092
- }
2093
- if (expression instanceof FunctionCallAst) {
2094
- const opening = expression.lparen();
2095
- if (opening !== void 0 && context.offset > opening.offset) {
2096
- const name = expression.name();
2097
- const identifier = name?.identifier()?.name();
2098
- return identifier !== void 0 && name?.isSimpleName(identifier) === true ? signatureArguments(context, expression, [...path, {
2099
- kind: "functionCall",
2100
- name: identifier
2101
- }]) : void 0;
2102
- }
2103
- return expression.name()?.syntax.isInside(context.offset) === true ? position : void 0;
2104
- }
2105
- return position;
2106
- }
2107
- function providePslSignatureHelp(input) {
2108
- const context = classifyPslSignatureContext(input);
2109
- if (context === void 0) return null;
2110
- const spec = attributeSpecResolver(context, input.candidates)(context.attributeName);
2111
- if (spec === void 0) return null;
2112
- return signatureHelp(context, spec, input.clientSupportsLabelOffsets === true);
2113
- }
2114
- function signatureHelp(context, spec, labelOffsets) {
2115
- const callIndex = context.path.reduce((last, step, index) => step.kind === "functionCall" ? index : last, -1);
2116
- const call = context.path[callIndex];
2117
- const signaturePath = context.path.slice(0, callIndex + 1);
2118
- const name = call?.kind === "functionCall" ? call.name : `${spec.level === "field" ? "@" : "@@"}${spec.name}`;
2119
- const signatures = resolveGrammar(spec, signaturePath).flatMap((grammar) => {
2120
- if ("kind" in grammar) return [];
2121
- const active = context.path[callIndex + 1];
2122
- const params = parameters(grammar, active?.kind === "namedArgument" ? active.name : void 0);
2123
- const index = parameterIndex(context, active, params);
2124
- return [{
2125
- signature: renderSignature(name, grammar, params, labelOffsets),
2126
- index
2127
- }];
2128
- });
2129
- if (signatures.length === 0) return null;
2130
- const matched = signatures.findIndex(({ signature, index }) => index >= 0 && index < (signature.parameters?.length ?? 0));
2131
- const activeSignature = matched < 0 ? 0 : matched;
2132
- const activeParameter = signatures[activeSignature]?.index;
2133
- return {
2134
- signatures: signatures.map(({ signature }) => signature),
2135
- activeSignature,
2136
- ...matched >= 0 && activeParameter !== void 0 ? { activeParameter } : {}
2137
- };
2138
- }
2139
- function parameterIndex(context, active, params) {
2140
- if (active?.kind === "namedArgument") return params.findIndex((param) => param.key === active.name);
2141
- if (active?.kind === "positionalArgument") return active.index;
2142
- const slot = context.argumentSlot;
2143
- if (slot !== void 0) return params.findIndex((param, index) => index >= slot.positionalIndex && !slot.existingNamedKeys.includes(param.key));
2144
- return -1;
2145
- }
2146
- function parameters(signature, activeName) {
2147
- const positional = signature.positional ?? [];
2148
- const keys = new Set(positional.map((param) => param.key));
2149
- const namedAlias = activeName === void 0 ? void 0 : signature.named?.[activeName];
2150
- return [...positional.map((param) => param.key === activeName && namedAlias !== void 0 ? {
2151
- key: param.key,
2152
- ...namedAlias
2153
- } : param), ...Object.entries(signature.named ?? {}).flatMap(([key, param]) => keys.has(key) ? [] : [{
2154
- key,
2155
- ...param
2156
- }])];
2157
- }
2158
- function renderSignature(name, signature, params, labelOffsets) {
2159
- let label = `${name}(`;
2160
- const rendered = params.map((param, index) => {
2161
- if (index > 0) label += ", ";
2162
- const positional = index < (signature.positional?.length ?? 0);
2163
- const optional = "optional" in param.type && param.type.optional === true;
2164
- const typeLabel = optional && param.type.label.includes(" | ") ? `(${param.type.label})` : param.type.label;
2165
- const text = positional ? `${typeLabel}${optional ? "?" : ""}` : `${param.key}${optional ? "?" : ""}: ${param.type.label}`;
2166
- const start = label.length;
2167
- label += text;
2168
- const documentation = positional ? `**${param.key}**\n\n${param.documentation}${signature.named?.[param.key] === void 0 ? "" : `\n\nAccepted positionally or by \`${param.key}:\`.`}` : param.documentation;
2169
- return {
2170
- label: positional && labelOffsets ? [start, label.length] : text,
2171
- documentation: {
2172
- kind: MarkupKind.Markdown,
2173
- value: documentation
2174
- }
2175
- };
2176
- });
2177
- return {
2178
- label: `${label})`,
2179
- documentation: {
2180
- kind: MarkupKind.Markdown,
2181
- value: signature.documentation
2182
- },
2183
- parameters: rendered
2184
- };
2185
- }
2186
2488
  const CONFIG_LOAD_FAILED_CODE = "PRISMA_CONFIG_LOAD_FAILED";
2187
2489
  var Project = class {
2188
2490
  configPath;
@@ -2270,6 +2572,22 @@ var Project = class {
2270
2572
  return null;
2271
2573
  }
2272
2574
  }
2575
+ async hover(uri, position) {
2576
+ const data = await this.#resolveMember(uri);
2577
+ const document = data?.artifacts.document(uri);
2578
+ if (data === void 0 || document === void 0) return null;
2579
+ try {
2580
+ return providePslHover({
2581
+ document: document.parse().document,
2582
+ sourceFile: document.sourceFile,
2583
+ position,
2584
+ binder: data.artifacts.binder(),
2585
+ pslBlockDescriptors: data.controlStack.pslBlockDescriptors
2586
+ });
2587
+ } catch {
2588
+ return null;
2589
+ }
2590
+ }
2273
2591
  async foldingRanges(uri) {
2274
2592
  const data = await this.#resolveMember(uri);
2275
2593
  const document = data?.artifacts.document(uri);
@@ -2686,6 +3004,10 @@ function createServerOn(connection) {
2686
3004
  if (getOpenDocument(uri) === void 0) return null;
2687
3005
  return (await projects.nearestProject(uri))?.signatureHelp(uri, position, clientCapabilities.signatureLabelOffsets) ?? null;
2688
3006
  }
3007
+ async function hoverForDocument(uri, position) {
3008
+ if (getOpenDocument(uri) === void 0) return null;
3009
+ return (await projects.nearestProject(uri))?.hover(uri, position) ?? null;
3010
+ }
2689
3011
  connection.onInitialize(async (params) => {
2690
3012
  rootPath = resolveRootPath(params);
2691
3013
  clientCapabilities = resolveClientCapabilities(params);
@@ -2712,6 +3034,7 @@ function createServerOn(connection) {
2712
3034
  ","
2713
3035
  ] },
2714
3036
  signatureHelpProvider: { triggerCharacters: ["(", ","] },
3037
+ hoverProvider: true,
2715
3038
  ...clientCapabilities.pullDiagnostics ? { diagnosticProvider: {
2716
3039
  interFileDependencies: true,
2717
3040
  workspaceDiagnostics: false
@@ -2723,6 +3046,7 @@ function createServerOn(connection) {
2723
3046
  connection.onDocumentFormatting((params) => formatDocument(params.textDocument.uri));
2724
3047
  connection.onCompletion((params) => completeDocument(params.textDocument.uri, params.position));
2725
3048
  connection.onSignatureHelp((params) => signatureHelpForDocument(params.textDocument.uri, params.position));
3049
+ connection.onHover((params) => hoverForDocument(params.textDocument.uri, params.position));
2726
3050
  connection.languages.semanticTokens.on((params) => semanticTokensForDocument(params.textDocument.uri));
2727
3051
  connection.languages.semanticTokens.onRange((params) => semanticTokensForDocument(params.textDocument.uri, params.range));
2728
3052
  connection.languages.diagnostics.on(async (params) => {
@@ -3048,4 +3372,4 @@ function startServer(streams) {
3048
3372
  //#endregion
3049
3373
  export { startServer };
3050
3374
 
3051
- //# sourceMappingURL=exports-EXh7hBAx.mjs.map
3375
+ //# sourceMappingURL=exports-C4Peu_9F.mjs.map