@effect/language-service 0.38.1 → 0.38.3

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/index.js CHANGED
@@ -960,7 +960,7 @@ var match = (fa, opts) => {
960
960
  var orElse2 = (f) => (fa) => {
961
961
  const nano = Object.create(MatchProto);
962
962
  nano[args] = fa;
963
- nano[contE] = f;
963
+ nano[contE] = (_) => _ instanceof NanoDefectException ? fail(_) : f(_);
964
964
  return nano;
965
965
  };
966
966
  var firstSuccessOf = (arr) => arr.slice(1).reduce((arr2, fa) => orElse2(() => fa)(arr2), arr[0]);
@@ -1148,6 +1148,19 @@ var filter = /* @__PURE__ */ dual(2, (self, predicate) => {
1148
1148
  }
1149
1149
  return out;
1150
1150
  });
1151
+ var partition = /* @__PURE__ */ dual(2, (self, predicate) => {
1152
+ const left3 = [];
1153
+ const right3 = [];
1154
+ const as = fromIterable(self);
1155
+ for (let i = 0; i < as.length; i++) {
1156
+ if (predicate(as[i], i)) {
1157
+ right3.push(as[i]);
1158
+ } else {
1159
+ left3.push(as[i]);
1160
+ }
1161
+ }
1162
+ return [left3, right3];
1163
+ });
1151
1164
  var every = /* @__PURE__ */ dual(2, (self, refinement) => self.every(refinement));
1152
1165
  var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
1153
1166
  const input = fromIterable(self);
@@ -1181,10 +1194,10 @@ function makeTypeScriptUtils(ts) {
1181
1194
  if (!hasProperty(packageJsonScope.contents, "packageJsonContent")) return;
1182
1195
  const packageJsonContent = packageJsonScope.contents.packageJsonContent;
1183
1196
  if (!hasProperty(packageJsonContent, "name")) return;
1184
- if (!hasProperty(packageJsonContent, "version")) return;
1185
1197
  if (!hasProperty(packageJsonScope, "packageDirectory")) return;
1186
1198
  if (!isString(packageJsonScope.packageDirectory)) return;
1187
- const { name, version } = packageJsonContent;
1199
+ const { name } = packageJsonContent;
1200
+ const version = hasProperty(packageJsonScope, "version") ? packageJsonScope.version : "";
1188
1201
  if (!isString(name)) return;
1189
1202
  if (!isString(version)) return;
1190
1203
  const hasEffectInPeerDependencies = hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) && hasProperty(packageJsonContent.peerDependencies, "effect");
@@ -1206,9 +1219,20 @@ function makeTypeScriptUtils(ts) {
1206
1219
  exportsKeys
1207
1220
  };
1208
1221
  }
1209
- function resolveModulePattern(sourceFile, pattern) {
1222
+ function resolveModulePattern(program, sourceFile, pattern) {
1210
1223
  if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
1211
- const packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
1224
+ let packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
1225
+ if (!packageJsonScope && hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath) && hasProperty(ts, "getTemporaryModuleResolutionState") && isFunction2(ts.getTemporaryModuleResolutionState) && hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath)) {
1226
+ const temporaryModuleResolutionState = ts.getTemporaryModuleResolutionState(
1227
+ void 0,
1228
+ program,
1229
+ program.getCompilerOptions()
1230
+ );
1231
+ packageJsonScope = parsePackageContentNameAndVersionFromScope({
1232
+ ...sourceFile,
1233
+ packageJsonScope: ts.getPackageScopeForPath(sourceFile.fileName, temporaryModuleResolutionState)
1234
+ });
1235
+ }
1212
1236
  const referencedPackages = [];
1213
1237
  for (const statement of sourceFile.statements) {
1214
1238
  if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
@@ -1746,18 +1770,21 @@ var getApplicableRefactors = fn("LSP.getApplicableRefactors")(function* (refacto
1746
1770
  const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
1747
1771
  const effectRefactors = [];
1748
1772
  for (const refactor of refactors2) {
1749
- const result = yield* option(refactor.apply(sourceFile, textRange));
1750
- if (isSome2(result)) {
1751
- effectRefactors.push({
1752
- name: refactorNameToFullyQualifiedName(refactor.name),
1753
- description: refactor.description,
1754
- actions: [{
1773
+ yield* pipe(
1774
+ refactor.apply(sourceFile, textRange),
1775
+ map3(
1776
+ (result) => effectRefactors.push({
1755
1777
  name: refactorNameToFullyQualifiedName(refactor.name),
1756
- description: result.value.description,
1757
- kind: result.value.kind
1758
- }]
1759
- });
1760
- }
1778
+ description: refactor.description,
1779
+ actions: [{
1780
+ name: refactorNameToFullyQualifiedName(refactor.name),
1781
+ description: result.description,
1782
+ kind: result.kind
1783
+ }]
1784
+ })
1785
+ ),
1786
+ ignore
1787
+ );
1761
1788
  }
1762
1789
  return effectRefactors;
1763
1790
  });
@@ -3226,6 +3253,55 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
3226
3253
  "TypeParser.extendsContextTag",
3227
3254
  (atLocation) => atLocation
3228
3255
  );
