@effect/language-service 0.25.1 → 0.26.0

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/index.js CHANGED
@@ -2674,11 +2674,16 @@ function make3(ts, typeChecker) {
2674
2674
  const pipeCall = cachedBy(
2675
2675
  function(node) {
2676
2676
  if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && node.expression.name.text === "pipe") {
2677
- return succeed({ node, subject: node.expression.expression, args: Array.from(node.arguments) });
2677
+ return succeed({
2678
+ node,
2679
+ subject: node.expression.expression,
2680
+ args: Array.from(node.arguments),
2681
+ kind: "pipeable"
2682
+ });
2678
2683
  }
2679
2684
  if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "pipe" && node.arguments.length > 0) {
2680
2685
  const [subject, ...args2] = node.arguments;
2681
- return succeed({ node, subject, args: args2 });
2686
+ return succeed({ node, subject, args: args2, kind: "pipe" });
2682
2687
  }
2683
2688
  return typeParserIssue("Node is not a pipe call", void 0, node);
2684
2689
  },
@@ -2717,6 +2722,7 @@ function make3(ts, typeChecker) {
2717
2722
  unnecessaryEffectGen: unnecessaryEffectGen2,
2718
2723
  effectSchemaType,
2719
2724
  contextTag,
2725
+ pipeableType,
2720
2726
  pipeCall,
2721
2727
  scopeType
2722
2728
  };
@@ -3605,7 +3611,7 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
3605
3611
  // src/diagnostics/tryCatchInEffectGen.ts
3606
3612
  var tryCatchInEffectGen = createDiagnostic({
3607
3613
  name: "tryCatchInEffectGen",
3608
- code: 12,
3614
+ code: 15,
3609
3615
  severity: "suggestion",
3610
3616
  apply: fn("tryCatchInEffectGen.apply")(function* (sourceFile, report) {
3611
3617
  const ts = yield* service(TypeScriptApi);
@@ -3735,6 +3741,80 @@ var unnecessaryPipe = createDiagnostic({
3735
3741
  })
3736
3742
  });
3737
3743
 
3744
+ // src/diagnostics/unnecessaryPipeChain.ts
3745
+ var unnecessaryPipeChain = createDiagnostic({
3746
+ name: "unnecessaryPipeChain",
3747
+ code: 16,
3748
+ severity: "suggestion",
3749
+ apply: fn("unnecessaryPipeChain.apply")(function* (sourceFile, report) {
3750
+ const ts = yield* service(TypeScriptApi);
3751
+ const typeParser = yield* service(TypeParser);
3752
+ const nodeToVisit = [];
3753
+ const appendNodeToVisit = (node) => {
3754
+ nodeToVisit.push(node);
3755
+ return void 0;
3756
+ };
3757
+ ts.forEachChild(sourceFile, appendNodeToVisit);
3758
+ while (nodeToVisit.length > 0) {
3759
+ const node = nodeToVisit.shift();
3760
+ ts.forEachChild(node, appendNodeToVisit);
3761
+ if (ts.isCallExpression(node)) {
3762
+ yield* pipe(
3763
+ typeParser.pipeCall(node),
3764
+ flatMap2(
3765
+ (pipeCall) => map4(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))
3766
+ ),
3767
+ map4(({ innerCall, pipeCall }) => {
3768
+ report({
3769
+ node,
3770
+ messageText: `Chained pipe calls can be simplified to a single pipe call`,
3771
+ fixes: [{
3772
+ fixName: "unnecessaryPipeChain_fix",
3773
+ description: "Rewrite as single pipe call",
3774
+ apply: gen(function* () {
3775
+ const changeTracker = yield* service(
3776
+ ChangeTracker
3777
+ );
3778
+ switch (innerCall.kind) {
3779
+ case "pipe": {
3780
+ changeTracker.replaceNode(
3781
+ sourceFile,
3782
+ node,
3783
+ ts.factory.createCallExpression(
3784
+ ts.factory.createIdentifier("pipe"),
3785
+ void 0,
3786
+ [innerCall.subject, ...innerCall.args, ...pipeCall.args]
3787
+ )
3788
+ );
3789
+ break;
3790
+ }
3791
+ case "pipeable": {
3792
+ changeTracker.replaceNode(
3793
+ sourceFile,
3794
+ node,
3795
+ ts.factory.createCallExpression(
3796
+ ts.factory.createPropertyAccessExpression(
3797
+ innerCall.subject,
3798
+ "pipe"
3799
+ ),
3800
+ void 0,
3801
+ [...innerCall.args, ...pipeCall.args]
3802
+ )
3803
+ );
3804
+ break;
3805
+ }
3806
+ }
3807
+ })
3808
+ }]
3809
+ });
3810
+ }),
3811
+ ignore
3812
+ );
3813
+ }
3814
+ }
3815
+ })
3816
+ });
3817
+
3738
3818
  // src/diagnostics.ts
3739
3819
  var diagnostics = [
3740
3820
  duplicatePackage,
@@ -3751,7 +3831,8 @@ var diagnostics = [
3751
3831
  tryCatchInEffectGen,
3752
3832
  importFromBarrel,
3753
3833
  scopeInLayerEffect,
3754
- effectInVoidSuccess
3834
+ effectInVoidSuccess,
3835
+ unnecessaryPipeChain
3755
3836
  ];
3756
3837
 
3757
3838
  // src/completions/effectDiagnosticsComment.ts
@@ -9928,6 +10009,66 @@ var toggleLazyConst = createRefactor({
9928
10009
  })
9929
10010
  });
