@effect/language-service 0.10.2 → 0.11.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/index.js +102 -18
- package/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,6 +71,7 @@ Few options can be provided alongside the initialization of the Language Service
|
|
|
71
71
|
- Pipe to datafirst: Transform a pipe() call into a series of datafirst function calls (where available).
|
|
72
72
|
- Toggle return type signature: With a single refactor, adds or removes type annotations from the definition.
|
|
73
73
|
- Remove unnecessary `Effect.gen` definitions that contains a single `yield` statement.
|
|
74
|
+
- Wrap an `Effect` expression with `Effect.gen`
|
|
74
75
|
|
|
75
76
|
## Configuring diagnostics
|
|
76
77
|
|
package/index.js
CHANGED
|
@@ -1166,24 +1166,7 @@ var transformAsyncAwaitToEffectGen = fn("AST.transformAsyncAwaitToEffectGen")(
|
|
|
1166
1166
|
return ts.visitEachChild(_, visitor, ts.nullTransformationContext);
|
|
1167
1167
|
}
|
|
1168
1168
|
const generatorBody = visitor(node.body);
|
|
1169
|
-
const
|
|
1170
|
-
void 0,
|
|
1171
|
-
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
1172
|
-
void 0,
|
|
1173
|
-
[],
|
|
1174
|
-
[],
|
|
1175
|
-
void 0,
|
|
1176
|
-
generatorBody
|
|
1177
|
-
// NOTE(mattia): intended, to use same routine for both ConciseBody and Body
|
|
1178
|
-
);
|
|
1179
|
-
const effectGenCallExp = ts.factory.createCallExpression(
|
|
1180
|
-
ts.factory.createPropertyAccessExpression(
|
|
1181
|
-
ts.factory.createIdentifier(effectModuleName),
|
|
1182
|
-
"gen"
|
|
1183
|
-
),
|
|
1184
|
-
void 0,
|
|
1185
|
-
[generator]
|
|
1186
|
-
);
|
|
1169
|
+
const effectGenCallExp = yield* createEffectGenCallExpression(effectModuleName, generatorBody);
|
|
1187
1170
|
let currentFlags = ts.getCombinedModifierFlags(node);
|
|
1188
1171
|
currentFlags &= ~ts.ModifierFlags.Async;
|
|
1189
1172
|
const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags);
|
|
@@ -1405,6 +1388,47 @@ var parseDataForExtendsClassCompletion = fn(
|
|
|
1405
1388
|
{ accessedObject, classDeclaration, className: classDeclaration.name, replacementSpan }
|
|
1406
1389
|
);
|
|
1407
1390
|
});
|
|
1391
|
+
var createEffectGenCallExpression = fn("AST.createEffectGenCallExpression")(function* (effectModuleIdentifierName, node) {
|
|
1392
|
+
const ts = yield* service(TypeScriptApi);
|
|
1393
|
+
const generator = ts.factory.createFunctionExpression(
|
|
1394
|
+
void 0,
|
|
1395
|
+
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
1396
|
+
void 0,
|
|
1397
|
+
[],
|
|
1398
|
+
[],
|
|
1399
|
+
void 0,
|
|
1400
|
+
node
|
|
1401
|
+
// NOTE(mattia): intended, to use same routine for both ConciseBody and Body
|
|
1402
|
+
);
|
|
1403
|
+
return ts.factory.createCallExpression(
|
|
1404
|
+
ts.factory.createPropertyAccessExpression(
|
|
1405
|
+
ts.factory.createIdentifier(effectModuleIdentifierName),
|
|
1406
|
+
"gen"
|
|
1407
|
+
),
|
|
1408
|
+
void 0,
|
|
1409
|
+
[generator]
|
|
1410
|
+
);
|
|
1411
|
+
});
|
|
1412
|
+
var createEffectGenCallExpressionWithBlock = fn(
|
|
1413
|
+
"AST.createEffectGenCallExpressionWithBlock"
|
|
1414
|
+
)(function* (effectModuleIdentifierName, statement) {
|
|
1415
|
+
const ts = yield* service(TypeScriptApi);
|
|
1416
|
+
return yield* createEffectGenCallExpression(
|
|
1417
|
+
effectModuleIdentifierName,
|
|
1418
|
+
ts.factory.createBlock(Array.isArray(statement) ? statement : [statement], false)
|
|
1419
|
+
);
|
|
1420
|
+
});
|
|
1421
|
+
var createReturnYieldStarStatement = fn("AST.createReturnYieldStarStatement")(
|
|
1422
|
+
function* (expr) {
|
|
1423
|
+
const ts = yield* service(TypeScriptApi);
|
|
1424
|
+
return ts.factory.createReturnStatement(
|
|
1425
|
+
ts.factory.createYieldExpression(
|
|
1426
|
+
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
1427
|
+
expr
|
|
1428
|
+
)
|
|
1429
|
+
);
|
|
1430
|
+
}
|
|
1431
|
+
);
|
|
1408
1432
|
|
|
1409
1433
|
// src/core/LSP.ts
|
|
1410
1434
|
var RefactorNotApplicableError = class {
|
|
@@ -3103,6 +3127,65 @@ var toggleTypeAnnotation = createRefactor({
|
|
|
3103
3127
|
})
|
|
3104
3128
|
});
|
|
3105
3129
|
|
|
3130
|
+
// src/refactors/wrapWithEffectGen.ts
|
|
3131
|
+
var wrapWithEffectGen = createRefactor({
|
|
3132
|
+
name: "effect/wrapWithEffectGen",
|
|
3133
|
+
description: "Wrap with Effect.gen",
|
|
3134
|
+
apply: (sourceFile, textRange) => gen2(function* () {
|
|
3135
|
+
const ts = yield* service(TypeScriptApi);
|
|
3136
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3137
|
+
const findEffectToWrap = fn("findEffectToWrap")(function* (node2) {
|
|
3138
|
+
if (!ts.isExpression(node2)) return yield* fail("is not an expression");
|
|
3139
|
+
const parent = node2.parent;
|
|
3140
|
+
if (parent != null && ts.isVariableDeclaration(parent) && parent.initializer !== node2) return yield* fail("is LHS of variable declaration");
|
|
3141
|
+
const type = typeChecker.getTypeAtLocation(node2);
|
|
3142
|
+
yield* effectType(type, node2);
|
|
3143
|
+
return node2;
|
|
3144
|
+
});
|
|
3145
|
+
const maybeNode = yield* pipe(
|
|
3146
|
+
yield* getAncestorNodesInRange(sourceFile, textRange),
|
|
3147
|
+
map2(findEffectToWrap),
|
|
3148
|
+
firstSuccessOf,
|
|
3149
|
+
option
|
|
3150
|
+
);
|
|
3151
|
+
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
3152
|
+
const node = maybeNode.value;
|
|
3153
|
+
if (!ts.isExpression(node)) return yield* fail(new RefactorNotApplicableError());
|
|
3154
|
+
const effectGen2 = yield* createEffectGenCallExpressionWithBlock(
|
|
3155
|
+
yield* getEffectModuleIdentifierName(sourceFile),
|
|
3156
|
+
yield* createReturnYieldStarStatement(node)
|
|
3157
|
+
);
|
|
3158
|
+
return {
|
|
3159
|
+
kind: "refactor.rewrite.effect.wrapWithEffectGen",
|
|
3160
|
+
description: `Wrap with Effect.gen`,
|
|
3161
|
+
apply: gen2(function* () {
|
|
3162
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
3163
|
+
changeTracker.replaceNode(sourceFile, node, effectGen2);
|
|
3164
|
+
})
|
|
3165
|
+
};
|
|
3166
|
+
})
|
|
3167
|
+
});
|
|
3168
|
+
var getEffectModuleIdentifierName = fn("getEffectModuleIdentifierName")(
|
|
3169
|
+
function* (sourceFile) {
|
|
3170
|
+
return match2(
|
|
3171
|
+
yield* option(
|
|
3172
|
+
findImportedModuleIdentifier(
|
|
3173
|
+
sourceFile,
|
|
3174
|
+
(node) => pipe(
|
|
3175
|
+
importedEffectModule(node),
|
|
3176
|
+
option,
|
|
3177
|
+
map3(isSome2)
|
|
3178
|
+
)
|
|
3179
|
+
)
|
|
3180
|
+
),
|
|
3181
|
+
{
|
|
3182
|
+
onNone: () => "Effect",
|
|
3183
|
+
onSome: (node) => node.text
|
|
3184
|
+
}
|
|
3185
|
+
);
|
|
3186
|
+
}
|
|
3187
|
+
);
|
|
3188
|
+
|
|
3106
3189
|
// src/refactors/wrapWithPipe.ts
|
|
3107
3190
|
var wrapWithPipe = createRefactor({
|
|
3108
3191
|
name: "effect/wrapWithPipe",
|
|
@@ -3133,6 +3216,7 @@ var refactors = [
|
|
|
3133
3216
|
toggleLazyConst,
|
|
3134
3217
|
toggleReturnTypeAnnotation,
|
|
3135
3218
|
toggleTypeAnnotation,
|
|
3219
|
+
wrapWithEffectGen,
|
|
3136
3220
|
wrapWithPipe,
|
|
3137
3221
|
effectGenToFn
|
|
3138
3222
|
];
|