@prisma/orm-toolchain 8.0.0-rc.11-dev.26 → 8.0.0-rc.11-dev.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -5144,7 +5144,7 @@ const lspCommand = defineServerCommand({
5144
5144
  } },
5145
5145
  handler: async (args, io) => {
5146
5146
  const exitCode = await withoutClientProcessIdInArgv(async () => {
5147
- const { startServer } = await import("./exports-Bg8ce6Ih.mjs");
5147
+ const { startServer } = await import("./exports-DMDyYe3P.mjs");
5148
5148
  return startServer({
5149
5149
  stdin: io.stdin,
5150
5150
  stdout: io.stdout,
@@ -10,7 +10,7 @@ import { format } from "@prisma/orm-framework/psl-parser/format";
10
10
  import { CompletionItemKind, ConnectionError, ConnectionErrors, DiagnosticSeverity, DidChangeWatchedFilesNotification, DocumentDiagnosticReportKind, FoldingRangeKind, InsertTextFormat, LSPErrorCodes, MarkupKind, ProposedFeatures, RegistrationRequest, ResponseError, SemanticTokenModifiers, SemanticTokenTypes, TextDocumentSyncKind, TextDocuments, createConnection } from "vscode-languageserver";
11
11
  import { TextDocument } from "vscode-languageserver-textdocument";
12
12
  import { ArrayLiteralAst, AttributeArgAst, AttributeArgListAst, BooleanLiteralExprAst, CompositeTypeDeclarationAst, FieldAttributeAst, FieldDeclarationAst, FunctionCallAst, GenericBlockDeclarationAst, IdentifierAst, KeyValuePairAst, ModelAttributeAst, ModelDeclarationAst, NamespaceDeclarationAst, NumberLiteralExprAst, ObjectLiteralExprAst, StringLiteralExprAst, SyntaxNode, TypesBlockAst, any, filterChildren, findChildToken, isTrivia, nonTriviaSibling, parse, skipTriviaToken } from "@prisma/orm-framework/psl-parser/syntax";
13
- import { isAuthoringPslBlockDescriptor } from "@prisma/orm-framework/components/authoring";
13
+ import { isAuthoringPslBlockDescriptor, isAuthoringTypeConstructorDescriptor } from "@prisma/orm-framework/components/authoring";
14
14
  import { assembleAttributeSpecs, buildSymbolTable, findBlockDescriptor } from "@prisma/orm-framework/psl-parser";
15
15
  import { hasPslInterpreter } from "@prisma/orm-framework/psl-parser/interpret";
16
16
  import { ProposedFeatures as ProposedFeatures$1, StreamMessageReader, StreamMessageWriter, createConnection as createConnection$1, createProtocolConnection } from "vscode-languageserver/node";
@@ -543,6 +543,16 @@ function cursorIdentifier(at, offset) {
543
543
  const left = at.leftBiased();
544
544
  if (left?.kind === "Ident" && left.endOffset === offset) return left;
545
545
  }
546
+ /**
547
+ * Presentation-level classification of a `types {}` binding: a
548
+ * non-constructor binding whose base is a configured scalar type refines that
549
+ * scalar (rendered as a default-library type); everything else reads as a
550
+ * plain alias. The authoritative scalar-or-not pronouncement lives in the
551
+ * interpreter's named-type resolution — this mirrors it for display only.
552
+ */
553
+ function refinesScalarType(symbol, scalarTypes) {
554
+ return !symbol.isConstructor && symbol.baseType !== void 0 && scalarTypes.includes(symbol.baseType);
555
+ }
546
556
  function modelSymbolForNode(symbolTable, node) {
547
557
  const topLevelMatch = Object.values(symbolTable.topLevel.models).find((model) => sameSyntax(model.node.syntax, node.syntax));
548
558
  if (topLevelMatch !== void 0) return topLevelMatch;
@@ -554,7 +564,7 @@ function modelSymbolForNode(symbolTable, node) {
554
564
  function fieldSymbolForNode(model, node) {
555
565
  return Object.values(model.fields).find((field) => sameSyntax(field.node.syntax, node.syntax));
556
566
  }
557
- function localFieldNames(context, symbols) {
567
+ function localFieldNames(context, symbols, scalarTypes, typeConstructors = {}) {
558
568
  switch (context.kind) {
559
569
  case "blockAttributeNamedKey":
560
570
  case "blockAttributeArgumentSlot":
@@ -564,10 +574,10 @@ function localFieldNames(context, symbols) {
564
574
  case "fieldAttributeValue":
565
575
  case "modelAttributeNamedKey":
566
576
  case "modelAttributeArgumentSlot":
567
- case "modelAttributeValue": return Object.keys(modelSymbolForNode(symbols, context.model)?.fields ?? {});
577
+ case "modelAttributeValue": return scalarFieldNames(symbols, modelSymbolForNode(symbols, context.model), scalarTypes, typeConstructors);
568
578
  }
569
579
  }
570
- function referencedFieldNames(context, symbols) {
580
+ function referencedFieldNames(context, symbols, scalarTypes, typeConstructors = {}) {
571
581
  switch (context.kind) {
572
582
  case "blockAttributeNamedKey":
573
583
  case "blockAttributeArgumentSlot":
@@ -582,10 +592,35 @@ function referencedFieldNames(context, symbols) {
582
592
  if (model === void 0) return [];
583
593
  const field = fieldSymbolForNode(model, context.field);
584
594
  if (field === void 0) return [];
585
- return Object.keys(referencedModel(symbols, model, field)?.fields ?? {});
595
+ return scalarFieldNames(symbols, referencedModel(symbols, model, field), scalarTypes, typeConstructors);
586
596
  }
587
597
  }
588
598
  }
599
+ function scalarFieldNames(symbols, model, scalarTypes, typeConstructors) {
600
+ if (model === void 0) return [];
601
+ const namespaceName = model.node.syntax.findAncestor(NamespaceDeclarationAst.cast)?.name()?.name();
602
+ const namespace = namespaceName === void 0 ? void 0 : symbols.topLevel.namespaces[namespaceName];
603
+ return Object.values(model.fields).filter((field) => {
604
+ if (field.malformedType === true || field.typeContractSpaceId !== void 0) return false;
605
+ if (field.typeConstructor !== void 0) return isScalarConstructor(field.typeConstructor.path, typeConstructors);
606
+ if (field.typeNamespaceId !== void 0) return false;
607
+ const name = field.typeName;
608
+ if (namespace?.models[name] !== void 0 || namespace?.compositeTypes[name] !== void 0 || namespace?.blocks[name] !== void 0 || symbols.topLevel.models[name] !== void 0 || symbols.topLevel.compositeTypes[name] !== void 0 || symbols.topLevel.blocks[name] !== void 0) return false;
609
+ const namedType = symbols.topLevel.namedTypes[name];
610
+ if (namedType === void 0) return scalarTypes.includes(name);
611
+ return namedType.typeConstructor === void 0 ? refinesScalarType(namedType, scalarTypes) : isScalarConstructor(namedType.typeConstructor.path, typeConstructors);
612
+ }).map((field) => field.name);
613
+ }
614
+ function isScalarConstructor(path, typeConstructors) {
615
+ let current = typeConstructors;
616
+ for (const [index, segment] of path.entries()) {
617
+ const value = Object.hasOwn(current, segment) ? current[segment] : void 0;
618
+ if (value === void 0) return false;
619
+ if (isAuthoringTypeConstructorDescriptor(value)) return index === path.length - 1;
620
+ current = value;
621
+ }
622
+ return false;
623
+ }
589
624
  function referencedModel(symbols, model, field) {
590
625
  if (field.malformedType === true || field.typeContractSpaceId !== void 0) return void 0;
591
626
  if (field.typeNamespaceId !== void 0) return symbols.topLevel.namespaces[field.typeNamespaceId]?.models[field.typeName];
@@ -652,11 +687,11 @@ function requiredArguments(signature) {
652
687
  }])];
653
688
  }
654
689
  function requiredArgumentSnippet(argument, tabStop) {
655
- if (argument.kind === "positional") return argSnippetPlaceholder(argument.argument.type, tabStop);
656
- return `${argument.key}: ${argSnippetPlaceholder(argument.type, tabStop)}`;
690
+ if (argument.kind === "positional") return argSnippetPlaceholder(argument.argument.type, tabStop, argument.argument.key);
691
+ return `${argument.key}: ${argSnippetPlaceholder(argument.type, tabStop, argument.key)}`;
657
692
  }
658
- function argSnippetPlaceholder(param, tabStop) {
659
- const placeholder = `\${${tabStop.toString()}:}`;
693
+ function argSnippetPlaceholder(param, tabStop, key) {
694
+ const placeholder = `\${${tabStop.toString()}:${key}}`;
660
695
  if (param.kind === "str") return `"${placeholder}"`;
661
696
  if (param.kind === "list") return `[${placeholder}]`;
662
697
  if (param.kind === "record") return `{ ${placeholder} }`;
@@ -706,11 +741,11 @@ function provideAttributeValueCompletionItems(input, spec) {
706
741
  return orderedItems(resolveGrammar(spec, input.context.path).flatMap((grammar) => "kind" in grammar ? valueItems(input, grammar, input.context.syntax) : []));
707
742
  }
708
743
  function namedKeyItems(input, signature) {
709
- return Object.keys(signature.named ?? {}).filter((name) => !input.context.existingNamedKeys.includes(name)).map((name) => {
744
+ return Object.entries(signature.named ?? {}).filter(([name]) => !input.context.existingNamedKeys.includes(name)).map(([name, param]) => {
710
745
  const snippet = input.clientSupportsSnippets && !input.context.hasColon;
711
- const value = snippet ? "${1:}" : "";
746
+ const value = snippet ? `\${1:${name}}` : "";
712
747
  return {
713
- ...completionItem(input, name, input.context.hasColon ? name : `${name}: ${value}`, CompletionItemKind.Property, snippet),
748
+ ...completionItem(input, name, input.context.hasColon ? name : `${name}: ${value}`, CompletionItemKind.Property, snippet, param.documentation),
714
749
  ...!input.context.hasColon && input.clientSupportsTriggerSuggestCommand === true ? { command: {
715
750
  title: "Suggest argument values",
716
751
  command: "editor.action.triggerSuggest"
@@ -728,7 +763,7 @@ function valueItems(input, param, syntax) {
728
763
  const args = requiredArgumentsSnippet(type.signature) || (hasParameters ? "${1:}" : "");
729
764
  const text = snippet ? `${type.name}(${args})` : type.name;
730
765
  return [{
731
- ...completionItem(input, type.name, text, CompletionItemKind.Function, snippet),
766
+ ...completionItem(input, type.name, text, CompletionItemKind.Function, snippet, type.signature.documentation),
732
767
  ...snippet && input.clientSupportsTriggerParameterHintsCommand === true && hasParameters ? { command: {
733
768
  title: "Show argument hints",
734
769
  command: "editor.action.triggerParameterHints"
@@ -737,7 +772,7 @@ function valueItems(input, param, syntax) {
737
772
  }
738
773
  if (syntax === "functionName") return [];
739
774
  switch (type.kind) {
740
- case "identifier": return scalarItems(input, [type.name]);
775
+ case "identifier": return scalarItems(input, [type.name], type.documentation);
741
776
  case "str": return scalarItems(input, type.value === void 0 ? [] : [JSON.stringify(type.value)]);
742
777
  case "num": return scalarItems(input, type.value === void 0 ? [] : [String(type.value)]);
743
778
  case "bool": return scalarItems(input, ["true", "false"]);
@@ -751,14 +786,14 @@ function valueItems(input, param, syntax) {
751
786
  case "rejecting": return [];
752
787
  }
753
788
  }
754
- function scalarItems(input, labels) {
755
- return labels.map((label) => completionItem(input, label, label, CompletionItemKind.Value));
789
+ function scalarItems(input, labels, documentation) {
790
+ return labels.map((label) => completionItem(input, label, label, CompletionItemKind.Value, false, documentation));
756
791
  }
757
- function completionItem(input, label, newText, kind, snippet = false) {
792
+ function completionItem(input, label, newText, kind, snippet = false, documentation) {
758
793
  return {
759
794
  label,
760
795
  kind,
761
- detail: kind === CompletionItemKind.Property ? "Attribute argument" : "PSL argument value",
796
+ detail: documentation ?? (kind === CompletionItemKind.Property ? "Attribute argument" : "PSL argument value"),
762
797
  filterText: label,
763
798
  textEdit: {
764
799
  range: {
@@ -786,16 +821,6 @@ function orderedItems(items) {
786
821
  sortText: index.toString().padStart(4, "0")
787
822
  }));
788
823
  }
789
- /**
790
- * Presentation-level classification of a `types {}` binding: a
791
- * non-constructor binding whose base is a configured scalar type refines that
792
- * scalar (rendered as a default-library type); everything else reads as a
793
- * plain alias. The authoritative scalar-or-not pronouncement lives in the
794
- * interpreter's named-type resolution — this mirrors it for display only.
795
- */
796
- function refinesScalarType(symbol, scalarTypes) {
797
- return !symbol.isConstructor && symbol.baseType !== void 0 && scalarTypes.includes(symbol.baseType);
798
- }
799
824
  const categoryOrder = {
800
825
  configuredScalar: 0,
801
826
  topLevelModel: 1,
@@ -811,13 +836,13 @@ const declarationKeywordCategoryOrder = {
811
836
  genericBlock: 1
812
837
  };
813
838
  const nameSnippetPlaceholder = "${1:Name}";
839
+ const namespaceSnippetPlaceholder = "${1:name}";
840
+ const namespaceNativeDeclarationKeywords = [nativeDeclarationKeyword("model", "model ", `model ${nameSnippetPlaceholder} {\n \${0:// Fields}\n}`, "Defines a data model."), nativeDeclarationKeyword("type", "type ", `type ${nameSnippetPlaceholder} {\n \${0:// Fields}\n}`, "Defines a reusable composite type.")];
814
841
  const documentNativeDeclarationKeywords = [
815
- nativeDeclarationKeyword("model", "model ", `model ${nameSnippetPlaceholder} {\n $0\n}`),
816
- nativeDeclarationKeyword("type", "type ", `type ${nameSnippetPlaceholder} {\n $0\n}`),
817
- nativeDeclarationKeyword("types", "types ", "types {\n $0\n}"),
818
- nativeDeclarationKeyword("namespace", "namespace ", `namespace \${1:name} {\n $0\n}`)
842
+ ...namespaceNativeDeclarationKeywords,
843
+ nativeDeclarationKeyword("types", "types ", "types {\n ${0:// Type aliases}\n}", "Defines reusable named types."),
844
+ nativeDeclarationKeyword("namespace", "namespace ", `namespace ${namespaceSnippetPlaceholder} {\n \${0:// Models and types}\n}`, "Groups declarations belonging to the same database schema or database.")
819
845
  ];
820
- const namespaceNativeDeclarationKeywords = [nativeDeclarationKeyword("model", "model ", `model ${nameSnippetPlaceholder} {\n $0\n}`), nativeDeclarationKeyword("type", "type ", `type ${nameSnippetPlaceholder} {\n $0\n}`)];
821
846
  function providePslCompletionItems(input) {
822
847
  const { context } = input;
823
848
  switch (context.kind) {
@@ -848,7 +873,7 @@ function providePslCompletionItems(input) {
848
873
  clientSupportsSnippets: input.clientSupportsSnippets,
849
874
  clientSupportsTriggerSuggestCommand: input.clientSupportsTriggerSuggestCommand === true,
850
875
  clientSupportsTriggerParameterHintsCommand: input.clientSupportsTriggerParameterHintsCommand === true,
851
- fieldNames: (kind) => kind === "fieldRef" ? localFieldNames(context, input.candidates.symbolTable) : referencedFieldNames(context, input.candidates.symbolTable)
876
+ fieldNames: (kind) => kind === "fieldRef" ? localFieldNames(context, input.candidates.symbolTable, input.candidates.scalarTypes, input.candidates.authoringContributions?.type) : referencedFieldNames(context, input.candidates.symbolTable, input.candidates.scalarTypes, input.candidates.authoringContributions?.type)
852
877
  }, spec);
853
878
  }
854
879
  case "fieldAttributeValue":
@@ -860,7 +885,7 @@ function providePslCompletionItems(input) {
860
885
  sourceFile: input.sourceFile,
861
886
  clientSupportsSnippets: input.clientSupportsSnippets,
862
887
  clientSupportsTriggerParameterHintsCommand: input.clientSupportsTriggerParameterHintsCommand === true,
863
- fieldNames: (kind) => kind === "fieldRef" ? localFieldNames(context, input.candidates.symbolTable) : referencedFieldNames(context, input.candidates.symbolTable)
888
+ fieldNames: (kind) => kind === "fieldRef" ? localFieldNames(context, input.candidates.symbolTable, input.candidates.scalarTypes, input.candidates.authoringContributions?.type) : referencedFieldNames(context, input.candidates.symbolTable, input.candidates.scalarTypes, input.candidates.authoringContributions?.type)
864
889
  }, spec);
865
890
  }
866
891
  case "declarationKeyword": return provideDeclarationKeywordCompletionItems(context, input.sourceFile, input.candidates, input.clientSupportsSnippets);
@@ -877,16 +902,17 @@ function provideAttributeNameCompletionItems(context, sourceFile, source, client
877
902
  };
878
903
  const resolveSpec = attributeSpecResolver(context, source);
879
904
  return names.map((name) => {
905
+ const spec = resolveSpec(name);
880
906
  const newText = attributeNameEditText({
881
907
  name,
882
- spec: resolveSpec(name),
908
+ spec,
883
909
  hasArgumentList: context.hasArgumentList,
884
910
  clientSupportsSnippets
885
911
  });
886
912
  return {
887
913
  label: name,
888
914
  kind: CompletionItemKind.Function,
889
- detail: "PSL attribute",
915
+ detail: spec?.documentation || "PSL attribute",
890
916
  sortText: name,
891
917
  filterText: name,
892
918
  textEdit: {
@@ -941,25 +967,41 @@ function provideDeclarationKeywordCompletionItems(context, sourceFile, source, c
941
967
  function declarationKeywordCandidates(scope, source) {
942
968
  return [...scope === "namespace" ? namespaceNativeDeclarationKeywords : documentNativeDeclarationKeywords, ...genericBlockDeclarationKeywordCandidates(source.pslBlockDescriptors)];
943
969
  }
944
- function nativeDeclarationKeyword(label, insertText, snippetText) {
970
+ function nativeDeclarationKeyword(label, insertText, snippetText, documentation) {
945
971
  return {
946
972
  category: "native",
947
973
  label,
948
974
  insertText,
949
975
  snippetText,
950
- detail: "PSL declaration keyword",
976
+ detail: documentation,
951
977
  kind: CompletionItemKind.Keyword
952
978
  };
953
979
  }
954
980
  function genericBlockDeclarationKeywordCandidates(descriptors) {
955
- return descriptorBlockKeywords(descriptors).map((keyword) => ({
956
- category: "genericBlock",
957
- label: keyword,
958
- insertText: `${keyword} `,
959
- snippetText: `${keyword} ${nameSnippetPlaceholder} {\n $0\n}`,
960
- detail: "Generic block keyword",
961
- kind: CompletionItemKind.Keyword
962
- }));
981
+ return descriptorBlockKeywords(descriptors).map((keyword) => {
982
+ const descriptor = findBlockDescriptor(descriptors, keyword);
983
+ return {
984
+ category: "genericBlock",
985
+ label: keyword,
986
+ insertText: `${keyword} `,
987
+ snippetText: genericBlockSnippet(keyword, descriptor),
988
+ detail: descriptor?.documentation || "Generic block keyword",
989
+ kind: CompletionItemKind.Keyword
990
+ };
991
+ });
992
+ }
993
+ function genericBlockSnippet(keyword, descriptor) {
994
+ const parameters = Object.entries(descriptor?.parameters ?? {}).filter(([, parameter]) => parameter.required === true).map(([name, parameter], index) => {
995
+ const placeholder = `\${${index + 2}:${name}}`;
996
+ return ` ${name} = ${parameter.kind === "list" ? `[${placeholder}]` : placeholder}`;
997
+ });
998
+ const cursor = parameters.length === 0 ? "${0:// Block parameters and attributes}" : "$0";
999
+ return [
1000
+ `${keyword} ${nameSnippetPlaceholder} {`,
1001
+ ...parameters,
1002
+ ` ${cursor}`,
1003
+ "}"
1004
+ ].join("\n");
963
1005
  }
964
1006
  function descriptorBlockKeywords(descriptors) {
965
1007
  const keywords = [];
@@ -989,7 +1031,7 @@ function provideGenericBlockKeyCompletionItems(context, sourceFile, source) {
989
1031
  return Object.keys(descriptor.parameters).filter((parameterName) => !existing.has(parameterName)).map((parameterName, index) => ({
990
1032
  label: parameterName,
991
1033
  kind: CompletionItemKind.Property,
992
- detail: "Generic block parameter",
1034
+ detail: descriptor.parameters[parameterName]?.documentation || "Generic block parameter",
993
1035
  sortText: genericBlockParameterSortText(index, parameterName),
994
1036
  filterText: parameterName,
995
1037
  textEdit: {
@@ -1009,7 +1051,7 @@ function existingGenericBlockParameterNames(block, cursorOffset) {
1009
1051
  }
1010
1052
  function provideModelTypeCompletionItems(context, sourceFile, source) {
1011
1053
  return modelTypeCompletionItems(context, sourceFile, [
1012
- ...configuredScalarCandidates(source.scalarTypes),
1054
+ ...configuredScalarCandidates(source),
1013
1055
  ...topLevelSymbolCandidates(source.symbolTable, source.scalarTypes),
1014
1056
  ...allNamespaceCandidates(source.symbolTable)
1015
1057
  ]);
@@ -1035,13 +1077,14 @@ function modelTypeCompletionItems(context, sourceFile, candidates) {
1035
1077
  }
1036
1078
  }));
1037
1079
  }
1038
- function configuredScalarCandidates(scalarTypes) {
1039
- return sortedUnique(scalarTypes).map((name) => ({
1080
+ function configuredScalarCandidates(source) {
1081
+ const constructors = source.authoringContributions?.type ?? {};
1082
+ return sortedUnique(source.scalarTypes).map((name) => ({
1040
1083
  category: "configuredScalar",
1041
1084
  label: name,
1042
1085
  insertText: name,
1043
1086
  filterText: name,
1044
- detail: "Configured scalar type",
1087
+ detail: constructors[name] !== void 0 && isAuthoringTypeConstructorDescriptor(constructors[name]) ? constructors[name].documentation || "Configured scalar type" : "Configured scalar type",
1045
1088
  kind: CompletionItemKind.Keyword
1046
1089
  }));
1047
1090
  }
@@ -2686,4 +2729,4 @@ function startServer(streams) {
2686
2729
  //#endregion
2687
2730
  export { startServer };
2688
2731
 
2689
- //# sourceMappingURL=exports-Bg8ce6Ih.mjs.map
2732
+ //# sourceMappingURL=exports-DMDyYe3P.mjs.map