3256
+ const extendsEffectTag = cachedBy(
3257
+ fn("TypeParser.extendsEffectTag")(function* (atLocation) {
3258
+ if (!atLocation.name) {
3259
+ return yield* typeParserIssue("Class has no name", void 0, atLocation);
3260
+ }
3261
+ const heritageClauses = atLocation.heritageClauses;
3262
+ if (!heritageClauses) {
3263
+ return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
3264
+ }
3265
+ for (const heritageClause of heritageClauses) {
3266
+ for (const typeX of heritageClause.types) {
3267
+ if (ts.isExpressionWithTypeArguments(typeX)) {
3268
+ const wholeCall = typeX.expression;
3269
+ if (ts.isCallExpression(wholeCall)) {
3270
+ const effectTagCall = wholeCall.expression;
3271
+ if (ts.isCallExpression(effectTagCall) && wholeCall.typeArguments && wholeCall.typeArguments.length > 0) {
3272
+ const effectTagIdentifier = effectTagCall.expression;
3273
+ const selfTypeNode = wholeCall.typeArguments[0];
3274
+ if (ts.isPropertyAccessExpression(effectTagIdentifier) && ts.isIdentifier(effectTagIdentifier.name) && ts.idText(effectTagIdentifier.name) === "Tag") {
3275
+ const parsedEffectModule = yield* pipe(
3276
+ importedEffectModule(effectTagIdentifier.expression),
3277
+ option
3278
+ );
3279
+ if (isSome2(parsedEffectModule)) {
3280
+ const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
3281
+ if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
3282
+ const type = typeChecker.getTypeOfSymbol(classSym);
3283
+ const tagType = yield* contextTag(type, atLocation);
3284
+ return {
3285
+ className: atLocation.name,
3286
+ selfTypeNode,
3287
+ keyStringLiteral: ts.isStringLiteral(effectTagCall.arguments[0]) ? effectTagCall.arguments[0] : void 0,
3288
+ args: effectTagCall.arguments,
3289
+ Identifier: tagType.Identifier,
3290
+ Service: tagType.Service,
3291
+ Tag: parsedEffectModule.value
3292
+ };
3293
+ }
3294
+ }
3295
+ }
3296
+ }
3297
+ }
3298
+ }
3299
+ }
3300
+ return yield* typeParserIssue("Class does not extend Effect.Tag", void 0, atLocation);
3301
+ }),
3302
+ "TypeParser.extendsEffectTag",
3303
+ (atLocation) => atLocation
3304
+ );
3229
3305
  const extendsEffectService = cachedBy(
3230
3306
  fn("TypeParser.extendsEffectService")(function* (atLocation) {
3231
3307
  if (!atLocation.name) {
@@ -3308,6 +3384,7 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
3308
3384
  pipeCall,
3309
3385
  scopeType,
3310
3386
  promiseLike,
3387
+ extendsEffectTag,
3311
3388
  extendsEffectService,
3312
3389
  extendsContextTag,
3313
3390
  extendsSchemaClass,
@@ -3520,6 +3597,7 @@ var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
3520
3597
  if (!ts.isClassDeclaration(node)) return yield* fail("not a class declaration");
3521
3598
  const { Service, accessors: accessors2, className } = yield* pipe(
3522
3599
  typeParser.extendsEffectService(node),
3600
+ orElse2(() => map3(typeParser.extendsEffectTag(node), (_) => ({ accessors: true, ..._ }))),
3523
3601
  orElse2(() => fail("not a class extending Effect.Service call"))
3524
3602
  );
3525
3603
  if (accessors2 !== true) return yield* fail("accessors are not enabled in the Effect.Service call");
@@ -3962,7 +4040,7 @@ var importFromBarrel = createDiagnostic({
3962
4040
  const program = yield* service(TypeScriptProgram);
3963
4041
  const packageNamesToCheck = flatten(
3964
4042
  languageServicePluginOptions.namespaceImportPackages.map(
3965
- (packageName) => tsUtils.resolveModulePattern(sourceFile, packageName)
4043
+ (packageName) => tsUtils.resolveModulePattern(program, sourceFile, packageName)
3966
4044
  )
3967
4045
  );
3968
4046
  const isImportedFromBarrelExport = (element) => {
@@ -5700,7 +5778,7 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
5700
5778
  const collectImportCache = fn("TypeScriptApi")(
5701
5779
  function* (packagePatterns, kind, topLevelNamedReexports) {
5702
5780
  for (const packagePattern of packagePatterns) {
5703
- const packageNames = tsUtils.resolveModulePattern(fromSourceFile, packagePattern);
5781
+ const packageNames = tsUtils.resolveModulePattern(program, fromSourceFile, packagePattern);
5704
5782
  for (const packageName of packageNames) {
5705
5783
  const packageInfo = getPackageInfo(fromSourceFile.fileName, packageName);
5706
5784
  if (!packageInfo) continue;
@@ -10821,7 +10899,7 @@ function findInnermostGraphEdge(graph, kind, key) {
10821
10899
  }
10822
10900
  }
10823
10901
  function escapeMermaid(text) {
10824
- return text.replace(/"/mg, "#quot;").replace(/\n/mg, " ");
10902
+ return text.replace(/"/mg, "#quot;").replace(/\n/mg, " ").replace(/</mg, "#lt;").replace(/>/mg, "#gt;");
10825
10903
  }
10826
10904
  function processNodeMermaid(graph, ctx, ctxL) {
10827
10905
  return gen(function* () {
@@ -11678,12 +11756,35 @@ var layerMagic = createRefactor({
11678
11756
  (_) => succeed((_.flags & ts.TypeFlags.Never) !== 0)
11679
11757
  );
11680
11758
  }
11681
- const typeReferences = pipe(
11759
+ const previouslyProvided = yield* pipe(
11760
+ typeParser.layerType(typeChecker.getTypeAtLocation(atLocation), atLocation),
11761
+ map3((_) => _.ROut),
11762
+ option
11763
+ );
11764
+ const [existingBefore, newlyIntroduced] = pipe(
11682
11765
  fromIterable(memory.values()),
11683
11766
  sort(typeCheckerUtils.deterministicTypeOrder),
11767
+ partition(
11768
+ (_) => isNone2(previouslyProvided) || typeChecker.isTypeAssignableTo(_, previouslyProvided.value)
11769
+ )
11770
+ );
11771
+ const typeReferences = pipe(
11772
+ newlyIntroduced,
11684
11773
  map5((_) => typeChecker.typeToTypeNode(_, void 0, ts.NodeBuilderFlags.NoTruncation)),
11685
11774
  filter((_) => !!_)
11686
11775
  );
11776
+ const providesUnion = typeReferences.length === 0 ? ts.factory.createTypeReferenceNode("never") : ts.factory.createUnionTypeNode(typeReferences);
11777
+ const typeStrings = pipe(
11778
+ existingBefore,
11779
+ map5((_) => typeChecker.typeToString(_, void 0, ts.TypeFormatFlags.NoTruncation)),
11780
+ filter((_) => !!_)
11781
+ );
11782
+ const unionWithComment = typeStrings.length === 0 ? providesUnion : ts.addSyntheticTrailingComment(
11783
+ providesUnion,
11784
+ ts.SyntaxKind.MultiLineCommentTrivia,
11785
+ " " + typeStrings.join(" | ") + " ",
11786
+ false
11787
+ );
11687
11788
  const newDeclaration = ts.factory.createAsExpression(
11688
11789
  ts.factory.createAsExpression(
11689
11790
  ts.factory.createArrayLiteralExpression(extractedLayers.map((_) => _.node)),
@@ -11691,9 +11792,7 @@ var layerMagic = createRefactor({
11691
11792
  ),
11692
11793
  ts.factory.createTypeReferenceNode(
11693
11794
  ts.factory.createQualifiedName(ts.factory.createIdentifier(layerIdentifier), "Layer"),
11694
- typeReferences.length === 0 ? [
11695
- ts.factory.createTypeReferenceNode("never")
11696
- ] : [ts.factory.createUnionTypeNode(typeReferences)]
11795
+ [unionWithComment]
11697
11796
  )
11698
11797
  );
11699
11798
  changeTracker.replaceNode(sourceFile, atLocation, newDeclaration, {
@@ -13061,6 +13160,7 @@ var renameKeyStrings = (sourceFile, position, _findInStrings, _findInComments, _
13061
13160
  const baseIdentifier = yield* pipe(
13062
13161
  map3(typeParser.extendsContextTag(parentClass), (_) => [_.keyStringLiteral]),
13063
13162
  orElse2(() => map3(typeParser.extendsEffectService(parentClass), (_) => [_.keyStringLiteral])),
13163
+ orElse2(() => map3(typeParser.extendsEffectTag(parentClass), (_) => [_.keyStringLiteral])),
13064
13164
  orElse2(
13065
13165
  () => map3(typeParser.extendsSchemaTaggedClass(parentClass), (_) => [_.keyStringLiteral, _.tagStringLiteral])
13066
13166
  ),