@effect/language-service 0.28.3 → 0.29.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/index.js CHANGED
@@ -735,104 +735,12 @@ var none2 = () => none;
735
735
  var some2 = some;
736
736
  var isNone2 = isNone;
737
737
  var isSome2 = isSome;
738
- var match = /* @__PURE__ */ dual(2, (self, {
739
- onNone,
740
- onSome
741
- }) => isNone2(self) ? onNone() : onSome(self.value));
742
738
  var getOrElse2 = /* @__PURE__ */ dual(2, (self, onNone) => isNone2(self) ? onNone() : self.value);
743
739
  var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : self);
744
740
  var fromNullable = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
745
741
  var getOrUndefined = /* @__PURE__ */ getOrElse2(constUndefined);
746
742
  var map2 = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() : some2(f(self.value)));
747
743
 
748
- // node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/array.js
749
- var isNonEmptyArray = (self) => self.length > 0;
750
-
751
- // node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Array.js
752
- var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
753
- var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
754
- var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
755
- var isArray = Array.isArray;
756
- var isEmptyArray = (self) => self.length === 0;
757
- var isEmptyReadonlyArray = isEmptyArray;
758
- var isNonEmptyReadonlyArray = isNonEmptyArray;
759
- var isOutOfBounds = (i, as) => i < 0 || i >= as.length;
760
- var get = /* @__PURE__ */ dual(2, (self, index) => {
761
- const i = Math.floor(index);
762
- return isOutOfBounds(i, self) ? none2() : some2(self[i]);
763
- });
764
- var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
765
- const i = Math.floor(index);
766
- if (isOutOfBounds(i, self)) {
767
- throw new Error(`Index ${i} out of bounds`);
768
- }
769
- return self[i];
770
- });
771
- var head = /* @__PURE__ */ get(0);
772
- var headNonEmpty = /* @__PURE__ */ unsafeGet(0);
773
- var tailNonEmpty = (self) => self.slice(1);
774
- var sort = /* @__PURE__ */ dual(2, (self, O) => {
775
- const out = Array.from(self);
776
- out.sort(O);
777
- return out;
778
- });
779
- var containsWith = (isEquivalent) => dual(2, (self, a) => {
780
- for (const i of self) {
781
- if (isEquivalent(a, i)) {
782
- return true;
783
- }
784
- }
785
- return false;
786
- });
787
- var _equivalence = /* @__PURE__ */ equivalence();
788
- var intersectionWith = (isEquivalent) => {
789
- const has = containsWith(isEquivalent);
790
- return dual(2, (self, that) => fromIterable(self).filter((a) => has(that, a)));
791
- };
792
- var intersection = /* @__PURE__ */ intersectionWith(_equivalence);
793
- var empty = () => [];
794
- var map3 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
795
- var flatMap = /* @__PURE__ */ dual(2, (self, f) => {
796
- if (isEmptyReadonlyArray(self)) {
797
- return [];
798
- }
799
- const out = [];
800
- for (let i = 0; i < self.length; i++) {
801
- const inner = f(self[i], i);
802
- for (let j = 0; j < inner.length; j++) {
803
- out.push(inner[j]);
804
- }
805
- }
806
- return out;
807
- });
808
- var flatten = /* @__PURE__ */ flatMap(identity);
809
- var filter = /* @__PURE__ */ dual(2, (self, predicate) => {
810
- const as = fromIterable(self);
811
- const out = [];
812
- for (let i = 0; i < as.length; i++) {
813
- if (predicate(as[i], i)) {
814
- out.push(as[i]);
815
- }
816
- }
817
- return out;
818
- });
819
- var every = /* @__PURE__ */ dual(2, (self, refinement) => self.every(refinement));
820
- var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
821
- const input = fromIterable(self);
822
- if (isNonEmptyReadonlyArray(input)) {
823
- const out = [headNonEmpty(input)];
824
- const rest = tailNonEmpty(input);
825
- for (const r of rest) {
826
- if (out.every((a) => !isEquivalent(r, a))) {
827
- out.push(r);
828
- }
829
- }
830
- return out;
831
- }
832
- return [];
833
- });
834
- var dedupe = (self) => dedupeWith(self, equivalence());
835
-
836
744
  // src/core/Nano.ts