9930
10011
 
10012
+ // src/refactors/togglePipeStyle.ts
10013
+ var togglePipeStyle = createRefactor({
10014
+ name: "togglePipeStyle",
10015
+ description: "Toggle pipe style",
10016
+ apply: fn("togglePipeStyle.apply")(function* (sourceFile, textRange) {
10017
+ const ts = yield* service(TypeScriptApi);
10018
+ const typeChecker = yield* service(TypeCheckerApi);
10019
+ const typeParser = yield* service(TypeParser);
10020
+ const togglePipeStyle2 = (node) => gen(function* () {
10021
+ const pipeCall = yield* typeParser.pipeCall(node);
10022
+ switch (pipeCall.kind) {
10023
+ case "pipe": {
10024
+ yield* typeParser.pipeableType(typeChecker.getTypeAtLocation(pipeCall.subject), pipeCall.subject);
10025
+ return {
10026
+ kind: "refactor.rewrite.effect.togglePipeStyle",
10027
+ description: "Rewrite as X.pipe(Y, Z, ...)",
10028
+ apply: gen(function* () {
10029
+ const changeTracker = yield* service(ChangeTracker);
10030
+ changeTracker.replaceNode(
10031
+ sourceFile,
10032
+ node,
10033
+ ts.factory.createCallExpression(
10034
+ ts.factory.createPropertyAccessExpression(
10035
+ pipeCall.subject,
10036
+ "pipe"
10037
+ ),
10038
+ void 0,
10039
+ pipeCall.args
10040
+ )
10041
+ );
10042
+ })
10043
+ };
10044
+ }
10045
+ case "pipeable":
10046
+ return {
10047
+ kind: "refactor.rewrite.effect.togglePipeStyle",
10048
+ description: "Rewrite as pipe(X, Y, Z, ...)",
10049
+ apply: gen(function* () {
10050
+ const changeTracker = yield* service(ChangeTracker);
10051
+ changeTracker.replaceNode(
10052
+ sourceFile,
10053
+ node,
10054
+ ts.factory.createCallExpression(
10055
+ ts.factory.createIdentifier("pipe"),
10056
+ void 0,
10057
+ [pipeCall.subject].concat(pipeCall.args)
10058
+ )
10059
+ );
10060
+ })
10061
+ };
10062
+ }
10063
+ });
10064
+ const ancestorNodes = yield* getAncestorNodesInRange(sourceFile, textRange);
10065
+ return yield* pipe(
10066
+ firstSuccessOf(ancestorNodes.map(togglePipeStyle2)),
10067
+ orElse2(() => fail(new RefactorNotApplicableError()))
10068
+ );
10069
+ })
10070
+ });
10071
+
9931
10072
  // src/refactors/toggleReturnTypeAnnotation.ts
9932
10073
  var toggleReturnTypeAnnotation = createRefactor({
9933
10074
  name: "toggleReturnTypeAnnotation",
@@ -10644,7 +10785,8 @@ var refactors = [
10644
10785
  toggleTypeAnnotation,
10645
10786
  wrapWithEffectGen,
10646
10787
  wrapWithPipe,
10647
- effectGenToFn
10788
+ effectGenToFn,
10789
+ togglePipeStyle
10648
10790
  ];
10649
10791
 
10650
10792
  // src/index.ts