@prisma/orm-toolchain 8.0.0-rc.21-dev.6 → 8.0.0-rc.21-dev.8
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.
|
@@ -12,12 +12,12 @@ import { EMPTY_GENERATOR_FUNCTIONS } from "@prisma/orm-framework/components/comp
|
|
|
12
12
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
13
13
|
import { normalize as normalize$1 } from "node:path";
|
|
14
14
|
import { format, resolveFormatOptions } from "@prisma/orm-framework/psl-parser/format";
|
|
15
|
-
import { EMPTY_DATA_TYPES, assembleAttributeSpecs, blockSpecContext, blockSpecFactoryOf, buildSymbolTable, contributedTypeOf, createBinder, entityReference, findBlockDescriptor, groupedTypeLabel, isNamespaceLike, isPrismaNextSchema, isPslIdentifier, matchesSelector, memberEntries, renameLegacyDirective, typeReferenceNode } from "@prisma/orm-framework/psl-parser";
|
|
15
|
+
import { EMPTY_DATA_TYPES, assembleAttributeSpecs, blockSpecContext, blockSpecFactoryOf, buildSymbolTable, chosenTypeConstructor, contributedTypeOf, createBinder, entityReference, findBlockDescriptor, groupedTypeLabel, isContributedTypeChoice, isNamespaceLike, isPrismaNextSchema, isPslIdentifier, matchesSelector, memberEntries, printTypeConstructorCall, readResolvedConstructorCall, renameLegacyDirective, typeReferenceNode } from "@prisma/orm-framework/psl-parser";
|
|
16
16
|
import { CompletionItemKind, CompletionItemTag, ConnectionError, ConnectionErrors, DiagnosticSeverity, DidChangeWatchedFilesNotification, DocumentDiagnosticReportKind, FoldingRangeKind, InsertTextFormat, LSPErrorCodes, MarkupKind, ProposedFeatures, RegistrationRequest, ResponseError, SemanticTokenModifiers, SemanticTokenTypes, TextDocumentSyncKind, UnregistrationRequest, createConnection } from "vscode-languageserver";
|
|
17
17
|
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
18
|
-
import { ArrayLiteralAst, AttributeArgAst, AttributeArgListAst, BooleanLiteralExprAst, CompositeTypeDeclarationAst, FieldAttributeAst, FieldDeclarationAst, FunctionCallAst, GenericBlockDeclarationAst, IdentifierAst, KeyValuePairAst, MixinDeclarationAst, MixinInclusionAst, ModelAttributeAst, ModelDeclarationAst, NamespaceDeclarationAst, NumberLiteralExprAst, ObjectLiteralExprAst, PathExprAst, PslSources, StringLiteralExprAst, SyntaxNode, SyntaxToken, TaggedLiteralExprAst, TypesBlockAst, any, filterChildren, isTrivia, nonTriviaSibling, parse, skipTriviaToken } from "@prisma/orm-framework/psl-parser/syntax";
|
|
18
|
+
import { ArrayLiteralAst, AttributeArgAst, AttributeArgListAst, BooleanLiteralExprAst, CompositeTypeDeclarationAst, FieldAttributeAst, FieldDeclarationAst, FunctionCallAst, GenericBlockDeclarationAst, IdentifierAst, KeyValuePairAst, MixinDeclarationAst, MixinInclusionAst, ModelAttributeAst, ModelDeclarationAst, NamespaceDeclarationAst, NumberLiteralExprAst, ObjectLiteralExprAst, PathExprAst, PslSources, StringLiteralExprAst, SyntaxNode, SyntaxToken, TaggedLiteralExprAst, TypeAnnotationAst, TypesBlockAst, any, filterChildren, isTrivia, nonTriviaSibling, parse, skipTriviaToken } from "@prisma/orm-framework/psl-parser/syntax";
|
|
19
19
|
import { hasPslInterpreter } from "@prisma/orm-framework/psl-parser/interpret";
|
|
20
|
-
import { admittedTags, describeAdmittedForms, isAuthoringPslBlockDescriptor } from "@prisma/orm-framework/components/authoring";
|
|
20
|
+
import { admittedTags, describeAdmittedForms, isAuthoringPslBlockDescriptor, isAuthoringTypeChoiceOption, writtenTypeConstructorCall } from "@prisma/orm-framework/components/authoring";
|
|
21
21
|
import { dataTypeId } from "@prisma/orm-framework/components/codec";
|
|
22
22
|
import { ProposedFeatures as ProposedFeatures$1, StreamMessageReader, StreamMessageWriter, createConnection as createConnection$1, createProtocolConnection } from "vscode-languageserver/node";
|
|
23
23
|
import { Console } from "node:console";
|
|
@@ -458,12 +458,12 @@ function attributeSpecResolver(context, source) {
|
|
|
458
458
|
};
|
|
459
459
|
const node = typeReferenceNode(field);
|
|
460
460
|
const typeResolution = node === void 0 ? void 0 : source.binder.symbolForNode(node);
|
|
461
|
-
const
|
|
461
|
+
const contributedType = contributedTypeOf(typeResolution, source.binder, field.typeConstructor);
|
|
462
462
|
return (name) => specs.field[name]?.({
|
|
463
463
|
...specContext,
|
|
464
464
|
field,
|
|
465
465
|
typeResolution,
|
|
466
|
-
|
|
466
|
+
contributedType
|
|
467
467
|
});
|
|
468
468
|
}
|
|
469
469
|
}
|
|
@@ -1154,9 +1154,9 @@ function scopeCompletionItems(entries, binder, dataTypes, range, capabilities, s
|
|
|
1154
1154
|
break;
|
|
1155
1155
|
case "contributedType": {
|
|
1156
1156
|
const descriptor = resolution.symbol.descriptor;
|
|
1157
|
-
if (descriptor.kind === "typeAlias") {
|
|
1157
|
+
if (descriptor.kind === "typeAlias" || descriptor.kind === "typeChoice") {
|
|
1158
1158
|
item.kind = CompletionItemKind.Class;
|
|
1159
|
-
item.detail = descriptor.documentation || "Type alias";
|
|
1159
|
+
item.detail = descriptor.documentation || (descriptor.kind === "typeAlias" ? "Type alias" : "Convenience type");
|
|
1160
1160
|
break;
|
|
1161
1161
|
}
|
|
1162
1162
|
const callable = descriptor.args !== void 0 || descriptor.entityRefArg !== void 0;
|
|
@@ -2089,7 +2089,7 @@ function providePslHover(input) {
|
|
|
2089
2089
|
}
|
|
2090
2090
|
function hoverValueAt(input, token) {
|
|
2091
2091
|
const result = resolveHoverResult(input.binder, token);
|
|
2092
|
-
if (result !== void 0) return renderHoverResult(result, input
|
|
2092
|
+
if (result !== void 0) return renderHoverResult(result, input);
|
|
2093
2093
|
return blockKeywordDocumentationAt(token, input.pslBlockDescriptors);
|
|
2094
2094
|
}
|
|
2095
2095
|
function resolveHoverResult(binder, token) {
|
|
@@ -2114,7 +2114,8 @@ function resolveHoverResult(binder, token) {
|
|
|
2114
2114
|
};
|
|
2115
2115
|
case "contributedType": return {
|
|
2116
2116
|
kind: "contributedType",
|
|
2117
|
-
symbol: resolution.symbol
|
|
2117
|
+
symbol: resolution.symbol,
|
|
2118
|
+
annotation: token.parent.findAncestor(TypeAnnotationAst.cast)
|
|
2118
2119
|
};
|
|
2119
2120
|
case "parameter": return {
|
|
2120
2121
|
kind: "parameter",
|
|
@@ -2131,11 +2132,11 @@ function resolveHoverResult(binder, token) {
|
|
|
2131
2132
|
default: return;
|
|
2132
2133
|
}
|
|
2133
2134
|
}
|
|
2134
|
-
function renderHoverResult(result,
|
|
2135
|
+
function renderHoverResult(result, input) {
|
|
2135
2136
|
if (result.kind === "entity") return renderEntityContent(result.symbol);
|
|
2136
2137
|
if (result.kind === "namespace") return renderNamespaceContent(result.symbol);
|
|
2137
2138
|
if (result.kind === "attribute") return renderAttributeContent(result.symbol);
|
|
2138
|
-
if (result.kind === "contributedType") return renderContributedTypeContent(result
|
|
2139
|
+
if (result.kind === "contributedType") return renderContributedTypeContent(result, input);
|
|
2139
2140
|
if (result.kind === "parameter") return renderParameterContent(result.symbol);
|
|
2140
2141
|
if (result.kind === "function") return renderFunctionContent(result.symbol);
|
|
2141
2142
|
return renderConstantContent(result.symbol);
|
|
@@ -2164,12 +2165,52 @@ function renderAttributeContent(symbol) {
|
|
|
2164
2165
|
"```"
|
|
2165
2166
|
].join("\n"), symbol.spec.documentation);
|
|
2166
2167
|
}
|
|
2167
|
-
function renderContributedTypeContent(
|
|
2168
|
-
|
|
2168
|
+
function renderContributedTypeContent(result, input) {
|
|
2169
|
+
const { symbol } = result;
|
|
2170
|
+
const fence = [
|
|
2169
2171
|
"```prisma",
|
|
2170
|
-
renderContributedTypeLabel(symbol, dataTypes),
|
|
2172
|
+
renderContributedTypeLabel(symbol, input.dataTypes),
|
|
2171
2173
|
"```"
|
|
2172
|
-
].join("\n")
|
|
2174
|
+
].join("\n");
|
|
2175
|
+
if (!isContributedTypeChoice(symbol)) return withDocumentation(fence, symbol.descriptor.documentation);
|
|
2176
|
+
const chosen = renderChosenType(symbol, result.annotation, input);
|
|
2177
|
+
return `${withDocumentation(chosen === void 0 ? fence : `${fence}\n\n${chosen}`, symbol.descriptor.documentation)}\n\n${renderTypeChoices(symbol, input.dataTypes)}`;
|
|
2178
|
+
}
|
|
2179
|
+
/** The explicit type `type`, at the level of the type choice `symbol`, called with `args` as the tools write it; `undefined` when the type choice names no such type or an argument has no literal. */
|
|
2180
|
+
function writtenChosenType(symbol, type, args, dataTypes) {
|
|
2181
|
+
const descriptor = symbol.choiceTypes.get(type);
|
|
2182
|
+
return descriptor && writtenTypeConstructorCall([...symbol.path.slice(0, -1), type], descriptor, args, dataTypes);
|
|
2183
|
+
}
|
|
2184
|
+
/** The explicit type the call at `annotation` becomes, or `undefined` when its arguments choose none or it cannot be written. */
|
|
2185
|
+
function renderChosenType(symbol, annotation, input) {
|
|
2186
|
+
const call = readResolvedConstructorCall(annotation, input.sources);
|
|
2187
|
+
const chosen = chosenTypeConstructor(symbol, call, input.dataTypes);
|
|
2188
|
+
const written = chosen.ok && writtenChosenType(symbol, chosen.value.type, chosen.value.args, input.dataTypes);
|
|
2189
|
+
if (written === false || written === void 0) return void 0;
|
|
2190
|
+
return `${inlineCode(call === void 0 ? symbol.path.join(".") : printTypeConstructorCall(call))} is exactly ${inlineCode(written)}.`;
|
|
2191
|
+
}
|
|
2192
|
+
/** Each combination of a type choice's options, as written, and the explicit type it becomes. */
|
|
2193
|
+
function renderTypeChoices(symbol, dataTypes) {
|
|
2194
|
+
const { descriptor } = symbol;
|
|
2195
|
+
const options = descriptor.args.filter(isAuthoringTypeChoiceOption);
|
|
2196
|
+
const cell = (value, option) => value === option.default ? `${value} (default)` : value ?? "";
|
|
2197
|
+
const becomes = (row) => {
|
|
2198
|
+
const defaults = row.defaults ?? {};
|
|
2199
|
+
const args = (symbol.choiceTypes.get(row.type)?.args ?? []).map((argument) => argument.name !== void 0 && Object.hasOwn(defaults, argument.name) ? defaults[argument.name] : void 0);
|
|
2200
|
+
return inlineCode(writtenChosenType(symbol, row.type, args, dataTypes) ?? `${[...symbol.path.slice(0, -1), row.type].join(".")}(...)`);
|
|
2201
|
+
};
|
|
2202
|
+
return [
|
|
2203
|
+
`| ${[...options.map((option) => option.name), "Becomes"].join(" | ")} |`,
|
|
2204
|
+
`| ${[...options, void 0].map(() => "---").join(" | ")} |`,
|
|
2205
|
+
...descriptor.choices.map((row) => `| ${[...options.map((option) => cell(row.when[option.name], option)), becomes(row)].join(" | ")} |`)
|
|
2206
|
+
].join("\n");
|
|
2207
|
+
}
|
|
2208
|
+
/** `text` as a Markdown code span, fenced by more backticks than any run inside it. */
|
|
2209
|
+
function inlineCode(text) {
|
|
2210
|
+
const longestRun = Math.max(0, ...(text.match(/`+/g) ?? []).map((run) => run.length));
|
|
2211
|
+
const fence = "`".repeat(longestRun + 1);
|
|
2212
|
+
const padding = text.startsWith("`") || text.endsWith("`") || longestRun > 0 ? " " : "";
|
|
2213
|
+
return `${fence}${padding}${text}${padding}${fence}`;
|
|
2173
2214
|
}
|
|
2174
2215
|
function renderParameterContent(symbol) {
|
|
2175
2216
|
return withDocumentation([
|
|
@@ -2203,9 +2244,12 @@ function renderContributedTypeLabel(symbol, dataTypes) {
|
|
|
2203
2244
|
const args = descriptor.kind === "typeAlias" ? [] : descriptor.args ?? [];
|
|
2204
2245
|
if (args.length === 0) return path;
|
|
2205
2246
|
return `${path}(${args.map((arg, index) => {
|
|
2206
|
-
return `${arg.name ?? `arg${index + 1}`}${arg.optional === true ? "?" : ""}: ${
|
|
2247
|
+
return `${arg.name ?? `arg${index + 1}`}${arg.optional === true ? "?" : ""}: ${argumentTypeLabel(arg, dataTypes)}`;
|
|
2207
2248
|
}).join(", ")})`;
|
|
2208
2249
|
}
|
|
2250
|
+
function argumentTypeLabel(arg, dataTypes) {
|
|
2251
|
+
return arg.kind === "value" ? describeAdmittedForms(dataTypes, dataTypeId(arg.dataType)) : arg.values.join(" | ");
|
|
2252
|
+
}
|
|
2209
2253
|
function blockKeywordDocumentationAt(token, pslBlockDescriptors) {
|
|
2210
2254
|
const declaration = GenericBlockDeclarationAst.cast(token.parent) ?? MixinDeclarationAst.cast(token.parent);
|
|
2211
2255
|
if (declaration === void 0 || declaration.keyword()?.offset !== token.offset) return void 0;
|
|
@@ -3049,7 +3093,8 @@ var Project = class {
|
|
|
3049
3093
|
position,
|
|
3050
3094
|
binder: data.artifacts.binder(),
|
|
3051
3095
|
pslBlockDescriptors: data.controlStack.pslBlockDescriptors,
|
|
3052
|
-
dataTypes: data.controlStack.dataTypes ?? EMPTY_DATA_TYPES
|
|
3096
|
+
dataTypes: data.controlStack.dataTypes ?? EMPTY_DATA_TYPES,
|
|
3097
|
+
sources: data.artifacts.sources
|
|
3053
3098
|
});
|
|
3054
3099
|
} catch {
|
|
3055
3100
|
return null;
|
|
@@ -3964,4 +4009,4 @@ function startServer(streams) {
|
|
|
3964
4009
|
//#endregion
|
|
3965
4010
|
export { startServer };
|
|
3966
4011
|
|
|
3967
|
-
//# sourceMappingURL=exports-
|
|
4012
|
+
//# sourceMappingURL=exports-Byp-xgRY.mjs.map
|