@effect/language-service 0.38.0 → 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.0",
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
  });
@@ -2536,8 +2539,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2536
2539
  node,
2537
2540
  effectModule,
2538
2541
  generatorFunction,
2539
- body: generatorFunction.body,
2540
- functionStar: generatorFunction.getFirstToken()
2542
+ body: generatorFunction.body
2541
2543
  }))
2542
2544
  );
2543
2545
  },
@@ -2584,8 +2586,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2584
2586
  node,
2585
2587
  effectModule,
2586
2588
  generatorFunction,
2587
- body: generatorFunction.body,
2588
- functionStar: generatorFunction.getFirstToken()
2589
+ body: generatorFunction.body
2589
2590
  }))
2590
2591
  );
2591
2592
  },
@@ -2637,8 +2638,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2637
2638
  node,
2638
2639
  generatorFunction,
2639
2640
  effectModule,
2640
- body: generatorFunction.body,
2641
- functionStar: generatorFunction.getFirstToken()
2641
+ body: generatorFunction.body
2642
2642
  }))
2643
2643
  );
2644
2644
  },
@@ -3143,6 +3143,55 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
3143
3143
  "TypeParser.extendsContextTag",
3144
3144
  (atLocation) => atLocation
3145
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
+ );
3146
3195
  const extendsEffectService = cachedBy(
3147
3196
  fn("TypeParser.extendsEffectService")(function* (atLocation) {
3148
3197
  if (!atLocation.name) {
@@ -3225,6 +3274,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
3225
3274
  pipeCall,
3226
3275
  scopeType,
3227
3276
  promiseLike,
3277
+ extendsEffectTag,
3228
3278
  extendsEffectService,
3229
3279
  extendsContextTag,
3230
3280
  extendsSchemaClass,
@@ -4103,6 +4153,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
4103
4153
  apply: fn("missingStarInYieldEffectGen.apply")(function* (sourceFile, report) {
4104
4154
  const ts = yield* service(TypeScriptApi);
4105
4155
  const typeParser = yield* service(TypeParser);
4156
+ const tsUtils = yield* service(TypeScriptUtils);
4106
4157
  const brokenGenerators = /* @__PURE__ */ new Set();
4107
4158
  const brokenYields = /* @__PURE__ */ new Set();
4108
4159
  const nodeToVisit = [];
@@ -4125,9 +4176,9 @@ var missingStarInYieldEffectGen = createDiagnostic({
4125
4176
  typeParser.effectGen(effectGenNode),
4126
4177
  orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
4127
4178
  orElse2(() => typeParser.effectFnGen(effectGenNode)),
4128
- map4(({ functionStar }) => {
4129
- if (functionStar) {
4130
- brokenGenerators.add(functionStar);
4179
+ map4(({ generatorFunction }) => {
4180
+ if (generatorFunction) {
4181
+ brokenGenerators.add(ts.getTokenPosOfNode(generatorFunction, tsUtils.getSourceFileOfNode(node)));
4131
4182
  }
4132
4183
  brokenYields.add(node);
4133
4184
  }),
@@ -4137,8 +4188,8 @@ var missingStarInYieldEffectGen = createDiagnostic({
4137
4188
  }
4138
4189
  }
4139
4190
  brokenGenerators.forEach(
4140
- (node) => report({
4141
- location: node,
4191
+ (pos) => report({
4192
+ location: { pos, end: pos + "function".length },
4142
4193
  messageText: `Seems like you used yield instead of yield* inside this Effect.gen.`,
4143
4194
  fixes: []
4144
4195
  })
@@ -4466,6 +4517,7 @@ var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
4466
4517
  if (!ts.isClassDeclaration(node)) return yield* fail("not a class declaration");
4467
4518
  const { Service, accessors: accessors2, className } = yield* pipe(
4468
4519
  typeParser.extendsEffectService(node),
4520
+ orElse2(() => map4(typeParser.extendsEffectTag(node), (_) => ({ accessors: true, ..._ }))),
4469
4521
  orElse2(() => fail("not a class extending Effect.Service call"))
4470
4522
  );
4471
4523
  if (accessors2 !== true) return yield* fail("accessors are not enabled in the Effect.Service call");