@effect/language-service 0.7.1 → 0.8.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.
Files changed (3) hide show
  1. package/index.js +3348 -1096
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all2) => {
4
+ for (var name in all2)
5
+ __defProp(target, name, { get: all2[name], enumerable: true });
6
+ };
2
7
 
3
8
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Function.js
4
9
  var isFunction = (input) => typeof input === "function";
@@ -65,6 +70,9 @@ var dual = function(arity, body) {
65
70
  };
66
71
  var identity = (a) => a;
67
72
  var constant = (value) => () => value;
73
+ var constTrue = /* @__PURE__ */ constant(true);
74
+ var constFalse = /* @__PURE__ */ constant(false);
75
+ var constNull = /* @__PURE__ */ constant(null);
68
76
  var constUndefined = /* @__PURE__ */ constant(void 0);
69
77
  function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
70
78
  switch (arguments.length) {
@@ -96,6 +104,73 @@ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
96
104
  }
97
105
  }
98
106
 
107
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Either.js
108
+ var Either_exports = {};
109
+ __export(Either_exports, {
110
+ Do: () => Do,
111
+ TypeId: () => TypeId3,
112
+ all: () => all,
113
+ andThen: () => andThen,
114
+ ap: () => ap,
115
+ bind: () => bind2,
116
+ bindTo: () => bindTo2,
117
+ filterOrLeft: () => filterOrLeft,
118
+ flatMap: () => flatMap,
119
+ flip: () => flip,
120
+ fromNullable: () => fromNullable,
121
+ fromOption: () => fromOption2,
122
+ gen: () => gen,
123
+ getEquivalence: () => getEquivalence,
124
+ getLeft: () => getLeft2,
125
+ getOrElse: () => getOrElse,
126
+ getOrNull: () => getOrNull,
127
+ getOrThrow: () => getOrThrow,
128
+ getOrThrowWith: () => getOrThrowWith,
129
+ getOrUndefined: () => getOrUndefined,
130
+ getRight: () => getRight2,
131
+ isEither: () => isEither2,
132
+ isLeft: () => isLeft2,
133
+ isRight: () => isRight2,
134
+ left: () => left2,
135
+ let: () => let_2,
136
+ liftPredicate: () => liftPredicate,
137
+ map: () => map,
138
+ mapBoth: () => mapBoth,
139
+ mapLeft: () => mapLeft,
140
+ match: () => match,
141
+ merge: () => merge,
142
+ orElse: () => orElse,
143
+ right: () => right2,
144
+ try: () => try_,
145
+ zipWith: () => zipWith
146
+ });
147
+
148
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Equivalence.js
149
+ var make = (isEquivalent) => (self, that) => self === that || isEquivalent(self, that);
150
+ var array = (item) => make((self, that) => {
151
+ if (self.length !== that.length) {
152
+ return false;
153
+ }
154
+ for (let i = 0; i < self.length; i++) {
155
+ const isEq = item(self[i], that[i]);
156
+ if (!isEq) {
157
+ return false;
158
+ }
159
+ }
160
+ return true;
161
+ });
162
+
163
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/doNotation.js
164
+ var let_ = (map8) => dual(3, (self, name, f) => map8(self, (a) => Object.assign({}, a, {
165
+ [name]: f(a)
166
+ })));
167
+ var bindTo = (map8) => dual(2, (self, name) => map8(self, (a) => ({
168
+ [name]: a
169
+ })));
170
+ var bind = (map8, flatMap5) => dual(3, (self, name, f) => flatMap5(self, (a) => map8(f(a), (b) => Object.assign({}, a, {
171
+ [name]: b
172
+ }))));
173
+
99
174
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/version.js
100
175
  var moduleVersion = "3.12.5";
101
176
  var getCurrentVersion = () => moduleVersion;
@@ -115,11 +190,11 @@ var globalValue = (id, compute) => {
115
190
  };
116
191
 
117
192
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Predicate.js
118
- var isBoolean = (input) => typeof input === "boolean";
119
193
  var isFunction2 = isFunction;
120
194
  var isRecordOrArray = (input) => typeof input === "object" && input !== null;
121
195
  var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
122
196
  var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObject(self) && property in self);
197
+ var isTagged = /* @__PURE__ */ dual(2, (self, tag) => hasProperty(self, "_tag") && self["_tag"] === tag);
123
198
 
124
199
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/errors.js
125
200
  var getBugErrorMessage = (message) => `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`;
@@ -310,14 +385,21 @@ var string = (str) => {
310
385
  }
311
386
  return optimize(h);
312
387
  };
