@prisma/orm-toolchain 8.0.0-rc.14-dev.31 → 8.0.0-rc.14-dev.33

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
@@ -6730,7 +6730,7 @@ const lspCommand = defineServerCommand({
6730
6730
  } },
6731
6731
  handler: async (args, io) => {
6732
6732
  const exitCode = await withoutClientProcessIdInArgv(async () => {
6733
- const { startServer } = await import("./exports-C4Peu_9F.mjs");
6733
+ const { startServer } = await import("./exports-BufoY0DR.mjs");
6734
6734
  return startServer({
6735
6735
  stdin: io.stdin,
6736
6736
  stdout: io.stdout,
@@ -1561,6 +1561,83 @@ function compareNames(left, right) {
1561
1561
  if (left > right) return 1;
1562
1562
  return 0;
1563
1563
  }
1564
+ function resolvedNodeAt(token, binder) {
1565
+ const found = token.parent.findAncestor((node) => {
1566
+ const resolution = binder.symbolForNode(node);
1567
+ if (resolution !== void 0) return {
1568
+ node,
1569
+ resolution
1570
+ };
1571
+ return binder.declaredSymbol(node) === void 0 ? void 0 : "declaration";
1572
+ });
1573
+ return found === "declaration" ? void 0 : found;
1574
+ }
1575
+ function provideDefinition(source, position, linkSupport) {
1576
+ const token = tokenAt(source, source.sourceFile.offsetAt(position));
1577
+ const reference = token === void 0 ? void 0 : resolvedNodeAt(token, source.binder);
1578
+ if (reference === void 0) return null;
1579
+ const declarations = declarationsOf(reference.resolution);
1580
+ if (declarations.length === 0) return null;
1581
+ if (declarations.some((declaration) => declaration.name?.syntax === reference.node)) return null;
1582
+ if (!linkSupport) return declarations.map((declaration) => {
1583
+ const target = source.sources.sourceFileFor(declaration.node);
1584
+ return {
1585
+ uri: target.filename,
1586
+ range: rangeOf(target, nameNode(declaration))
1587
+ };
1588
+ });
1589
+ const originSelectionRange = rangeOf(source.sourceFile, reference.node);
1590
+ return declarations.map((declaration) => {
1591
+ const target = source.sources.sourceFileFor(declaration.node);
1592
+ return {
1593
+ originSelectionRange,
1594
+ targetUri: target.filename,
1595
+ targetRange: rangeOf(target, declaration.node),
1596
+ targetSelectionRange: rangeOf(target, nameNode(declaration))
1597
+ };
1598
+ });
1599
+ }
1600
+ function tokenAt(source, offset) {
1601
+ const at = source.document.syntax.tokenAtOffset(offset);
1602
+ const right = at.rightBiased();
1603
+ return right?.kind === "Ident" ? right : at.leftBiased();
1604
+ }
1605
+ function declarationsOf(resolution) {
1606
+ switch (resolution.kind) {
1607
+ case "model":
1608
+ case "compositeType":
1609
+ case "namedType":
1610
+ case "block":
1611
+ case "field": return [declarationOf(resolution.symbol)];
1612
+ case "namespace": return resolution.symbol.declarations.map(({ node }) => ({
1613
+ node: node.syntax,
1614
+ name: node.name()
1615
+ }));
1616
+ case "contributedType":
1617
+ case "contributedNamespace":
1618
+ case "crossSpace":
1619
+ case "attribute":
1620
+ case "parameter":
1621
+ case "function":
1622
+ case "constant":
1623
+ case "unresolved": return [];
1624
+ }
1625
+ }
1626
+ function declarationOf(symbol) {
1627
+ return {
1628
+ node: symbol.node.syntax,
1629
+ name: symbol.node.name()
1630
+ };
1631
+ }
1632
+ function nameNode(declaration) {
1633
+ return declaration.name?.syntax ?? declaration.node;
1634
+ }
1635
+ function rangeOf(sourceFile, node) {
1636
+ return {
1637
+ start: sourceFile.positionAt(node.offset),
1638
+ end: sourceFile.positionAt(node.endOffset)
1639
+ };
1640
+ }
1564
1641
  /**
1565
1642
  * Computes folding ranges for block declarations in a PSL document.
1566
1643
  *
@@ -1790,6 +1867,9 @@ function resolveSignatureParameters(signature, activeName) {
1790
1867
  ...param
1791
1868
  }])];
1792
1869
  }
1870
+ function namedParameterText(key, type) {
1871
+ return `${key}${"optional" in type && type.optional === true ? "?" : ""}: ${type.label}`;
1872
+ }
1793
1873
  function renderSignatureLabel(name, signature, params) {
1794
1874
  let label = `${name}(`;
1795
1875
  const parts = params.map((param, index) => {
@@ -1797,7 +1877,7 @@ function renderSignatureLabel(name, signature, params) {
1797
1877
  const positional = index < (signature.positional?.length ?? 0);
1798
1878
  const optional = "optional" in param.type && param.type.optional === true;
1799
1879
  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}`;
1880
+ const text = positional ? `${typeLabel}${optional ? "?" : ""}` : namedParameterText(param.key, param.type);
1801
1881
  const start = label.length;
1802
1882
  label += text;
1803
1883
  return {
@@ -1864,9 +1944,7 @@ function identTokenAt(root, offset) {
1864
1944
  return right?.kind === "Ident" ? right : void 0;
1865
1945
  }
1866
1946
  function resolveHoverResult(binder, token) {
1867
- return token.parent.findAncestor((node) => narrowHoverResult(binder.symbolForNode(node)));
1868
- }
1869
- function narrowHoverResult(resolution) {
1947
+ const resolution = resolvedNodeAt(token, binder)?.resolution;
1870
1948
  switch (resolution?.kind) {
1871
1949
  case "model":
1872
1950
  case "compositeType":
@@ -1876,6 +1954,10 @@ function narrowHoverResult(resolution) {
1876
1954
  kind: "entity",
1877
1955
  symbol: resolution.symbol
1878
1956
  };
1957
+ case "namespace": return {
1958
+ kind: "namespace",
1959
+ symbol: resolution.symbol
1960
+ };
1879
1961
  case "attribute": return {
1880
1962
  kind: "attribute",
1881
1963
  symbol: resolution.symbol
@@ -1884,13 +1966,29 @@ function narrowHoverResult(resolution) {
1884
1966
  kind: "contributedType",
1885
1967
  symbol: resolution.symbol
1886
1968
  };
1969
+ case "parameter": return {
1970
+ kind: "parameter",
1971
+ symbol: resolution.symbol
1972
+ };
1973
+ case "function": return {
1974
+ kind: "function",
1975
+ symbol: resolution.symbol
1976
+ };
1977
+ case "constant": return {
1978
+ kind: "constant",
1979
+ symbol: resolution.symbol
1980
+ };
1887
1981
  default: return;
1888
1982
  }
1889
1983
  }
1890
1984
  function renderHoverResult(result) {
1891
1985
  if (result.kind === "entity") return renderEntityContent(result.symbol);
1986
+ if (result.kind === "namespace") return renderNamespaceContent(result.symbol);
1892
1987
  if (result.kind === "attribute") return renderAttributeContent(result.symbol);
1893
- return renderContributedTypeContent(result.symbol);
1988
+ if (result.kind === "contributedType") return renderContributedTypeContent(result.symbol);
1989
+ if (result.kind === "parameter") return renderParameterContent(result.symbol);
1990
+ if (result.kind === "function") return renderFunctionContent(result.symbol);
1991
+ return renderConstantContent(result.symbol);
1894
1992
  }
1895
1993
  function renderEntityContent(entity) {
1896
1994
  return withDocumentation([
@@ -1899,6 +1997,13 @@ function renderEntityContent(entity) {
1899
1997
  "```"
1900
1998
  ].join("\n"), entity.node.docComment());
1901
1999
  }
2000
+ function renderNamespaceContent(namespace) {
2001
+ return [
2002
+ "```prisma",
2003
+ `namespace ${namespace.name}`,
2004
+ "```"
2005
+ ].join("\n");
2006
+ }
1902
2007
  function renderAttributeContent(symbol) {
1903
2008
  const name = `${symbol.level === "field" ? "@" : "@@"}${symbol.name}`;
1904
2009
  const params = resolveSignatureParameters(symbol.spec, void 0);
@@ -1916,6 +2021,29 @@ function renderContributedTypeContent(symbol) {
1916
2021
  "```"
1917
2022
  ].join("\n"), symbol.descriptor.kind === "typeConstructor" ? symbol.descriptor.documentation : void 0);
1918
2023
  }
2024
+ function renderParameterContent(symbol) {
2025
+ return withDocumentation([
2026
+ "```prisma",
2027
+ namedParameterText(symbol.name, symbol.param.type),
2028
+ "```"
2029
+ ].join("\n"), symbol.param.documentation);
2030
+ }
2031
+ function renderFunctionContent(symbol) {
2032
+ const params = resolveSignatureParameters(symbol.signature, void 0);
2033
+ const { label } = renderSignatureLabel(symbol.name, symbol.signature, params);
2034
+ return withDocumentation([
2035
+ "```prisma",
2036
+ label,
2037
+ "```"
2038
+ ].join("\n"), symbol.signature.documentation);
2039
+ }
2040
+ function renderConstantContent(symbol) {
2041
+ return withDocumentation([
2042
+ "```prisma",
2043
+ symbol.name,
2044
+ "```"
2045
+ ].join("\n"), symbol.documentation);
2046
+ }
1919
2047
  function withDocumentation(fence, documentation) {
1920
2048
  return documentation === void 0 || documentation === "" ? fence : `${fence}\n\n${documentation}`;
1921
2049
  }
@@ -2354,7 +2482,7 @@ function collectExpression(expression, source, tokens, context = {}) {
2354
2482
  if (expression instanceof FunctionCallAst) {
2355
2483
  const memberPath = expression.memberPath();
2356
2484
  if (memberPath === void 0) collectTypeReference(expression.name(), source, tokens);
2357
- else collectMemberPath(memberPath, tokens);
2485
+ else collectMemberPath(memberPath, source, tokens);
2358
2486
  for (const arg of expression.args()) collectAttributeArg(arg, source, tokens);
2359
2487
  return;
2360
2488
  }
@@ -2371,14 +2499,17 @@ function collectExpression(expression, source, tokens, context = {}) {
2371
2499
  }
2372
2500
  if (expression instanceof TaggedLiteralExprAst) return;
2373
2501
  if (expression instanceof PathExprAst) {
2374
- collectMemberPath(expression, tokens);
2502
+ collectMemberPath(expression, source, tokens);
2375
2503
  return;
2376
2504
  }
2377
2505
  collectIdentifierExpression(expression, source, tokens, context);
2378
2506
  }
2379
2507
  /** A member path such as `address.city` names fields, one per segment. */
2380
- function collectMemberPath(path, tokens) {
2381
- for (const segment of path.segments()) addIdentifier(segment, "property", tokens);
2508
+ function collectMemberPath(path, source, tokens) {
2509
+ for (const segment of path.segments()) {
2510
+ const resolution = source.binder.symbolForNode(segment.syntax);
2511
+ addIdentifier(segment, resolution?.kind === "namespace" || resolution?.kind === "contributedNamespace" ? "namespace" : "property", tokens);
2512
+ }
2382
2513
  }
2383
2514
  function collectIdentifierExpression(identifier, source, tokens, context) {
2384
2515
  if (identifier.name() === void 0) return;
@@ -2400,8 +2531,8 @@ function collectTypeReference(name, source, tokens) {
2400
2531
  const segments = identifierSegments(name);
2401
2532
  if (segments.length === 0) return;
2402
2533
  for (const segment of segments.slice(0, -1)) {
2403
- const qualifier = source.binder.scopeAt(name.syntax).lookup(segment.text);
2404
- if (qualifier !== void 0 && isNamespaceLike(qualifier)) tokens.push(rangeForIdentifier(segment.identifier, "namespace"));
2534
+ const qualifier = source.binder.symbolForNode(segment.identifier.syntax);
2535
+ if (qualifier?.kind === "namespace" || qualifier?.kind === "contributedNamespace") tokens.push(rangeForIdentifier(segment.identifier, "namespace"));
2405
2536
  }
2406
2537
  const finalSegment = segments[segments.length - 1];
2407
2538
  if (finalSegment === void 0) return;
@@ -2588,6 +2719,21 @@ var Project = class {
2588
2719
  return null;
2589
2720
  }
2590
2721
  }
2722
+ async definition(uri, position, linkSupport) {
2723
+ const data = await this.#resolveMember(uri);
2724
+ const document = data?.artifacts.document(uri);
2725
+ if (data === void 0 || document === void 0) return null;
2726
+ try {
2727
+ return provideDefinition({
2728
+ document: document.parse().document,
2729
+ sourceFile: document.sourceFile,
2730
+ sources: data.artifacts.sources,
2731
+ binder: data.artifacts.binder()
2732
+ }, position, linkSupport);
2733
+ } catch {
2734
+ return null;
2735
+ }
2736
+ }
2591
2737
  async foldingRanges(uri) {
2592
2738
  const data = await this.#resolveMember(uri);
2593
2739
  const document = data?.artifacts.document(uri);
@@ -3008,6 +3154,10 @@ function createServerOn(connection) {
3008
3154
  if (getOpenDocument(uri) === void 0) return null;
3009
3155
  return (await projects.nearestProject(uri))?.hover(uri, position) ?? null;
3010
3156
  }
3157
+ async function definitionForDocument(uri, position) {
3158
+ if (getOpenDocument(uri) === void 0) return null;
3159
+ return (await projects.nearestProject(uri))?.definition(uri, position, clientCapabilities.definitionLinks) ?? null;
3160
+ }
3011
3161
  connection.onInitialize(async (params) => {
3012
3162
  rootPath = resolveRootPath(params);
3013
3163
  clientCapabilities = resolveClientCapabilities(params);
@@ -3035,6 +3185,7 @@ function createServerOn(connection) {
3035
3185
  ] },
3036
3186
  signatureHelpProvider: { triggerCharacters: ["(", ","] },
3037
3187
  hoverProvider: true,
3188
+ definitionProvider: true,
3038
3189
  ...clientCapabilities.pullDiagnostics ? { diagnosticProvider: {
3039
3190
  interFileDependencies: true,
3040
3191
  workspaceDiagnostics: false
@@ -3046,6 +3197,7 @@ function createServerOn(connection) {
3046
3197
  connection.onDocumentFormatting((params) => formatDocument(params.textDocument.uri));
3047
3198
  connection.onCompletion((params) => completeDocument(params.textDocument.uri, params.position));
3048
3199
  connection.onSignatureHelp((params) => signatureHelpForDocument(params.textDocument.uri, params.position));
3200
+ connection.onDefinition((params) => definitionForDocument(params.textDocument.uri, params.position));
3049
3201
  connection.onHover((params) => hoverForDocument(params.textDocument.uri, params.position));
3050
3202
  connection.languages.semanticTokens.on((params) => semanticTokensForDocument(params.textDocument.uri));
3051
3203
  connection.languages.semanticTokens.onRange((params) => semanticTokensForDocument(params.textDocument.uri, params.range));
@@ -3099,6 +3251,7 @@ const noClientCapabilities = {
3099
3251
  watchedFilesRegistration: false,
3100
3252
  completionSnippets: false,
3101
3253
  signatureLabelOffsets: false,
3254
+ definitionLinks: false,
3102
3255
  completionTriggerSuggestCommand: false,
3103
3256
  completionTriggerParameterHintsCommand: false,
3104
3257
  pullDiagnostics: false,
@@ -3109,6 +3262,7 @@ function resolveClientCapabilities(params) {
3109
3262
  watchedFilesRegistration: params.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration === true,
3110
3263
  completionSnippets: params.capabilities.textDocument?.completion?.completionItem?.snippetSupport === true,
3111
3264
  signatureLabelOffsets: params.capabilities.textDocument?.signatureHelp?.signatureInformation?.parameterInformation?.labelOffsetSupport === true,
3265
+ definitionLinks: params.capabilities.textDocument?.definition?.linkSupport === true,
3112
3266
  completionTriggerSuggestCommand: supportsCompletionCommand(params.initializationOptions, "supportsTriggerSuggestCommand"),
3113
3267
  completionTriggerParameterHintsCommand: supportsCompletionCommand(params.initializationOptions, "supportsTriggerParameterHintsCommand"),
3114
3268
  pullDiagnostics: params.capabilities.textDocument?.diagnostic?.relatedDocumentSupport === true,
@@ -3372,4 +3526,4 @@ function startServer(streams) {
3372
3526
  //#endregion
3373
3527
  export { startServer };
3374
3528
 
3375
- //# sourceMappingURL=exports-C4Peu_9F.mjs.map
3529
+ //# sourceMappingURL=exports-BufoY0DR.mjs.map