@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/README.md +5 -2
- package/cli.js +85 -4
- package/cli.js.map +1 -1
- package/index.js +147 -5
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +85 -4
- package/transform.js.map +1 -1
package/README.md
CHANGED
|
@@ -47,6 +47,7 @@ And you're done! You'll now be able to use a set of refactors and diagnostics th
|
|
|
47
47
|
- Unnecessary usages of `Effect.gen` or `pipe()`
|
|
48
48
|
- Warn when importing from a barrel file instead of from the module directly
|
|
49
49
|
- Warn on usage of try/catch inside `Effect.gen` and family
|
|
50
|
+
- Detect unnecessary pipe chains like `X.pipe(Y).pipe(Z)`
|
|
50
51
|
|
|
51
52
|
### Completions
|
|
52
53
|
|
|
@@ -67,6 +68,7 @@ And you're done! You'll now be able to use a set of refactors and diagnostics th
|
|
|
67
68
|
- Toggle return type signature: With a single refactor, adds or removes type annotations from the definition.
|
|
68
69
|
- Remove unnecessary `Effect.gen` definitions that contains a single `yield` statement.
|
|
69
70
|
- Wrap an `Effect` expression with `Effect.gen`
|
|
71
|
+
- Toggle between pipe styles `X.pipe(Y)` and `pipe(X, Y)`
|
|
70
72
|
|
|
71
73
|
### Miscellaneous
|
|
72
74
|
- "Go to definition" for RpcClient will resolve to the Rpc definition
|
|
@@ -119,8 +121,9 @@ Your `tsconfig.json` should look like this:
|
|
|
119
121
|
|
|
120
122
|
To get diagnostics you need to install `ts-patch` which will make it possible to run `tspc`.
|
|
121
123
|
|
|
122
|
-
Running `tspc` in your project will now also run the plugin and give you the diagnostics at compile time.
|
|
123
|
-
Effect diagnostics will be shown only after standard TypeScript diagnostics have been satisfied.
|
|
124
|
+
Running `tspc` in your project will now also run the plugin and give you the error diagnostics at compile time.
|
|
125
|
+
Effect error diagnostics will be shown only after standard TypeScript diagnostics have been satisfied.
|
|
126
|
+
Beware that setting noEmit will completely skip the effect diagnostics.
|
|
124
127
|
|
|
125
128
|
```ts
|
|
126
129
|
$ npx tspc
|
package/cli.js
CHANGED
|
@@ -31428,11 +31428,16 @@ function make62(ts2, typeChecker) {
|
|
|
31428
31428
|
const pipeCall = cachedBy(
|
|
31429
31429
|
function(node) {
|
|
31430
31430
|
if (ts2.isCallExpression(node) && ts2.isPropertyAccessExpression(node.expression) && ts2.isIdentifier(node.expression.name) && node.expression.name.text === "pipe") {
|
|
31431
|
-
return succeed17({
|
|
31431
|
+
return succeed17({
|
|
31432
|
+
node,
|
|
31433
|
+
subject: node.expression.expression,
|
|
31434
|
+
args: Array.from(node.arguments),
|
|
31435
|
+
kind: "pipeable"
|
|
31436
|
+
});
|
|
31432
31437
|
}
|
|
31433
31438
|
if (ts2.isCallExpression(node) && ts2.isIdentifier(node.expression) && node.expression.text === "pipe" && node.arguments.length > 0) {
|
|
31434
31439
|
const [subject, ...args3] = node.arguments;
|
|
31435
|
-
return succeed17({ node, subject, args: args3 });
|
|
31440
|
+
return succeed17({ node, subject, args: args3, kind: "pipe" });
|
|
31436
31441
|
}
|
|
31437
31442
|
return typeParserIssue("Node is not a pipe call", void 0, node);
|
|
31438
31443
|
},
|
|
@@ -31471,6 +31476,7 @@ function make62(ts2, typeChecker) {
|
|
|
31471
31476
|
unnecessaryEffectGen: unnecessaryEffectGen2,
|
|
31472
31477
|
effectSchemaType,
|
|
31473
31478
|
contextTag,
|
|
31479
|
+
pipeableType,
|
|
31474
31480
|
pipeCall,
|
|
31475
31481
|
scopeType
|
|
31476
31482
|
};
|
|
@@ -32407,7 +32413,7 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
|
|
|
32407
32413
|
// src/diagnostics/tryCatchInEffectGen.ts
|
|
32408
32414
|
var tryCatchInEffectGen = createDiagnostic({
|
|
32409
32415
|
name: "tryCatchInEffectGen",
|
|
32410
|
-
code:
|
|
32416
|
+
code: 15,
|
|
32411
32417
|
severity: "suggestion",
|
|
32412
32418
|
apply: fn("tryCatchInEffectGen.apply")(function* (sourceFile, report) {
|
|
32413
32419
|
const ts2 = yield* service2(TypeScriptApi);
|
|
@@ -32537,6 +32543,80 @@ var unnecessaryPipe = createDiagnostic({
|
|
|
32537
32543
|
})
|
|
32538
32544
|
});
|
|
32539
32545
|
|
|
32546
|
+
// src/diagnostics/unnecessaryPipeChain.ts
|
|
32547
|
+
var unnecessaryPipeChain = createDiagnostic({
|
|
32548
|
+
name: "unnecessaryPipeChain",
|
|
32549
|
+
code: 16,
|
|
32550
|
+
severity: "suggestion",
|
|
32551
|
+
apply: fn("unnecessaryPipeChain.apply")(function* (sourceFile, report) {
|
|
32552
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
32553
|
+
const typeParser = yield* service2(TypeParser);
|
|
32554
|
+
const nodeToVisit = [];
|
|
32555
|
+
const appendNodeToVisit = (node) => {
|
|
32556
|
+
nodeToVisit.push(node);
|
|
32557
|
+
return void 0;
|
|
32558
|
+
};
|
|
32559
|
+
ts2.forEachChild(sourceFile, appendNodeToVisit);
|
|
32560
|
+
while (nodeToVisit.length > 0) {
|
|
32561
|
+
const node = nodeToVisit.shift();
|
|
32562
|
+
ts2.forEachChild(node, appendNodeToVisit);
|
|
32563
|
+
if (ts2.isCallExpression(node)) {
|
|
32564
|
+
yield* pipe(
|
|
32565
|
+
typeParser.pipeCall(node),
|
|
32566
|
+
flatMap18(
|
|
32567
|
+
(pipeCall) => map33(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))
|
|
32568
|
+
),
|
|
32569
|
+
map33(({ innerCall, pipeCall }) => {
|
|
32570
|
+
report({
|
|
32571
|
+
node,
|
|
32572
|
+
messageText: `Chained pipe calls can be simplified to a single pipe call`,
|
|
32573
|
+
fixes: [{
|
|
32574
|
+
fixName: "unnecessaryPipeChain_fix",
|
|
32575
|
+
description: "Rewrite as single pipe call",
|
|
32576
|
+
apply: gen3(function* () {
|
|
32577
|
+
const changeTracker = yield* service2(
|
|
32578
|
+
ChangeTracker
|
|
32579
|
+
);
|
|
32580
|
+
switch (innerCall.kind) {
|
|
32581
|
+
case "pipe": {
|
|
32582
|
+
changeTracker.replaceNode(
|
|
32583
|
+
sourceFile,
|
|
32584
|
+
node,
|
|
32585
|
+
ts2.factory.createCallExpression(
|
|
32586
|
+
ts2.factory.createIdentifier("pipe"),
|
|
32587
|
+
void 0,
|
|
32588
|
+
[innerCall.subject, ...innerCall.args, ...pipeCall.args]
|
|
32589
|
+
)
|
|
32590
|
+
);
|
|
32591
|
+
break;
|
|
32592
|
+
}
|
|
32593
|
+
case "pipeable": {
|
|
32594
|
+
changeTracker.replaceNode(
|
|
32595
|
+
sourceFile,
|
|
32596
|
+
node,
|
|
32597
|
+
ts2.factory.createCallExpression(
|
|
32598
|
+
ts2.factory.createPropertyAccessExpression(
|
|
32599
|
+
innerCall.subject,
|
|
32600
|
+
"pipe"
|
|
32601
|
+
),
|
|
32602
|
+
void 0,
|
|
32603
|
+
[...innerCall.args, ...pipeCall.args]
|
|
32604
|
+
)
|
|
32605
|
+
);
|
|
32606
|
+
break;
|
|
32607
|
+
}
|
|
32608
|
+
}
|
|
32609
|
+
})
|
|
32610
|
+
}]
|
|
32611
|
+
});
|
|
32612
|
+
}),
|
|
32613
|
+
ignore3
|
|
32614
|
+
);
|
|
32615
|
+
}
|
|
32616
|
+
}
|
|
32617
|
+
})
|
|
32618
|
+
});
|
|
32619
|
+
|
|
32540
32620
|
// src/diagnostics.ts
|
|
32541
32621
|
var diagnostics = [
|
|
32542
32622
|
duplicatePackage,
|
|
@@ -32553,7 +32633,8 @@ var diagnostics = [
|
|
|
32553
32633
|
tryCatchInEffectGen,
|
|
32554
32634
|
importFromBarrel,
|
|
32555
32635
|
scopeInLayerEffect,
|
|
32556
|
-
effectInVoidSuccess
|
|
32636
|
+
effectInVoidSuccess,
|
|
32637
|
+
unnecessaryPipeChain
|
|
32557
32638
|
];
|
|
32558
32639
|
|
|
32559
32640
|
// src/cli.ts
|