@prisma/orm-toolchain 8.0.0-rc.13 → 8.0.0-rc.13-dev.2
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.
|
@@ -7,7 +7,7 @@ import { join } from "pathe";
|
|
|
7
7
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
8
|
import { normalize as normalize$1 } from "node:path";
|
|
9
9
|
import { format } from "@prisma/orm-framework/psl-parser/format";
|
|
10
|
-
import { assembleAttributeSpecs, buildSymbolTable, findBlockDescriptor, isPrismaNextSchema, renameLegacyDirective } from "@prisma/orm-framework/psl-parser";
|
|
10
|
+
import { assembleAttributeSpecs, blockSpecFactoryOf, buildSymbolTable, findBlockDescriptor, isPrismaNextSchema, renameLegacyDirective } from "@prisma/orm-framework/psl-parser";
|
|
11
11
|
import { CompletionItemKind, CompletionItemTag, ConnectionError, ConnectionErrors, DiagnosticSeverity, DidChangeWatchedFilesNotification, DocumentDiagnosticReportKind, FoldingRangeKind, InsertTextFormat, LSPErrorCodes, MarkupKind, ProposedFeatures, RegistrationRequest, ResponseError, SemanticTokenModifiers, SemanticTokenTypes, TextDocumentSyncKind, createConnection } from "vscode-languageserver";
|
|
12
12
|
import { ArrayLiteralAst, AttributeArgAst, AttributeArgListAst, BooleanLiteralExprAst, CompositeTypeDeclarationAst, FieldAttributeAst, FieldDeclarationAst, FunctionCallAst, GenericBlockDeclarationAst, IdentifierAst, KeyValuePairAst, ModelAttributeAst, ModelDeclarationAst, NamespaceDeclarationAst, NumberLiteralExprAst, ObjectLiteralExprAst, PslSources, StringLiteralExprAst, SyntaxNode, TaggedLiteralExprAst, TypesBlockAst, any, filterChildren, findChildToken, isTrivia, nonTriviaSibling, parse, skipTriviaToken } from "@prisma/orm-framework/psl-parser/syntax";
|
|
13
13
|
import { isAuthoringPslBlockDescriptor, isAuthoringTypeConstructorDescriptor } from "@prisma/orm-framework/components/authoring";
|
|
@@ -555,6 +555,14 @@ function modelSymbolForNode(symbolTable, node) {
|
|
|
555
555
|
if (namespaceMatch !== void 0) return namespaceMatch;
|
|
556
556
|
}
|
|
557
557
|
}
|
|
558
|
+
function blockSymbolForNode(symbolTable, node) {
|
|
559
|
+
const topLevelMatch = Object.values(symbolTable.topLevel.blocks).find((block) => sameSyntax(block.node.syntax, node.syntax));
|
|
560
|
+
if (topLevelMatch !== void 0) return topLevelMatch;
|
|
561
|
+
for (const namespace of Object.values(symbolTable.topLevel.namespaces)) {
|
|
562
|
+
const namespaceMatch = Object.values(namespace.blocks).find((block) => sameSyntax(block.node.syntax, node.syntax));
|
|
563
|
+
if (namespaceMatch !== void 0) return namespaceMatch;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
558
566
|
function fieldSymbolForNode(model, node) {
|
|
559
567
|
return Object.values(model.fields).find((field) => sameSyntax(field.node.syntax, node.syntax));
|
|
560
568
|
}
|
|
@@ -628,10 +636,15 @@ function attributeSpecResolver(context, source) {
|
|
|
628
636
|
switch (context.ownerKind) {
|
|
629
637
|
case "block": {
|
|
630
638
|
const descriptor = findBlockDescriptor(source.pslBlockDescriptors, context.blockKeyword);
|
|
639
|
+
const block = blockSymbolForNode(source.symbolTable, context.block);
|
|
640
|
+
if (block === void 0) return () => void 0;
|
|
631
641
|
return (name) => {
|
|
632
642
|
const factory = descriptor?.attributes?.[name];
|
|
633
643
|
if (factory === void 0) return void 0;
|
|
634
|
-
return blindCast(factory)(
|
|
644
|
+
return blindCast(factory)({
|
|
645
|
+
symbols: source.symbolTable,
|
|
646
|
+
block
|
|
647
|
+
});
|
|
635
648
|
};
|
|
636
649
|
}
|
|
637
650
|
case "model": {
|
|
@@ -700,16 +713,13 @@ function argSnippetPlaceholder(param, tabStop, key) {
|
|
|
700
713
|
function isOptionalParam(param) {
|
|
701
714
|
return "optional" in param && param.optional === true;
|
|
702
715
|
}
|
|
703
|
-
function directArgType(param) {
|
|
704
|
-
return blindCast(param);
|
|
705
|
-
}
|
|
706
716
|
function resolveGrammar(signature, path) {
|
|
707
717
|
let grammars = [signature];
|
|
708
718
|
for (const step of path) grammars = grammars.flatMap((grammar) => advanceGrammar(grammar, step));
|
|
709
719
|
return grammars;
|
|
710
720
|
}
|
|
711
721
|
function advanceGrammar(grammar, step) {
|
|
712
|
-
const type = "kind" in grammar ?
|
|
722
|
+
const type = "kind" in grammar ? grammar : void 0;
|
|
713
723
|
if (type?.kind === "oneOf") return type.alternatives.flatMap((alternative) => advanceGrammar(alternative, step));
|
|
714
724
|
switch (step.kind) {
|
|
715
725
|
case "positionalArgument": {
|
|
@@ -753,9 +763,8 @@ function namedKeyItems(input, signature) {
|
|
|
753
763
|
};
|
|
754
764
|
});
|
|
755
765
|
}
|
|
756
|
-
function valueItems(input,
|
|
757
|
-
if (
|
|
758
|
-
const type = directArgType(param);
|
|
766
|
+
function valueItems(input, type, syntax) {
|
|
767
|
+
if (type === void 0) return [];
|
|
759
768
|
if (type.kind === "oneOf") return type.alternatives.flatMap((alternative) => valueItems(input, alternative, syntax));
|
|
760
769
|
if (type.kind === "funcCall") {
|
|
761
770
|
const snippet = input.clientSupportsSnippets && syntax !== "functionName";
|
|
@@ -780,6 +789,7 @@ function valueItems(input, param, syntax) {
|
|
|
780
789
|
case "str": return scalarItems(input, type.value === void 0 ? [] : [JSON.stringify(type.value)]);
|
|
781
790
|
case "num": return scalarItems(input, type.value === void 0 ? [] : [String(type.value)]);
|
|
782
791
|
case "bool": return scalarItems(input, ["true", "false"]);
|
|
792
|
+
case "null": return scalarItems(input, ["null"]);
|
|
783
793
|
case "fieldRef":
|
|
784
794
|
case "referencedFieldRef": return scalarItems(input, input.fieldNames(type.kind));
|
|
785
795
|
case "list":
|
|
@@ -989,22 +999,16 @@ function genericBlockDeclarationKeywordCandidates(descriptors) {
|
|
|
989
999
|
category: "genericBlock",
|
|
990
1000
|
label: keyword,
|
|
991
1001
|
insertText: `${keyword} `,
|
|
992
|
-
snippetText: genericBlockSnippet(keyword
|
|
1002
|
+
snippetText: genericBlockSnippet(keyword),
|
|
993
1003
|
detail: descriptor?.documentation || "Generic block keyword",
|
|
994
1004
|
kind: CompletionItemKind.Keyword
|
|
995
1005
|
};
|
|
996
1006
|
});
|
|
997
1007
|
}
|
|
998
|
-
function genericBlockSnippet(keyword
|
|
999
|
-
const parameters = Object.entries(descriptor?.parameters ?? {}).filter(([, parameter]) => parameter.required === true).map(([name, parameter], index) => {
|
|
1000
|
-
const placeholder = `\${${index + 2}:${name}}`;
|
|
1001
|
-
return ` ${name} = ${parameter.kind === "list" ? `[${placeholder}]` : placeholder}`;
|
|
1002
|
-
});
|
|
1003
|
-
const cursor = parameters.length === 0 ? "${0:// Block parameters and attributes}" : "$0";
|
|
1008
|
+
function genericBlockSnippet(keyword) {
|
|
1004
1009
|
return [
|
|
1005
1010
|
`${keyword} ${nameSnippetPlaceholder} {`,
|
|
1006
|
-
|
|
1007
|
-
` ${cursor}`,
|
|
1011
|
+
` \${0:// Block keys and attributes}`,
|
|
1008
1012
|
"}"
|
|
1009
1013
|
].join("\n");
|
|
1010
1014
|
}
|
|
@@ -1028,15 +1032,22 @@ function declarationKeywordSortText(candidate) {
|
|
|
1028
1032
|
function provideGenericBlockKeyCompletionItems(context, sourceFile, source) {
|
|
1029
1033
|
const descriptor = findBlockDescriptor(source.pslBlockDescriptors, context.blockKeyword);
|
|
1030
1034
|
if (descriptor === void 0) return [];
|
|
1035
|
+
const block = blockSymbolForNode(source.symbolTable, context.block);
|
|
1036
|
+
if (block === void 0) return [];
|
|
1037
|
+
const spec = blockSpecFactoryOf(descriptor)({
|
|
1038
|
+
symbols: source.symbolTable,
|
|
1039
|
+
block
|
|
1040
|
+
});
|
|
1041
|
+
if (spec.mode !== "struct") return [];
|
|
1031
1042
|
const existing = existingGenericBlockParameterNames(context.block, context.offset);
|
|
1032
1043
|
const replacementRange = {
|
|
1033
1044
|
start: sourceFile.positionAt(context.replacementStartOffset),
|
|
1034
1045
|
end: sourceFile.positionAt(context.offset)
|
|
1035
1046
|
};
|
|
1036
|
-
return Object.
|
|
1047
|
+
return Object.entries(spec.parameters).filter(([parameterName]) => !existing.has(parameterName)).map(([parameterName, parameter], index) => ({
|
|
1037
1048
|
label: parameterName,
|
|
1038
1049
|
kind: CompletionItemKind.Property,
|
|
1039
|
-
detail:
|
|
1050
|
+
detail: parameter.documentation || "Generic block parameter",
|
|
1040
1051
|
sortText: genericBlockParameterSortText(index, parameterName),
|
|
1041
1052
|
filterText: parameterName,
|
|
1042
1053
|
textEdit: {
|
|
@@ -1400,13 +1411,12 @@ function isThenable(value) {
|
|
|
1400
1411
|
* of symbol-table diagnostics. Never throws on malformed input — `parse`
|
|
1401
1412
|
* recovers and `buildSymbolTable` is documented not to throw.
|
|
1402
1413
|
*/
|
|
1403
|
-
function runPipeline(filename, text
|
|
1414
|
+
function runPipeline(filename, text) {
|
|
1404
1415
|
const { document, sources, diagnostics: parseDiagnostics } = parse(text, filename);
|
|
1405
1416
|
const sourceFile = sources.sourceFileFor(document.syntax);
|
|
1406
1417
|
const { symbolTable, diagnostics: symbolTableDiagnostics } = buildSymbolTable({
|
|
1407
1418
|
documents: [document],
|
|
1408
|
-
sources
|
|
1409
|
-
pslBlockDescriptors: inputs.pslBlockDescriptors
|
|
1419
|
+
sources
|
|
1410
1420
|
});
|
|
1411
1421
|
return {
|
|
1412
1422
|
document,
|
|
@@ -1423,9 +1433,9 @@ function runPipeline(filename, text, inputs) {
|
|
|
1423
1433
|
* "publish no diagnostics", but only the latter is a document we own and keep
|
|
1424
1434
|
* diagnosing.
|
|
1425
1435
|
*/
|
|
1426
|
-
function computeDocumentDiagnostics(uri, text, inputs
|
|
1436
|
+
function computeDocumentDiagnostics(uri, text, inputs) {
|
|
1427
1437
|
if (!inputs.includes(uri) || !isPrismaNextSchema(text)) return null;
|
|
1428
|
-
const { document, sourceFile, symbolTable, diagnostics, parseDiagnostics } = runPipeline(uri, text
|
|
1438
|
+
const { document, sourceFile, symbolTable, diagnostics, parseDiagnostics } = runPipeline(uri, text);
|
|
1429
1439
|
return {
|
|
1430
1440
|
diagnostics,
|
|
1431
1441
|
parseDiagnostics,
|
|
@@ -1435,7 +1445,7 @@ function computeDocumentDiagnostics(uri, text, inputs, controlStack) {
|
|
|
1435
1445
|
};
|
|
1436
1446
|
}
|
|
1437
1447
|
function createProjectArtifacts(options) {
|
|
1438
|
-
const { inputs,
|
|
1448
|
+
const { inputs, getDocument, interpretation } = options;
|
|
1439
1449
|
const documents = /* @__PURE__ */ new Map();
|
|
1440
1450
|
let symbolTableResult;
|
|
1441
1451
|
let sources = new PslSources([]);
|
|
@@ -1502,7 +1512,7 @@ function createProjectArtifacts(options) {
|
|
|
1502
1512
|
if (existing !== void 0) return existing;
|
|
1503
1513
|
const textDocument = getDocument(uri);
|
|
1504
1514
|
if (textDocument === void 0) return;
|
|
1505
|
-
const computed = computeDocumentDiagnostics(textDocument.uri, textDocument.getText(), inputs
|
|
1515
|
+
const computed = computeDocumentDiagnostics(textDocument.uri, textDocument.getText(), inputs);
|
|
1506
1516
|
if (computed === null) return;
|
|
1507
1517
|
const artifacts = {
|
|
1508
1518
|
document: computed.document,
|
|
@@ -1523,8 +1533,7 @@ function createProjectArtifacts(options) {
|
|
|
1523
1533
|
if (currentDocuments.length === 0) throw new InternalError("invariant violated: project has no readable configured input — callers must check document artifacts first");
|
|
1524
1534
|
symbolTableResult ??= buildSymbolTable({
|
|
1525
1535
|
documents: currentDocuments,
|
|
1526
|
-
sources
|
|
1527
|
-
pslBlockDescriptors: controlStack.pslBlockDescriptors
|
|
1536
|
+
sources
|
|
1528
1537
|
});
|
|
1529
1538
|
return symbolTableResult;
|
|
1530
1539
|
}
|
|
@@ -2240,7 +2249,6 @@ function createServerOn(connection) {
|
|
|
2240
2249
|
const resolution = await resolveConfigInputs(configPath);
|
|
2241
2250
|
const artifacts = createProjectArtifacts({
|
|
2242
2251
|
inputs: resolution.inputs,
|
|
2243
|
-
controlStack: resolution.controlStack,
|
|
2244
2252
|
getDocument,
|
|
2245
2253
|
onInterpretationError: (uri, error) => {
|
|
2246
2254
|
const detail = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
@@ -2817,4 +2825,4 @@ function startServer(streams) {
|
|
|
2817
2825
|
//#endregion
|
|
2818
2826
|
export { startServer };
|
|
2819
2827
|
|
|
2820
|
-
//# sourceMappingURL=exports-
|
|
2828
|
+
//# sourceMappingURL=exports-DKwrm64h.mjs.map
|