313
- var structureKeys = (o, keys) => {
388
+ var structureKeys = (o, keys2) => {
314
389
  let h = 12289;
315
- for (let i = 0; i < keys.length; i++) {
316
- h ^= pipe(string(keys[i]), combine(hash(o[keys[i]])));
390
+ for (let i = 0; i < keys2.length; i++) {
391
+ h ^= pipe(string(keys2[i]), combine(hash(o[keys2[i]])));
317
392
  }
318
393
  return optimize(h);
319
394
  };
320
395
  var structure = (o) => structureKeys(o, Object.keys(o));
396
+ var array2 = (arr) => {
397
+ let h = 6151;
398
+ for (let i = 0; i < arr.length; i++) {
399
+ h = pipe(h, combine(hash(arr[i])));
400
+ }
401
+ return optimize(h);
402
+ };
321
403
  var cached = function() {
322
404
  if (arguments.length === 1) {
323
405
  const self2 = arguments[0];
@@ -393,21 +475,6 @@ function compareBoth(self, that) {
393
475
  }
394
476
  var isEqual = (u) => hasProperty(u, symbol2);
395
477
 
396
- // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Equivalence.js
397
- var make = (isEquivalent) => (self, that) => self === that || isEquivalent(self, that);
398
- var array = (item) => make((self, that) => {
399
- if (self.length !== that.length) {
400
- return false;
401
- }
402
- for (let i = 0; i < self.length; i++) {
403
- const isEq = item(self[i], that[i]);
404
- if (!isEq) {
405
- return false;
406
- }
407
- }
408
- return true;
409
- });
410
-
411
478
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Inspectable.js
412
479
  var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
413
480
  var toJSON = (x) => {
@@ -448,6 +515,12 @@ var Class = class {
448
515
  return format(this.toJSON());
449
516
  }
450
517
  };
518
+ var stringifyCircular = (obj, whitespace) => {
519
+ let cache = [];
520
+ const retVal = JSON.stringify(obj, (_key, value) => typeof value === "object" && value !== null ? cache.includes(value) ? void 0 : cache.push(value) && (redactableState.fiberRefs !== void 0 && isRedactable(value) ? value[symbolRedactable](redactableState.fiberRefs) : value) : value, whitespace);
521
+ cache = void 0;
522
+ return retVal;
523
+ };
451
524
  var symbolRedactable = /* @__PURE__ */ Symbol.for("effect/Inspectable/Redactable");
452
525
  var isRedactable = (u) => typeof u === "object" && u !== null && symbolRedactable in u;
453
526
  var redactableState = /* @__PURE__ */ globalValue("effect/Inspectable/redactableState", () => ({
@@ -495,6 +568,8 @@ var pipeArguments = (self, args) => {
495
568
 
496
569
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/opCodes/effect.js
497
570
  var OP_COMMIT = "Commit";
571
+ var OP_FAILURE = "Failure";
572
+ var OP_WITH_RUNTIME = "WithRuntime";
498
573
 
499
574
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/effectable.js
500
575
  var EffectTypeId = /* @__PURE__ */ Symbol.for("effect/Effect");
@@ -641,53 +716,164 @@ var some = (value) => {
641
716
  return a;
642
717
  };
643
718
 
644
- // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Order.js
645
- var make2 = (compare) => (self, that) => self === that ? 0 : compare(self, that);
719
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/either.js
720
+ var TypeId2 = /* @__PURE__ */ Symbol.for("effect/Either");
721
+ var CommonProto2 = {
722
+ ...EffectPrototype,
723
+ [TypeId2]: {
724
+ _R: (_) => _
725
+ },
726
+ [NodeInspectSymbol]() {
727
+ return this.toJSON();
728
+ },
729
+ toString() {
730
+ return format(this.toJSON());
731
+ }
732
+ };
733
+ var RightProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto2), {
734
+ _tag: "Right",
735
+ _op: "Right",
736
+ [symbol2](that) {
737
+ return isEither(that) && isRight(that) && equals(this.right, that.right);
738
+ },
739
+ [symbol]() {
740
+ return combine(hash(this._tag))(hash(this.right));
741
+ },
742
+ toJSON() {
743
+ return {
744
+ _id: "Either",
745
+ _tag: this._tag,
746
+ right: toJSON(this.right)
747
+ };
748
+ }
749
+ });
750
+ var LeftProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto2), {
751
+ _tag: "Left",
752
+ _op: "Left",
753
+ [symbol2](that) {
754
+ return isEither(that) && isLeft(that) && equals(this.left, that.left);
755
+ },
756
+ [symbol]() {
757
+ return combine(hash(this._tag))(hash(this.left));
758
+ },
759
+ toJSON() {
760
+ return {
761
+ _id: "Either",
762
+ _tag: this._tag,
763
+ left: toJSON(this.left)
764
+ };
765
+ }
766
+ });
767
+ var isEither = (input) => hasProperty(input, TypeId2);
768
+ var isLeft = (ma) => ma._tag === "Left";
769
+ var isRight = (ma) => ma._tag === "Right";
770
+ var left = (left3) => {
771
+ const a = Object.create(LeftProto);
772
+ a.left = left3;
773
+ return a;
774
+ };
775
+ var right = (right3) => {
776
+ const a = Object.create(RightProto);
777
+ a.right = right3;
778
+ return a;
779
+ };
780
+ var getLeft = (self) => isRight(self) ? none : some(self.left);
781
+ var getRight = (self) => isLeft(self) ? none : some(self.right);
782
+ var fromOption = /* @__PURE__ */ dual(2, (self, onNone) => isNone(self) ? left(onNone()) : right(self.value));
646
783
 
647
- // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Option.js
648
- var none2 = () => none;
649
- var some2 = some;
650
- var isNone2 = isNone;
651
- var isSome2 = isSome;
652
- var getOrElse = /* @__PURE__ */ dual(2, (self, onNone) => isNone2(self) ? onNone() : self.value);
653
- var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : self);
654
- var fromNullable = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
784
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Either.js
785
+ var TypeId3 = TypeId2;
786
+ var right2 = right;
787
+ var left2 = left;
788
+ var fromNullable = /* @__PURE__ */ dual(2, (self, onNullable) => self == null ? left2(onNullable(self)) : right2(self));
789
+ var fromOption2 = fromOption;
790
+ var try_ = (evaluate) => {
791
+ if (isFunction2(evaluate)) {
792
+ try {
793
+ return right2(evaluate());
794
+ } catch (e) {
795
+ return left2(e);
796
+ }
797
+ } else {
798
+ try {
799
+ return right2(evaluate.try());
800
+ } catch (e) {
801
+ return left2(evaluate.catch(e));
802
+ }
803
+ }
804
+ };
805
+ var isEither2 = isEither;
806
+ var isLeft2 = isLeft;
807
+ var isRight2 = isRight;
808
+ var getRight2 = getRight;
809
+ var getLeft2 = getLeft;
810
+ var getEquivalence = ({
811
+ left: left3,
812
+ right: right3
813
+ }) => make((x, y) => isLeft2(x) ? isLeft2(y) && left3(x.left, y.left) : isRight2(y) && right3(x.right, y.right));
814
+ var mapBoth = /* @__PURE__ */ dual(2, (self, {
815
+ onLeft,
816
+ onRight
817
+ }) => isLeft2(self) ? left2(onLeft(self.left)) : right2(onRight(self.right)));
818
+ var mapLeft = /* @__PURE__ */ dual(2, (self, f) => isLeft2(self) ? left2(f(self.left)) : right2(self.right));
819
+ var map = /* @__PURE__ */ dual(2, (self, f) => isRight2(self) ? right2(f(self.right)) : left2(self.left));
820
+ var match = /* @__PURE__ */ dual(2, (self, {
821
+ onLeft,
822
+ onRight
823
+ }) => isLeft2(self) ? onLeft(self.left) : onRight(self.right));
824
+ var liftPredicate = /* @__PURE__ */ dual(3, (a, predicate, orLeftWith) => predicate(a) ? right2(a) : left2(orLeftWith(a)));
825
+ var filterOrLeft = /* @__PURE__ */ dual(3, (self, predicate, orLeftWith) => flatMap(self, (r) => predicate(r) ? right2(r) : left2(orLeftWith(r))));
826
+ var merge = /* @__PURE__ */ match({
827
+ onLeft: identity,
828
+ onRight: identity
829
+ });
830
+ var getOrElse = /* @__PURE__ */ dual(2, (self, onLeft) => isLeft2(self) ? onLeft(self.left) : self.right);
831
+ var getOrNull = /* @__PURE__ */ getOrElse(constNull);
655
832
  var getOrUndefined = /* @__PURE__ */ getOrElse(constUndefined);
656
- var map = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() : some2(f(self.value)));
657
- var flatMap = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() : f(self.value));
833
+ var getOrThrowWith = /* @__PURE__ */ dual(2, (self, onLeft) => {
834
+ if (isRight2(self)) {
835
+ return self.right;
836
+ }
837
+ throw onLeft(self.left);
838
+ });
839
+ var getOrThrow = /* @__PURE__ */ getOrThrowWith(() => new Error("getOrThrow called on a Left"));
840
+ var orElse = /* @__PURE__ */ dual(2, (self, that) => isLeft2(self) ? that(self.left) : right2(self.right));
841
+ var flatMap = /* @__PURE__ */ dual(2, (self, f) => isLeft2(self) ? left2(self.left) : f(self.right));
842
+ var andThen = /* @__PURE__ */ dual(2, (self, f) => flatMap(self, (a) => {
843
+ const b = isFunction2(f) ? f(a) : f;
844
+ return isEither2(b) ? b : right2(b);
845
+ }));
846
+ var zipWith = /* @__PURE__ */ dual(3, (self, that, f) => flatMap(self, (r) => map(that, (r2) => f(r, r2))));
847
+ var ap = /* @__PURE__ */ dual(2, (self, that) => zipWith(self, that, (f, a) => f(a)));
658
848
  var all = (input) => {
659
849
  if (Symbol.iterator in input) {
660
850
  const out2 = [];
661
- for (const o of input) {
662
- if (isNone2(o)) {
663
- return none2();
851
+ for (const e of input) {
852
+ if (isLeft2(e)) {
853
+ return e;
664
854
  }
665
- out2.push(o.value);
855
+ out2.push(e.right);
666
856
  }
667
- return some2(out2);
857
+ return right2(out2);
668
858
  }
669
859
  const out = {};
670
860
  for (const key of Object.keys(input)) {
671
- const o = input[key];
672
- if (isNone2(o)) {
673
- return none2();
861
+ const e = input[key];
862
+ if (isLeft2(e)) {
863
+ return e;
674
864
  }
675
- out[key] = o.value;
865
+ out[key] = e.right;
676
866
  }
677
- return some2(out);
867
+ return right2(out);
678
868
  };
869
+ var flip = (self) => isLeft2(self) ? right2(self.left) : left2(self.right);
679
870
  var adapter2 = /* @__PURE__ */ adapter();
680
871
  var gen = (...args) => {
681
- let f;
682
- if (args.length === 1) {
683
- f = args[0];
684
- } else {
685
- f = args[1].bind(args[0]);
686
- }
872
+ const f = args.length === 1 ? args[0] : args[1].bind(args[0]);
687
873
  const iterator = f(adapter2);
688
874
  let state = iterator.next();
689
875
  if (state.done) {
690
- return some2(state.value);
876
+ return right2(state.value);
691
877
  } else {
692
878
  let current = state.value;
693
879
  if (isGenKind(current)) {
@@ -695,11 +881,11 @@ var gen = (...args) => {
695
881
  } else {
696
882
  current = yieldWrapGet(current);
697
883
  }
698
- if (isNone2(current)) {
884
+ if (isLeft2(current)) {
699
885
  return current;
700
886
  }
701
887
  while (!state.done) {
702
- state = iterator.next(current.value);
888
+ state = iterator.next(current.right);
703
889
  if (!state.done) {
704
890
  current = state.value;
705
891
  if (isGenKind(current)) {
@@ -707,230 +893,42 @@ var gen = (...args) => {
707
893
  } else {
708
894
  current = yieldWrapGet(current);
709
895
  }
710
- if (isNone2(current)) {
896
+ if (isLeft2(current)) {
711
897
  return current;
712
898
  }
713
899
  }
714
900
  }
715
- return some2(state.value);
901
+ return right2(state.value);
716
902
  }
717
903
  };
718
-
719
- // src/definition.ts
720
- function createRefactor(definition) {
721
- return definition;
722
- }
723
- function createDiagnostic(definition) {
724
- return definition;
725
- }
726
-
727
- // src/utils/TypeParser.ts
728
- var covariantTypeArgument = (type) => {
729
- const signatures = type.getCallSignatures();
730
- if (signatures.length !== 1) return none2();
731
- return some2(signatures[0].getReturnType());
732
- };
733
- function pipeableType(ts, typeChecker) {
734
- return (type, atLocation) => {
735
- const pipeSymbol = typeChecker.getPropertyOfType(type, "pipe");
736
- if (!pipeSymbol) return none2();
737
- const pipeType = typeChecker.getTypeOfSymbolAtLocation(pipeSymbol, atLocation);
738
- const signatures = pipeType.getCallSignatures();
739
- if (signatures.length === 0) return none2();
740
- return some2(type);
741
- };
742
- }
743
- function varianceStructCovariantType(ts, typeChecker) {
744
- return (type, atLocation, propertyName) => gen(function* (_) {
745
- const propertySymbol = yield* fromNullable(
746
- typeChecker.getPropertyOfType(type, propertyName)
747
- );
748
- const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
749
- return yield* covariantTypeArgument(propertyType);
750
- });
751
- }
752
- function effectVarianceStruct(ts, typeChecker) {
753
- return (type, atLocation) => all({
754
- A: varianceStructCovariantType(ts, typeChecker)(type, atLocation, "_A"),
755
- E: varianceStructCovariantType(ts, typeChecker)(type, atLocation, "_E"),
756
- R: varianceStructCovariantType(ts, typeChecker)(type, atLocation, "_R")
757
- });
758
- }
759
- function effectType(ts, typeChecker) {
760
- return (type, atLocation) => gen(function* (_) {
761
- yield* pipeableType(ts, typeChecker)(type, atLocation);
762
- for (const propertySymbol of typeChecker.getPropertiesOfType(type)) {
763
- const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
764
- const varianceArgs = effectVarianceStruct(ts, typeChecker)(
765
- propertyType,
766
- atLocation
767
- );
768
- if (isSome2(varianceArgs)) {
769
- return yield* varianceArgs;
770
- }
771
- }
772
- return yield* none2();
773
- });
774
- }
775
- function fiberType(ts, typeChecker) {
776
- return (type, atLocation) => gen(function* (_) {
777
- const awaitSymbol = yield* fromNullable(
778
- typeChecker.getPropertyOfType(type, "await")
779
- );
780
- const pollSymbol = yield* fromNullable(
781
- typeChecker.getPropertyOfType(type, "poll")
782
- );
783
- if (!awaitSymbol || !pollSymbol) return yield* none2();
784
- return effectType(ts, typeChecker)(type, atLocation);
785
- });
786
- }
787
- function effectSubtype(ts, typeChecker) {
788
- return (type, atLocation) => gen(function* (_) {
789
- const tagSymbol = yield* fromNullable(
790
- typeChecker.getPropertyOfType(type, "_tag")
791
- );
792
- if (!tagSymbol) return yield* none2();
793
- return effectType(ts, typeChecker)(type, atLocation);
794
- });
795
- }
796
- function importedEffectModule(ts, typeChecker) {
797
- return (node) => gen(function* () {
798
- const type = typeChecker.getTypeAtLocation(node);
799
- const propertySymbol = yield* fromNullable(
800
- typeChecker.getPropertyOfType(type, "never")
801
- );
802
- const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, node);
803
- return yield* effectType(ts, typeChecker)(propertyType, node).pipe(
804
- map(() => node)
805
- );
806
- });
807
- }
808
- function effectGen(ts, typeChecker) {
809
- return (node) => gen(function* () {
810
- if (!ts.isCallExpression(node)) return yield* none2();
811
- if (node.arguments.length === 0) return yield* none2();
812
- const generatorFunction = node.arguments[0];
813
- if (!ts.isFunctionExpression(generatorFunction)) return yield* none2();
814
- if (generatorFunction.asteriskToken === void 0) return yield* none2();
815
- if (!ts.isPropertyAccessExpression(node.expression)) return yield* none2();
816
- const propertyAccess = node.expression;
817
- if (propertyAccess.name.text !== "gen") return yield* none2();
818
- const effectModule = yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression);
819
- return {
820
- node,
821
- effectModule,
822
- generatorFunction,
823
- body: generatorFunction.body,
824
- functionStar: generatorFunction.getFirstToken()
825
- };
826
- });
827
- }
828
- function effectFnUntracedGen(ts, typeChecker) {
829
- return (node) => gen(function* () {
830
- if (!ts.isCallExpression(node)) return yield* none2();
831
- if (node.arguments.length === 0) return yield* none2();
832
- const generatorFunction = node.arguments[0];
833
- if (!ts.isFunctionExpression(generatorFunction)) return yield* none2();
834
- if (generatorFunction.asteriskToken === void 0) return yield* none2();
835
- if (!ts.isPropertyAccessExpression(node.expression)) return yield* none2();
836
- const propertyAccess = node.expression;
837
- if (propertyAccess.name.text !== "fnUntraced") return yield* none2();
838
- const effectModule = yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression);
839
- return {
840
- node,
841
- effectModule,
842
- generatorFunction,
843
- body: generatorFunction.body,
844
- functionStar: generatorFunction.getFirstToken()
845
- };
846
- });
847
- }
848
- function effectFnGen(ts, typeChecker) {
849
- return (node) => gen(function* () {
850
- if (!ts.isCallExpression(node)) return yield* none2();
851
- if (node.arguments.length === 0) return yield* none2();
852
- const generatorFunction = node.arguments[0];
853
- if (!ts.isFunctionExpression(generatorFunction)) return yield* none2();
854
- if (generatorFunction.asteriskToken === void 0) return yield* none2();
855
- const expressionToTest = ts.isCallExpression(node.expression) ? node.expression.expression : node.expression;
856
- if (!ts.isPropertyAccessExpression(expressionToTest)) return yield* none2();
857
- const propertyAccess = expressionToTest;
858
- if (propertyAccess.name.text !== "fn") return yield* none2();
859
- const effectModule = yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression);
860
- return {
861
- node,
862
- generatorFunction,
863
- effectModule,
864
- body: generatorFunction.body,
865
- functionStar: generatorFunction.getFirstToken()
866
- };
867
- });
868
- }
869
-
870
- // src/diagnostics/floatingEffect.ts
871
- var floatingEffect = createDiagnostic({
872
- code: 3,
873
- apply: (ts, program) => (sourceFile) => {
874
- const typeChecker = program.getTypeChecker();
875
- const effectDiagnostics = [];
876
- function isFloatingExpression(node) {
877
- if (!ts.isExpressionStatement(node)) return false;
878
- if (!(ts.isBlock(node.parent) || ts.isSourceFile(node.parent))) return false;
879
- const expression = node.expression;
880
- if (ts.isBinaryExpression(expression) && expression.operatorToken && expression.operatorToken.kind === ts.SyntaxKind.EqualsToken) return false;
881
- return true;
882
- }
883
- const visit = (node) => {
884
- if (isFloatingExpression(node)) {
885
- const type = typeChecker.getTypeAtLocation(node.expression);
886
- const effect = effectType(ts, typeChecker)(type, node.expression);
887
- if (isSome2(effect)) {
888
- const allowedFloatingEffects = pipe(
889
- fiberType(ts, typeChecker)(type, node.expression),
890
- orElse(() => effectSubtype(ts, typeChecker)(type, node.expression))
891
- );
892
- if (isNone2(allowedFloatingEffects)) {
893
- effectDiagnostics.push({
894
- node,
895
- category: ts.DiagnosticCategory.Error,
896
- messageText: `Effect must be yielded or assigned to a variable.`
897
- });
898
- }
899
- }
900
- }
901
- ts.forEachChild(node, visit);
902
- };
903
- ts.forEachChild(sourceFile, visit);
904
- return effectDiagnostics;
905
- }
906
- });
904
+ var Do = /* @__PURE__ */ right2({});
905
+ var bind2 = /* @__PURE__ */ bind(map, flatMap);
906
+ var bindTo2 = /* @__PURE__ */ bindTo(map);
907
+ var let_2 = /* @__PURE__ */ let_(map);
907
908
 
908
909
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/array.js
909
910
  var isNonEmptyArray = (self) => self.length > 0;
910
911
 
911
- // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Iterable.js
912
- var findFirst = /* @__PURE__ */ dual(2, (self, f) => {
913
- let i = 0;
914
- for (const a of self) {
915
- const o = f(a, i);
916
- if (isBoolean(o)) {
917
- if (o) {
918
- return some2(a);
919
- }
920
- } else {
921
- if (isSome2(o)) {
922
- return o;
923
- }
924
- }
925
- i++;
926
- }
927
- return none2();
928
- });
912
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Order.js
913
+ var make2 = (compare) => (self, that) => self === that ? 0 : compare(self, that);
914
+
915
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Option.js
916
+ var none2 = () => none;
917
+ var some2 = some;
918
+ var isNone2 = isNone;
919
+ var isSome2 = isSome;
920
+ var match2 = /* @__PURE__ */ dual(2, (self, {
921
+ onNone,
922
+ onSome
923
+ }) => isNone2(self) ? onNone() : onSome(self.value));
924
+ var getOrElse2 = /* @__PURE__ */ dual(2, (self, onNone) => isNone2(self) ? onNone() : self.value);
925
+ var orElse2 = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : self);
926
+ var fromNullable2 = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
927
+ var getOrUndefined2 = /* @__PURE__ */ getOrElse2(constUndefined);
929
928
 
930
929
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Array.js
931
930
  var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
932
931
  var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
933
- var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
934
932
  var isArray = Array.isArray;
935
933
  var isNonEmptyReadonlyArray = isNonEmptyArray;
936
934
  var isOutOfBound = (i, as) => i < 0 || i >= as.length;
@@ -948,7 +946,7 @@ var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
948
946
  var head = /* @__PURE__ */ get(0);
949
947
  var headNonEmpty = /* @__PURE__ */ unsafeGet(0);
950
948
  var tailNonEmpty = (self) => self.slice(1);
951
- var findFirst2 = findFirst;
949
+ var reverse = (self) => Array.from(self).reverse();
952
950
  var sort = /* @__PURE__ */ dual(2, (self, O) => {
953
951
  const out = Array.from(self);
954
952
  out.sort(O);
@@ -966,6 +964,7 @@ var filter = /* @__PURE__ */ dual(2, (self, predicate) => {
966
964
  }
967
965
  return out;
968
966
  });
967
+ var reduce = /* @__PURE__ */ dual(3, (self, b, f) => fromIterable(self).reduce((b2, a, i) => f(b2, a, i), b));
969
968
  var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
970
969
  const input = fromIterable(self);
971
970
  if (isNonEmptyReadonlyArray(input)) {
@@ -981,241 +980,1855 @@ var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
981
980
  return [];
982
981
  });
983
982
 
984
- // src/utils/AST.ts
985
- function collectSelfAndAncestorNodesInRange(node, textRange) {
986
- let result = empty();
987
- let parent = node;
988
- while (parent) {
989
- if (parent.end >= textRange.end) {
990
- result = pipe(result, append(parent));
991
- }
992
- parent = parent.parent;
983
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Chunk.js
984
+ var TypeId4 = /* @__PURE__ */ Symbol.for("effect/Chunk");
985
+ function copy(src, srcPos, dest, destPos, len) {
986
+ for (let i = srcPos; i < Math.min(src.length, srcPos + len); i++) {
987
+ dest[destPos + i - srcPos] = src[i];
993
988
  }
994
- return result;
995
- }
996
- function getAncestorNodesInRange(ts) {
997
- return (sourceFile, textRange) => {
998
- const precedingToken = ts.findPrecedingToken(textRange.pos, sourceFile);
999
- if (!precedingToken) return empty();
1000
- return collectSelfAndAncestorNodesInRange(precedingToken, textRange);
1001
- };
989
+ return dest;
1002
990
  }
1003
- function findNodeAtPosition(ts, sourceFile, position) {
1004
- function find(node) {
1005
- if (position >= node.getStart() && position < node.getEnd()) {
1006
- return ts.forEachChild(node, find) || node;
991
+ var emptyArray = [];
992
+ var getEquivalence2 = (isEquivalent) => make((self, that) => self.length === that.length && toReadonlyArray(self).every((value, i) => isEquivalent(value, unsafeGet2(that, i))));
993
+ var _equivalence = /* @__PURE__ */ getEquivalence2(equals);
994
+ var ChunkProto = {
995
+ [TypeId4]: {
996
+ _A: (_) => _
997
+ },
998
+ toString() {
999
+ return format(this.toJSON());
1000
+ },
1001
+ toJSON() {
1002
+ return {
1003
+ _id: "Chunk",
1004
+ values: toReadonlyArray(this).map(toJSON)
1005
+ };
1006
+ },
1007
+ [NodeInspectSymbol]() {
1008
+ return this.toJSON();
1009
+ },
1010
+ [symbol2](that) {
1011
+ return isChunk(that) && _equivalence(this, that);
1012
+ },
1013
+ [symbol]() {
1014
+ return cached(this, array2(toReadonlyArray(this)));
1015
+ },
1016
+ [Symbol.iterator]() {
1017
+ switch (this.backing._tag) {
1018
+ case "IArray": {
1019
+ return this.backing.array[Symbol.iterator]();
1020
+ }
1021
+ case "IEmpty": {
1022
+ return emptyArray[Symbol.iterator]();
1023
+ }
1024
+ default: {
1025
+ return toReadonlyArray(this)[Symbol.iterator]();
1026
+ }
1007
1027
  }
1008
- return void 0;
1028
+ },
1029
+ pipe() {
1030
+ return pipeArguments(this, arguments);
1009
1031
  }
1010
- return fromNullable(find(sourceFile));
1011
- }
1012
- function collectDescendantsAndAncestorsInRange(ts, sourceFile, textRange) {
1013
- const nodeAtPosition = findNodeAtPosition(ts, sourceFile, textRange.pos);
1014
- if (isNone2(nodeAtPosition)) return empty();
1015
- return collectSelfAndAncestorNodesInRange(nodeAtPosition.value, textRange);
1016
- }
1017
- function getSingleReturnEffectFromEffectGen(ts, typeChecker, node) {
1018
- const effectGenLike = effectGen(ts, typeChecker)(node);
1019
- if (isSome2(effectGenLike)) {
1020
- const body = effectGenLike.value.body;
1021
- if (body.statements.length === 1 && ts.isReturnStatement(body.statements[0]) && body.statements[0].expression && ts.isYieldExpression(body.statements[0].expression) && body.statements[0].expression.expression) {
1022
- const nodeToCheck = body.statements[0].expression.expression;
1023
- const type = typeChecker.getTypeAtLocation(nodeToCheck);
1024
- const maybeEffect = effectType(ts, typeChecker)(type, nodeToCheck);
1025
- if (isSome2(maybeEffect)) {
1026
- return some2(nodeToCheck);
1027
- }
1032
+ };
1033
+ var makeChunk = (backing) => {
1034
+ const chunk = Object.create(ChunkProto);
1035
+ chunk.backing = backing;
1036
+ switch (backing._tag) {
1037
+ case "IEmpty": {
1038
+ chunk.length = 0;
1039
+ chunk.depth = 0;
1040
+ chunk.left = chunk;
1041
+ chunk.right = chunk;
1042
+ break;
1043
+ }
1044
+ case "IConcat": {
1045
+ chunk.length = backing.left.length + backing.right.length;
1046
+ chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth);
1047
+ chunk.left = backing.left;
1048
+ chunk.right = backing.right;
1049
+ break;
1050
+ }
1051
+ case "IArray": {
1052
+ chunk.length = backing.array.length;
1053
+ chunk.depth = 0;
1054
+ chunk.left = _empty;
1055
+ chunk.right = _empty;
1056
+ break;
1057
+ }
1058
+ case "ISingleton": {
1059
+ chunk.length = 1;
1060
+ chunk.depth = 0;
1061
+ chunk.left = _empty;
1062
+ chunk.right = _empty;
1063
+ break;
1064
+ }
1065
+ case "ISlice": {
1066
+ chunk.length = backing.length;
1067
+ chunk.depth = backing.chunk.depth + 1;
1068
+ chunk.left = _empty;
1069
+ chunk.right = _empty;
1070
+ break;
1028
1071
  }
1029
1072
  }
1030
- return none2();
1031
- }
1032
- function toTextRange(positionOrRange) {
1033
- return typeof positionOrRange === "number" ? { end: positionOrRange, pos: positionOrRange } : positionOrRange;
1073
+ return chunk;
1074
+ };
1075
+ var isChunk = (u) => hasProperty(u, TypeId4);
1076
+ var _empty = /* @__PURE__ */ makeChunk({
1077
+ _tag: "IEmpty"
1078
+ });
1079
+ var empty2 = () => _empty;
1080
+ var make3 = (...as) => as.length === 1 ? of(as[0]) : unsafeFromNonEmptyArray(as);
1081
+ var of = (a) => makeChunk({
1082
+ _tag: "ISingleton",
1083
+ a
1084
+ });
1085
+ var fromIterable2 = (self) => isChunk(self) ? self : makeChunk({
1086
+ _tag: "IArray",
1087
+ array: fromIterable(self)
1088
+ });
1089
+ var copyToArray = (self, array3, initial) => {
1090
+ switch (self.backing._tag) {
1091
+ case "IArray": {
1092
+ copy(self.backing.array, 0, array3, initial, self.length);
1093
+ break;
1094
+ }
1095
+ case "IConcat": {
1096
+ copyToArray(self.left, array3, initial);
1097
+ copyToArray(self.right, array3, initial + self.left.length);
1098
+ break;
1099
+ }
1100
+ case "ISingleton": {
1101
+ array3[initial] = self.backing.a;
1102
+ break;
1103
+ }
1104
+ case "ISlice": {
1105
+ let i = 0;
1106
+ let j = initial;
1107
+ while (i < self.length) {
1108
+ array3[j] = unsafeGet2(self, i);
1109
+ i += 1;
1110
+ j += 1;
1111
+ }
1112
+ break;
1113
+ }
1114
+ }
1115
+ };
1116
+ var toReadonlyArray_ = (self) => {
1117
+ switch (self.backing._tag) {
1118
+ case "IEmpty": {
1119
+ return emptyArray;
1120
+ }
1121
+ case "IArray": {
1122
+ return self.backing.array;
1123
+ }
1124
+ default: {
1125
+ const arr = new Array(self.length);
1126
+ copyToArray(self, arr, 0);
1127
+ self.backing = {
1128
+ _tag: "IArray",
1129
+ array: arr
1130
+ };
1131
+ self.left = _empty;
1132
+ self.right = _empty;
1133
+ self.depth = 0;
1134
+ return arr;
1135
+ }
1136
+ }
1137
+ };
1138
+ var toReadonlyArray = toReadonlyArray_;
1139
+ var reverseChunk = (self) => {
1140
+ switch (self.backing._tag) {
1141
+ case "IEmpty":
1142
+ case "ISingleton":
1143
+ return self;
1144
+ case "IArray": {
1145
+ return makeChunk({
1146
+ _tag: "IArray",
1147
+ array: reverse(self.backing.array)
1148
+ });
1149
+ }
1150
+ case "IConcat": {
1151
+ return makeChunk({
1152
+ _tag: "IConcat",
1153
+ left: reverse2(self.backing.right),
1154
+ right: reverse2(self.backing.left)
1155
+ });
1156
+ }
1157
+ case "ISlice":
1158
+ return unsafeFromArray(reverse(toReadonlyArray(self)));
1159
+ }
1160
+ };
1161
+ var reverse2 = reverseChunk;
1162
+ var unsafeFromArray = (self) => makeChunk({
1163
+ _tag: "IArray",
1164
+ array: self
1165
+ });
1166
+ var unsafeFromNonEmptyArray = (self) => unsafeFromArray(self);
1167
+ var unsafeGet2 = /* @__PURE__ */ dual(2, (self, index) => {
1168
+ switch (self.backing._tag) {
1169
+ case "IEmpty": {
1170
+ throw new Error(`Index out of bounds`);
1171
+ }
1172
+ case "ISingleton": {
1173
+ if (index !== 0) {
1174
+ throw new Error(`Index out of bounds`);
1175
+ }
1176
+ return self.backing.a;
1177
+ }
1178
+ case "IArray": {
1179
+ if (index >= self.length || index < 0) {
1180
+ throw new Error(`Index out of bounds`);
1181
+ }
1182
+ return self.backing.array[index];
1183
+ }
1184
+ case "IConcat": {
1185
+ return index < self.left.length ? unsafeGet2(self.left, index) : unsafeGet2(self.right, index - self.left.length);
1186
+ }
1187
+ case "ISlice": {
1188
+ return unsafeGet2(self.backing.chunk, index + self.backing.offset);
1189
+ }
1190
+ }
1191
+ });
1192
+ var prepend = /* @__PURE__ */ dual(2, (self, elem) => appendAll(of(elem), self));
1193
+ var appendAll = /* @__PURE__ */ dual(2, (self, that) => {
1194
+ if (self.backing._tag === "IEmpty") {
1195
+ return that;
1196
+ }
1197
+ if (that.backing._tag === "IEmpty") {
1198
+ return self;
1199
+ }
1200
+ const diff = that.depth - self.depth;
1201
+ if (Math.abs(diff) <= 1) {
1202
+ return makeChunk({
1203
+ _tag: "IConcat",
1204
+ left: self,
1205
+ right: that
1206
+ });
1207
+ } else if (diff < -1) {
1208
+ if (self.left.depth >= self.right.depth) {
1209
+ const nr = appendAll(self.right, that);
1210
+ return makeChunk({
1211
+ _tag: "IConcat",
1212
+ left: self.left,
1213
+ right: nr
1214
+ });
1215
+ } else {
1216
+ const nrr = appendAll(self.right.right, that);
1217
+ if (nrr.depth === self.depth - 3) {
1218
+ const nr = makeChunk({
1219
+ _tag: "IConcat",
1220
+ left: self.right.left,
1221
+ right: nrr
1222
+ });
1223
+ return makeChunk({
1224
+ _tag: "IConcat",
1225
+ left: self.left,
1226
+ right: nr
1227
+ });
1228
+ } else {
1229
+ const nl = makeChunk({
1230
+ _tag: "IConcat",
1231
+ left: self.left,
1232
+ right: self.right.left
1233
+ });
1234
+ return makeChunk({
1235
+ _tag: "IConcat",
1236
+ left: nl,
1237
+ right: nrr
1238
+ });
1239
+ }
1240
+ }
1241
+ } else {
1242
+ if (that.right.depth >= that.left.depth) {
1243
+ const nl = appendAll(self, that.left);
1244
+ return makeChunk({
1245
+ _tag: "IConcat",
1246
+ left: nl,
1247
+ right: that.right
1248
+ });
1249
+ } else {
1250
+ const nll = appendAll(self, that.left.left);
1251
+ if (nll.depth === that.depth - 3) {
1252
+ const nl = makeChunk({
1253
+ _tag: "IConcat",
1254
+ left: nll,
1255
+ right: that.left.right
1256
+ });
1257
+ return makeChunk({
1258
+ _tag: "IConcat",
1259
+ left: nl,
1260
+ right: that.right
1261
+ });
1262
+ } else {
1263
+ const nr = makeChunk({
1264
+ _tag: "IConcat",
1265
+ left: that.left.right,
1266
+ right: that.right
1267
+ });
1268
+ return makeChunk({
1269
+ _tag: "IConcat",
1270
+ left: nll,
1271
+ right: nr
1272
+ });
1273
+ }
1274
+ }
1275
+ }
1276
+ });
1277
+ var isEmpty = (self) => self.length === 0;
1278
+ var isNonEmpty = (self) => self.length > 0;
1279
+ var unsafeHead = (self) => unsafeGet2(self, 0);
1280
+ var headNonEmpty2 = unsafeHead;
1281
+
1282
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/hashMap/config.js
1283
+ var SIZE = 5;
1284
+ var BUCKET_SIZE = /* @__PURE__ */ Math.pow(2, SIZE);
1285
+ var MASK = BUCKET_SIZE - 1;
1286
+ var MAX_INDEX_NODE = BUCKET_SIZE / 2;
1287
+ var MIN_ARRAY_NODE = BUCKET_SIZE / 4;
1288
+
1289
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/hashMap/bitwise.js
1290
+ function popcount(x) {
1291
+ x -= x >> 1 & 1431655765;
1292
+ x = (x & 858993459) + (x >> 2 & 858993459);
1293
+ x = x + (x >> 4) & 252645135;
1294
+ x += x >> 8;
1295
+ x += x >> 16;
1296
+ return x & 127;
1034
1297
  }
1035
- function isNodeInRange(textRange) {
1036
- return (node) => node.pos <= textRange.pos && node.end >= textRange.end;
1298
+ function hashFragment(shift, h) {
1299
+ return h >>> shift & MASK;
1037
1300
  }
1038
- function transformAsyncAwaitToEffectGen(ts) {
1039
- return (node, effectModuleName, onAwait) => {
1040
- function visitor(_) {
1041
- if (ts.isAwaitExpression(_)) {
1042
- const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext);
1043
- return ts.factory.createYieldExpression(
1044
- ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
1045
- onAwait(expression)
1046
- );
1301
+ function toBitmap(x) {
1302
+ return 1 << x;
1303
+ }
1304
+ function fromBitmap(bitmap, bit) {
1305
+ return popcount(bitmap & bit - 1);
1306
+ }
1307
+
1308
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/stack.js
1309
+ var make4 = (value, previous) => ({
1310
+ value,
1311
+ previous
1312
+ });
1313
+
1314
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/hashMap/array.js
1315
+ function arrayUpdate(mutate2, at, v, arr) {
1316
+ let out = arr;
1317
+ if (!mutate2) {
1318
+ const len = arr.length;
1319
+ out = new Array(len);
1320
+ for (let i = 0; i < len; ++i) out[i] = arr[i];
1321
+ }
1322
+ out[at] = v;
1323
+ return out;
1324
+ }
1325
+ function arraySpliceOut(mutate2, at, arr) {
1326
+ const newLen = arr.length - 1;
1327
+ let i = 0;
1328
+ let g = 0;
1329
+ let out = arr;
1330
+ if (mutate2) {
1331
+ i = g = at;
1332
+ } else {
1333
+ out = new Array(newLen);
1334
+ while (i < at) out[g++] = arr[i++];
1335
+ }
1336
+ ;
1337
+ ++i;
1338
+ while (i <= newLen) out[g++] = arr[i++];
1339
+ if (mutate2) {
1340
+ out.length = newLen;
1341
+ }
1342
+ return out;
1343
+ }
1344
+ function arraySpliceIn(mutate2, at, v, arr) {
1345
+ const len = arr.length;
1346
+ if (mutate2) {
1347
+ let i2 = len;
1348
+ while (i2 >= at) arr[i2--] = arr[i2];
1349
+ arr[at] = v;
1350
+ return arr;
1351
+ }
1352
+ let i = 0, g = 0;
1353
+ const out = new Array(len + 1);
1354
+ while (i < at) out[g++] = arr[i++];
1355
+ out[at] = v;
1356
+ while (i < len) out[++g] = arr[i++];
1357
+ return out;
1358
+ }
1359
+
1360
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/hashMap/node.js
1361
+ var EmptyNode = class _EmptyNode {
1362
+ _tag = "EmptyNode";
1363
+ modify(edit, _shift, f, hash2, key, size4) {
1364
+ const v = f(none2());
1365
+ if (isNone2(v)) return new _EmptyNode();
1366
+ ++size4.value;
1367
+ return new LeafNode(edit, hash2, key, v);
1368
+ }
1369
+ };
1370
+ function isEmptyNode(a) {
1371
+ return isTagged(a, "EmptyNode");
1372
+ }
1373
+ function isLeafNode(node) {
1374
+ return isEmptyNode(node) || node._tag === "LeafNode" || node._tag === "CollisionNode";
1375
+ }
1376
+ function canEditNode(node, edit) {
1377
+ return isEmptyNode(node) ? false : edit === node.edit;
1378
+ }
1379
+ var LeafNode = class _LeafNode {
1380
+ edit;
1381
+ hash;
1382
+ key;
1383
+ value;
1384
+ _tag = "LeafNode";
1385
+ constructor(edit, hash2, key, value) {
1386
+ this.edit = edit;
1387
+ this.hash = hash2;
1388
+ this.key = key;
1389
+ this.value = value;
1390
+ }
1391
+ modify(edit, shift, f, hash2, key, size4) {
1392
+ if (equals(key, this.key)) {
1393
+ const v2 = f(this.value);
1394
+ if (v2 === this.value) return this;
1395
+ else if (isNone2(v2)) {
1396
+ ;
1397
+ --size4.value;
1398
+ return new EmptyNode();
1047
1399
  }
1048
- return ts.visitEachChild(_, visitor, ts.nullTransformationContext);
1400
+ if (canEditNode(this, edit)) {
1401
+ this.value = v2;
1402
+ return this;
1403
+ }
1404
+ return new _LeafNode(edit, hash2, key, v2);
1049
1405
  }
1050
- const generatorBody = visitor(node.body);
1051
- const generator = ts.factory.createFunctionExpression(
1052
- void 0,
1053
- ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
1054
- void 0,
1055
- [],
1056
- [],
1057
- void 0,
1058
- generatorBody
1059
- // NOTE(mattia): intended, to use same routine for both ConciseBody and Body
1060
- );
1061
- const effectGenCallExp = ts.factory.createCallExpression(
1062
- ts.factory.createPropertyAccessExpression(
1063
- ts.factory.createIdentifier(effectModuleName),
1064
- "gen"
1065
- ),
1066
- void 0,
1067
- [generator]
1068
- );
1069
- let currentFlags = ts.getCombinedModifierFlags(node);
1070
- currentFlags &= ~ts.ModifierFlags.Async;
1071
- const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags);
1072
- if (ts.isArrowFunction(node)) {
1073
- return ts.factory.createArrowFunction(
1074
- newModifiers,
1075
- node.typeParameters,
1076
- node.parameters,
1077
- void 0,
1078
- node.equalsGreaterThanToken,
1079
- effectGenCallExp
1080
- );
1406
+ const v = f(none2());
1407
+ if (isNone2(v)) return this;
1408
+ ++size4.value;
1409
+ return mergeLeaves(edit, shift, this.hash, this, hash2, new _LeafNode(edit, hash2, key, v));
1410
+ }
1411
+ };
1412
+ var CollisionNode = class _CollisionNode {
1413
+ edit;
1414
+ hash;
1415
+ children;
1416
+ _tag = "CollisionNode";
1417
+ constructor(edit, hash2, children) {
1418
+ this.edit = edit;
1419
+ this.hash = hash2;
1420
+ this.children = children;
1421
+ }
1422
+ modify(edit, shift, f, hash2, key, size4) {
1423
+ if (hash2 === this.hash) {
1424
+ const canEdit = canEditNode(this, edit);
1425
+ const list = this.updateCollisionList(canEdit, edit, this.hash, this.children, f, key, size4);
1426
+ if (list === this.children) return this;
1427
+ return list.length > 1 ? new _CollisionNode(edit, this.hash, list) : list[0];
1081
1428
  }
1082
- const newBody = ts.factory.createBlock([
1083
- ts.factory.createReturnStatement(effectGenCallExp)
1084
- ]);
1085
- if (ts.isFunctionDeclaration(node)) {
1086
- return ts.factory.createFunctionDeclaration(
1087
- newModifiers,
1088
- node.asteriskToken,
1089
- node.name,
1090
- node.typeParameters,
1091
- node.parameters,
1092
- void 0,
1093
- newBody
1094
- );
1429
+ const v = f(none2());
1430
+ if (isNone2(v)) return this;
1431
+ ++size4.value;
1432
+ return mergeLeaves(edit, shift, this.hash, this, hash2, new LeafNode(edit, hash2, key, v));
1433
+ }
1434
+ updateCollisionList(mutate2, edit, hash2, list, f, key, size4) {
1435
+ const len = list.length;
1436
+ for (let i = 0; i < len; ++i) {
1437
+ const child = list[i];
1438
+ if ("key" in child && equals(key, child.key)) {
1439
+ const value = child.value;
1440
+ const newValue2 = f(value);
1441
+ if (newValue2 === value) return list;
1442
+ if (isNone2(newValue2)) {
1443
+ ;
1444
+ --size4.value;
1445
+ return arraySpliceOut(mutate2, i, list);
1446
+ }
1447
+ return arrayUpdate(mutate2, i, new LeafNode(edit, hash2, key, newValue2), list);
1448
+ }
1095
1449
  }
1096
- return ts.factory.createFunctionExpression(
1097
- newModifiers,
1098
- node.asteriskToken,
1099
- node.name,
1100
- node.typeParameters,
1101
- node.parameters,
1102
- void 0,
1103
- newBody
1104
- );
1105
- };
1450
+ const newValue = f(none2());
1451
+ if (isNone2(newValue)) return list;
1452
+ ++size4.value;
1453
+ return arrayUpdate(mutate2, len, new LeafNode(edit, hash2, key, newValue), list);
1454
+ }
1455
+ };
1456
+ var IndexedNode = class _IndexedNode {
1457
+ edit;
1458
+ mask;
1459
+ children;
1460
+ _tag = "IndexedNode";
1461
+ constructor(edit, mask, children) {
1462
+ this.edit = edit;
1463
+ this.mask = mask;
1464
+ this.children = children;
1465
+ }
1466
+ modify(edit, shift, f, hash2, key, size4) {
1467
+ const mask = this.mask;
1468
+ const children = this.children;
1469
+ const frag = hashFragment(shift, hash2);
1470
+ const bit = toBitmap(frag);
1471
+ const indx = fromBitmap(mask, bit);
1472
+ const exists = mask & bit;
1473
+ const canEdit = canEditNode(this, edit);
1474
+ if (!exists) {
1475
+ const _newChild = new EmptyNode().modify(edit, shift + SIZE, f, hash2, key, size4);
1476
+ if (!_newChild) return this;
1477
+ return children.length >= MAX_INDEX_NODE ? expand(edit, frag, _newChild, mask, children) : new _IndexedNode(edit, mask | bit, arraySpliceIn(canEdit, indx, _newChild, children));
1478
+ }
1479
+ const current = children[indx];
1480
+ const child = current.modify(edit, shift + SIZE, f, hash2, key, size4);
1481
+ if (current === child) return this;
1482
+ let bitmap = mask;
1483
+ let newChildren;
1484
+ if (isEmptyNode(child)) {
1485
+ bitmap &= ~bit;
1486
+ if (!bitmap) return new EmptyNode();
1487
+ if (children.length <= 2 && isLeafNode(children[indx ^ 1])) {
1488
+ return children[indx ^ 1];
1489
+ }
1490
+ newChildren = arraySpliceOut(canEdit, indx, children);
1491
+ } else {
1492
+ newChildren = arrayUpdate(canEdit, indx, child, children);
1493
+ }
1494
+ if (canEdit) {
1495
+ this.mask = bitmap;
1496
+ this.children = newChildren;
1497
+ return this;
1498
+ }
1499
+ return new _IndexedNode(edit, bitmap, newChildren);
1500
+ }
1501
+ };
1502
+ var ArrayNode = class _ArrayNode {
1503
+ edit;
1504
+ size;
1505
+ children;
1506
+ _tag = "ArrayNode";
1507
+ constructor(edit, size4, children) {
1508
+ this.edit = edit;
1509
+ this.size = size4;
1510
+ this.children = children;
1511
+ }
1512
+ modify(edit, shift, f, hash2, key, size4) {
1513
+ let count = this.size;
1514
+ const children = this.children;
1515
+ const frag = hashFragment(shift, hash2);
1516
+ const child = children[frag];
1517
+ const newChild = (child || new EmptyNode()).modify(edit, shift + SIZE, f, hash2, key, size4);
1518
+ if (child === newChild) return this;
1519
+ const canEdit = canEditNode(this, edit);
1520
+ let newChildren;
1521
+ if (isEmptyNode(child) && !isEmptyNode(newChild)) {
1522
+ ;
1523
+ ++count;
1524
+ newChildren = arrayUpdate(canEdit, frag, newChild, children);
1525
+ } else if (!isEmptyNode(child) && isEmptyNode(newChild)) {
1526
+ ;
1527
+ --count;
1528
+ if (count <= MIN_ARRAY_NODE) {
1529
+ return pack(edit, count, frag, children);
1530
+ }
1531
+ newChildren = arrayUpdate(canEdit, frag, new EmptyNode(), children);
1532
+ } else {
1533
+ newChildren = arrayUpdate(canEdit, frag, newChild, children);
1534
+ }
1535
+ if (canEdit) {
1536
+ this.size = count;
1537
+ this.children = newChildren;
1538
+ return this;
1539
+ }
1540
+ return new _ArrayNode(edit, count, newChildren);
1541
+ }
1542
+ };
1543
+ function pack(edit, count, removed, elements) {
1544
+ const children = new Array(count - 1);
1545
+ let g = 0;
1546
+ let bitmap = 0;
1547
+ for (let i = 0, len = elements.length; i < len; ++i) {
1548
+ if (i !== removed) {
1549
+ const elem = elements[i];
1550
+ if (elem && !isEmptyNode(elem)) {
1551
+ children[g++] = elem;
1552
+ bitmap |= 1 << i;
1553
+ }
1554
+ }
1555
+ }
1556
+ return new IndexedNode(edit, bitmap, children);
1106
1557
  }
1107
- function addReturnTypeAnnotation(ts, changes) {
1108
- return (sourceFile, declaration, typeNode) => {
1109
- const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
1110
- const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
1111
- const endNode = needParens ? declaration.parameters[0] : closeParen;
1112
- if (endNode) {
1113
- if (needParens) {
1114
- changes.insertNodeBefore(
1115
- sourceFile,
1116
- endNode,
1117
- ts.factory.createToken(ts.SyntaxKind.OpenParenToken)
1118
- );
1119
- changes.insertNodeAfter(
1120
- sourceFile,
1121
- endNode,
1122
- ts.factory.createToken(ts.SyntaxKind.CloseParenToken)
1123
- );
1558
+ function expand(edit, frag, child, bitmap, subNodes) {
1559
+ const arr = [];
1560
+ let bit = bitmap;
1561
+ let count = 0;
1562
+ for (let i = 0; bit; ++i) {
1563
+ if (bit & 1) arr[i] = subNodes[count++];
1564
+ bit >>>= 1;
1565
+ }
1566
+ arr[frag] = child;
1567
+ return new ArrayNode(edit, count + 1, arr);
1568
+ }
1569
+ function mergeLeavesInner(edit, shift, h1, n1, h2, n2) {
1570
+ if (h1 === h2) return new CollisionNode(edit, h1, [n2, n1]);
1571
+ const subH1 = hashFragment(shift, h1);
1572
+ const subH2 = hashFragment(shift, h2);
1573
+ if (subH1 === subH2) {
1574
+ return (child) => new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), [child]);
1575
+ } else {
1576
+ const children = subH1 < subH2 ? [n1, n2] : [n2, n1];
1577
+ return new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), children);
1578
+ }
1579
+ }
1580
+ function mergeLeaves(edit, shift, h1, n1, h2, n2) {
1581
+ let stack = void 0;
1582
+ let currentShift = shift;
1583
+ while (true) {
1584
+ const res = mergeLeavesInner(edit, currentShift, h1, n1, h2, n2);
1585
+ if (typeof res === "function") {
1586
+ stack = make4(res, stack);
1587
+ currentShift = currentShift + SIZE;
1588
+ } else {
1589
+ let final = res;
1590
+ while (stack != null) {
1591
+ final = stack.value(final);
1592
+ stack = stack.previous;
1124
1593
  }
1125
- changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: ": " });
1594
+ return final;
1595
+ }
1596
+ }
1597
+ }
1598
+
1599
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/hashMap.js
1600
+ var HashMapSymbolKey = "effect/HashMap";
1601
+ var HashMapTypeId = /* @__PURE__ */ Symbol.for(HashMapSymbolKey);
1602
+ var HashMapProto = {
1603
+ [HashMapTypeId]: HashMapTypeId,
1604
+ [Symbol.iterator]() {
1605
+ return new HashMapIterator(this, (k, v) => [k, v]);
1606
+ },
1607
+ [symbol]() {
1608
+ let hash2 = hash(HashMapSymbolKey);
1609
+ for (const item of this) {
1610
+ hash2 ^= pipe(hash(item[0]), combine(hash(item[1])));
1611
+ }
1612
+ return cached(this, hash2);
1613
+ },
1614
+ [symbol2](that) {
1615
+ if (isHashMap(that)) {
1616
+ if (that._size !== this._size) {
1617
+ return false;
1618
+ }
1619
+ for (const item of this) {
1620
+ const elem = pipe(that, getHash(item[0], hash(item[0])));
1621
+ if (isNone2(elem)) {
1622
+ return false;
1623
+ } else {
1624
+ if (!equals(item[1], elem.value)) {
1625
+ return false;
1626
+ }
1627
+ }
1628
+ }
1629
+ return true;
1630
+ }
1631
+ return false;
1632
+ },
1633
+ toString() {
1634
+ return format(this.toJSON());
1635
+ },
1636
+ toJSON() {
1637
+ return {
1638
+ _id: "HashMap",
1639
+ values: Array.from(this).map(toJSON)
1640
+ };
1641
+ },
1642
+ [NodeInspectSymbol]() {
1643
+ return this.toJSON();
1644
+ },
1645
+ pipe() {
1646
+ return pipeArguments(this, arguments);
1647
+ }
1648
+ };
1649
+ var makeImpl = (editable, edit, root, size4) => {
1650
+ const map8 = Object.create(HashMapProto);
1651
+ map8._editable = editable;
1652
+ map8._edit = edit;
1653
+ map8._root = root;
1654
+ map8._size = size4;
1655
+ return map8;
1656
+ };
1657
+ var HashMapIterator = class _HashMapIterator {
1658
+ map;
1659
+ f;
1660
+ v;
1661
+ constructor(map8, f) {
1662
+ this.map = map8;
1663
+ this.f = f;
1664
+ this.v = visitLazy(this.map._root, this.f, void 0);
1665
+ }
1666
+ next() {
1667
+ if (isNone2(this.v)) {
1668
+ return {
1669
+ done: true,
1670
+ value: void 0
1671
+ };
1672
+ }
1673
+ const v0 = this.v.value;
1674
+ this.v = applyCont(v0.cont);
1675
+ return {
1676
+ done: false,
1677
+ value: v0.value
1678
+ };
1679
+ }
1680
+ [Symbol.iterator]() {
1681
+ return new _HashMapIterator(this.map, this.f);
1682
+ }
1683
+ };
1684
+ var applyCont = (cont) => cont ? visitLazyChildren(cont[0], cont[1], cont[2], cont[3], cont[4]) : none2();
1685
+ var visitLazy = (node, f, cont = void 0) => {
1686
+ switch (node._tag) {
1687
+ case "LeafNode": {
1688
+ if (isSome2(node.value)) {
1689
+ return some2({
1690
+ value: f(node.key, node.value.value),
1691
+ cont
1692
+ });
1693
+ }
1694
+ return applyCont(cont);
1695
+ }
1696
+ case "CollisionNode":
1697
+ case "ArrayNode":
1698
+ case "IndexedNode": {
1699
+ const children = node.children;
1700
+ return visitLazyChildren(children.length, children, 0, f, cont);
1701
+ }
1702
+ default: {
1703
+ return applyCont(cont);
1704
+ }
1705
+ }
1706
+ };
1707
+ var visitLazyChildren = (len, children, i, f, cont) => {
1708
+ while (i < len) {
1709
+ const child = children[i++];
1710
+ if (child && !isEmptyNode(child)) {
1711
+ return visitLazy(child, f, [len, children, i, f, cont]);
1712
+ }
1713
+ }
1714
+ return applyCont(cont);
1715
+ };
1716
+ var _empty2 = /* @__PURE__ */ makeImpl(false, 0, /* @__PURE__ */ new EmptyNode(), 0);
1717
+ var empty3 = () => _empty2;
1718
+ var isHashMap = (u) => hasProperty(u, HashMapTypeId);
1719
+ var getHash = /* @__PURE__ */ dual(3, (self, key, hash2) => {
1720
+ let node = self._root;
1721
+ let shift = 0;
1722
+ while (true) {
1723
+ switch (node._tag) {
1724
+ case "LeafNode": {
1725
+ return equals(key, node.key) ? node.value : none2();
1726
+ }
1727
+ case "CollisionNode": {
1728
+ if (hash2 === node.hash) {
1729
+ const children = node.children;
1730
+ for (let i = 0, len = children.length; i < len; ++i) {
1731
+ const child = children[i];
1732
+ if ("key" in child && equals(key, child.key)) {
1733
+ return child.value;
1734
+ }
1735
+ }
1736
+ }
1737
+ return none2();
1738
+ }
1739
+ case "IndexedNode": {
1740
+ const frag = hashFragment(shift, hash2);
1741
+ const bit = toBitmap(frag);
1742
+ if (node.mask & bit) {
1743
+ node = node.children[fromBitmap(node.mask, bit)];
1744
+ shift += SIZE;
1745
+ break;
1746
+ }
1747
+ return none2();
1748
+ }
1749
+ case "ArrayNode": {
1750
+ node = node.children[hashFragment(shift, hash2)];
1751
+ if (node) {
1752
+ shift += SIZE;
1753
+ break;
1754
+ }
1755
+ return none2();
1756
+ }
1757
+ default:
1758
+ return none2();
1759
+ }
1760
+ }
1761
+ });
1762
+ var set = /* @__PURE__ */ dual(3, (self, key, value) => modifyAt(self, key, () => some2(value)));
1763
+ var setTree = /* @__PURE__ */ dual(3, (self, newRoot, newSize) => {
1764
+ if (self._editable) {
1765
+ ;
1766
+ self._root = newRoot;
1767
+ self._size = newSize;
1768
+ return self;
1769
+ }
1770
+ return newRoot === self._root ? self : makeImpl(self._editable, self._edit, newRoot, newSize);
1771
+ });
1772
+ var keys = (self) => new HashMapIterator(self, (key) => key);
1773
+ var size = (self) => self._size;
1774
+ var beginMutation = (self) => makeImpl(true, self._edit + 1, self._root, self._size);
1775
+ var modifyAt = /* @__PURE__ */ dual(3, (self, key, f) => modifyHash(self, key, hash(key), f));
1776
+ var modifyHash = /* @__PURE__ */ dual(4, (self, key, hash2, f) => {
1777
+ const size4 = {
1778
+ value: self._size
1779
+ };
1780
+ const newRoot = self._root.modify(self._editable ? self._edit : NaN, 0, f, hash2, key, size4);
1781
+ return pipe(self, setTree(newRoot, size4.value));
1782
+ });
1783
+ var forEach = /* @__PURE__ */ dual(2, (self, f) => reduce2(self, void 0, (_, value, key) => f(value, key)));
1784
+ var reduce2 = /* @__PURE__ */ dual(3, (self, zero, f) => {
1785
+ const root = self._root;
1786
+ if (root._tag === "LeafNode") {
1787
+ return isSome2(root.value) ? f(zero, root.value.value, root.key) : zero;
1788
+ }
1789
+ if (root._tag === "EmptyNode") {
1790
+ return zero;
1791
+ }
1792
+ const toVisit = [root.children];
1793
+ let children;
1794
+ while (children = toVisit.pop()) {
1795
+ for (let i = 0, len = children.length; i < len; ) {
1796
+ const child = children[i++];
1797
+ if (child && !isEmptyNode(child)) {
1798
+ if (child._tag === "LeafNode") {
1799
+ if (isSome2(child.value)) {
1800
+ zero = f(zero, child.value.value, child.key);
1801
+ }
1802
+ } else {
1803
+ toVisit.push(child.children);
1804
+ }
1805
+ }
1806
+ }
1807
+ }
1808
+ return zero;
1809
+ });
1810
+
1811
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/hashSet.js
1812
+ var HashSetSymbolKey = "effect/HashSet";
1813
+ var HashSetTypeId = /* @__PURE__ */ Symbol.for(HashSetSymbolKey);
1814
+ var HashSetProto = {
1815
+ [HashSetTypeId]: HashSetTypeId,
1816
+ [Symbol.iterator]() {
1817
+ return keys(this._keyMap);
1818
+ },
1819
+ [symbol]() {
1820
+ return cached(this, combine(hash(this._keyMap))(hash(HashSetSymbolKey)));
1821
+ },
1822
+ [symbol2](that) {
1823
+ if (isHashSet(that)) {
1824
+ return size(this._keyMap) === size(that._keyMap) && equals(this._keyMap, that._keyMap);
1825
+ }
1826
+ return false;
1827
+ },
1828
+ toString() {
1829
+ return format(this.toJSON());
1830
+ },
1831
+ toJSON() {
1832
+ return {
1833
+ _id: "HashSet",
1834
+ values: Array.from(this).map(toJSON)
1835
+ };
1836
+ },
1837
+ [NodeInspectSymbol]() {
1838
+ return this.toJSON();
1839
+ },
1840
+ pipe() {
1841
+ return pipeArguments(this, arguments);
1842
+ }
1843
+ };
1844
+ var makeImpl2 = (keyMap) => {
1845
+ const set2 = Object.create(HashSetProto);
1846
+ set2._keyMap = keyMap;
1847
+ return set2;
1848
+ };
1849
+ var isHashSet = (u) => hasProperty(u, HashSetTypeId);
1850
+ var _empty3 = /* @__PURE__ */ makeImpl2(/* @__PURE__ */ empty3());
1851
+ var empty4 = () => _empty3;
1852
+ var size2 = (self) => size(self._keyMap);
1853
+ var beginMutation2 = (self) => makeImpl2(beginMutation(self._keyMap));
1854
+ var endMutation = (self) => {
1855
+ ;
1856
+ self._keyMap._editable = false;
1857
+ return self;
1858
+ };
1859
+ var mutate = /* @__PURE__ */ dual(2, (self, f) => {
1860
+ const transient = beginMutation2(self);
1861
+ f(transient);
1862
+ return endMutation(transient);
1863
+ });
1864
+ var add = /* @__PURE__ */ dual(2, (self, value) => self._keyMap._editable ? (set(value, true)(self._keyMap), self) : makeImpl2(set(value, true)(self._keyMap)));
1865
+ var union2 = /* @__PURE__ */ dual(2, (self, that) => mutate(empty4(), (set2) => {
1866
+ forEach2(self, (value) => add(set2, value));
1867
+ for (const value of that) {
1868
+ add(set2, value);
1869
+ }
1870
+ }));
1871
+ var forEach2 = /* @__PURE__ */ dual(2, (self, f) => forEach(self._keyMap, (_, k) => f(k)));
1872
+
1873
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/HashSet.js
1874
+ var empty5 = empty4;
1875
+ var size3 = size2;
1876
+ var add2 = add;
1877
+ var union3 = union2;
1878
+
1879
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/opCodes/cause.js
1880
+ var OP_DIE = "Die";
1881
+ var OP_EMPTY = "Empty";
1882
+ var OP_FAIL = "Fail";
1883
+ var OP_INTERRUPT = "Interrupt";
1884
+ var OP_PARALLEL = "Parallel";
1885
+ var OP_SEQUENTIAL = "Sequential";
1886
+
1887
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/cause.js
1888
+ var CauseSymbolKey = "effect/Cause";
1889
+ var CauseTypeId = /* @__PURE__ */ Symbol.for(CauseSymbolKey);
1890
+ var variance = {
1891
+ /* c8 ignore next */
1892
+ _E: (_) => _
1893
+ };
1894
+ var proto = {
1895
+ [CauseTypeId]: variance,
1896
+ [symbol]() {
1897
+ return pipe(hash(CauseSymbolKey), combine(hash(flattenCause(this))), cached(this));
1898
+ },
1899
+ [symbol2](that) {
1900
+ return isCause(that) && causeEquals(this, that);
1901
+ },
1902
+ pipe() {
1903
+ return pipeArguments(this, arguments);
1904
+ },
1905
+ toJSON() {
1906
+ switch (this._tag) {
1907
+ case "Empty":
1908
+ return {
1909
+ _id: "Cause",
1910
+ _tag: this._tag
1911
+ };
1912
+ case "Die":
1913
+ return {
1914
+ _id: "Cause",
1915
+ _tag: this._tag,
1916
+ defect: toJSON(this.defect)
1917
+ };
1918
+ case "Interrupt":
1919
+ return {
1920
+ _id: "Cause",
1921
+ _tag: this._tag,
1922
+ fiberId: this.fiberId.toJSON()
1923
+ };
1924
+ case "Fail":
1925
+ return {
1926
+ _id: "Cause",
1927
+ _tag: this._tag,
1928
+ failure: toJSON(this.error)
1929
+ };
1930
+ case "Sequential":
1931
+ case "Parallel":
1932
+ return {
1933
+ _id: "Cause",
1934
+ _tag: this._tag,
1935
+ left: toJSON(this.left),
1936
+ right: toJSON(this.right)
1937
+ };
1938
+ }
1939
+ },
1940
+ toString() {
1941
+ return pretty(this);
1942
+ },
1943
+ [NodeInspectSymbol]() {
1944
+ return this.toJSON();
1945
+ }
1946
+ };
1947
+ var fail = (error) => {
1948
+ const o = Object.create(proto);
1949
+ o._tag = OP_FAIL;
1950
+ o.error = error;
1951
+ return o;
1952
+ };
1953
+ var parallel = (left3, right3) => {
1954
+ const o = Object.create(proto);
1955
+ o._tag = OP_PARALLEL;
1956
+ o.left = left3;
1957
+ o.right = right3;
1958
+ return o;
1959
+ };
1960
+ var sequential = (left3, right3) => {
1961
+ const o = Object.create(proto);
1962
+ o._tag = OP_SEQUENTIAL;
1963
+ o.left = left3;
1964
+ o.right = right3;
1965
+ return o;
1966
+ };
1967
+ var isCause = (u) => hasProperty(u, CauseTypeId);
1968
+ var isInterruptedOnly = (self) => reduceWithContext(void 0, IsInterruptedOnlyCauseReducer)(self);
1969
+ var causeEquals = (left3, right3) => {
1970
+ let leftStack = of(left3);
1971
+ let rightStack = of(right3);
1972
+ while (isNonEmpty(leftStack) && isNonEmpty(rightStack)) {
1973
+ const [leftParallel, leftSequential] = pipe(headNonEmpty2(leftStack), reduce4([empty5(), empty2()], ([parallel2, sequential2], cause) => {
1974
+ const [par, seq] = evaluateCause(cause);
1975
+ return some2([pipe(parallel2, union3(par)), pipe(sequential2, appendAll(seq))]);
1976
+ }));
1977
+ const [rightParallel, rightSequential] = pipe(headNonEmpty2(rightStack), reduce4([empty5(), empty2()], ([parallel2, sequential2], cause) => {
1978
+ const [par, seq] = evaluateCause(cause);
1979
+ return some2([pipe(parallel2, union3(par)), pipe(sequential2, appendAll(seq))]);
1980
+ }));
1981
+ if (!equals(leftParallel, rightParallel)) {
1982
+ return false;
1983
+ }
1984
+ leftStack = leftSequential;
1985
+ rightStack = rightSequential;
1986
+ }
1987
+ return true;
1988
+ };
1989
+ var flattenCause = (cause) => {
1990
+ return flattenCauseLoop(of(cause), empty2());
1991
+ };
1992
+ var flattenCauseLoop = (causes, flattened) => {
1993
+ while (1) {
1994
+ const [parallel2, sequential2] = pipe(causes, reduce([empty5(), empty2()], ([parallel3, sequential3], cause) => {
1995
+ const [par, seq] = evaluateCause(cause);
1996
+ return [pipe(parallel3, union3(par)), pipe(sequential3, appendAll(seq))];
1997
+ }));
1998
+ const updated = size3(parallel2) > 0 ? pipe(flattened, prepend(parallel2)) : flattened;
1999
+ if (isEmpty(sequential2)) {
2000
+ return reverse2(updated);
2001
+ }
2002
+ causes = sequential2;
2003
+ flattened = updated;
2004
+ }
2005
+ throw new Error(getBugErrorMessage("Cause.flattenCauseLoop"));
2006
+ };
2007
+ var evaluateCause = (self) => {
2008
+ let cause = self;
2009
+ const stack = [];
2010
+ let _parallel = empty5();
2011
+ let _sequential = empty2();
2012
+ while (cause !== void 0) {
2013
+ switch (cause._tag) {
2014
+ case OP_EMPTY: {
2015
+ if (stack.length === 0) {
2016
+ return [_parallel, _sequential];
2017
+ }
2018
+ cause = stack.pop();
2019
+ break;
2020
+ }
2021
+ case OP_FAIL: {
2022
+ _parallel = add2(_parallel, make3(cause._tag, cause.error));
2023
+ if (stack.length === 0) {
2024
+ return [_parallel, _sequential];
2025
+ }
2026
+ cause = stack.pop();
2027
+ break;
2028
+ }
2029
+ case OP_DIE: {
2030
+ _parallel = add2(_parallel, make3(cause._tag, cause.defect));
2031
+ if (stack.length === 0) {
2032
+ return [_parallel, _sequential];
2033
+ }
2034
+ cause = stack.pop();
2035
+ break;
2036
+ }
2037
+ case OP_INTERRUPT: {
2038
+ _parallel = add2(_parallel, make3(cause._tag, cause.fiberId));
2039
+ if (stack.length === 0) {
2040
+ return [_parallel, _sequential];
2041
+ }
2042
+ cause = stack.pop();
2043
+ break;
2044
+ }
2045
+ case OP_SEQUENTIAL: {
2046
+ switch (cause.left._tag) {
2047
+ case OP_EMPTY: {
2048
+ cause = cause.right;
2049
+ break;
2050
+ }
2051
+ case OP_SEQUENTIAL: {
2052
+ cause = sequential(cause.left.left, sequential(cause.left.right, cause.right));
2053
+ break;
2054
+ }
2055
+ case OP_PARALLEL: {
2056
+ cause = parallel(sequential(cause.left.left, cause.right), sequential(cause.left.right, cause.right));
2057
+ break;
2058
+ }
2059
+ default: {
2060
+ _sequential = prepend(_sequential, cause.right);
2061
+ cause = cause.left;
2062
+ break;
2063
+ }
2064
+ }
2065
+ break;
2066
+ }
2067
+ case OP_PARALLEL: {
2068
+ stack.push(cause.right);
2069
+ cause = cause.left;
2070
+ break;
2071
+ }
2072
+ }
2073
+ }
2074
+ throw new Error(getBugErrorMessage("Cause.evaluateCauseLoop"));
2075
+ };
2076
+ var IsInterruptedOnlyCauseReducer = {
2077
+ emptyCase: constTrue,
2078
+ failCase: constFalse,
2079
+ dieCase: constFalse,
2080
+ interruptCase: constTrue,
2081
+ sequentialCase: (_, left3, right3) => left3 && right3,
2082
+ parallelCase: (_, left3, right3) => left3 && right3
2083
+ };
2084
+ var OP_SEQUENTIAL_CASE = "SequentialCase";
2085
+ var OP_PARALLEL_CASE = "ParallelCase";
2086
+ var reduce4 = /* @__PURE__ */ dual(3, (self, zero, pf) => {
2087
+ let accumulator = zero;
2088
+ let cause = self;
2089
+ const causes = [];
2090
+ while (cause !== void 0) {
2091
+ const option2 = pf(accumulator, cause);
2092
+ accumulator = isSome2(option2) ? option2.value : accumulator;
2093
+ switch (cause._tag) {
2094
+ case OP_SEQUENTIAL: {
2095
+ causes.push(cause.right);
2096
+ cause = cause.left;
2097
+ break;
2098
+ }
2099
+ case OP_PARALLEL: {
2100
+ causes.push(cause.right);
2101
+ cause = cause.left;
2102
+ break;
2103
+ }
2104
+ default: {
2105
+ cause = void 0;
2106
+ break;
2107
+ }
2108
+ }
2109
+ if (cause === void 0 && causes.length > 0) {
2110
+ cause = causes.pop();
2111
+ }
2112
+ }
2113
+ return accumulator;
2114
+ });
2115
+ var reduceWithContext = /* @__PURE__ */ dual(3, (self, context, reducer) => {
2116
+ const input = [self];
2117
+ const output = [];
2118
+ while (input.length > 0) {
2119
+ const cause = input.pop();
2120
+ switch (cause._tag) {
2121
+ case OP_EMPTY: {
2122
+ output.push(right2(reducer.emptyCase(context)));
2123
+ break;
2124
+ }
2125
+ case OP_FAIL: {
2126
+ output.push(right2(reducer.failCase(context, cause.error)));
2127
+ break;
2128
+ }
2129
+ case OP_DIE: {
2130
+ output.push(right2(reducer.dieCase(context, cause.defect)));
2131
+ break;
2132
+ }
2133
+ case OP_INTERRUPT: {
2134
+ output.push(right2(reducer.interruptCase(context, cause.fiberId)));
2135
+ break;
2136
+ }
2137
+ case OP_SEQUENTIAL: {
2138
+ input.push(cause.right);
2139
+ input.push(cause.left);
2140
+ output.push(left2({
2141
+ _tag: OP_SEQUENTIAL_CASE
2142
+ }));
2143
+ break;
2144
+ }
2145
+ case OP_PARALLEL: {
2146
+ input.push(cause.right);
2147
+ input.push(cause.left);
2148
+ output.push(left2({
2149
+ _tag: OP_PARALLEL_CASE
2150
+ }));
2151
+ break;
2152
+ }
2153
+ }
2154
+ }
2155
+ const accumulator = [];
2156
+ while (output.length > 0) {
2157
+ const either = output.pop();
2158
+ switch (either._tag) {
2159
+ case "Left": {
2160
+ switch (either.left._tag) {
2161
+ case OP_SEQUENTIAL_CASE: {
2162
+ const left3 = accumulator.pop();
2163
+ const right3 = accumulator.pop();
2164
+ const value = reducer.sequentialCase(context, left3, right3);
2165
+ accumulator.push(value);
2166
+ break;
2167
+ }
2168
+ case OP_PARALLEL_CASE: {
2169
+ const left3 = accumulator.pop();
2170
+ const right3 = accumulator.pop();
2171
+ const value = reducer.parallelCase(context, left3, right3);
2172
+ accumulator.push(value);
2173
+ break;
2174
+ }
2175
+ }
2176
+ break;
2177
+ }
2178
+ case "Right": {
2179
+ accumulator.push(either.right);
2180
+ break;
2181
+ }
2182
+ }
2183
+ }
2184
+ if (accumulator.length === 0) {
2185
+ throw new Error("BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues");
2186
+ }
2187
+ return accumulator.pop();
2188
+ });
2189
+ var pretty = (cause, options) => {
2190
+ if (isInterruptedOnly(cause)) {
2191
+ return "All fibers interrupted without errors.";
2192
+ }
2193
+ return prettyErrors(cause).map(function(e) {
2194
+ if (options?.renderErrorCause !== true || e.cause === void 0) {
2195
+ return e.stack;
2196
+ }
2197
+ return `${e.stack} {
2198
+ ${renderErrorCause(e.cause, " ")}
2199
+ }`;
2200
+ }).join("\n");
2201
+ };
2202
+ var renderErrorCause = (cause, prefix) => {
2203
+ const lines = cause.stack.split("\n");
2204
+ let stack = `${prefix}[cause]: ${lines[0]}`;
2205
+ for (let i = 1, len = lines.length; i < len; i++) {
2206
+ stack += `
2207
+ ${prefix}${lines[i]}`;
2208
+ }
2209
+ if (cause.cause) {
2210
+ stack += ` {
2211
+ ${renderErrorCause(cause.cause, `${prefix} `)}
2212
+ ${prefix}}`;
2213
+ }
2214
+ return stack;
2215
+ };
2216
+ var PrettyError = class _PrettyError extends globalThis.Error {
2217
+ span = void 0;
2218
+ constructor(originalError) {
2219
+ const originalErrorIsObject = typeof originalError === "object" && originalError !== null;
2220
+ const prevLimit = Error.stackTraceLimit;
2221
+ Error.stackTraceLimit = 1;
2222
+ super(prettyErrorMessage(originalError), originalErrorIsObject && "cause" in originalError && typeof originalError.cause !== "undefined" ? {
2223
+ cause: new _PrettyError(originalError.cause)
2224
+ } : void 0);
2225
+ if (this.message === "") {
2226
+ this.message = "An error has occurred";
2227
+ }
2228
+ Error.stackTraceLimit = prevLimit;
2229
+ this.name = originalError instanceof Error ? originalError.name : "Error";
2230
+ if (originalErrorIsObject) {
2231
+ if (spanSymbol in originalError) {
2232
+ this.span = originalError[spanSymbol];
2233
+ }
2234
+ Object.keys(originalError).forEach((key) => {
2235
+ if (!(key in this)) {
2236
+ this[key] = originalError[key];
2237
+ }
2238
+ });
2239
+ }
2240
+ this.stack = prettyErrorStack(`${this.name}: ${this.message}`, originalError instanceof Error && originalError.stack ? originalError.stack : "", this.span);
2241
+ }
2242
+ };
2243
+ var prettyErrorMessage = (u) => {
2244
+ if (typeof u === "string") {
2245
+ return u;
2246
+ }
2247
+ if (typeof u === "object" && u !== null && u instanceof Error) {
2248
+ return u.message;
2249
+ }
2250
+ try {
2251
+ if (hasProperty(u, "toString") && isFunction2(u["toString"]) && u["toString"] !== Object.prototype.toString && u["toString"] !== globalThis.Array.prototype.toString) {
2252
+ return u["toString"]();
2253
+ }
2254
+ } catch {
2255
+ }
2256
+ return stringifyCircular(u);
2257
+ };
2258
+ var locationRegex = /\((.*)\)/g;
2259
+ var spanToTrace = /* @__PURE__ */ globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
2260
+ var prettyErrorStack = (message, stack, span) => {
2261
+ const out = [message];
2262
+ const lines = stack.startsWith(message) ? stack.slice(message.length).split("\n") : stack.split("\n");
2263
+ for (let i = 1; i < lines.length; i++) {
2264
+ if (lines[i].includes("Generator.next")) {
2265
+ break;
2266
+ }
2267
+ if (lines[i].includes("effect_internal_function")) {
2268
+ out.pop();
2269
+ break;
2270
+ }
2271
+ out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>"));
2272
+ }
2273
+ if (span) {
2274
+ let current = span;
2275
+ let i = 0;
2276
+ while (current && current._tag === "Span" && i < 10) {
2277
+ const stackFn = spanToTrace.get(current);
2278
+ if (typeof stackFn === "function") {
2279
+ const stack2 = stackFn();
2280
+ if (typeof stack2 === "string") {
2281
+ const locationMatchAll = stack2.matchAll(locationRegex);
2282
+ let match3 = false;
2283
+ for (const [, location] of locationMatchAll) {
2284
+ match3 = true;
2285
+ out.push(` at ${current.name} (${location})`);
2286
+ }
2287
+ if (!match3) {
2288
+ out.push(` at ${current.name} (${stack2.replace(/^at /, "")})`);
2289
+ }
2290
+ } else {
2291
+ out.push(` at ${current.name}`);
2292
+ }
2293
+ } else {
2294
+ out.push(` at ${current.name}`);
2295
+ }
2296
+ current = getOrUndefined2(current.parent);
2297
+ i++;
2298
+ }
2299
+ }
2300
+ return out.join("\n");
2301
+ };
2302
+ var spanSymbol = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation");
2303
+ var prettyErrors = (cause) => reduceWithContext(cause, void 0, {
2304
+ emptyCase: () => [],
2305
+ dieCase: (_, unknownError) => {
2306
+ return [new PrettyError(unknownError)];
2307
+ },
2308
+ failCase: (_, error) => {
2309
+ return [new PrettyError(error)];
2310
+ },
2311
+ interruptCase: () => [],
2312
+ parallelCase: (_, l, r) => [...l, ...r],
2313
+ sequentialCase: (_, l, r) => [...l, ...r]
2314
+ });
2315
+
2316
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/singleShotGen.js
2317
+ var SingleShotGen2 = class _SingleShotGen {
2318
+ self;
2319
+ called = false;
2320
+ constructor(self) {
2321
+ this.self = self;
2322
+ }
2323
+ next(a) {
2324
+ return this.called ? {
2325
+ value: a,
2326
+ done: true
2327
+ } : (this.called = true, {
2328
+ value: this.self,
2329
+ done: false
2330
+ });
2331
+ }
2332
+ return(a) {
2333
+ return {
2334
+ value: a,
2335
+ done: true
2336
+ };
2337
+ }
2338
+ throw(e) {
2339
+ throw e;
2340
+ }
2341
+ [Symbol.iterator]() {
2342
+ return new _SingleShotGen(this.self);
2343
+ }
2344
+ };
2345
+
2346
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/core.js
2347
+ var EffectTypeId2 = /* @__PURE__ */ Symbol.for("effect/Effect");
2348
+ var EffectPrimitive = class {
2349
+ _op;
2350
+ effect_instruction_i0 = void 0;
2351
+ effect_instruction_i1 = void 0;
2352
+ effect_instruction_i2 = void 0;
2353
+ trace = void 0;
2354
+ [EffectTypeId2] = effectVariance;
2355
+ constructor(_op) {
2356
+ this._op = _op;
2357
+ }
2358
+ [symbol2](that) {
2359
+ return this === that;
2360
+ }
2361
+ [symbol]() {
2362
+ return cached(this, random(this));
2363
+ }
2364
+ pipe() {
2365
+ return pipeArguments(this, arguments);
2366
+ }
2367
+ toJSON() {
2368
+ return {
2369
+ _id: "Effect",
2370
+ _op: this._op,
2371
+ effect_instruction_i0: toJSON(this.effect_instruction_i0),
2372
+ effect_instruction_i1: toJSON(this.effect_instruction_i1),
2373
+ effect_instruction_i2: toJSON(this.effect_instruction_i2)
2374
+ };
2375
+ }
2376
+ toString() {
2377
+ return format(this.toJSON());
2378
+ }
2379
+ [NodeInspectSymbol]() {
2380
+ return this.toJSON();
2381
+ }
2382
+ [Symbol.iterator]() {
2383
+ return new SingleShotGen2(new YieldWrap(this));
2384
+ }
2385
+ };
2386
+ var EffectPrimitiveFailure = class {
2387
+ _op;
2388
+ effect_instruction_i0 = void 0;
2389
+ effect_instruction_i1 = void 0;
2390
+ effect_instruction_i2 = void 0;
2391
+ trace = void 0;
2392
+ [EffectTypeId2] = effectVariance;
2393
+ constructor(_op) {
2394
+ this._op = _op;
2395
+ this._tag = _op;
2396
+ }
2397
+ [symbol2](that) {
2398
+ return exitIsExit(that) && that._op === "Failure" && // @ts-expect-error
2399
+ equals(this.effect_instruction_i0, that.effect_instruction_i0);
2400
+ }
2401
+ [symbol]() {
2402
+ return pipe(
2403
+ // @ts-expect-error
2404
+ string(this._tag),
2405
+ // @ts-expect-error
2406
+ combine(hash(this.effect_instruction_i0)),
2407
+ cached(this)
2408
+ );
2409
+ }
2410
+ get cause() {
2411
+ return this.effect_instruction_i0;
2412
+ }
2413
+ pipe() {
2414
+ return pipeArguments(this, arguments);
2415
+ }
2416
+ toJSON() {
2417
+ return {
2418
+ _id: "Exit",
2419
+ _tag: this._op,
2420
+ cause: this.cause.toJSON()
2421
+ };
2422
+ }
2423
+ toString() {
2424
+ return format(this.toJSON());
2425
+ }
2426
+ [NodeInspectSymbol]() {
2427
+ return this.toJSON();
2428
+ }
2429
+ [Symbol.iterator]() {
2430
+ return new SingleShotGen2(new YieldWrap(this));
2431
+ }
2432
+ };
2433
+ var EffectPrimitiveSuccess = class {
2434
+ _op;
2435
+ effect_instruction_i0 = void 0;
2436
+ effect_instruction_i1 = void 0;
2437
+ effect_instruction_i2 = void 0;
2438
+ trace = void 0;
2439
+ [EffectTypeId2] = effectVariance;
2440
+ constructor(_op) {
2441
+ this._op = _op;
2442
+ this._tag = _op;
2443
+ }
2444
+ [symbol2](that) {
2445
+ return exitIsExit(that) && that._op === "Success" && // @ts-expect-error
2446
+ equals(this.effect_instruction_i0, that.effect_instruction_i0);
2447
+ }
2448
+ [symbol]() {
2449
+ return pipe(
2450
+ // @ts-expect-error
2451
+ string(this._tag),
2452
+ // @ts-expect-error
2453
+ combine(hash(this.effect_instruction_i0)),
2454
+ cached(this)
2455
+ );
2456
+ }
2457
+ get value() {
2458
+ return this.effect_instruction_i0;
2459
+ }
2460
+ pipe() {
2461
+ return pipeArguments(this, arguments);
2462
+ }
2463
+ toJSON() {
2464
+ return {
2465
+ _id: "Exit",
2466
+ _tag: this._op,
2467
+ value: toJSON(this.value)
2468
+ };
2469
+ }
2470
+ toString() {
2471
+ return format(this.toJSON());
2472
+ }
2473
+ [NodeInspectSymbol]() {
2474
+ return this.toJSON();
2475
+ }
2476
+ [Symbol.iterator]() {
2477
+ return new SingleShotGen2(new YieldWrap(this));
2478
+ }
2479
+ };
2480
+ var isEffect = (u) => hasProperty(u, EffectTypeId2);
2481
+ var withFiberRuntime = (withRuntime) => {
2482
+ const effect = new EffectPrimitive(OP_WITH_RUNTIME);
2483
+ effect.effect_instruction_i0 = withRuntime;
2484
+ return effect;
2485
+ };
2486
+ var spanSymbol2 = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation");
2487
+ var originalSymbol = /* @__PURE__ */ Symbol.for("effect/OriginalAnnotation");
2488
+ var capture = (obj, span) => {
2489
+ if (isSome2(span)) {
2490
+ return new Proxy(obj, {
2491
+ has(target, p) {
2492
+ return p === spanSymbol2 || p === originalSymbol || p in target;
2493
+ },
2494
+ get(target, p) {
2495
+ if (p === spanSymbol2) {
2496
+ return span.value;
2497
+ }
2498
+ if (p === originalSymbol) {
2499
+ return obj;
2500
+ }
2501
+ return target[p];
2502
+ }
2503
+ });
2504
+ }
2505
+ return obj;
2506
+ };
2507
+ var fail2 = (error) => isObject(error) && !(spanSymbol2 in error) ? withFiberRuntime((fiber) => failCause(fail(capture(error, currentSpanFromFiber(fiber))))) : failCause(fail(error));
2508
+ var failCause = (cause) => {
2509
+ const effect = new EffectPrimitiveFailure(OP_FAILURE);
2510
+ effect.effect_instruction_i0 = cause;
2511
+ return effect;
2512
+ };
2513
+ var logLevelAll = {
2514
+ _tag: "All",
2515
+ syslog: 0,
2516
+ label: "ALL",
2517
+ ordinal: Number.MIN_SAFE_INTEGER,
2518
+ pipe() {
2519
+ return pipeArguments(this, arguments);
2520
+ }
2521
+ };
2522
+ var logLevelNone = {
2523
+ _tag: "None",
2524
+ syslog: 7,
2525
+ label: "OFF",
2526
+ ordinal: Number.MAX_SAFE_INTEGER,
2527
+ pipe() {
2528
+ return pipeArguments(this, arguments);
2529
+ }
2530
+ };
2531
+ var RequestResolverSymbolKey = "effect/RequestResolver";
2532
+ var RequestResolverTypeId = /* @__PURE__ */ Symbol.for(RequestResolverSymbolKey);
2533
+ var requestResolverVariance = {
2534
+ /* c8 ignore next */
2535
+ _A: (_) => _,
2536
+ /* c8 ignore next */
2537
+ _R: (_) => _
2538
+ };
2539
+ var RequestResolverImpl = class _RequestResolverImpl {
2540
+ runAll;
2541
+ target;
2542
+ [RequestResolverTypeId] = requestResolverVariance;
2543
+ constructor(runAll, target) {
2544
+ this.runAll = runAll;
2545
+ this.target = target;
2546
+ }
2547
+ [symbol]() {
2548
+ return cached(this, this.target ? hash(this.target) : random(this));
2549
+ }
2550
+ [symbol2](that) {
2551
+ return this.target ? isRequestResolver(that) && equals(this.target, that.target) : this === that;
2552
+ }
2553
+ identified(...ids) {
2554
+ return new _RequestResolverImpl(this.runAll, fromIterable2(ids));
2555
+ }
2556
+ pipe() {
2557
+ return pipeArguments(this, arguments);
2558
+ }
2559
+ };
2560
+ var isRequestResolver = (u) => hasProperty(u, RequestResolverTypeId);
2561
+ var YieldableError = /* @__PURE__ */ function() {
2562
+ class YieldableError2 extends globalThis.Error {
2563
+ commit() {
2564
+ return fail2(this);
1126
2565
  }
1127
- };
1128
- }
1129
- function removeReturnTypeAnnotation(ts, changes) {
1130
- return (sourceFile, declaration) => {
1131
- const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
1132
- const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
1133
- const endNode = needParens ? declaration.parameters[0] : closeParen;
1134
- if (endNode && declaration.type) {
1135
- changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end });
2566
+ toJSON() {
2567
+ return {
2568
+ ...this
2569
+ };
1136
2570
  }
1137
- };
1138
- }
1139
- function findImportedModuleIdentifier(ts) {
1140
- return (test) => (sourceFile) => {
1141
- for (const statement of sourceFile.statements) {
1142
- if (!ts.isImportDeclaration(statement)) continue;
1143
- const importClause = statement.importClause;
1144
- if (!importClause) continue;
1145
- const namedBindings = importClause.namedBindings;
1146
- if (!namedBindings) continue;
1147
- if (ts.isNamespaceImport(namedBindings)) {
1148
- if (test(namedBindings.name)) return some2(namedBindings.name);
1149
- } else if (ts.isNamedImports(namedBindings)) {
1150
- for (const importSpecifier of namedBindings.elements) {
1151
- if (test(importSpecifier.name)) return some2(importSpecifier.name);
1152
- }
2571
+ [NodeInspectSymbol]() {
2572
+ if (this.toString !== globalThis.Error.prototype.toString) {
2573
+ return this.stack ? `${this.toString()}
2574
+ ${this.stack.split("\n").slice(1).join("\n")}` : this.toString();
2575
+ } else if ("Bun" in globalThis) {
2576
+ return pretty(fail(this), {
2577
+ renderErrorCause: true
2578
+ });
1153
2579
  }
2580
+ return this;
1154
2581
  }
1155
- return none2();
1156
- };
1157
- }
1158
- function simplifyTypeNode(ts) {
1159
- function collectCallable(typeNode) {
1160
- if (ts.isParenthesizedTypeNode(typeNode)) return collectCallable(typeNode.type);
1161
- if (ts.isFunctionTypeNode(typeNode)) {
1162
- return some2([
1163
- ts.factory.createCallSignature(typeNode.typeParameters, typeNode.parameters, typeNode.type)
1164
- ]);
1165
- }
1166
- if (ts.isTypeLiteralNode(typeNode)) {
1167
- const allCallSignatures = typeNode.members.every(ts.isCallSignatureDeclaration);
1168
- if (allCallSignatures) {
1169
- return some2(typeNode.members);
2582
+ }
2583
+ Object.assign(YieldableError2.prototype, StructuralCommitPrototype);
2584
+ return YieldableError2;
2585
+ }();
2586
+ var makeException = (proto2, tag) => {
2587
+ class Base extends YieldableError {
2588
+ _tag = tag;
2589
+ }
2590
+ Object.assign(Base.prototype, proto2);
2591
+ Base.prototype.name = tag;
2592
+ return Base;
2593
+ };
2594
+ var RuntimeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/RuntimeException");
2595
+ var RuntimeException = /* @__PURE__ */ makeException({
2596
+ [RuntimeExceptionTypeId]: RuntimeExceptionTypeId
2597
+ }, "RuntimeException");
2598
+ var InterruptedExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InterruptedException");
2599
+ var InterruptedException = /* @__PURE__ */ makeException({
2600
+ [InterruptedExceptionTypeId]: InterruptedExceptionTypeId
2601
+ }, "InterruptedException");
2602
+ var IllegalArgumentExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/IllegalArgument");
2603
+ var IllegalArgumentException = /* @__PURE__ */ makeException({
2604
+ [IllegalArgumentExceptionTypeId]: IllegalArgumentExceptionTypeId
2605
+ }, "IllegalArgumentException");
2606
+ var NoSuchElementExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/NoSuchElement");
2607
+ var NoSuchElementException = /* @__PURE__ */ makeException({
2608
+ [NoSuchElementExceptionTypeId]: NoSuchElementExceptionTypeId
2609
+ }, "NoSuchElementException");
2610
+ var InvalidPubSubCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InvalidPubSubCapacityException");
2611
+ var InvalidPubSubCapacityException = /* @__PURE__ */ makeException({
2612
+ [InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId
2613
+ }, "InvalidPubSubCapacityException");
2614
+ var ExceededCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/ExceededCapacityException");
2615
+ var ExceededCapacityException = /* @__PURE__ */ makeException({
2616
+ [ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId
2617
+ }, "ExceededCapacityException");
2618
+ var TimeoutExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/Timeout");
2619
+ var TimeoutException = /* @__PURE__ */ makeException({
2620
+ [TimeoutExceptionTypeId]: TimeoutExceptionTypeId
2621
+ }, "TimeoutException");
2622
+ var exitIsExit = (u) => isEffect(u) && "_tag" in u && (u._tag === "Success" || u._tag === "Failure");
2623
+ var currentSpanFromFiber = (fiber) => {
2624
+ const span = fiber.currentSpan;
2625
+ return span !== void 0 && span._tag === "Span" ? some2(span) : none2();
2626
+ };
2627
+
2628
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Data.js
2629
+ var Error2 = /* @__PURE__ */ function() {
2630
+ const plainArgsSymbol = /* @__PURE__ */ Symbol.for("effect/Data/Error/plainArgs");
2631
+ return class Base extends YieldableError {
2632
+ constructor(args) {
2633
+ super(args?.message, args?.cause ? {
2634
+ cause: args.cause
2635
+ } : void 0);
2636
+ if (args) {
2637
+ Object.assign(this, args);
2638
+ Object.defineProperty(this, plainArgsSymbol, {
2639
+ value: args,
2640
+ enumerable: false
2641
+ });
1170
2642
  }
1171
2643
  }
1172
- if (ts.isIntersectionTypeNode(typeNode)) {
1173
- const members = typeNode.types.map(collectCallable);
1174
- if (members.every(isSome2)) {
1175
- return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
1176
- }
2644
+ toJSON() {
2645
+ return {
2646
+ ...this[plainArgsSymbol],
2647
+ ...this
2648
+ };
1177
2649
  }
1178
- return none2();
2650
+ };
2651
+ }();
2652
+ var TaggedError = (tag) => {
2653
+ class Base extends Error2 {
2654
+ _tag = tag;
1179
2655
  }
1180
- return (typeNode) => {
1181
- const callSignatures = collectCallable(typeNode);
1182
- if (isSome2(callSignatures) && callSignatures.value.length > 1) {
1183
- return ts.factory.createTypeLiteralNode(callSignatures.value);
2656
+ ;
2657
+ Base.prototype.name = tag;
2658
+ return Base;
2659
+ };
2660
+
2661
+ // src/core/Nano.ts
2662
+ var NanoInterruptedException = class extends TaggedError("NanoInterruptedException") {
2663
+ };
2664
+ var NanoDefectException = class extends TaggedError("NanoDefectException") {
2665
+ };
2666
+ var NanoTag = class {
2667
+ constructor(key) {
2668
+ this.key = key;
2669
+ }
2670
+ };
2671
+ var Tag = (identifier) => new NanoTag(identifier);
2672
+ var contextEmpty = { value: {} };
2673
+ var contextAdd = (context, tag, value) => ({
2674
+ ...context,
2675
+ value: {
2676
+ ...context.value,
2677
+ [tag.key]: value
2678
+ }
2679
+ });
2680
+ var contextGet = (context, tag) => {
2681
+ if (tag.key in context.value) {
2682
+ return some2(context.value[tag.key]);
2683
+ }
2684
+ return none2();
2685
+ };
2686
+ var Nano = class {
2687
+ constructor(run2) {
2688
+ this.run = run2;
2689
+ }
2690
+ [Symbol.iterator]() {
2691
+ return new SingleShotGen(new YieldWrap(this));
2692
+ }
2693
+ };
2694
+ var run = (fa) => pipe(
2695
+ try_({
2696
+ try: () => fa.run(contextEmpty),
2697
+ catch: (error) => new NanoDefectException({ value: error })
2698
+ }),
2699
+ flatMap((_) => _),
2700
+ flatMap((_) => _)
2701
+ );
2702
+ var succeed = (value) => new Nano(() => right2(right2(value)));
2703
+ var fail3 = (value) => new Nano(() => right2(left2(value)));
2704
+ var sync = (value) => new Nano(() => right2(right2(value())));
2705
+ var flatMap4 = dual(2, (fa, f) => new Nano((ctx) => {
2706
+ const result = fa.run(ctx);
2707
+ if (isLeft2(result)) return result;
2708
+ if (isLeft2(result.right)) return result;
2709
+ return f(result.right.right).run(ctx);
2710
+ }));
2711
+ var map7 = dual(2, (fa, f) => new Nano((ctx) => {
2712
+ const result = fa.run(ctx);
2713
+ if (isLeft2(result)) return result;
2714
+ if (isLeft2(result.right)) return result;
2715
+ return right2(right2(f(result.right.right)));
2716
+ }));
2717
+ var orElse3 = (f) => (fa) => new Nano((ctx) => {
2718
+ const result = fa.run(ctx);
2719
+ if (isLeft2(result)) return result;
2720
+ if (isLeft2(result.right)) return f().run(ctx);
2721
+ return result;
2722
+ });
2723
+ var firstSuccessOf = (arr) => reduce(arr.slice(1), arr[0], (arr2, fa) => orElse3(() => fa)(arr2));
2724
+ var service = (tag) => new Nano(
2725
+ (ctx) => contextGet(ctx, tag).pipe(match2({
2726
+ onNone: () => left2(new NanoDefectException({ value: `Cannot find service ${tag.key}` })),
2727
+ onSome: (value) => right2(right2(value))
2728
+ }))
2729
+ );
2730
+ var provideService = (tag, value) => (fa) => new Nano((ctx) => {
2731
+ return fa.run(contextAdd(ctx, tag, value));
2732
+ });
2733
+ var gen2 = (...args) => new Nano((ctx) => {
2734
+ const iterator = args[0]();
2735
+ let state = iterator.next();
2736
+ while (!state.done) {
2737
+ const current = isGenKind(state.value) ? state.value.value : yieldWrapGet(state.value);
2738
+ const result = current.run(ctx);
2739
+ if (isLeft2(result)) {
2740
+ return result;
1184
2741
  }
1185
- return typeNode;
1186
- };
2742
+ const inner = result.right;
2743
+ if (isLeft2(inner)) {
2744
+ return result;
2745
+ }
2746
+ state = iterator.next(inner.right);
2747
+ }
2748
+ return right2(right2(state.value));
2749
+ });
2750
+ var option = (fa) => new Nano((ctx) => {
2751
+ return match(fa.run(ctx), {
2752
+ onLeft: (cause) => left2(cause),
2753
+ onRight: match({
2754
+ onLeft: () => right2(right2(none2())),
2755
+ onRight: (value) => right2(right2(some2(value)))
2756
+ })
2757
+ });
2758
+ });
2759
+
2760
+ // src/core/LSP.ts
2761
+ var RefactorNotApplicableError = class extends TaggedError("RefactorNotApplicableError") {
2762
+ };
2763
+ function createRefactor(definition) {
2764
+ return definition;
1187
2765
  }
1188
- function isPipeCall(ts) {
1189
- return (node) => {
1190
- if (!ts.isCallExpression(node)) return false;
1191
- const expression = node.expression;
1192
- if (!ts.isIdentifier(expression)) return false;
1193
- if (expression.text !== "pipe") return false;
1194
- return true;
1195
- };
2766
+ function createDiagnostic(definition) {
2767
+ return definition;
1196
2768
  }
1197
- function asDataFirstExpression(ts, checker) {
1198
- return (node, self) => {
1199
- if (!ts.isCallExpression(node)) return none2();
1200
- const signature = checker.getResolvedSignature(node);
1201
- if (!signature) return none2();
1202
- const callSignatures = checker.getTypeAtLocation(node.expression).getCallSignatures();
1203
- for (let i = 0; i < callSignatures.length; i++) {
1204
- const callSignature = callSignatures[i];
1205
- if (callSignature.parameters.length === node.arguments.length + 1) {
1206
- return some2(
1207
- ts.factory.createCallExpression(
1208
- node.expression,
1209
- [],
1210
- [self].concat(node.arguments)
1211
- )
1212
- );
2769
+ var PluginOptions = Tag("PluginOptions");
2770
+ var SourceFileNotFoundError = class extends TaggedError("SourceFileNotFoundError") {
2771
+ };
2772
+ function getSemanticDiagnostics(diagnostics2, sourceFile) {
2773
+ return gen2(function* () {
2774
+ const effectDiagnostics = [];
2775
+ for (const diagnostic of diagnostics2) {
2776
+ const result = yield* option(diagnostic.apply(sourceFile));
2777
+ if (isSome2(result)) {
2778
+ effectDiagnostics.push(...result.value.map((_) => ({
2779
+ file: sourceFile,
2780
+ start: _.node.getStart(sourceFile),
2781
+ length: _.node.getEnd() - _.node.getStart(sourceFile),
2782
+ messageText: _.messageText,
2783
+ category: _.category,
2784
+ code: diagnostic.code,
2785
+ source: "effect"
2786
+ })));
1213
2787
  }
1214
2788
  }
1215
- return none2();
1216
- };
2789
+ return effectDiagnostics;
2790
+ });
2791
+ }
2792
+ function getApplicableRefactors(refactors2, sourceFile, positionOrRange) {
2793
+ return gen2(function* () {
2794
+ const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
2795
+ const effectRefactors = [];
2796
+ for (const refactor of refactors2) {
2797
+ const result = yield* option(refactor.apply(sourceFile, textRange));
2798
+ if (isSome2(result)) {
2799
+ effectRefactors.push({
2800
+ name: refactor.name,
2801
+ description: refactor.description,
2802
+ actions: [{
2803
+ name: refactor.name,
2804
+ description: result.value.description,
2805
+ kind: result.value.kind
2806
+ }]
2807
+ });
2808
+ }
2809
+ }
2810
+ return effectRefactors;
2811
+ });
2812
+ }
2813
+ function getEditsForRefactor(refactors2, sourceFile, positionOrRange, refactorName) {
2814
+ return gen2(function* () {
2815
+ const refactor = refactors2.find((refactor2) => refactor2.name === refactorName);
2816
+ if (!refactor) {
2817
+ return yield* fail3(new RefactorNotApplicableError());
2818
+ }
2819
+ const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
2820
+ return yield* refactor.apply(sourceFile, textRange);
2821
+ });
1217
2822
  }
1218
- function deterministicTypeOrder(ts, typeChecker) {
2823
+
2824
+ // src/utils/TypeScriptApi.ts
2825
+ var TypeScriptApi = Tag("TypeScriptApi");
2826
+ var ChangeTracker = Tag("ChangeTracker");
2827
+
2828
+ // src/utils/TypeCheckerApi.ts
2829
+ var TypeCheckerApi = Tag("TypeChecker");
2830
+ var deterministicTypeOrder = gen2(function* () {
2831
+ const typeChecker = yield* service(TypeCheckerApi);
1219
2832
  return make2((a, b) => {
1220
2833
  const aName = typeChecker.typeToString(a);
1221
2834
  const bName = typeChecker.typeToString(b);
@@ -1223,40 +2836,10 @@ function deterministicTypeOrder(ts, typeChecker) {
1223
2836
  if (aName > bName) return 1;
1224
2837
  return 0;
1225
2838
  });
1226
- }
1227
- function tryPreserveDeclarationSemantics(ts) {
1228
- return (nodeToReplace, node) => {
1229
- if (!ts.isExpression(node)) return node;
1230
- if (ts.isFunctionDeclaration(nodeToReplace)) {
1231
- if (!nodeToReplace.name) return node;
1232
- return ts.factory.createVariableStatement(
1233
- nodeToReplace.modifiers,
1234
- ts.factory.createVariableDeclarationList(
1235
- [ts.factory.createVariableDeclaration(
1236
- nodeToReplace.name,
1237
- void 0,
1238
- void 0,
1239
- node
1240
- )],
1241
- ts.NodeFlags.Const
1242
- )
1243
- );
1244
- } else if (ts.isMethodDeclaration(nodeToReplace)) {
1245
- return ts.factory.createPropertyDeclaration(
1246
- nodeToReplace.modifiers,
1247
- nodeToReplace.name,
1248
- void 0,
1249
- void 0,
1250
- node
1251
- );
1252
- }
1253
- return node;
1254
- };
1255
- }
1256
-
1257
- // src/utils/TypeCheckerApi.ts
1258
- function getMissingTypeEntriesInTargetType(ts, typeChecker) {
1259
- return (realType, expectedType) => {
2839
+ });
2840
+ function getMissingTypeEntriesInTargetType(realType, expectedType) {
2841
+ return gen2(function* () {
2842
+ const typeChecker = yield* service(TypeCheckerApi);
1260
2843
  const result = [];
1261
2844
  const toTest = [realType];
1262
2845
  while (toTest.length > 0) {
@@ -1272,28 +2855,34 @@ function getMissingTypeEntriesInTargetType(ts, typeChecker) {
1272
2855
  }
1273
2856
  }
1274
2857
  return result;
1275
- };
2858
+ });
1276
2859
  }
1277
- function getInferredReturnType(ts, typeChecker) {
1278
- function isConvertibleDeclaration(node) {
1279
- switch (node.kind) {
1280
- case ts.SyntaxKind.FunctionDeclaration:
1281
- case ts.SyntaxKind.FunctionExpression:
1282
- case ts.SyntaxKind.ArrowFunction:
1283
- case ts.SyntaxKind.MethodDeclaration:
1284
- return true;
1285
- default:
1286
- return false;
1287
- }
1288
- }
1289
- return (node) => {
1290
- let declaration = node;
1291
- while (declaration && !isConvertibleDeclaration(declaration)) {
1292
- declaration = declaration.parent;
2860
+ var CannotFindAncestorConvertibleDeclarationError = class extends TaggedError("CannotFindAncestorConvertibleDeclarationError") {
2861
+ };
2862
+ function getAncestorConvertibleDeclaration(node) {
2863
+ return gen2(function* () {
2864
+ const ts = yield* service(TypeScriptApi);
2865
+ let current = node;
2866
+ while (current) {
2867
+ if (ts.isFunctionDeclaration(current) || ts.isFunctionExpression(current) || ts.isArrowFunction(current) || ts.isMethodDeclaration(current)) {
2868
+ return current;
2869
+ }
2870
+ current = current.parent;
1293
2871
  }
1294
- if (!isConvertibleDeclaration(declaration)) return none2();
1295
- if (!declaration || !declaration.body) {
1296
- return none2();
2872
+ return yield* fail3(new CannotFindAncestorConvertibleDeclarationError({ node }));
2873
+ });
2874
+ }
2875
+ var CannotInferReturnTypeFromEmptyBody = class extends TaggedError("CannotInferReturnTypeFromEmptyBody") {
2876
+ };
2877
+ var CannotInferReturnType = class extends TaggedError("CannotInferReturnType") {
2878
+ };
2879
+ function getInferredReturnType(declaration) {
2880
+ return gen2(function* () {
2881
+ const typeChecker = yield* service(TypeCheckerApi);
2882
+ if (!declaration.body) {
2883
+ return yield* fail3(
2884
+ new CannotInferReturnTypeFromEmptyBody({ declaration })
2885
+ );
1297
2886
  }
1298
2887
  let returnType;
1299
2888
  if (typeChecker.isImplementationOfOverload(declaration)) {
@@ -1309,20 +2898,24 @@ function getInferredReturnType(ts, typeChecker) {
1309
2898
  if (signature) {
1310
2899
  const typePredicate = typeChecker.getTypePredicateOfSignature(signature);
1311
2900
  if (typePredicate && typePredicate.type) {
1312
- return some2(typePredicate.type);
2901
+ return typePredicate.type;
1313
2902
  } else {
1314
2903
  returnType = typeChecker.getReturnTypeOfSignature(signature);
1315
2904
  }
1316
2905
  }
1317
2906
  }
1318
2907
  if (!returnType) {
1319
- return none2();
2908
+ return yield* fail3(
2909
+ new CannotInferReturnType({ declaration })
2910
+ );
1320
2911
  }
1321
- return some2(returnType);
1322
- };
2912
+ return returnType;
2913
+ });
1323
2914
  }
1324
- function expectedAndRealType(ts, typeChecker) {
1325
- return (node) => {
2915
+ function expectedAndRealType(node) {
2916
+ return gen2(function* () {
2917
+ const typeChecker = yield* service(TypeCheckerApi);
2918
+ const ts = yield* service(TypeScriptApi);
1326
2919
  if (ts.isVariableDeclaration(node) && node.initializer) {
1327
2920
  const expectedType = typeChecker.getTypeAtLocation(node.name);
1328
2921
  const realType = typeChecker.getTypeAtLocation(node.initializer);
@@ -1354,57 +2947,383 @@ function expectedAndRealType(ts, typeChecker) {
1354
2947
  }
1355
2948
  }
1356
2949
  }
1357
- if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
1358
- const expectedType = typeChecker.getTypeAtLocation(node.left);
1359
- const realType = typeChecker.getTypeAtLocation(node.right);
1360
- return [[node.left, expectedType, node.right, realType]];
2950
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
2951
+ const expectedType = typeChecker.getTypeAtLocation(node.left);
2952
+ const realType = typeChecker.getTypeAtLocation(node.right);
2953
+ return [[node.left, expectedType, node.right, realType]];
2954
+ }
2955
+ if (ts.isReturnStatement(node) && node.expression) {
2956
+ const parentDeclaration = yield* option(getAncestorConvertibleDeclaration(node));
2957
+ if (isSome2(parentDeclaration)) {
2958
+ const expectedType = yield* option(getInferredReturnType(parentDeclaration.value));
2959
+ const realType = typeChecker.getTypeAtLocation(node.expression);
2960
+ if (isSome2(expectedType)) return [[node, expectedType.value, node, realType]];
2961
+ }
2962
+ }
2963
+ if (ts.isArrowFunction(node) && ts.isExpression(node.body)) {
2964
+ const body = node.body;
2965
+ const expectedType = typeChecker.getContextualType(body);
2966
+ const realType = typeChecker.getTypeAtLocation(body);
2967
+ if (expectedType) return [[body, expectedType, body, realType]];
2968
+ }
2969
+ if (ts.isSatisfiesExpression(node)) {
2970
+ const expectedType = typeChecker.getTypeAtLocation(node.type);
2971
+ const realType = typeChecker.getTypeAtLocation(node.expression);
2972
+ return [[node.expression, expectedType, node.expression, realType]];
2973
+ }
2974
+ return [];
2975
+ });
2976
+ }
2977
+
2978
+ // src/utils/TypeParser.ts
2979
+ var TypeParserIssue = class extends TaggedError("@effect/language-service/TypeParserIssue") {
2980
+ };
2981
+ function typeParserIssue(message, type, node) {
2982
+ return fail3(new TypeParserIssue({ type, message, node }));
2983
+ }
2984
+ function covariantTypeArgument(type) {
2985
+ const signatures = type.getCallSignatures();
2986
+ if (signatures.length !== 1) {
2987
+ return typeParserIssue("Covariant type has no call signature", type);
2988
+ }
2989
+ return succeed(signatures[0].getReturnType());
2990
+ }
2991
+ function pipeableType(type, atLocation) {
2992
+ return gen2(function* () {
2993
+ const typeChecker = yield* service(TypeCheckerApi);
2994
+ const pipeSymbol = typeChecker.getPropertyOfType(type, "pipe");
2995
+ if (!pipeSymbol) {
2996
+ return yield* typeParserIssue("Type has no 'pipe' property", type, atLocation);
2997
+ }
2998
+ const pipeType = typeChecker.getTypeOfSymbolAtLocation(pipeSymbol, atLocation);
2999
+ const signatures = pipeType.getCallSignatures();
3000
+ if (signatures.length === 0) {
3001
+ return yield* typeParserIssue("'pipe' property is not callable", type, atLocation);
3002
+ }
3003
+ return type;
3004
+ });
3005
+ }
3006
+ function varianceStructCovariantType(type, atLocation, propertyName) {
3007
+ return gen2(function* () {
3008
+ const typeChecker = yield* service(TypeCheckerApi);
3009
+ const propertySymbol = typeChecker.getPropertyOfType(type, propertyName);
3010
+ if (!propertySymbol) {
3011
+ return yield* typeParserIssue(`Type has no '${propertyName}' property`, type, atLocation);
3012
+ }
3013
+ const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
3014
+ return yield* covariantTypeArgument(propertyType);
3015
+ });
3016
+ }
3017
+ function effectVarianceStruct(type, atLocation) {
3018
+ return gen2(function* () {
3019
+ return {
3020
+ A: yield* varianceStructCovariantType(type, atLocation, "_A"),
3021
+ E: yield* varianceStructCovariantType(type, atLocation, "_E"),
3022
+ R: yield* varianceStructCovariantType(type, atLocation, "_R")
3023
+ };
3024
+ });
3025
+ }
3026
+ function effectType(type, atLocation) {
3027
+ return gen2(function* () {
3028
+ const typeChecker = yield* service(TypeCheckerApi);
3029
+ yield* pipeableType(type, atLocation);
3030
+ for (const propertySymbol of typeChecker.getPropertiesOfType(type)) {
3031
+ const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
3032
+ const varianceArgs = yield* option(effectVarianceStruct(
3033
+ propertyType,
3034
+ atLocation
3035
+ ));
3036
+ if (isSome2(varianceArgs)) {
3037
+ return varianceArgs.value;
3038
+ }
3039
+ }
3040
+ return yield* typeParserIssue("Type has no effect variance struct", type, atLocation);
3041
+ });
3042
+ }
3043
+ function fiberType(type, atLocation) {
3044
+ return gen2(function* () {
3045
+ const typeChecker = yield* service(TypeCheckerApi);
3046
+ const awaitSymbol = typeChecker.getPropertyOfType(type, "await");
3047
+ const pollSymbol = typeChecker.getPropertyOfType(type, "poll");
3048
+ if (!awaitSymbol || !pollSymbol) {
3049
+ return yield* typeParserIssue(
3050
+ "Type is not a fiber because it does not have 'await' or 'poll' property",
3051
+ type,
3052
+ atLocation
3053
+ );
3054
+ }
3055
+ return yield* effectType(type, atLocation);
3056
+ });
3057
+ }
3058
+ function effectSubtype(type, atLocation) {
3059
+ return gen2(function* () {
3060
+ const typeChecker = yield* service(TypeCheckerApi);
3061
+ const tagSymbol = typeChecker.getPropertyOfType(type, "_tag");
3062
+ if (!tagSymbol) {
3063
+ return yield* typeParserIssue(
3064
+ "Type is not a subtype of effect because it does not have '_tag' property",
3065
+ type,
3066
+ atLocation
3067
+ );
3068
+ }
3069
+ return yield* effectType(type, atLocation);
3070
+ });
3071
+ }
3072
+ function importedEffectModule(node) {
3073
+ return gen2(function* () {
3074
+ const ts = yield* service(TypeScriptApi);
3075
+ const typeChecker = yield* service(TypeCheckerApi);
3076
+ const type = typeChecker.getTypeAtLocation(node);
3077
+ const propertySymbol = typeChecker.getPropertyOfType(type, "never");
3078
+ if (!propertySymbol) {
3079
+ return yield* typeParserIssue("Type has no 'never' property", type, node);
3080
+ }
3081
+ if (!ts.isExpression(node)) {
3082
+ return yield* typeParserIssue("Node is not an expression", type, node);
3083
+ }
3084
+ const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, node);
3085
+ yield* effectType(propertyType, node);
3086
+ return node;
3087
+ });
3088
+ }
3089
+ function effectGen(node) {
3090
+ return gen2(function* () {
3091
+ const ts = yield* service(TypeScriptApi);
3092
+ if (!ts.isCallExpression(node)) {
3093
+ return yield* typeParserIssue("Node is not a call expression", void 0, node);
3094
+ }
3095
+ if (node.arguments.length === 0) {
3096
+ return yield* typeParserIssue("Node has no arguments", void 0, node);
3097
+ }
3098
+ const generatorFunction = node.arguments[0];
3099
+ if (!ts.isFunctionExpression(generatorFunction)) {
3100
+ return yield* typeParserIssue("Node is not a function expression", void 0, node);
3101
+ }
3102
+ if (generatorFunction.asteriskToken === void 0) {
3103
+ return yield* typeParserIssue("Node is not a generator function", void 0, node);
3104
+ }
3105
+ if (!ts.isPropertyAccessExpression(node.expression)) {
3106
+ return yield* typeParserIssue("Node is not a property access expression", void 0, node);
3107
+ }
3108
+ const propertyAccess = node.expression;
3109
+ if (propertyAccess.name.text !== "gen") {
3110
+ return yield* typeParserIssue("Call expression name is not 'gen'", void 0, node);
3111
+ }
3112
+ const effectModule = yield* importedEffectModule(propertyAccess.expression);
3113
+ return {
3114
+ node,
3115
+ effectModule,
3116
+ generatorFunction,
3117
+ body: generatorFunction.body,
3118
+ functionStar: generatorFunction.getFirstToken()
3119
+ };
3120
+ });
3121
+ }
3122
+ function effectFnUntracedGen(node) {
3123
+ return gen2(function* () {
3124
+ const ts = yield* service(TypeScriptApi);
3125
+ if (!ts.isCallExpression(node)) {
3126
+ return yield* typeParserIssue("Node is not a call expression", void 0, node);
3127
+ }
3128
+ if (node.arguments.length === 0) {
3129
+ return yield* typeParserIssue("Node has no arguments", void 0, node);
3130
+ }
3131
+ const generatorFunction = node.arguments[0];
3132
+ if (!ts.isFunctionExpression(generatorFunction)) {
3133
+ return yield* typeParserIssue("Node is not a function expression", void 0, node);
3134
+ }
3135
+ if (generatorFunction.asteriskToken === void 0) {
3136
+ return yield* typeParserIssue(
3137
+ "Node is not a generator function",
3138
+ void 0,
3139
+ node
3140
+ );
3141
+ }
3142
+ if (!ts.isPropertyAccessExpression(node.expression)) {
3143
+ return yield* typeParserIssue(
3144
+ "Node is not a property access expression",
3145
+ void 0,
3146
+ node
3147
+ );
3148
+ }
3149
+ const propertyAccess = node.expression;
3150
+ if (propertyAccess.name.text !== "fnUntraced") {
3151
+ return yield* typeParserIssue(
3152
+ "Call expression name is not 'fnUntraced'",
3153
+ void 0,
3154
+ node
3155
+ );
3156
+ }
3157
+ const effectModule = yield* importedEffectModule(propertyAccess.expression);
3158
+ return {
3159
+ node,
3160
+ effectModule,
3161
+ generatorFunction,
3162
+ body: generatorFunction.body,
3163
+ functionStar: generatorFunction.getFirstToken()
3164
+ };
3165
+ });
3166
+ }
3167
+ function effectFnGen(node) {
3168
+ return gen2(function* () {
3169
+ const ts = yield* service(TypeScriptApi);
3170
+ if (!ts.isCallExpression(node)) {
3171
+ return yield* typeParserIssue("Node is not a call expression", void 0, node);
3172
+ }
3173
+ if (node.arguments.length === 0) {
3174
+ return yield* typeParserIssue("Node has no arguments", void 0, node);
1361
3175
  }
1362
- if (ts.isReturnStatement(node) && node.expression) {
1363
- const expectedType = getOrUndefined(getInferredReturnType(ts, typeChecker)(node));
1364
- const realType = typeChecker.getTypeAtLocation(node.expression);
1365
- if (expectedType) return [[node, expectedType, node, realType]];
3176
+ const generatorFunction = node.arguments[0];
3177
+ if (!ts.isFunctionExpression(generatorFunction)) {
3178
+ return yield* typeParserIssue(
3179
+ "Node is not a function expression",
3180
+ void 0,
3181
+ node
3182
+ );
1366
3183
  }
1367
- if (ts.isArrowFunction(node) && ts.isExpression(node.body)) {
1368
- const body = node.body;
1369
- const expectedType = typeChecker.getContextualType(body);
1370
- const realType = typeChecker.getTypeAtLocation(body);
1371
- if (expectedType) return [[body, expectedType, body, realType]];
3184
+ if (generatorFunction.asteriskToken === void 0) {
3185
+ return yield* typeParserIssue(
3186
+ "Node is not a generator function",
3187
+ void 0,
3188
+ node
3189
+ );
1372
3190
  }
1373
- if (ts.isSatisfiesExpression(node)) {
1374
- const expectedType = typeChecker.getTypeAtLocation(node.type);
1375
- const realType = typeChecker.getTypeAtLocation(node.expression);
1376
- return [[node.expression, expectedType, node.expression, realType]];
3191
+ const expressionToTest = ts.isCallExpression(node.expression) ? node.expression.expression : node.expression;
3192
+ if (!ts.isPropertyAccessExpression(expressionToTest)) {
3193
+ return yield* typeParserIssue(
3194
+ "Node is not a property access expression",
3195
+ void 0,
3196
+ node
3197
+ );
1377
3198
  }
1378
- return [];
1379
- };
3199
+ const propertyAccess = expressionToTest;
3200
+ if (propertyAccess.name.text !== "fn") {
3201
+ return yield* typeParserIssue(
3202
+ "Call expression name is not 'fn'",
3203
+ void 0,
3204
+ node
3205
+ );
3206
+ }
3207
+ const effectModule = yield* importedEffectModule(propertyAccess.expression);
3208
+ return {
3209
+ node,
3210
+ generatorFunction,
3211
+ effectModule,
3212
+ body: generatorFunction.body,
3213
+ functionStar: generatorFunction.getFirstToken()
3214
+ };
3215
+ });
3216
+ }
3217
+ function returnYieldEffectBlock(body) {
3218
+ return gen2(function* () {
3219
+ const ts = yield* service(TypeScriptApi);
3220
+ const typeChecker = yield* service(TypeCheckerApi);
3221
+ if (!ts.isBlock(body)) return yield* typeParserIssue("Node is not a block", void 0, body);
3222
+ if (body.statements.length === 1 && ts.isReturnStatement(body.statements[0]) && body.statements[0].expression && ts.isYieldExpression(body.statements[0].expression) && body.statements[0].expression.expression) {
3223
+ const nodeToCheck = body.statements[0].expression.expression;
3224
+ const type = typeChecker.getTypeAtLocation(nodeToCheck);
3225
+ yield* effectType(type, nodeToCheck);
3226
+ return nodeToCheck;
3227
+ }
3228
+ return yield* typeParserIssue(
3229
+ "Node is not a return statement with a yield expression",
3230
+ void 0,
3231
+ body
3232
+ );
3233
+ });
1380
3234
  }
1381
3235
 
3236
+ // src/diagnostics/floatingEffect.ts
3237
+ var floatingEffect = createDiagnostic({
3238
+ name: "effect/floatingEffect",
3239
+ code: 3,
3240
+ apply: (sourceFile) => gen2(function* () {
3241
+ const ts = yield* service(TypeScriptApi);
3242
+ const typeChecker = yield* service(TypeCheckerApi);
3243
+ function isFloatingExpression(node) {
3244
+ if (!ts.isExpressionStatement(node)) return false;
3245
+ if (!(ts.isBlock(node.parent) || ts.isSourceFile(node.parent))) return false;
3246
+ const expression = node.expression;
3247
+ if (ts.isBinaryExpression(expression) && expression.operatorToken && expression.operatorToken.kind === ts.SyntaxKind.EqualsToken) return false;
3248
+ return true;
3249
+ }
3250
+ const effectDiagnostics = [];
3251
+ const nodeToVisit = [];
3252
+ const appendNodeToVisit = (node) => {
3253
+ nodeToVisit.push(node);
3254
+ return void 0;
3255
+ };
3256
+ ts.forEachChild(sourceFile, appendNodeToVisit);
3257
+ while (nodeToVisit.length > 0) {
3258
+ const node = nodeToVisit.shift();
3259
+ ts.forEachChild(node, appendNodeToVisit);
3260
+ if (!isFloatingExpression(node)) continue;
3261
+ const type = typeChecker.getTypeAtLocation(node.expression);
3262
+ const effect = yield* option(effectType(type, node.expression));
3263
+ if (isSome2(effect)) {
3264
+ const allowedFloatingEffects = yield* pipe(
3265
+ fiberType(type, node.expression),
3266
+ orElse3(() => effectSubtype(type, node.expression)),
3267
+ option
3268
+ );
3269
+ if (isNone2(allowedFloatingEffects)) {
3270
+ effectDiagnostics.push({
3271
+ node,
3272
+ category: ts.DiagnosticCategory.Error,
3273
+ messageText: `Effect must be yielded or assigned to a variable.`
3274
+ });
3275
+ }
3276
+ }
3277
+ }
3278
+ return effectDiagnostics;
3279
+ })
3280
+ });
3281
+
1382
3282
  // src/diagnostics/missingEffectContext.ts
1383
3283
  var missingEffectContext = createDiagnostic({
3284
+ name: "effect/missingEffectContext",
1384
3285
  code: 1,
1385
- apply: (ts, program) => (sourceFile) => {
1386
- const typeChecker = program.getTypeChecker();
1387
- const effectDiagnostics = [];
1388
- const sortTypes = sort(deterministicTypeOrder(ts, typeChecker));
1389
- const visit = (node) => {
1390
- const entries = expectedAndRealType(ts, typeChecker)(node);
1391
- for (const [node2, expectedType, valueNode, realType] of entries) {
1392
- const expectedEffect = effectType(ts, typeChecker)(
3286
+ apply: (sourceFile) => gen2(function* () {
3287
+ const ts = yield* service(TypeScriptApi);
3288
+ const typeChecker = yield* service(TypeCheckerApi);
3289
+ const typeOrder = yield* deterministicTypeOrder;
3290
+ function checkForMissingContextTypes(node, expectedType, valueNode, realType) {
3291
+ return gen2(function* () {
3292
+ const expectedEffect = yield* effectType(
1393
3293
  expectedType,
1394
- node2
3294
+ node
1395
3295
  );
1396
- if (isNone2(expectedEffect)) continue;
1397
- const realEffect = effectType(ts, typeChecker)(
3296
+ const realEffect = yield* effectType(
1398
3297
  realType,
1399
3298
  valueNode
1400
3299
  );
1401
- if (isNone2(realEffect)) continue;
1402
- const missingContext = getMissingTypeEntriesInTargetType(
1403
- ts,
1404
- typeChecker
1405
- )(
1406
- realEffect.value.R,
1407
- expectedEffect.value.R
3300
+ return yield* getMissingTypeEntriesInTargetType(
3301
+ realEffect.R,
3302
+ expectedEffect.R
3303
+ );
3304
+ });
3305
+ }
3306
+ const effectDiagnostics = [];
3307
+ const sortTypes = sort(typeOrder);
3308
+ const nodeToVisit = [];
3309
+ const appendNodeToVisit = (node) => {
3310
+ nodeToVisit.push(node);
3311
+ return void 0;
3312
+ };
3313
+ ts.forEachChild(sourceFile, appendNodeToVisit);
3314
+ while (nodeToVisit.length > 0) {
3315
+ const node = nodeToVisit.shift();
3316
+ ts.forEachChild(node, appendNodeToVisit);
3317
+ const entries = yield* expectedAndRealType(node);
3318
+ for (const [node2, expectedType, valueNode, realType] of entries) {
3319
+ const missingContext = yield* pipe(
3320
+ checkForMissingContextTypes(
3321
+ node2,
3322
+ expectedType,
3323
+ valueNode,
3324
+ realType
3325
+ ),
3326
+ orElse3(() => succeed([]))
1408
3327
  );
1409
3328
  if (missingContext.length > 0) {
1410
3329
  effectDiagnostics.push(
@@ -1416,88 +3335,115 @@ var missingEffectContext = createDiagnostic({
1416
3335
  );
1417
3336
  }
1418
3337
  }
1419
- ts.forEachChild(node, visit);
1420
- };
1421
- ts.forEachChild(sourceFile, visit);
3338
+ }
1422
3339
  return effectDiagnostics;
1423
- }
3340
+ })
1424
3341
  });
1425
3342
 
1426
3343
  // src/diagnostics/missingEffectError.ts
1427
3344
  var missingEffectError = createDiagnostic({
1428
- code: 2,
1429
- apply: (ts, program) => (sourceFile) => {
1430
- const typeChecker = program.getTypeChecker();
1431
- const effectDiagnostics = [];
1432
- const sortTypes = sort(deterministicTypeOrder(ts, typeChecker));
1433
- const visit = (node) => {
1434
- const entries = expectedAndRealType(ts, typeChecker)(node);
1435
- for (const [node2, expectedType, valueNode, realType] of entries) {
1436
- const expectedEffect = effectType(ts, typeChecker)(
3345
+ name: "effect/missingEffectError",
3346
+ code: 1,
3347
+ apply: (sourceFile) => gen2(function* () {
3348
+ const ts = yield* service(TypeScriptApi);
3349
+ const typeChecker = yield* service(TypeCheckerApi);
3350
+ const typeOrder = yield* deterministicTypeOrder;
3351
+ function checkForMissingErrorTypes(node, expectedType, valueNode, realType) {
3352
+ return gen2(function* () {
3353
+ const expectedEffect = yield* effectType(
1437
3354
  expectedType,
1438
- node2
3355
+ node
1439
3356
  );
1440
- if (isNone2(expectedEffect)) continue;
1441
- const realEffect = effectType(ts, typeChecker)(
3357
+ const realEffect = yield* effectType(
1442
3358
  realType,
1443
3359
  valueNode
1444
3360
  );
1445
- if (isNone2(realEffect)) continue;
1446
- const missingErrorTypes = getMissingTypeEntriesInTargetType(
1447
- ts,
1448
- typeChecker
1449
- )(
1450
- realEffect.value.E,
1451
- expectedEffect.value.E
3361
+ return yield* getMissingTypeEntriesInTargetType(
3362
+ realEffect.E,
3363
+ expectedEffect.E
3364
+ );
3365
+ });
3366
+ }
3367
+ const effectDiagnostics = [];
3368
+ const sortTypes = sort(typeOrder);
3369
+ const nodeToVisit = [];
3370
+ const appendNodeToVisit = (node) => {
3371
+ nodeToVisit.push(node);
3372
+ return void 0;
3373
+ };
3374
+ ts.forEachChild(sourceFile, appendNodeToVisit);
3375
+ while (nodeToVisit.length > 0) {
3376
+ const node = nodeToVisit.shift();
3377
+ ts.forEachChild(node, appendNodeToVisit);
3378
+ const entries = yield* expectedAndRealType(node);
3379
+ for (const [node2, expectedType, valueNode, realType] of entries) {
3380
+ const missingContext = yield* pipe(
3381
+ checkForMissingErrorTypes(
3382
+ node2,
3383
+ expectedType,
3384
+ valueNode,
3385
+ realType
3386
+ ),
3387
+ orElse3(() => succeed([]))
1452
3388
  );
1453
- if (missingErrorTypes.length > 0) {
3389
+ if (missingContext.length > 0) {
1454
3390
  effectDiagnostics.push(
1455
3391
  {
1456
3392
  node: node2,
1457
3393
  category: ts.DiagnosticCategory.Error,
1458
- messageText: `Missing '${sortTypes(missingErrorTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect errors.`
3394
+ messageText: `Missing '${sortTypes(missingContext).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect errors.`
1459
3395
  }
1460
3396
  );
1461
3397
  }
1462
3398
  }
1463
- ts.forEachChild(node, visit);
1464
- };
1465
- ts.forEachChild(sourceFile, visit);
3399
+ }
1466
3400
  return effectDiagnostics;
1467
- }
3401
+ })
1468
3402
  });
1469
3403
 
1470
3404
  // src/diagnostics/missingStarInYieldEffectGen.ts
1471
3405
  var missingStarInYieldEffectGen = createDiagnostic({
3406
+ name: "effect/missingStarInYieldEffectGen",
1472
3407
  code: 4,
1473
- apply: (ts, program) => (sourceFile) => {
1474
- const typeChecker = program.getTypeChecker();
3408
+ apply: (sourceFile) => gen2(function* () {
3409
+ const ts = yield* service(TypeScriptApi);
3410
+ const typeChecker = yield* service(TypeCheckerApi);
1475
3411
  const effectDiagnostics = [];
1476
3412
  const brokenGenerators = /* @__PURE__ */ new Set();
1477
3413
  const brokenYields = /* @__PURE__ */ new Set();
1478
- const visit = (functionStarNode) => (node) => {
3414
+ const nodeToVisit = [];
3415
+ const appendNodeToVisit = (functionStarNode) => (node) => {
3416
+ nodeToVisit.push([node, functionStarNode]);
3417
+ return void 0;
3418
+ };
3419
+ ts.forEachChild(sourceFile, appendNodeToVisit(void 0));
3420
+ while (nodeToVisit.length > 0) {
3421
+ const [node, functionStarNode] = nodeToVisit.shift();
1479
3422
  if (functionStarNode && ts.isYieldExpression(node) && node.expression && node.asteriskToken === void 0) {
1480
3423
  const type = typeChecker.getTypeAtLocation(node.expression);
1481
- const effect = effectType(ts, typeChecker)(type, node.expression);
3424
+ const effect = yield* option(effectType(type, node.expression));
1482
3425
  if (isSome2(effect)) {
1483
3426
  brokenGenerators.add(functionStarNode);
1484
3427
  brokenYields.add(node);
1485
3428
  }
1486
3429
  }
1487
- const effectGenLike = pipe(
1488
- effectGen(ts, typeChecker)(node),
1489
- orElse(() => effectFnUntracedGen(ts, typeChecker)(node)),
1490
- orElse(() => effectFnGen(ts, typeChecker)(node))
3430
+ const effectGenLike = yield* pipe(
3431
+ effectGen(node),
3432
+ orElse3(() => effectFnUntracedGen(node)),
3433
+ orElse3(() => effectFnGen(node)),
3434
+ option
1491
3435
  );
1492
3436
  if (isSome2(effectGenLike)) {
1493
- ts.forEachChild(effectGenLike.value.body, visit(effectGenLike.value.functionStar));
3437
+ ts.forEachChild(
3438
+ effectGenLike.value.body,
3439
+ appendNodeToVisit(effectGenLike.value.functionStar)
3440
+ );
1494
3441
  } else if ((ts.isFunctionExpression(node) || ts.isMethodDeclaration(node)) && node.asteriskToken !== void 0) {
1495
- ts.forEachChild(node, visit(void 0));
3442
+ ts.forEachChild(node, appendNodeToVisit(void 0));
1496
3443
  } else {
1497
- ts.forEachChild(node, visit(functionStarNode));
3444
+ ts.forEachChild(node, appendNodeToVisit(functionStarNode));
1498
3445
  }
1499
- };
1500
- ts.forEachChild(sourceFile, visit(void 0));
3446
+ }
1501
3447
  brokenGenerators.forEach(
1502
3448
  (node) => effectDiagnostics.push({
1503
3449
  node,
@@ -1513,23 +3459,35 @@ var missingStarInYieldEffectGen = createDiagnostic({
1513
3459
  })
1514
3460
  );
1515
3461
  return effectDiagnostics;
1516
- }
3462
+ })
1517
3463
  });
1518
3464
 
1519
3465
  // src/diagnostics/unnecessaryEffectGen.ts
1520
3466
  var unnecessaryEffectGen = createDiagnostic({
3467
+ name: "effect/unnecessaryEffectGen",
1521
3468
  code: 5,
1522
- apply: (ts, program) => (sourceFile) => {
1523
- const typeChecker = program.getTypeChecker();
3469
+ apply: (sourceFile) => gen2(function* () {
3470
+ const ts = yield* service(TypeScriptApi);
1524
3471
  const effectDiagnostics = [];
1525
3472
  const brokenGenerators = /* @__PURE__ */ new Set();
1526
- const visit = (node) => {
1527
- if (isSome2(getSingleReturnEffectFromEffectGen(ts, typeChecker, node))) {
3473
+ const nodeToVisit = [];
3474
+ const appendNodeToVisit = (node) => {
3475
+ nodeToVisit.push(node);
3476
+ return void 0;
3477
+ };
3478
+ ts.forEachChild(sourceFile, appendNodeToVisit);
3479
+ while (nodeToVisit.length > 0) {
3480
+ const node = nodeToVisit.shift();
3481
+ ts.forEachChild(node, appendNodeToVisit);
3482
+ const maybeUnnecessaryGen = yield* pipe(
3483
+ effectGen(node),
3484
+ flatMap4(({ body }) => returnYieldEffectBlock(body)),
3485
+ option
3486
+ );
3487
+ if (isSome2(maybeUnnecessaryGen)) {
1528
3488
  brokenGenerators.add(node);
1529
3489
  }
1530
- ts.forEachChild(node, visit);
1531
- };
1532
- ts.forEachChild(sourceFile, visit);
3490
+ }
1533
3491
  brokenGenerators.forEach(
1534
3492
  (node) => effectDiagnostics.push({
1535
3493
  node,
@@ -1538,17 +3496,258 @@ var unnecessaryEffectGen = createDiagnostic({
1538
3496
  })
1539
3497
  );
1540
3498
  return effectDiagnostics;
1541
- }
3499
+ })
1542
3500
  });
1543
3501
 
1544
3502
  // src/diagnostics.ts
1545
- var diagnostics = {
3503
+ var diagnostics = [
1546
3504
  missingEffectContext,
1547
3505
  missingEffectError,
1548
3506
  floatingEffect,
1549
3507
  missingStarInYieldEffectGen,
1550
3508
  unnecessaryEffectGen
3509
+ ];
3510
+
3511
+ // src/utils/AST.ts
3512
+ function collectSelfAndAncestorNodesInRange(node, textRange) {
3513
+ return sync(() => {
3514
+ let result = empty();
3515
+ let parent = node;
3516
+ while (parent) {
3517
+ if (parent.end >= textRange.end) {
3518
+ result = pipe(result, append(parent));
3519
+ }
3520
+ parent = parent.parent;
3521
+ }
3522
+ return result;
3523
+ });
3524
+ }
3525
+ function getAncestorNodesInRange(sourceFile, textRange) {
3526
+ return gen2(function* () {
3527
+ const ts = yield* service(TypeScriptApi);
3528
+ const precedingToken = ts.findPrecedingToken(textRange.pos, sourceFile);
3529
+ if (!precedingToken) return empty();
3530
+ return yield* collectSelfAndAncestorNodesInRange(precedingToken, textRange);
3531
+ });
3532
+ }
3533
+ var NodeNotFoundError = class extends TaggedError("@effect/language-service/NodeNotFoundError") {
3534
+ };
3535
+ function findNodeAtPosition(sourceFile, position) {
3536
+ return gen2(function* () {
3537
+ const ts = yield* service(TypeScriptApi);
3538
+ function find(node) {
3539
+ if (position >= node.getStart() && position < node.getEnd()) {
3540
+ return ts.forEachChild(node, find) || node;
3541
+ }
3542
+ return void 0;
3543
+ }
3544
+ const result = find(sourceFile);
3545
+ if (!result) return yield* fail3(new NodeNotFoundError());
3546
+ return result;
3547
+ });
3548
+ }
3549
+ function collectDescendantsAndAncestorsInRange(sourceFile, textRange) {
3550
+ return gen2(function* () {
3551
+ const nodeAtPosition = yield* option(findNodeAtPosition(sourceFile, textRange.pos));
3552
+ if (isNone2(nodeAtPosition)) return empty();
3553
+ return yield* collectSelfAndAncestorNodesInRange(nodeAtPosition.value, textRange);
3554
+ });
3555
+ }
3556
+ function toTextRange(positionOrRange) {
3557
+ return typeof positionOrRange === "number" ? { end: positionOrRange, pos: positionOrRange } : positionOrRange;
3558
+ }
3559
+ function isNodeInRange(textRange) {
3560
+ return (node) => node.pos <= textRange.pos && node.end >= textRange.end;
3561
+ }
3562
+ function transformAsyncAwaitToEffectGen(node, effectModuleName, onAwait) {
3563
+ return gen2(function* () {
3564
+ const ts = yield* service(TypeScriptApi);
3565
+ function visitor(_) {
3566
+ if (ts.isAwaitExpression(_)) {
3567
+ const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext);
3568
+ return ts.factory.createYieldExpression(
3569
+ ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
3570
+ onAwait(expression)
3571
+ );
3572
+ }
3573
+ return ts.visitEachChild(_, visitor, ts.nullTransformationContext);
3574
+ }
3575
+ const generatorBody = visitor(node.body);
3576
+ const generator = ts.factory.createFunctionExpression(
3577
+ void 0,
3578
+ ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
3579
+ void 0,
3580
+ [],
3581
+ [],
3582
+ void 0,
3583
+ generatorBody
3584
+ // NOTE(mattia): intended, to use same routine for both ConciseBody and Body
3585
+ );
3586
+ const effectGenCallExp = ts.factory.createCallExpression(
3587
+ ts.factory.createPropertyAccessExpression(
3588
+ ts.factory.createIdentifier(effectModuleName),
3589
+ "gen"
3590
+ ),
3591
+ void 0,
3592
+ [generator]
3593
+ );
3594
+ let currentFlags = ts.getCombinedModifierFlags(node);
3595
+ currentFlags &= ~ts.ModifierFlags.Async;
3596
+ const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags);
3597
+ if (ts.isArrowFunction(node)) {
3598
+ return ts.factory.createArrowFunction(
3599
+ newModifiers,
3600
+ node.typeParameters,
3601
+ node.parameters,
3602
+ void 0,
3603
+ node.equalsGreaterThanToken,
3604
+ effectGenCallExp
3605
+ );
3606
+ }
3607
+ const newBody = ts.factory.createBlock([
3608
+ ts.factory.createReturnStatement(effectGenCallExp)
3609
+ ]);
3610
+ if (ts.isFunctionDeclaration(node)) {
3611
+ return ts.factory.createFunctionDeclaration(
3612
+ newModifiers,
3613
+ node.asteriskToken,
3614
+ node.name,
3615
+ node.typeParameters,
3616
+ node.parameters,
3617
+ void 0,
3618
+ newBody
3619
+ );
3620
+ }
3621
+ return ts.factory.createFunctionExpression(
3622
+ newModifiers,
3623
+ node.asteriskToken,
3624
+ node.name,
3625
+ node.typeParameters,
3626
+ node.parameters,
3627
+ void 0,
3628
+ newBody
3629
+ );
3630
+ });
3631
+ }
3632
+ function addReturnTypeAnnotation(sourceFile, declaration, typeNode) {
3633
+ return gen2(function* () {
3634
+ const ts = yield* service(TypeScriptApi);
3635
+ const changes = yield* service(ChangeTracker);
3636
+ const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
3637
+ const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
3638
+ const endNode = needParens ? declaration.parameters[0] : closeParen;
3639
+ if (endNode) {
3640
+ if (needParens) {
3641
+ changes.insertNodeBefore(
3642
+ sourceFile,
3643
+ endNode,
3644
+ ts.factory.createToken(ts.SyntaxKind.OpenParenToken)
3645
+ );
3646
+ changes.insertNodeAfter(
3647
+ sourceFile,
3648
+ endNode,
3649
+ ts.factory.createToken(ts.SyntaxKind.CloseParenToken)
3650
+ );
3651
+ }
3652
+ changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: ": " });
3653
+ }
3654
+ });
3655
+ }
3656
+ function removeReturnTypeAnnotation(sourceFile, declaration) {
3657
+ return gen2(function* () {
3658
+ const ts = yield* service(TypeScriptApi);
3659
+ const changes = yield* service(ChangeTracker);
3660
+ const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
3661
+ const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
3662
+ const endNode = needParens ? declaration.parameters[0] : closeParen;
3663
+ if (endNode && declaration.type) {
3664
+ changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end });
3665
+ }
3666
+ });
3667
+ }
3668
+ var ImportModuleIdentifierNotFoundError = class extends TaggedError("@effect/language-service/ImportModuleIdentifierNotFoundError") {
1551
3669
  };
3670
+ function findImportedModuleIdentifier(sourceFile, test) {
3671
+ return gen2(function* () {
3672
+ const ts = yield* service(TypeScriptApi);
3673
+ for (const statement of sourceFile.statements) {
3674
+ if (!ts.isImportDeclaration(statement)) continue;
3675
+ const importClause = statement.importClause;
3676
+ if (!importClause) continue;
3677
+ const namedBindings = importClause.namedBindings;
3678
+ if (!namedBindings) continue;
3679
+ if (ts.isNamespaceImport(namedBindings)) {
3680
+ if (yield* test(namedBindings.name)) return namedBindings.name;
3681
+ } else if (ts.isNamedImports(namedBindings)) {
3682
+ for (const importSpecifier of namedBindings.elements) {
3683
+ if (yield* test(importSpecifier.name)) return importSpecifier.name;
3684
+ }
3685
+ }
3686
+ }
3687
+ return yield* fail3(new ImportModuleIdentifierNotFoundError());
3688
+ });
3689
+ }
3690
+ function simplifyTypeNode(typeNode) {
3691
+ function collectCallable(ts, typeNode2) {
3692
+ if (ts.isParenthesizedTypeNode(typeNode2)) return collectCallable(ts, typeNode2.type);
3693
+ if (ts.isFunctionTypeNode(typeNode2)) {
3694
+ return some2([
3695
+ ts.factory.createCallSignature(typeNode2.typeParameters, typeNode2.parameters, typeNode2.type)
3696
+ ]);
3697
+ }
3698
+ if (ts.isTypeLiteralNode(typeNode2)) {
3699
+ const allCallSignatures = typeNode2.members.every(ts.isCallSignatureDeclaration);
3700
+ if (allCallSignatures) {
3701
+ return some2(typeNode2.members);
3702
+ }
3703
+ }
3704
+ if (ts.isIntersectionTypeNode(typeNode2)) {
3705
+ const members = typeNode2.types.map((node) => collectCallable(ts, node));
3706
+ if (members.every(isSome2)) {
3707
+ return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
3708
+ }
3709
+ }
3710
+ return none2();
3711
+ }
3712
+ return gen2(function* () {
3713
+ const ts = yield* service(TypeScriptApi);
3714
+ const callSignatures = collectCallable(ts, typeNode);
3715
+ if (isSome2(callSignatures) && callSignatures.value.length > 1) {
3716
+ return ts.factory.createTypeLiteralNode(callSignatures.value);
3717
+ }
3718
+ return typeNode;
3719
+ });
3720
+ }
3721
+ function tryPreserveDeclarationSemantics(nodeToReplace, node) {
3722
+ return gen2(function* () {
3723
+ const ts = yield* service(TypeScriptApi);
3724
+ if (!ts.isExpression(node)) return node;
3725
+ if (ts.isFunctionDeclaration(nodeToReplace)) {
3726
+ if (!nodeToReplace.name) return node;
3727
+ return ts.factory.createVariableStatement(
3728
+ nodeToReplace.modifiers,
3729
+ ts.factory.createVariableDeclarationList(
3730
+ [ts.factory.createVariableDeclaration(
3731
+ nodeToReplace.name,
3732
+ void 0,
3733
+ void 0,
3734
+ node
3735
+ )],
3736
+ ts.NodeFlags.Const
3737
+ )
3738
+ );
3739
+ } else if (ts.isMethodDeclaration(nodeToReplace)) {
3740
+ return ts.factory.createPropertyDeclaration(
3741
+ nodeToReplace.modifiers,
3742
+ nodeToReplace.name,
3743
+ void 0,
3744
+ void 0,
3745
+ node
3746
+ );
3747
+ }
3748
+ return node;
3749
+ });
3750
+ }
1552
3751
 
1553
3752
  // src/quickinfo.ts
1554
3753
  var SymbolDisplayPartEq = make(
@@ -1566,231 +3765,273 @@ function dedupeJsDocTags(quickInfo) {
1566
3765
  }
1567
3766
  return quickInfo;
1568
3767
  }
1569
- function formatTypeForQuickInfo(ts, typeChecker) {
1570
- return (channelType, channelName) => {
3768
+ function formatTypeForQuickInfo(channelType, channelName) {
3769
+ return gen2(function* () {
3770
+ const ts = yield* service(TypeScriptApi);
3771
+ const typeChecker = yield* service(TypeCheckerApi);
1571
3772
  const stringRepresentation = typeChecker.typeToString(
1572
3773
  channelType,
1573
3774
  void 0,
1574
3775
  ts.TypeFormatFlags.NoTruncation
1575
3776
  );
1576
3777
  return `type ${channelName} = ${stringRepresentation}`;
1577
- };
3778
+ });
1578
3779
  }
1579
- function prependEffectTypeArguments(ts, program) {
1580
- return (sourceFileName, position, quickInfo) => {
1581
- const sourceFile = program.getSourceFile(sourceFileName);
1582
- if (!sourceFile) return quickInfo;
1583
- const hasTruncationHappened = ts.displayPartsToString(quickInfo.displayParts).indexOf("...") > -1;
1584
- if (!hasTruncationHappened) return quickInfo;
1585
- const typeChecker = program.getTypeChecker();
1586
- const effectTypeArgsDocumentation = pipe(
1587
- getAncestorNodesInRange(ts)(sourceFile, toTextRange(position)),
1588
- head,
1589
- flatMap(
1590
- (_) => effectType(ts, typeChecker)(typeChecker.getTypeAtLocation(_), _)
1591
- ),
1592
- map((_) => [{
3780
+ function prependEffectTypeArguments(sourceFile, position, quickInfo) {
3781
+ return pipe(
3782
+ gen2(function* () {
3783
+ const ts = yield* service(TypeScriptApi);
3784
+ const typeChecker = yield* service(TypeCheckerApi);
3785
+ const hasTruncationHappened = ts.displayPartsToString(quickInfo.displayParts).indexOf("...") > -1;
3786
+ if (!hasTruncationHappened) return quickInfo;
3787
+ const maybeNode = pipe(
3788
+ yield* getAncestorNodesInRange(sourceFile, toTextRange(position)),
3789
+ head
3790
+ );
3791
+ if (isNone2(maybeNode)) return quickInfo;
3792
+ const effectType2 = yield* effectType(
3793
+ typeChecker.getTypeAtLocation(maybeNode.value),
3794
+ maybeNode.value
3795
+ );
3796
+ const effectTypeArgsDocumentation = [{
1593
3797
  kind: "text",
1594
- text: "```ts\n/* Effect Type Parameters */\n" + formatTypeForQuickInfo(ts, typeChecker)(_.A, "Success") + "\n" + formatTypeForQuickInfo(ts, typeChecker)(_.E, "Failure") + "\n" + formatTypeForQuickInfo(ts, typeChecker)(_.R, "Requirements") + "\n```\n"
1595
- }]),
1596
- getOrElse(() => [])
1597
- );
1598
- if (quickInfo.documentation) {
3798
+ text: "```ts\n/* Effect Type Parameters */\n" + (yield* formatTypeForQuickInfo(effectType2.A, "Success")) + "\n" + (yield* formatTypeForQuickInfo(effectType2.E, "Failure")) + "\n" + (yield* formatTypeForQuickInfo(effectType2.R, "Requirements")) + "\n```\n"
3799
+ }];
3800
+ if (quickInfo.documentation) {
3801
+ return {
3802
+ ...quickInfo,
3803
+ documentation: effectTypeArgsDocumentation.concat(quickInfo.documentation)
3804
+ };
3805
+ }
1599
3806
  return {
1600
3807
  ...quickInfo,
1601
- documentation: effectTypeArgsDocumentation.concat(quickInfo.documentation)
3808
+ documentation: effectTypeArgsDocumentation
1602
3809
  };
1603
- }
1604
- return {
1605
- ...quickInfo,
1606
- documentation: effectTypeArgsDocumentation
1607
- };
1608
- };
3810
+ }),
3811
+ orElse3(() => succeed(quickInfo))
3812
+ );
1609
3813
  }
1610
3814
 
1611
3815
  // src/refactors/asyncAwaitToGen.ts
1612
3816
  var asyncAwaitToGen = createRefactor({
1613
3817
  name: "effect/asyncAwaitToGen",
1614
3818
  description: "Convert to Effect.gen",
1615
- apply: (ts, program) => (sourceFile, textRange) => pipe(
1616
- getAncestorNodesInRange(ts)(sourceFile, textRange),
1617
- filter(
1618
- (node) => ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)
1619
- ),
1620
- filter((node) => !!node.body),
1621
- filter(
1622
- (node) => !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)
1623
- ),
1624
- head,
1625
- map((node) => ({
3819
+ apply: (sourceFile, textRange) => gen2(function* () {
3820
+ const ts = yield* service(TypeScriptApi);
3821
+ const typeChecker = yield* service(TypeCheckerApi);
3822
+ const maybeNode = pipe(
3823
+ yield* getAncestorNodesInRange(sourceFile, textRange),
3824
+ filter(
3825
+ (node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
3826
+ ),
3827
+ filter((node2) => !!node2.body),
3828
+ filter(
3829
+ (node2) => !!(ts.getCombinedModifierFlags(node2) & ts.ModifierFlags.Async)
3830
+ ),
3831
+ head
3832
+ );
3833
+ if (isNone2(maybeNode)) return yield* fail3(new RefactorNotApplicableError());
3834
+ const node = maybeNode.value;
3835
+ return {
1626
3836
  kind: "refactor.rewrite.effect.asyncAwaitToGen",
1627
3837
  description: "Rewrite to Effect.gen",
1628
- apply: (changeTracker) => {
1629
- const isImportedEffectModule = importedEffectModule(
1630
- ts,
1631
- program.getTypeChecker()
1632
- );
1633
- const effectModuleIdentifierName = pipe(
1634
- findImportedModuleIdentifier(ts)(
1635
- (node2) => isSome2(isImportedEffectModule(node2))
1636
- )(sourceFile),
1637
- map((node2) => node2.text),
1638
- getOrElse(() => "Effect")
1639
- );
1640
- const newDeclaration = transformAsyncAwaitToEffectGen(
1641
- ts
1642
- )(
1643
- node,
1644
- effectModuleIdentifierName,
1645
- (expression) => ts.factory.createCallExpression(
1646
- ts.factory.createPropertyAccessExpression(
1647
- ts.factory.createIdentifier(effectModuleIdentifierName),
1648
- "promise"
1649
- ),
1650
- void 0,
1651
- [
1652
- ts.factory.createArrowFunction(
1653
- void 0,
1654
- void 0,
1655
- [],
1656
- void 0,
1657
- void 0,
1658
- expression
3838
+ apply: pipe(
3839
+ gen2(function* () {
3840
+ const changeTracker = yield* service(ChangeTracker);
3841
+ const effectModuleIdentifierName = match2(
3842
+ yield* option(
3843
+ findImportedModuleIdentifier(
3844
+ sourceFile,
3845
+ (node2) => pipe(
3846
+ importedEffectModule(node2),
3847
+ option,
3848
+ map7(isSome2)
3849
+ )
1659
3850
  )
1660
- ]
1661
- )
1662
- );
1663
- changeTracker.replaceNode(sourceFile, node, newDeclaration);
1664
- }
1665
- }))
1666
- )
3851
+ ),
3852
+ {
3853
+ onNone: () => "Effect",
3854
+ onSome: (node2) => node2.text
3855
+ }
3856
+ );
3857
+ const newDeclaration = yield* transformAsyncAwaitToEffectGen(
3858
+ node,
3859
+ effectModuleIdentifierName,
3860
+ (expression) => ts.factory.createCallExpression(
3861
+ ts.factory.createPropertyAccessExpression(
3862
+ ts.factory.createIdentifier(effectModuleIdentifierName),
3863
+ "promise"
3864
+ ),
3865
+ void 0,
3866
+ [
3867
+ ts.factory.createArrowFunction(
3868
+ void 0,
3869
+ void 0,
3870
+ [],
3871
+ void 0,
3872
+ void 0,
3873
+ expression
3874
+ )
3875
+ ]
3876
+ )
3877
+ );
3878
+ changeTracker.replaceNode(sourceFile, node, newDeclaration);
3879
+ }),
3880
+ provideService(TypeScriptApi, ts),
3881
+ provideService(TypeCheckerApi, typeChecker)
3882
+ )
3883
+ };
3884
+ })
1667
3885
  });
1668
3886
 
1669
3887
  // src/refactors/asyncAwaitToGenTryPromise.ts
1670
3888
  var asyncAwaitToGenTryPromise = createRefactor({
1671
3889
  name: "effect/asyncAwaitToGenTryPromise",
1672
3890
  description: "Convert to Effect.gen with failures",
1673
- apply: (ts, program) => (sourceFile, textRange) => pipe(
1674
- getAncestorNodesInRange(ts)(sourceFile, textRange),
1675
- filter(
1676
- (node) => ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)
1677
- ),
1678
- filter((node) => !!node.body),
1679
- filter(
1680
- (node) => !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)
1681
- ),
1682
- head,
1683
- map((node) => ({
3891
+ apply: (sourceFile, textRange) => gen2(function* () {
3892
+ const ts = yield* service(TypeScriptApi);
3893
+ const typeChecker = yield* service(TypeCheckerApi);
3894
+ const maybeNode = pipe(
3895
+ yield* getAncestorNodesInRange(sourceFile, textRange),
3896
+ filter(
3897
+ (node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
3898
+ ),
3899
+ filter((node2) => !!node2.body),
3900
+ filter(
3901
+ (node2) => !!(ts.getCombinedModifierFlags(node2) & ts.ModifierFlags.Async)
3902
+ ),
3903
+ head
3904
+ );
3905
+ if (isNone2(maybeNode)) return yield* fail3(new RefactorNotApplicableError());
3906
+ const node = maybeNode.value;
3907
+ return {
1684
3908
  kind: "refactor.rewrite.effect.asyncAwaitToGenTryPromise",
1685
3909
  description: "Rewrite to Effect.gen with failures",
1686
- apply: (changeTracker) => {
1687
- const isImportedEffectModule = importedEffectModule(
1688
- ts,
1689
- program.getTypeChecker()
1690
- );
1691
- const effectModuleIdentifierName = pipe(
1692
- findImportedModuleIdentifier(ts)(
1693
- (node2) => isSome2(isImportedEffectModule(node2))
1694
- )(sourceFile),
1695
- map((node2) => node2.text),
1696
- getOrElse(() => "Effect")
1697
- );
1698
- let errorCount = 0;
1699
- function createErrorADT() {
1700
- errorCount++;
1701
- return ts.factory.createObjectLiteralExpression([
1702
- ts.factory.createPropertyAssignment(
1703
- "_tag",
1704
- ts.factory.createAsExpression(
1705
- ts.factory.createStringLiteral("Error" + errorCount),
1706
- ts.factory.createTypeReferenceNode("const")
3910
+ apply: pipe(
3911
+ gen2(function* () {
3912
+ const changeTracker = yield* service(ChangeTracker);
3913
+ const effectModuleIdentifierName = match2(
3914
+ yield* option(
3915
+ findImportedModuleIdentifier(
3916
+ sourceFile,
3917
+ (node2) => pipe(
3918
+ importedEffectModule(node2),
3919
+ option,
3920
+ map7(isSome2)
3921
+ )
1707
3922
  )
1708
3923
  ),
1709
- ts.factory.createShorthandPropertyAssignment("error")
1710
- ]);
1711
- }
1712
- const newDeclaration = transformAsyncAwaitToEffectGen(
1713
- ts
1714
- )(
1715
- node,
1716
- effectModuleIdentifierName,
1717
- (expression) => ts.factory.createCallExpression(
1718
- ts.factory.createPropertyAccessExpression(
1719
- ts.factory.createIdentifier(effectModuleIdentifierName),
1720
- "tryPromise"
1721
- ),
1722
- void 0,
1723
- [
1724
- ts.factory.createObjectLiteralExpression([
1725
- ts.factory.createPropertyAssignment(
1726
- ts.factory.createIdentifier("try"),
1727
- ts.factory.createArrowFunction(
1728
- void 0,
1729
- void 0,
1730
- [],
1731
- void 0,
1732
- void 0,
1733
- expression
1734
- )
1735
- ),
1736
- ts.factory.createPropertyAssignment(
1737
- ts.factory.createIdentifier("catch"),
1738
- ts.factory.createArrowFunction(
1739
- void 0,
1740
- void 0,
1741
- [ts.factory.createParameterDeclaration(void 0, void 0, "error")],
1742
- void 0,
1743
- void 0,
1744
- createErrorADT()
1745
- )
3924
+ {
3925
+ onNone: () => "Effect",
3926
+ onSome: (node2) => node2.text
3927
+ }
3928
+ );
3929
+ let errorCount = 0;
3930
+ function createErrorADT() {
3931
+ errorCount++;
3932
+ return ts.factory.createObjectLiteralExpression([
3933
+ ts.factory.createPropertyAssignment(
3934
+ "_tag",
3935
+ ts.factory.createAsExpression(
3936
+ ts.factory.createStringLiteral("Error" + errorCount),
3937
+ ts.factory.createTypeReferenceNode("const")
1746
3938
  )
1747
- ])
1748
- ]
1749
- )
1750
- );
1751
- changeTracker.replaceNode(sourceFile, node, newDeclaration);
1752
- }
1753
- }))
1754
- )
3939
+ ),
3940
+ ts.factory.createShorthandPropertyAssignment("error")
3941
+ ]);
3942
+ }
3943
+ const newDeclaration = yield* transformAsyncAwaitToEffectGen(
3944
+ node,
3945
+ effectModuleIdentifierName,
3946
+ (expression) => ts.factory.createCallExpression(
3947
+ ts.factory.createPropertyAccessExpression(
3948
+ ts.factory.createIdentifier(effectModuleIdentifierName),
3949
+ "tryPromise"
3950
+ ),
3951
+ void 0,
3952
+ [
3953
+ ts.factory.createObjectLiteralExpression([
3954
+ ts.factory.createPropertyAssignment(
3955
+ ts.factory.createIdentifier("try"),
3956
+ ts.factory.createArrowFunction(
3957
+ void 0,
3958
+ void 0,
3959
+ [],
3960
+ void 0,
3961
+ void 0,
3962
+ expression
3963
+ )
3964
+ ),
3965
+ ts.factory.createPropertyAssignment(
3966
+ ts.factory.createIdentifier("catch"),
3967
+ ts.factory.createArrowFunction(
3968
+ void 0,
3969
+ void 0,
3970
+ [ts.factory.createParameterDeclaration(void 0, void 0, "error")],
3971
+ void 0,
3972
+ void 0,
3973
+ createErrorADT()
3974
+ )
3975
+ )
3976
+ ])
3977
+ ]
3978
+ )
3979
+ );
3980
+ changeTracker.replaceNode(sourceFile, node, newDeclaration);
3981
+ }),
3982
+ provideService(TypeScriptApi, ts),
3983
+ provideService(TypeCheckerApi, typeChecker)
3984
+ )
3985
+ };
3986
+ })
1755
3987
  });
1756
3988
 
1757
3989
  // src/refactors/effectGenToFn.ts
1758
3990
  var effectGenToFn = createRefactor({
1759
3991
  name: "effect/effectGenToFn",
1760
3992
  description: "Convert to Effect.fn",
1761
- apply: (ts, program) => (sourceFile, textRange) => pipe(
1762
- getAncestorNodesInRange(ts)(sourceFile, textRange),
1763
- findFirst2(
1764
- (node) => gen(function* () {
1765
- const effectGen2 = yield* effectGen(ts, program.getTypeChecker())(node);
1766
- let pipeArgs = ts.factory.createNodeArray([]);
1767
- let nodeToReplace = node.parent;
3993
+ apply: (sourceFile, textRange) => gen2(function* () {
3994
+ const ts = yield* service(TypeScriptApi);
3995
+ function parseEffectGenNode(node) {
3996
+ return gen2(function* () {
3997
+ const effectGen2 = yield* effectGen(node);
3998
+ let pipeArgs2 = ts.factory.createNodeArray([]);
3999
+ let nodeToReplace2 = node.parent;
1768
4000
  if (ts.isPropertyAccessExpression(node.parent) && node.parent.name.text === "pipe" && ts.isCallExpression(node.parent.parent)) {
1769
- pipeArgs = node.parent.parent.arguments;
1770
- nodeToReplace = node.parent.parent.parent;
4001
+ pipeArgs2 = node.parent.parent.arguments;
4002
+ nodeToReplace2 = node.parent.parent.parent;
1771
4003
  }
1772
- while (nodeToReplace) {
1773
- if (ts.isArrowFunction(nodeToReplace) || ts.isFunctionDeclaration(nodeToReplace) || ts.isMethodDeclaration(nodeToReplace)) {
1774
- return { ...effectGen2, pipeArgs, nodeToReplace };
4004
+ while (nodeToReplace2) {
4005
+ if (ts.isArrowFunction(nodeToReplace2) || ts.isFunctionDeclaration(nodeToReplace2) || ts.isMethodDeclaration(nodeToReplace2)) {
4006
+ return { ...effectGen2, pipeArgs: pipeArgs2, nodeToReplace: nodeToReplace2 };
1775
4007
  }
1776
- if (ts.isConciseBody(nodeToReplace) || ts.isReturnStatement(nodeToReplace)) {
1777
- nodeToReplace = nodeToReplace.parent;
4008
+ if (ts.isConciseBody(nodeToReplace2) || ts.isReturnStatement(nodeToReplace2)) {
4009
+ nodeToReplace2 = nodeToReplace2.parent;
1778
4010
  continue;
1779
4011
  }
1780
- if (ts.isBlock(nodeToReplace) && nodeToReplace.statements.length === 1) {
1781
- nodeToReplace = nodeToReplace.parent;
4012
+ if (ts.isBlock(nodeToReplace2) && nodeToReplace2.statements.length === 1) {
4013
+ nodeToReplace2 = nodeToReplace2.parent;
1782
4014
  continue;
1783
4015
  }
1784
4016
  break;
1785
4017
  }
1786
- return yield* none2();
1787
- })
1788
- ),
1789
- map(
1790
- ({ effectModule, generatorFunction, nodeToReplace, pipeArgs }) => ({
1791
- kind: "refactor.rewrite.effect.effectGenToFn",
1792
- description: "Convert to Effect.fn",
1793
- apply: (changeTracker) => {
4018
+ return yield* fail3(new RefactorNotApplicableError());
4019
+ });
4020
+ }
4021
+ const maybeNode = yield* pipe(
4022
+ yield* getAncestorNodesInRange(sourceFile, textRange),
4023
+ map2(parseEffectGenNode),
4024
+ firstSuccessOf,
4025
+ option
4026
+ );
4027
+ if (isNone2(maybeNode)) return yield* fail3(new RefactorNotApplicableError());
4028
+ const { effectModule, generatorFunction, nodeToReplace, pipeArgs } = maybeNode.value;
4029
+ return {
4030
+ kind: "refactor.rewrite.effect.effectGenToFn",
4031
+ description: "Convert to Effect.fn",
4032
+ apply: pipe(
4033
+ gen2(function* () {
4034
+ const changeTracker = yield* service(ChangeTracker);
1794
4035
  const effectFn = nodeToReplace.name && ts.isIdentifier(nodeToReplace.name) ? ts.factory.createCallExpression(
1795
4036
  ts.factory.createPropertyAccessExpression(
1796
4037
  effectModule,
@@ -1818,37 +4059,36 @@ var effectGenToFn = createRefactor({
1818
4059
  changeTracker.replaceNode(
1819
4060
  sourceFile,
1820
4061
  nodeToReplace,
1821
- tryPreserveDeclarationSemantics(ts)(nodeToReplace, effectFnCallWithGenerator)
4062
+ yield* tryPreserveDeclarationSemantics(nodeToReplace, effectFnCallWithGenerator)
1822
4063
  );
1823
- }
1824
- })
1825
- )
1826
- )
4064
+ }),
4065
+ provideService(TypeScriptApi, ts)
4066
+ )
4067
+ };
4068
+ })
1827
4069
  });
1828
4070
 
1829
4071
  // src/refactors/functionToArrow.ts
1830
4072
  var functionToArrow = createRefactor({
1831
4073
  name: "effect/functionToArrow",
1832
4074
  description: "Convert to arrow",
1833
- apply: (ts) => (sourceFile, textRange) => pipe(
1834
- pipe(
1835
- getAncestorNodesInRange(ts)(sourceFile, textRange),
1836
- filter(ts.isFunctionDeclaration)
1837
- ),
1838
- appendAll(
1839
- pipe(
1840
- getAncestorNodesInRange(ts)(sourceFile, textRange),
1841
- filter(ts.isMethodDeclaration)
1842
- )
1843
- ),
1844
- filter((node) => !!node.body),
1845
- filter((node) => !!node.name && isNodeInRange(textRange)(node.name)),
1846
- head,
1847
- map(
1848
- (node) => ({
1849
- kind: "refactor.rewrite.effect.functionToArrow",
1850
- description: "Convert to arrow",
1851
- apply: (changeTracker) => {
4075
+ apply: (sourceFile, textRange) => gen2(function* () {
4076
+ const ts = yield* service(TypeScriptApi);
4077
+ const maybeNode = pipe(
4078
+ yield* getAncestorNodesInRange(sourceFile, textRange),
4079
+ filter((_) => ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_)),
4080
+ filter((_) => !!_.body),
4081
+ filter((_) => !!_.name && isNodeInRange(textRange)(_.name)),
4082
+ head
4083
+ );
4084
+ if (isNone2(maybeNode)) return yield* fail3(new RefactorNotApplicableError());
4085
+ const node = maybeNode.value;
4086
+ return {
4087
+ kind: "refactor.rewrite.effect.functionToArrow",
4088
+ description: "Convert to arrow",
4089
+ apply: pipe(
4090
+ gen2(function* () {
4091
+ const changeTracker = yield* service(ChangeTracker);
1852
4092
  const body = node.body;
1853
4093
  let newBody = ts.factory.createBlock(body.statements);
1854
4094
  if (body.statements.length === 1) {
@@ -1869,269 +4109,306 @@ var functionToArrow = createRefactor({
1869
4109
  ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
1870
4110
  newBody
1871
4111
  );
1872
- let constFlags = ts.getCombinedModifierFlags(node);
1873
- constFlags &= ~arrowFlags;
1874
- const constModifiers = ts.factory.createModifiersFromModifierFlags(constFlags);
1875
- let newDeclaration = node;
1876
- if (ts.isMethodDeclaration(node)) {
1877
- newDeclaration = ts.factory.createPropertyDeclaration(
1878
- constModifiers,
1879
- node.name,
1880
- void 0,
1881
- void 0,
1882
- arrowFunction
1883
- );
1884
- } else if (ts.isFunctionDeclaration(node)) {
1885
- newDeclaration = ts.factory.createVariableStatement(
1886
- constModifiers,
1887
- ts.factory.createVariableDeclarationList(
1888
- [
1889
- ts.factory.createVariableDeclaration(
1890
- node.name,
1891
- void 0,
1892
- void 0,
1893
- arrowFunction
1894
- )
1895
- ],
1896
- ts.NodeFlags.Const
1897
- )
1898
- );
1899
- }
1900
- changeTracker.replaceNode(sourceFile, node, newDeclaration);
1901
- }
1902
- })
1903
- )
1904
- )
4112
+ const newDeclaration = yield* tryPreserveDeclarationSemantics(
4113
+ node,
4114
+ arrowFunction
4115
+ );
4116
+ changeTracker.replaceNode(sourceFile, node, newDeclaration, {
4117
+ leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll,
4118
+ trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Exclude
4119
+ });
4120
+ }),
4121
+ provideService(TypeScriptApi, ts)
4122
+ )
4123
+ };
4124
+ })
1905
4125
  });
1906
4126
 
1907
4127
  // src/refactors/pipeableToDatafirst.ts
1908
4128
  var pipeableToDatafirst = createRefactor({
1909
4129
  name: "effect/pipeableToDatafirst",
1910
4130
  description: "Rewrite to datafirst",
1911
- apply: (ts, program) => (sourceFile, textRange) => pipe(
1912
- getAncestorNodesInRange(ts)(sourceFile, textRange),
1913
- filter(isPipeCall(ts)),
1914
- filter((node) => isNodeInRange(textRange)(node.expression)),
1915
- filter(
1916
- (node) => node.arguments.length > 0
1917
- ),
1918
- map2((node) => {
1919
- let newNode = node.arguments[0];
1920
- let didSomething = false;
1921
- for (let i = 1; i < node.arguments.length; i++) {
1922
- const arg = node.arguments[i];
1923
- const a = asDataFirstExpression(ts, program.getTypeChecker())(arg, newNode);
1924
- if (isSome2(a)) {
1925
- newNode = a.value;
1926
- didSomething = true;
1927
- } else {
1928
- if (isPipeCall(ts)(newNode)) {
1929
- newNode = ts.factory.createCallExpression(
1930
- ts.factory.createIdentifier("pipe"),
4131
+ apply: (sourceFile, textRange) => gen2(function* () {
4132
+ const ts = yield* service(TypeScriptApi);
4133
+ const typeChecker = yield* service(TypeCheckerApi);
4134
+ function isPipeCall(node2) {
4135
+ if (!ts.isCallExpression(node2)) return false;
4136
+ const expression = node2.expression;
4137
+ if (!ts.isIdentifier(expression)) return false;
4138
+ if (expression.text !== "pipe") return false;
4139
+ return true;
4140
+ }
4141
+ function asDataFirstExpression(node2, self) {
4142
+ if (!ts.isCallExpression(node2)) return none2();
4143
+ const signature = typeChecker.getResolvedSignature(node2);
4144
+ if (!signature) return none2();
4145
+ const callSignatures = typeChecker.getTypeAtLocation(node2.expression).getCallSignatures();
4146
+ for (let i = 0; i < callSignatures.length; i++) {
4147
+ const callSignature = callSignatures[i];
4148
+ if (callSignature.parameters.length === node2.arguments.length + 1) {
4149
+ return some2(
4150
+ ts.factory.createCallExpression(
4151
+ node2.expression,
1931
4152
  [],
1932
- newNode.arguments.concat([arg])
1933
- );
4153
+ [self].concat(node2.arguments)
4154
+ )
4155
+ );
4156
+ }
4157
+ }
4158
+ return none2();
4159
+ }
4160
+ const maybeNode = pipe(
4161
+ yield* getAncestorNodesInRange(sourceFile, textRange),
4162
+ filter(isPipeCall),
4163
+ filter((node2) => isNodeInRange(textRange)(node2.expression)),
4164
+ filter(
4165
+ (node2) => node2.arguments.length > 0
4166
+ ),
4167
+ map2((node2) => {
4168
+ let newNode2 = node2.arguments[0];
4169
+ let didSomething = false;
4170
+ for (let i = 1; i < node2.arguments.length; i++) {
4171
+ const arg = node2.arguments[i];
4172
+ const a = asDataFirstExpression(arg, newNode2);
4173
+ if (isSome2(a)) {
4174
+ newNode2 = a.value;
4175
+ didSomething = true;
1934
4176
  } else {
1935
- newNode = ts.factory.createCallExpression(ts.factory.createIdentifier("pipe"), [], [
1936
- newNode,
1937
- arg
1938
- ]);
4177
+ if (isPipeCall(newNode2)) {
4178
+ newNode2 = ts.factory.createCallExpression(
4179
+ ts.factory.createIdentifier("pipe"),
4180
+ [],
4181
+ newNode2.arguments.concat([arg])
4182
+ );
4183
+ } else {
4184
+ newNode2 = ts.factory.createCallExpression(ts.factory.createIdentifier("pipe"), [], [
4185
+ newNode2,
4186
+ arg
4187
+ ]);
4188
+ }
1939
4189
  }
1940
4190
  }
1941
- }
1942
- return didSomething ? some2([node, newNode]) : none2();
1943
- }),
1944
- filter(isSome2),
1945
- map2((_) => _.value),
1946
- head,
1947
- map(([node, newNode]) => ({
4191
+ return didSomething ? some2([node2, newNode2]) : none2();
4192
+ }),
4193
+ filter(isSome2),
4194
+ map2((_) => _.value),
4195
+ head
4196
+ );
4197
+ if (isNone2(maybeNode)) return yield* fail3(new RefactorNotApplicableError());
4198
+ const [node, newNode] = maybeNode.value;
4199
+ return {
1948
4200
  kind: "refactor.rewrite.effect.pipeableToDatafirst",
1949
4201
  description: "Rewrite to datafirst",
1950
- apply: (changeTracker) => {
4202
+ apply: gen2(function* () {
4203
+ const changeTracker = yield* service(ChangeTracker);
1951
4204
  changeTracker.replaceNode(sourceFile, node, newNode);
1952
- }
1953
- }))
1954
- )
4205
+ })
4206
+ };
4207
+ })
1955
4208
  });
1956
4209
 
1957
4210
  // src/refactors/removeUnnecessaryEffectGen.ts
1958
4211
  var removeUnnecessaryEffectGen = createRefactor({
1959
4212
  name: "effect/removeUnnecessaryEffectGen",
1960
4213
  description: "Remove unnecessary Effect.gen",
1961
- apply: (ts, program) => (sourceFile, textRange) => {
1962
- const typeChecker = program.getTypeChecker();
1963
- return pipe(
1964
- collectDescendantsAndAncestorsInRange(ts, sourceFile, textRange),
1965
- findFirst2(
1966
- (node) => gen(function* () {
1967
- const returnedYieldedEffect = yield* getSingleReturnEffectFromEffectGen(
1968
- ts,
1969
- typeChecker,
1970
- node
1971
- );
1972
- return { nodeToReplace: node, returnedYieldedEffect };
1973
- })
1974
- ),
1975
- map((a) => ({
4214
+ apply: (sourceFile, textRange) => gen2(function* () {
4215
+ for (const nodeToReplace of yield* collectDescendantsAndAncestorsInRange(
4216
+ sourceFile,
4217
+ textRange
4218
+ )) {
4219
+ const maybeNode = yield* pipe(
4220
+ effectGen(nodeToReplace),
4221
+ flatMap4(({ body }) => returnYieldEffectBlock(body)),
4222
+ option
4223
+ );
4224
+ if (isNone2(maybeNode)) continue;
4225
+ const returnedYieldedEffect = maybeNode.value;
4226
+ return {
1976
4227
  kind: "refactor.rewrite.effect.removeUnnecessaryEffectGen",
1977
4228
  description: "Remove unnecessary Effect.gen",
1978
- apply: (changeTracker) => {
1979
- changeTracker.replaceNode(sourceFile, a.nodeToReplace, a.returnedYieldedEffect);
1980
- }
1981
- }))
1982
- );
1983
- }
4229
+ apply: gen2(function* () {
4230
+ const changeTracker = yield* service(ChangeTracker);
4231
+ changeTracker.replaceNode(sourceFile, nodeToReplace, returnedYieldedEffect);
4232
+ })
4233
+ };
4234
+ }
4235
+ return yield* fail3(new RefactorNotApplicableError());
4236
+ })
1984
4237
  });
1985
4238
 
1986
4239
  // src/refactors/toggleLazyConst.ts
1987
4240
  var toggleLazyConst = createRefactor({
1988
4241
  name: "effect/toggleLazyConst",
1989
4242
  description: "Toggle type annotation",
1990
- apply: (ts) => (sourceFile, textRange) => pipe(
1991
- getAncestorNodesInRange(ts)(sourceFile, textRange),
1992
- filter(ts.isVariableDeclaration),
1993
- filter((node) => isNodeInRange(textRange)(node.name)),
1994
- filter(
1995
- (node) => !!node.initializer && !(ts.isArrowFunction(node.initializer) && ts.isBlock(node.initializer.body))
1996
- ),
1997
- head,
1998
- map(
1999
- (node) => ({
2000
- kind: "refactor.rewrite.effect.toggleLazyConst",
2001
- description: "Toggle lazy const",
2002
- apply: (changeTracker) => {
2003
- const initializer = node.initializer;
2004
- if (ts.isArrowFunction(initializer) && initializer.parameters.length === 0) {
2005
- changeTracker.deleteRange(sourceFile, {
2006
- pos: initializer.body.end,
2007
- end: initializer.end
2008
- });
2009
- changeTracker.deleteRange(sourceFile, {
2010
- pos: initializer.pos,
2011
- end: initializer.body.pos
2012
- });
2013
- return;
2014
- }
2015
- changeTracker.insertText(sourceFile, initializer.pos, " () =>");
4243
+ apply: (sourceFile, textRange) => gen2(function* () {
4244
+ const ts = yield* service(TypeScriptApi);
4245
+ const maybeNode = pipe(
4246
+ yield* getAncestorNodesInRange(sourceFile, textRange),
4247
+ filter(ts.isVariableDeclaration),
4248
+ filter((node2) => isNodeInRange(textRange)(node2.name)),
4249
+ filter(
4250
+ (node2) => !!node2.initializer && !(ts.isArrowFunction(node2.initializer) && ts.isBlock(node2.initializer.body))
4251
+ ),
4252
+ head
4253
+ );
4254
+ if (isNone2(maybeNode)) return yield* fail3(new RefactorNotApplicableError());
4255
+ const node = maybeNode.value;
4256
+ return {
4257
+ kind: "refactor.rewrite.effect.toggleLazyConst",
4258
+ description: "Toggle lazy const",
4259
+ apply: gen2(function* () {
4260
+ const changeTracker = yield* service(ChangeTracker);
4261
+ const initializer = node.initializer;
4262
+ if (ts.isArrowFunction(initializer) && initializer.parameters.length === 0) {
4263
+ changeTracker.deleteRange(sourceFile, {
4264
+ pos: initializer.body.end,
4265
+ end: initializer.end
4266
+ });
4267
+ changeTracker.deleteRange(sourceFile, {
4268
+ pos: initializer.pos,
4269
+ end: initializer.body.pos
4270
+ });
4271
+ return;
2016
4272
  }
4273
+ changeTracker.insertText(sourceFile, initializer.pos, " () =>");
2017
4274
  })
2018
- )
2019
- )
4275
+ };
4276
+ })
2020
4277
  });
2021
4278
 
2022
4279
  // src/refactors/toggleReturnTypeAnnotation.ts
2023
4280
  var toggleReturnTypeAnnotation = createRefactor({
2024
4281
  name: "effect/toggleReturnTypeAnnotation",
2025
4282
  description: "Toggle return type annotation",
2026
- apply: (ts, program) => (sourceFile, textRange) => {
2027
- return gen(function* () {
2028
- const typeChecker = program.getTypeChecker();
2029
- const node = yield* pipe(
2030
- getAncestorNodesInRange(ts)(sourceFile, textRange),
2031
- filter(
2032
- (node2) => ts.isFunctionDeclaration(node2) || ts.isFunctionExpression(node2) || ts.isArrowFunction(node2) || ts.isMethodDeclaration(node2)
2033
- ),
2034
- head
2035
- );
2036
- if (node.type) {
2037
- return {
2038
- kind: "refactor.rewrite.effect.toggleReturnTypeAnnotation",
2039
- description: "Toggle return type annotation",
2040
- apply: (changeTracker) => removeReturnTypeAnnotation(ts, changeTracker)(sourceFile, node)
2041
- };
2042
- }
2043
- const returnType = yield* getInferredReturnType(ts, typeChecker)(node);
2044
- const returnTypeNode = yield* fromNullable(
2045
- typeChecker.typeToTypeNode(returnType, node, ts.NodeBuilderFlags.NoTruncation)
2046
- );
4283
+ apply: (sourceFile, textRange) => gen2(function* () {
4284
+ const ts = yield* service(TypeScriptApi);
4285
+ const typeChecker = yield* service(TypeCheckerApi);
4286
+ const maybeNode = pipe(
4287
+ yield* getAncestorNodesInRange(sourceFile, textRange),
4288
+ filter(
4289
+ (node2) => ts.isFunctionDeclaration(node2) || ts.isFunctionExpression(node2) || ts.isArrowFunction(node2) || ts.isMethodDeclaration(node2)
4290
+ ),
4291
+ head
4292
+ );
4293
+ if (isNone2(maybeNode)) return yield* fail3(new RefactorNotApplicableError());
4294
+ const node = maybeNode.value;
4295
+ if (node.type) {
2047
4296
  return {
2048
4297
  kind: "refactor.rewrite.effect.toggleReturnTypeAnnotation",
2049
4298
  description: "Toggle return type annotation",
2050
- apply: (changeTracker) => {
2051
- addReturnTypeAnnotation(ts, changeTracker)(
2052
- sourceFile,
2053
- node,
2054
- simplifyTypeNode(ts)(returnTypeNode)
2055
- );
2056
- }
4299
+ apply: pipe(
4300
+ removeReturnTypeAnnotation(sourceFile, node),
4301
+ provideService(TypeScriptApi, ts)
4302
+ )
2057
4303
  };
2058
- });
2059
- }
4304
+ }
4305
+ const returnType = yield* option(getInferredReturnType(node));
4306
+ if (isNone2(returnType)) return yield* fail3(new RefactorNotApplicableError());
4307
+ const returnTypeNode = typeChecker.typeToTypeNode(
4308
+ returnType.value,
4309
+ node,
4310
+ ts.NodeBuilderFlags.NoTruncation
4311
+ );
4312
+ if (!returnTypeNode) return yield* fail3(new RefactorNotApplicableError());
4313
+ return {
4314
+ kind: "refactor.rewrite.effect.toggleReturnTypeAnnotation",
4315
+ description: "Toggle return type annotation",
4316
+ apply: pipe(
4317
+ addReturnTypeAnnotation(
4318
+ sourceFile,
4319
+ node,
4320
+ yield* simplifyTypeNode(returnTypeNode)
4321
+ ),
4322
+ provideService(TypeCheckerApi, typeChecker),
4323
+ provideService(TypeScriptApi, ts)
4324
+ )
4325
+ };
4326
+ })
2060
4327
  });
2061
4328
 
2062
4329
  // src/refactors/toggleTypeAnnotation.ts
2063
4330
  var toggleTypeAnnotation = createRefactor({
2064
4331
  name: "effect/toggleTypeAnnotation",
2065
4332
  description: "Toggle type annotation",
2066
- apply: (ts, program) => (sourceFile, textRange) => pipe(
2067
- getAncestorNodesInRange(ts)(sourceFile, textRange),
2068
- filter(
2069
- (node) => ts.isVariableDeclaration(node) || ts.isPropertyDeclaration(node)
2070
- ),
2071
- filter((node) => isNodeInRange(textRange)(node.name)),
2072
- filter((node) => !!node.initializer),
2073
- head,
2074
- map(
2075
- (node) => ({
2076
- kind: "refactor.rewrite.effect.toggleTypeAnnotation",
2077
- description: "Toggle type annotation",
2078
- apply: (changeTracker) => {
2079
- const typeChecker = program.getTypeChecker();
4333
+ apply: (sourceFile, textRange) => gen2(function* () {
4334
+ const ts = yield* service(TypeScriptApi);
4335
+ const typeChecker = yield* service(TypeCheckerApi);
4336
+ const maybeNode = pipe(
4337
+ yield* getAncestorNodesInRange(sourceFile, textRange),
4338
+ filter(
4339
+ (node2) => ts.isVariableDeclaration(node2) || ts.isPropertyDeclaration(node2)
4340
+ ),
4341
+ filter((node2) => isNodeInRange(textRange)(node2.name)),
4342
+ filter((node2) => !!node2.initializer),
4343
+ head
4344
+ );
4345
+ if (isNone2(maybeNode)) return yield* fail3(new RefactorNotApplicableError());
4346
+ const node = maybeNode.value;
4347
+ return {
4348
+ kind: "refactor.rewrite.effect.toggleTypeAnnotation",
4349
+ description: "Toggle type annotation",
4350
+ apply: pipe(
4351
+ gen2(function* () {
4352
+ const changeTracker = yield* service(ChangeTracker);
2080
4353
  if (node.type) {
2081
4354
  changeTracker.deleteRange(sourceFile, { pos: node.name.end, end: node.type.end });
2082
4355
  return;
2083
4356
  }
2084
4357
  const initializer = node.initializer;
2085
4358
  const initializerType = typeChecker.getTypeAtLocation(initializer);
2086
- const initializerTypeNode = fromNullable(typeChecker.typeToTypeNode(
4359
+ const initializerTypeNode = fromNullable2(typeChecker.typeToTypeNode(
2087
4360
  initializerType,
2088
4361
  node,
2089
4362
  ts.NodeBuilderFlags.NoTruncation
2090
4363
  )).pipe(
2091
- orElse(
2092
- () => fromNullable(typeChecker.typeToTypeNode(
4364
+ orElse2(
4365
+ () => fromNullable2(typeChecker.typeToTypeNode(
2093
4366
  initializerType,
2094
4367
  void 0,
2095
4368
  ts.NodeBuilderFlags.NoTruncation
2096
4369
  ))
2097
4370
  ),
2098
- getOrUndefined
4371
+ getOrUndefined2
2099
4372
  );
2100
4373
  if (initializerTypeNode) {
2101
4374
  changeTracker.insertNodeAt(
2102
4375
  sourceFile,
2103
4376
  node.name.end,
2104
- simplifyTypeNode(ts)(initializerTypeNode),
4377
+ yield* simplifyTypeNode(initializerTypeNode),
2105
4378
  {
2106
4379
  prefix: ": "
2107
4380
  }
2108
4381
  );
2109
4382
  }
2110
- }
2111
- })
2112
- )
2113
- )
4383
+ }),
4384
+ provideService(TypeScriptApi, ts)
4385
+ )
4386
+ };
4387
+ })
2114
4388
  });
2115
4389
 
2116
4390
  // src/refactors/wrapWithPipe.ts
2117
4391
  var wrapWithPipe = createRefactor({
2118
4392
  name: "effect/wrapWithPipe",
2119
4393
  description: "Wrap with pipe",
2120
- apply: () => (sourceFile, textRange) => {
2121
- if (textRange.end - textRange.pos === 0) return none2();
2122
- return some2({
4394
+ apply: (sourceFile, textRange) => gen2(function* () {
4395
+ if (textRange.end - textRange.pos === 0) {
4396
+ return yield* fail3(new RefactorNotApplicableError());
4397
+ }
4398
+ return {
2123
4399
  kind: "refactor.rewrite.effect.wrapWithPipe",
2124
4400
  description: `Wrap with pipe(...)`,
2125
- apply: (changeTracker) => {
4401
+ apply: gen2(function* () {
4402
+ const changeTracker = yield* service(ChangeTracker);
2126
4403
  changeTracker.insertText(sourceFile, textRange.pos, "pipe(");
2127
4404
  changeTracker.insertText(sourceFile, textRange.end, ")");
2128
- }
2129
- });
2130
- }
4405
+ })
4406
+ };
4407
+ })
2131
4408
  });
2132
4409
 
2133
4410
  // src/refactors.ts
2134
- var refactors = {
4411
+ var refactors = [
2135
4412
  asyncAwaitToGen,
2136
4413
  asyncAwaitToGenTryPromise,
2137
4414
  functionToArrow,
@@ -2142,11 +4419,10 @@ var refactors = {
2142
4419
  toggleTypeAnnotation,
2143
4420
  wrapWithPipe,
2144
4421
  effectGenToFn
2145
- };
4422
+ ];
2146
4423
 
2147
4424
  // src/index.ts
2148
4425
  var init = (modules) => {
2149
- const ts = modules.typescript;
2150
4426
  function create(info) {
2151
4427
  const languageService = info.languageService;
2152
4428
  const pluginOptions = {
@@ -2161,35 +4437,18 @@ var init = (modules) => {
2161
4437
  const applicableDiagnostics = languageService.getSemanticDiagnostics(fileName, ...args);
2162
4438
  const program = languageService.getProgram();
2163
4439
  if (pluginOptions.diagnostics && program) {
2164
- const effectDiagnostics = pipe(
2165
- fromNullable(program.getSourceFile(fileName)),
2166
- map(
2167
- (sourceFile) => pipe(
2168
- Object.values(diagnostics).map(
2169
- (diagnostic) => pipe(
2170
- diagnostic.apply(modules.typescript, program, pluginOptions)(
2171
- sourceFile,
2172
- applicableDiagnostics
2173
- ).map((_) => ({
2174
- file: sourceFile,
2175
- start: _.node.getStart(sourceFile),
2176
- length: _.node.getEnd() - _.node.getStart(sourceFile),
2177
- messageText: _.messageText,
2178
- category: _.category,
2179
- code: diagnostic.code,
2180
- source: "effect"
2181
- }))
2182
- )
2183
- ),
2184
- (_) => _.reduce(
2185
- (arr, maybeRefactor) => arr.concat(maybeRefactor),
2186
- []
2187
- )
2188
- )
2189
- ),
2190
- getOrElse(() => [])
2191
- );
2192
- return effectDiagnostics.concat(applicableDiagnostics);
4440
+ const sourceFile = program.getSourceFile(fileName);
4441
+ if (sourceFile) {
4442
+ return pipe(
4443
+ getSemanticDiagnostics(diagnostics, sourceFile),
4444
+ provideService(TypeScriptApi, modules.typescript),
4445
+ provideService(TypeCheckerApi, program.getTypeChecker()),
4446
+ provideService(PluginOptions, pluginOptions),
4447
+ run,
4448
+ Either_exports.map((effectDiagnostics) => effectDiagnostics.concat(applicableDiagnostics)),
4449
+ Either_exports.getOrElse(() => applicableDiagnostics)
4450
+ );
4451
+ }
2193
4452
  }
2194
4453
  return applicableDiagnostics;
2195
4454
  };
@@ -2198,78 +4457,58 @@ var init = (modules) => {
2198
4457
  const [fileName, positionOrRange] = args;
2199
4458
  const program = languageService.getProgram();
2200
4459
  if (program) {
2201
- const textRange = toTextRange(positionOrRange);
2202
- const effectRefactors = pipe(
2203
- fromNullable(program.getSourceFile(fileName)),
2204
- map(
2205
- (sourceFile) => pipe(
2206
- Object.values(refactors).map(
2207
- (refactor) => pipe(
2208
- refactor.apply(modules.typescript, program, pluginOptions)(
2209
- sourceFile,
2210
- textRange
2211
- ),
2212
- map((_) => ({
2213
- name: refactor.name,
2214
- description: refactor.description,
2215
- actions: [{
2216
- name: refactor.name,
2217
- description: _.description,
2218
- kind: _.kind
2219
- }]
2220
- }))
2221
- )
2222
- ),
2223
- (_) => _.reduce(
2224
- (arr, maybeRefactor) => arr.concat(isSome2(maybeRefactor) ? [maybeRefactor.value] : []),
2225
- []
2226
- )
2227
- )
2228
- ),
2229
- getOrElse(() => [])
2230
- );
2231
- info.project.projectService.logger.info(
2232
- "[@effect/language-service] possible refactors are " + JSON.stringify(effectRefactors)
2233
- );
2234
- return applicableRefactors.concat(effectRefactors);
4460
+ const sourceFile = program.getSourceFile(fileName);
4461
+ if (sourceFile) {
4462
+ return pipe(
4463
+ getApplicableRefactors(refactors, sourceFile, positionOrRange),
4464
+ provideService(TypeScriptApi, modules.typescript),
4465
+ provideService(TypeCheckerApi, program.getTypeChecker()),
4466
+ provideService(PluginOptions, pluginOptions),
4467
+ run,
4468
+ Either_exports.map((effectRefactors) => applicableRefactors.concat(effectRefactors)),
4469
+ Either_exports.getOrElse(() => applicableRefactors)
4470
+ );
4471
+ }
2235
4472
  }
2236
4473
  return applicableRefactors;
2237
4474
  };
2238
4475
  proxy.getEditsForRefactor = (fileName, formatOptions, positionOrRange, refactorName, actionName, preferences, ...args) => {
2239
4476
  const program = languageService.getProgram();
2240
4477
  if (program) {
2241
- for (const refactor of Object.values(refactors)) {
2242
- if (refactor.name === refactorName) {
2243
- const textRange = toTextRange(positionOrRange);
2244
- const possibleRefactor = pipe(
2245
- fromNullable(program.getSourceFile(fileName)),
2246
- flatMap(
2247
- (sourceFile) => refactor.apply(modules.typescript, program, pluginOptions)(
2248
- sourceFile,
2249
- textRange
4478
+ const sourceFile = program.getSourceFile(fileName);
4479
+ if (sourceFile) {
4480
+ const result = pipe(
4481
+ gen2(function* () {
4482
+ const applicableRefactor = yield* getEditsForRefactor(
4483
+ refactors,
4484
+ sourceFile,
4485
+ positionOrRange,
4486
+ refactorName
4487
+ );
4488
+ const formatContext = modules.typescript.formatting.getFormatContext(
4489
+ formatOptions,
4490
+ info.languageServiceHost
4491
+ );
4492
+ const edits = modules.typescript.textChanges.ChangeTracker.with(
4493
+ {
4494
+ formatContext,
4495
+ host: info.languageServiceHost,
4496
+ preferences: preferences || {}
4497
+ },
4498
+ (changeTracker) => pipe(
4499
+ applicableRefactor.apply,
4500
+ provideService(ChangeTracker, changeTracker),
4501
+ run
2250
4502
  )
2251
- )
2252
- );
2253
- if (isNone2(possibleRefactor)) {
2254
- info.project.projectService.logger.info(
2255
- "[@effect/language-service] requested refactor " + refactorName + " is not applicable"
2256
4503
  );
2257
- return { edits: [] };
2258
- }
2259
- const formatContext = ts.formatting.getFormatContext(
2260
- formatOptions,
2261
- info.languageServiceHost
2262
- );
2263
- const edits = ts.textChanges.ChangeTracker.with(
2264
- {
2265
- formatContext,
2266
- host: info.languageServiceHost,
2267
- preferences: preferences || {}
2268
- },
2269
- (changeTracker) => possibleRefactor.value.apply(changeTracker)
2270
- );
2271
- return { edits };
2272
- }
4504
+ return { edits };
4505
+ }),
4506
+ provideService(TypeScriptApi, modules.typescript),
4507
+ provideService(TypeCheckerApi, program.getTypeChecker()),
4508
+ provideService(PluginOptions, pluginOptions),
4509
+ run
4510
+ );
4511
+ if (Either_exports.isRight(result)) return result.right;
2273
4512
  }
2274
4513
  }
2275
4514
  return languageService.getEditsForRefactor(
@@ -2288,7 +4527,20 @@ var init = (modules) => {
2288
4527
  const dedupedTagsQuickInfo = dedupeJsDocTags(quickInfo);
2289
4528
  const program = languageService.getProgram();
2290
4529
  if (program) {
2291
- return prependEffectTypeArguments(ts, program)(fileName, position, dedupedTagsQuickInfo);
4530
+ const sourceFile = program.getSourceFile(fileName);
4531
+ if (sourceFile) {
4532
+ return pipe(
4533
+ prependEffectTypeArguments(
4534
+ sourceFile,
4535
+ position,
4536
+ dedupedTagsQuickInfo
4537
+ ),
4538
+ provideService(TypeScriptApi, modules.typescript),
4539
+ provideService(TypeCheckerApi, program.getTypeChecker()),
4540
+ run,
4541
+ Either_exports.getOrElse(() => dedupedTagsQuickInfo)
4542
+ );
4543
+ }
2292
4544
  }
2293
4545
  return dedupedTagsQuickInfo;
2294
4546
  }