@effect/language-service 0.84.0 → 0.84.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 -1
- package/cli.js +59 -16
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +54 -12
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +54 -12
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/schema.json +1 -1
- package/transform.js +54 -12
- package/transform.js.map +1 -1
package/package.json
CHANGED
package/schema.json
CHANGED
|
@@ -2757,7 +2757,7 @@
|
|
|
2757
2757
|
"suggestion"
|
|
2758
2758
|
],
|
|
2759
2759
|
"default": "suggestion",
|
|
2760
|
-
"description": "Suggests using Runtime methods instead of Effect.run* inside Effect contexts Default severity: suggestion."
|
|
2760
|
+
"description": "Suggests using Runtime or Effect.run*With methods instead of Effect.run* inside Effect contexts Default severity: suggestion."
|
|
2761
2761
|
},
|
|
2762
2762
|
"schemaStructWithTag": {
|
|
2763
2763
|
"type": "string",
|
package/transform.js
CHANGED
|
@@ -5933,12 +5933,14 @@ var getParameterName = (typescript, name) => {
|
|
|
5933
5933
|
}
|
|
5934
5934
|
return "parameter";
|
|
5935
5935
|
};
|
|
5936
|
-
var hasOuterContextualFunctionType = (typescript, typeChecker, node) => {
|
|
5936
|
+
var hasOuterContextualFunctionType = (typescript, typeChecker, typeCheckerUtils, node) => {
|
|
5937
5937
|
const contextualType = typeChecker.getContextualType(node);
|
|
5938
5938
|
if (!contextualType) {
|
|
5939
5939
|
return false;
|
|
5940
5940
|
}
|
|
5941
|
-
return
|
|
5941
|
+
return typeCheckerUtils.unrollUnionMembers(contextualType).some(
|
|
5942
|
+
(type) => typeChecker.getSignaturesOfType(type, typescript.SignatureKind.Call).length > 0
|
|
5943
|
+
);
|
|
5942
5944
|
};
|
|
5943
5945
|
var effectFnImplicitAny = createDiagnostic({
|
|
5944
5946
|
name: "effectFnImplicitAny",
|
|
@@ -5952,6 +5954,7 @@ var effectFnImplicitAny = createDiagnostic({
|
|
|
5952
5954
|
const ts = yield* service(TypeScriptApi);
|
|
5953
5955
|
const program = yield* service(TypeScriptProgram);
|
|
5954
5956
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
5957
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
5955
5958
|
const typeParser = yield* service(TypeParser);
|
|
5956
5959
|
const noImplicitAny = program.getCompilerOptions().noImplicitAny ?? program.getCompilerOptions().strict ?? false;
|
|
5957
5960
|
if (!noImplicitAny) {
|
|
@@ -5991,7 +5994,7 @@ var effectFnImplicitAny = createDiagnostic({
|
|
|
5991
5994
|
),
|
|
5992
5995
|
orUndefined
|
|
5993
5996
|
);
|
|
5994
|
-
if (!parsed || hasOuterContextualFunctionType(ts, typeChecker, parsed.call)) {
|
|
5997
|
+
if (!parsed || hasOuterContextualFunctionType(ts, typeChecker, typeCheckerUtils, parsed.call)) {
|
|
5995
5998
|
continue;
|
|
5996
5999
|
}
|
|
5997
6000
|
for (const parameter of parsed.fn.parameters) {
|
|
@@ -11155,16 +11158,16 @@ Nested Effect-able types may be intended if you plan to later manually flatten o
|
|
|
11155
11158
|
var runEffectInsideEffect = createDiagnostic({
|
|
11156
11159
|
name: "runEffectInsideEffect",
|
|
11157
11160
|
code: 32,
|
|
11158
|
-
description: "Suggests using Runtime methods instead of Effect.run* inside Effect contexts",
|
|
11161
|
+
description: "Suggests using Runtime or Effect.run*With methods instead of Effect.run* inside Effect contexts",
|
|
11159
11162
|
group: "antipattern",
|
|
11160
11163
|
severity: "suggestion",
|
|
11161
11164
|
fixable: true,
|
|
11162
|
-
supportedEffect: ["v3"],
|
|
11165
|
+
supportedEffect: ["v3", "v4"],
|
|
11163
11166
|
apply: fn("runEffectInsideEffect.apply")(function* (sourceFile, report) {
|
|
11164
11167
|
const ts = yield* service(TypeScriptApi);
|
|
11165
11168
|
const typeParser = yield* service(TypeParser);
|
|
11166
11169
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
11167
|
-
|
|
11170
|
+
const supportedEffect = typeParser.supportedEffect();
|
|
11168
11171
|
const parseEffectMethod = (node, methodName) => pipe(
|
|
11169
11172
|
typeParser.isNodeReferenceToEffectModuleApi(methodName)(node),
|
|
11170
11173
|
map4(() => ({ node, methodName }))
|
|
@@ -11197,9 +11200,10 @@ var runEffectInsideEffect = createDiagnostic({
|
|
|
11197
11200
|
if (scopeNode && scopeNode !== effectGen.generatorFunction) {
|
|
11198
11201
|
const fixAddRuntime = gen(function* () {
|
|
11199
11202
|
const changeTracker = yield* service(ChangeTracker);
|
|
11200
|
-
const runtimeModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", "Runtime") || "Runtime";
|
|
11201
11203
|
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", "Effect") || "Effect";
|
|
11204
|
+
const runtimeModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", "Runtime") || "Runtime";
|
|
11202
11205
|
let runtimeIdentifier = void 0;
|
|
11206
|
+
let servicesIdentifier = void 0;
|
|
11203
11207
|
for (const statement of effectGen.generatorFunction.body.statements) {
|
|
11204
11208
|
if (ts.isVariableStatement(statement) && statement.declarationList.declarations.length === 1) {
|
|
11205
11209
|
const declaration = statement.declarationList.declarations[0];
|
|
@@ -11213,11 +11217,46 @@ var runEffectInsideEffect = createDiagnostic({
|
|
|
11213
11217
|
if (isSome2(maybeEffectRuntime) && ts.isIdentifier(declaration.name)) {
|
|
11214
11218
|
runtimeIdentifier = ts.idText(declaration.name);
|
|
11215
11219
|
}
|
|
11220
|
+
const maybeEffectServices = yield* pipe(
|
|
11221
|
+
typeParser.isNodeReferenceToEffectModuleApi("services")(yieldedExpression.expression),
|
|
11222
|
+
option
|
|
11223
|
+
);
|
|
11224
|
+
if (isSome2(maybeEffectServices) && ts.isIdentifier(declaration.name)) {
|
|
11225
|
+
servicesIdentifier = ts.idText(declaration.name);
|
|
11226
|
+
}
|
|
11216
11227
|
}
|
|
11217
11228
|
}
|
|
11218
11229
|
}
|
|
11219
11230
|
}
|
|
11220
|
-
if (!
|
|
11231
|
+
if (supportedEffect === "v4" && !servicesIdentifier) {
|
|
11232
|
+
changeTracker.insertNodeAt(
|
|
11233
|
+
sourceFile,
|
|
11234
|
+
effectGen.body.statements[0].pos,
|
|
11235
|
+
ts.factory.createVariableStatement(
|
|
11236
|
+
void 0,
|
|
11237
|
+
ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(
|
|
11238
|
+
"effectServices",
|
|
11239
|
+
void 0,
|
|
11240
|
+
void 0,
|
|
11241
|
+
ts.factory.createYieldExpression(
|
|
11242
|
+
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
11243
|
+
ts.factory.createCallExpression(
|
|
11244
|
+
ts.factory.createPropertyAccessExpression(
|
|
11245
|
+
ts.factory.createIdentifier(effectModuleIdentifier),
|
|
11246
|
+
"services"
|
|
11247
|
+
),
|
|
11248
|
+
[ts.factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)],
|
|
11249
|
+
[]
|
|
11250
|
+
)
|
|
11251
|
+
)
|
|
11252
|
+
)], ts.NodeFlags.Const)
|
|
11253
|
+
),
|
|
11254
|
+
{
|
|
11255
|
+
prefix: "\n",
|
|
11256
|
+
suffix: "\n"
|
|
11257
|
+
}
|
|
11258
|
+
);
|
|
11259
|
+
} else if (supportedEffect === "v3" && !runtimeIdentifier) {
|
|
11221
11260
|
changeTracker.insertNodeAt(
|
|
11222
11261
|
sourceFile,
|
|
11223
11262
|
effectGen.body.statements[0].pos,
|
|
@@ -11253,16 +11292,19 @@ var runEffectInsideEffect = createDiagnostic({
|
|
|
11253
11292
|
changeTracker.insertText(
|
|
11254
11293
|
sourceFile,
|
|
11255
11294
|
node.arguments[0].pos,
|
|
11256
|
-
`${runtimeModuleIdentifier}.${isEffectRunCall.value.methodName}(${runtimeIdentifier || "effectRuntime"}, `
|
|
11295
|
+
supportedEffect === "v4" ? `${effectModuleIdentifier}.${isEffectRunCall.value.methodName}With(${servicesIdentifier || "effectServices"})(` : `${runtimeModuleIdentifier}.${isEffectRunCall.value.methodName}(${runtimeIdentifier || "effectRuntime"}, `
|
|
11257
11296
|
);
|
|
11258
11297
|
});
|
|
11298
|
+
const v4MethodName = `${isEffectRunCall.value.methodName}With`;
|
|
11299
|
+
const messageText = supportedEffect === "v4" ? `Using ${nodeText} inside an Effect is not recommended. The same services should generally be used instead to run child effects.
|
|
11300
|
+
Consider extracting the current services by using for example Effect.services and then use Effect.${v4MethodName} with the extracted services instead.` : `Using ${nodeText} inside an Effect is not recommended. The same runtime should generally be used instead to run child effects.
|
|
11301
|
+
Consider extracting the Runtime by using for example Effect.runtime and then use Runtime.${isEffectRunCall.value.methodName} with the extracted runtime instead.`;
|
|
11259
11302
|
report({
|
|
11260
11303
|
location: node.expression,
|
|
11261
|
-
messageText
|
|
11262
|
-
Consider extracting the Runtime by using for example Effect.runtime and then use Runtime.${isEffectRunCall.value.methodName} with the extracted runtime instead.`,
|
|
11304
|
+
messageText,
|
|
11263
11305
|
fixes: [{
|
|
11264
11306
|
fixName: "runEffectInsideEffect_fix",
|
|
11265
|
-
description: "Use a runtime to run the Effect",
|
|
11307
|
+
description: supportedEffect === "v4" ? "Use the current services to run the Effect" : "Use a runtime to run the Effect",
|
|
11266
11308
|
apply: fixAddRuntime
|
|
11267
11309
|
}]
|
|
11268
11310
|
});
|