@effect/language-service 0.38.1 → 0.38.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/language-service",
3
- "version": "0.38.1",
3
+ "version": "0.38.2",
4
4
  "description": "A Language-Service Plugin to Refactor and Diagnostic effect-ts projects",
5
5
  "main": "index.cjs",
6
6
  "bin": {
package/transform.js CHANGED
@@ -1058,7 +1058,7 @@ var match = (fa, opts) => {
1058
1058
  var orElse2 = (f) => (fa) => {
1059
1059
  const nano = Object.create(MatchProto);
1060
1060
  nano[args] = fa;
1061
- nano[contE] = f;
1061
+ nano[contE] = (_) => _ instanceof NanoDefectException ? fail(_) : f(_);
1062
1062
  return nano;
1063
1063
  };
1064
1064
  var firstSuccessOf = (arr) => arr.slice(1).reduce((arr2, fa) => orElse2(() => fa)(arr2), arr[0]);
@@ -1729,18 +1729,21 @@ var getApplicableRefactors = fn("LSP.getApplicableRefactors")(function* (refacto
1729
1729
  const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
1730
1730
  const effectRefactors = [];
1731
1731
  for (const refactor of refactors) {
1732
- const result = yield* option(refactor.apply(sourceFile, textRange));
1733
- if (isSome2(result)) {
1734
- effectRefactors.push({
1735
- name: refactorNameToFullyQualifiedName(refactor.name),
1736
- description: refactor.description,
1737
- actions: [{
1732
+ yield* pipe(
1733
+ refactor.apply(sourceFile, textRange),
1734
+ map4(
1735
+ (result) => effectRefactors.push({
1738
1736
  name: refactorNameToFullyQualifiedName(refactor.name),
1739
- description: result.value.description,
1740
- kind: result.value.kind
1741
- }]
1742
- });
1743
- }
1737
+ description: refactor.description,
1738
+ actions: [{
1739
+ name: refactorNameToFullyQualifiedName(refactor.name),
1740
+ description: result.description,
1741
+ kind: result.kind
1742
+ }]
1743
+ })
1744
+ ),
1745
+ ignore
1746
+ );
1744
1747
  }
1745
1748
  return effectRefactors;
1746
1749
  });
@@ -3140,6 +3143,55 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
3140
3143
  "TypeParser.extendsContextTag",
3141
3144
  (atLocation) => atLocation
3142
3145
  );
3146
+ const extendsEffectTag = cachedBy(
3147
+ fn("TypeParser.extendsEffectTag")(function* (atLocation) {
3148
+ if (!atLocation.name) {
3149
+ return yield* typeParserIssue("Class has no name", void 0, atLocation);
3150
+ }
3151
+ const heritageClauses = atLocation.heritageClauses;
3152
+ if (!heritageClauses) {
3153
+ return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
3154
+ }
3155
+ for (const heritageClause of heritageClauses) {
3156
+ for (const typeX of heritageClause.types) {
3157
+ if (ts.isExpressionWithTypeArguments(typeX)) {
3158
+ const wholeCall = typeX.expression;
3159
+ if (ts.isCallExpression(wholeCall)) {
3160
+ const effectTagCall = wholeCall.expression;
3161
+ if (ts.isCallExpression(effectTagCall) && wholeCall.typeArguments && wholeCall.typeArguments.length > 0) {
3162
+ const effectTagIdentifier = effectTagCall.expression;
3163
+ const selfTypeNode = wholeCall.typeArguments[0];
3164
+ if (ts.isPropertyAccessExpression(effectTagIdentifier) && ts.isIdentifier(effectTagIdentifier.name) && ts.idText(effectTagIdentifier.name) === "Tag") {
3165
+ const parsedEffectModule = yield* pipe(
3166
+ importedEffectModule(effectTagIdentifier.expression),
3167
+ option
3168
+ );
3169
+ if (isSome2(parsedEffectModule)) {
3170
+ const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
3171
+ if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
3172
+ const type = typeChecker.getTypeOfSymbol(classSym);
3173
+ const tagType = yield* contextTag(type, atLocation);
3174
+ return {
3175
+ className: atLocation.name,
3176
+ selfTypeNode,
3177
+ keyStringLiteral: ts.isStringLiteral(effectTagCall.arguments[0]) ? effectTagCall.arguments[0] : void 0,
3178
+ args: effectTagCall.arguments,
3179
+ Identifier: tagType.Identifier,
3180
+ Service: tagType.Service,
3181
+ Tag: parsedEffectModule.value
3182
+ };
3183
+ }
3184
+ }
3185
+ }
3186
+ }
3187
+ }
3188
+ }
3189
+ }
3190
+ return yield* typeParserIssue("Class does not extend Effect.Tag", void 0, atLocation);
3191
+ }),
3192
+ "TypeParser.extendsEffectTag",
3193
+ (atLocation) => atLocation
3194
+ );
3143
3195
  const extendsEffectService = cachedBy(
3144
3196
  fn("TypeParser.extendsEffectService")(function* (atLocation) {
3145
3197
  if (!atLocation.name) {
@@ -3222,6 +3274,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
3222
3274
  pipeCall,
3223
3275
  scopeType,
3224
3276
  promiseLike,
3277
+ extendsEffectTag,
3225
3278
  extendsEffectService,
3226
3279
  extendsContextTag,
3227
3280
  extendsSchemaClass,
@@ -4464,6 +4517,7 @@ var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
4464
4517
  if (!ts.isClassDeclaration(node)) return yield* fail("not a class declaration");
4465
4518
  const { Service, accessors: accessors2, className } = yield* pipe(
4466
4519
  typeParser.extendsEffectService(node),
4520
+ orElse2(() => map4(typeParser.extendsEffectTag(node), (_) => ({ accessors: true, ..._ }))),
4467
4521
  orElse2(() => fail("not a class extending Effect.Service call"))
4468
4522
  );
4469
4523
  if (accessors2 !== true) return yield* fail("accessors are not enabled in the Effect.Service call");