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