@effect/language-service 0.68.0 → 0.69.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 +1 -0
- package/cli.js +100 -1
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +99 -0
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +99 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +99 -0
- package/transform.js.map +1 -1
|
@@ -4855,6 +4855,104 @@ ${versions.map((version) => `- found ${version} at ${resolvedPackages[packageNam
|
|
|
4855
4855
|
})
|
|
4856
4856
|
});
|
|
4857
4857
|
|
|
4858
|
+
// src/diagnostics/effectFnIife.ts
|
|
4859
|
+
var effectFnIife = createDiagnostic({
|
|
4860
|
+
name: "effectFnIife",
|
|
4861
|
+
code: 46,
|
|
4862
|
+
description: "Effect.fn or Effect.fnUntraced is called as an IIFE (Immediately Invoked Function Expression). Use Effect.gen instead.",
|
|
4863
|
+
severity: "warning",
|
|
4864
|
+
apply: fn("effectFnIife.apply")(function* (sourceFile, report) {
|
|
4865
|
+
const ts = yield* service(TypeScriptApi);
|
|
4866
|
+
const typeParser = yield* service(TypeParser);
|
|
4867
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4868
|
+
const sourceEffectModuleName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4869
|
+
sourceFile,
|
|
4870
|
+
"effect",
|
|
4871
|
+
"Effect"
|
|
4872
|
+
) || "Effect";
|
|
4873
|
+
const nodeToVisit = [];
|
|
4874
|
+
const appendNodeToVisit = (node) => {
|
|
4875
|
+
nodeToVisit.push(node);
|
|
4876
|
+
return void 0;
|
|
4877
|
+
};
|
|
4878
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
4879
|
+
while (nodeToVisit.length > 0) {
|
|
4880
|
+
const node = nodeToVisit.shift();
|
|
4881
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
4882
|
+
if (!ts.isCallExpression(node)) continue;
|
|
4883
|
+
const innerCall = node.expression;
|
|
4884
|
+
if (!ts.isCallExpression(innerCall)) continue;
|
|
4885
|
+
const parsed = yield* pipe(
|
|
4886
|
+
typeParser.effectFnGen(innerCall),
|
|
4887
|
+
map4((result) => ({
|
|
4888
|
+
kind: "fn",
|
|
4889
|
+
effectModule: result.effectModule,
|
|
4890
|
+
generatorFunction: result.generatorFunction,
|
|
4891
|
+
pipeArguments: result.pipeArguments
|
|
4892
|
+
})),
|
|
4893
|
+
orElse2(
|
|
4894
|
+
() => pipe(
|
|
4895
|
+
typeParser.effectFnUntracedGen(innerCall),
|
|
4896
|
+
map4((result) => ({
|
|
4897
|
+
kind: "fnUntraced",
|
|
4898
|
+
effectModule: result.effectModule,
|
|
4899
|
+
generatorFunction: result.generatorFunction,
|
|
4900
|
+
pipeArguments: result.pipeArguments
|
|
4901
|
+
}))
|
|
4902
|
+
)
|
|
4903
|
+
),
|
|
4904
|
+
orElse2(
|
|
4905
|
+
() => pipe(
|
|
4906
|
+
typeParser.effectFn(innerCall),
|
|
4907
|
+
map4((result) => ({
|
|
4908
|
+
kind: "fn",
|
|
4909
|
+
effectModule: result.effectModule,
|
|
4910
|
+
generatorFunction: void 0,
|
|
4911
|
+
pipeArguments: result.pipeArguments
|
|
4912
|
+
}))
|
|
4913
|
+
)
|
|
4914
|
+
),
|
|
4915
|
+
option
|
|
4916
|
+
);
|
|
4917
|
+
if (isNone2(parsed)) continue;
|
|
4918
|
+
const { effectModule, generatorFunction, kind, pipeArguments: pipeArguments2 } = parsed.value;
|
|
4919
|
+
const effectModuleName = ts.isIdentifier(effectModule) ? ts.idText(effectModule) : sourceEffectModuleName;
|
|
4920
|
+
const fixes = [];
|
|
4921
|
+
if (generatorFunction && generatorFunction.parameters.length === 0) {
|
|
4922
|
+
fixes.push({
|
|
4923
|
+
fixName: "effectFnIife_toEffectGen",
|
|
4924
|
+
description: "Convert to Effect.gen",
|
|
4925
|
+
apply: gen(function* () {
|
|
4926
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
4927
|
+
const effectGenCall = ts.factory.createCallExpression(
|
|
4928
|
+
ts.factory.createPropertyAccessExpression(
|
|
4929
|
+
ts.factory.createIdentifier(effectModuleName),
|
|
4930
|
+
"gen"
|
|
4931
|
+
),
|
|
4932
|
+
void 0,
|
|
4933
|
+
[generatorFunction]
|
|
4934
|
+
);
|
|
4935
|
+
let replacementNode = effectGenCall;
|
|
4936
|
+
if (pipeArguments2.length > 0) {
|
|
4937
|
+
replacementNode = ts.factory.createCallExpression(
|
|
4938
|
+
ts.factory.createPropertyAccessExpression(effectGenCall, "pipe"),
|
|
4939
|
+
void 0,
|
|
4940
|
+
[...pipeArguments2]
|
|
4941
|
+
);
|
|
4942
|
+
}
|
|
4943
|
+
changeTracker.replaceNode(sourceFile, node, replacementNode);
|
|
4944
|
+
})
|
|
4945
|
+
});
|
|
4946
|
+
}
|
|
4947
|
+
report({
|
|
4948
|
+
location: node,
|
|
4949
|
+
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).`,
|
|
4950
|
+
fixes
|
|
4951
|
+
});
|
|
4952
|
+
}
|
|
4953
|
+
})
|
|
4954
|
+
});
|
|
4955
|
+
|
|
4858
4956
|
// src/diagnostics/effectFnOpportunity.ts
|
|
4859
4957
|
var effectFnOpportunity = createDiagnostic({
|
|
4860
4958
|
name: "effectFnOpportunity",
|
|
@@ -9155,6 +9253,7 @@ var diagnostics = [
|
|
|
9155
9253
|
globalErrorInEffectFailure,
|
|
9156
9254
|
layerMergeAllWithDependencies,
|
|
9157
9255
|
effectMapVoid,
|
|
9256
|
+
effectFnIife,
|
|
9158
9257
|
effectFnOpportunity,
|
|
9159
9258
|
redundantSchemaTagIdentifier,
|
|
9160
9259
|
schemaSyncInEffect,
|