837
745
  var NanoTag = class {
838
746
  constructor(key) {
@@ -950,13 +858,13 @@ var OnSuccessProto = {
950
858
  return this[args];
951
859
  }
952
860
  };
953
- var flatMap2 = dual(2, (fa, f) => {
861
+ var flatMap = dual(2, (fa, f) => {
954
862
  const nano = Object.create(OnSuccessProto);
955
863
  nano[args] = fa;
956
864
  nano[contA] = f;
957
865
  return nano;
958
866
  });
959
- var map4 = dual(2, (fa, f) => flatMap2(fa, (_) => succeed(f(_))));
867
+ var map3 = dual(2, (fa, f) => flatMap(fa, (_) => succeed(f(_))));
960
868
  var SyncProto = {
961
869
  ...PrimitiveProto,
962
870
  [evaluate](fiber) {
@@ -997,7 +905,7 @@ var MatchProto = {
997
905
  return this[args];
998
906
  }
999
907
  };
1000
- var match2 = (fa, opts) => {
908
+ var match = (fa, opts) => {
1001
909
  const nano = Object.create(MatchProto);
1002
910
  nano[args] = fa;
1003
911
  nano[contA] = opts.onSuccess;
@@ -1020,7 +928,7 @@ var ProvideServiceProto = {
1020
928
  ...fiber._services,
1021
929
  [tag.key]: value
1022
930
  };
1023
- return match2(fa, {
931
+ return match(fa, {
1024
932
  onSuccess: (_) => {
1025
933
  fiber._services = prevServices;
1026
934
  return succeed(_);
@@ -1063,7 +971,7 @@ var CachedProto = {
1063
971
  fiber._cache[type] = cache;
1064
972
  const cached2 = cache.get(key);
1065
973
  if (cached2) return cached2;
1066
- return match2(fa, {
974
+ return match(fa, {
1067
975
  onSuccess: (_) => {
1068
976
  cache.set(key, succeed(_));
1069
977
  return succeed(_);
@@ -1111,44 +1019,138 @@ var all = fn("all")(
1111
1019
  var TypeScriptApi = Tag("TypeScriptApi");
1112
1020
  var TypeScriptProgram = Tag("TypeScriptProgram");
1113
1021
  var ChangeTracker = Tag("ChangeTracker");
1114
- function parsePackageContentNameAndVersionFromScope(v) {
1115
- if (!isObject(v)) return;
1116
- if (!hasProperty(v, "packageJsonScope")) return;
1117
- if (!v.packageJsonScope) return;
1118
- const packageJsonScope = v.packageJsonScope;
1119
- if (!hasProperty(packageJsonScope, "contents")) return;
1120
- if (!hasProperty(packageJsonScope.contents, "packageJsonContent")) return;
1121
- const packageJsonContent = packageJsonScope.contents.packageJsonContent;
1122
- if (!hasProperty(packageJsonContent, "name")) return;
1123
- if (!hasProperty(packageJsonContent, "version")) return;
1124
- if (!hasProperty(packageJsonScope, "packageDirectory")) return;
1125
- if (!isString(packageJsonScope.packageDirectory)) return;
1126
- const { name, version } = packageJsonContent;
1127
- if (!isString(name)) return;
1128
- if (!isString(version)) return;
1129
- const hasEffectInPeerDependencies = hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) && hasProperty(packageJsonContent.peerDependencies, "effect");
1130
- const referencedPackages = Object.keys({
1131
- ...hasProperty(packageJsonContent, "dependencies") && isObject(packageJsonContent.dependencies) ? packageJsonContent.dependencies : {},
1132
- ...hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) ? packageJsonContent.peerDependencies : {},
1133
- ...hasProperty(packageJsonContent, "devDependencies") && isObject(packageJsonContent.devDependencies) ? packageJsonContent.devDependencies : {}
1134
- });
1135
- const exportsKeys = Object.keys(
1136
- hasProperty(packageJsonContent, "exports") && isObject(packageJsonContent.exports) ? packageJsonContent.exports : {}
1137
- );
1138
- return {
1139
- name: name.toLowerCase(),
1140
- version: version.toLowerCase(),
1141
- hasEffectInPeerDependencies,
1142
- contents: packageJsonContent,
1143
- packageDirectory: packageJsonScope.packageDirectory,
1144
- referencedPackages,
1145
- exportsKeys
1146
- };
1147
- }
1148
- var resolveModulePattern = fn("resolveModulePattern")(
1149
- function* (sourceFile, pattern) {
1022
+
1023
+ // node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/array.js
1024
+ var isNonEmptyArray = (self) => self.length > 0;
1025
+
1026
+ // node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Array.js
1027
+ var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
1028
+ var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
1029
+ var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
1030
+ var isArray = Array.isArray;
1031
+ var isEmptyArray = (self) => self.length === 0;
1032
+ var isEmptyReadonlyArray = isEmptyArray;
1033
+ var isNonEmptyReadonlyArray = isNonEmptyArray;
1034
+ var isOutOfBounds = (i, as) => i < 0 || i >= as.length;
1035
+ var get = /* @__PURE__ */ dual(2, (self, index) => {
1036
+ const i = Math.floor(index);
1037
+ return isOutOfBounds(i, self) ? none2() : some2(self[i]);
1038
+ });
1039
+ var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
1040
+ const i = Math.floor(index);
1041
+ if (isOutOfBounds(i, self)) {
1042
+ throw new Error(`Index ${i} out of bounds`);
1043
+ }
1044
+ return self[i];
1045
+ });
1046
+ var head = /* @__PURE__ */ get(0);
1047
+ var headNonEmpty = /* @__PURE__ */ unsafeGet(0);
1048
+ var tailNonEmpty = (self) => self.slice(1);
1049
+ var sort = /* @__PURE__ */ dual(2, (self, O) => {
1050
+ const out = Array.from(self);
1051
+ out.sort(O);
1052
+ return out;
1053
+ });
1054
+ var containsWith = (isEquivalent) => dual(2, (self, a) => {
1055
+ for (const i of self) {
1056
+ if (isEquivalent(a, i)) {
1057
+ return true;
1058
+ }
1059
+ }
1060
+ return false;
1061
+ });
1062
+ var _equivalence = /* @__PURE__ */ equivalence();
1063
+ var intersectionWith = (isEquivalent) => {
1064
+ const has = containsWith(isEquivalent);
1065
+ return dual(2, (self, that) => fromIterable(self).filter((a) => has(that, a)));
1066
+ };
1067
+ var intersection = /* @__PURE__ */ intersectionWith(_equivalence);
1068
+ var empty = () => [];
1069
+ var map4 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
1070
+ var flatMap2 = /* @__PURE__ */ dual(2, (self, f) => {
1071
+ if (isEmptyReadonlyArray(self)) {
1072
+ return [];
1073
+ }
1074
+ const out = [];
1075
+ for (let i = 0; i < self.length; i++) {
1076
+ const inner = f(self[i], i);
1077
+ for (let j = 0; j < inner.length; j++) {
1078
+ out.push(inner[j]);
1079
+ }
1080
+ }
1081
+ return out;
1082
+ });
1083
+ var flatten = /* @__PURE__ */ flatMap2(identity);
1084
+ var filter = /* @__PURE__ */ dual(2, (self, predicate) => {
1085
+ const as = fromIterable(self);
1086
+ const out = [];
1087
+ for (let i = 0; i < as.length; i++) {
1088
+ if (predicate(as[i], i)) {
1089
+ out.push(as[i]);
1090
+ }
1091
+ }
1092
+ return out;
1093
+ });
1094
+ var every = /* @__PURE__ */ dual(2, (self, refinement) => self.every(refinement));
1095
+ var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
1096
+ const input = fromIterable(self);
1097
+ if (isNonEmptyReadonlyArray(input)) {
1098
+ const out = [headNonEmpty(input)];
1099
+ const rest = tailNonEmpty(input);
1100
+ for (const r of rest) {
1101
+ if (out.every((a) => !isEquivalent(r, a))) {
1102
+ out.push(r);
1103
+ }
1104
+ }
1105
+ return out;
1106
+ }
1107
+ return [];
1108
+ });
1109
+ var dedupe = (self) => dedupeWith(self, equivalence());
1110
+
1111
+ // src/core/TypeScriptUtils.ts
1112
+ var TypeScriptUtils = Tag("TypeScriptUtils");
1113
+ var nanoLayer = (fa) => pipe(
1114
+ service(TypeScriptApi),
1115
+ flatMap((ts) => pipe(fa, provideService(TypeScriptUtils, makeTypeScriptUtils(ts))))
1116
+ );
1117
+ function makeTypeScriptUtils(ts) {
1118
+ function parsePackageContentNameAndVersionFromScope(v) {
1119
+ if (!isObject(v)) return;
1120
+ if (!hasProperty(v, "packageJsonScope")) return;
1121
+ if (!v.packageJsonScope) return;
1122
+ const packageJsonScope = v.packageJsonScope;
1123
+ if (!hasProperty(packageJsonScope, "contents")) return;
1124
+ if (!hasProperty(packageJsonScope.contents, "packageJsonContent")) return;
1125
+ const packageJsonContent = packageJsonScope.contents.packageJsonContent;
1126
+ if (!hasProperty(packageJsonContent, "name")) return;
1127
+ if (!hasProperty(packageJsonContent, "version")) return;
1128
+ if (!hasProperty(packageJsonScope, "packageDirectory")) return;
1129
+ if (!isString(packageJsonScope.packageDirectory)) return;
1130
+ const { name, version } = packageJsonContent;
1131
+ if (!isString(name)) return;
1132
+ if (!isString(version)) return;
1133
+ const hasEffectInPeerDependencies = hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) && hasProperty(packageJsonContent.peerDependencies, "effect");
1134
+ const referencedPackages = Object.keys({
1135
+ ...hasProperty(packageJsonContent, "dependencies") && isObject(packageJsonContent.dependencies) ? packageJsonContent.dependencies : {},
1136
+ ...hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) ? packageJsonContent.peerDependencies : {},
1137
+ ...hasProperty(packageJsonContent, "devDependencies") && isObject(packageJsonContent.devDependencies) ? packageJsonContent.devDependencies : {}
1138
+ });
1139
+ const exportsKeys = Object.keys(
1140
+ hasProperty(packageJsonContent, "exports") && isObject(packageJsonContent.exports) ? packageJsonContent.exports : {}
1141
+ );
1142
+ return {
1143
+ name: name.toLowerCase(),
1144
+ version: version.toLowerCase(),
1145
+ hasEffectInPeerDependencies,
1146
+ contents: packageJsonContent,
1147
+ packageDirectory: packageJsonScope.packageDirectory,
1148
+ referencedPackages,
1149
+ exportsKeys
1150
+ };
1151
+ }
1152
+ function resolveModulePattern(sourceFile, pattern) {
1150
1153
  if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
1151
- const ts = yield* service(TypeScriptApi);
1152
1154
  const packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
1153
1155
  const referencedPackages = [];
1154
1156
  for (const statement of sourceFile.statements) {
@@ -1161,31 +1163,47 @@ var resolveModulePattern = fn("resolveModulePattern")(
1161
1163
  return pipe(
1162
1164
  referencedPackages.concat(packageJsonScope?.referencedPackages || []),
1163
1165
  dedupe,
1164
- map3((packageName) => packageName.toLowerCase()),
1166
+ map4((packageName) => packageName.toLowerCase()),
1165
1167
  filter(
1166
1168
  (packageName) => pattern.endsWith("*") && packageName.startsWith(pattern.toLowerCase().substring(0, pattern.length - 1))
1167
1169
  )
1168
1170
  );
1169
1171
  }
1170
- );
1171
- function makeGetModuleSpecifier(ts) {
1172
- if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
1173
- const _internal = ts.moduleSpecifiers.getModuleSpecifier;
1174
- return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options) => {
1175
- return _internal(
1176
- compilerOptions,
1177
- importingSourceFile,
1178
- importingSourceFileName,
1179
- toFileName,
1180
- host,
1181
- options
1182
- );
1183
- };
1184
- }
1185
-
1186
- // src/core/AST.ts
1187
- function collectSelfAndAncestorNodesInRange(node, textRange) {
1188
- return sync(() => {
1172
+ function makeGetModuleSpecifier() {
1173
+ if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
1174
+ const _internal = ts.moduleSpecifiers.getModuleSpecifier;
1175
+ return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options) => {
1176
+ return _internal(
1177
+ compilerOptions,
1178
+ importingSourceFile,
1179
+ importingSourceFileName,
1180
+ toFileName,
1181
+ host,
1182
+ options
1183
+ );
1184
+ };
1185
+ }
1186
+ function findNodeWithLeadingCommentAtPosition(sourceFile, position) {
1187
+ const sourceText = sourceFile.text;
1188
+ let result;
1189
+ function find(node) {
1190
+ const leading = ts.getLeadingCommentRanges(sourceText, node.getFullStart());
1191
+ if (leading) {
1192
+ for (const commentRange of leading) {
1193
+ if (commentRange.pos <= position && position < commentRange.end) {
1194
+ result = { node, commentRange };
1195
+ return;
1196
+ }
1197
+ }
1198
+ }
1199
+ if (node.getFullStart() <= position && position < node.getEnd()) {
1200
+ node.forEachChild(find);
1201
+ }
1202
+ }
1203
+ find(sourceFile);
1204
+ return result;
1205
+ }
1206
+ function collectSelfAndAncestorNodesInRange(node, textRange) {
1189
1207
  let result = empty();
1190
1208
  let parent = node;
1191
1209
  while (parent) {
@@ -1195,52 +1213,50 @@ function collectSelfAndAncestorNodesInRange(node, textRange) {
1195
1213
  parent = parent.parent;
1196
1214
  }
1197
1215
  return result;
1198
- });
1199
- }
1200
- var getAncestorNodesInRange = fn("AST.getAncestorNodesInRange")(function* (sourceFile, textRange) {
1201
- const nodeAtPosition = yield* option(findNodeAtPosition(sourceFile, textRange.pos));
1202
- if (isNone2(nodeAtPosition)) return empty();
1203
- return yield* collectSelfAndAncestorNodesInRange(nodeAtPosition.value, textRange);
1204
- });
1205
- var NodeNotFoundError = class {
1206
- _tag = "@effect/language-service/NodeNotFoundError";
1207
- };
1208
- var findNodeAtPosition = fn("AST.findNodeAtPosition")(function* (sourceFile, position) {
1209
- const ts = yield* service(TypeScriptApi);
1210
- function find(node) {
1211
- if (position >= node.getStart() && position < node.getEnd()) {
1212
- return ts.forEachChild(node, find) || node;
1216
+ }
1217
+ function findNodeAtPosition(sourceFile, position) {
1218
+ function find(node) {
1219
+ if (position >= node.getStart() && position < node.getEnd()) {
1220
+ return ts.forEachChild(node, find) || node;
1221
+ }
1222
+ return void 0;
1213
1223
  }
1214
- return void 0;
1224
+ return find(sourceFile);
1215
1225
  }
1216
- const result = find(sourceFile);
1217
- if (!result) return yield* fail(new NodeNotFoundError());
1218
- return result;
1219
- });
1220
- var getCommentAtPosition = fn("TypeScriptApi.getCommentAtPosition")(function* (sourceFile, pos) {
1221
- const ts = yield* service(TypeScriptApi);
1222
- const token = yield* findNodeAtPosition(sourceFile, pos);
1223
- if (token === void 0 || token.kind === ts.SyntaxKind.JsxText || pos >= token.end - (ts.tokenToString(token.kind) || "").length) {
1224
- return yield* fail(new NodeNotFoundError());
1225
- }
1226
- const startPos = token.pos === 0 ? (ts.getShebang(sourceFile.text) || "").length : token.pos;
1227
- if (startPos === 0) return yield* fail(new NodeNotFoundError());
1228
- const result = ts.forEachTrailingCommentRange(sourceFile.text, startPos, isCommentInRange, pos) || ts.forEachLeadingCommentRange(sourceFile.text, startPos, isCommentInRange, pos);
1229
- if (!result) return yield* fail(new NodeNotFoundError());
1230
- return result;
1231
- });
1232
- function isCommentInRange(pos, end, kind, _nl, at) {
1233
- return at >= pos && at < end ? { pos, end, kind } : void 0;
1234
- }
1235
- function toTextRange(positionOrRange) {
1236
- return typeof positionOrRange === "number" ? { end: positionOrRange, pos: positionOrRange } : positionOrRange;
1237
- }
1238
- function isNodeInRange(textRange) {
1239
- return (node) => node.pos <= textRange.pos && node.end >= textRange.end;
1240
- }
1241
- var transformAsyncAwaitToEffectGen = fn("AST.transformAsyncAwaitToEffectGen")(
1242
- function* (node, effectModuleName, onAwait) {
1243
- const ts = yield* service(TypeScriptApi);
1226
+ function findNodeAtPositionIncludingTrivia(sourceFile, position) {
1227
+ function find(node) {
1228
+ if (position >= node.pos && position < node.end) {
1229
+ return ts.forEachChild(node, find) || node;
1230
+ }
1231
+ return void 0;
1232
+ }
1233
+ return find(sourceFile);
1234
+ }
1235
+ function getAncestorNodesInRange(sourceFile, textRange) {
1236
+ const nodeAtPosition = findNodeAtPosition(sourceFile, textRange.pos);
1237
+ if (!nodeAtPosition) return empty();
1238
+ return collectSelfAndAncestorNodesInRange(nodeAtPosition, textRange);
1239
+ }
1240
+ function getCommentAtPosition(sourceFile, pos) {
1241
+ const token = findNodeAtPositionIncludingTrivia(sourceFile, pos);
1242
+ if (token === void 0 || token.kind === ts.SyntaxKind.JsxText || pos >= token.end - (ts.tokenToString(token.kind) || "").length) {
1243
+ return;
1244
+ }
1245
+ const startPos = token.pos === 0 ? (ts.getShebang(sourceFile.text) || "").length : token.pos;
1246
+ if (startPos === 0) return;
1247
+ const result = ts.forEachTrailingCommentRange(sourceFile.text, startPos, isCommentInRange, pos) || ts.forEachLeadingCommentRange(sourceFile.text, startPos, isCommentInRange, pos);
1248
+ return result;
1249
+ }
1250
+ function isCommentInRange(pos, end, kind, _nl, at) {
1251
+ return at >= pos && at < end ? { pos, end, kind } : void 0;
1252
+ }
1253
+ function toTextRange(positionOrRange) {
1254
+ return typeof positionOrRange === "number" ? { end: positionOrRange, pos: positionOrRange } : positionOrRange;
1255
+ }
1256
+ function isNodeInRange(textRange) {
1257
+ return (node) => node.pos <= textRange.pos && node.end >= textRange.end;
1258
+ }
1259
+ function transformAsyncAwaitToEffectGen(node, effectModuleName, onAwait) {
1244
1260
  function visitor(_) {
1245
1261
  if (ts.isAwaitExpression(_)) {
1246
1262
  const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext);
@@ -1252,7 +1268,7 @@ var transformAsyncAwaitToEffectGen = fn("AST.transformAsyncAwaitToEffectGen")(
1252
1268
  return ts.visitEachChild(_, visitor, ts.nullTransformationContext);
1253
1269
  }
1254
1270
  const generatorBody = visitor(node.body);
1255
- const effectGenCallExp = yield* createEffectGenCallExpression(effectModuleName, generatorBody);
1271
+ const effectGenCallExp = createEffectGenCallExpression(effectModuleName, generatorBody);
1256
1272
  let currentFlags = ts.getCombinedModifierFlags(node);
1257
1273
  currentFlags &= ~ts.ModifierFlags.Async;
1258
1274
  const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags);
@@ -1290,45 +1306,7 @@ var transformAsyncAwaitToEffectGen = fn("AST.transformAsyncAwaitToEffectGen")(
1290
1306
  newBody
1291
1307
  );
1292
1308
  }
1293
- );
1294
- var addReturnTypeAnnotation = fn("AST.addReturnTypeAnnotation")(function* (sourceFile, declaration, typeNode) {
1295
- const ts = yield* service(TypeScriptApi);
1296
- const changes = yield* service(ChangeTracker);
1297
- const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
1298
- const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
1299
- const endNode = needParens ? declaration.parameters[0] : closeParen;
1300
- if (endNode) {
1301
- if (needParens) {
1302
- changes.insertNodeBefore(
1303
- sourceFile,
1304
- endNode,
1305
- ts.factory.createToken(ts.SyntaxKind.OpenParenToken)
1306
- );
1307
- changes.insertNodeAfter(
1308
- sourceFile,
1309
- endNode,
1310
- ts.factory.createToken(ts.SyntaxKind.CloseParenToken)
1311
- );
1312
- }
1313
- changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: ": " });
1314
- }
1315
- });
1316
- var removeReturnTypeAnnotation = fn("AST.removeReturnTypeAnnotation")(function* (sourceFile, declaration) {
1317
- const ts = yield* service(TypeScriptApi);
1318
- const changes = yield* service(ChangeTracker);
1319
- const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
1320
- const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
1321
- const endNode = needParens ? declaration.parameters[0] : closeParen;
1322
- if (endNode && declaration.type) {
1323
- changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end });
1324
- }
1325
- });
1326
- var ImportModuleIdentifierNotFoundError = class {
1327
- _tag = "@effect/language-service/ImportModuleIdentifierNotFoundError";
1328
- };
1329
- var findImportedModuleIdentifier = fn("AST.findImportedModuleIdentifier")(
1330
- function* (sourceFile, test) {
1331
- const ts = yield* service(TypeScriptApi);
1309
+ function findImportedModuleIdentifier(sourceFile, test) {
1332
1310
  for (const statement of sourceFile.statements) {
1333
1311
  if (!ts.isImportDeclaration(statement)) continue;
1334
1312
  const importClause = statement.importClause;
@@ -1336,72 +1314,64 @@ var findImportedModuleIdentifier = fn("AST.findImportedModuleIdentifier")(
1336
1314
  const namedBindings = importClause.namedBindings;
1337
1315
  if (!namedBindings) continue;
1338
1316
  if (ts.isNamespaceImport(namedBindings)) {
1339
- if (yield* test(namedBindings.name, statement.moduleSpecifier, none2())) {
1340
- return namedBindings.name;
1317
+ if (test(namedBindings.name, statement.moduleSpecifier, none2())) {
1318
+ return namedBindings.name.text;
1341
1319
  }
1342
1320
  } else if (ts.isNamedImports(namedBindings)) {
1343
1321
  for (const importSpecifier of namedBindings.elements) {
1344
1322
  const importProperty = fromNullable(importSpecifier.propertyName).pipe(
1345
1323
  orElse(() => some2(importSpecifier.name))
1346
1324
  );
1347
- if (yield* test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
1348
- return importSpecifier.name;
1325
+ if (test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
1326
+ return importSpecifier.name.text;
1349
1327
  }
1350
1328
  }
1351
1329
  }
1352
1330
  }
1353
- return yield* fail(new ImportModuleIdentifierNotFoundError());
1354
1331
  }
1355
- );
1356
- function findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, packageName, moduleName) {
1357
- return findImportedModuleIdentifier(
1358
- sourceFile,
1359
- fn(
1360
- "AST.findImportedModuleIdentifierByPackageAndNameOrBarrel.findImportedModuleIdentifier"
1361
- )(function* (_, fromModule, importProperty) {
1362
- const ts = yield* service(TypeScriptApi);
1363
- if (isNone2(importProperty) && ts.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
1364
- return true;
1332
+ function findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, packageName, moduleName) {
1333
+ return findImportedModuleIdentifier(
1334
+ sourceFile,
1335
+ (_, fromModule, importProperty) => {
1336
+ if (isNone2(importProperty) && ts.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
1337
+ return true;
1338
+ }
1339
+ if (isSome2(importProperty) && ts.isIdentifier(importProperty.value) && importProperty.value.text === moduleName && ts.isStringLiteral(fromModule) && fromModule.text === packageName) {
1340
+ return true;
1341
+ }
1342
+ return false;
1365
1343
  }
1366
- if (isSome2(importProperty) && ts.isIdentifier(importProperty.value) && importProperty.value.text === moduleName && ts.isStringLiteral(fromModule) && fromModule.text === packageName) {
1367
- return true;
1344
+ );
1345
+ }
1346
+ function simplifyTypeNode(typeNode) {
1347
+ function collectCallable(typeNode2) {
1348
+ if (ts.isParenthesizedTypeNode(typeNode2)) return collectCallable(typeNode2.type);
1349
+ if (ts.isFunctionTypeNode(typeNode2)) {
1350
+ return some2([
1351
+ ts.factory.createCallSignature(typeNode2.typeParameters, typeNode2.parameters, typeNode2.type)
1352
+ ]);
1353
+ }
1354
+ if (ts.isTypeLiteralNode(typeNode2)) {
1355
+ const allCallSignatures = typeNode2.members.every(ts.isCallSignatureDeclaration);
1356
+ if (allCallSignatures) {
1357
+ return some2(typeNode2.members);
1358
+ }
1368
1359
  }
1369
- return false;
1370
- })
1371
- );
1372
- }
1373
- var simplifyTypeNode = fn("AST.simplifyTypeNode")(function* (typeNode) {
1374
- const ts = yield* service(TypeScriptApi);
1375
- function collectCallable(typeNode2) {
1376
- if (ts.isParenthesizedTypeNode(typeNode2)) return collectCallable(typeNode2.type);
1377
- if (ts.isFunctionTypeNode(typeNode2)) {
1378
- return some2([
1379
- ts.factory.createCallSignature(typeNode2.typeParameters, typeNode2.parameters, typeNode2.type)
1380
- ]);
1381
- }
1382
- if (ts.isTypeLiteralNode(typeNode2)) {
1383
- const allCallSignatures = typeNode2.members.every(ts.isCallSignatureDeclaration);
1384
- if (allCallSignatures) {
1385
- return some2(typeNode2.members);
1360
+ if (ts.isIntersectionTypeNode(typeNode2)) {
1361
+ const members = typeNode2.types.map((node) => collectCallable(node));
1362
+ if (members.every(isSome2)) {
1363
+ return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
1364
+ }
1386
1365
  }
1366
+ return none2();
1387
1367
  }
1388
- if (ts.isIntersectionTypeNode(typeNode2)) {
1389
- const members = typeNode2.types.map((node) => collectCallable(node));
1390
- if (members.every(isSome2)) {
1391
- return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
1392
- }
1368
+ const callSignatures = collectCallable(typeNode);
1369
+ if (isSome2(callSignatures) && callSignatures.value.length > 1) {
1370
+ return ts.factory.createTypeLiteralNode(callSignatures.value);
1393
1371
  }
1394
- return none2();
1372
+ return typeNode;
1395
1373
  }
1396
- const callSignatures = collectCallable(typeNode);
1397
- if (isSome2(callSignatures) && callSignatures.value.length > 1) {
1398
- return ts.factory.createTypeLiteralNode(callSignatures.value);
1399
- }
1400
- return typeNode;
1401
- });
1402
- var tryPreserveDeclarationSemantics = fn("AST.tryPreserveDeclarationSemantics")(
1403
- function* (nodeToReplace, node) {
1404
- const ts = yield* service(TypeScriptApi);
1374
+ function tryPreserveDeclarationSemantics(nodeToReplace, node) {
1405
1375
  if (!ts.isExpression(node)) return node;
1406
1376
  if (ts.isFunctionDeclaration(nodeToReplace)) {
1407
1377
  if (!nodeToReplace.name) return node;
@@ -1428,14 +1398,9 @@ var tryPreserveDeclarationSemantics = fn("AST.tryPreserveDeclarationSemantics")(
1428
1398
  }
1429
1399
  return node;
1430
1400
  }
1431
- );
1432
- var parseAccessedExpressionForCompletion = fn(
1433
- "AST.parseAccessedExpressionForCompletion"
1434
- )(
1435
- function* (sourceFile, position) {
1436
- const ts = yield* service(TypeScriptApi);
1401
+ function parseAccessedExpressionForCompletion(sourceFile, position) {
1437
1402
  const precedingToken = ts.findPrecedingToken(position, sourceFile, void 0, true);
1438
- if (!precedingToken) return yield* fail(new NodeNotFoundError());
1403
+ if (!precedingToken) return;
1439
1404
  let accessedObject = precedingToken;
1440
1405
  let replacementSpan = ts.createTextSpan(position, 0);
1441
1406
  let outerNode = precedingToken;
@@ -1461,67 +1426,56 @@ var parseAccessedExpressionForCompletion = fn(
1461
1426
  accessedObject = precedingToken;
1462
1427
  outerNode = precedingToken;
1463
1428
  } else {
1464
- return yield* fail(new NodeNotFoundError());
1429
+ return;
1465
1430
  }
1466
1431
  return { accessedObject, outerNode, replacementSpan };
1467
1432
  }
1468
- );
1469
- var parseDataForExtendsClassCompletion = fn(
1470
- "AST.parseDataForExtendsClassCompletion"
1471
- )(function* (sourceFile, position) {
1472
- const ts = yield* service(TypeScriptApi);
1473
- const { accessedObject, outerNode, replacementSpan } = yield* parseAccessedExpressionForCompletion(
1474
- sourceFile,
1475
- position
1476
- );
1477
- if (!ts.isIdentifier(accessedObject)) return yield* fail(new NodeNotFoundError());
1478
- let classDeclaration = outerNode.parent;
1479
- while (ts.isExpressionWithTypeArguments(classDeclaration) || ts.isHeritageClause(classDeclaration)) {
1480
- if (!classDeclaration.parent) break;
1481
- classDeclaration = classDeclaration.parent;
1482
- }
1483
- if (!ts.isClassDeclaration(classDeclaration)) return yield* fail(new NodeNotFoundError());
1484
- if (!classDeclaration.name) return yield* fail(new NodeNotFoundError());
1485
- return {
1486
- accessedObject,
1487
- classDeclaration,
1488
- className: classDeclaration.name,
1489
- replacementSpan
1490
- };
1491
- });
1492
- var createEffectGenCallExpression = fn("AST.createEffectGenCallExpression")(function* (effectModuleIdentifierName, node) {
1493
- const ts = yield* service(TypeScriptApi);
1494
- const generator = ts.factory.createFunctionExpression(
1495
- void 0,
1496
- ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
1497
- void 0,
1498
- [],
1499
- [],
1500
- void 0,
1501
- node
1502
- // NOTE(mattia): intended, to use same routine for both ConciseBody and Body
1503
- );
1504
- return ts.factory.createCallExpression(
1505
- ts.factory.createPropertyAccessExpression(
1506
- ts.factory.createIdentifier(effectModuleIdentifierName),
1507
- "gen"
1508
- ),
1509
- void 0,
1510
- [generator]
1511
- );
1512
- });
1513
- var createEffectGenCallExpressionWithBlock = fn(
1514
- "AST.createEffectGenCallExpressionWithBlock"
1515
- )(function* (effectModuleIdentifierName, statement) {
1516
- const ts = yield* service(TypeScriptApi);
1517
- return yield* createEffectGenCallExpression(
1518
- effectModuleIdentifierName,
1519
- ts.factory.createBlock(Array.isArray(statement) ? statement : [statement], false)
1520
- );
1521
- });
1522
- var createReturnYieldStarStatement = fn("AST.createReturnYieldStarStatement")(
1523
- function* (expr) {
1524
- const ts = yield* service(TypeScriptApi);
1433
+ function parseDataForExtendsClassCompletion(sourceFile, position) {
1434
+ const maybeInfos = parseAccessedExpressionForCompletion(sourceFile, position);
1435
+ if (!maybeInfos) return;
1436
+ const { accessedObject, outerNode, replacementSpan } = maybeInfos;
1437
+ if (!ts.isIdentifier(accessedObject)) return;
1438
+ let classDeclaration = outerNode.parent;
1439
+ while (ts.isExpressionWithTypeArguments(classDeclaration) || ts.isHeritageClause(classDeclaration)) {
1440
+ if (!classDeclaration.parent) break;
1441
+ classDeclaration = classDeclaration.parent;
1442
+ }
1443
+ if (!ts.isClassDeclaration(classDeclaration)) return;
1444
+ if (!classDeclaration.name) return;
1445
+ return {
1446
+ accessedObject,
1447
+ classDeclaration,
1448
+ className: classDeclaration.name,
1449
+ replacementSpan
1450
+ };
1451
+ }
1452
+ function createEffectGenCallExpression(effectModuleIdentifierName, node) {
1453
+ const generator = ts.factory.createFunctionExpression(
1454
+ void 0,
1455
+ ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
1456
+ void 0,
1457
+ [],
1458
+ [],
1459
+ void 0,
1460
+ node
1461
+ // NOTE(mattia): intended, to use same routine for both ConciseBody and Body
1462
+ );
1463
+ return ts.factory.createCallExpression(
1464
+ ts.factory.createPropertyAccessExpression(
1465
+ ts.factory.createIdentifier(effectModuleIdentifierName),
1466
+ "gen"
1467
+ ),
1468
+ void 0,
1469
+ [generator]
1470
+ );
1471
+ }
1472
+ function createEffectGenCallExpressionWithBlock(effectModuleIdentifierName, statement) {
1473
+ return createEffectGenCallExpression(
1474
+ effectModuleIdentifierName,
1475
+ ts.factory.createBlock(isArray(statement) ? statement : [statement], false)
1476
+ );
1477
+ }
1478
+ function createReturnYieldStarStatement(expr) {
1525
1479
  return ts.factory.createReturnStatement(
1526
1480
  ts.factory.createYieldExpression(
1527
1481
  ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
@@ -1529,7 +1483,26 @@ var createReturnYieldStarStatement = fn("AST.createReturnYieldStarStatement")(
1529
1483
  )
1530
1484
  );
1531
1485
  }
1532
- );
1486
+ return {
1487
+ findNodeAtPositionIncludingTrivia,
1488
+ parsePackageContentNameAndVersionFromScope,
1489
+ resolveModulePattern,
1490
+ findNodeWithLeadingCommentAtPosition,
1491
+ getCommentAtPosition,
1492
+ getAncestorNodesInRange,
1493
+ toTextRange,
1494
+ isNodeInRange,
1495
+ transformAsyncAwaitToEffectGen,
1496
+ findImportedModuleIdentifierByPackageAndNameOrBarrel,
1497
+ simplifyTypeNode,
1498
+ tryPreserveDeclarationSemantics,
1499
+ parseDataForExtendsClassCompletion,
1500
+ createEffectGenCallExpressionWithBlock,
1501
+ createReturnYieldStarStatement,
1502
+ makeGetModuleSpecifier,
1503
+ parseAccessedExpressionForCompletion
1504
+ };
1505
+ }
1533
1506
 
1534
1507
  // src/core/LanguageServicePluginOptions.ts
1535
1508
  var LanguageServicePluginOptions = Tag("PluginOptions");
@@ -1539,7 +1512,7 @@ function parseDiagnosticSeverity(config) {
1539
1512
  pipe(
1540
1513
  Object.entries(config),
1541
1514
  filter(([key, value]) => isString(key) && isString(value)),
1542
- map3(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),
1515
+ map4(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),
1543
1516
  filter(
1544
1517
  ([_, value]) => value === "off" || value === "error" || value === "warning" || value === "message" || value === "suggestion"
1545
1518
  )
@@ -1631,27 +1604,8 @@ var getCompletionsAtPosition = fn("LSP.getCompletionsAtPosition")(function* (com
1631
1604
  var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1632
1605
  function* (sourceFile) {
1633
1606
  const ts = yield* service(TypeScriptApi);
1607
+ const tsUtils = yield* service(TypeScriptUtils);
1634
1608
  const pluginOptions = yield* service(LanguageServicePluginOptions);
1635
- function findNodeWithLeadingCommentAtPosition(position) {
1636
- const sourceText = sourceFile.text;
1637
- let result;
1638
- function find(node) {
1639
- const leading = ts.getLeadingCommentRanges(sourceText, node.getFullStart());
1640
- if (leading) {
1641
- for (const r of leading) {
1642
- if (r.pos <= position && position < r.end) {
1643
- result = node;
1644
- return;
1645
- }
1646
- }
1647
- }
1648
- if (node.getFullStart() <= position && position < node.getEnd()) {
1649
- node.forEachChild(find);
1650
- }
1651
- }
1652
- find(sourceFile);
1653
- return result;
1654
- }
1655
1609
  function findParentStatementForDisableNextLine(node) {
1656
1610
  let result;
1657
1611
  function find(node2) {
@@ -1669,10 +1623,10 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1669
1623
  const sectionOverrides = {};
1670
1624
  const skippedRules = [];
1671
1625
  const regex = /@effect-diagnostics(-next-line)?((?:\s[a-zA-Z0-9/]+:(?:off|warning|error|message|suggestion|skip-file))+)?/gm;
1672
- let match3;
1673
- while ((match3 = regex.exec(sourceFile.text)) !== null) {
1674
- const nextLineCaptureGroup = match3[1];
1675
- const rulesCaptureGroup = match3[2];
1626
+ let match2;
1627
+ while ((match2 = regex.exec(sourceFile.text)) !== null) {
1628
+ const nextLineCaptureGroup = match2[1];
1629
+ const rulesCaptureGroup = match2[2];
1676
1630
  if (rulesCaptureGroup) {
1677
1631
  const trimmedRuleString = rulesCaptureGroup.trim();
1678
1632
  if (trimmedRuleString) {
@@ -1684,19 +1638,19 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1684
1638
  if (ruleLevel === "skip-file") skippedRules.push(ruleName);
1685
1639
  const isOverrideNextLine = nextLineCaptureGroup && nextLineCaptureGroup.trim().toLowerCase() === "-next-line";
1686
1640
  if (isOverrideNextLine) {
1687
- const node = findNodeWithLeadingCommentAtPosition(match3.index);
1688
- if (node) {
1641
+ const foundNode = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, match2.index);
1642
+ if (foundNode) {
1689
1643
  lineOverrides[ruleName] = lineOverrides[ruleName] || [];
1690
1644
  lineOverrides[ruleName].unshift({
1691
- pos: node.getFullStart(),
1692
- end: node.end,
1645
+ pos: foundNode.node.getFullStart(),
1646
+ end: foundNode.node.end,
1693
1647
  level: ruleLevel
1694
1648
  });
1695
1649
  }
1696
1650
  } else {
1697
1651
  sectionOverrides[ruleName] = sectionOverrides[ruleName] || [];
1698
1652
  sectionOverrides[ruleName].unshift({
1699
- pos: match3.index,
1653
+ pos: match2.index,
1700
1654
  level: ruleLevel
1701
1655
  });
1702
1656
  }
@@ -1711,7 +1665,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1711
1665
  message: ts.DiagnosticCategory.Message,
1712
1666
  suggestion: ts.DiagnosticCategory.Suggestion
1713
1667
  };
1714
- const execute = fn("LSP.ruleExecutor")(function* (rule) {
1668
+ const execute = (rule) => gen(function* () {
1715
1669
  const diagnostics2 = [];
1716
1670
  const codeFixes = [];
1717
1671
  const ruleNameLowered = rule.name.toLowerCase();
@@ -1720,13 +1674,13 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1720
1674
  if (defaultLevel === "off" && (lineOverrides[ruleNameLowered] || sectionOverrides[ruleNameLowered] || []).length === 0) {
1721
1675
  return { diagnostics: diagnostics2, codeFixes };
1722
1676
  }
1723
- const fixByDisableNextLine = (_) => ({
1677
+ const fixByDisableNextLine = (node) => ({
1724
1678
  fixName: rule.name + "_skipNextLine",
1725
1679
  description: "Disable " + rule.name + " for this line",
1726
- apply: flatMap2(
1680
+ apply: flatMap(
1727
1681
  service(ChangeTracker),
1728
- (changeTracker) => sync(() => {
1729
- const disableAtNode = findParentStatementForDisableNextLine(_.node);
1682
+ (changeTracker) => gen(function* () {
1683
+ const disableAtNode = findParentStatementForDisableNextLine(node);
1730
1684
  const { line } = ts.getLineAndCharacterOfPosition(sourceFile, disableAtNode.getStart());
1731
1685
  changeTracker.insertCommentBeforeLine(
1732
1686
  sourceFile,
@@ -1740,7 +1694,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1740
1694
  const fixByDisableEntireFile = {
1741
1695
  fixName: rule.name + "_skipFile",
1742
1696
  description: "Disable " + rule.name + " for this entire file",
1743
- apply: flatMap2(
1697
+ apply: flatMap(
1744
1698
  service(ChangeTracker),
1745
1699
  (changeTracker) => sync(
1746
1700
  () => changeTracker.insertText(
@@ -1754,29 +1708,30 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1754
1708
  };
1755
1709
  const applicableDiagnostics = [];
1756
1710
  yield* rule.apply(sourceFile, (entry) => {
1711
+ const range = "getEnd" in entry.location ? { pos: entry.location.getStart(sourceFile), end: entry.location.getEnd() } : entry.location;
1712
+ const node = "getEnd" in entry.location ? entry.location : tsUtils.findNodeAtPositionIncludingTrivia(sourceFile, entry.location.pos);
1757
1713
  applicableDiagnostics.push({
1758
- ...entry,
1759
- fixes: entry.fixes.concat([fixByDisableNextLine(entry), fixByDisableEntireFile])
1714
+ range,
1715
+ messageText: entry.messageText,
1716
+ fixes: entry.fixes.concat(node ? [fixByDisableNextLine(node)] : []).concat([fixByDisableEntireFile])
1760
1717
  });
1761
1718
  });
1762
1719
  for (const emitted of applicableDiagnostics.slice(0)) {
1763
1720
  let newLevel = defaultLevel;
1764
1721
  const lineOverride = (lineOverrides[ruleNameLowered] || []).find(
1765
- (_) => _.pos < emitted.node.getStart(sourceFile) && _.end >= emitted.node.getEnd()
1722
+ (_) => _.pos < emitted.range.pos && _.end >= emitted.range.end
1766
1723
  );
1767
1724
  if (lineOverride) {
1768
1725
  newLevel = lineOverride.level;
1769
1726
  } else {
1770
- const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find(
1771
- (_) => _.pos < emitted.node.getStart(sourceFile)
1772
- );
1727
+ const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find((_) => _.pos < emitted.range.pos);
1773
1728
  if (sectionOverride) newLevel = sectionOverride.level;
1774
1729
  }
1775
1730
  if (!(newLevel in levelToDiagnosticCategory)) continue;
1776
1731
  diagnostics2.push({
1777
1732
  file: sourceFile,
1778
- start: emitted.node.getStart(sourceFile),
1779
- length: emitted.node.getEnd() - emitted.node.getStart(sourceFile),
1733
+ start: emitted.range.pos,
1734
+ length: emitted.range.end - emitted.range.pos,
1780
1735
  messageText: emitted.messageText,
1781
1736
  category: levelToDiagnosticCategory[newLevel],
1782
1737
  code: rule.code,
@@ -1786,8 +1741,8 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1786
1741
  codeFixes.push({
1787
1742
  ...fix,
1788
1743
  code: rule.code,
1789
- start: emitted.node.getStart(sourceFile),
1790
- end: emitted.node.getEnd()
1744
+ start: emitted.range.pos,
1745
+ end: emitted.range.end
1791
1746
  });
1792
1747
  }
1793
1748
  }
@@ -1796,28 +1751,97 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1796
1751
  return { execute };
1797
1752
  }
1798
1753
  );
1754
+ var cyrb53 = (str, seed = 0) => {
1755
+ let h1 = 3735928559 ^ seed, h2 = 1103547991 ^ seed;
1756
+ for (let i = 0, ch; i < str.length; i++) {
1757
+ ch = str.charCodeAt(i);
1758
+ h1 = Math.imul(h1 ^ ch, 2654435761);
1759
+ h2 = Math.imul(h2 ^ ch, 1597334677);
1760
+ }
1761
+ h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507);
1762
+ h1 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
1763
+ h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
1764
+ h2 ^= Math.imul(h1 ^ h1 >>> 13, 3266489909);
1765
+ return (h2 >>> 0).toString(16).padStart(8, "0") + (h1 >>> 0).toString(16).padStart(8, "0");
1766
+ };
1767
+ var CodegenNotApplicableError = class {
1768
+ constructor(cause) {
1769
+ this.cause = cause;
1770
+ }
1771
+ _tag = "@effect/language-service/CodegenNotApplicableError";
1772
+ };
1773
+ function createCodegen(definition) {
1774
+ return definition;
1775
+ }
1776
+ var getCodegensForSourceFile = fn("LSP.getApplicableCodegens")(function* (codegens2, sourceFile) {
1777
+ const tsUtils = yield* service(TypeScriptUtils);
1778
+ const result = [];
1779
+ const regex = /@effect-codegens((?:\s[a-zA-Z0-9]+(?::(?:[a-zA-Z0-9]+))?)+)+/gmid;
1780
+ let match2;
1781
+ while ((match2 = regex.exec(sourceFile.text)) !== null) {
1782
+ const pos = match2.indices?.[0]?.[0];
1783
+ if (!pos) continue;
1784
+ const commentRange = tsUtils.getCommentAtPosition(sourceFile, pos);
1785
+ if (!commentRange) continue;
1786
+ const commentText = sourceFile.text.slice(pos, commentRange.end);
1787
+ const codegenRegex = /(\s+)(\w+)(?::(\w+))?/gmi;
1788
+ let codegenMatch;
1789
+ while ((codegenMatch = codegenRegex.exec(commentText)) !== null) {
1790
+ const whitespace = codegenMatch[1] || "";
1791
+ const codegenName = codegenMatch[2] || "";
1792
+ const codegenHash = codegenMatch[3] || "";
1793
+ const range = {
1794
+ pos: codegenMatch.index + pos + whitespace.length,
1795
+ end: codegenMatch.index + pos + codegenMatch[0].length
1796
+ };
1797
+ const codegen = codegens2.find((codegen2) => codegen2.name === codegenName);
1798
+ if (!codegen) continue;
1799
+ result.push({ codegen, hash: codegenHash, range });
1800
+ }
1801
+ }
1802
+ return result;
1803
+ });
1804
+ var getEditsForCodegen = fn("LSP.getEditsForCodegen")(function* (codegens2, sourceFile, textRange) {
1805
+ const applicableCodegens = yield* getCodegensForSourceFile(codegens2, sourceFile);
1806
+ const inRangeCodegens = applicableCodegens.filter(
1807
+ (codegen2) => codegen2.range.pos <= textRange.pos && codegen2.range.end >= textRange.end
1808
+ );
1809
+ if (inRangeCodegens.length !== 1) {
1810
+ return yield* fail(new CodegenNotApplicableError("zero or multiple codegens in range"));
1811
+ }
1812
+ const { codegen, range } = inRangeCodegens[0];
1813
+ const edit = yield* codegen.apply(sourceFile, range);
1814
+ const updateHashComment = pipe(
1815
+ service(ChangeTracker),
1816
+ map3((changeTracker) => {
1817
+ changeTracker.deleteRange(sourceFile, range);
1818
+ changeTracker.insertText(sourceFile, range.pos, `${codegen.name}:${edit.hash}`);
1819
+ })
1820
+ );
1821
+ return {
1822
+ ...edit,
1823
+ apply: pipe(
1824
+ edit.apply,
1825
+ flatMap(() => updateHashComment)
1826
+ ),
1827
+ ignore: updateHashComment
1828
+ };
1829
+ });
1799
1830
 
1800
1831
  // src/completions/contextSelfInClasses.ts
1801
1832
  var contextSelfInClasses = createCompletion({
1802
1833
  name: "contextSelfInClasses",
1803
1834
  apply: fn("contextSelfInClasses")(function* (sourceFile, position) {
1804
1835
  const ts = yield* service(TypeScriptApi);
1805
- const maybeInfos = yield* option(
1806
- parseDataForExtendsClassCompletion(sourceFile, position)
1807
- );
1808
- if (isNone2(maybeInfos)) return [];
1809
- const { accessedObject, className, replacementSpan } = maybeInfos.value;
1810
- const contextName = yield* option(
1811
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
1812
- sourceFile,
1813
- "effect",
1814
- "Context"
1815
- )
1816
- );
1817
- const contextIdentifier = match(contextName, {
1818
- onNone: () => "Context",
1819
- onSome: (_) => _.text
1820
- });
1836
+ const tsUtils = yield* service(TypeScriptUtils);
1837
+ const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
1838
+ if (!maybeInfos) return [];
1839
+ const { accessedObject, className, replacementSpan } = maybeInfos;
1840
+ const contextIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
1841
+ sourceFile,
1842
+ "effect",
1843
+ "Context"
1844
+ ) || "Context";
1821
1845
  if (contextIdentifier !== accessedObject.text) return [];
1822
1846
  const name = className.text;
1823
1847
  return [{
@@ -1832,12 +1856,6 @@ var contextSelfInClasses = createCompletion({
1832
1856
 
1833
1857
  // src/core/TypeCheckerApi.ts
1834
1858
  var TypeCheckerApi = Tag("TypeChecker");
1835
- var TypeCheckerApiCache = Tag("TypeCheckerApiCache");
1836
- function makeTypeCheckerApiCache() {
1837
- return {
1838
- expectedAndRealType: /* @__PURE__ */ new WeakMap()
1839
- };
1840
- }
1841
1859
  var deterministicTypeOrder = gen(function* () {
1842
1860
  const typeChecker = yield* service(TypeCheckerApi);
1843
1861
  return make2((a, b) => {
@@ -1936,106 +1954,106 @@ var getInferredReturnType = fn("TypeCheckerApi.getInferredReturnType")(function*
1936
1954
  }
1937
1955
  return returnType;
1938
1956
  });
1939
- var expectedAndRealType = fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
1940
- const cache = yield* service(TypeCheckerApiCache);
1941
- const resultCached = cache.expectedAndRealType.get(sourceFile);
1942
- if (resultCached) return resultCached;
1943
- const typeChecker = yield* service(TypeCheckerApi);
1944
- const ts = yield* service(TypeScriptApi);
1945
- const result = [];
1946
- const nodeToVisit = [sourceFile];
1947
- const appendNodeToVisit = (node) => {
1948
- nodeToVisit.push(node);
1949
- return void 0;
1950
- };
1951
- while (nodeToVisit.length > 0) {
1952
- const node = nodeToVisit.shift();
1953
- if (ts.isVariableDeclaration(node) && node.initializer) {
1954
- const expectedType = typeChecker.getTypeAtLocation(node.name);
1955
- const realType = typeChecker.getTypeAtLocation(node.initializer);
1956
- result.push([node.name, expectedType, node.initializer, realType]);
1957
- appendNodeToVisit(node.initializer);
1958
- continue;
1959
- } else if (ts.isCallExpression(node)) {
1960
- const resolvedSignature = typeChecker.getResolvedSignature(node);
1961
- if (resolvedSignature) {
1962
- resolvedSignature.getParameters().map((parameter, index) => {
1963
- const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
1964
- const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
1965
- result.push([
1966
- node.arguments[index],
1967
- expectedType,
1968
- node.arguments[index],
1969
- realType
1970
- ]);
1971
- });
1972
- }
1973
- ts.forEachChild(node, appendNodeToVisit);
1974
- continue;
1975
- } else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
1976
- const parent = node.parent;
1977
- if (ts.isObjectLiteralElement(parent)) {
1978
- if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
1979
- const type = typeChecker.getContextualType(parent.parent);
1980
- if (type) {
1981
- const symbol3 = typeChecker.getPropertyOfType(type, node.text);
1982
- if (symbol3) {
1983
- const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
1984
- const realType = typeChecker.getTypeAtLocation(node);
1985
- result.push([node, expectedType, node, realType]);
1957
+ var expectedAndRealType = cachedBy(
1958
+ fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
1959
+ const typeChecker = yield* service(TypeCheckerApi);
1960
+ const ts = yield* service(TypeScriptApi);
1961
+ const result = [];
1962
+ const nodeToVisit = [sourceFile];
1963
+ const appendNodeToVisit = (node) => {
1964
+ nodeToVisit.push(node);
1965
+ return void 0;
1966
+ };
1967
+ while (nodeToVisit.length > 0) {
1968
+ const node = nodeToVisit.shift();
1969
+ if (ts.isVariableDeclaration(node) && node.initializer) {
1970
+ const expectedType = typeChecker.getTypeAtLocation(node.name);
1971
+ const realType = typeChecker.getTypeAtLocation(node.initializer);
1972
+ result.push([node.name, expectedType, node.initializer, realType]);
1973
+ appendNodeToVisit(node.initializer);
1974
+ continue;
1975
+ } else if (ts.isCallExpression(node)) {
1976
+ const resolvedSignature = typeChecker.getResolvedSignature(node);
1977
+ if (resolvedSignature) {
1978
+ resolvedSignature.getParameters().map((parameter, index) => {
1979
+ const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
1980
+ const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
1981
+ result.push([
1982
+ node.arguments[index],
1983
+ expectedType,
1984
+ node.arguments[index],
1985
+ realType
1986
+ ]);
1987
+ });
1988
+ }
1989
+ ts.forEachChild(node, appendNodeToVisit);
1990
+ continue;
1991
+ } else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
1992
+ const parent = node.parent;
1993
+ if (ts.isObjectLiteralElement(parent)) {
1994
+ if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
1995
+ const type = typeChecker.getContextualType(parent.parent);
1996
+ if (type) {
1997
+ const symbol3 = typeChecker.getPropertyOfType(type, node.text);
1998
+ if (symbol3) {
1999
+ const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
2000
+ const realType = typeChecker.getTypeAtLocation(node);
2001
+ result.push([node, expectedType, node, realType]);
2002
+ }
1986
2003
  }
1987
2004
  }
1988
2005
  }
1989
- }
1990
- ts.forEachChild(node, appendNodeToVisit);
1991
- continue;
1992
- } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
1993
- const expectedType = typeChecker.getTypeAtLocation(node.left);
1994
- const realType = typeChecker.getTypeAtLocation(node.right);
1995
- result.push([node.left, expectedType, node.right, realType]);
1996
- appendNodeToVisit(node.right);
1997
- continue;
1998
- } else if (ts.isReturnStatement(node) && node.expression) {
1999
- const parentDeclaration = yield* option(getAncestorConvertibleDeclaration(node));
2000
- if (isSome2(parentDeclaration)) {
2001
- const expectedType = yield* option(getInferredReturnType(parentDeclaration.value));
2002
- const realType = typeChecker.getTypeAtLocation(node.expression);
2006
+ ts.forEachChild(node, appendNodeToVisit);
2007
+ continue;
2008
+ } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
2009
+ const expectedType = typeChecker.getTypeAtLocation(node.left);
2010
+ const realType = typeChecker.getTypeAtLocation(node.right);
2011
+ result.push([node.left, expectedType, node.right, realType]);
2012
+ appendNodeToVisit(node.right);
2013
+ continue;
2014
+ } else if (ts.isReturnStatement(node) && node.expression) {
2015
+ const parentDeclaration = yield* option(getAncestorConvertibleDeclaration(node));
2016
+ if (isSome2(parentDeclaration)) {
2017
+ const expectedType = yield* option(getInferredReturnType(parentDeclaration.value));
2018
+ const realType = typeChecker.getTypeAtLocation(node.expression);
2019
+ if (isSome2(expectedType)) {
2020
+ result.push([node, expectedType.value, node, realType]);
2021
+ }
2022
+ }
2023
+ ts.forEachChild(node, appendNodeToVisit);
2024
+ continue;
2025
+ } else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
2026
+ const body = node.body;
2027
+ const expectedType = typeChecker.getContextualType(body);
2028
+ const realType = typeChecker.getTypeAtLocation(body);
2029
+ if (expectedType) {
2030
+ result.push([body, expectedType, body, realType]);
2031
+ }
2032
+ ts.forEachChild(body, appendNodeToVisit);
2033
+ continue;
2034
+ } else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
2035
+ const body = node.body;
2036
+ const expectedType = yield* option(getInferredReturnType(node));
2037
+ const realType = typeChecker.getTypeAtLocation(body);
2003
2038
  if (isSome2(expectedType)) {
2004
- result.push([node, expectedType.value, node, realType]);
2039
+ result.push([body, expectedType.value, body, realType]);
2005
2040
  }
2041
+ ts.forEachChild(body, appendNodeToVisit);
2042
+ continue;
2043
+ } else if (ts.isSatisfiesExpression(node)) {
2044
+ const expectedType = typeChecker.getTypeAtLocation(node.type);
2045
+ const realType = typeChecker.getTypeAtLocation(node.expression);
2046
+ result.push([node.expression, expectedType, node.expression, realType]);
2047
+ appendNodeToVisit(node.expression);
2048
+ continue;
2006
2049
  }
2007
2050
  ts.forEachChild(node, appendNodeToVisit);
2008
- continue;
2009
- } else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
2010
- const body = node.body;
2011
- const expectedType = typeChecker.getContextualType(body);
2012
- const realType = typeChecker.getTypeAtLocation(body);
2013
- if (expectedType) {
2014
- result.push([body, expectedType, body, realType]);
2015
- }
2016
- ts.forEachChild(body, appendNodeToVisit);
2017
- continue;
2018
- } else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
2019
- const body = node.body;
2020
- const expectedType = yield* option(getInferredReturnType(node));
2021
- const realType = typeChecker.getTypeAtLocation(body);
2022
- if (isSome2(expectedType)) {
2023
- result.push([body, expectedType.value, body, realType]);
2024
- }
2025
- ts.forEachChild(body, appendNodeToVisit);
2026
- continue;
2027
- } else if (ts.isSatisfiesExpression(node)) {
2028
- const expectedType = typeChecker.getTypeAtLocation(node.type);
2029
- const realType = typeChecker.getTypeAtLocation(node.expression);
2030
- result.push([node.expression, expectedType, node.expression, realType]);
2031
- appendNodeToVisit(node.expression);
2032
- continue;
2033
2051
  }
2034
- ts.forEachChild(node, appendNodeToVisit);
2035
- }
2036
- cache.expectedAndRealType.set(sourceFile, result);
2037
- return result;
2038
- });
2052
+ return result;
2053
+ }),
2054
+ "TypeCheckerApi.expectedAndRealType",
2055
+ (sourceFile) => sourceFile
2056
+ );
2039
2057
  var unrollUnionMembers = (type) => {
2040
2058
  const result = [];
2041
2059
  let toTest = [type];
@@ -2117,123 +2135,45 @@ var durationInput = createCompletion({
2117
2135
  if (start < position && position < end) {
2118
2136
  isInString = true;
2119
2137
  }
2120
- if (position === end) {
2121
- isInString = !!previousToken.isUnterminated;
2122
- }
2123
- if (isInString && ts.isExpression(previousToken)) {
2124
- const type = typeChecker.getContextualType(previousToken);
2125
- if (type) {
2126
- if (!type.isUnion()) return [];
2127
- for (const member of type.types) {
2128
- if (member.flags & ts.TypeFlags.TemplateLiteral) {
2129
- if (hasProperty(member, "texts") && isArray(member.texts) && member.texts.length === 2 && String(member.texts[1]).trim() === "nanos") {
2130
- return ["nanos", "micros", "millis", "seconds", "minutes", "hours", "days", "weeks"].map(
2131
- (name) => ({
2132
- name,
2133
- kind: ts.ScriptElementKind.string,
2134
- insertText: `${"${0}"} ${name}`,
2135
- isSnippet: true
2136
- })
2137
- );
2138
- }
2139
- }
2140
- }
2141
- }
2142
- }
2143
- }
2144
- return [];
2145
- })
2146
- });
2147
-
2148
- // src/completions/effectDataClasses.ts
2149
- var effectDataClasses = createCompletion({
2150
- name: "effectDataClasses",
2151
- apply: fn("effectDataClasses")(function* (sourceFile, position) {
2152
- const ts = yield* service(TypeScriptApi);
2153
- const maybeInfos = yield* option(
2154
- parseDataForExtendsClassCompletion(sourceFile, position)
2155
- );
2156
- if (isNone2(maybeInfos)) return [];
2157
- const { accessedObject, className, replacementSpan } = maybeInfos.value;
2158
- const dataName = yield* option(
2159
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
2160
- sourceFile,
2161
- "effect",
2162
- "Data"
2163
- )
2164
- );
2165
- const effectDataIdentifier = match(dataName, {
2166
- onNone: () => "Data",
2167
- onSome: (_) => _.text
2168
- });
2169
- if (effectDataIdentifier !== accessedObject.text) return [];
2170
- const name = className.text;
2171
- return [{
2172
- name: `TaggedError("${name}")`,
2173
- kind: ts.ScriptElementKind.constElement,
2174
- insertText: `${effectDataIdentifier}.TaggedError("${name}")<{${"${0}"}}>{}`,
2175
- replacementSpan,
2176
- isSnippet: true
2177
- }, {
2178
- name: `TaggedClass("${name}")`,
2179
- kind: ts.ScriptElementKind.constElement,
2180
- insertText: `${effectDataIdentifier}.TaggedClass("${name}")<{${"${0}"}}>{}`,
2181
- replacementSpan,
2182
- isSnippet: true
2183
- }];
2184
- })
2185
- });
2186
-
2187
- // src/diagnostics/duplicatePackage.ts
2188
- var checkedPackagesCache = /* @__PURE__ */ new Map();
2189
- var programResolvedCacheSize = /* @__PURE__ */ new Map();
2190
- var duplicatePackage = createDiagnostic({
2191
- name: "duplicatePackage",
2192
- code: 6,
2193
- severity: "warning",
2194
- apply: fn("duplicatePackage.apply")(function* (sourceFile, report) {
2195
- const program = yield* service(TypeScriptProgram);
2196
- const options = yield* service(LanguageServicePluginOptions);
2197
- if (sourceFile.statements.length < 1) return;
2198
- let resolvedPackages = checkedPackagesCache.get(sourceFile.fileName) || {};
2199
- const newResolvedModuleSize = hasProperty(program, "resolvedModules") && hasProperty(program.resolvedModules, "size") && isNumber(program.resolvedModules.size) ? program.resolvedModules.size : 0;
2200
- const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1;
2201
- if (newResolvedModuleSize !== oldResolvedSize) {
2202
- const seenPackages = /* @__PURE__ */ new Set();
2203
- resolvedPackages = {};
2204
- program.getSourceFiles().map((_) => {
2205
- const packageInfo = parsePackageContentNameAndVersionFromScope(_);
2206
- if (!packageInfo) return;
2207
- const packageNameAndVersion = packageInfo.name + "@" + packageInfo.version;
2208
- if (seenPackages.has(packageNameAndVersion)) return;
2209
- seenPackages.add(packageNameAndVersion);
2210
- if (!(packageInfo.name === "effect" || packageInfo.hasEffectInPeerDependencies)) return;
2211
- if (options.allowedDuplicatedPackages.indexOf(packageInfo.name) > -1) return;
2212
- resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {};
2213
- resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.packageDirectory;
2214
- });
2215
- checkedPackagesCache.set(sourceFile.fileName, resolvedPackages);
2216
- programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize);
2217
- }
2218
- for (const packageName of Object.keys(resolvedPackages)) {
2219
- if (Object.keys(resolvedPackages[packageName]).length > 1) {
2220
- const versions = Object.keys(resolvedPackages[packageName]);
2221
- report({
2222
- node: sourceFile.statements[0],
2223
- messageText: `Package ${packageName} is referenced multiple times with different versions (${versions.join(", ")}) and may cause unexpected type errors.
2224
- Cleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.
2225
- If this is intended set the LSP config "allowedDuplicatedPackages" to ${JSON.stringify(options.allowedDuplicatedPackages.concat([packageName]))}.
2226
-
2227
- ${versions.map((version) => `- found ${version} at ${resolvedPackages[packageName][version]}`).join("\n")}`,
2228
- fixes: []
2229
- });
2230
- }
2138
+ if (position === end) {
2139
+ isInString = !!previousToken.isUnterminated;
2140
+ }
2141
+ if (isInString && ts.isExpression(previousToken)) {
2142
+ const type = typeChecker.getContextualType(previousToken);
2143
+ if (type) {
2144
+ if (!type.isUnion()) return [];
2145
+ for (const member of type.types) {
2146
+ if (member.flags & ts.TypeFlags.TemplateLiteral) {
2147
+ if (hasProperty(member, "texts") && isArray(member.texts) && member.texts.length === 2 && String(member.texts[1]).trim() === "nanos") {
2148
+ return ["nanos", "micros", "millis", "seconds", "minutes", "hours", "days", "weeks"].map(
2149
+ (name) => ({
2150
+ name,
2151
+ kind: ts.ScriptElementKind.string,
2152
+ insertText: `${"${0}"} ${name}`,
2153
+ isSnippet: true
2154
+ })
2155
+ );
2156
+ }
2157
+ }
2158
+ }
2159
+ }
2160
+ }
2231
2161
  }
2162
+ return [];
2232
2163
  })
2233
2164
  });
2234
2165
 
2235
2166
  // src/core/TypeParser.ts
2236
2167
  var TypeParser = Tag("@effect/language-service/TypeParser");
2168
+ var nanoLayer2 = (fa) => gen(function* () {
2169
+ const ts = yield* service(TypeScriptApi);
2170
+ const tsUtils = yield* service(TypeScriptUtils);
2171
+ const typeChecker = yield* service(TypeCheckerApi);
2172
+ return yield* pipe(
2173
+ fa,
2174
+ provideService(TypeParser, make3(ts, tsUtils, typeChecker))
2175
+ );
2176
+ });
2237
2177
  var TypeParserIssue = class _TypeParserIssue {
2238
2178
  _tag = "@effect/language-service/TypeParserIssue";
2239
2179
  static issue = fail(new _TypeParserIssue());
@@ -2241,7 +2181,7 @@ var TypeParserIssue = class _TypeParserIssue {
2241
2181
  function typeParserIssue(_message, _type, _node) {
2242
2182
  return TypeParserIssue.issue;
2243
2183
  }
2244
- function make3(ts, typeChecker) {
2184
+ function make3(ts, tsUtils, typeChecker) {
2245
2185
  function covariantTypeArgument(type) {
2246
2186
  const signatures = type.getCallSignatures();
2247
2187
  if (signatures.length !== 1) {
@@ -2303,7 +2243,7 @@ function make3(ts, typeChecker) {
2303
2243
  const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
2304
2244
  return invariantTypeArgument(propertyType);
2305
2245
  };
2306
- const effectVarianceStruct = (type, atLocation) => map4(
2246
+ const effectVarianceStruct = (type, atLocation) => map3(
2307
2247
  all(
2308
2248
  varianceStructCovariantType(type, atLocation, "_A"),
2309
2249
  varianceStructCovariantType(type, atLocation, "_E"),
@@ -2311,7 +2251,7 @@ function make3(ts, typeChecker) {
2311
2251
  ),
2312
2252
  ([A, E, R]) => ({ A, E, R })
2313
2253
  );
2314
- const layerVarianceStruct = (type, atLocation) => map4(
2254
+ const layerVarianceStruct = (type, atLocation) => map3(
2315
2255
  all(
2316
2256
  varianceStructContravariantType(type, atLocation, "_ROut"),
2317
2257
  varianceStructCovariantType(type, atLocation, "_E"),
@@ -2440,7 +2380,7 @@ function make3(ts, typeChecker) {
2440
2380
  }
2441
2381
  return pipe(
2442
2382
  importedEffectModule(propertyAccess.expression),
2443
- map4((effectModule) => ({
2383
+ map3((effectModule) => ({
2444
2384
  node,
2445
2385
  effectModule,
2446
2386
  generatorFunction,
@@ -2488,7 +2428,7 @@ function make3(ts, typeChecker) {
2488
2428
  }
2489
2429
  return pipe(
2490
2430
  importedEffectModule(propertyAccess.expression),
2491
- map4((effectModule) => ({
2431
+ map3((effectModule) => ({
2492
2432
  node,
2493
2433
  effectModule,
2494
2434
  generatorFunction,
@@ -2541,7 +2481,7 @@ function make3(ts, typeChecker) {
2541
2481
  }
2542
2482
  return pipe(
2543
2483
  importedEffectModule(propertyAccess.expression),
2544
- map4((effectModule) => ({
2484
+ map3((effectModule) => ({
2545
2485
  node,
2546
2486
  generatorFunction,
2547
2487
  effectModule,
@@ -2583,15 +2523,11 @@ function make3(ts, typeChecker) {
2583
2523
  if (!explicitReturn && !(successType.flags & ts.TypeFlags.VoidLike)) {
2584
2524
  replacementNode = pipe(
2585
2525
  gen(function* () {
2586
- const effectIdentifier = pipe(
2587
- yield* option(
2588
- findImportedModuleIdentifierByPackageAndNameOrBarrel(node.getSourceFile(), "effect", "Effect")
2589
- ),
2590
- match({
2591
- onNone: () => "Effect",
2592
- onSome: (_) => _.text
2593
- })
2594
- );
2526
+ const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
2527
+ node.getSourceFile(),
2528
+ "effect",
2529
+ "Effect"
2530
+ ) || "Effect";
2595
2531
  return ts.factory.createCallExpression(
2596
2532
  ts.factory.createPropertyAccessExpression(
2597
2533
  ts.factory.createIdentifier(effectIdentifier),
@@ -2619,7 +2555,7 @@ function make3(ts, typeChecker) {
2619
2555
  "TypeParser.unnecessaryEffectGen",
2620
2556
  (node) => node
2621
2557
  );
2622
- const effectSchemaVarianceStruct = (type, atLocation) => map4(
2558
+ const effectSchemaVarianceStruct = (type, atLocation) => map3(
2623
2559
  all(
2624
2560
  varianceStructInvariantType(type, atLocation, "_A"),
2625
2561
  varianceStructInvariantType(type, atLocation, "_I"),
@@ -2651,7 +2587,7 @@ function make3(ts, typeChecker) {
2651
2587
  "TypeParser.effectSchemaType",
2652
2588
  (type) => type
2653
2589
  );
2654
- const contextTagVarianceStruct = (type, atLocation) => map4(
2590
+ const contextTagVarianceStruct = (type, atLocation) => map3(
2655
2591
  all(
2656
2592
  varianceStructInvariantType(type, atLocation, "_Identifier"),
2657
2593
  varianceStructInvariantType(type, atLocation, "_Service")
@@ -2759,6 +2695,64 @@ function make3(ts, typeChecker) {
2759
2695
  "TypeParser.promiseLike",
2760
2696
  (type) => type
2761
2697
  );
2698
+ const extendsEffectService = cachedBy(
2699
+ fn("TypeParser.extendsEffectService")(function* (atLocation) {
2700
+ if (!atLocation.name) {
2701
+ return yield* typeParserIssue("Class has no name", void 0, atLocation);
2702
+ }
2703
+ const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
2704
+ if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
2705
+ const type = typeChecker.getTypeOfSymbol(classSym);
2706
+ const heritageClauses = atLocation.heritageClauses;
2707
+ if (!heritageClauses) {
2708
+ return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
2709
+ }
2710
+ for (const heritageClause of heritageClauses) {
2711
+ for (const typeX of heritageClause.types) {
2712
+ if (ts.isExpressionWithTypeArguments(typeX)) {
2713
+ const wholeCall = typeX.expression;
2714
+ if (ts.isCallExpression(wholeCall)) {
2715
+ const effectServiceCall = wholeCall.expression;
2716
+ if (ts.isCallExpression(effectServiceCall) && effectServiceCall.typeArguments && effectServiceCall.typeArguments.length > 0) {
2717
+ const effectServiceIdentifier = effectServiceCall.expression;
2718
+ const selfTypeNode = effectServiceCall.typeArguments[0];
2719
+ if (ts.isPropertyAccessExpression(effectServiceIdentifier) && ts.isIdentifier(effectServiceIdentifier.name) && effectServiceIdentifier.name.text === "Service") {
2720
+ const parsedContextTag = yield* pipe(
2721
+ importedEffectModule(effectServiceIdentifier.expression),
2722
+ flatMap(() => contextTag(type, atLocation)),
2723
+ option
2724
+ );
2725
+ if (isSome2(parsedContextTag)) {
2726
+ let accessors2 = void 0;
2727
+ if (wholeCall.arguments.length >= 2) {
2728
+ const args2 = wholeCall.arguments[1];
2729
+ if (ts.isObjectLiteralExpression(args2)) {
2730
+ for (const property of args2.properties) {
2731
+ if (ts.isPropertyAssignment(property) && property.name && ts.isIdentifier(property.name) && property.name.text === "accessors" && property.initializer && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
2732
+ accessors2 = true;
2733
+ }
2734
+ }
2735
+ }
2736
+ }
2737
+ return {
2738
+ ...parsedContextTag.value,
2739
+ className: atLocation.name,
2740
+ selfTypeNode,
2741
+ args: wholeCall.arguments,
2742
+ accessors: accessors2
2743
+ };
2744
+ }
2745
+ }
2746
+ }
2747
+ }
2748
+ }
2749
+ }
2750
+ }
2751
+ return yield* typeParserIssue("Class does not extend Effect.Service", void 0, atLocation);
2752
+ }),
2753
+ "TypeParser.extendsEffectService",
2754
+ (atLocation) => atLocation
2755
+ );
2762
2756
  return {
2763
2757
  effectType,
2764
2758
  strictEffectType,
@@ -2775,10 +2769,395 @@ function make3(ts, typeChecker) {
2775
2769
  pipeableType,
2776
2770
  pipeCall,
2777
2771
  scopeType,
2778
- promiseLike
2772
+ promiseLike,
2773
+ extendsEffectService
2779
2774
  };
2780
2775
  }
2781
2776
 
2777
+ // src/refactors/writeTagClassAccessors.ts
2778
+ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, service2, className, atLocation, involvedMembers) {
2779
+ const ts = yield* service(TypeScriptApi);
2780
+ const tsUtils = yield* service(TypeScriptUtils);
2781
+ const typeChecker = yield* service(TypeCheckerApi);
2782
+ const typeParser = yield* service(TypeParser);
2783
+ const changeTracker = yield* service(ChangeTracker);
2784
+ const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.getEnd() - 1;
2785
+ const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
2786
+ sourceFile,
2787
+ "effect",
2788
+ "Effect"
2789
+ ) || "Effect";
2790
+ const createFunctionProperty = (className2, propertyName, type, forceAny) => {
2791
+ const arrowBody = ts.factory.createCallExpression(
2792
+ ts.factory.createPropertyAccessExpression(
2793
+ ts.factory.createIdentifier(effectIdentifier),
2794
+ "andThen"
2795
+ ),
2796
+ void 0,
2797
+ [
2798
+ ts.factory.createIdentifier(className2.text),
2799
+ ts.factory.createArrowFunction(
2800
+ void 0,
2801
+ void 0,
2802
+ [ts.factory.createParameterDeclaration(
2803
+ void 0,
2804
+ void 0,
2805
+ "_",
2806
+ void 0,
2807
+ forceAny ? ts.factory.createTypeReferenceNode("any") : void 0
2808
+ )],
2809
+ void 0,
2810
+ void 0,
2811
+ ts.factory.createCallExpression(
2812
+ ts.factory.createPropertyAccessExpression(
2813
+ ts.factory.createIdentifier("_"),
2814
+ propertyName
2815
+ ),
2816
+ void 0,
2817
+ [
2818
+ ts.factory.createSpreadElement(ts.factory.createIdentifier("args"))
2819
+ ]
2820
+ )
2821
+ )
2822
+ ]
2823
+ );
2824
+ return ts.factory.createPropertyDeclaration(
2825
+ [ts.factory.createModifier(ts.SyntaxKind.StaticKeyword)],
2826
+ propertyName,
2827
+ void 0,
2828
+ type,
2829
+ ts.factory.createArrowFunction(
2830
+ void 0,
2831
+ void 0,
2832
+ [ts.factory.createParameterDeclaration(
2833
+ void 0,
2834
+ ts.factory.createToken(ts.SyntaxKind.DotDotDotToken),
2835
+ "args",
2836
+ void 0,
2837
+ forceAny ? ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode("any")) : void 0
2838
+ )],
2839
+ void 0,
2840
+ void 0,
2841
+ forceAny ? ts.factory.createAsExpression(arrowBody, ts.factory.createTypeReferenceNode("any")) : arrowBody
2842
+ )
2843
+ );
2844
+ };
2845
+ const generateReturnType = (type, atLocation2, className2) => pipe(
2846
+ typeParser.effectType(type, atLocation2),
2847
+ flatMap((returnedEffect) => {
2848
+ const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(className2.text) : ts.factory.createUnionTypeNode(
2849
+ [
2850
+ ts.factory.createTypeReferenceNode(className2.text),
2851
+ typeChecker.typeToTypeNode(returnedEffect.R, atLocation2, ts.NodeBuilderFlags.NoTruncation)
2852
+ ]
2853
+ );
2854
+ const successType = typeChecker.typeToTypeNode(
2855
+ returnedEffect.A,
2856
+ atLocation2,
2857
+ ts.NodeBuilderFlags.NoTruncation
2858
+ );
2859
+ if (!successType) return fail("error generating success type");
2860
+ const failureType = typeChecker.typeToTypeNode(
2861
+ returnedEffect.E,
2862
+ atLocation2,
2863
+ ts.NodeBuilderFlags.NoTruncation
2864
+ );
2865
+ if (!failureType) return fail("error generating failure type");
2866
+ const typeNode = ts.factory.createTypeReferenceNode(
2867
+ ts.factory.createQualifiedName(
2868
+ ts.factory.createIdentifier(effectIdentifier),
2869
+ ts.factory.createIdentifier("Effect")
2870
+ ),
2871
+ [successType, failureType, contextType]
2872
+ );
2873
+ return succeed(typeNode);
2874
+ }),
2875
+ orElse2(
2876
+ () => pipe(
2877
+ typeParser.promiseLike(type, atLocation2),
2878
+ flatMap(({ type: type2 }) => {
2879
+ const successType = typeChecker.typeToTypeNode(
2880
+ type2,
2881
+ atLocation2,
2882
+ ts.NodeBuilderFlags.NoTruncation
2883
+ );
2884
+ if (!successType) return fail("error generating success type");
2885
+ return succeed(ts.factory.createTypeReferenceNode(
2886
+ ts.factory.createQualifiedName(
2887
+ ts.factory.createIdentifier(effectIdentifier),
2888
+ ts.factory.createIdentifier("Effect")
2889
+ ),
2890
+ [
2891
+ successType,
2892
+ ts.factory.createTypeReferenceNode(
2893
+ ts.factory.createQualifiedName(
2894
+ ts.factory.createIdentifier("Cause"),
2895
+ ts.factory.createIdentifier("UnknownException")
2896
+ )
2897
+ ),
2898
+ ts.factory.createTypeReferenceNode(className2.text)
2899
+ ]
2900
+ ));
2901
+ })
2902
+ )
2903
+ ),
2904
+ orElse2(() => {
2905
+ const successType = typeChecker.typeToTypeNode(type, atLocation2, ts.NodeBuilderFlags.NoTruncation);
2906
+ if (!successType) return fail("error generating success type");
2907
+ const typeNode = ts.factory.createTypeReferenceNode(
2908
+ ts.factory.createQualifiedName(
2909
+ ts.factory.createIdentifier(effectIdentifier),
2910
+ ts.factory.createIdentifier("Effect")
2911
+ ),
2912
+ [
2913
+ successType,
2914
+ ts.factory.createTypeReferenceNode("never"),
2915
+ ts.factory.createTypeReferenceNode(className2.text)
2916
+ ]
2917
+ );
2918
+ return succeed(typeNode);
2919
+ })
2920
+ );
2921
+ const proxySignature = (signature, atLocation2, className2) => gen(function* () {
2922
+ const signatureDeclaration = typeChecker.signatureToSignatureDeclaration(
2923
+ signature,
2924
+ ts.SyntaxKind.FunctionType,
2925
+ atLocation2,
2926
+ ts.NodeBuilderFlags.NoTruncation
2927
+ );
2928
+ if (!signatureDeclaration) return yield* fail("error generating signature");
2929
+ const returnType = yield* generateReturnType(signature.getReturnType(), atLocation2, className2);
2930
+ return ts.factory.createFunctionTypeNode(
2931
+ signatureDeclaration.typeParameters,
2932
+ signatureDeclaration.parameters,
2933
+ returnType
2934
+ );
2935
+ });
2936
+ for (const { property, propertyType } of involvedMembers) {
2937
+ const callSignatures = [];
2938
+ let propertyDeclaration = void 0;
2939
+ for (const signature of propertyType.getCallSignatures()) {
2940
+ yield* pipe(
2941
+ proxySignature(signature, atLocation, className),
2942
+ map3((sig) => {
2943
+ callSignatures.push(sig);
2944
+ }),
2945
+ ignore
2946
+ );
2947
+ }
2948
+ const allSignatures = ts.factory.createIntersectionTypeNode(callSignatures);
2949
+ const type = tsUtils.simplifyTypeNode(allSignatures);
2950
+ propertyDeclaration = createFunctionProperty(className, property.getName(), type, callSignatures.length > 1);
2951
+ const oldProperty = atLocation.members.filter(ts.isPropertyDeclaration).find((p) => {
2952
+ const symbol3 = typeChecker.getSymbolAtLocation(p.name);
2953
+ return symbol3?.getName() === property.getName();
2954
+ });
2955
+ if (oldProperty) {
2956
+ changeTracker.deleteRange(sourceFile, {
2957
+ pos: oldProperty.getStart(sourceFile),
2958
+ end: oldProperty.getEnd()
2959
+ });
2960
+ changeTracker.insertNodeAt(sourceFile, oldProperty.getStart(sourceFile), propertyDeclaration);
2961
+ } else {
2962
+ changeTracker.insertNodeAt(sourceFile, insertLocation, propertyDeclaration, { suffix: "\n" });
2963
+ }
2964
+ }
2965
+ });
2966
+ var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
2967
+ const ts = yield* service(TypeScriptApi);
2968
+ const typeChecker = yield* service(TypeCheckerApi);
2969
+ const typeParser = yield* service(TypeParser);
2970
+ if (!ts.isClassDeclaration(node)) return yield* fail("not a class declaration");
2971
+ const { Service, accessors: accessors2, className } = yield* pipe(
2972
+ typeParser.extendsEffectService(node),
2973
+ orElse2(() => fail("not a class extending Effect.Service call"))
2974
+ );
2975
+ if (accessors2 !== true) return yield* fail("accessors are not enabled in the Effect.Service call");
2976
+ const involvedMembers = [];
2977
+ for (const property of typeChecker.getPropertiesOfType(Service)) {
2978
+ const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, node);
2979
+ const callSignatures = propertyType.getCallSignatures();
2980
+ if (callSignatures.length > 0) {
2981
+ const withTypeParameters = callSignatures.filter((_) => _.typeParameters && _.typeParameters.length > 0);
2982
+ if (callSignatures.length > 1 || withTypeParameters.length > 0) involvedMembers.push({ property, propertyType });
2983
+ }
2984
+ }
2985
+ const hash2 = involvedMembers.map(({ property, propertyType }) => {
2986
+ return property.getName() + ": " + typeChecker.typeToString(propertyType);
2987
+ }).concat([className.text]).join("\n");
2988
+ return { Service, className, atLocation: node, hash: cyrb53(hash2), involvedMembers };
2989
+ });
2990
+ var writeTagClassAccessors = createRefactor({
2991
+ name: "writeTagClassAccessors",
2992
+ description: "Implement accessors methods with generics or multiple signatures",
2993
+ apply: fn("writeTagClassAccessors.apply")(function* (sourceFile, textRange) {
2994
+ const ts = yield* service(TypeScriptApi);
2995
+ const tsUtils = yield* service(TypeScriptUtils);
2996
+ const typeChecker = yield* service(TypeCheckerApi);
2997
+ const typeParser = yield* service(TypeParser);
2998
+ const parseNode = (node) => pipe(
2999
+ parse2(node),
3000
+ map3(({ Service, atLocation, className, involvedMembers }) => ({
3001
+ kind: "refactor.rewrite.effect.writeTagClassAccessors",
3002
+ description: "Implement Service accessors",
3003
+ apply: pipe(
3004
+ generate(sourceFile, Service, className, atLocation, involvedMembers),
3005
+ provideService(TypeScriptUtils, tsUtils),
3006
+ provideService(TypeParser, typeParser),
3007
+ provideService(TypeCheckerApi, typeChecker),
3008
+ provideService(TypeScriptApi, ts)
3009
+ )
3010
+ }))
3011
+ );
3012
+ const parentNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange);
3013
+ return yield* pipe(
3014
+ firstSuccessOf(parentNodes.map(parseNode)),
3015
+ orElse2(() => fail(new RefactorNotApplicableError()))
3016
+ );
3017
+ })
3018
+ });
3019
+
3020
+ // src/codegens/accessors.ts
3021
+ var accessors = createCodegen({
3022
+ name: "accessors",
3023
+ apply: fn("accessors.apply")(function* (sourceFile, textRange) {
3024
+ const ts = yield* service(TypeScriptApi);
3025
+ const tsUtils = yield* service(TypeScriptUtils);
3026
+ const typeChecker = yield* service(TypeCheckerApi);
3027
+ const typeParser = yield* service(TypeParser);
3028
+ const nodeAndCommentRange = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, textRange.pos);
3029
+ if (!nodeAndCommentRange) return yield* fail(new CodegenNotApplicableError("no node and comment range"));
3030
+ return yield* pipe(
3031
+ parse2(nodeAndCommentRange.node),
3032
+ map3(
3033
+ (_) => ({
3034
+ hash: _.hash,
3035
+ description: "Generate accessors for the service",
3036
+ apply: pipe(
3037
+ generate(sourceFile, _.Service, _.className, _.atLocation, _.involvedMembers),
3038
+ provideService(TypeScriptApi, ts),
3039
+ provideService(TypeScriptUtils, tsUtils),
3040
+ provideService(TypeCheckerApi, typeChecker),
3041
+ provideService(TypeParser, typeParser)
3042
+ )
3043
+ })
3044
+ ),
3045
+ orElse2((cause) => fail(new CodegenNotApplicableError(cause)))
3046
+ );
3047
+ })
3048
+ });
3049
+
3050
+ // src/codegens.ts
3051
+ var codegens = [accessors];
3052
+
3053
+ // src/completions/effectCodegensComment.ts
3054
+ var effectCodegensComment = createCompletion({
3055
+ name: "effectCodegensComment",
3056
+ apply: fn("effectCodegensComment")(function* (sourceFile, position) {
3057
+ const ts = yield* service(TypeScriptApi);
3058
+ const sourceText = sourceFile.text;
3059
+ const match2 = /(\/\/|\/\*(?:\*?))\s*(@)\s*$/id.exec(sourceText.substring(0, position));
3060
+ if (match2 && match2.indices) {
3061
+ const lastIndex = match2.indices[2][0];
3062
+ const replacementSpan = {
3063
+ start: lastIndex,
3064
+ length: Math.max(0, position - lastIndex)
3065
+ };
3066
+ const allCodegens = sort(Object.values(codegens).map((codegen) => codegen.name), string2).join(",");
3067
+ const enableSnippet = "${1|" + allCodegens + "|} $0";
3068
+ return [{
3069
+ name: `@effect-codegens`,
3070
+ kind: ts.ScriptElementKind.string,
3071
+ insertText: "@effect-codegens " + enableSnippet,
3072
+ isSnippet: true,
3073
+ replacementSpan
3074
+ }];
3075
+ }
3076
+ return [];
3077
+ })
3078
+ });
3079
+
3080
+ // src/completions/effectDataClasses.ts
3081
+ var effectDataClasses = createCompletion({
3082
+ name: "effectDataClasses",
3083
+ apply: fn("effectDataClasses")(function* (sourceFile, position) {
3084
+ const ts = yield* service(TypeScriptApi);
3085
+ const tsUtils = yield* service(TypeScriptUtils);
3086
+ const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
3087
+ if (!maybeInfos) return [];
3088
+ const { accessedObject, className, replacementSpan } = maybeInfos;
3089
+ const effectDataIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
3090
+ sourceFile,
3091
+ "effect",
3092
+ "Data"
3093
+ ) || "Data";
3094
+ if (effectDataIdentifier !== accessedObject.text) return [];
3095
+ const name = className.text;
3096
+ return [{
3097
+ name: `TaggedError("${name}")`,
3098
+ kind: ts.ScriptElementKind.constElement,
3099
+ insertText: `${effectDataIdentifier}.TaggedError("${name}")<{${"${0}"}}>{}`,
3100
+ replacementSpan,
3101
+ isSnippet: true
3102
+ }, {
3103
+ name: `TaggedClass("${name}")`,
3104
+ kind: ts.ScriptElementKind.constElement,
3105
+ insertText: `${effectDataIdentifier}.TaggedClass("${name}")<{${"${0}"}}>{}`,
3106
+ replacementSpan,
3107
+ isSnippet: true
3108
+ }];
3109
+ })
3110
+ });
3111
+
3112
+ // src/diagnostics/duplicatePackage.ts
3113
+ var checkedPackagesCache = /* @__PURE__ */ new Map();
3114
+ var programResolvedCacheSize = /* @__PURE__ */ new Map();
3115
+ var duplicatePackage = createDiagnostic({
3116
+ name: "duplicatePackage",
3117
+ code: 6,
3118
+ severity: "warning",
3119
+ apply: fn("duplicatePackage.apply")(function* (sourceFile, report) {
3120
+ const program = yield* service(TypeScriptProgram);
3121
+ const tsUtils = yield* service(TypeScriptUtils);
3122
+ const options = yield* service(LanguageServicePluginOptions);
3123
+ if (sourceFile.statements.length < 1) return;
3124
+ let resolvedPackages = checkedPackagesCache.get(sourceFile.fileName) || {};
3125
+ const newResolvedModuleSize = hasProperty(program, "resolvedModules") && hasProperty(program.resolvedModules, "size") && isNumber(program.resolvedModules.size) ? program.resolvedModules.size : 0;
3126
+ const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1;
3127
+ if (newResolvedModuleSize !== oldResolvedSize) {
3128
+ const seenPackages = /* @__PURE__ */ new Set();
3129
+ resolvedPackages = {};
3130
+ program.getSourceFiles().map((_) => {
3131
+ const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(_);
3132
+ if (!packageInfo) return;
3133
+ const packageNameAndVersion = packageInfo.name + "@" + packageInfo.version;
3134
+ if (seenPackages.has(packageNameAndVersion)) return;
3135
+ seenPackages.add(packageNameAndVersion);
3136
+ if (!(packageInfo.name === "effect" || packageInfo.hasEffectInPeerDependencies)) return;
3137
+ if (options.allowedDuplicatedPackages.indexOf(packageInfo.name) > -1) return;
3138
+ resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {};
3139
+ resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.packageDirectory;
3140
+ });
3141
+ checkedPackagesCache.set(sourceFile.fileName, resolvedPackages);
3142
+ programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize);
3143
+ }
3144
+ for (const packageName of Object.keys(resolvedPackages)) {
3145
+ if (Object.keys(resolvedPackages[packageName]).length > 1) {
3146
+ const versions = Object.keys(resolvedPackages[packageName]);
3147
+ report({
3148
+ location: sourceFile.statements[0],
3149
+ messageText: `Package ${packageName} is referenced multiple times with different versions (${versions.join(", ")}) and may cause unexpected type errors.
3150
+ Cleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.
3151
+ If this is intended set the LSP config "allowedDuplicatedPackages" to ${JSON.stringify(options.allowedDuplicatedPackages.concat([packageName]))}.
3152
+
3153
+ ${versions.map((version) => `- found ${version} at ${resolvedPackages[packageName][version]}`).join("\n")}`,
3154
+ fixes: []
3155
+ });
3156
+ }
3157
+ }
3158
+ })
3159
+ });
3160
+
2782
3161
  // src/diagnostics/effectInVoidSuccess.ts
2783
3162
  var effectInVoidSuccess = createDiagnostic({
2784
3163
  name: "effectInVoidSuccess",
@@ -2794,7 +3173,7 @@ var effectInVoidSuccess = createDiagnostic({
2794
3173
  if (expectedEffect.A.flags & ts.TypeFlags.Void) {
2795
3174
  const voidValueTypes = unrollUnionMembers(realEffect.A);
2796
3175
  const voidedEffect = yield* firstSuccessOf(
2797
- voidValueTypes.map((_) => map4(typeParser.strictEffectType(_, node), () => _))
3176
+ voidValueTypes.map((_) => map3(typeParser.strictEffectType(_, node), () => _))
2798
3177
  );
2799
3178
  return { voidedEffect };
2800
3179
  }
@@ -2810,10 +3189,10 @@ var effectInVoidSuccess = createDiagnostic({
2810
3189
  valueNode,
2811
3190
  realType
2812
3191
  ),
2813
- map4(({ voidedEffect }) => {
3192
+ map3(({ voidedEffect }) => {
2814
3193
  report(
2815
3194
  {
2816
- node,
3195
+ location: node,
2817
3196
  messageText: `There is a nested '${typeChecker.typeToString(voidedEffect)}' in the 'void' success channel, beware that this could lead to nested Effect<Effect<...>> that won't be executed.`,
2818
3197
  fixes: []
2819
3198
  }
@@ -2862,7 +3241,7 @@ var floatingEffect = createDiagnostic({
2862
3241
  );
2863
3242
  if (isNone2(allowedFloatingEffects)) {
2864
3243
  report({
2865
- node,
3244
+ location: node,
2866
3245
  messageText: `Effect must be yielded or assigned to a variable.`,
2867
3246
  fixes: []
2868
3247
  });
@@ -2903,9 +3282,9 @@ var genericEffectServices = createDiagnostic({
2903
3282
  for (const [type, reportAt] of typesToCheck) {
2904
3283
  yield* pipe(
2905
3284
  typeParser.contextTag(type, node),
2906
- map4(() => {
3285
+ map3(() => {
2907
3286
  report({
2908
- node: reportAt,
3287
+ location: reportAt,
2909
3288
  messageText: `Effect Services with type parameters are not supported because they cannot be properly discriminated at runtime, which may cause unexpected behavior.`,
2910
3289
  fixes: []
2911
3290
  });
@@ -2927,17 +3306,16 @@ var importFromBarrel = createDiagnostic({
2927
3306
  const languageServicePluginOptions = yield* service(LanguageServicePluginOptions);
2928
3307
  if (languageServicePluginOptions.namespaceImportPackages.length === 0) return;
2929
3308
  const ts = yield* service(TypeScriptApi);
3309
+ const tsUtils = yield* service(TypeScriptUtils);
2930
3310
  const typeChecker = yield* service(TypeCheckerApi);
2931
3311
  const program = yield* service(TypeScriptProgram);
2932
3312
  const packageNamesToCheck = flatten(
2933
- yield* all(
2934
- ...languageServicePluginOptions.namespaceImportPackages.map(
2935
- (packageName) => resolveModulePattern(sourceFile, packageName)
2936
- )
3313
+ languageServicePluginOptions.namespaceImportPackages.map(
3314
+ (packageName) => tsUtils.resolveModulePattern(sourceFile, packageName)
2937
3315
  )
2938
3316
  );
2939
3317
  const isImportedFromBarrelExport = (element) => {
2940
- const getModuleSpecifier = makeGetModuleSpecifier(ts);
3318
+ const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
2941
3319
  const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
2942
3320
  if (!(getModuleSpecifier && resolveExternalModuleName)) return;
2943
3321
  const importDeclaration = ts.findAncestor(element, (node) => ts.isImportDeclaration(node));
@@ -3013,7 +3391,7 @@ var importFromBarrel = createDiagnostic({
3013
3391
  unbarrelledFileName
3014
3392
  } = result;
3015
3393
  report({
3016
- node,
3394
+ location: node,
3017
3395
  messageText: `Importing from barrel module ${barrelModuleName} is not allowed.`,
3018
3396
  fixes: [
3019
3397
  {
@@ -3078,13 +3456,13 @@ var leakingRequirements = createDiagnostic({
3078
3456
  let effectContextType = void 0;
3079
3457
  yield* pipe(
3080
3458
  typeParser.effectType(servicePropertyType, atLocation),
3081
- map4((_) => effectContextType = _.R),
3459
+ map3((_) => effectContextType = _.R),
3082
3460
  orElse2(() => {
3083
3461
  const servicePropertyCallSignatures = servicePropertyType.getCallSignatures();
3084
3462
  if (servicePropertyCallSignatures.length === 1) {
3085
3463
  return pipe(
3086
3464
  typeParser.effectType(servicePropertyCallSignatures[0].getReturnType(), atLocation),
3087
- map4((_) => {
3465
+ map3((_) => {
3088
3466
  effectContextType = _.R;
3089
3467
  })
3090
3468
  );
@@ -3102,7 +3480,7 @@ var leakingRequirements = createDiagnostic({
3102
3480
  if (type.flags & ts.TypeFlags.Never) return succeed(true);
3103
3481
  return pipe(
3104
3482
  typeParser.scopeType(type, atLocation),
3105
- map4(() => true),
3483
+ map3(() => true),
3106
3484
  orElse2(() => succeed(false))
3107
3485
  );
3108
3486
  }
@@ -3127,7 +3505,7 @@ var leakingRequirements = createDiagnostic({
3127
3505
  function reportLeakingRequirements(node, requirements) {
3128
3506
  if (requirements.length === 0) return;
3129
3507
  report({
3130
- node,
3508
+ location: node,
3131
3509
  messageText: `This Service is leaking the ${requirements.map((_) => typeChecker.typeToString(_)).join(" | ")} requirement.
3132
3510
  If these requirements cannot be cached and are expected to be provided per method invocation (e.g. HttpServerRequest), you can safely disable this diagnostic for this line through quickfixes.
3133
3511
  More info at https://effect.website/docs/requirements-management/layers/#avoiding-requirement-leakage`,
@@ -3158,10 +3536,10 @@ More info at https://effect.website/docs/requirements-management/layers/#avoidin
3158
3536
  for (const [type, reportAt] of typesToCheck) {
3159
3537
  yield* pipe(
3160
3538
  typeParser.contextTag(type, node),
3161
- flatMap2(
3539
+ flatMap(
3162
3540
  ({ Service }) => pipe(
3163
3541
  parseLeakedRequirements(Service, node),
3164
- map4((requirements) => reportLeakingRequirements(reportAt, sort(requirements, typeOrder)))
3542
+ map3((requirements) => reportLeakingRequirements(reportAt, sort(requirements, typeOrder)))
3165
3543
  )
3166
3544
  ),
3167
3545
  orElse2(() => sync(() => ts.forEachChild(node, appendNodeToVisit))),
@@ -3186,7 +3564,7 @@ var missingEffectContext = createDiagnostic({
3186
3564
  typeParser.effectType(expectedType, node),
3187
3565
  typeParser.effectType(realType, valueNode)
3188
3566
  ),
3189
- flatMap2(
3567
+ flatMap(
3190
3568
  ([expectedEffect, realEffect]) => getMissingTypeEntriesInTargetType(
3191
3569
  realEffect.R,
3192
3570
  expectedEffect.R
@@ -3204,10 +3582,10 @@ var missingEffectContext = createDiagnostic({
3204
3582
  valueNode,
3205
3583
  realType
3206
3584
  ),
3207
- map4(
3585
+ map3(
3208
3586
  (missingTypes) => missingTypes.length > 0 ? report(
3209
3587
  {
3210
- node,
3588
+ location: node,
3211
3589
  messageText: `Missing '${sortTypes(missingTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect context.`,
3212
3590
  fixes: []
3213
3591
  }
@@ -3227,18 +3605,15 @@ var missingEffectError = createDiagnostic({
3227
3605
  severity: "error",
3228
3606
  apply: fn("missingEffectError.apply")(function* (sourceFile, report) {
3229
3607
  const ts = yield* service(TypeScriptApi);
3608
+ const tsUtils = yield* service(TypeScriptUtils);
3230
3609
  const typeChecker = yield* service(TypeCheckerApi);
3231
3610
  const typeParser = yield* service(TypeParser);
3232
3611
  const typeOrder = yield* deterministicTypeOrder;
3233
- const effectModuleIdentifier = yield* pipe(
3234
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
3235
- sourceFile,
3236
- "effect",
3237
- "Effect"
3238
- ),
3239
- map4((_) => _.text),
3240
- orElse2(() => succeed("Effect"))
3241
- );
3612
+ const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
3613
+ sourceFile,
3614
+ "effect",
3615
+ "Effect"
3616
+ ) || "Effect";
3242
3617
  const createDieMessage = (message) => ts.factory.createCallExpression(
3243
3618
  ts.factory.createPropertyAccessExpression(
3244
3619
  ts.factory.createIdentifier(effectModuleIdentifier),
@@ -3252,13 +3627,13 @@ var missingEffectError = createDiagnostic({
3252
3627
  typeParser.effectType(expectedType, node),
3253
3628
  typeParser.effectType(realType, valueNode)
3254
3629
  ),
3255
- flatMap2(
3630
+ flatMap(
3256
3631
  ([expectedEffect, realEffect]) => pipe(
3257
3632
  getMissingTypeEntriesInTargetType(
3258
3633
  realEffect.E,
3259
3634
  expectedEffect.E
3260
3635
  ),
3261
- map4((missingErrorTypes) => ({ missingErrorTypes, expectedErrorType: expectedEffect.E }))
3636
+ map3((missingErrorTypes) => ({ missingErrorTypes, expectedErrorType: expectedEffect.E }))
3262
3637
  )
3263
3638
  )
3264
3639
  );
@@ -3273,7 +3648,7 @@ var missingEffectError = createDiagnostic({
3273
3648
  valueNode,
3274
3649
  realType
3275
3650
  ),
3276
- map4((result) => {
3651
+ map3((result) => {
3277
3652
  if (result.missingErrorTypes.length === 0) return;
3278
3653
  const fixes = [];
3279
3654
  if (ts.isExpression(valueNode) && result.expectedErrorType.flags & ts.TypeFlags.Never) {
@@ -3296,17 +3671,17 @@ var missingEffectError = createDiagnostic({
3296
3671
  if (ts.isExpression(valueNode)) {
3297
3672
  const propertyAssignments = pipe(
3298
3673
  result.missingErrorTypes,
3299
- map3((_) => typeChecker.getPropertyOfType(_, "_tag")),
3674
+ map4((_) => typeChecker.getPropertyOfType(_, "_tag")),
3300
3675
  filter((_) => !!_),
3301
- map3((_) => typeChecker.getTypeOfSymbolAtLocation(_, valueNode)),
3676
+ map4((_) => typeChecker.getTypeOfSymbolAtLocation(_, valueNode)),
3302
3677
  filter((_) => !!(_.flags & ts.TypeFlags.Literal)),
3303
- map3((_) => typeChecker.typeToTypeNode(_, void 0, ts.NodeBuilderFlags.NoTruncation)),
3678
+ map4((_) => typeChecker.typeToTypeNode(_, void 0, ts.NodeBuilderFlags.NoTruncation)),
3304
3679
  filter((_) => !!_ && ts.isLiteralTypeNode(_)),
3305
- map3((_) => _.literal),
3680
+ map4((_) => _.literal),
3306
3681
  filter((_) => ts.isLiteralExpression(_)),
3307
- map3((_) => _.text),
3682
+ map4((_) => _.text),
3308
3683
  sort(string2),
3309
- map3(
3684
+ map4(
3310
3685
  (_) => ts.factory.createPropertyAssignment(
3311
3686
  ts.factory.createIdentifier(_),
3312
3687
  ts.factory.createArrowFunction(
@@ -3340,7 +3715,7 @@ var missingEffectError = createDiagnostic({
3340
3715
  }
3341
3716
  report(
3342
3717
  {
3343
- node,
3718
+ location: node,
3344
3719
  messageText: `Missing '${sortTypes(result.missingErrorTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect errors.`,
3345
3720
  fixes
3346
3721
  }
@@ -3404,7 +3779,7 @@ var missingReturnYieldStar = createDiagnostic({
3404
3779
  })
3405
3780
  }] : [];
3406
3781
  report({
3407
- node,
3782
+ location: node,
3408
3783
  messageText: `Yielded Effect never succeeds, so it is best to use a 'return yield*' instead.`,
3409
3784
  fixes: fix
3410
3785
  });
@@ -3447,7 +3822,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
3447
3822
  typeParser.effectGen(effectGenNode),
3448
3823
  orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
3449
3824
  orElse2(() => typeParser.effectFnGen(effectGenNode)),
3450
- map4(({ functionStar }) => {
3825
+ map3(({ functionStar }) => {
3451
3826
  if (functionStar) {
3452
3827
  brokenGenerators.add(functionStar);
3453
3828
  }
@@ -3460,7 +3835,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
3460
3835
  }
3461
3836
  brokenGenerators.forEach(
3462
3837
  (node) => report({
3463
- node,
3838
+ location: node,
3464
3839
  messageText: `Seems like you used yield instead of yield* inside this Effect.gen.`,
3465
3840
  fixes: []
3466
3841
  })
@@ -3482,7 +3857,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
3482
3857
  })
3483
3858
  }] : [];
3484
3859
  report({
3485
- node,
3860
+ location: node,
3486
3861
  messageText: `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`,
3487
3862
  fixes: fix
3488
3863
  });
@@ -3497,34 +3872,27 @@ var multipleEffectProvide = createDiagnostic({
3497
3872
  severity: "warning",
3498
3873
  apply: fn("multipleEffectProvide.apply")(function* (sourceFile, report) {
3499
3874
  const ts = yield* service(TypeScriptApi);
3875
+ const tsUtils = yield* service(TypeScriptUtils);
3500
3876
  const typeChecker = yield* service(TypeCheckerApi);
3501
3877
  const typeParser = yield* service(TypeParser);
3502
- const effectModuleIdentifier = yield* pipe(
3503
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
3504
- sourceFile,
3505
- "effect",
3506
- "Effect"
3507
- ),
3508
- map4((_) => _.text),
3509
- orElse2(() => succeed("Effect"))
3510
- );
3511
- const layerModuleIdentifier = yield* pipe(
3512
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
3513
- sourceFile,
3514
- "effect",
3515
- "Layer"
3516
- ),
3517
- map4((_) => _.text),
3518
- orElse2(() => succeed("Layer"))
3519
- );
3878
+ const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
3879
+ sourceFile,
3880
+ "effect",
3881
+ "Effect"
3882
+ ) || "Effect";
3883
+ const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
3884
+ sourceFile,
3885
+ "effect",
3886
+ "Layer"
3887
+ ) || "Layer";
3520
3888
  const parseEffectProvideLayer = (node) => {
3521
3889
  if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && node.expression.name.text === "provide" && node.arguments.length > 0) {
3522
3890
  const layer = node.arguments[0];
3523
3891
  const type = typeChecker.getTypeAtLocation(layer);
3524
3892
  return pipe(
3525
3893
  typeParser.importedEffectModule(node.expression.expression),
3526
- flatMap2(() => typeParser.layerType(type, layer)),
3527
- map4(() => ({ layer, node })),
3894
+ flatMap(() => typeParser.layerType(type, layer)),
3895
+ map3(() => ({ layer, node })),
3528
3896
  orElse2(() => void_)
3529
3897
  );
3530
3898
  }
@@ -3546,7 +3914,7 @@ var multipleEffectProvide = createDiagnostic({
3546
3914
  for (const chunk of previousLayers) {
3547
3915
  if (chunk.length < 2) continue;
3548
3916
  report({
3549
- node: chunk[0].node,
3917
+ location: chunk[0].node,
3550
3918
  messageText: "Avoid chaining Effect.provide calls, as this can lead to service lifecycle issues. Instead, merge layers and provide them in a single call.",
3551
3919
  fixes: [{
3552
3920
  fixName: "multipleEffectProvide_fix",
@@ -3594,6 +3962,51 @@ var multipleEffectProvide = createDiagnostic({
3594
3962
  })
3595
3963
  });
3596
3964
 
3965
+ // src/diagnostics/outdatedEffectCodegen.ts
3966
+ var outdatedEffectCodegen = createDiagnostic({
3967
+ name: "outdatedEffectCodegen",
3968
+ code: 19,
3969
+ severity: "warning",
3970
+ apply: fn("outdatedEffectCodegen.apply")(function* (sourceFile, _report) {
3971
+ const codegensWithRanges = yield* getCodegensForSourceFile(codegens, sourceFile);
3972
+ for (const { codegen, hash: hash2, range } of codegensWithRanges) {
3973
+ yield* pipe(
3974
+ getEditsForCodegen([codegen], sourceFile, range),
3975
+ map3((applicable) => {
3976
+ if (applicable.hash !== hash2) {
3977
+ _report({
3978
+ location: range,
3979
+ messageText: `Codegen ${codegen.name} result is outdated`,
3980
+ fixes: [
3981
+ {
3982
+ fixName: "outdatedEffectCodegen_fix",
3983
+ description: `Re-run ${codegen.name}`,
3984
+ apply: applicable.apply
3985
+ },
3986
+ {
3987
+ fixName: "outdatedEffectCodegen_ignore",
3988
+ description: `Ignore this ${codegen.name} update`,
3989
+ apply: applicable.ignore
3990
+ }
3991
+ ]
3992
+ });
3993
+ }
3994
+ }),
3995
+ orElse2(
3996
+ (e) => sync(() => {
3997
+ _report({
3998
+ location: range,
3999
+ messageText: `Codegen ${codegen.name} is not applicable here: ${e.cause}`,
4000
+ fixes: []
4001
+ });
4002
+ })
4003
+ ),
4004
+ ignore
4005
+ );
4006
+ }
4007
+ })
4008
+ });
4009
+
3597
4010
  // src/diagnostics/returnEffectInGen.ts
3598
4011
  var returnEffectInGen = createDiagnostic({
3599
4012
  name: "returnEffectInGen",
@@ -3628,7 +4041,7 @@ var returnEffectInGen = createDiagnostic({
3628
4041
  typeParser.effectGen(effectGenNode),
3629
4042
  orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
3630
4043
  orElse2(() => typeParser.effectFnGen(effectGenNode)),
3631
- map4(() => {
4044
+ map3(() => {
3632
4045
  const fix = node.expression ? [{
3633
4046
  fixName: "returnEffectInGen_fix",
3634
4047
  description: "Add yield* statement",
@@ -3645,7 +4058,7 @@ var returnEffectInGen = createDiagnostic({
3645
4058
  })
3646
4059
  }] : [];
3647
4060
  report({
3648
- node,
4061
+ location: node,
3649
4062
  messageText: `You are returning an Effect-able type inside a generator function, and will result in nested Effect<Effect<...>>.
3650
4063
  Maybe you wanted to return yield* instead?
3651
4064
  Nested Effect-able types may be intended if you plan to later manually flatten or unwrap this Effect, if so you can safely disable this diagnostic for this line through quickfixes.`,
@@ -3668,17 +4081,14 @@ var scopeInLayerEffect = createDiagnostic({
3668
4081
  severity: "warning",
3669
4082
  apply: fn("scopeInLayerEffect.apply")(function* (sourceFile, report) {
3670
4083
  const ts = yield* service(TypeScriptApi);
4084
+ const tsUtils = yield* service(TypeScriptUtils);
3671
4085
  const typeChecker = yield* service(TypeCheckerApi);
3672
4086
  const typeParser = yield* service(TypeParser);
3673
- const layerModuleIdentifier = yield* pipe(
3674
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
3675
- sourceFile,
3676
- "effect",
3677
- "Layer"
3678
- ),
3679
- map4((_) => _.text),
3680
- orElse2(() => succeed("Layer"))
3681
- );
4087
+ const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
4088
+ sourceFile,
4089
+ "effect",
4090
+ "Layer"
4091
+ ) || "Layer";
3682
4092
  function parseLayerEffectApiCall(node) {
3683
4093
  if (!ts.isCallExpression(node)) return;
3684
4094
  const expression = node.expression;
@@ -3702,9 +4112,9 @@ var scopeInLayerEffect = createDiagnostic({
3702
4112
  }
3703
4113
  return pipe(
3704
4114
  firstSuccessOf(entries.map((type2) => typeParser.scopeType(type2, node))),
3705
- map4(
4115
+ map3(
3706
4116
  () => report({
3707
- node,
4117
+ location: node,
3708
4118
  messageText: `Seems like you are constructing a layer with a scope in the requirements.
3709
4119
  Consider using "scoped" instead to get rid of the scope in the requirements.`,
3710
4120
  fixes: methodIdentifier ? [{
@@ -3737,7 +4147,7 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
3737
4147
  const type = typeChecker.getTypeAtLocation(node);
3738
4148
  yield* pipe(
3739
4149
  typeParser.layerType(type, node),
3740
- flatMap2(({ RIn }) => reportIfLayerRequireScope(RIn, node, layerEffectApiCall.methodIdentifier)),
4150
+ flatMap(({ RIn }) => reportIfLayerRequireScope(RIn, node, layerEffectApiCall.methodIdentifier)),
3741
4151
  ignore
3742
4152
  );
3743
4153
  continue;
@@ -3751,7 +4161,7 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
3751
4161
  const type = typeChecker.getTypeOfSymbolAtLocation(defaultLayer, node);
3752
4162
  yield* pipe(
3753
4163
  typeParser.layerType(type, node),
3754
- flatMap2(({ RIn }) => reportIfLayerRequireScope(RIn, node, void 0)),
4164
+ flatMap(({ RIn }) => reportIfLayerRequireScope(RIn, node, void 0)),
3755
4165
  ignore
3756
4166
  );
3757
4167
  continue;
@@ -3820,7 +4230,7 @@ var strictBooleanExpressions = createDiagnostic({
3820
4230
  if (type.flags & ts.TypeFlags.BooleanLiteral) continue;
3821
4231
  const typeName = typeChecker.typeToString(type);
3822
4232
  report({
3823
- node: nodeToCheck,
4233
+ location: nodeToCheck,
3824
4234
  messageText: `Unexpected \`${typeName}\` type in condition, expected strictly a boolean instead.`,
3825
4235
  fixes: []
3826
4236
  });
@@ -3860,9 +4270,9 @@ var tryCatchInEffectGen = createDiagnostic({
3860
4270
  typeParser.effectGen(effectGenNode),
3861
4271
  orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
3862
4272
  orElse2(() => typeParser.effectFnGen(effectGenNode)),
3863
- map4(() => {
4273
+ map3(() => {
3864
4274
  report({
3865
- node,
4275
+ location: node,
3866
4276
  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).",
3867
4277
  fixes: []
3868
4278
  });
@@ -3895,9 +4305,9 @@ var unnecessaryEffectGen = createDiagnostic({
3895
4305
  if (ts.isCallExpression(node)) {
3896
4306
  yield* pipe(
3897
4307
  typeParser.unnecessaryEffectGen(node),
3898
- map4(
4308
+ map3(
3899
4309
  ({ replacementNode }) => report({
3900
- node,
4310
+ location: node,
3901
4311
  messageText: `This Effect.gen contains a single return statement.`,
3902
4312
  fixes: [{
3903
4313
  fixName: "unnecessaryEffectGen_fix",
@@ -3938,10 +4348,10 @@ var unnecessaryPipe = createDiagnostic({
3938
4348
  if (ts.isCallExpression(node)) {
3939
4349
  yield* pipe(
3940
4350
  typeParser.pipeCall(node),
3941
- map4(({ args: args2, subject }) => {
4351
+ map3(({ args: args2, subject }) => {
3942
4352
  if (args2.length === 0) {
3943
4353
  report({
3944
- node,
4354
+ location: node,
3945
4355
  messageText: `This pipe call contains no arguments.`,
3946
4356
  fixes: [{
3947
4357
  fixName: "unnecessaryPipe_fix",
@@ -3983,12 +4393,12 @@ var unnecessaryPipeChain = createDiagnostic({
3983
4393
  if (ts.isCallExpression(node)) {
3984
4394
  yield* pipe(
3985
4395
  typeParser.pipeCall(node),
3986
- flatMap2(
3987
- (pipeCall) => map4(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))
4396
+ flatMap(
4397
+ (pipeCall) => map3(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))
3988
4398
  ),
3989
- map4(({ innerCall, pipeCall }) => {
4399
+ map3(({ innerCall, pipeCall }) => {
3990
4400
  report({
3991
- node,
4401
+ location: node,
3992
4402
  messageText: `Chained pipe calls can be simplified to a single pipe call`,
3993
4403
  fixes: [{
3994
4404
  fixName: "unnecessaryPipeChain_fix",
@@ -4056,7 +4466,8 @@ var diagnostics = [
4056
4466
  effectInVoidSuccess,
4057
4467
  unnecessaryPipeChain,
4058
4468
  strictBooleanExpressions,
4059
- multipleEffectProvide
4469
+ multipleEffectProvide,
4470
+ outdatedEffectCodegen
4060
4471
  ];
4061
4472
 
4062
4473
  // src/completions/effectDiagnosticsComment.ts
@@ -4065,9 +4476,9 @@ var effectDiagnosticsComment = createCompletion({
4065
4476
  apply: fn("effectDiagnosticsComment")(function* (sourceFile, position) {
4066
4477
  const ts = yield* service(TypeScriptApi);
4067
4478
  const sourceText = sourceFile.text;
4068
- const match3 = /(\/\/|\/\*(?:\*?))\s*(@)\s*$/id.exec(sourceText.substring(0, position));
4069
- if (match3 && match3.indices) {
4070
- const lastIndex = match3.indices[2][0];
4479
+ const match2 = /(\/\/|\/\*(?:\*?))\s*(@)\s*$/id.exec(sourceText.substring(0, position));
4480
+ if (match2 && match2.indices) {
4481
+ const lastIndex = match2.indices[2][0];
4071
4482
  const replacementSpan = {
4072
4483
  start: lastIndex,
4073
4484
  length: Math.max(0, position - lastIndex)
@@ -4097,22 +4508,15 @@ var effectSchemaSelfInClasses = createCompletion({
4097
4508
  name: "effectSchemaSelfInClasses",
4098
4509
  apply: fn("effectSchemaSelfInClasses")(function* (sourceFile, position) {
4099
4510
  const ts = yield* service(TypeScriptApi);
4100
- const maybeInfos = yield* option(
4101
- parseDataForExtendsClassCompletion(sourceFile, position)
4102
- );
4103
- if (isNone2(maybeInfos)) return [];
4104
- const { accessedObject, className, replacementSpan } = maybeInfos.value;
4105
- const effectSchemaName = yield* option(
4106
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
4107
- sourceFile,
4108
- "effect",
4109
- "Schema"
4110
- )
4111
- );
4112
- const schemaIdentifier = match(effectSchemaName, {
4113
- onNone: () => "Schema",
4114
- onSome: (_) => _.text
4115
- });
4511
+ const tsUtils = yield* service(TypeScriptUtils);
4512
+ const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
4513
+ if (!maybeInfos) return [];
4514
+ const { accessedObject, className, replacementSpan } = maybeInfos;
4515
+ const schemaIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
4516
+ sourceFile,
4517
+ "effect",
4518
+ "Schema"
4519
+ ) || "Schema";
4116
4520
  if (schemaIdentifier !== accessedObject.text) return [];
4117
4521
  const name = className.text;
4118
4522
  return [{
@@ -4148,22 +4552,15 @@ var effectSelfInClasses = createCompletion({
4148
4552
  name: "effectSelfInClasses",
4149
4553
  apply: fn("effectSelfInClasses")(function* (sourceFile, position) {
4150
4554
  const ts = yield* service(TypeScriptApi);
4151
- const maybeInfos = yield* option(
4152
- parseDataForExtendsClassCompletion(sourceFile, position)
4153
- );
4154
- if (isNone2(maybeInfos)) return [];
4155
- const { accessedObject, className, replacementSpan } = maybeInfos.value;
4156
- const effectName = yield* option(
4157
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
4158
- sourceFile,
4159
- "effect",
4160
- "Effect"
4161
- )
4162
- );
4163
- const effectIdentifier = match(effectName, {
4164
- onNone: () => "Effect",
4165
- onSome: (_) => _.text
4166
- });
4555
+ const tsUtils = yield* service(TypeScriptUtils);
4556
+ const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
4557
+ if (!maybeInfos) return [];
4558
+ const { accessedObject, className, replacementSpan } = maybeInfos;
4559
+ const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
4560
+ sourceFile,
4561
+ "effect",
4562
+ "Effect"
4563
+ ) || "Effect";
4167
4564
  if (effectIdentifier !== accessedObject.text) return [];
4168
4565
  const name = className.text;
4169
4566
  return [{
@@ -4181,12 +4578,11 @@ var fnFunctionStar = createCompletion({
4181
4578
  name: "fnFunctionStar",
4182
4579
  apply: fn("fnFunctionStar")(function* (sourceFile, position) {
4183
4580
  const ts = yield* service(TypeScriptApi);
4581
+ const tsUtils = yield* service(TypeScriptUtils);
4184
4582
  const typeParser = yield* service(TypeParser);
4185
- const maybeInfos = yield* option(
4186
- parseAccessedExpressionForCompletion(sourceFile, position)
4187
- );
4188
- if (isNone2(maybeInfos)) return [];
4189
- const { accessedObject } = maybeInfos.value;
4583
+ const maybeInfos = tsUtils.parseAccessedExpressionForCompletion(sourceFile, position);
4584
+ if (!maybeInfos) return [];
4585
+ const { accessedObject } = maybeInfos;
4190
4586
  const isEffectModule = yield* option(typeParser.importedEffectModule(accessedObject));
4191
4587
  if (isNone2(isEffectModule)) return [];
4192
4588
  const span = ts.createTextSpan(
@@ -4194,9 +4590,9 @@ var fnFunctionStar = createCompletion({
4194
4590
  Math.max(0, position - accessedObject.end - 1)
4195
4591
  );
4196
4592
  const maybeFnName = pipe(
4197
- yield* getAncestorNodesInRange(sourceFile, toTextRange(accessedObject.pos)),
4593
+ tsUtils.getAncestorNodesInRange(sourceFile, tsUtils.toTextRange(accessedObject.pos)),
4198
4594
  filter(ts.isVariableDeclaration),
4199
- map3((_) => _.name && ts.isIdentifier(_.name) ? _.name.text : ""),
4595
+ map4((_) => _.name && ts.isIdentifier(_.name) ? _.name.text : ""),
4200
4596
  filter((_) => _.length > 0),
4201
4597
  head,
4202
4598
  map2((name) => [
@@ -4231,12 +4627,11 @@ var genFunctionStar = createCompletion({
4231
4627
  name: "genFunctionStar",
4232
4628
  apply: fn("genFunctionStar")(function* (sourceFile, position) {
4233
4629
  const ts = yield* service(TypeScriptApi);
4630
+ const tsUtils = yield* service(TypeScriptUtils);
4234
4631
  const typeChecker = yield* service(TypeCheckerApi);
4235
- const maybeInfos = yield* option(
4236
- parseAccessedExpressionForCompletion(sourceFile, position)
4237
- );
4238
- if (isNone2(maybeInfos)) return [];
4239
- const { accessedObject } = maybeInfos.value;
4632
+ const maybeInfos = tsUtils.parseAccessedExpressionForCompletion(sourceFile, position);
4633
+ if (!maybeInfos) return [];
4634
+ const { accessedObject } = maybeInfos;
4240
4635
  const type = typeChecker.getTypeAtLocation(accessedObject);
4241
4636
  const genMemberSymbol = type.getProperty("gen");
4242
4637
  if (!genMemberSymbol) return [];
@@ -4261,22 +4656,15 @@ var rpcMakeClasses = createCompletion({
4261
4656
  name: "rpcMakeClasses",
4262
4657
  apply: fn("rpcMakeClasses")(function* (sourceFile, position) {
4263
4658
  const ts = yield* service(TypeScriptApi);
4264
- const maybeInfos = yield* option(
4265
- parseDataForExtendsClassCompletion(sourceFile, position)
4266
- );
4267
- if (isNone2(maybeInfos)) return [];
4268
- const { accessedObject, className, replacementSpan } = maybeInfos.value;
4269
- const rpcName = yield* option(
4270
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
4271
- sourceFile,
4272
- "@effect/rpc",
4273
- "Rpc"
4274
- )
4275
- );
4276
- const rpcIdentifier = match(rpcName, {
4277
- onNone: () => "Rpc",
4278
- onSome: (_) => _.text
4279
- });
4659
+ const tsUtils = yield* service(TypeScriptUtils);
4660
+ const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
4661
+ if (!maybeInfos) return [];
4662
+ const { accessedObject, className, replacementSpan } = maybeInfos;
4663
+ const rpcIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
4664
+ sourceFile,
4665
+ "@effect/rpc",
4666
+ "Rpc"
4667
+ ) || "Rpc";
4280
4668
  if (rpcIdentifier !== accessedObject.text) return [];
4281
4669
  const name = className.text;
4282
4670
  return [{
@@ -4294,34 +4682,25 @@ var schemaBrand = createCompletion({
4294
4682
  name: "schemaBrand",
4295
4683
  apply: fn("schemaBrand")(function* (sourceFile, position) {
4296
4684
  const ts = yield* service(TypeScriptApi);
4297
- const maybeInfos = yield* option(
4298
- parseAccessedExpressionForCompletion(sourceFile, position)
4299
- );
4300
- if (isNone2(maybeInfos)) return [];
4301
- const { accessedObject } = maybeInfos.value;
4685
+ const tsUtils = yield* service(TypeScriptUtils);
4686
+ const maybeInfos = tsUtils.parseAccessedExpressionForCompletion(sourceFile, position);
4687
+ if (!maybeInfos) return [];
4688
+ const { accessedObject } = maybeInfos;
4302
4689
  if (!ts.isIdentifier(accessedObject)) return [];
4303
- const schemaName = match(
4304
- yield* option(
4305
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
4306
- sourceFile,
4307
- "effect",
4308
- "Schema"
4309
- )
4310
- ),
4311
- {
4312
- onNone: () => "Schema",
4313
- onSome: (_) => _.text
4314
- }
4315
- );
4690
+ const schemaName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
4691
+ sourceFile,
4692
+ "effect",
4693
+ "Schema"
4694
+ ) || "Schema";
4316
4695
  if (schemaName !== accessedObject.text) return [];
4317
4696
  const span = ts.createTextSpan(
4318
4697
  accessedObject.end + 1,
4319
4698
  Math.max(0, position - accessedObject.end - 1)
4320
4699
  );
4321
4700
  return pipe(
4322
- yield* getAncestorNodesInRange(sourceFile, toTextRange(accessedObject.pos)),
4701
+ tsUtils.getAncestorNodesInRange(sourceFile, tsUtils.toTextRange(accessedObject.pos)),
4323
4702
  filter(ts.isVariableDeclaration),
4324
- map3((_) => _.name && ts.isIdentifier(_.name) ? _.name.text : ""),
4703
+ map4((_) => _.name && ts.isIdentifier(_.name) ? _.name.text : ""),
4325
4704
  filter((_) => _.length > 0),
4326
4705
  head,
4327
4706
  map2((name) => [
@@ -4348,6 +4727,7 @@ var completions = [
4348
4727
  fnFunctionStar,
4349
4728
  effectDataClasses,
4350
4729
  effectDiagnosticsComment,
4730
+ effectCodegensComment,
4351
4731
  durationInput,
4352
4732
  schemaBrand
4353
4733
  ];
@@ -4355,10 +4735,11 @@ var completions = [
4355
4735
  // src/core/AutoImport.ts
4356
4736
  var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
4357
4737
  const ts = yield* service(TypeScriptApi);
4738
+ const tsUtils = yield* service(TypeScriptUtils);
4358
4739
  const program = yield* service(TypeScriptProgram);
4359
4740
  const languageServicePluginOptions = yield* service(LanguageServicePluginOptions);
4360
4741
  const host = program;
4361
- const getModuleSpecifier = makeGetModuleSpecifier(ts);
4742
+ const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
4362
4743
  function collectSourceFileReexports(sourceFile) {
4363
4744
  const namespaceExports = [];
4364
4745
  const namedExports = [];
@@ -4412,7 +4793,7 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
4412
4793
  if (!isArray(_entrypoints)) return;
4413
4794
  if (!every(isString)) return;
4414
4795
  const entrypoints = _entrypoints.map((_) => String(_));
4415
- const info = parsePackageContentNameAndVersionFromScope({ packageJsonScope: packageJsonInfo });
4796
+ const info = tsUtils.parsePackageContentNameAndVersionFromScope({ packageJsonScope: packageJsonInfo });
4416
4797
  if (!info) return { entrypoints, exportedKeys: [] };
4417
4798
  return { entrypoints, exportedKeys: info.exportsKeys };
4418
4799
  } catch (_) {
@@ -4442,7 +4823,7 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
4442
4823
  const collectImportCache = fn("TypeScriptApi")(
4443
4824
  function* (packagePatterns, kind) {
4444
4825
  for (const packagePattern of packagePatterns) {
4445
- const packageNames = yield* resolveModulePattern(fromSourceFile, packagePattern);
4826
+ const packageNames = tsUtils.resolveModulePattern(fromSourceFile, packagePattern);
4446
4827
  for (const packageName of packageNames) {
4447
4828
  const packageInfo = getPackageInfo(fromSourceFile.fileName, packageName);
4448
4829
  if (!packageInfo) continue;
@@ -4574,6 +4955,7 @@ var getOrMakeAutoImportProvider = fn("getOrMakeAutoImportProvider")(function* (s
4574
4955
  });
4575
4956
  var parseImportOnlyChanges = fn("parseImportOnlyChanges")(function* (sourceFile, changes) {
4576
4957
  const ts = yield* service(TypeScriptApi);
4958
+ const tsUtils = yield* service(TypeScriptUtils);
4577
4959
  const deletions = [];
4578
4960
  const imports = [];
4579
4961
  for (const change of changes) {
@@ -4609,7 +4991,7 @@ var parseImportOnlyChanges = fn("parseImportOnlyChanges")(function* (sourceFile,
4609
4991
  return;
4610
4992
  }
4611
4993
  } else {
4612
- const ancestorNodes = yield* getAncestorNodesInRange(sourceFile, {
4994
+ const ancestorNodes = tsUtils.getAncestorNodesInRange(sourceFile, {
4613
4995
  pos: change.span.start,
4614
4996
  end: change.span.start
4615
4997
  });
@@ -4903,12 +5285,13 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
4903
5285
  return gen(function* () {
4904
5286
  const program = yield* service(TypeScriptProgram);
4905
5287
  const ts = yield* service(TypeScriptApi);
5288
+ const tsUtils = yield* service(TypeScriptUtils);
4906
5289
  const typeChecker = yield* service(TypeCheckerApi);
4907
- const textRange = toTextRange(position);
5290
+ const textRange = tsUtils.toTextRange(position);
4908
5291
  function isSymbolFromEffectRpcModule(symbol3) {
4909
5292
  if (symbol3.valueDeclaration) {
4910
5293
  const sourceFile2 = symbol3.valueDeclaration.getSourceFile();
4911
- const packageInfo = parsePackageContentNameAndVersionFromScope(sourceFile2);
5294
+ const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(sourceFile2);
4912
5295
  if (packageInfo && packageInfo.name === "@effect/rpc") {
4913
5296
  const fileSymbol = typeChecker.getSymbolAtLocation(sourceFile2);
4914
5297
  return fileSymbol && fileSymbol.exports && fileSymbol.exports.has("isRpc") && fileSymbol.exports.has("make") && fileSymbol.exports.has("fromTaggedRequest");
@@ -4919,7 +5302,7 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
4919
5302
  function isSymbolFromEffectRpcClientModule(symbol3) {
4920
5303
  if (symbol3.valueDeclaration) {
4921
5304
  const sourceFile2 = symbol3.valueDeclaration.getSourceFile();
4922
- const packageInfo = parsePackageContentNameAndVersionFromScope(sourceFile2);
5305
+ const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(sourceFile2);
4923
5306
  if (packageInfo && packageInfo.name === "@effect/rpc") {
4924
5307
  const fileSymbol = typeChecker.getSymbolAtLocation(sourceFile2);
4925
5308
  return fileSymbol && fileSymbol.exports && fileSymbol.exports.has("RpcClient") && fileSymbol.exports.has("make");
@@ -4929,8 +5312,8 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
4929
5312
  }
4930
5313
  let rpcName = null;
4931
5314
  let callNode = null;
4932
- for (const node of yield* getAncestorNodesInRange(sourceFile, textRange)) {
4933
- if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && isNodeInRange(textRange)(node.name)) {
5315
+ for (const node of tsUtils.getAncestorNodesInRange(sourceFile, textRange)) {
5316
+ if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && tsUtils.isNodeInRange(textRange)(node.name)) {
4934
5317
  const type = typeChecker.getTypeAtLocation(node);
4935
5318
  for (const callSig of type.getCallSignatures()) {
4936
5319
  if (callSig.parameters.length >= 2 && isSymbolFromEffectRpcClientModule(callSig.parameters[1])) {
@@ -5082,7 +5465,7 @@ function effectTypeArgs(sourceFile, position, quickInfo2) {
5082
5465
  type,
5083
5466
  atLocation
5084
5467
  ),
5085
- map4((_) => makeSymbolDisplayParts("Effect Type Parameters", _.A, _.E, _.R)),
5468
+ map3((_) => makeSymbolDisplayParts("Effect Type Parameters", _.A, _.E, _.R)),
5086
5469
  orElse2(() => {
5087
5470
  const callSignatues = type.getCallSignatures();
5088
5471
  if (callSignatues.length !== 1) return succeed([]);
@@ -5092,7 +5475,7 @@ function effectTypeArgs(sourceFile, position, quickInfo2) {
5092
5475
  returnType,
5093
5476
  atLocation
5094
5477
  ),
5095
- map4((_) => makeSymbolDisplayParts("Returned Effect Type Parameters", _.A, _.E, _.R))
5478
+ map3((_) => makeSymbolDisplayParts("Returned Effect Type Parameters", _.A, _.E, _.R))
5096
5479
  );
5097
5480
  })
5098
5481
  );
@@ -6025,7 +6408,7 @@ var read_buf = (strm, buf, start, size) => {
6025
6408
  var longest_match = (s, cur_match) => {
6026
6409
  let chain_length = s.max_chain_length;
6027
6410
  let scan = s.strstart;
6028
- let match3;
6411
+ let match2;
6029
6412
  let len;
6030
6413
  let best_len = s.prev_length;
6031
6414
  let nice_match = s.nice_match;
@@ -6043,14 +6426,14 @@ var longest_match = (s, cur_match) => {
6043
6426
  nice_match = s.lookahead;
6044
6427
  }
6045
6428
  do {
6046
- match3 = cur_match;
6047
- if (_win[match3 + best_len] !== scan_end || _win[match3 + best_len - 1] !== scan_end1 || _win[match3] !== _win[scan] || _win[++match3] !== _win[scan + 1]) {
6429
+ match2 = cur_match;
6430
+ if (_win[match2 + best_len] !== scan_end || _win[match2 + best_len - 1] !== scan_end1 || _win[match2] !== _win[scan] || _win[++match2] !== _win[scan + 1]) {
6048
6431
  continue;
6049
6432
  }
6050
6433
  scan += 2;
6051
- match3++;
6434
+ match2++;
6052
6435
  do {
6053
- } while (_win[++scan] === _win[++match3] && _win[++scan] === _win[++match3] && _win[++scan] === _win[++match3] && _win[++scan] === _win[++match3] && _win[++scan] === _win[++match3] && _win[++scan] === _win[++match3] && _win[++scan] === _win[++match3] && _win[++scan] === _win[++match3] && scan < strend);
6436
+ } while (_win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && scan < strend);
6054
6437
  len = MAX_MATCH - (strend - scan);
6055
6438
  scan = strend - MAX_MATCH;
6056
6439
  if (len > best_len) {
@@ -7751,7 +8134,7 @@ var inflate_table = (type, lens, lens_index, codes, table, table_index, work, op
7751
8134
  let mask;
7752
8135
  let next;
7753
8136
  let base = null;
7754
- let match3;
8137
+ let match2;
7755
8138
  const count = new Uint16Array(MAXBITS + 1);
7756
8139
  const offs = new Uint16Array(MAXBITS + 1);
7757
8140
  let extra = null;
@@ -7807,15 +8190,15 @@ var inflate_table = (type, lens, lens_index, codes, table, table_index, work, op
7807
8190
  }
7808
8191
  if (type === CODES$1) {
7809
8192
  base = extra = work;
7810
- match3 = 20;
8193
+ match2 = 20;
7811
8194
  } else if (type === LENS$1) {
7812
8195
  base = lbase;
7813
8196
  extra = lext;
7814
- match3 = 257;
8197
+ match2 = 257;
7815
8198
  } else {
7816
8199
  base = dbase;
7817
8200
  extra = dext;
7818
- match3 = 0;
8201
+ match2 = 0;
7819
8202
  }
7820
8203
  huff = 0;
7821
8204
  sym = 0;
@@ -7831,12 +8214,12 @@ var inflate_table = (type, lens, lens_index, codes, table, table_index, work, op
7831
8214
  }
7832
8215
  for (; ; ) {
7833
8216
  here_bits = len - drop;
7834
- if (work[sym] + 1 < match3) {
8217
+ if (work[sym] + 1 < match2) {
7835
8218
  here_op = 0;
7836
8219
  here_val = work[sym];
7837
- } else if (work[sym] >= match3) {
7838
- here_op = extra[work[sym] - match3];
7839
- here_val = base[work[sym] - match3];
8220
+ } else if (work[sym] >= match2) {
8221
+ here_op = extra[work[sym] - match2];
8222
+ here_val = base[work[sym] - match2];
7840
8223
  } else {
7841
8224
  here_op = 32 + 64;
7842
8225
  here_val = 0;
@@ -9599,13 +9982,14 @@ function layerInfo(sourceFile, position, quickInfo2) {
9599
9982
  return pipe(
9600
9983
  gen(function* () {
9601
9984
  const ts = yield* service(TypeScriptApi);
9985
+ const tsUtils = yield* service(TypeScriptUtils);
9602
9986
  const typeChecker = yield* service(TypeCheckerApi);
9603
9987
  const typeParser = yield* service(TypeParser);
9604
- const range = toTextRange(position);
9988
+ const range = tsUtils.toTextRange(position);
9605
9989
  const maybeNode = pipe(
9606
- yield* getAncestorNodesInRange(sourceFile, range),
9990
+ tsUtils.getAncestorNodesInRange(sourceFile, range),
9607
9991
  filter((_) => ts.isVariableDeclaration(_) || ts.isPropertyDeclaration(_)),
9608
- filter((_) => isNodeInRange(range)(_.name)),
9992
+ filter((_) => tsUtils.isNodeInRange(range)(_.name)),
9609
9993
  head
9610
9994
  );
9611
9995
  if (isNone2(maybeNode)) return quickInfo2;
@@ -9622,7 +10006,7 @@ function layerInfo(sourceFile, position, quickInfo2) {
9622
10006
  };
9623
10007
  const layerInfoDisplayParts = yield* pipe(
9624
10008
  processLayerGraphNode(graphCtx, layerNode, void 0),
9625
- flatMap2(
10009
+ flatMap(
9626
10010
  (rootNode) => gen(function* () {
9627
10011
  yield* succeed(void 0);
9628
10012
  const lines = [];
@@ -9715,10 +10099,10 @@ var asyncAwaitToGen = createRefactor({
9715
10099
  description: "Convert to Effect.gen",
9716
10100
  apply: fn("asyncAwaitToGen.apply")(function* (sourceFile, textRange) {
9717
10101
  const ts = yield* service(TypeScriptApi);
10102
+ const tsUtils = yield* service(TypeScriptUtils);
9718
10103
  const typeChecker = yield* service(TypeCheckerApi);
9719
- const typeParser = yield* service(TypeParser);
9720
10104
  const maybeNode = pipe(
9721
- yield* getAncestorNodesInRange(sourceFile, textRange),
10105
+ tsUtils.getAncestorNodesInRange(sourceFile, textRange),
9722
10106
  filter(
9723
10107
  (node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
9724
10108
  ),
@@ -9734,23 +10118,12 @@ var asyncAwaitToGen = createRefactor({
9734
10118
  apply: pipe(
9735
10119
  gen(function* () {
9736
10120
  const changeTracker = yield* service(ChangeTracker);
9737
- const effectModuleIdentifierName = match(
9738
- yield* option(
9739
- findImportedModuleIdentifier(
9740
- sourceFile,
9741
- (node2) => pipe(
9742
- typeParser.importedEffectModule(node2),
9743
- option,
9744
- map4(isSome2)
9745
- )
9746
- )
9747
- ),
9748
- {
9749
- onNone: () => "Effect",
9750
- onSome: (node2) => node2.text
9751
- }
9752
- );
9753
- const newDeclaration = yield* transformAsyncAwaitToEffectGen(
10121
+ const effectModuleIdentifierName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
10122
+ sourceFile,
10123
+ "effect",
10124
+ "Effect"
10125
+ ) || "Effect";
10126
+ const newDeclaration = tsUtils.transformAsyncAwaitToEffectGen(
9754
10127
  node,
9755
10128
  effectModuleIdentifierName,
9756
10129
  (expression) => ts.factory.createCallExpression(
@@ -9786,10 +10159,10 @@ var asyncAwaitToGenTryPromise = createRefactor({
9786
10159
  description: "Convert to Effect.gen with failures",
9787
10160
  apply: fn("asyncAwaitToGenTryPromise.apply")(function* (sourceFile, textRange) {
9788
10161
  const ts = yield* service(TypeScriptApi);
10162
+ const tsUtils = yield* service(TypeScriptUtils);
9789
10163
  const typeChecker = yield* service(TypeCheckerApi);
9790
- const typeParser = yield* service(TypeParser);
9791
10164
  const maybeNode = pipe(
9792
- yield* getAncestorNodesInRange(sourceFile, textRange),
10165
+ tsUtils.getAncestorNodesInRange(sourceFile, textRange),
9793
10166
  filter(
9794
10167
  (node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
9795
10168
  ),
@@ -9805,22 +10178,11 @@ var asyncAwaitToGenTryPromise = createRefactor({
9805
10178
  apply: pipe(
9806
10179
  gen(function* () {
9807
10180
  const changeTracker = yield* service(ChangeTracker);
9808
- const effectModuleIdentifierName = match(
9809
- yield* option(
9810
- findImportedModuleIdentifier(
9811
- sourceFile,
9812
- (node2) => pipe(
9813
- typeParser.importedEffectModule(node2),
9814
- option,
9815
- map4(isSome2)
9816
- )
9817
- )
9818
- ),
9819
- {
9820
- onNone: () => "Effect",
9821
- onSome: (node2) => node2.text
9822
- }
9823
- );
10181
+ const effectModuleIdentifierName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
10182
+ sourceFile,
10183
+ "effect",
10184
+ "Effect"
10185
+ ) || "Effect";
9824
10186
  let errorCount = 0;
9825
10187
  function createErrorADT() {
9826
10188
  errorCount++;
@@ -9835,7 +10197,7 @@ var asyncAwaitToGenTryPromise = createRefactor({
9835
10197
  ts.factory.createShorthandPropertyAssignment("error")
9836
10198
  ]);
9837
10199
  }
9838
- const newDeclaration = yield* transformAsyncAwaitToEffectGen(
10200
+ const newDeclaration = tsUtils.transformAsyncAwaitToEffectGen(
9839
10201
  node,
9840
10202
  effectModuleIdentifierName,
9841
10203
  (expression) => ts.factory.createCallExpression(
@@ -9887,6 +10249,7 @@ var effectGenToFn = createRefactor({
9887
10249
  description: "Convert to Effect.fn",
9888
10250
  apply: fn("effectGenToFn.apply")(function* (sourceFile, textRange) {
9889
10251
  const ts = yield* service(TypeScriptApi);
10252
+ const tsUtils = yield* service(TypeScriptUtils);
9890
10253
  const typeParser = yield* service(TypeParser);
9891
10254
  const parseEffectGenNode = fn("asyncAwaitToGen.apply")(function* (node) {
9892
10255
  const effectGen = yield* typeParser.effectGen(node);
@@ -9923,8 +10286,8 @@ var effectGenToFn = createRefactor({
9923
10286
  return yield* fail(new RefactorNotApplicableError());
9924
10287
  });
9925
10288
  const maybeNode = yield* pipe(
9926
- yield* getAncestorNodesInRange(sourceFile, textRange),
9927
- map3(parseEffectGenNode),
10289
+ tsUtils.getAncestorNodesInRange(sourceFile, textRange),
10290
+ map4(parseEffectGenNode),
9928
10291
  firstSuccessOf,
9929
10292
  option
9930
10293
  );
@@ -9963,7 +10326,7 @@ var effectGenToFn = createRefactor({
9963
10326
  changeTracker.replaceNode(
9964
10327
  sourceFile,
9965
10328
  nodeToReplace,
9966
- yield* tryPreserveDeclarationSemantics(nodeToReplace, effectFnCallWithGenerator)
10329
+ tsUtils.tryPreserveDeclarationSemantics(nodeToReplace, effectFnCallWithGenerator)
9967
10330
  );
9968
10331
  }),
9969
10332
  provideService(TypeScriptApi, ts)
@@ -9978,11 +10341,12 @@ var functionToArrow = createRefactor({
9978
10341
  description: "Convert to arrow",
9979
10342
  apply: fn("functionToArrow.apply")(function* (sourceFile, textRange) {
9980
10343
  const ts = yield* service(TypeScriptApi);
10344
+ const tsUtils = yield* service(TypeScriptUtils);
9981
10345
  const maybeNode = pipe(
9982
- yield* getAncestorNodesInRange(sourceFile, textRange),
10346
+ tsUtils.getAncestorNodesInRange(sourceFile, textRange),
9983
10347
  filter((_) => ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_)),
9984
10348
  filter((_) => !!_.body),
9985
- filter((_) => !!_.name && isNodeInRange(textRange)(_.name)),
10349
+ filter((_) => !!_.name && tsUtils.isNodeInRange(textRange)(_.name)),
9986
10350
  head
9987
10351
  );
9988
10352
  if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
@@ -10013,7 +10377,7 @@ var functionToArrow = createRefactor({
10013
10377
  ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
10014
10378
  newBody
10015
10379
  );
10016
- const newDeclaration = yield* tryPreserveDeclarationSemantics(
10380
+ const newDeclaration = tsUtils.tryPreserveDeclarationSemantics(
10017
10381
  node,
10018
10382
  arrowFunction
10019
10383
  );
@@ -10034,6 +10398,7 @@ var _findSchemaVariableDeclaration = fn(
10034
10398
  )(
10035
10399
  function* (sourceFile, textRange) {
10036
10400
  const ts = yield* service(TypeScriptApi);
10401
+ const tsUtils = yield* service(TypeScriptUtils);
10037
10402
  const typeChecker = yield* service(TypeCheckerApi);
10038
10403
  const typeParser = yield* service(TypeParser);
10039
10404
  const findSchema = fn("makeSchemaOpaque.apply.findSchema")(
@@ -10059,8 +10424,8 @@ var _findSchemaVariableDeclaration = fn(
10059
10424
  }
10060
10425
  );
10061
10426
  return yield* pipe(
10062
- yield* getAncestorNodesInRange(sourceFile, textRange),
10063
- map3(findSchema),
10427
+ tsUtils.getAncestorNodesInRange(sourceFile, textRange),
10428
+ map4(findSchema),
10064
10429
  firstSuccessOf,
10065
10430
  option
10066
10431
  );
@@ -10147,6 +10512,7 @@ var makeSchemaOpaque = createRefactor({
10147
10512
  description: "Make Schema opaque",
10148
10513
  apply: fn("makeSchemaOpaque.apply")(function* (sourceFile, textRange) {
10149
10514
  const ts = yield* service(TypeScriptApi);
10515
+ const tsUtils = yield* service(TypeScriptUtils);
10150
10516
  const maybeNode = yield* _findSchemaVariableDeclaration(sourceFile, textRange);
10151
10517
  if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
10152
10518
  const { identifier, types, variableDeclarationList, variableStatement } = maybeNode.value;
@@ -10156,19 +10522,11 @@ var makeSchemaOpaque = createRefactor({
10156
10522
  apply: pipe(
10157
10523
  gen(function* () {
10158
10524
  const changeTracker = yield* service(ChangeTracker);
10159
- const effectSchemaName = match(
10160
- yield* option(
10161
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
10162
- sourceFile,
10163
- "effect",
10164
- "Schema"
10165
- )
10166
- ),
10167
- {
10168
- onNone: () => "Schema",
10169
- onSome: (_) => _.text
10170
- }
10171
- );
10525
+ const effectSchemaName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
10526
+ sourceFile,
10527
+ "effect",
10528
+ "Schema"
10529
+ ) || "Schema";
10172
10530
  const newIdentifier = ts.factory.createIdentifier(identifier.text + "_");
10173
10531
  const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(
10174
10532
  effectSchemaName,
@@ -10225,6 +10583,7 @@ var makeSchemaOpaqueWithNs = createRefactor({
10225
10583
  description: "Make Schema opaque with namespace",
10226
10584
  apply: fn("makeSchemaOpaqueWithNs.apply")(function* (sourceFile, textRange) {
10227
10585
  const ts = yield* service(TypeScriptApi);
10586
+ const tsUtils = yield* service(TypeScriptUtils);
10228
10587
  const maybeNode = yield* _findSchemaVariableDeclaration(sourceFile, textRange);
10229
10588
  if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
10230
10589
  const { identifier, types, variableDeclarationList, variableStatement } = maybeNode.value;
@@ -10234,19 +10593,11 @@ var makeSchemaOpaqueWithNs = createRefactor({
10234
10593
  apply: pipe(
10235
10594
  gen(function* () {
10236
10595
  const changeTracker = yield* service(ChangeTracker);
10237
- const effectSchemaName = match(
10238
- yield* option(
10239
- findImportedModuleIdentifierByPackageAndNameOrBarrel(
10240
- sourceFile,
10241
- "effect",
10242
- "Schema"
10243
- )
10244
- ),
10245
- {
10246
- onNone: () => "Schema",
10247
- onSome: (_) => _.text
10248
- }
10249
- );
10596
+ const effectSchemaName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
10597
+ sourceFile,
10598
+ "effect",
10599
+ "Schema"
10600
+ ) || "Schema";
10250
10601
  const newIdentifier = ts.factory.createIdentifier(identifier.text + "_");
10251
10602
  const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(
10252
10603
  effectSchemaName,
@@ -10320,6 +10671,7 @@ var pipeableToDatafirst = createRefactor({
10320
10671
  apply: fn("pipeableToDatafirst.apply")(function* (sourceFile, textRange) {
10321
10672
  const ts = yield* service(TypeScriptApi);
10322
10673
  const typeChecker = yield* service(TypeCheckerApi);
10674
+ const tsUtils = yield* service(TypeScriptUtils);
10323
10675
  function isPipeCall(node2) {
10324
10676
  if (!ts.isCallExpression(node2)) return false;
10325
10677
  const expression = node2.expression;
@@ -10347,13 +10699,13 @@ var pipeableToDatafirst = createRefactor({
10347
10699
  return none2();
10348
10700
  }
10349
10701
  const maybeNode = pipe(
10350
- yield* getAncestorNodesInRange(sourceFile, textRange),
10702
+ tsUtils.getAncestorNodesInRange(sourceFile, textRange),
10351
10703
  filter(isPipeCall),
10352
- filter((node2) => isNodeInRange(textRange)(node2.expression)),
10704
+ filter((node2) => tsUtils.isNodeInRange(textRange)(node2.expression)),
10353
10705
  filter(
10354
10706
  (node2) => node2.arguments.length > 0
10355
10707
  ),
10356
- map3((node2) => {
10708
+ map4((node2) => {
10357
10709
  let newNode2 = node2.arguments[0];
10358
10710
  let didSomething = false;
10359
10711
  for (let i = 1; i < node2.arguments.length; i++) {
@@ -10380,7 +10732,7 @@ var pipeableToDatafirst = createRefactor({
10380
10732
  return didSomething ? some2([node2, newNode2]) : none2();
10381
10733
  }),
10382
10734
  filter(isSome2),
10383
- map3((_) => _.value),
10735
+ map4((_) => _.value),
10384
10736
  head
10385
10737
  );
10386
10738
  if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
@@ -10401,8 +10753,9 @@ var removeUnnecessaryEffectGen = createRefactor({
10401
10753
  name: "removeUnnecessaryEffectGen",
10402
10754
  description: "Remove unnecessary Effect.gen",
10403
10755
  apply: fn("removeUnnecessaryEffectGen.apply")(function* (sourceFile, textRange) {
10756
+ const tsUtils = yield* service(TypeScriptUtils);
10404
10757
  const typeParser = yield* service(TypeParser);
10405
- for (const nodeToReplace of yield* getAncestorNodesInRange(sourceFile, textRange)) {
10758
+ for (const nodeToReplace of tsUtils.getAncestorNodesInRange(sourceFile, textRange)) {
10406
10759
  const maybeNode = yield* option(typeParser.unnecessaryEffectGen(nodeToReplace));
10407
10760
  if (isNone2(maybeNode)) continue;
10408
10761
  const replacementNode = maybeNode.value.replacementNode;
@@ -10425,10 +10778,11 @@ var toggleLazyConst = createRefactor({
10425
10778
  description: "Toggle lazy const",
10426
10779
  apply: fn("toggleLazyConst.apply")(function* (sourceFile, textRange) {
10427
10780
  const ts = yield* service(TypeScriptApi);
10781
+ const tsUtils = yield* service(TypeScriptUtils);
10428
10782
  const maybeNode = pipe(
10429
- yield* getAncestorNodesInRange(sourceFile, textRange),
10783
+ tsUtils.getAncestorNodesInRange(sourceFile, textRange),
10430
10784
  filter(ts.isVariableDeclaration),
10431
- filter((node2) => isNodeInRange(textRange)(node2.name)),
10785
+ filter((node2) => tsUtils.isNodeInRange(textRange)(node2.name)),
10432
10786
  filter(
10433
10787
  (node2) => !!node2.initializer && !(ts.isArrowFunction(node2.initializer) && ts.isBlock(node2.initializer.body))
10434
10788
  ),
@@ -10467,6 +10821,7 @@ var togglePipeStyle = createRefactor({
10467
10821
  const ts = yield* service(TypeScriptApi);
10468
10822
  const typeChecker = yield* service(TypeCheckerApi);
10469
10823
  const typeParser = yield* service(TypeParser);
10824
+ const tsUtils = yield* service(TypeScriptUtils);
10470
10825
  const togglePipeStyle2 = (node) => gen(function* () {
10471
10826
  const pipeCall = yield* typeParser.pipeCall(node);
10472
10827
  switch (pipeCall.kind) {
@@ -10511,7 +10866,7 @@ var togglePipeStyle = createRefactor({
10511
10866
  };
10512
10867
  }
10513
10868
  });
10514
- const ancestorNodes = yield* getAncestorNodesInRange(sourceFile, textRange);
10869
+ const ancestorNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange);
10515
10870
  return yield* pipe(
10516
10871
  firstSuccessOf(ancestorNodes.map(togglePipeStyle2)),
10517
10872
  orElse2(() => fail(new RefactorNotApplicableError()))
@@ -10525,9 +10880,38 @@ var toggleReturnTypeAnnotation = createRefactor({
10525
10880
  description: "Toggle return type annotation",
10526
10881
  apply: fn("toggleReturnTypeAnnotation.apply")(function* (sourceFile, textRange) {
10527
10882
  const ts = yield* service(TypeScriptApi);
10883
+ const tsUtils = yield* service(TypeScriptUtils);
10528
10884
  const typeChecker = yield* service(TypeCheckerApi);
10885
+ function addReturnTypeAnnotation(sourceFile2, changeTracker, declaration, typeNode) {
10886
+ const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile2);
10887
+ const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
10888
+ const endNode = needParens ? declaration.parameters[0] : closeParen;
10889
+ if (endNode) {
10890
+ if (needParens) {
10891
+ changeTracker.insertNodeBefore(
10892
+ sourceFile2,
10893
+ endNode,
10894
+ ts.factory.createToken(ts.SyntaxKind.OpenParenToken)
10895
+ );
10896
+ changeTracker.insertNodeAfter(
10897
+ sourceFile2,
10898
+ endNode,
10899
+ ts.factory.createToken(ts.SyntaxKind.CloseParenToken)
10900
+ );
10901
+ }
10902
+ changeTracker.insertNodeAt(sourceFile2, endNode.end, typeNode, { prefix: ": " });
10903
+ }
10904
+ }
10905
+ function removeReturnTypeAnnotation(sourceFile2, changeTracker, declaration) {
10906
+ const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile2);
10907
+ const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
10908
+ const endNode = needParens ? declaration.parameters[0] : closeParen;
10909
+ if (endNode && declaration.type) {
10910
+ changeTracker.deleteRange(sourceFile2, { pos: endNode.end, end: declaration.type.end });
10911
+ }
10912
+ }
10529
10913
  const maybeNode = pipe(
10530
- yield* getAncestorNodesInRange(sourceFile, textRange),
10914
+ tsUtils.getAncestorNodesInRange(sourceFile, textRange),
10531
10915
  filter(
10532
10916
  (node2) => ts.isFunctionDeclaration(node2) || ts.isFunctionExpression(node2) || ts.isArrowFunction(node2) || ts.isMethodDeclaration(node2)
10533
10917
  ),
@@ -10540,8 +10924,8 @@ var toggleReturnTypeAnnotation = createRefactor({
10540
10924
  kind: "refactor.rewrite.effect.toggleReturnTypeAnnotation",
10541
10925
  description: "Toggle return type annotation",
10542
10926
  apply: pipe(
10543
- removeReturnTypeAnnotation(sourceFile, node),
10544
- provideService(TypeScriptApi, ts)
10927
+ service(ChangeTracker),
10928
+ map3((changeTracker) => removeReturnTypeAnnotation(sourceFile, changeTracker, node))
10545
10929
  )
10546
10930
  };
10547
10931
  }
@@ -10557,13 +10941,10 @@ var toggleReturnTypeAnnotation = createRefactor({
10557
10941
  kind: "refactor.rewrite.effect.toggleReturnTypeAnnotation",
10558
10942
  description: "Toggle return type annotation",
10559
10943
  apply: pipe(
10560
- addReturnTypeAnnotation(
10561
- sourceFile,
10562
- node,
10563
- yield* simplifyTypeNode(returnTypeNode)
10564
- ),
10565
- provideService(TypeCheckerApi, typeChecker),
10566
- provideService(TypeScriptApi, ts)
10944
+ service(ChangeTracker),
10945
+ map3(
10946
+ (changeTracker) => addReturnTypeAnnotation(sourceFile, changeTracker, node, tsUtils.simplifyTypeNode(returnTypeNode))
10947
+ )
10567
10948
  )
10568
10949
  };
10569
10950
  })
@@ -10575,11 +10956,12 @@ var toggleTypeAnnotation = createRefactor({
10575
10956
  description: "Toggle type annotation",
10576
10957
  apply: fn("toggleTypeAnnotation.apply")(function* (sourceFile, textRange) {
10577
10958
  const ts = yield* service(TypeScriptApi);
10959
+ const tsUtils = yield* service(TypeScriptUtils);
10578
10960
  const typeChecker = yield* service(TypeCheckerApi);
10579
10961
  const maybeNode = pipe(
10580
- yield* getAncestorNodesInRange(sourceFile, textRange),
10962
+ tsUtils.getAncestorNodesInRange(sourceFile, textRange),
10581
10963
  filter((node2) => ts.isVariableDeclaration(node2) || ts.isPropertyDeclaration(node2)),
10582
- filter((node2) => isNodeInRange(textRange)(node2.name)),
10964
+ filter((node2) => tsUtils.isNodeInRange(textRange)(node2.name)),
10583
10965
  filter((node2) => !!node2.initializer),
10584
10966
  head
10585
10967
  );
@@ -10615,7 +10997,7 @@ var toggleTypeAnnotation = createRefactor({
10615
10997
  changeTracker.insertNodeAt(
10616
10998
  sourceFile,
10617
10999
  node.name.end,
10618
- yield* simplifyTypeNode(initializerTypeNode),
11000
+ tsUtils.simplifyTypeNode(initializerTypeNode),
10619
11001
  {
10620
11002
  prefix: ": "
10621
11003
  }
@@ -10667,21 +11049,16 @@ var IndexSignatureWithMoreThanOneParameterError = class {
10667
11049
  };
10668
11050
  var SchemaGenContext = Tag("SchemaGenContext");
10669
11051
  var makeSchemaGenContext = fn("SchemaGen.makeSchemaGenContext")(function* (sourceFile) {
10670
- const effectSchemaIdentifier = pipe(
10671
- yield* option(
10672
- findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", "Schema")
10673
- ),
10674
- match({
10675
- onNone: () => "Schema",
10676
- onSome: (_) => _.text
10677
- })
10678
- );
11052
+ const tsUtils = yield* service(TypeScriptUtils);
11053
+ const effectSchemaIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
11054
+ sourceFile,
11055
+ "effect",
11056
+ "Schema"
11057
+ ) || "Schema";
10679
11058
  const moduleToImportedName = {};
10680
11059
  for (const moduleName of ["Option", "Either", "Chunk", "Duration"]) {
10681
- const importedName = yield* option(
10682
- findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", moduleName)
10683
- );
10684
- if (isSome2(importedName)) moduleToImportedName[moduleName] = importedName.value.text;
11060
+ const importedName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", moduleName);
11061
+ if (importedName) moduleToImportedName[moduleName] = importedName;
10685
11062
  }
10686
11063
  const ts = yield* service(TypeScriptApi);
10687
11064
  return {
@@ -11065,10 +11442,11 @@ var process = fn("SchemaGen.process")(
11065
11442
  var findNodeToProcess = fn("SchemaGen.findNodeToProcess")(
11066
11443
  function* (sourceFile, textRange) {
11067
11444
  const ts = yield* service(TypeScriptApi);
11445
+ const tsUtils = yield* service(TypeScriptUtils);
11068
11446
  return pipe(
11069
- yield* getAncestorNodesInRange(sourceFile, textRange),
11447
+ tsUtils.getAncestorNodesInRange(sourceFile, textRange),
11070
11448
  filter((node) => ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)),
11071
- filter((node) => isNodeInRange(textRange)(node.name)),
11449
+ filter((node) => tsUtils.isNodeInRange(textRange)(node.name)),
11072
11450
  filter((node) => (node.typeParameters || []).length === 0),
11073
11451
  head
11074
11452
  );
@@ -11101,6 +11479,7 @@ var typeToEffectSchema = createRefactor({
11101
11479
  description: "Refactor to Schema",
11102
11480
  apply: fn("typeToEffectSchema.apply")(function* (sourceFile, textRange) {
11103
11481
  const ts = yield* service(TypeScriptApi);
11482
+ const tsUtils = yield* service(TypeScriptUtils);
11104
11483
  const typeChecker = yield* service(TypeCheckerApi);
11105
11484
  const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
11106
11485
  if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
@@ -11111,6 +11490,7 @@ var typeToEffectSchema = createRefactor({
11111
11490
  apply: pipe(
11112
11491
  applyAtNode(sourceFile, node, false),
11113
11492
  provideService(TypeCheckerApi, typeChecker),
11493
+ provideService(TypeScriptUtils, tsUtils),
11114
11494
  provideService(TypeScriptApi, ts)
11115
11495
  )
11116
11496
  };
@@ -11123,6 +11503,7 @@ var typeToEffectSchemaClass = createRefactor({
11123
11503
  description: "Refactor to Schema.Class",
11124
11504
  apply: fn("typeToEffectSchemaClass.apply")(function* (sourceFile, textRange) {
11125
11505
  const ts = yield* service(TypeScriptApi);
11506
+ const tsUtils = yield* service(TypeScriptUtils);
11126
11507
  const typeChecker = yield* service(TypeCheckerApi);
11127
11508
  const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
11128
11509
  if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
@@ -11133,6 +11514,7 @@ var typeToEffectSchemaClass = createRefactor({
11133
11514
  apply: pipe(
11134
11515
  applyAtNode(sourceFile, node, true),
11135
11516
  provideService(TypeCheckerApi, typeChecker),
11517
+ provideService(TypeScriptUtils, tsUtils),
11136
11518
  provideService(TypeScriptApi, ts)
11137
11519
  )
11138
11520
  };
@@ -11145,6 +11527,7 @@ var wrapWithEffectGen = createRefactor({
11145
11527
  description: "Wrap with Effect.gen",
11146
11528
  apply: fn("wrapWithEffectGen.apply")(function* (sourceFile, textRange) {
11147
11529
  const ts = yield* service(TypeScriptApi);
11530
+ const tsUtils = yield* service(TypeScriptUtils);
11148
11531
  const typeChecker = yield* service(TypeCheckerApi);
11149
11532
  const typeParser = yield* service(TypeParser);
11150
11533
  const findEffectToWrap = fn("wrapWithEffectGen.apply.findEffectToWrap")(
@@ -11158,37 +11541,26 @@ var wrapWithEffectGen = createRefactor({
11158
11541
  }
11159
11542
  );
11160
11543
  const maybeNode = yield* pipe(
11161
- yield* getAncestorNodesInRange(sourceFile, textRange),
11162
- map3(findEffectToWrap),
11544
+ tsUtils.getAncestorNodesInRange(sourceFile, textRange),
11545
+ map4(findEffectToWrap),
11163
11546
  firstSuccessOf,
11164
11547
  option
11165
11548
  );
11166
11549
  if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
11167
- const effectModuleIdentifier = match(
11168
- yield* option(
11169
- findImportedModuleIdentifier(
11170
- sourceFile,
11171
- (node) => pipe(
11172
- typeParser.importedEffectModule(node),
11173
- option,
11174
- map4(isSome2)
11175
- )
11176
- )
11177
- ),
11178
- {
11179
- onNone: () => "Effect",
11180
- onSome: (node) => node.text
11181
- }
11182
- );
11550
+ const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
11551
+ sourceFile,
11552
+ "effect",
11553
+ "Effect"
11554
+ ) || "Effect";
11183
11555
  return {
11184
11556
  kind: "refactor.rewrite.effect.wrapWithEffectGen",
11185
11557
  description: `Wrap with Effect.gen`,
11186
11558
  apply: pipe(
11187
11559
  gen(function* () {
11188
11560
  const changeTracker = yield* service(ChangeTracker);
11189
- const effectGen = yield* createEffectGenCallExpressionWithBlock(
11561
+ const effectGen = tsUtils.createEffectGenCallExpressionWithBlock(
11190
11562
  effectModuleIdentifier,
11191
- yield* createReturnYieldStarStatement(maybeNode.value)
11563
+ tsUtils.createReturnYieldStarStatement(maybeNode.value)
11192
11564
  );
11193
11565
  changeTracker.replaceNode(sourceFile, maybeNode.value, effectGen);
11194
11566
  }),
@@ -11219,273 +11591,6 @@ var wrapWithPipe = createRefactor({
11219
11591
  })
11220
11592
  });
11221
11593
 
11222
- // src/refactors/writeTagClassAccessors.ts
11223
- var writeTagClassAccessors = createRefactor({
11224
- name: "writeTagClassAccessors",
11225
- description: "Implement Service accessors",
11226
- apply: fn("writeTagClassAccessors.apply")(function* (sourceFile, textRange) {
11227
- const ts = yield* service(TypeScriptApi);
11228
- const typeChecker = yield* service(TypeCheckerApi);
11229
- const typeParser = yield* service(TypeParser);
11230
- const effectIdentifier = pipe(
11231
- yield* option(
11232
- findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", "Effect")
11233
- ),
11234
- match({
11235
- onNone: () => "Effect",
11236
- onSome: (_) => _.text
11237
- })
11238
- );
11239
- const createConstantProperty = (className, propertyName, type) => ts.factory.createPropertyDeclaration(
11240
- [ts.factory.createModifier(ts.SyntaxKind.StaticKeyword)],
11241
- propertyName,
11242
- void 0,
11243
- type,
11244
- ts.factory.createCallExpression(
11245
- ts.factory.createPropertyAccessExpression(
11246
- ts.factory.createIdentifier(effectIdentifier),
11247
- "andThen"
11248
- ),
11249
- void 0,
11250
- [
11251
- ts.factory.createIdentifier(className.text),
11252
- ts.factory.createArrowFunction(
11253
- void 0,
11254
- void 0,
11255
- [ts.factory.createParameterDeclaration(
11256
- void 0,
11257
- void 0,
11258
- "_"
11259
- )],
11260
- void 0,
11261
- void 0,
11262
- ts.factory.createPropertyAccessExpression(
11263
- ts.factory.createIdentifier("_"),
11264
- propertyName
11265
- )
11266
- )
11267
- ]
11268
- )
11269
- );
11270
- const createFunctionProperty = (className, propertyName, type, forceAny) => {
11271
- const arrowBody = ts.factory.createCallExpression(
11272
- ts.factory.createPropertyAccessExpression(
11273
- ts.factory.createIdentifier(effectIdentifier),
11274
- "andThen"
11275
- ),
11276
- void 0,
11277
- [
11278
- ts.factory.createIdentifier(className.text),
11279
- ts.factory.createArrowFunction(
11280
- void 0,
11281
- void 0,
11282
- [ts.factory.createParameterDeclaration(
11283
- void 0,
11284
- void 0,
11285
- "_",
11286
- void 0,
11287
- forceAny ? ts.factory.createTypeReferenceNode("any") : void 0
11288
- )],
11289
- void 0,
11290
- void 0,
11291
- ts.factory.createCallExpression(
11292
- ts.factory.createPropertyAccessExpression(
11293
- ts.factory.createIdentifier("_"),
11294
- propertyName
11295
- ),
11296
- void 0,
11297
- [
11298
- ts.factory.createSpreadElement(ts.factory.createIdentifier("args"))
11299
- ]
11300
- )
11301
- )
11302
- ]
11303
- );
11304
- return ts.factory.createPropertyDeclaration(
11305
- [ts.factory.createModifier(ts.SyntaxKind.StaticKeyword)],
11306
- propertyName,
11307
- void 0,
11308
- type,
11309
- ts.factory.createArrowFunction(
11310
- void 0,
11311
- void 0,
11312
- [ts.factory.createParameterDeclaration(
11313
- void 0,
11314
- ts.factory.createToken(ts.SyntaxKind.DotDotDotToken),
11315
- "args",
11316
- void 0,
11317
- forceAny ? ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode("any")) : void 0
11318
- )],
11319
- void 0,
11320
- void 0,
11321
- forceAny ? ts.factory.createAsExpression(arrowBody, ts.factory.createTypeReferenceNode("any")) : arrowBody
11322
- )
11323
- );
11324
- };
11325
- const generateReturnType = (type, atLocation, className) => pipe(
11326
- typeParser.effectType(type, atLocation),
11327
- flatMap2((returnedEffect) => {
11328
- const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(className.text) : ts.factory.createUnionTypeNode(
11329
- [
11330
- ts.factory.createTypeReferenceNode(className.text),
11331
- typeChecker.typeToTypeNode(returnedEffect.R, atLocation, ts.NodeBuilderFlags.NoTruncation)
11332
- ]
11333
- );
11334
- const successType = typeChecker.typeToTypeNode(
11335
- returnedEffect.A,
11336
- atLocation,
11337
- ts.NodeBuilderFlags.NoTruncation
11338
- );
11339
- if (!successType) return fail("error generating success type");
11340
- const failureType = typeChecker.typeToTypeNode(
11341
- returnedEffect.E,
11342
- atLocation,
11343
- ts.NodeBuilderFlags.NoTruncation
11344
- );
11345
- if (!failureType) return fail("error generating failure type");
11346
- const typeNode = ts.factory.createTypeReferenceNode(
11347
- ts.factory.createQualifiedName(
11348
- ts.factory.createIdentifier(effectIdentifier),
11349
- ts.factory.createIdentifier("Effect")
11350
- ),
11351
- [successType, failureType, contextType]
11352
- );
11353
- return succeed(typeNode);
11354
- }),
11355
- orElse2(
11356
- () => pipe(
11357
- typeParser.promiseLike(type, atLocation),
11358
- flatMap2(({ type: type2 }) => {
11359
- const successType = typeChecker.typeToTypeNode(
11360
- type2,
11361
- atLocation,
11362
- ts.NodeBuilderFlags.NoTruncation
11363
- );
11364
- if (!successType) return fail("error generating success type");
11365
- return succeed(ts.factory.createTypeReferenceNode(
11366
- ts.factory.createQualifiedName(
11367
- ts.factory.createIdentifier(effectIdentifier),
11368
- ts.factory.createIdentifier("Effect")
11369
- ),
11370
- [
11371
- successType,
11372
- ts.factory.createTypeReferenceNode(
11373
- ts.factory.createQualifiedName(
11374
- ts.factory.createIdentifier("Cause"),
11375
- ts.factory.createIdentifier("UnknownException")
11376
- )
11377
- ),
11378
- ts.factory.createTypeReferenceNode(className.text)
11379
- ]
11380
- ));
11381
- })
11382
- )
11383
- ),
11384
- orElse2(() => {
11385
- const successType = typeChecker.typeToTypeNode(type, atLocation, ts.NodeBuilderFlags.NoTruncation);
11386
- if (!successType) return fail("error generating success type");
11387
- const typeNode = ts.factory.createTypeReferenceNode(
11388
- ts.factory.createQualifiedName(
11389
- ts.factory.createIdentifier(effectIdentifier),
11390
- ts.factory.createIdentifier("Effect")
11391
- ),
11392
- [
11393
- successType,
11394
- ts.factory.createTypeReferenceNode("never"),
11395
- ts.factory.createTypeReferenceNode(className.text)
11396
- ]
11397
- );
11398
- return succeed(typeNode);
11399
- })
11400
- );
11401
- const proxySignature = (signature, atLocation, className) => gen(function* () {
11402
- const signatureDeclaration = typeChecker.signatureToSignatureDeclaration(
11403
- signature,
11404
- ts.SyntaxKind.FunctionType,
11405
- atLocation,
11406
- ts.NodeBuilderFlags.NoTruncation
11407
- );
11408
- if (!signatureDeclaration) return yield* fail("error generating signature");
11409
- const returnType = yield* generateReturnType(signature.getReturnType(), atLocation, className);
11410
- return ts.factory.createFunctionTypeNode(
11411
- signatureDeclaration.typeParameters,
11412
- signatureDeclaration.parameters,
11413
- returnType
11414
- );
11415
- });
11416
- const writeAccessors = fn("writeTagClassAccessors.writeAccessors")(
11417
- function* (service2, className, atLocation) {
11418
- const changeTracker = yield* service(ChangeTracker);
11419
- const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.getEnd() - 1;
11420
- for (const property of typeChecker.getPropertiesOfType(service2)) {
11421
- const servicePropertyType = typeChecker.getTypeOfSymbolAtLocation(property, atLocation);
11422
- const callSignatures = [];
11423
- let propertyDeclaration = void 0;
11424
- for (const signature of servicePropertyType.getCallSignatures()) {
11425
- yield* pipe(
11426
- proxySignature(signature, atLocation, className),
11427
- map4((sig) => {
11428
- callSignatures.push(sig);
11429
- }),
11430
- ignore
11431
- );
11432
- }
11433
- if (callSignatures.length === 0) {
11434
- yield* pipe(
11435
- generateReturnType(servicePropertyType, atLocation, className),
11436
- map4((type) => {
11437
- propertyDeclaration = createConstantProperty(className, property.getName(), type);
11438
- }),
11439
- ignore
11440
- );
11441
- } else {
11442
- const allSignatures = ts.factory.createIntersectionTypeNode(callSignatures);
11443
- const type = yield* simplifyTypeNode(allSignatures);
11444
- propertyDeclaration = createFunctionProperty(className, property.getName(), type, callSignatures.length > 1);
11445
- }
11446
- if (propertyDeclaration) {
11447
- const oldProperty = atLocation.members.filter(ts.isPropertyDeclaration).find((p) => {
11448
- const symbol3 = typeChecker.getSymbolAtLocation(p.name);
11449
- return symbol3?.getName() === property.getName();
11450
- });
11451
- if (oldProperty) {
11452
- changeTracker.deleteRange(sourceFile, {
11453
- pos: oldProperty.getStart(sourceFile),
11454
- end: oldProperty.getEnd()
11455
- });
11456
- changeTracker.insertNodeAt(sourceFile, oldProperty.getStart(sourceFile), propertyDeclaration);
11457
- } else {
11458
- changeTracker.insertNodeAt(sourceFile, insertLocation, propertyDeclaration, { suffix: "\n" });
11459
- }
11460
- }
11461
- }
11462
- }
11463
- );
11464
- const writeTagClassAccessors2 = (node) => gen(function* () {
11465
- if (!ts.isClassDeclaration(node)) return yield* fail(new RefactorNotApplicableError());
11466
- if (!node.name) return yield* fail(new RefactorNotApplicableError());
11467
- const classSym = typeChecker.getSymbolAtLocation(node.name);
11468
- if (!classSym) return yield* fail(new RefactorNotApplicableError());
11469
- const type = typeChecker.getTypeOfSymbol(classSym);
11470
- const { Service } = yield* pipe(
11471
- typeParser.contextTag(type, node),
11472
- orElse2(() => fail(new RefactorNotApplicableError()))
11473
- );
11474
- return {
11475
- kind: "refactor.rewrite.effect.writeTagClassAccessors",
11476
- description: "Implement Service accessors",
11477
- apply: pipe(
11478
- writeAccessors(Service, node.name, node),
11479
- provideService(TypeCheckerApi, typeChecker),
11480
- provideService(TypeScriptApi, ts)
11481
- )
11482
- };
11483
- });
11484
- const parentNodes = yield* getAncestorNodesInRange(sourceFile, textRange);
11485
- return yield* firstSuccessOf(parentNodes.map(writeTagClassAccessors2));
11486
- })
11487
- });
11488
-
11489
11594
  // src/refactors.ts
11490
11595
  var refactors = [
11491
11596
  asyncAwaitToGen,
@@ -11536,13 +11641,10 @@ var init = (modules) => {
11536
11641
  function runNano(program) {
11537
11642
  return (fa) => pipe(
11538
11643
  fa,
11539
- provideService(TypeParser, make3(modules.typescript, program.getTypeChecker())),
11540
- provideService(TypeScriptProgram, program),
11644
+ nanoLayer2,
11645
+ nanoLayer,
11541
11646
  provideService(TypeCheckerApi, program.getTypeChecker()),
11542
- provideService(
11543
- TypeCheckerApiCache,
11544
- makeTypeCheckerApiCache()
11545
- ),
11647
+ provideService(TypeScriptProgram, program),
11546
11648
  provideService(TypeScriptApi, modules.typescript),
11547
11649
  provideService(
11548
11650
  LanguageServicePluginOptions,
@@ -11626,7 +11728,7 @@ var init = (modules) => {
11626
11728
  }
11627
11729
  return effectCodeFixes;
11628
11730
  }),
11629
- flatMap2(
11731
+ flatMap(
11630
11732
  (effectCodeFixes) => pipe(
11631
11733
  middlewareAutoImportQuickfixes(
11632
11734
  sourceFile,
@@ -11635,7 +11737,7 @@ var init = (modules) => {
11635
11737
  preferences,
11636
11738
  applicableCodeFixes
11637
11739
  ),
11638
- map4((modifiedCodeFixes) => effectCodeFixes.concat(modifiedCodeFixes))
11740
+ map3((modifiedCodeFixes) => effectCodeFixes.concat(modifiedCodeFixes))
11639
11741
  )
11640
11742
  ),
11641
11743
  runNano(program),
@@ -11744,7 +11846,7 @@ var init = (modules) => {
11744
11846
  if (sourceFile) {
11745
11847
  return pipe(
11746
11848
  appendEffectCompletionEntryData(sourceFile, applicableCompletions),
11747
- flatMap2(
11849
+ flatMap(
11748
11850
  (augmentedCompletions) => pipe(
11749
11851
  getCompletionsAtPosition(
11750
11852
  completions,
@@ -11753,7 +11855,7 @@ var init = (modules) => {
11753
11855
  options,
11754
11856
  formattingSettings
11755
11857
  ),
11756
- map4(
11858
+ map3(
11757
11859
  (effectCompletions) => augmentedCompletions ? {
11758
11860
  ...augmentedCompletions,
11759
11861
  entries: effectCompletions.concat(augmentedCompletions.entries)