@effect/language-service 0.68.0 → 0.69.1
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 +1 -0
- package/cli.js +103 -2
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +102 -1
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +102 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +102 -1
- package/transform.js.map +1 -1
package/index.js
CHANGED
|
@@ -8325,6 +8325,104 @@ ${versions.map((version) => `- found ${version} at ${resolvedPackages[packageNam
|
|
|
8325
8325
|
})
|
|
8326
8326
|
});
|
|
8327
8327
|
|
|
8328
|
+
// src/diagnostics/effectFnIife.ts
|
|
8329
|
+
var effectFnIife = createDiagnostic({
|
|
8330
|
+
name: "effectFnIife",
|
|
8331
|
+
code: 46,
|
|
8332
|
+
description: "Effect.fn or Effect.fnUntraced is called as an IIFE (Immediately Invoked Function Expression). Use Effect.gen instead.",
|
|
8333
|
+
severity: "warning",
|
|
8334
|
+
apply: fn("effectFnIife.apply")(function* (sourceFile, report) {
|
|
8335
|
+
const ts = yield* service(TypeScriptApi);
|
|
8336
|
+
const typeParser = yield* service(TypeParser);
|
|
8337
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
8338
|
+
const sourceEffectModuleName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
8339
|
+
sourceFile,
|
|
8340
|
+
"effect",
|
|
8341
|
+
"Effect"
|
|
8342
|
+
) || "Effect";
|
|
8343
|
+
const nodeToVisit = [];
|
|
8344
|
+
const appendNodeToVisit = (node) => {
|
|
8345
|
+
nodeToVisit.push(node);
|
|
8346
|
+
return void 0;
|
|
8347
|
+
};
|
|
8348
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
8349
|
+
while (nodeToVisit.length > 0) {
|
|
8350
|
+
const node = nodeToVisit.shift();
|
|
8351
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
8352
|
+
if (!ts.isCallExpression(node)) continue;
|
|
8353
|
+
const innerCall = node.expression;
|
|
8354
|
+
if (!ts.isCallExpression(innerCall)) continue;
|
|
8355
|
+
const parsed = yield* pipe(
|
|
8356
|
+
typeParser.effectFnGen(innerCall),
|
|
8357
|
+
map8((result) => ({
|
|
8358
|
+
kind: "fn",
|
|
8359
|
+
effectModule: result.effectModule,
|
|
8360
|
+
generatorFunction: result.generatorFunction,
|
|
8361
|
+
pipeArguments: result.pipeArguments
|
|
8362
|
+
})),
|
|
8363
|
+
orElse2(
|
|
8364
|
+
() => pipe(
|
|
8365
|
+
typeParser.effectFnUntracedGen(innerCall),
|
|
8366
|
+
map8((result) => ({
|
|
8367
|
+
kind: "fnUntraced",
|
|
8368
|
+
effectModule: result.effectModule,
|
|
8369
|
+
generatorFunction: result.generatorFunction,
|
|
8370
|
+
pipeArguments: result.pipeArguments
|
|
8371
|
+
}))
|
|
8372
|
+
)
|
|
8373
|
+
),
|
|
8374
|
+
orElse2(
|
|
8375
|
+
() => pipe(
|
|
8376
|
+
typeParser.effectFn(innerCall),
|
|
8377
|
+
map8((result) => ({
|
|
8378
|
+
kind: "fn",
|
|
8379
|
+
effectModule: result.effectModule,
|
|
8380
|
+
generatorFunction: void 0,
|
|
8381
|
+
pipeArguments: result.pipeArguments
|
|
8382
|
+
}))
|
|
8383
|
+
)
|
|
8384
|
+
),
|
|
8385
|
+
option
|
|
8386
|
+
);
|
|
8387
|
+
if (isNone2(parsed)) continue;
|
|
8388
|
+
const { effectModule, generatorFunction, kind, pipeArguments: pipeArguments2 } = parsed.value;
|
|
8389
|
+
const effectModuleName = ts.isIdentifier(effectModule) ? ts.idText(effectModule) : sourceEffectModuleName;
|
|
8390
|
+
const fixes = [];
|
|
8391
|
+
if (generatorFunction && generatorFunction.parameters.length === 0) {
|
|
8392
|
+
fixes.push({
|
|
8393
|
+
fixName: "effectFnIife_toEffectGen",
|
|
8394
|
+
description: "Convert to Effect.gen",
|
|
8395
|
+
apply: gen(function* () {
|
|
8396
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
8397
|
+
const effectGenCall = ts.factory.createCallExpression(
|
|
8398
|
+
ts.factory.createPropertyAccessExpression(
|
|
8399
|
+
ts.factory.createIdentifier(effectModuleName),
|
|
8400
|
+
"gen"
|
|
8401
|
+
),
|
|
8402
|
+
void 0,
|
|
8403
|
+
[generatorFunction]
|
|
8404
|
+
);
|
|
8405
|
+
let replacementNode = effectGenCall;
|
|
8406
|
+
if (pipeArguments2.length > 0) {
|
|
8407
|
+
replacementNode = ts.factory.createCallExpression(
|
|
8408
|
+
ts.factory.createPropertyAccessExpression(effectGenCall, "pipe"),
|
|
8409
|
+
void 0,
|
|
8410
|
+
[...pipeArguments2]
|
|
8411
|
+
);
|
|
8412
|
+
}
|
|
8413
|
+
changeTracker.replaceNode(sourceFile, node, replacementNode);
|
|
8414
|
+
})
|
|
8415
|
+
});
|
|
8416
|
+
}
|
|
8417
|
+
report({
|
|
8418
|
+
location: node,
|
|
8419
|
+
messageText: `${effectModuleName}.${kind} returns a reusable function that can take arguments, but here it's called immediately. Use Effect.gen instead (optionally with Effect.withSpan for tracing).`,
|
|
8420
|
+
fixes
|
|
8421
|
+
});
|
|
8422
|
+
}
|
|
8423
|
+
})
|
|
8424
|
+
});
|
|
8425
|
+
|
|
8328
8426
|
// src/diagnostics/effectFnOpportunity.ts
|
|
8329
8427
|
var effectFnOpportunity = createDiagnostic({
|
|
8330
8428
|
name: "effectFnOpportunity",
|
|
@@ -8590,9 +8688,11 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
8590
8688
|
});
|
|
8591
8689
|
}
|
|
8592
8690
|
const pipeArgsSuffix = pipeArguments2.length > 0 ? ` Effect.fn also accepts the piped transformations as additional arguments.` : ``;
|
|
8691
|
+
const suggestConsultingQuickFixes = ` Your editor quickfixes or the "effect-language-service" cli can show you how to convert to Effect.fn or Effect.fnUntraced.`;
|
|
8692
|
+
const orFnUntraced = target.value.generatorFunction ? `, or Effect.fnUntraced` : ``;
|
|
8593
8693
|
report({
|
|
8594
8694
|
location: nameIdentifier ?? targetNode,
|
|
8595
|
-
messageText:
|
|
8695
|
+
messageText: `This function could benefit from Effect.fn's automatic tracing and concise syntax${orFnUntraced}.${pipeArgsSuffix}${suggestConsultingQuickFixes}`,
|
|
8596
8696
|
fixes
|
|
8597
8697
|
});
|
|
8598
8698
|
}
|
|
@@ -11592,6 +11692,7 @@ var diagnostics = [
|
|
|
11592
11692
|
globalErrorInEffectFailure,
|
|
11593
11693
|
layerMergeAllWithDependencies,
|
|
11594
11694
|
effectMapVoid,
|
|
11695
|
+
effectFnIife,
|
|
11595
11696
|
effectFnOpportunity,
|
|
11596
11697
|
redundantSchemaTagIdentifier,
|
|
11597
11698
|
schemaSyncInEffect,
|