@effect/language-service 0.36.0 → 0.37.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.
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/effect-lsp-patch-utils.ts
21
21
  var effect_lsp_patch_utils_exports = {};
22
22
  __export(effect_lsp_patch_utils_exports, {
23
- checkSourceFileWorker: () => checkSourceFileWorker
23
+ appendMetadataRelationError: () => appendMetadataRelationError,
24
+ checkSourceFileWorker: () => checkSourceFileWorker,
25
+ clearSourceFileEffectMetadata: () => clearSourceFileEffectMetadata
24
26
  });
25
27
  module.exports = __toCommonJS(effect_lsp_patch_utils_exports);
26
28
 
@@ -331,10 +333,10 @@ var string = (str) => {
331
333
  }
332
334
  return optimize(h);
333
335
  };
334
- var structureKeys = (o, keys) => {
336
+ var structureKeys = (o, keys2) => {
335
337
  let h = 12289;
336
- for (let i = 0; i < keys.length; i++) {
337
- h ^= pipe(string(keys[i]), combine(hash(o[keys[i]])));
338
+ for (let i = 0; i < keys2.length; i++) {
339
+ h ^= pipe(string(keys2[i]), combine(hash(o[keys2[i]])));
338
340
  }
339
341
  return optimize(h);
340
342
  };
@@ -739,24 +741,17 @@ var isSome2 = isSome;
739
741
  var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : self);
740
742
  var fromNullable = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
741
743
 
742
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Iterable.js
743
- var findFirst = /* @__PURE__ */ dual(2, (self, f) => {
744
- let i = 0;
745
- for (const a of self) {
746
- const o = f(a, i);
747
- if (isBoolean(o)) {
748
- if (o) {
749
- return some2(a);
750
- }
751
- } else {
752
- if (isSome2(o)) {
753
- return o;
754
- }
755
- }
756
- i++;
744
+ // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Record.js
745
+ var map2 = /* @__PURE__ */ dual(2, (self, f) => {
746
+ const out = {
747
+ ...self
748
+ };
749
+ for (const key of keys(self)) {
750
+ out[key] = f(self[key], key);
757
751
  }
758
- return none2();
752
+ return out;
759
753
  });
754
+ var keys = (self) => Object.keys(self);
760
755
 
761
756
  // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Array.js
762
757
  var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
@@ -776,7 +771,6 @@ var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
776
771
  });
777
772
  var headNonEmpty = /* @__PURE__ */ unsafeGet(0);
778
773
  var tailNonEmpty = (self) => self.slice(1);
779
- var findFirst2 = findFirst;
780
774
  var sort = /* @__PURE__ */ dual(2, (self, O) => {
781
775
  const out = Array.from(self);
782
776
  out.sort(O);
@@ -797,7 +791,7 @@ var intersectionWith = (isEquivalent) => {
797
791
  };
798
792
  var intersection = /* @__PURE__ */ intersectionWith(_equivalence);
799
793
  var empty = () => [];
800
- var map2 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
794
+ var map3 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
801
795
  var flatMap = /* @__PURE__ */ dual(2, (self, f) => {
802
796
  if (isEmptyReadonlyArray(self)) {
803
797
  return [];
@@ -935,6 +929,7 @@ var NanoFiber = class {
935
929
  _yielded = void 0;
936
930
  _services = {};
937
931
  _cache = {};
932
+ _perf = false;
938
933
  runLoop(nano) {
939
934
  let current = nano;
940
935
  while (true) {
@@ -958,6 +953,34 @@ var NanoFiber = class {
958
953
  return NanoYield;
959
954
  }
960
955
  };
956
+ var timings = {};
957
+ var timingsCount = {};
958
+ var WithSpanProto = {
959
+ ...PrimitiveProto,
960
+ [evaluate](fiber) {
961
+ const [fa, name] = this[args];
962
+ if (!fiber._perf) return fa;
963
+ const start = performance.now();
964
+ timingsCount[name] = (timingsCount[name] || 0) + 1;
965
+ return match(fa, {
966
+ onSuccess: (_) => {
967
+ const end = performance.now();
968
+ timings[name] = (timings[name] || 0) + (end - start);
969
+ return succeed(_);
970
+ },
971
+ onFailure: (_) => {
972
+ const end = performance.now();
973
+ timings[name] = (timings[name] || 0) + (end - start);
974
+ return fail(_);
975
+ }
976
+ });
977
+ }
978
+ };
979
+ var withSpan = (name) => (fa) => {
980
+ const nano = Object.create(WithSpanProto);
981
+ nano[args] = [fa, name];
982
+ return nano;
983
+ };
961
984
  var unsafeRun = (nano) => {
962
985
  const fiber = new NanoFiber();
963
986
  const result = fiber.runLoop(nano);
@@ -979,7 +1002,7 @@ var flatMap2 = dual(2, (fa, f) => {
979
1002
  nano[contA] = f;
980
1003
  return nano;
981
1004
  });
982
- var map3 = dual(2, (fa, f) => flatMap2(fa, (_) => succeed(f(_))));
1005
+ var map4 = dual(2, (fa, f) => flatMap2(fa, (_) => succeed(f(_))));
983
1006
  var SyncProto = {
984
1007
  ...PrimitiveProto,
985
1008
  [evaluate](fiber) {
@@ -1012,7 +1035,7 @@ var unsafeFromIterator = (iterator, initial) => {
1012
1035
  return nano;
1013
1036
  };
1014
1037
  var gen = (...args2) => suspend(() => unsafeFromIterator(args2[0]()));
1015
- var fn = (_) => (body) => (...args2) => suspend(() => unsafeFromIterator(body(...args2)));
1038
+ var fn = (_) => (body) => (...args2) => withSpan(_)(suspend(() => unsafeFromIterator(body(...args2))));
1016
1039
  var MatchProto = {
1017
1040
  ...PrimitiveProto,
1018
1041
  [evaluate](fiber) {
@@ -1138,7 +1161,7 @@ function parseDiagnosticSeverity(config) {
1138
1161
  pipe(
1139
1162
  Object.entries(config),
1140
1163
  filter(([key, value]) => isString(key) && isString(value)),
1141
- map2(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),
1164
+ map3(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),
1142
1165
  filter(
1143
1166
  ([_, value]) => value === "off" || value === "error" || value === "warning" || value === "message" || value === "suggestion"
1144
1167
  )
@@ -1156,8 +1179,10 @@ var defaults = {
1156
1179
  inlays: true,
1157
1180
  allowedDuplicatedPackages: [],
1158
1181
  namespaceImportPackages: [],
1182
+ topLevelNamedReexports: "ignore",
1159
1183
  barrelImportPackages: [],
1160
- topLevelNamedReexports: "ignore"
1184
+ importAliases: {},
1185
+ renames: true
1161
1186
  };
1162
1187
  function parse(config) {
1163
1188
  return {
@@ -1172,7 +1197,9 @@ function parse(config) {
1172
1197
  allowedDuplicatedPackages: isObject(config) && hasProperty(config, "allowedDuplicatedPackages") && isArray(config.allowedDuplicatedPackages) && config.allowedDuplicatedPackages.every(isString) ? config.allowedDuplicatedPackages.map((_) => _.toLowerCase()) : defaults.allowedDuplicatedPackages,
1173
1198
  namespaceImportPackages: isObject(config) && hasProperty(config, "namespaceImportPackages") && isArray(config.namespaceImportPackages) && config.namespaceImportPackages.every(isString) ? config.namespaceImportPackages.map((_) => _.toLowerCase()) : defaults.namespaceImportPackages,
1174
1199
  barrelImportPackages: isObject(config) && hasProperty(config, "barrelImportPackages") && isArray(config.barrelImportPackages) && config.barrelImportPackages.every(isString) ? config.barrelImportPackages.map((_) => _.toLowerCase()) : defaults.barrelImportPackages,
1175
- topLevelNamedReexports: isObject(config) && hasProperty(config, "topLevelNamedReexports") && isString(config.topLevelNamedReexports) && ["ignore", "follow"].includes(config.topLevelNamedReexports.toLowerCase()) ? config.topLevelNamedReexports.toLowerCase() : defaults.topLevelNamedReexports
1200
+ importAliases: isObject(config) && hasProperty(config, "importAliases") && isRecord(config.importAliases) ? map2(config.importAliases, (value) => String(value)) : defaults.importAliases,
1201
+ topLevelNamedReexports: isObject(config) && hasProperty(config, "topLevelNamedReexports") && isString(config.topLevelNamedReexports) && ["ignore", "follow"].includes(config.topLevelNamedReexports.toLowerCase()) ? config.topLevelNamedReexports.toLowerCase() : defaults.topLevelNamedReexports,
1202
+ renames: isObject(config) && hasProperty(config, "renames") && isBoolean(config.renames) ? config.renames : defaults.renames
1176
1203
  };
1177
1204
  }
1178
1205
 
@@ -1236,7 +1263,7 @@ function makeTypeScriptUtils(ts) {
1236
1263
  return pipe(
1237
1264
  referencedPackages.concat(packageJsonScope?.referencedPackages || []),
1238
1265
  dedupe,
1239
- map2((packageName) => packageName.toLowerCase()),
1266
+ map3((packageName) => packageName.toLowerCase()),
1240
1267
  filter(
1241
1268
  (packageName) => pattern.endsWith("*") && packageName.startsWith(pattern.toLowerCase().substring(0, pattern.length - 1))
1242
1269
  )
@@ -1352,7 +1379,7 @@ function makeTypeScriptUtils(ts) {
1352
1379
  fnCall = ts.factory.createCallExpression(
1353
1380
  fnCall,
1354
1381
  void 0,
1355
- [ts.factory.createStringLiteral(fnName.text)]
1382
+ [ts.factory.createStringLiteral(ts.idText(fnName))]
1356
1383
  );
1357
1384
  }
1358
1385
  return tryPreserveDeclarationSemantics(
@@ -1424,7 +1451,7 @@ function makeTypeScriptUtils(ts) {
1424
1451
  if (!namedBindings) continue;
1425
1452
  if (ts.isNamespaceImport(namedBindings)) {
1426
1453
  if (test(namedBindings.name, statement.moduleSpecifier, none2())) {
1427
- return namedBindings.name.text;
1454
+ return ts.idText(namedBindings.name);
1428
1455
  }
1429
1456
  } else if (ts.isNamedImports(namedBindings)) {
1430
1457
  for (const importSpecifier of namedBindings.elements) {
@@ -1432,7 +1459,7 @@ function makeTypeScriptUtils(ts) {
1432
1459
  orElse(() => some2(importSpecifier.name))
1433
1460
  );
1434
1461
  if (test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
1435
- return importSpecifier.name.text;
1462
+ return ts.idText(importSpecifier.name);
1436
1463
  }
1437
1464
  }
1438
1465
  }
@@ -1445,7 +1472,7 @@ function makeTypeScriptUtils(ts) {
1445
1472
  if (isNone2(importProperty) && ts.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
1446
1473
  return true;
1447
1474
  }
1448
- if (isSome2(importProperty) && ts.isIdentifier(importProperty.value) && importProperty.value.text === moduleName && ts.isStringLiteral(fromModule) && fromModule.text === packageName) {
1475
+ if (isSome2(importProperty) && ts.isIdentifier(importProperty.value) && ts.idText(importProperty.value) === moduleName && ts.isStringLiteral(fromModule) && fromModule.text === packageName) {
1449
1476
  return true;
1450
1477
  }
1451
1478
  return false;
@@ -1943,7 +1970,7 @@ var getEditsForCodegen = fn("LSP.getEditsForCodegen")(function* (codegens2, sour
1943
1970
  const edit = yield* codegen.apply(sourceFile, range);
1944
1971
  const updateHashComment = pipe(
1945
1972
  service(ChangeTracker),
1946
- map3((changeTracker) => {
1973
+ map4((changeTracker) => {
1947
1974
  changeTracker.deleteRange(sourceFile, range);
1948
1975
  changeTracker.insertText(sourceFile, range.pos, `${codegen.name}:${edit.hash}`);
1949
1976
  })
@@ -1957,191 +1984,17 @@ var getEditsForCodegen = fn("LSP.getEditsForCodegen")(function* (codegens2, sour
1957
1984
  ignore: updateHashComment
1958
1985
  };
1959
1986
  });
1987
+ var getEffectLspPatchSourceFileMetadata = (sourceFile) => {
1988
+ return sourceFile["@effect-lsp-patch/metadata"];
1989
+ };
1990
+ var getOrDefaultEffectLspPatchSourceFileMetadata = (sourceFile) => {
1991
+ return getEffectLspPatchSourceFileMetadata(sourceFile) || (sourceFile["@effect-lsp-patch/metadata"] = {
1992
+ relationErrors: []
1993
+ });
1994
+ };
1960
1995
 
1961
1996
  // src/core/TypeCheckerApi.ts
1962
1997
  var TypeCheckerApi = Tag("TypeChecker");
1963
- var deterministicTypeOrder = gen(function* () {
1964
- const typeChecker = yield* service(TypeCheckerApi);
1965
- return make((a, b) => {
1966
- const aName = typeChecker.typeToString(a);
1967
- const bName = typeChecker.typeToString(b);
1968
- if (aName < bName) return -1;
1969
- if (aName > bName) return 1;
1970
- return 0;
1971
- });
1972
- });
1973
- var CannotFindAncestorConvertibleDeclarationError = class {
1974
- constructor(node) {
1975
- this.node = node;
1976
- }
1977
- _tag = "@effect/language-service/CannotFindAncestorConvertibleDeclarationError";
1978
- };
1979
- var getAncestorConvertibleDeclaration = fn(
1980
- "TypeCheckerApi.getAncestorConvertibleDeclaration"
1981
- )(function* (node) {
1982
- const ts = yield* service(TypeScriptApi);
1983
- let current = node;
1984
- while (current) {
1985
- if (ts.isFunctionDeclaration(current) || ts.isFunctionExpression(current) || ts.isArrowFunction(current) || ts.isMethodDeclaration(current)) {
1986
- return current;
1987
- }
1988
- current = current.parent;
1989
- }
1990
- return yield* fail(new CannotFindAncestorConvertibleDeclarationError(node));
1991
- });
1992
- var CannotInferReturnTypeFromEmptyBody = class {
1993
- constructor(declaration) {
1994
- this.declaration = declaration;
1995
- }
1996
- _tag = "@effect/language-service/CannotInferReturnTypeFromEmptyBody";
1997
- };
1998
- var CannotInferReturnType = class {
1999
- constructor(declaration) {
2000
- this.declaration = declaration;
2001
- }
2002
- _tag = "@effect/language-service/CannotInferReturnType";
2003
- };
2004
- var getInferredReturnType = fn("TypeCheckerApi.getInferredReturnType")(function* (declaration) {
2005
- const typeChecker = yield* service(TypeCheckerApi);
2006
- const ts = yield* service(TypeScriptApi);
2007
- if (!declaration.body) {
2008
- return yield* fail(
2009
- new CannotInferReturnTypeFromEmptyBody(declaration)
2010
- );
2011
- }
2012
- let returnType;
2013
- if (typeChecker.isImplementationOfOverload(declaration)) {
2014
- const signatures = typeChecker.getSignaturesOfType(
2015
- typeChecker.getTypeAtLocation(declaration),
2016
- ts.SignatureKind.Call
2017
- );
2018
- if (signatures.length > 1) {
2019
- returnType = typeChecker.getUnionType(
2020
- signatures.map((s) => typeChecker.getReturnTypeOfSignature(s)).filter((_) => !!_)
2021
- );
2022
- }
2023
- }
2024
- if (!returnType) {
2025
- const signature = typeChecker.getSignatureFromDeclaration(declaration);
2026
- if (signature) {
2027
- const typePredicate = typeChecker.getTypePredicateOfSignature(signature);
2028
- if (typePredicate && typePredicate.type) {
2029
- return typePredicate.type;
2030
- } else {
2031
- returnType = typeChecker.getReturnTypeOfSignature(signature);
2032
- }
2033
- }
2034
- }
2035
- if (!returnType) {
2036
- return yield* fail(
2037
- new CannotInferReturnType(declaration)
2038
- );
2039
- }
2040
- return returnType;
2041
- });
2042
- var expectedAndRealType = cachedBy(
2043
- fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
2044
- const typeChecker = yield* service(TypeCheckerApi);
2045
- const ts = yield* service(TypeScriptApi);
2046
- const result = [];
2047
- const nodeToVisit = [sourceFile];
2048
- const appendNodeToVisit = (node) => {
2049
- nodeToVisit.push(node);
2050
- return void 0;
2051
- };
2052
- while (nodeToVisit.length > 0) {
2053
- const node = nodeToVisit.shift();
2054
- if (ts.isVariableDeclaration(node) && node.initializer) {
2055
- const expectedType = typeChecker.getTypeAtLocation(node.name);
2056
- const realType = typeChecker.getTypeAtLocation(node.initializer);
2057
- result.push([node.name, expectedType, node.initializer, realType]);
2058
- appendNodeToVisit(node.initializer);
2059
- continue;
2060
- } else if (ts.isCallExpression(node)) {
2061
- const resolvedSignature = typeChecker.getResolvedSignature(node);
2062
- if (resolvedSignature) {
2063
- resolvedSignature.parameters.map((parameter, index) => {
2064
- const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
2065
- const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
2066
- result.push([
2067
- node.arguments[index],
2068
- expectedType,
2069
- node.arguments[index],
2070
- realType
2071
- ]);
2072
- });
2073
- }
2074
- ts.forEachChild(node, appendNodeToVisit);
2075
- continue;
2076
- } else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
2077
- const parent = node.parent;
2078
- if (ts.isObjectLiteralElement(parent)) {
2079
- if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
2080
- const type = typeChecker.getContextualType(parent.parent);
2081
- if (type) {
2082
- const name = ts.isIdentifier(node) ? ts.idText(node) : ts.isStringLiteral(node) ? node.text : void 0;
2083
- if (name) {
2084
- const symbol3 = typeChecker.getPropertyOfType(type, name);
2085
- if (symbol3) {
2086
- const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
2087
- const realType = typeChecker.getTypeAtLocation(node);
2088
- result.push([node, expectedType, node, realType]);
2089
- }
2090
- }
2091
- }
2092
- }
2093
- }
2094
- ts.forEachChild(node, appendNodeToVisit);
2095
- continue;
2096
- } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
2097
- const expectedType = typeChecker.getTypeAtLocation(node.left);
2098
- const realType = typeChecker.getTypeAtLocation(node.right);
2099
- result.push([node.left, expectedType, node.right, realType]);
2100
- appendNodeToVisit(node.right);
2101
- continue;
2102
- } else if (ts.isReturnStatement(node) && node.expression) {
2103
- const parentDeclaration = yield* option(getAncestorConvertibleDeclaration(node));
2104
- if (isSome2(parentDeclaration)) {
2105
- const expectedType = yield* option(getInferredReturnType(parentDeclaration.value));
2106
- const realType = typeChecker.getTypeAtLocation(node.expression);
2107
- if (isSome2(expectedType)) {
2108
- result.push([node, expectedType.value, node, realType]);
2109
- }
2110
- }
2111
- ts.forEachChild(node, appendNodeToVisit);
2112
- continue;
2113
- } else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
2114
- const body = node.body;
2115
- const expectedType = typeChecker.getContextualType(body);
2116
- const realType = typeChecker.getTypeAtLocation(body);
2117
- if (expectedType) {
2118
- result.push([body, expectedType, body, realType]);
2119
- }
2120
- ts.forEachChild(body, appendNodeToVisit);
2121
- continue;
2122
- } else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
2123
- const body = node.body;
2124
- const expectedType = yield* option(getInferredReturnType(node));
2125
- const realType = typeChecker.getTypeAtLocation(body);
2126
- if (isSome2(expectedType)) {
2127
- result.push([body, expectedType.value, body, realType]);
2128
- }
2129
- ts.forEachChild(body, appendNodeToVisit);
2130
- continue;
2131
- } else if (ts.isSatisfiesExpression(node)) {
2132
- const expectedType = typeChecker.getTypeAtLocation(node.type);
2133
- const realType = typeChecker.getTypeAtLocation(node.expression);
2134
- result.push([node.expression, expectedType, node.expression, realType]);
2135
- appendNodeToVisit(node.expression);
2136
- continue;
2137
- }
2138
- ts.forEachChild(node, appendNodeToVisit);
2139
- }
2140
- return result;
2141
- }),
2142
- "TypeCheckerApi.expectedAndRealType",
2143
- (sourceFile) => sourceFile
2144
- );
2145
1998
  function makeResolveExternalModuleName(typeChecker) {
2146
1999
  if (!(hasProperty(typeChecker, "resolveExternalModuleName") && isFunction(typeChecker.resolveExternalModuleName))) {
2147
2000
  return;
@@ -2254,12 +2107,161 @@ function makeTypeCheckerUtils(ts, typeChecker) {
2254
2107
  };
2255
2108
  }
2256
2109
  );
2110
+ const deterministicTypeOrder = make((a, b) => {
2111
+ const aName = typeChecker.typeToString(a);
2112
+ const bName = typeChecker.typeToString(b);
2113
+ if (aName < bName) return -1;
2114
+ if (aName > bName) return 1;
2115
+ return 0;
2116
+ });
2117
+ const getAncestorConvertibleDeclaration = (node) => {
2118
+ let current = node;
2119
+ while (current) {
2120
+ if (ts.isFunctionDeclaration(current) || ts.isFunctionExpression(current) || ts.isArrowFunction(current) || ts.isMethodDeclaration(current)) {
2121
+ return current;
2122
+ }
2123
+ current = current.parent;
2124
+ }
2125
+ };
2126
+ const getInferredReturnType = (declaration) => {
2127
+ if (!declaration.body) {
2128
+ return;
2129
+ }
2130
+ let returnType;
2131
+ if (typeChecker.isImplementationOfOverload(declaration)) {
2132
+ const signatures = typeChecker.getSignaturesOfType(
2133
+ typeChecker.getTypeAtLocation(declaration),
2134
+ ts.SignatureKind.Call
2135
+ );
2136
+ if (signatures.length > 1) {
2137
+ returnType = typeChecker.getUnionType(
2138
+ signatures.map((s) => typeChecker.getReturnTypeOfSignature(s)).filter((_) => !!_)
2139
+ );
2140
+ }
2141
+ }
2142
+ if (!returnType) {
2143
+ const signature = typeChecker.getSignatureFromDeclaration(declaration);
2144
+ if (signature) {
2145
+ const typePredicate = typeChecker.getTypePredicateOfSignature(signature);
2146
+ if (typePredicate && typePredicate.type) {
2147
+ return typePredicate.type;
2148
+ } else {
2149
+ returnType = typeChecker.getReturnTypeOfSignature(signature);
2150
+ }
2151
+ }
2152
+ }
2153
+ return returnType;
2154
+ };
2155
+ const expectedAndRealTypeCache = /* @__PURE__ */ new WeakMap();
2156
+ const expectedAndRealType = (sourceFile) => {
2157
+ const cached2 = expectedAndRealTypeCache.get(sourceFile);
2158
+ if (cached2) return cached2;
2159
+ const result = [];
2160
+ const nodeToVisit = [sourceFile];
2161
+ const appendNodeToVisit = (node) => {
2162
+ nodeToVisit.push(node);
2163
+ return void 0;
2164
+ };
2165
+ while (nodeToVisit.length > 0) {
2166
+ const node = nodeToVisit.shift();
2167
+ if (ts.isVariableDeclaration(node) && node.initializer) {
2168
+ const expectedType = typeChecker.getTypeAtLocation(node.name);
2169
+ const realType = typeChecker.getTypeAtLocation(node.initializer);
2170
+ result.push([node.name, expectedType, node.initializer, realType]);
2171
+ appendNodeToVisit(node.initializer);
2172
+ continue;
2173
+ } else if (ts.isCallExpression(node)) {
2174
+ const resolvedSignature = typeChecker.getResolvedSignature(node);
2175
+ if (resolvedSignature) {
2176
+ resolvedSignature.parameters.map((parameter, index) => {
2177
+ const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
2178
+ const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
2179
+ result.push([
2180
+ node.arguments[index],
2181
+ expectedType,
2182
+ node.arguments[index],
2183
+ realType
2184
+ ]);
2185
+ });
2186
+ }
2187
+ ts.forEachChild(node, appendNodeToVisit);
2188
+ continue;
2189
+ } else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
2190
+ const parent = node.parent;
2191
+ if (ts.isObjectLiteralElement(parent)) {
2192
+ if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
2193
+ const type = typeChecker.getContextualType(parent.parent);
2194
+ if (type) {
2195
+ const name = ts.isIdentifier(node) ? ts.idText(node) : ts.isStringLiteral(node) ? node.text : void 0;
2196
+ if (name) {
2197
+ const symbol3 = typeChecker.getPropertyOfType(type, name);
2198
+ if (symbol3) {
2199
+ const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
2200
+ const realType = typeChecker.getTypeAtLocation(node);
2201
+ result.push([node, expectedType, node, realType]);
2202
+ }
2203
+ }
2204
+ }
2205
+ }
2206
+ }
2207
+ ts.forEachChild(node, appendNodeToVisit);
2208
+ continue;
2209
+ } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
2210
+ const expectedType = typeChecker.getTypeAtLocation(node.left);
2211
+ const realType = typeChecker.getTypeAtLocation(node.right);
2212
+ result.push([node.left, expectedType, node.right, realType]);
2213
+ appendNodeToVisit(node.right);
2214
+ continue;
2215
+ } else if (ts.isReturnStatement(node) && node.expression) {
2216
+ const parentDeclaration = getAncestorConvertibleDeclaration(node);
2217
+ if (parentDeclaration) {
2218
+ const expectedType = getInferredReturnType(parentDeclaration);
2219
+ const realType = typeChecker.getTypeAtLocation(node.expression);
2220
+ if (expectedType) {
2221
+ result.push([node, expectedType, node, realType]);
2222
+ }
2223
+ }
2224
+ ts.forEachChild(node, appendNodeToVisit);
2225
+ continue;
2226
+ } else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
2227
+ const body = node.body;
2228
+ const expectedType = typeChecker.getContextualType(body);
2229
+ const realType = typeChecker.getTypeAtLocation(body);
2230
+ if (expectedType) {
2231
+ result.push([body, expectedType, body, realType]);
2232
+ }
2233
+ ts.forEachChild(body, appendNodeToVisit);
2234
+ continue;
2235
+ } else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
2236
+ const body = node.body;
2237
+ const expectedType = getInferredReturnType(node);
2238
+ const realType = typeChecker.getTypeAtLocation(body);
2239
+ if (expectedType) {
2240
+ result.push([body, expectedType, body, realType]);
2241
+ }
2242
+ ts.forEachChild(body, appendNodeToVisit);
2243
+ continue;
2244
+ } else if (ts.isSatisfiesExpression(node)) {
2245
+ const expectedType = typeChecker.getTypeAtLocation(node.type);
2246
+ const realType = typeChecker.getTypeAtLocation(node.expression);
2247
+ result.push([node.expression, expectedType, node.expression, realType]);
2248
+ appendNodeToVisit(node.expression);
2249
+ continue;
2250
+ }
2251
+ ts.forEachChild(node, appendNodeToVisit);
2252
+ }
2253
+ expectedAndRealTypeCache.set(sourceFile, result);
2254
+ return result;
2255
+ };
2257
2256
  return {
2258
2257
  isUnion,
2259
2258
  getTypeParameterAtPosition,
2260
2259
  getMissingTypeEntriesInTargetType,
2261
2260
  unrollUnionMembers,
2262
- appendToUniqueTypesMap
2261
+ appendToUniqueTypesMap,
2262
+ deterministicTypeOrder,
2263
+ getInferredReturnType,
2264
+ expectedAndRealType
2263
2265
  };
2264
2266
  }
2265
2267
 
@@ -2344,7 +2346,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2344
2346
  const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
2345
2347
  return invariantTypeArgument(propertyType);
2346
2348
  };
2347
- const effectVarianceStruct = (type, atLocation) => map3(
2349
+ const effectVarianceStruct = (type, atLocation) => map4(
2348
2350
  all(
2349
2351
  varianceStructCovariantType(type, atLocation, "_A"),
2350
2352
  varianceStructCovariantType(type, atLocation, "_E"),
@@ -2352,7 +2354,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2352
2354
  ),
2353
2355
  ([A, E, R]) => ({ A, E, R })
2354
2356
  );
2355
- const layerVarianceStruct = (type, atLocation) => map3(
2357
+ const layerVarianceStruct = (type, atLocation) => map4(
2356
2358
  all(
2357
2359
  varianceStructContravariantType(type, atLocation, "_ROut"),
2358
2360
  varianceStructCovariantType(type, atLocation, "_E"),
@@ -2491,6 +2493,21 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2491
2493
  "TypeParser.importedEffectModule",
2492
2494
  (node) => node
2493
2495
  );
2496
+ const importedDataModule = cachedBy(
2497
+ fn("TypeParser.importedDataModule")(function* (node) {
2498
+ const type = typeChecker.getTypeAtLocation(node);
2499
+ const propertySymbol = typeChecker.getPropertyOfType(type, "TaggedError");
2500
+ if (!propertySymbol) {
2501
+ return yield* typeParserIssue("Type has no 'TaggedError' property", type, node);
2502
+ }
2503
+ if (!ts.isExpression(node)) {
2504
+ return yield* typeParserIssue("Node is not an expression", type, node);
2505
+ }
2506
+ return node;
2507
+ }),
2508
+ "TypeParser.importedDataModule",
2509
+ (node) => node
2510
+ );
2494
2511
  const effectGen = cachedBy(
2495
2512
  function(node) {
2496
2513
  if (!ts.isCallExpression(node)) {
@@ -2510,12 +2527,12 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2510
2527
  return typeParserIssue("Node is not a property access expression", void 0, node);
2511
2528
  }
2512
2529
  const propertyAccess = node.expression;
2513
- if (propertyAccess.name.text !== "gen") {
2530
+ if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "gen")) {
2514
2531
  return typeParserIssue("Call expression name is not 'gen'", void 0, node);
2515
2532
  }
2516
2533
  return pipe(
2517
2534
  importedEffectModule(propertyAccess.expression),
2518
- map3((effectModule) => ({
2535
+ map4((effectModule) => ({
2519
2536
  node,
2520
2537
  effectModule,
2521
2538
  generatorFunction,
@@ -2554,7 +2571,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2554
2571
  );
2555
2572
  }
2556
2573
  const propertyAccess = node.expression;
2557
- if (propertyAccess.name.text !== "fnUntraced") {
2574
+ if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "fnUntraced")) {
2558
2575
  return typeParserIssue(
2559
2576
  "Call expression name is not 'fnUntraced'",
2560
2577
  void 0,
@@ -2563,7 +2580,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2563
2580
  }
2564
2581
  return pipe(
2565
2582
  importedEffectModule(propertyAccess.expression),
2566
- map3((effectModule) => ({
2583
+ map4((effectModule) => ({
2567
2584
  node,
2568
2585
  effectModule,
2569
2586
  generatorFunction,
@@ -2607,7 +2624,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2607
2624
  );
2608
2625
  }
2609
2626
  const propertyAccess = expressionToTest;
2610
- if (propertyAccess.name.text !== "fn") {
2627
+ if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "fn")) {
2611
2628
  return typeParserIssue(
2612
2629
  "Call expression name is not 'fn'",
2613
2630
  void 0,
@@ -2616,7 +2633,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2616
2633
  }
2617
2634
  return pipe(
2618
2635
  importedEffectModule(propertyAccess.expression),
2619
- map3((effectModule) => ({
2636
+ map4((effectModule) => ({
2620
2637
  node,
2621
2638
  generatorFunction,
2622
2639
  effectModule,
@@ -2690,7 +2707,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2690
2707
  "TypeParser.unnecessaryEffectGen",
2691
2708
  (node) => node
2692
2709
  );
2693
- const effectSchemaVarianceStruct = (type, atLocation) => map3(
2710
+ const effectSchemaVarianceStruct = (type, atLocation) => map4(
2694
2711
  all(
2695
2712
  varianceStructInvariantType(type, atLocation, "_A"),
2696
2713
  varianceStructInvariantType(type, atLocation, "_I"),
@@ -2722,7 +2739,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2722
2739
  "TypeParser.effectSchemaType",
2723
2740
  (type) => type
2724
2741
  );
2725
- const contextTagVarianceStruct = (type, atLocation) => map3(
2742
+ const contextTagVarianceStruct = (type, atLocation) => map4(
2726
2743
  all(
2727
2744
  varianceStructInvariantType(type, atLocation, "_Identifier"),
2728
2745
  varianceStructInvariantType(type, atLocation, "_Service")
@@ -2761,7 +2778,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2761
2778
  kind: "pipeable"
2762
2779
  });
2763
2780
  }
2764
- if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "pipe" && node.arguments.length > 0) {
2781
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && ts.idText(node.expression) === "pipe" && node.arguments.length > 0) {
2765
2782
  const [subject, ...args2] = node.arguments;
2766
2783
  return succeed({ node, subject, args: args2, kind: "pipe" });
2767
2784
  }
@@ -2886,7 +2903,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2886
2903
  for (const typeX of heritageClause.types) {
2887
2904
  if (ts.isExpressionWithTypeArguments(typeX)) {
2888
2905
  const expression = typeX.expression;
2889
- if (ts.isCallExpression(expression)) {
2906
+ if (ts.isCallExpression(expression) && expression.arguments.length > 0) {
2890
2907
  const schemaTaggedClassTCall = expression.expression;
2891
2908
  if (ts.isCallExpression(schemaTaggedClassTCall) && schemaTaggedClassTCall.typeArguments && schemaTaggedClassTCall.typeArguments.length > 0) {
2892
2909
  const selfTypeNode = schemaTaggedClassTCall.typeArguments[0];
@@ -2900,6 +2917,8 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2900
2917
  return {
2901
2918
  className: atLocation.name,
2902
2919
  selfTypeNode,
2920
+ keyStringLiteral: schemaTaggedClassTCall.arguments.length > 0 && ts.isStringLiteral(schemaTaggedClassTCall.arguments[0]) ? schemaTaggedClassTCall.arguments[0] : void 0,
2921
+ tagStringLiteral: expression.arguments.length > 0 && ts.isStringLiteral(expression.arguments[0]) ? expression.arguments[0] : void 0,
2903
2922
  Schema: parsedSchemaModule.value
2904
2923
  };
2905
2924
  }
@@ -2941,6 +2960,8 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2941
2960
  return {
2942
2961
  className: atLocation.name,
2943
2962
  selfTypeNode,
2963
+ keyStringLiteral: schemaTaggedErrorTCall.arguments.length > 0 && ts.isStringLiteral(schemaTaggedErrorTCall.arguments[0]) ? schemaTaggedErrorTCall.arguments[0] : void 0,
2964
+ tagStringLiteral: expression.arguments.length > 0 && ts.isStringLiteral(expression.arguments[0]) ? expression.arguments[0] : void 0,
2944
2965
  Schema: parsedSchemaModule.value
2945
2966
  };
2946
2967
  }
@@ -2955,6 +2976,82 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2955
2976
  "TypeParser.extendsSchemaTaggedError",
2956
2977
  (atLocation) => atLocation
2957
2978
  );
2979
+ const extendsDataTaggedError = cachedBy(
2980
+ fn("TypeParser.extendsDataTaggedError")(function* (atLocation) {
2981
+ if (!atLocation.name) {
2982
+ return yield* typeParserIssue("Class has no name", void 0, atLocation);
2983
+ }
2984
+ const heritageClauses = atLocation.heritageClauses;
2985
+ if (!heritageClauses) {
2986
+ return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
2987
+ }
2988
+ for (const heritageClause of heritageClauses) {
2989
+ for (const typeX of heritageClause.types) {
2990
+ if (ts.isExpressionWithTypeArguments(typeX)) {
2991
+ const expression = typeX.expression;
2992
+ if (ts.isCallExpression(expression)) {
2993
+ const dataTaggedErrorCall = expression;
2994
+ const dataIdentifier = dataTaggedErrorCall.expression;
2995
+ if (ts.isPropertyAccessExpression(dataIdentifier) && ts.isIdentifier(dataIdentifier.name) && ts.idText(dataIdentifier.name) === "TaggedError") {
2996
+ const parsedDataModule = yield* pipe(
2997
+ importedDataModule(dataIdentifier.expression),
2998
+ option
2999
+ );
3000
+ if (isSome2(parsedDataModule)) {
3001
+ return {
3002
+ className: atLocation.name,
3003
+ keyStringLiteral: dataTaggedErrorCall.arguments.length > 0 && ts.isStringLiteral(dataTaggedErrorCall.arguments[0]) ? dataTaggedErrorCall.arguments[0] : void 0,
3004
+ Data: parsedDataModule.value
3005
+ };
3006
+ }
3007
+ }
3008
+ }
3009
+ }
3010
+ }
3011
+ }
3012
+ return yield* typeParserIssue("Class does not extend Data.TaggedError", void 0, atLocation);
3013
+ }),
3014
+ "TypeParser.extendsDataTaggedError",
3015
+ (atLocation) => atLocation
3016
+ );
3017
+ const extendsDataTaggedClass = cachedBy(
3018
+ fn("TypeParser.extendsDataTaggedClass")(function* (atLocation) {
3019
+ if (!atLocation.name) {
3020
+ return yield* typeParserIssue("Class has no name", void 0, atLocation);
3021
+ }
3022
+ const heritageClauses = atLocation.heritageClauses;
3023
+ if (!heritageClauses) {
3024
+ return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
3025
+ }
3026
+ for (const heritageClause of heritageClauses) {
3027
+ for (const typeX of heritageClause.types) {
3028
+ if (ts.isExpressionWithTypeArguments(typeX)) {
3029
+ const expression = typeX.expression;
3030
+ if (ts.isCallExpression(expression)) {
3031
+ const dataTaggedClassCall = expression;
3032
+ const dataIdentifier = dataTaggedClassCall.expression;
3033
+ if (ts.isPropertyAccessExpression(dataIdentifier) && ts.isIdentifier(dataIdentifier.name) && ts.idText(dataIdentifier.name) === "TaggedClass") {
3034
+ const parsedDataModule = yield* pipe(
3035
+ importedDataModule(dataIdentifier.expression),
3036
+ option
3037
+ );
3038
+ if (isSome2(parsedDataModule)) {
3039
+ return {
3040
+ className: atLocation.name,
3041
+ keyStringLiteral: dataTaggedClassCall.arguments.length > 0 && ts.isStringLiteral(dataTaggedClassCall.arguments[0]) ? dataTaggedClassCall.arguments[0] : void 0,
3042
+ Data: parsedDataModule.value
3043
+ };
3044
+ }
3045
+ }
3046
+ }
3047
+ }
3048
+ }
3049
+ }
3050
+ return yield* typeParserIssue("Class does not extend Data.TaggedClass", void 0, atLocation);
3051
+ }),
3052
+ "TypeParser.extendsDataTaggedClass",
3053
+ (atLocation) => atLocation
3054
+ );
2958
3055
  const extendsSchemaTaggedRequest = cachedBy(
2959
3056
  fn("TypeParser.extendsSchemaTaggedRequest")(function* (atLocation) {
2960
3057
  if (!atLocation.name) {
@@ -2982,6 +3079,8 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
2982
3079
  return {
2983
3080
  className: atLocation.name,
2984
3081
  selfTypeNode,
3082
+ tagStringLiteral: expression.arguments.length > 0 && ts.isStringLiteral(expression.arguments[0]) ? expression.arguments[0] : void 0,
3083
+ keyStringLiteral: schemaTaggedRequestTCall.arguments.length > 0 && ts.isStringLiteral(schemaTaggedRequestTCall.arguments[0]) ? schemaTaggedRequestTCall.arguments[0] : void 0,
2985
3084
  Schema: parsedSchemaModule.value
2986
3085
  };
2987
3086
  }
@@ -3001,9 +3100,6 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
3001
3100
  if (!atLocation.name) {
3002
3101
  return yield* typeParserIssue("Class has no name", void 0, atLocation);
3003
3102
  }
3004
- const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
3005
- if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
3006
- const type = typeChecker.getTypeOfSymbol(classSym);
3007
3103
  const heritageClauses = atLocation.heritageClauses;
3008
3104
  if (!heritageClauses) {
3009
3105
  return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
@@ -3023,10 +3119,14 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
3023
3119
  option
3024
3120
  );
3025
3121
  if (isSome2(parsedContextModule)) {
3122
+ const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
3123
+ if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
3124
+ const type = typeChecker.getTypeOfSymbol(classSym);
3026
3125
  const tagType = yield* contextTag(type, atLocation);
3027
3126
  return {
3028
3127
  className: atLocation.name,
3029
3128
  selfTypeNode,
3129
+ keyStringLiteral: ts.isStringLiteral(contextTagCall.arguments[0]) ? contextTagCall.arguments[0] : void 0,
3030
3130
  args: contextTagCall.arguments,
3031
3131
  Identifier: tagType.Identifier,
3032
3132
  Tag: parsedContextModule.value
@@ -3048,9 +3148,6 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
3048
3148
  if (!atLocation.name) {
3049
3149
  return yield* typeParserIssue("Class has no name", void 0, atLocation);
3050
3150
  }
3051
- const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
3052
- if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
3053
- const type = typeChecker.getTypeOfSymbol(classSym);
3054
3151
  const heritageClauses = atLocation.heritageClauses;
3055
3152
  if (!heritageClauses) {
3056
3153
  return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
@@ -3065,6 +3162,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
3065
3162
  const effectServiceIdentifier = effectServiceCall.expression;
3066
3163
  const selfTypeNode = effectServiceCall.typeArguments[0];
3067
3164
  if (ts.isPropertyAccessExpression(effectServiceIdentifier) && ts.isIdentifier(effectServiceIdentifier.name) && ts.idText(effectServiceIdentifier.name) === "Service") {
3165
+ const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
3166
+ if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
3167
+ const type = typeChecker.getTypeOfSymbol(classSym);
3068
3168
  const parsedContextTag = yield* pipe(
3069
3169
  importedEffectModule(effectServiceIdentifier.expression),
3070
3170
  flatMap2(() => contextTag(type, atLocation)),
@@ -3091,6 +3191,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
3091
3191
  className: atLocation.name,
3092
3192
  selfTypeNode,
3093
3193
  args: wholeCall.arguments,
3194
+ keyStringLiteral: ts.isStringLiteral(wholeCall.arguments[0]) ? wholeCall.arguments[0] : void 0,
3094
3195
  options: wholeCall.arguments[1],
3095
3196
  accessors: accessors2,
3096
3197
  dependencies
@@ -3129,6 +3230,8 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
3129
3230
  extendsSchemaClass,
3130
3231
  extendsSchemaTaggedClass,
3131
3232
  extendsSchemaTaggedError,
3233
+ extendsDataTaggedError,
3234
+ extendsDataTaggedClass,
3132
3235
  extendsSchemaTaggedRequest
3133
3236
  };
3134
3237
  }
@@ -3261,13 +3364,13 @@ var effectInVoidSuccess = createDiagnostic({
3261
3364
  if (expectedEffect.A.flags & ts.TypeFlags.Void) {
3262
3365
  const voidValueTypes = typeCheckerUtils.unrollUnionMembers(realEffect.A);
3263
3366
  const voidedEffect = yield* firstSuccessOf(
3264
- voidValueTypes.map((_) => map3(typeParser.strictEffectType(_, node), () => _))
3367
+ voidValueTypes.map((_) => map4(typeParser.strictEffectType(_, node), () => _))
3265
3368
  );
3266
3369
  return { voidedEffect };
3267
3370
  }
3268
3371
  return yield* fail(typeParserIssue("expectedEffect success is not void"));
3269
3372
  });
3270
- const entries = yield* expectedAndRealType(sourceFile);
3373
+ const entries = typeCheckerUtils.expectedAndRealType(sourceFile);
3271
3374
  for (const [node, expectedType, valueNode, realType] of entries) {
3272
3375
  if (expectedType !== realType) {
3273
3376
  yield* pipe(
@@ -3277,7 +3380,7 @@ var effectInVoidSuccess = createDiagnostic({
3277
3380
  valueNode,
3278
3381
  realType
3279
3382
  ),
3280
- map3(({ voidedEffect }) => {
3383
+ map4(({ voidedEffect }) => {
3281
3384
  report(
3282
3385
  {
3283
3386
  location: node,
@@ -3372,7 +3475,7 @@ var genericEffectServices = createDiagnostic({
3372
3475
  for (const [type, reportAt] of typesToCheck) {
3373
3476
  yield* pipe(
3374
3477
  typeParser.contextTag(type, node),
3375
- map3(() => {
3478
+ map4(() => {
3376
3479
  report({
3377
3480
  location: reportAt,
3378
3481
  messageText: `Effect Services with type parameters are not supported because they cannot be properly discriminated at runtime, which may cause unexpected behavior.`,
@@ -3536,7 +3639,6 @@ var leakingRequirements = createDiagnostic({
3536
3639
  const typeChecker = yield* service(TypeCheckerApi);
3537
3640
  const typeCheckerUtils = yield* service(TypeCheckerUtils);
3538
3641
  const typeParser = yield* service(TypeParser);
3539
- const typeOrder = yield* deterministicTypeOrder;
3540
3642
  const parseLeakedRequirements = cachedBy(
3541
3643
  fn("leakingServices.checkServiceLeaking")(
3542
3644
  function* (service2, atLocation) {
@@ -3550,7 +3652,7 @@ var leakingRequirements = createDiagnostic({
3550
3652
  let effectContextType = void 0;
3551
3653
  yield* pipe(
3552
3654
  typeParser.effectType(servicePropertyType, atLocation),
3553
- map3((_) => effectContextType = _.R),
3655
+ map4((_) => effectContextType = _.R),
3554
3656
  orElse2(() => {
3555
3657
  const servicePropertyCallSignatures = typeChecker.getSignaturesOfType(
3556
3658
  servicePropertyType,
@@ -3562,7 +3664,7 @@ var leakingRequirements = createDiagnostic({
3562
3664
  typeChecker.getReturnTypeOfSignature(servicePropertyCallSignatures[0]),
3563
3665
  atLocation
3564
3666
  ),
3565
- map3((_) => {
3667
+ map4((_) => {
3566
3668
  effectContextType = _.R;
3567
3669
  })
3568
3670
  );
@@ -3580,7 +3682,7 @@ var leakingRequirements = createDiagnostic({
3580
3682
  if (type.flags & ts.TypeFlags.Never) return succeed(true);
3581
3683
  return pipe(
3582
3684
  typeParser.scopeType(type, atLocation),
3583
- map3(() => true),
3685
+ map4(() => true),
3584
3686
  orElse2(() => succeed(false))
3585
3687
  );
3586
3688
  }
@@ -3639,7 +3741,9 @@ More info at https://effect.website/docs/requirements-management/layers/#avoidin
3639
3741
  flatMap2(
3640
3742
  ({ Service }) => pipe(
3641
3743
  parseLeakedRequirements(Service, node),
3642
- map3((requirements) => reportLeakingRequirements(reportAt, sort(requirements, typeOrder)))
3744
+ map4(
3745
+ (requirements) => reportLeakingRequirements(reportAt, sort(requirements, typeCheckerUtils.deterministicTypeOrder))
3746
+ )
3643
3747
  )
3644
3748
  ),
3645
3749
  orElse2(() => sync(() => ts.forEachChild(node, appendNodeToVisit))),
@@ -3658,22 +3762,21 @@ var missingEffectContext = createDiagnostic({
3658
3762
  apply: fn("missingEffectContext.apply")(function* (sourceFile, report) {
3659
3763
  const typeChecker = yield* service(TypeCheckerApi);
3660
3764
  const typeParser = yield* service(TypeParser);
3661
- const typeOrder = yield* deterministicTypeOrder;
3662
3765
  const typeCheckerUtils = yield* service(TypeCheckerUtils);
3663
3766
  const checkForMissingContextTypes = (node, expectedType, valueNode, realType) => pipe(
3664
3767
  all(
3665
3768
  typeParser.effectType(expectedType, node),
3666
3769
  typeParser.effectType(realType, valueNode)
3667
3770
  ),
3668
- map3(
3771
+ map4(
3669
3772
  ([expectedEffect, realEffect]) => typeCheckerUtils.getMissingTypeEntriesInTargetType(
3670
3773
  realEffect.R,
3671
3774
  expectedEffect.R
3672
3775
  )
3673
3776
  )
3674
3777
  );
3675
- const sortTypes = sort(typeOrder);
3676
- const entries = yield* expectedAndRealType(sourceFile);
3778
+ const sortTypes = sort(typeCheckerUtils.deterministicTypeOrder);
3779
+ const entries = getEffectLspPatchSourceFileMetadata(sourceFile)?.relationErrors || typeCheckerUtils.expectedAndRealType(sourceFile);
3677
3780
  for (const [node, expectedType, valueNode, realType] of entries) {
3678
3781
  if (expectedType !== realType) {
3679
3782
  yield* pipe(
@@ -3683,7 +3786,7 @@ var missingEffectContext = createDiagnostic({
3683
3786
  valueNode,
3684
3787
  realType
3685
3788
  ),
3686
- map3(
3789
+ map4(
3687
3790
  (missingTypes) => missingTypes.length > 0 ? report(
3688
3791
  {
3689
3792
  location: node,
@@ -3710,7 +3813,6 @@ var missingEffectError = createDiagnostic({
3710
3813
  const typeChecker = yield* service(TypeCheckerApi);
3711
3814
  const typeCheckerUtils = yield* service(TypeCheckerUtils);
3712
3815
  const typeParser = yield* service(TypeParser);
3713
- const typeOrder = yield* deterministicTypeOrder;
3714
3816
  const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
3715
3817
  sourceFile,
3716
3818
  "effect",
@@ -3729,7 +3831,7 @@ var missingEffectError = createDiagnostic({
3729
3831
  typeParser.effectType(expectedType, node),
3730
3832
  typeParser.effectType(realType, valueNode)
3731
3833
  ),
3732
- map3(
3834
+ map4(
3733
3835
  ([expectedEffect, realEffect]) => pipe(
3734
3836
  typeCheckerUtils.getMissingTypeEntriesInTargetType(
3735
3837
  realEffect.E,
@@ -3739,8 +3841,8 @@ var missingEffectError = createDiagnostic({
3739
3841
  )
3740
3842
  )
3741
3843
  );
3742
- const sortTypes = sort(typeOrder);
3743
- const entries = yield* expectedAndRealType(sourceFile);
3844
+ const sortTypes = sort(typeCheckerUtils.deterministicTypeOrder);
3845
+ const entries = getEffectLspPatchSourceFileMetadata(sourceFile)?.relationErrors || typeCheckerUtils.expectedAndRealType(sourceFile);
3744
3846
  for (const [node, expectedType, valueNode, realType] of entries) {
3745
3847
  if (expectedType !== realType) {
3746
3848
  yield* pipe(
@@ -3750,7 +3852,7 @@ var missingEffectError = createDiagnostic({
3750
3852
  valueNode,
3751
3853
  realType
3752
3854
  ),
3753
- map3((result) => {
3855
+ map4((result) => {
3754
3856
  if (result.missingErrorTypes.length === 0) return;
3755
3857
  const fixes = [];
3756
3858
  if (ts.isExpression(valueNode) && result.expectedErrorType.flags & ts.TypeFlags.Never) {
@@ -3777,17 +3879,17 @@ var missingEffectError = createDiagnostic({
3777
3879
  if (ts.isExpression(valueNode)) {
3778
3880
  const propertyAssignments = pipe(
3779
3881
  result.missingErrorTypes,
3780
- map2((_) => typeChecker.getPropertyOfType(_, "_tag")),
3882
+ map3((_) => typeChecker.getPropertyOfType(_, "_tag")),
3781
3883
  filter((_) => !!_),
3782
- map2((_) => typeChecker.getTypeOfSymbolAtLocation(_, valueNode)),
3884
+ map3((_) => typeChecker.getTypeOfSymbolAtLocation(_, valueNode)),
3783
3885
  filter((_) => !!(_.flags & ts.TypeFlags.Literal)),
3784
- map2((_) => typeChecker.typeToTypeNode(_, void 0, ts.NodeBuilderFlags.NoTruncation)),
3886
+ map3((_) => typeChecker.typeToTypeNode(_, void 0, ts.NodeBuilderFlags.NoTruncation)),
3785
3887
  filter((_) => !!_ && ts.isLiteralTypeNode(_)),
3786
- map2((_) => _.literal),
3888
+ map3((_) => _.literal),
3787
3889
  filter((_) => ts.isLiteralExpression(_)),
3788
- map2((_) => _.text),
3890
+ map3((_) => _.text),
3789
3891
  sort(string2),
3790
- map2(
3892
+ map3(
3791
3893
  (_) => ts.factory.createPropertyAssignment(
3792
3894
  ts.factory.createIdentifier(_),
3793
3895
  ts.factory.createArrowFunction(
@@ -4023,7 +4125,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
4023
4125
  typeParser.effectGen(effectGenNode),
4024
4126
  orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
4025
4127
  orElse2(() => typeParser.effectFnGen(effectGenNode)),
4026
- map3(({ functionStar }) => {
4128
+ map4(({ functionStar }) => {
4027
4129
  if (functionStar) {
4028
4130
  brokenGenerators.add(functionStar);
4029
4131
  }
@@ -4093,7 +4195,7 @@ var multipleEffectProvide = createDiagnostic({
4093
4195
  return pipe(
4094
4196
  typeParser.importedEffectModule(node.expression.expression),
4095
4197
  flatMap2(() => typeParser.layerType(type, layer)),
4096
- map3(() => ({ layer, node })),
4198
+ map4(() => ({ layer, node })),
4097
4199
  orElse2(() => void_)
4098
4200
  );
4099
4201
  }
@@ -4184,7 +4286,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
4184
4286
  ),
4185
4287
  void 0,
4186
4288
  [
4187
- ts.factory.createIdentifier(className2.text),
4289
+ ts.factory.createIdentifier(ts.idText(className2)),
4188
4290
  ts.factory.createArrowFunction(
4189
4291
  void 0,
4190
4292
  void 0,
@@ -4234,9 +4336,9 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
4234
4336
  const generateReturnType = (type, atLocation2, className2) => pipe(
4235
4337
  typeParser.effectType(type, atLocation2),
4236
4338
  flatMap2((returnedEffect) => {
4237
- const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(className2.text) : ts.factory.createUnionTypeNode(
4339
+ const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(ts.idText(className2)) : ts.factory.createUnionTypeNode(
4238
4340
  [
4239
- ts.factory.createTypeReferenceNode(className2.text),
4341
+ ts.factory.createTypeReferenceNode(ts.idText(className2)),
4240
4342
  typeChecker.typeToTypeNode(returnedEffect.R, atLocation2, ts.NodeBuilderFlags.NoTruncation)
4241
4343
  ]
4242
4344
  );
@@ -4284,7 +4386,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
4284
4386
  ts.factory.createIdentifier("UnknownException")
4285
4387
  )
4286
4388
  ),
4287
- ts.factory.createTypeReferenceNode(className2.text)
4389
+ ts.factory.createTypeReferenceNode(ts.idText(className2))
4288
4390
  ]
4289
4391
  ));
4290
4392
  })
@@ -4301,7 +4403,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
4301
4403
  [
4302
4404
  successType,
4303
4405
  ts.factory.createTypeReferenceNode("never"),
4304
- ts.factory.createTypeReferenceNode(className2.text)
4406
+ ts.factory.createTypeReferenceNode(ts.idText(className2))
4305
4407
  ]
4306
4408
  );
4307
4409
  return succeed(typeNode);
@@ -4332,7 +4434,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
4332
4434
  for (const signature of typeChecker.getSignaturesOfType(propertyType, ts.SignatureKind.Call)) {
4333
4435
  yield* pipe(
4334
4436
  proxySignature(signature, atLocation, className),
4335
- map3((sig) => {
4437
+ map4((sig) => {
4336
4438
  callSignatures.push(sig);
4337
4439
  }),
4338
4440
  ignore
@@ -4378,7 +4480,7 @@ var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
4378
4480
  }
4379
4481
  const hash2 = involvedMembers.map(({ property, propertyType }) => {
4380
4482
  return ts.symbolName(property) + ": " + typeChecker.typeToString(propertyType);
4381
- }).concat([className.text]).join("\n");
4483
+ }).concat([ts.idText(className)]).join("\n");
4382
4484
  return { Service, className, atLocation: node, hash: cyrb53(hash2), involvedMembers };
4383
4485
  });
4384
4486
  var writeTagClassAccessors = createRefactor({
@@ -4391,7 +4493,7 @@ var writeTagClassAccessors = createRefactor({
4391
4493
  const typeParser = yield* service(TypeParser);
4392
4494
  const parseNode = (node) => pipe(
4393
4495
  parse2(node),
4394
- map3(({ Service, atLocation, className, involvedMembers }) => ({
4496
+ map4(({ Service, atLocation, className, involvedMembers }) => ({
4395
4497
  kind: "refactor.rewrite.effect.writeTagClassAccessors",
4396
4498
  description: "Implement Service accessors",
4397
4499
  apply: pipe(
@@ -4423,7 +4525,7 @@ var accessors = createCodegen({
4423
4525
  if (!nodeAndCommentRange) return yield* fail(new CodegenNotApplicableError("no node and comment range"));
4424
4526
  return yield* pipe(
4425
4527
  parse2(nodeAndCommentRange.node),
4426
- map3(
4528
+ map4(
4427
4529
  (_) => ({
4428
4530
  hash: _.hash,
4429
4531
  description: "Generate accessors for the service",
@@ -4454,7 +4556,7 @@ var outdatedEffectCodegen = createDiagnostic({
4454
4556
  for (const { codegen, hash: hash2, range } of codegensWithRanges) {
4455
4557
  yield* pipe(
4456
4558
  getEditsForCodegen([codegen], sourceFile, range),
4457
- map3((applicable) => {
4559
+ map4((applicable) => {
4458
4560
  if (applicable.hash !== hash2) {
4459
4561
  _report({
4460
4562
  location: range,
@@ -4514,7 +4616,7 @@ var overriddenSchemaConstructor = createDiagnostic({
4514
4616
  const typeAtLocation = typeChecker.getTypeAtLocation(type.expression);
4515
4617
  const isSchema = yield* pipe(
4516
4618
  typeParser.effectSchemaType(typeAtLocation, type.expression),
4517
- map3(() => true),
4619
+ map4(() => true),
4518
4620
  orElse2(() => succeed(false))
4519
4621
  );
4520
4622
  if (isSchema) {
@@ -4585,7 +4687,7 @@ var returnEffectInGen = createDiagnostic({
4585
4687
  typeParser.effectGen(effectGenNode),
4586
4688
  orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
4587
4689
  orElse2(() => typeParser.effectFnGen(effectGenNode)),
4588
- map3(() => {
4690
+ map4(() => {
4589
4691
  const fix = node.expression ? [{
4590
4692
  fixName: "returnEffectInGen_fix",
4591
4693
  description: "Add yield* statement",
@@ -4648,7 +4750,7 @@ var scopeInLayerEffect = createDiagnostic({
4648
4750
  const entries = typeCheckerUtils.unrollUnionMembers(type);
4649
4751
  return pipe(
4650
4752
  firstSuccessOf(entries.map((type2) => typeParser.scopeType(type2, node))),
4651
- map3(
4753
+ map4(
4652
4754
  () => report({
4653
4755
  location: node,
4654
4756
  messageText: `Seems like you are constructing a layer with a scope in the requirements.
@@ -4807,7 +4909,7 @@ var tryCatchInEffectGen = createDiagnostic({
4807
4909
  typeParser.effectGen(effectGenNode),
4808
4910
  orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
4809
4911
  orElse2(() => typeParser.effectFnGen(effectGenNode)),
4810
- map3(() => {
4912
+ map4(() => {
4811
4913
  report({
4812
4914
  location: node,
4813
4915
  messageText: "Avoid using try/catch inside Effect generators. Use Effect's error handling mechanisms instead (e.g., Effect.try, Effect.tryPromise, Effect.catchAll, Effect.catchTag).",
@@ -4842,7 +4944,7 @@ var unnecessaryEffectGen = createDiagnostic({
4842
4944
  if (ts.isCallExpression(node)) {
4843
4945
  yield* pipe(
4844
4946
  typeParser.unnecessaryEffectGen(node),
4845
- map3(
4947
+ map4(
4846
4948
  ({ replacementNode }) => report({
4847
4949
  location: node,
4848
4950
  messageText: `This Effect.gen contains a single return statement.`,
@@ -4885,7 +4987,7 @@ var unnecessaryPipe = createDiagnostic({
4885
4987
  if (ts.isCallExpression(node)) {
4886
4988
  yield* pipe(
4887
4989
  typeParser.pipeCall(node),
4888
- map3(({ args: args2, subject }) => {
4990
+ map4(({ args: args2, subject }) => {
4889
4991
  if (args2.length === 0) {
4890
4992
  report({
4891
4993
  location: node,
@@ -4931,9 +5033,9 @@ var unnecessaryPipeChain = createDiagnostic({
4931
5033
  yield* pipe(
4932
5034
  typeParser.pipeCall(node),
4933
5035
  flatMap2(
4934
- (pipeCall) => map3(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))
5036
+ (pipeCall) => map4(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))
4935
5037
  ),
4936
- map3(({ innerCall, pipeCall }) => {
5038
+ map4(({ innerCall, pipeCall }) => {
4937
5039
  report({
4938
5040
  location: node,
4939
5041
  messageText: `Chained pipe calls can be simplified to a single pipe call`,
@@ -5067,14 +5169,29 @@ var diagnostics = [
5067
5169
  ];
5068
5170
 
5069
5171
  // src/effect-lsp-patch-utils.ts
5070
- function checkSourceFileWorker(tsInstance, program, sourceFile, compilerOptions, addDiagnostic) {
5071
- const pluginOptions = pipe(
5072
- compilerOptions.plugins || [],
5073
- findFirst2((_) => hasProperty(_, "name") && _.name === "@effect/language-service")
5074
- );
5075
- if (isNone2(pluginOptions)) {
5076
- return;
5172
+ var extractEffectLspOptions = (compilerOptions) => {
5173
+ return (hasProperty(compilerOptions, "plugins") && isArray(compilerOptions.plugins) ? compilerOptions.plugins : []).find((_) => hasProperty(_, "name") && _.name === "@effect/language-service");
5174
+ };
5175
+ function clearSourceFileEffectMetadata(sourceFile) {
5176
+ getOrDefaultEffectLspPatchSourceFileMetadata(sourceFile).relationErrors = [];
5177
+ }
5178
+ function appendMetadataRelationError(tsInstance, errorNode, source, target) {
5179
+ let sourceFile = errorNode;
5180
+ while (sourceFile.parent && !tsInstance.isSourceFile(sourceFile)) {
5181
+ sourceFile = sourceFile.parent;
5182
+ }
5183
+ if (tsInstance.isSourceFile(sourceFile)) {
5184
+ getOrDefaultEffectLspPatchSourceFileMetadata(sourceFile).relationErrors.push([
5185
+ errorNode,
5186
+ target,
5187
+ errorNode,
5188
+ source
5189
+ ]);
5077
5190
  }
5191
+ }
5192
+ function checkSourceFileWorker(tsInstance, program, sourceFile, compilerOptions, addDiagnostic) {
5193
+ const pluginOptions = extractEffectLspOptions(compilerOptions);
5194
+ if (!pluginOptions) return;
5078
5195
  pipe(
5079
5196
  getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),
5080
5197
  nanoLayer3,
@@ -5098,11 +5215,13 @@ function checkSourceFileWorker(tsInstance, program, sourceFile, compilerOptions,
5098
5215
  console.error(e);
5099
5216
  return [];
5100
5217
  }),
5101
- map2(addDiagnostic)
5218
+ map3(addDiagnostic)
5102
5219
  );
5103
5220
  }
5104
5221
  // Annotate the CommonJS export names for ESM import in node:
5105
5222
  0 && (module.exports = {
5106
- checkSourceFileWorker
5223
+ appendMetadataRelationError,
5224
+ checkSourceFileWorker,
5225
+ clearSourceFileEffectMetadata
5107
5226
  });
5108
5227
  //# sourceMappingURL=effect-lsp-patch-utils.js.map