@effect/language-service 0.21.7 → 0.21.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.
Files changed (3) hide show
  1. package/index.js +69 -28
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -3619,41 +3619,82 @@ function dedupeJsDocs(quickInfo2) {
3619
3619
  }
3620
3620
 
3621
3621
  // src/quickinfo/effectTypeArgs.ts
3622
- function formatTypeForQuickInfo(channelType, channelName) {
3623
- return gen2(function* () {
3624
- const ts = yield* service(TypeScriptApi);
3625
- const typeChecker = yield* service(TypeCheckerApi);
3626
- const stringRepresentation = typeChecker.typeToString(
3627
- channelType,
3628
- void 0,
3629
- ts.TypeFormatFlags.NoTruncation
3630
- );
3631
- return `type ${channelName} = ${stringRepresentation}`;
3632
- });
3633
- }
3634
3622
  function effectTypeArgs(sourceFile, position, quickInfo2) {
3635
3623
  return pipe(
3636
3624
  gen2(function* () {
3637
3625
  const ts = yield* service(TypeScriptApi);
3638
3626
  const typeChecker = yield* service(TypeCheckerApi);
3639
3627
  const typeParser = yield* service(TypeParser);
3640
- const maybeNode = pipe(
3641
- yield* getAncestorNodesInRange(sourceFile, toTextRange(position)),
3642
- head
3643
- );
3644
- if (isNone2(maybeNode)) return quickInfo2;
3645
- const node = maybeNode.value;
3646
- const hasTruncationHappened = quickInfo2 && ts.displayPartsToString(quickInfo2.displayParts).indexOf("...") > -1;
3647
- const nodeForType = !quickInfo2 && ts.isYieldExpression(node) && node.asteriskToken && node.expression ? node.expression : hasTruncationHappened ? node : void 0;
3648
- if (!nodeForType) return quickInfo2;
3649
- const effectType = yield* typeParser.effectType(
3650
- typeChecker.getTypeAtLocation(nodeForType),
3651
- nodeForType
3628
+ function formatTypeForQuickInfo(channelType, channelName) {
3629
+ const stringRepresentation = typeChecker.typeToString(
3630
+ channelType,
3631
+ void 0,
3632
+ ts.TypeFormatFlags.NoTruncation
3633
+ );
3634
+ return `type ${channelName} = ${stringRepresentation}`;
3635
+ }
3636
+ function makeSymbolDisplayParts(title, A, E, R) {
3637
+ return [{
3638
+ kind: "text",
3639
+ text: "```ts\n/* " + title + " */\n" + formatTypeForQuickInfo(A, "Success") + "\n" + formatTypeForQuickInfo(E, "Failure") + "\n" + formatTypeForQuickInfo(R, "Requirements") + "\n```\n"
3640
+ }];
3641
+ }
3642
+ function getNodeForQuickInfo(node2) {
3643
+ if (ts.isNewExpression(node2.parent) && node2.pos === node2.parent.pos) {
3644
+ return node2.parent.expression;
3645
+ }
3646
+ if (ts.isNamedTupleMember(node2.parent) && node2.pos === node2.parent.pos) {
3647
+ return node2.parent;
3648
+ }
3649
+ if (ts.isJsxNamespacedName(node2.parent)) {
3650
+ return node2.parent;
3651
+ }
3652
+ return node2;
3653
+ }
3654
+ function getDataForQuickInfo() {
3655
+ if (!("getTouchingPropertyName" in ts && typeof ts.getTouchingPropertyName === "function")) return;
3656
+ const touchingNode = ts.getTouchingPropertyName(sourceFile, position);
3657
+ if (touchingNode === sourceFile) return;
3658
+ const adjustedNode = getNodeForQuickInfo(touchingNode);
3659
+ if (ts.isToken(adjustedNode) && adjustedNode.kind === ts.SyntaxKind.YieldKeyword) {
3660
+ if (ts.isYieldExpression(adjustedNode.parent) && adjustedNode.parent.asteriskToken && adjustedNode.parent.expression) {
3661
+ return {
3662
+ type: typeChecker.getTypeAtLocation(adjustedNode.parent.expression),
3663
+ atLocation: adjustedNode.parent.expression,
3664
+ node: adjustedNode.parent,
3665
+ shouldTry: true
3666
+ };
3667
+ }
3668
+ }
3669
+ return {
3670
+ type: typeChecker.getTypeAtLocation(adjustedNode),
3671
+ atLocation: adjustedNode,
3672
+ node: adjustedNode,
3673
+ shouldTry: quickInfo2 && ts.displayPartsToString(quickInfo2.displayParts).indexOf("...") > -1
3674
+ };
3675
+ }
3676
+ const data = getDataForQuickInfo();
3677
+ if (!(data && data.shouldTry)) return quickInfo2;
3678
+ const { atLocation, node, type } = data;
3679
+ const effectTypeArgsDocumentation = yield* pipe(
3680
+ typeParser.effectType(
3681
+ type,
3682
+ atLocation
3683
+ ),
3684
+ map4((_) => makeSymbolDisplayParts("Effect Type Parameters", _.A, _.E, _.R)),
3685
+ orElse3(() => {
3686
+ const callSignatues = type.getCallSignatures();
3687
+ if (callSignatues.length !== 1) return succeed([]);
3688
+ const returnType = callSignatues[0].getReturnType();
3689
+ return pipe(
3690
+ typeParser.effectType(
3691
+ returnType,
3692
+ atLocation
3693
+ ),
3694
+ map4((_) => makeSymbolDisplayParts("Returned Effect Type Parameters", _.A, _.E, _.R))
3695
+ );
3696
+ })
3652
3697
  );
3653
- const effectTypeArgsDocumentation = [{
3654
- kind: "text",
3655
- text: "```ts\n/* Effect Type Parameters */\n" + (yield* formatTypeForQuickInfo(effectType.A, "Success")) + "\n" + (yield* formatTypeForQuickInfo(effectType.E, "Failure")) + "\n" + (yield* formatTypeForQuickInfo(effectType.R, "Requirements")) + "\n```\n"
3656
- }];
3657
3698
  if (!quickInfo2) {
3658
3699
  const start = node.getStart();
3659
3700
  const end = node.getEnd();