@effect/language-service 0.3.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js ADDED
@@ -0,0 +1,2102 @@
1
+ "use strict";
2
+
3
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Function.js
4
+ var isFunction = (input) => typeof input === "function";
5
+ var dual = function(arity, body) {
6
+ if (typeof arity === "function") {
7
+ return function() {
8
+ if (arity(arguments)) {
9
+ return body.apply(this, arguments);
10
+ }
11
+ return (self) => body(self, ...arguments);
12
+ };
13
+ }
14
+ switch (arity) {
15
+ case 0:
16
+ case 1:
17
+ throw new RangeError(`Invalid arity ${arity}`);
18
+ case 2:
19
+ return function(a, b) {
20
+ if (arguments.length >= 2) {
21
+ return body(a, b);
22
+ }
23
+ return function(self) {
24
+ return body(self, a);
25
+ };
26
+ };
27
+ case 3:
28
+ return function(a, b, c) {
29
+ if (arguments.length >= 3) {
30
+ return body(a, b, c);
31
+ }
32
+ return function(self) {
33
+ return body(self, a, b);
34
+ };
35
+ };
36
+ case 4:
37
+ return function(a, b, c, d) {
38
+ if (arguments.length >= 4) {
39
+ return body(a, b, c, d);
40
+ }
41
+ return function(self) {
42
+ return body(self, a, b, c);
43
+ };
44
+ };
45
+ case 5:
46
+ return function(a, b, c, d, e) {
47
+ if (arguments.length >= 5) {
48
+ return body(a, b, c, d, e);
49
+ }
50
+ return function(self) {
51
+ return body(self, a, b, c, d);
52
+ };
53
+ };
54
+ default:
55
+ return function() {
56
+ if (arguments.length >= arity) {
57
+ return body.apply(this, arguments);
58
+ }
59
+ const args = arguments;
60
+ return function(self) {
61
+ return body(self, ...args);
62
+ };
63
+ };
64
+ }
65
+ };
66
+ var identity = (a) => a;
67
+ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
68
+ switch (arguments.length) {
69
+ case 1:
70
+ return a;
71
+ case 2:
72
+ return ab(a);
73
+ case 3:
74
+ return bc(ab(a));
75
+ case 4:
76
+ return cd(bc(ab(a)));
77
+ case 5:
78
+ return de(cd(bc(ab(a))));
79
+ case 6:
80
+ return ef(de(cd(bc(ab(a)))));
81
+ case 7:
82
+ return fg(ef(de(cd(bc(ab(a))))));
83
+ case 8:
84
+ return gh(fg(ef(de(cd(bc(ab(a)))))));
85
+ case 9:
86
+ return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
87
+ default: {
88
+ let ret = arguments[0];
89
+ for (let i = 1; i < arguments.length; i++) {
90
+ ret = arguments[i](ret);
91
+ }
92
+ return ret;
93
+ }
94
+ }
95
+ }
96
+
97
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/version.js
98
+ var moduleVersion = "3.12.5";
99
+ var getCurrentVersion = () => moduleVersion;
100
+
101
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/GlobalValue.js
102
+ var globalStoreId = `effect/GlobalValue/globalStoreId/${/* @__PURE__ */ getCurrentVersion()}`;
103
+ var globalStore;
104
+ var globalValue = (id, compute) => {
105
+ if (!globalStore) {
106
+ globalThis[globalStoreId] ??= /* @__PURE__ */ new Map();
107
+ globalStore = globalThis[globalStoreId];
108
+ }
109
+ if (!globalStore.has(id)) {
110
+ globalStore.set(id, compute());
111
+ }
112
+ return globalStore.get(id);
113
+ };
114
+
115
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Predicate.js
116
+ var isFunction2 = isFunction;
117
+ var isRecordOrArray = (input) => typeof input === "object" && input !== null;
118
+ var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
119
+ var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObject(self) && property in self);
120
+
121
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/errors.js
122
+ var getBugErrorMessage = (message) => `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`;
123
+
124
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Utils.js
125
+ var GenKindTypeId = /* @__PURE__ */ Symbol.for("effect/Gen/GenKind");
126
+ var isGenKind = (u) => isObject(u) && GenKindTypeId in u;
127
+ var GenKindImpl = class {
128
+ value;
129
+ constructor(value) {
130
+ this.value = value;
131
+ }
132
+ /**
133
+ * @since 2.0.0
134
+ */
135
+ get _F() {
136
+ return identity;
137
+ }
138
+ /**
139
+ * @since 2.0.0
140
+ */
141
+ get _R() {
142
+ return (_) => _;
143
+ }
144
+ /**
145
+ * @since 2.0.0
146
+ */
147
+ get _O() {
148
+ return (_) => _;
149
+ }
150
+ /**
151
+ * @since 2.0.0
152
+ */
153
+ get _E() {
154
+ return (_) => _;
155
+ }
156
+ /**
157
+ * @since 2.0.0
158
+ */
159
+ [GenKindTypeId] = GenKindTypeId;
160
+ /**
161
+ * @since 2.0.0
162
+ */
163
+ [Symbol.iterator]() {
164
+ return new SingleShotGen(this);
165
+ }
166
+ };
167
+ var SingleShotGen = class _SingleShotGen {
168
+ self;
169
+ called = false;
170
+ constructor(self) {
171
+ this.self = self;
172
+ }
173
+ /**
174
+ * @since 2.0.0
175
+ */
176
+ next(a) {
177
+ return this.called ? {
178
+ value: a,
179
+ done: true
180
+ } : (this.called = true, {
181
+ value: this.self,
182
+ done: false
183
+ });
184
+ }
185
+ /**
186
+ * @since 2.0.0
187
+ */
188
+ return(a) {
189
+ return {
190
+ value: a,
191
+ done: true
192
+ };
193
+ }
194
+ /**
195
+ * @since 2.0.0
196
+ */
197
+ throw(e) {
198
+ throw e;
199
+ }
200
+ /**
201
+ * @since 2.0.0
202
+ */
203
+ [Symbol.iterator]() {
204
+ return new _SingleShotGen(this.self);
205
+ }
206
+ };
207
+ var adapter = () => function() {
208
+ let x = arguments[0];
209
+ for (let i = 1; i < arguments.length; i++) {
210
+ x = arguments[i](x);
211
+ }
212
+ return new GenKindImpl(x);
213
+ };
214
+ var MUL_HI = 1481765933 >>> 0;
215
+ var MUL_LO = 1284865837 >>> 0;
216
+ var YieldWrapTypeId = /* @__PURE__ */ Symbol.for("effect/Utils/YieldWrap");
217
+ var YieldWrap = class {
218
+ /**
219
+ * @since 3.0.6
220
+ */
221
+ #value;
222
+ constructor(value) {
223
+ this.#value = value;
224
+ }
225
+ /**
226
+ * @since 3.0.6
227
+ */
228
+ [YieldWrapTypeId]() {
229
+ return this.#value;
230
+ }
231
+ };
232
+ function yieldWrapGet(self) {
233
+ if (typeof self === "object" && self !== null && YieldWrapTypeId in self) {
234
+ return self[YieldWrapTypeId]();
235
+ }
236
+ throw new Error(getBugErrorMessage("yieldWrapGet"));
237
+ }
238
+ var structuralRegionState = /* @__PURE__ */ globalValue("effect/Utils/isStructuralRegion", () => ({
239
+ enabled: false,
240
+ tester: void 0
241
+ }));
242
+ var genConstructor = function* () {
243
+ }.constructor;
244
+
245
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Hash.js
246
+ var randomHashCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Hash/randomHashCache"), () => /* @__PURE__ */ new WeakMap());
247
+ var symbol = /* @__PURE__ */ Symbol.for("effect/Hash");
248
+ var hash = (self) => {
249
+ if (structuralRegionState.enabled === true) {
250
+ return 0;
251
+ }
252
+ switch (typeof self) {
253
+ case "number":
254
+ return number(self);
255
+ case "bigint":
256
+ return string(self.toString(10));
257
+ case "boolean":
258
+ return string(String(self));
259
+ case "symbol":
260
+ return string(String(self));
261
+ case "string":
262
+ return string(self);
263
+ case "undefined":
264
+ return string("undefined");
265
+ case "function":
266
+ case "object": {
267
+ if (self === null) {
268
+ return string("null");
269
+ } else if (self instanceof Date) {
270
+ return hash(self.toISOString());
271
+ } else if (isHash(self)) {
272
+ return self[symbol]();
273
+ } else {
274
+ return random(self);
275
+ }
276
+ }
277
+ default:
278
+ throw new Error(`BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`);
279
+ }
280
+ };
281
+ var random = (self) => {
282
+ if (!randomHashCache.has(self)) {
283
+ randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)));
284
+ }
285
+ return randomHashCache.get(self);
286
+ };
287
+ var combine = (b) => (self) => self * 53 ^ b;
288
+ var optimize = (n) => n & 3221225471 | n >>> 1 & 1073741824;
289
+ var isHash = (u) => hasProperty(u, symbol);
290
+ var number = (n) => {
291
+ if (n !== n || n === Infinity) {
292
+ return 0;
293
+ }
294
+ let h = n | 0;
295
+ if (h !== n) {
296
+ h ^= n * 4294967295;
297
+ }
298
+ while (n > 4294967295) {
299
+ h ^= n /= 4294967295;
300
+ }
301
+ return optimize(h);
302
+ };
303
+ var string = (str) => {
304
+ let h = 5381, i = str.length;
305
+ while (i) {
306
+ h = h * 33 ^ str.charCodeAt(--i);
307
+ }
308
+ return optimize(h);
309
+ };
310
+ var structureKeys = (o, keys) => {
311
+ let h = 12289;
312
+ for (let i = 0; i < keys.length; i++) {
313
+ h ^= pipe(string(keys[i]), combine(hash(o[keys[i]])));
314
+ }
315
+ return optimize(h);
316
+ };
317
+ var structure = (o) => structureKeys(o, Object.keys(o));
318
+ var cached = function() {
319
+ if (arguments.length === 1) {
320
+ const self2 = arguments[0];
321
+ return function(hash3) {
322
+ Object.defineProperty(self2, symbol, {
323
+ value() {
324
+ return hash3;
325
+ },
326
+ enumerable: false
327
+ });
328
+ return hash3;
329
+ };
330
+ }
331
+ const self = arguments[0];
332
+ const hash2 = arguments[1];
333
+ Object.defineProperty(self, symbol, {
334
+ value() {
335
+ return hash2;
336
+ },
337
+ enumerable: false
338
+ });
339
+ return hash2;
340
+ };
341
+
342
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Equal.js
343
+ var symbol2 = /* @__PURE__ */ Symbol.for("effect/Equal");
344
+ function equals() {
345
+ if (arguments.length === 1) {
346
+ return (self) => compareBoth(self, arguments[0]);
347
+ }
348
+ return compareBoth(arguments[0], arguments[1]);
349
+ }
350
+ function compareBoth(self, that) {
351
+ if (self === that) {
352
+ return true;
353
+ }
354
+ const selfType = typeof self;
355
+ if (selfType !== typeof that) {
356
+ return false;
357
+ }
358
+ if (selfType === "object" || selfType === "function") {
359
+ if (self !== null && that !== null) {
360
+ if (isEqual(self) && isEqual(that)) {
361
+ if (hash(self) === hash(that) && self[symbol2](that)) {
362
+ return true;
363
+ } else {
364
+ return structuralRegionState.enabled && structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
365
+ }
366
+ } else if (self instanceof Date && that instanceof Date) {
367
+ return self.toISOString() === that.toISOString();
368
+ }
369
+ }
370
+ if (structuralRegionState.enabled) {
371
+ if (Array.isArray(self) && Array.isArray(that)) {
372
+ return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]));
373
+ }
374
+ if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {
375
+ const keysSelf = Object.keys(self);
376
+ const keysThat = Object.keys(that);
377
+ if (keysSelf.length === keysThat.length) {
378
+ for (const key of keysSelf) {
379
+ if (!(key in that && compareBoth(self[key], that[key]))) {
380
+ return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
381
+ }
382
+ }
383
+ return true;
384
+ }
385
+ }
386
+ return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
387
+ }
388
+ }
389
+ return structuralRegionState.enabled && structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
390
+ }
391
+ var isEqual = (u) => hasProperty(u, symbol2);
392
+
393
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Equivalence.js
394
+ var make = (isEquivalent) => (self, that) => self === that || isEquivalent(self, that);
395
+ var array = (item) => make((self, that) => {
396
+ if (self.length !== that.length) {
397
+ return false;
398
+ }
399
+ for (let i = 0; i < self.length; i++) {
400
+ const isEq = item(self[i], that[i]);
401
+ if (!isEq) {
402
+ return false;
403
+ }
404
+ }
405
+ return true;
406
+ });
407
+
408
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Inspectable.js
409
+ var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
410
+ var toJSON = (x) => {
411
+ try {
412
+ if (hasProperty(x, "toJSON") && isFunction2(x["toJSON"]) && x["toJSON"].length === 0) {
413
+ return x.toJSON();
414
+ } else if (Array.isArray(x)) {
415
+ return x.map(toJSON);
416
+ }
417
+ } catch (_) {
418
+ return {};
419
+ }
420
+ return redact(x);
421
+ };
422
+ var format = (x) => JSON.stringify(x, null, 2);
423
+ var BaseProto = {
424
+ toJSON() {
425
+ return toJSON(this);
426
+ },
427
+ [NodeInspectSymbol]() {
428
+ return this.toJSON();
429
+ },
430
+ toString() {
431
+ return format(this.toJSON());
432
+ }
433
+ };
434
+ var Class = class {
435
+ /**
436
+ * @since 2.0.0
437
+ */
438
+ [NodeInspectSymbol]() {
439
+ return this.toJSON();
440
+ }
441
+ /**
442
+ * @since 2.0.0
443
+ */
444
+ toString() {
445
+ return format(this.toJSON());
446
+ }
447
+ };
448
+ var symbolRedactable = /* @__PURE__ */ Symbol.for("effect/Inspectable/Redactable");
449
+ var isRedactable = (u) => typeof u === "object" && u !== null && symbolRedactable in u;
450
+ var redactableState = /* @__PURE__ */ globalValue("effect/Inspectable/redactableState", () => ({
451
+ fiberRefs: void 0
452
+ }));
453
+ var redact = (u) => {
454
+ if (isRedactable(u) && redactableState.fiberRefs !== void 0) {
455
+ return u[symbolRedactable](redactableState.fiberRefs);
456
+ }
457
+ return u;
458
+ };
459
+
460
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Pipeable.js
461
+ var pipeArguments = (self, args) => {
462
+ switch (args.length) {
463
+ case 0:
464
+ return self;
465
+ case 1:
466
+ return args[0](self);
467
+ case 2:
468
+ return args[1](args[0](self));
469
+ case 3:
470
+ return args[2](args[1](args[0](self)));
471
+ case 4:
472
+ return args[3](args[2](args[1](args[0](self))));
473
+ case 5:
474
+ return args[4](args[3](args[2](args[1](args[0](self)))));
475
+ case 6:
476
+ return args[5](args[4](args[3](args[2](args[1](args[0](self))))));
477
+ case 7:
478
+ return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))));
479
+ case 8:
480
+ return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))));
481
+ case 9:
482
+ return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))));
483
+ default: {
484
+ let ret = self;
485
+ for (let i = 0, len = args.length; i < len; i++) {
486
+ ret = args[i](ret);
487
+ }
488
+ return ret;
489
+ }
490
+ }
491
+ };
492
+
493
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/opCodes/effect.js
494
+ var OP_COMMIT = "Commit";
495
+
496
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/effectable.js
497
+ var EffectTypeId = /* @__PURE__ */ Symbol.for("effect/Effect");
498
+ var StreamTypeId = /* @__PURE__ */ Symbol.for("effect/Stream");
499
+ var SinkTypeId = /* @__PURE__ */ Symbol.for("effect/Sink");
500
+ var ChannelTypeId = /* @__PURE__ */ Symbol.for("effect/Channel");
501
+ var effectVariance = {
502
+ /* c8 ignore next */
503
+ _R: (_) => _,
504
+ /* c8 ignore next */
505
+ _E: (_) => _,
506
+ /* c8 ignore next */
507
+ _A: (_) => _,
508
+ _V: /* @__PURE__ */ getCurrentVersion()
509
+ };
510
+ var sinkVariance = {
511
+ /* c8 ignore next */
512
+ _A: (_) => _,
513
+ /* c8 ignore next */
514
+ _In: (_) => _,
515
+ /* c8 ignore next */
516
+ _L: (_) => _,
517
+ /* c8 ignore next */
518
+ _E: (_) => _,
519
+ /* c8 ignore next */
520
+ _R: (_) => _
521
+ };
522
+ var channelVariance = {
523
+ /* c8 ignore next */
524
+ _Env: (_) => _,
525
+ /* c8 ignore next */
526
+ _InErr: (_) => _,
527
+ /* c8 ignore next */
528
+ _InElem: (_) => _,
529
+ /* c8 ignore next */
530
+ _InDone: (_) => _,
531
+ /* c8 ignore next */
532
+ _OutErr: (_) => _,
533
+ /* c8 ignore next */
534
+ _OutElem: (_) => _,
535
+ /* c8 ignore next */
536
+ _OutDone: (_) => _
537
+ };
538
+ var EffectPrototype = {
539
+ [EffectTypeId]: effectVariance,
540
+ [StreamTypeId]: effectVariance,
541
+ [SinkTypeId]: sinkVariance,
542
+ [ChannelTypeId]: channelVariance,
543
+ [symbol2](that) {
544
+ return this === that;
545
+ },
546
+ [symbol]() {
547
+ return cached(this, random(this));
548
+ },
549
+ [Symbol.iterator]() {
550
+ return new SingleShotGen(new YieldWrap(this));
551
+ },
552
+ pipe() {
553
+ return pipeArguments(this, arguments);
554
+ }
555
+ };
556
+ var StructuralPrototype = {
557
+ [symbol]() {
558
+ return cached(this, structure(this));
559
+ },
560
+ [symbol2](that) {
561
+ const selfKeys = Object.keys(this);
562
+ const thatKeys = Object.keys(that);
563
+ if (selfKeys.length !== thatKeys.length) {
564
+ return false;
565
+ }
566
+ for (const key of selfKeys) {
567
+ if (!(key in that && equals(this[key], that[key]))) {
568
+ return false;
569
+ }
570
+ }
571
+ return true;
572
+ }
573
+ };
574
+ var CommitPrototype = {
575
+ ...EffectPrototype,
576
+ _op: OP_COMMIT
577
+ };
578
+ var StructuralCommitPrototype = {
579
+ ...CommitPrototype,
580
+ ...StructuralPrototype
581
+ };
582
+
583
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/option.js
584
+ var TypeId = /* @__PURE__ */ Symbol.for("effect/Option");
585
+ var CommonProto = {
586
+ ...EffectPrototype,
587
+ [TypeId]: {
588
+ _A: (_) => _
589
+ },
590
+ [NodeInspectSymbol]() {
591
+ return this.toJSON();
592
+ },
593
+ toString() {
594
+ return format(this.toJSON());
595
+ }
596
+ };
597
+ var SomeProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto), {
598
+ _tag: "Some",
599
+ _op: "Some",
600
+ [symbol2](that) {
601
+ return isOption(that) && isSome(that) && equals(this.value, that.value);
602
+ },
603
+ [symbol]() {
604
+ return cached(this, combine(hash(this._tag))(hash(this.value)));
605
+ },
606
+ toJSON() {
607
+ return {
608
+ _id: "Option",
609
+ _tag: this._tag,
610
+ value: toJSON(this.value)
611
+ };
612
+ }
613
+ });
614
+ var NoneHash = /* @__PURE__ */ hash("None");
615
+ var NoneProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto), {
616
+ _tag: "None",
617
+ _op: "None",
618
+ [symbol2](that) {
619
+ return isOption(that) && isNone(that);
620
+ },
621
+ [symbol]() {
622
+ return NoneHash;
623
+ },
624
+ toJSON() {
625
+ return {
626
+ _id: "Option",
627
+ _tag: this._tag
628
+ };
629
+ }
630
+ });
631
+ var isOption = (input) => hasProperty(input, TypeId);
632
+ var isNone = (fa) => fa._tag === "None";
633
+ var isSome = (fa) => fa._tag === "Some";
634
+ var none = /* @__PURE__ */ Object.create(NoneProto);
635
+ var some = (value) => {
636
+ const a = Object.create(SomeProto);
637
+ a.value = value;
638
+ return a;
639
+ };
640
+
641
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Order.js
642
+ var make2 = (compare) => (self, that) => self === that ? 0 : compare(self, that);
643
+
644
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Option.js
645
+ var none2 = () => none;
646
+ var some2 = some;
647
+ var isNone2 = isNone;
648
+ var isSome2 = isSome;
649
+ var getOrElse = /* @__PURE__ */ dual(2, (self, onNone) => isNone2(self) ? onNone() : self.value);
650
+ var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : self);
651
+ var fromNullable = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
652
+ var map = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() : some2(f(self.value)));
653
+ var flatMap = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() : f(self.value));
654
+ var all = (input) => {
655
+ if (Symbol.iterator in input) {
656
+ const out2 = [];
657
+ for (const o of input) {
658
+ if (isNone2(o)) {
659
+ return none2();
660
+ }
661
+ out2.push(o.value);
662
+ }
663
+ return some2(out2);
664
+ }
665
+ const out = {};
666
+ for (const key of Object.keys(input)) {
667
+ const o = input[key];
668
+ if (isNone2(o)) {
669
+ return none2();
670
+ }
671
+ out[key] = o.value;
672
+ }
673
+ return some2(out);
674
+ };
675
+ var adapter2 = /* @__PURE__ */ adapter();
676
+ var gen = (...args) => {
677
+ let f;
678
+ if (args.length === 1) {
679
+ f = args[0];
680
+ } else {
681
+ f = args[1].bind(args[0]);
682
+ }
683
+ const iterator = f(adapter2);
684
+ let state = iterator.next();
685
+ if (state.done) {
686
+ return some2(state.value);
687
+ } else {
688
+ let current = state.value;
689
+ if (isGenKind(current)) {
690
+ current = current.value;
691
+ } else {
692
+ current = yieldWrapGet(current);
693
+ }
694
+ if (isNone2(current)) {
695
+ return current;
696
+ }
697
+ while (!state.done) {
698
+ state = iterator.next(current.value);
699
+ if (!state.done) {
700
+ current = state.value;
701
+ if (isGenKind(current)) {
702
+ current = current.value;
703
+ } else {
704
+ current = yieldWrapGet(current);
705
+ }
706
+ if (isNone2(current)) {
707
+ return current;
708
+ }
709
+ }
710
+ }
711
+ return some2(state.value);
712
+ }
713
+ };
714
+
715
+ // src/definition.ts
716
+ function createRefactor(definition) {
717
+ return definition;
718
+ }
719
+ function createDiagnostic(definition) {
720
+ return definition;
721
+ }
722
+
723
+ // src/utils/TypeParser.ts
724
+ var covariantTypeArgument = (type) => {
725
+ const signatures = type.getCallSignatures();
726
+ if (signatures.length !== 1) return none2();
727
+ return some2(signatures[0].getReturnType());
728
+ };
729
+ function pipeableType(ts, typeChecker) {
730
+ return (type, atLocation) => {
731
+ const pipeSymbol = typeChecker.getPropertyOfType(type, "pipe");
732
+ if (!pipeSymbol) return none2();
733
+ const pipeType = typeChecker.getTypeOfSymbolAtLocation(pipeSymbol, atLocation);
734
+ const signatures = pipeType.getCallSignatures();
735
+ if (signatures.length === 0) return none2();
736
+ return some2(type);
737
+ };
738
+ }
739
+ function varianceStructCovariantType(ts, typeChecker) {
740
+ return (type, atLocation, propertyName) => gen(function* (_) {
741
+ const propertySymbol = yield* fromNullable(
742
+ typeChecker.getPropertyOfType(type, propertyName)
743
+ );
744
+ const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
745
+ return yield* covariantTypeArgument(propertyType);
746
+ });
747
+ }
748
+ function effectVarianceStruct(ts, typeChecker) {
749
+ return (type, atLocation) => all({
750
+ A: varianceStructCovariantType(ts, typeChecker)(type, atLocation, "_A"),
751
+ E: varianceStructCovariantType(ts, typeChecker)(type, atLocation, "_E"),
752
+ R: varianceStructCovariantType(ts, typeChecker)(type, atLocation, "_R")
753
+ });
754
+ }
755
+ function effectType(ts, typeChecker) {
756
+ return (type, atLocation) => gen(function* (_) {
757
+ yield* pipeableType(ts, typeChecker)(type, atLocation);
758
+ for (const propertySymbol of typeChecker.getPropertiesOfType(type)) {
759
+ const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
760
+ const varianceArgs = effectVarianceStruct(ts, typeChecker)(
761
+ propertyType,
762
+ atLocation
763
+ );
764
+ if (isSome2(varianceArgs)) {
765
+ return yield* varianceArgs;
766
+ }
767
+ }
768
+ return yield* none2();
769
+ });
770
+ }
771
+ function fiberType(ts, typeChecker) {
772
+ return (type, atLocation) => gen(function* (_) {
773
+ const awaitSymbol = yield* fromNullable(
774
+ typeChecker.getPropertyOfType(type, "await")
775
+ );
776
+ const pollSymbol = yield* fromNullable(
777
+ typeChecker.getPropertyOfType(type, "poll")
778
+ );
779
+ if (!awaitSymbol || !pollSymbol) return yield* none2();
780
+ return effectType(ts, typeChecker)(type, atLocation);
781
+ });
782
+ }
783
+ function effectSubtype(ts, typeChecker) {
784
+ return (type, atLocation) => gen(function* (_) {
785
+ const tagSymbol = yield* fromNullable(
786
+ typeChecker.getPropertyOfType(type, "_tag")
787
+ );
788
+ if (!tagSymbol) return yield* none2();
789
+ return effectType(ts, typeChecker)(type, atLocation);
790
+ });
791
+ }
792
+ function importedEffectModule(ts, typeChecker) {
793
+ return (node) => gen(function* () {
794
+ const type = typeChecker.getTypeAtLocation(node);
795
+ const propertySymbol = yield* fromNullable(
796
+ typeChecker.getPropertyOfType(type, "never")
797
+ );
798
+ const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, node);
799
+ return yield* effectType(ts, typeChecker)(propertyType, node).pipe(
800
+ map(() => node)
801
+ );
802
+ });
803
+ }
804
+ function effectGen(ts, typeChecker) {
805
+ return (node) => gen(function* () {
806
+ if (!ts.isCallExpression(node)) return yield* none2();
807
+ if (node.arguments.length === 0) return yield* none2();
808
+ const generatorFunction = node.arguments[0];
809
+ if (!ts.isFunctionExpression(generatorFunction)) return yield* none2();
810
+ if (generatorFunction.asteriskToken === void 0) return yield* none2();
811
+ if (!ts.isPropertyAccessExpression(node.expression)) return yield* none2();
812
+ const propertyAccess = node.expression;
813
+ if (propertyAccess.name.text !== "gen") return yield* none2();
814
+ return yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression).pipe(
815
+ map(() => ({
816
+ body: generatorFunction.body,
817
+ functionStar: generatorFunction.getFirstToken()
818
+ }))
819
+ );
820
+ });
821
+ }
822
+ function effectFnUntracedGen(ts, typeChecker) {
823
+ return (node) => gen(function* () {
824
+ if (!ts.isCallExpression(node)) return yield* none2();
825
+ if (node.arguments.length === 0) return yield* none2();
826
+ const generatorFunction = node.arguments[0];
827
+ if (!ts.isFunctionExpression(generatorFunction)) return yield* none2();
828
+ if (generatorFunction.asteriskToken === void 0) return yield* none2();
829
+ if (!ts.isPropertyAccessExpression(node.expression)) return yield* none2();
830
+ const propertyAccess = node.expression;
831
+ if (propertyAccess.name.text !== "fnUntraced") return yield* none2();
832
+ return yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression).pipe(
833
+ map(() => ({
834
+ body: generatorFunction.body,
835
+ functionStar: generatorFunction.getFirstToken()
836
+ }))
837
+ );
838
+ });
839
+ }
840
+ function effectFnGen(ts, typeChecker) {
841
+ return (node) => gen(function* () {
842
+ if (!ts.isCallExpression(node)) return yield* none2();
843
+ if (node.arguments.length === 0) return yield* none2();
844
+ const generatorFunction = node.arguments[0];
845
+ if (!ts.isFunctionExpression(generatorFunction)) return yield* none2();
846
+ if (generatorFunction.asteriskToken === void 0) return yield* none2();
847
+ const expressionToTest = ts.isCallExpression(node.expression) ? node.expression.expression : node.expression;
848
+ if (!ts.isPropertyAccessExpression(expressionToTest)) return yield* none2();
849
+ const propertyAccess = expressionToTest;
850
+ if (propertyAccess.name.text !== "fn") return yield* none2();
851
+ return yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression).pipe(
852
+ map(() => ({
853
+ body: generatorFunction.body,
854
+ functionStar: generatorFunction.getFirstToken()
855
+ }))
856
+ );
857
+ });
858
+ }
859
+ function expectedAndRealType(ts, typeChecker) {
860
+ return (node) => {
861
+ if (ts.isVariableDeclaration(node) && node.initializer) {
862
+ const expectedType = typeChecker.getTypeAtLocation(node.name);
863
+ const realType = typeChecker.getTypeAtLocation(node.initializer);
864
+ return [[node.name, expectedType, node.initializer, realType]];
865
+ }
866
+ if (ts.isCallExpression(node)) {
867
+ const resolvedSignature = typeChecker.getResolvedSignature(node);
868
+ if (resolvedSignature) {
869
+ return resolvedSignature.getParameters().map((parameter, index) => {
870
+ const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
871
+ const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
872
+ return [node.arguments[index], expectedType, node.arguments[index], realType];
873
+ });
874
+ }
875
+ }
876
+ if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
877
+ const parent = node.parent;
878
+ if (ts.isObjectLiteralElement(parent)) {
879
+ if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
880
+ const type = typeChecker.getContextualType(parent.parent);
881
+ if (type) {
882
+ const symbol3 = typeChecker.getPropertyOfType(type, node.text);
883
+ if (symbol3) {
884
+ const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
885
+ const realType = typeChecker.getTypeAtLocation(node);
886
+ return [[node, expectedType, node, realType]];
887
+ }
888
+ }
889
+ }
890
+ }
891
+ }
892
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
893
+ const expectedType = typeChecker.getTypeAtLocation(node.left);
894
+ const realType = typeChecker.getTypeAtLocation(node.right);
895
+ return [[node.left, expectedType, node.right, realType]];
896
+ }
897
+ if (ts.isReturnStatement(node) && node.expression) {
898
+ const expectedType = typeChecker.getContextualType(node.expression);
899
+ const realType = typeChecker.getTypeAtLocation(node.expression);
900
+ if (expectedType) return [[node, expectedType, node, realType]];
901
+ }
902
+ if (ts.isArrowFunction(node) && ts.isExpression(node.body)) {
903
+ const body = node.body;
904
+ const expectedType = typeChecker.getContextualType(body);
905
+ const realType = typeChecker.getTypeAtLocation(body);
906
+ if (expectedType) return [[body, expectedType, body, realType]];
907
+ }
908
+ if (ts.isSatisfiesExpression(node)) {
909
+ const expectedType = typeChecker.getTypeAtLocation(node.type);
910
+ const realType = typeChecker.getTypeAtLocation(node.expression);
911
+ return [[node.expression, expectedType, node.expression, realType]];
912
+ }
913
+ return [];
914
+ };
915
+ }
916
+
917
+ // src/diagnostics/floatingEffect.ts
918
+ var floatingEffect = createDiagnostic({
919
+ code: 3,
920
+ apply: (ts, program) => (sourceFile) => {
921
+ const typeChecker = program.getTypeChecker();
922
+ const effectDiagnostics = [];
923
+ function isFloatingExpression(node) {
924
+ if (!ts.isExpressionStatement(node)) return false;
925
+ if (!(ts.isBlock(node.parent) || ts.isSourceFile(node.parent))) return false;
926
+ const expression = node.expression;
927
+ if (ts.isBinaryExpression(expression) && expression.operatorToken && expression.operatorToken.kind === ts.SyntaxKind.EqualsToken) return false;
928
+ return true;
929
+ }
930
+ const visit = (node) => {
931
+ if (isFloatingExpression(node)) {
932
+ const type = typeChecker.getTypeAtLocation(node.expression);
933
+ const effect = effectType(ts, typeChecker)(type, node.expression);
934
+ if (isSome2(effect)) {
935
+ const allowedFloatingEffects = pipe(
936
+ fiberType(ts, typeChecker)(type, node.expression),
937
+ orElse(() => effectSubtype(ts, typeChecker)(type, node.expression))
938
+ );
939
+ if (isNone2(allowedFloatingEffects)) {
940
+ effectDiagnostics.push({
941
+ node,
942
+ category: ts.DiagnosticCategory.Error,
943
+ messageText: `Effect must be yielded or assigned to a variable.`
944
+ });
945
+ }
946
+ }
947
+ }
948
+ ts.forEachChild(node, visit);
949
+ };
950
+ ts.forEachChild(sourceFile, visit);
951
+ return effectDiagnostics;
952
+ }
953
+ });
954
+
955
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/array.js
956
+ var isNonEmptyArray = (self) => self.length > 0;
957
+
958
+ // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Array.js
959
+ var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
960
+ var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
961
+ var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
962
+ var isArray = Array.isArray;
963
+ var isNonEmptyReadonlyArray = isNonEmptyArray;
964
+ var isOutOfBound = (i, as) => i < 0 || i >= as.length;
965
+ var get = /* @__PURE__ */ dual(2, (self, index) => {
966
+ const i = Math.floor(index);
967
+ return isOutOfBound(i, self) ? none2() : some2(self[i]);
968
+ });
969
+ var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
970
+ const i = Math.floor(index);
971
+ if (isOutOfBound(i, self)) {
972
+ throw new Error(`Index ${i} out of bounds`);
973
+ }
974
+ return self[i];
975
+ });
976
+ var head = /* @__PURE__ */ get(0);
977
+ var headNonEmpty = /* @__PURE__ */ unsafeGet(0);
978
+ var tailNonEmpty = (self) => self.slice(1);
979
+ var sort = /* @__PURE__ */ dual(2, (self, O) => {
980
+ const out = Array.from(self);
981
+ out.sort(O);
982
+ return out;
983
+ });
984
+ var empty = () => [];
985
+ var map2 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
986
+ var filter = /* @__PURE__ */ dual(2, (self, predicate) => {
987
+ const as = fromIterable(self);
988
+ const out = [];
989
+ for (let i = 0; i < as.length; i++) {
990
+ if (predicate(as[i], i)) {
991
+ out.push(as[i]);
992
+ }
993
+ }
994
+ return out;
995
+ });
996
+ var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
997
+ const input = fromIterable(self);
998
+ if (isNonEmptyReadonlyArray(input)) {
999
+ const out = [headNonEmpty(input)];
1000
+ const rest = tailNonEmpty(input);
1001
+ for (const r of rest) {
1002
+ if (out.every((a) => !isEquivalent(r, a))) {
1003
+ out.push(r);
1004
+ }
1005
+ }
1006
+ return out;
1007
+ }
1008
+ return [];
1009
+ });
1010
+
1011
+ // src/utils/AST.ts
1012
+ function getNodesContainingRange(ts) {
1013
+ return (sourceFile, textRange) => {
1014
+ const precedingToken = ts.findPrecedingToken(textRange.pos, sourceFile);
1015
+ if (!precedingToken) return empty();
1016
+ let result = empty();
1017
+ let parent = precedingToken;
1018
+ while (parent) {
1019
+ if (parent.end >= textRange.end) {
1020
+ result = pipe(result, append(parent));
1021
+ }
1022
+ parent = parent.parent;
1023
+ }
1024
+ return result;
1025
+ };
1026
+ }
1027
+ function toTextRange(positionOrRange) {
1028
+ return typeof positionOrRange === "number" ? { end: positionOrRange, pos: positionOrRange } : positionOrRange;
1029
+ }
1030
+ function isNodeInRange(textRange) {
1031
+ return (node) => node.pos <= textRange.pos && node.end >= textRange.end;
1032
+ }
1033
+ function findModuleNamedBindings(ts) {
1034
+ return (sourceFile, moduleName) => fromNullable(ts.forEachChild(sourceFile, (node) => {
1035
+ if (!ts.isImportDeclaration(node)) return;
1036
+ const moduleSpecifier = node.moduleSpecifier;
1037
+ if (!ts.isStringLiteral(moduleSpecifier)) return;
1038
+ if (moduleSpecifier.text !== moduleName) return;
1039
+ const importClause = node.importClause;
1040
+ if (!importClause) return;
1041
+ const namedBindings = importClause.namedBindings;
1042
+ if (!namedBindings) return;
1043
+ return namedBindings;
1044
+ }));
1045
+ }
1046
+ function findModuleNamespaceImportIdentifierName(ts) {
1047
+ return (sourceFile, moduleName) => pipe(
1048
+ findModuleNamedBindings(ts)(sourceFile, moduleName),
1049
+ map(
1050
+ (namedBindings) => {
1051
+ if (!ts.isNamespaceImport(namedBindings)) return;
1052
+ return namedBindings.name.text;
1053
+ }
1054
+ ),
1055
+ flatMap(fromNullable)
1056
+ );
1057
+ }
1058
+ function findModuleNamedImportIdentifierName(ts) {
1059
+ return (sourceFile, moduleName, namedImport) => pipe(
1060
+ findModuleNamedBindings(ts)(sourceFile, moduleName),
1061
+ map((namedBindings) => {
1062
+ if (!ts.isNamedImports(namedBindings)) return;
1063
+ for (const importSpecifier of namedBindings.elements) {
1064
+ if (importSpecifier.propertyName?.getText() === namedImport) {
1065
+ return importSpecifier.name?.escapedText || importSpecifier.propertyName?.getText();
1066
+ }
1067
+ }
1068
+ }),
1069
+ flatMap(fromNullable)
1070
+ );
1071
+ }
1072
+ function findModuleImportIdentifierNameViaTypeChecker(ts, typeChecker) {
1073
+ return (sourceFile, importName) => {
1074
+ return fromNullable(ts.forEachChild(sourceFile, (node) => {
1075
+ if (!ts.isImportDeclaration(node)) return;
1076
+ if (!node.importClause) return;
1077
+ const namedBindings = node.importClause.namedBindings;
1078
+ if (!namedBindings) return;
1079
+ if (ts.isNamespaceImport(namedBindings)) {
1080
+ const symbol3 = typeChecker.getTypeAtLocation(namedBindings).getSymbol();
1081
+ if (!symbol3 || !symbol3.exports) return;
1082
+ if (!symbol3.exports.has(importName)) return;
1083
+ return namedBindings.name.escapedText;
1084
+ }
1085
+ if (ts.isNamedImports(namedBindings)) {
1086
+ for (const importSpecifier of namedBindings.elements) {
1087
+ const symbol3 = typeChecker.getTypeAtLocation(importSpecifier).getSymbol();
1088
+ if (!symbol3 || !symbol3.exports) return;
1089
+ if (!symbol3.exports.has(importName)) return;
1090
+ return importSpecifier.name?.escapedText || importSpecifier.propertyName?.getText();
1091
+ }
1092
+ }
1093
+ }));
1094
+ };
1095
+ }
1096
+ function transformAsyncAwaitToEffectGen(ts) {
1097
+ return (node, effectName, onAwait) => {
1098
+ function visitor(_) {
1099
+ if (ts.isAwaitExpression(_)) {
1100
+ const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext);
1101
+ return ts.factory.createYieldExpression(
1102
+ ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
1103
+ onAwait(expression)
1104
+ );
1105
+ }
1106
+ return ts.visitEachChild(_, visitor, ts.nullTransformationContext);
1107
+ }
1108
+ const generatorBody = visitor(node.body);
1109
+ const generator = ts.factory.createFunctionExpression(
1110
+ void 0,
1111
+ ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
1112
+ void 0,
1113
+ [],
1114
+ [],
1115
+ void 0,
1116
+ generatorBody
1117
+ // NOTE(mattia): intended, to use same routine for both ConciseBody and Body
1118
+ );
1119
+ const effectGenCallExp = ts.factory.createCallExpression(
1120
+ ts.factory.createPropertyAccessExpression(
1121
+ ts.factory.createIdentifier(effectName),
1122
+ "gen"
1123
+ ),
1124
+ void 0,
1125
+ [generator]
1126
+ );
1127
+ let currentFlags = ts.getCombinedModifierFlags(node);
1128
+ currentFlags &= ~ts.ModifierFlags.Async;
1129
+ const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags);
1130
+ if (ts.isArrowFunction(node)) {
1131
+ return ts.factory.createArrowFunction(
1132
+ newModifiers,
1133
+ node.typeParameters,
1134
+ node.parameters,
1135
+ void 0,
1136
+ node.equalsGreaterThanToken,
1137
+ effectGenCallExp
1138
+ );
1139
+ }
1140
+ const newBody = ts.factory.createBlock([
1141
+ ts.factory.createReturnStatement(effectGenCallExp)
1142
+ ]);
1143
+ if (ts.isFunctionDeclaration(node)) {
1144
+ return ts.factory.createFunctionDeclaration(
1145
+ newModifiers,
1146
+ node.asteriskToken,
1147
+ node.name,
1148
+ node.typeParameters,
1149
+ node.parameters,
1150
+ void 0,
1151
+ newBody
1152
+ );
1153
+ }
1154
+ return ts.factory.createFunctionExpression(
1155
+ newModifiers,
1156
+ node.asteriskToken,
1157
+ node.name,
1158
+ node.typeParameters,
1159
+ node.parameters,
1160
+ void 0,
1161
+ newBody
1162
+ );
1163
+ };
1164
+ }
1165
+ function addReturnTypeAnnotation(ts, changes) {
1166
+ return (sourceFile, declaration, typeNode) => {
1167
+ const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
1168
+ const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
1169
+ const endNode = needParens ? declaration.parameters[0] : closeParen;
1170
+ if (endNode) {
1171
+ if (needParens) {
1172
+ changes.insertNodeBefore(
1173
+ sourceFile,
1174
+ endNode,
1175
+ ts.factory.createToken(ts.SyntaxKind.OpenParenToken)
1176
+ );
1177
+ changes.insertNodeAfter(
1178
+ sourceFile,
1179
+ endNode,
1180
+ ts.factory.createToken(ts.SyntaxKind.CloseParenToken)
1181
+ );
1182
+ }
1183
+ changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: ": " });
1184
+ }
1185
+ };
1186
+ }
1187
+ function removeReturnTypeAnnotation(ts, changes) {
1188
+ return (sourceFile, declaration) => {
1189
+ const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
1190
+ const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
1191
+ const endNode = needParens ? declaration.parameters[0] : closeParen;
1192
+ if (endNode && declaration.type) {
1193
+ changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end });
1194
+ }
1195
+ };
1196
+ }
1197
+ function getEffectModuleIdentifier(ts, typeChecker) {
1198
+ return (sourceFile) => pipe(
1199
+ findModuleNamespaceImportIdentifierName(ts)(sourceFile, "effect/Effect"),
1200
+ orElse(() => findModuleNamedImportIdentifierName(ts)(sourceFile, "effect", "Effect")),
1201
+ orElse(
1202
+ () => findModuleImportIdentifierNameViaTypeChecker(ts, typeChecker)(sourceFile, "Effect")
1203
+ ),
1204
+ getOrElse(
1205
+ () => "Effect"
1206
+ )
1207
+ );
1208
+ }
1209
+ function simplifyTypeNode(ts) {
1210
+ function collectCallable(typeNode) {
1211
+ if (ts.isParenthesizedTypeNode(typeNode)) return collectCallable(typeNode.type);
1212
+ if (ts.isFunctionTypeNode(typeNode)) {
1213
+ return some2([
1214
+ ts.factory.createCallSignature(typeNode.typeParameters, typeNode.parameters, typeNode.type)
1215
+ ]);
1216
+ }
1217
+ if (ts.isTypeLiteralNode(typeNode)) {
1218
+ const allCallSignatures = typeNode.members.every(ts.isCallSignatureDeclaration);
1219
+ if (allCallSignatures) {
1220
+ return some2(typeNode.members);
1221
+ }
1222
+ }
1223
+ if (ts.isIntersectionTypeNode(typeNode)) {
1224
+ const members = typeNode.types.map(collectCallable);
1225
+ if (members.every(isSome2)) {
1226
+ return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
1227
+ }
1228
+ }
1229
+ return none2();
1230
+ }
1231
+ return (typeNode) => {
1232
+ const callSignatures = collectCallable(typeNode);
1233
+ if (isSome2(callSignatures) && callSignatures.value.length > 1) {
1234
+ return ts.factory.createTypeLiteralNode(callSignatures.value);
1235
+ }
1236
+ return typeNode;
1237
+ };
1238
+ }
1239
+ function isPipeCall(ts) {
1240
+ return (node) => {
1241
+ if (!ts.isCallExpression(node)) return false;
1242
+ const expression = node.expression;
1243
+ if (!ts.isIdentifier(expression)) return false;
1244
+ if (expression.text !== "pipe") return false;
1245
+ return true;
1246
+ };
1247
+ }
1248
+ function asDataFirstExpression(ts, checker) {
1249
+ return (node, self) => {
1250
+ if (!ts.isCallExpression(node)) return none2();
1251
+ const signature = checker.getResolvedSignature(node);
1252
+ if (!signature) return none2();
1253
+ const callSignatures = checker.getTypeAtLocation(node.expression).getCallSignatures();
1254
+ for (let i = 0; i < callSignatures.length; i++) {
1255
+ const callSignature = callSignatures[i];
1256
+ if (callSignature.parameters.length === node.arguments.length + 1) {
1257
+ return some2(
1258
+ ts.factory.createCallExpression(
1259
+ node.expression,
1260
+ [],
1261
+ [self].concat(node.arguments)
1262
+ )
1263
+ );
1264
+ }
1265
+ }
1266
+ return none2();
1267
+ };
1268
+ }
1269
+ function deterministicTypeOrder(ts, typeChecker) {
1270
+ return make2((a, b) => {
1271
+ const aName = typeChecker.typeToString(a);
1272
+ const bName = typeChecker.typeToString(b);
1273
+ if (aName < bName) return -1;
1274
+ if (aName > bName) return 1;
1275
+ return 0;
1276
+ });
1277
+ }
1278
+
1279
+ // src/utils/TypeCheckerApi.ts
1280
+ function getMissingTypeEntriesInTargetType(ts, typeChecker) {
1281
+ return (realType, expectedType) => {
1282
+ const result = [];
1283
+ const toTest = [realType];
1284
+ while (toTest.length > 0) {
1285
+ const type = toTest.pop();
1286
+ if (!type) return result;
1287
+ if (type.isUnion()) {
1288
+ toTest.push(...type.types);
1289
+ } else {
1290
+ const assignable = typeChecker.isTypeAssignableTo(type, expectedType);
1291
+ if (!assignable) {
1292
+ result.push(type);
1293
+ }
1294
+ }
1295
+ }
1296
+ return result;
1297
+ };
1298
+ }
1299
+
1300
+ // src/diagnostics/missingEffectContext.ts
1301
+ var missingEffectContext = createDiagnostic({
1302
+ code: 1,
1303
+ apply: (ts, program) => (sourceFile) => {
1304
+ const typeChecker = program.getTypeChecker();
1305
+ const effectDiagnostics = [];
1306
+ const sortTypes = sort(deterministicTypeOrder(ts, typeChecker));
1307
+ const visit = (node) => {
1308
+ const entries = expectedAndRealType(ts, typeChecker)(node);
1309
+ for (const [node2, expectedType, valueNode, realType] of entries) {
1310
+ const expectedEffect = effectType(ts, typeChecker)(
1311
+ expectedType,
1312
+ node2
1313
+ );
1314
+ if (isNone2(expectedEffect)) continue;
1315
+ const realEffect = effectType(ts, typeChecker)(
1316
+ realType,
1317
+ valueNode
1318
+ );
1319
+ if (isNone2(realEffect)) continue;
1320
+ const missingContext = getMissingTypeEntriesInTargetType(
1321
+ ts,
1322
+ typeChecker
1323
+ )(
1324
+ realEffect.value.R,
1325
+ expectedEffect.value.R
1326
+ );
1327
+ if (missingContext.length > 0) {
1328
+ effectDiagnostics.push(
1329
+ {
1330
+ node: node2,
1331
+ category: ts.DiagnosticCategory.Error,
1332
+ messageText: `Missing '${sortTypes(missingContext).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect context.`
1333
+ }
1334
+ );
1335
+ }
1336
+ }
1337
+ ts.forEachChild(node, visit);
1338
+ };
1339
+ ts.forEachChild(sourceFile, visit);
1340
+ return effectDiagnostics;
1341
+ }
1342
+ });
1343
+
1344
+ // src/diagnostics/missingEffectError.ts
1345
+ var missingEffectError = createDiagnostic({
1346
+ code: 2,
1347
+ apply: (ts, program) => (sourceFile) => {
1348
+ const typeChecker = program.getTypeChecker();
1349
+ const effectDiagnostics = [];
1350
+ const sortTypes = sort(deterministicTypeOrder(ts, typeChecker));
1351
+ const visit = (node) => {
1352
+ const entries = expectedAndRealType(ts, typeChecker)(node);
1353
+ for (const [node2, expectedType, valueNode, realType] of entries) {
1354
+ const expectedEffect = effectType(ts, typeChecker)(
1355
+ expectedType,
1356
+ node2
1357
+ );
1358
+ if (isNone2(expectedEffect)) continue;
1359
+ const realEffect = effectType(ts, typeChecker)(
1360
+ realType,
1361
+ valueNode
1362
+ );
1363
+ if (isNone2(realEffect)) continue;
1364
+ const missingErrorTypes = getMissingTypeEntriesInTargetType(
1365
+ ts,
1366
+ typeChecker
1367
+ )(
1368
+ realEffect.value.E,
1369
+ expectedEffect.value.E
1370
+ );
1371
+ if (missingErrorTypes.length > 0) {
1372
+ effectDiagnostics.push(
1373
+ {
1374
+ node: node2,
1375
+ category: ts.DiagnosticCategory.Error,
1376
+ messageText: `Missing '${sortTypes(missingErrorTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect errors.`
1377
+ }
1378
+ );
1379
+ }
1380
+ }
1381
+ ts.forEachChild(node, visit);
1382
+ };
1383
+ ts.forEachChild(sourceFile, visit);
1384
+ return effectDiagnostics;
1385
+ }
1386
+ });
1387
+
1388
+ // src/diagnostics/missingStarInYieldEffectGen.ts
1389
+ var missingStarInYieldEffectGen = createDiagnostic({
1390
+ code: 4,
1391
+ apply: (ts, program) => (sourceFile) => {
1392
+ const typeChecker = program.getTypeChecker();
1393
+ const effectDiagnostics = [];
1394
+ const brokenGenerators = /* @__PURE__ */ new Set();
1395
+ const brokenYields = /* @__PURE__ */ new Set();
1396
+ const visit = (functionStarNode) => (node) => {
1397
+ if (functionStarNode && ts.isYieldExpression(node) && node.expression && node.asteriskToken === void 0) {
1398
+ const type = typeChecker.getTypeAtLocation(node.expression);
1399
+ const effect = effectType(ts, typeChecker)(type, node.expression);
1400
+ if (isSome2(effect)) {
1401
+ brokenGenerators.add(functionStarNode);
1402
+ brokenYields.add(node);
1403
+ }
1404
+ }
1405
+ const effectGenLike = pipe(
1406
+ effectGen(ts, typeChecker)(node),
1407
+ orElse(() => effectFnUntracedGen(ts, typeChecker)(node)),
1408
+ orElse(() => effectFnGen(ts, typeChecker)(node))
1409
+ );
1410
+ if (isSome2(effectGenLike)) {
1411
+ ts.forEachChild(effectGenLike.value.body, visit(effectGenLike.value.functionStar));
1412
+ } else if ((ts.isFunctionExpression(node) || ts.isMethodDeclaration(node)) && node.asteriskToken !== void 0) {
1413
+ ts.forEachChild(node, visit(void 0));
1414
+ } else {
1415
+ ts.forEachChild(node, visit(functionStarNode));
1416
+ }
1417
+ };
1418
+ ts.forEachChild(sourceFile, visit(void 0));
1419
+ brokenGenerators.forEach(
1420
+ (node) => effectDiagnostics.push({
1421
+ node,
1422
+ category: ts.DiagnosticCategory.Error,
1423
+ messageText: `Seems like you used yield instead of yield* inside this Effect.gen.`
1424
+ })
1425
+ );
1426
+ brokenYields.forEach(
1427
+ (node) => effectDiagnostics.push({
1428
+ node,
1429
+ category: ts.DiagnosticCategory.Error,
1430
+ messageText: `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`
1431
+ })
1432
+ );
1433
+ return effectDiagnostics;
1434
+ }
1435
+ });
1436
+
1437
+ // src/diagnostics/unnecessaryEffectGen.ts
1438
+ var unnecessaryEffectGen = createDiagnostic({
1439
+ code: 5,
1440
+ apply: (ts, program) => (sourceFile) => {
1441
+ const typeChecker = program.getTypeChecker();
1442
+ const effectDiagnostics = [];
1443
+ const brokenGenerators = /* @__PURE__ */ new Set();
1444
+ const visit = (node) => {
1445
+ const effectGenLike = effectGen(ts, typeChecker)(node);
1446
+ if (isSome2(effectGenLike)) {
1447
+ const body = effectGenLike.value.body;
1448
+ 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) {
1449
+ const nodeToCheck = body.statements[0].expression.expression;
1450
+ const type = typeChecker.getTypeAtLocation(nodeToCheck);
1451
+ const maybeEffect = effectType(ts, typeChecker)(type, nodeToCheck);
1452
+ if (isSome2(maybeEffect)) {
1453
+ brokenGenerators.add(node);
1454
+ }
1455
+ }
1456
+ }
1457
+ ts.forEachChild(node, visit);
1458
+ };
1459
+ ts.forEachChild(sourceFile, visit);
1460
+ brokenGenerators.forEach(
1461
+ (node) => effectDiagnostics.push({
1462
+ node,
1463
+ category: ts.DiagnosticCategory.Warning,
1464
+ messageText: `This Effect.gen is useless here because it only contains a single return statement.`
1465
+ })
1466
+ );
1467
+ return effectDiagnostics;
1468
+ }
1469
+ });
1470
+
1471
+ // src/diagnostics.ts
1472
+ var diagnostics = {
1473
+ missingEffectContext,
1474
+ missingEffectError,
1475
+ floatingEffect,
1476
+ missingStarInYieldEffectGen,
1477
+ unnecessaryEffectGen
1478
+ };
1479
+
1480
+ // src/quickinfo.ts
1481
+ var SymbolDisplayPartEq = make(
1482
+ (fa, fb) => fa.kind === fb.kind && fa.text === fb.text
1483
+ );
1484
+ var JSDocTagInfoEq = make(
1485
+ (fa, fb) => fa.name === fb.name && typeof fa.text === typeof fb.text && (typeof fa.text !== "undefined" ? array(SymbolDisplayPartEq)(fa.text, fb.text) : true)
1486
+ );
1487
+ function dedupeJsDocTags(quickInfo) {
1488
+ if (quickInfo.tags) {
1489
+ return {
1490
+ ...quickInfo,
1491
+ tags: dedupeWith(quickInfo.tags, JSDocTagInfoEq)
1492
+ };
1493
+ }
1494
+ return quickInfo;
1495
+ }
1496
+ function formatTypeForQuickInfo(ts, typeChecker) {
1497
+ return (channelType, channelName) => {
1498
+ const stringRepresentation = typeChecker.typeToString(
1499
+ channelType,
1500
+ void 0,
1501
+ ts.TypeFormatFlags.NoTruncation
1502
+ );
1503
+ return `type ${channelName} = ${stringRepresentation}`;
1504
+ };
1505
+ }
1506
+ function prependEffectTypeArguments(ts, program) {
1507
+ return (sourceFileName, position, quickInfo) => {
1508
+ const sourceFile = program.getSourceFile(sourceFileName);
1509
+ if (!sourceFile) return quickInfo;
1510
+ const hasTruncationHappened = ts.displayPartsToString(quickInfo.displayParts).indexOf("...") > -1;
1511
+ if (!hasTruncationHappened) return quickInfo;
1512
+ const typeChecker = program.getTypeChecker();
1513
+ const effectTypeArgsDocumentation = pipe(
1514
+ getNodesContainingRange(ts)(sourceFile, toTextRange(position)),
1515
+ head,
1516
+ flatMap(
1517
+ (_) => effectType(ts, typeChecker)(typeChecker.getTypeAtLocation(_), _)
1518
+ ),
1519
+ map((_) => [{
1520
+ kind: "text",
1521
+ 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"
1522
+ }]),
1523
+ getOrElse(() => [])
1524
+ );
1525
+ if (quickInfo.documentation) {
1526
+ return {
1527
+ ...quickInfo,
1528
+ documentation: effectTypeArgsDocumentation.concat(quickInfo.documentation)
1529
+ };
1530
+ }
1531
+ return {
1532
+ ...quickInfo,
1533
+ documentation: effectTypeArgsDocumentation
1534
+ };
1535
+ };
1536
+ }
1537
+
1538
+ // src/refactors/asyncAwaitToGen.ts
1539
+ var asyncAwaitToGen = createRefactor({
1540
+ name: "effect/asyncAwaitToGen",
1541
+ description: "Convert to Effect.gen",
1542
+ apply: (ts, program) => (sourceFile, textRange) => pipe(
1543
+ getNodesContainingRange(ts)(sourceFile, textRange),
1544
+ filter(ts.isFunctionDeclaration),
1545
+ filter((node) => !!node.body),
1546
+ filter(
1547
+ (node) => !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)
1548
+ ),
1549
+ head,
1550
+ map((node) => ({
1551
+ kind: "refactor.rewrite.effect.asyncAwaitToGen",
1552
+ description: "Rewrite to Effect.gen",
1553
+ apply: (changeTracker) => {
1554
+ const effectName = getEffectModuleIdentifier(ts, program.getTypeChecker())(sourceFile);
1555
+ const newDeclaration = transformAsyncAwaitToEffectGen(
1556
+ ts
1557
+ )(
1558
+ node,
1559
+ effectName,
1560
+ (expression) => ts.factory.createCallExpression(
1561
+ ts.factory.createPropertyAccessExpression(
1562
+ ts.factory.createIdentifier(effectName),
1563
+ "promise"
1564
+ ),
1565
+ void 0,
1566
+ [
1567
+ ts.factory.createArrowFunction(
1568
+ void 0,
1569
+ void 0,
1570
+ [],
1571
+ void 0,
1572
+ void 0,
1573
+ expression
1574
+ )
1575
+ ]
1576
+ )
1577
+ );
1578
+ changeTracker.replaceNode(sourceFile, node, newDeclaration);
1579
+ }
1580
+ }))
1581
+ )
1582
+ });
1583
+
1584
+ // src/refactors/asyncAwaitToGenTryPromise.ts
1585
+ var asyncAwaitToGenTryPromise = createRefactor({
1586
+ name: "effect/asyncAwaitToGenTryPromise",
1587
+ description: "Convert to Effect.gen with failures",
1588
+ apply: (ts, program) => (sourceFile, textRange) => pipe(
1589
+ getNodesContainingRange(ts)(sourceFile, textRange),
1590
+ filter(ts.isFunctionDeclaration),
1591
+ filter((node) => !!node.body),
1592
+ filter(
1593
+ (node) => !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)
1594
+ ),
1595
+ head,
1596
+ map((node) => ({
1597
+ kind: "refactor.rewrite.effect.asyncAwaitToGenTryPromise",
1598
+ description: "Rewrite to Effect.gen with failures",
1599
+ apply: (changeTracker) => {
1600
+ const effectName = getEffectModuleIdentifier(ts, program.getTypeChecker())(sourceFile);
1601
+ let errorCount = 0;
1602
+ function createErrorADT() {
1603
+ errorCount++;
1604
+ return ts.factory.createObjectLiteralExpression([
1605
+ ts.factory.createPropertyAssignment(
1606
+ "_tag",
1607
+ ts.factory.createAsExpression(
1608
+ ts.factory.createStringLiteral("Error" + errorCount),
1609
+ ts.factory.createTypeReferenceNode("const")
1610
+ )
1611
+ ),
1612
+ ts.factory.createShorthandPropertyAssignment("error")
1613
+ ]);
1614
+ }
1615
+ const newDeclaration = transformAsyncAwaitToEffectGen(
1616
+ ts
1617
+ )(
1618
+ node,
1619
+ effectName,
1620
+ (expression) => ts.factory.createCallExpression(
1621
+ ts.factory.createPropertyAccessExpression(
1622
+ ts.factory.createIdentifier(effectName),
1623
+ "tryPromise"
1624
+ ),
1625
+ void 0,
1626
+ [
1627
+ ts.factory.createObjectLiteralExpression([
1628
+ ts.factory.createPropertyAssignment(
1629
+ ts.factory.createIdentifier("try"),
1630
+ ts.factory.createArrowFunction(
1631
+ void 0,
1632
+ void 0,
1633
+ [],
1634
+ void 0,
1635
+ void 0,
1636
+ expression
1637
+ )
1638
+ ),
1639
+ ts.factory.createPropertyAssignment(
1640
+ ts.factory.createIdentifier("catch"),
1641
+ ts.factory.createArrowFunction(
1642
+ void 0,
1643
+ void 0,
1644
+ [ts.factory.createParameterDeclaration(void 0, void 0, "error")],
1645
+ void 0,
1646
+ void 0,
1647
+ createErrorADT()
1648
+ )
1649
+ )
1650
+ ])
1651
+ ]
1652
+ )
1653
+ );
1654
+ changeTracker.replaceNode(sourceFile, node, newDeclaration);
1655
+ }
1656
+ }))
1657
+ )
1658
+ });
1659
+
1660
+ // src/refactors/functionToArrow.ts
1661
+ var functionToArrow = createRefactor({
1662
+ name: "effect/functionToArrow",
1663
+ description: "Convert to arrow",
1664
+ apply: (ts) => (sourceFile, textRange) => pipe(
1665
+ pipe(
1666
+ getNodesContainingRange(ts)(sourceFile, textRange),
1667
+ filter(ts.isFunctionDeclaration)
1668
+ ),
1669
+ appendAll(
1670
+ pipe(
1671
+ getNodesContainingRange(ts)(sourceFile, textRange),
1672
+ filter(ts.isMethodDeclaration)
1673
+ )
1674
+ ),
1675
+ filter((node) => !!node.body),
1676
+ filter((node) => !!node.name && isNodeInRange(textRange)(node.name)),
1677
+ head,
1678
+ map(
1679
+ (node) => ({
1680
+ kind: "refactor.rewrite.effect.functionToArrow",
1681
+ description: "Convert to arrow",
1682
+ apply: (changeTracker) => {
1683
+ const body = node.body;
1684
+ let newBody = ts.factory.createBlock(body.statements);
1685
+ if (body.statements.length === 1) {
1686
+ const statement = body.statements[0];
1687
+ if (statement && ts.isReturnStatement(statement) && statement.expression) {
1688
+ newBody = statement.expression;
1689
+ }
1690
+ }
1691
+ let arrowFlags = ts.getCombinedModifierFlags(node);
1692
+ arrowFlags &= ~ts.ModifierFlags.Export;
1693
+ arrowFlags &= ~ts.ModifierFlags.Default;
1694
+ const arrowModifiers = ts.factory.createModifiersFromModifierFlags(arrowFlags);
1695
+ const arrowFunction = ts.factory.createArrowFunction(
1696
+ arrowModifiers,
1697
+ node.typeParameters,
1698
+ node.parameters,
1699
+ void 0,
1700
+ ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
1701
+ newBody
1702
+ );
1703
+ let constFlags = ts.getCombinedModifierFlags(node);
1704
+ constFlags &= ~arrowFlags;
1705
+ const constModifiers = ts.factory.createModifiersFromModifierFlags(constFlags);
1706
+ let newDeclaration = node;
1707
+ if (ts.isMethodDeclaration(node)) {
1708
+ newDeclaration = ts.factory.createPropertyDeclaration(
1709
+ constModifiers,
1710
+ node.name,
1711
+ void 0,
1712
+ void 0,
1713
+ arrowFunction
1714
+ );
1715
+ } else if (ts.isFunctionDeclaration(node)) {
1716
+ newDeclaration = ts.factory.createVariableStatement(
1717
+ constModifiers,
1718
+ ts.factory.createVariableDeclarationList(
1719
+ [
1720
+ ts.factory.createVariableDeclaration(
1721
+ node.name,
1722
+ void 0,
1723
+ void 0,
1724
+ arrowFunction
1725
+ )
1726
+ ],
1727
+ ts.NodeFlags.Const
1728
+ )
1729
+ );
1730
+ }
1731
+ changeTracker.replaceNode(sourceFile, node, newDeclaration);
1732
+ }
1733
+ })
1734
+ )
1735
+ )
1736
+ });
1737
+
1738
+ // src/refactors/pipeableToDatafirst.ts
1739
+ var pipeableToDatafirst = createRefactor({
1740
+ name: "effect/pipeableToDatafirst",
1741
+ description: "Rewrite to datafirst",
1742
+ apply: (ts, program) => (sourceFile, textRange) => pipe(
1743
+ getNodesContainingRange(ts)(sourceFile, textRange),
1744
+ filter(isPipeCall(ts)),
1745
+ filter((node) => isNodeInRange(textRange)(node.expression)),
1746
+ filter(
1747
+ (node) => node.arguments.length > 0
1748
+ ),
1749
+ map2((node) => {
1750
+ let newNode = node.arguments[0];
1751
+ let didSomething = false;
1752
+ for (let i = 1; i < node.arguments.length; i++) {
1753
+ const arg = node.arguments[i];
1754
+ const a = asDataFirstExpression(ts, program.getTypeChecker())(arg, newNode);
1755
+ if (isSome2(a)) {
1756
+ newNode = a.value;
1757
+ didSomething = true;
1758
+ } else {
1759
+ if (isPipeCall(ts)(newNode)) {
1760
+ newNode = ts.factory.createCallExpression(
1761
+ ts.factory.createIdentifier("pipe"),
1762
+ [],
1763
+ newNode.arguments.concat([arg])
1764
+ );
1765
+ } else {
1766
+ newNode = ts.factory.createCallExpression(ts.factory.createIdentifier("pipe"), [], [
1767
+ newNode,
1768
+ arg
1769
+ ]);
1770
+ }
1771
+ }
1772
+ }
1773
+ return didSomething ? some2([node, newNode]) : none2();
1774
+ }),
1775
+ filter(isSome2),
1776
+ map2((_) => _.value),
1777
+ head,
1778
+ map(([node, newNode]) => ({
1779
+ kind: "refactor.rewrite.effect.pipeableToDatafirst",
1780
+ description: "Rewrite to datafirst",
1781
+ apply: (changeTracker) => {
1782
+ changeTracker.replaceNode(sourceFile, node, newNode);
1783
+ }
1784
+ }))
1785
+ )
1786
+ });
1787
+
1788
+ // src/refactors/toggleLazyConst.ts
1789
+ var toggleLazyConst = createRefactor({
1790
+ name: "effect/toggleLazyConst",
1791
+ description: "Toggle type annotation",
1792
+ apply: (ts) => (sourceFile, textRange) => pipe(
1793
+ getNodesContainingRange(ts)(sourceFile, textRange),
1794
+ filter(ts.isVariableDeclaration),
1795
+ filter((node) => isNodeInRange(textRange)(node.name)),
1796
+ filter(
1797
+ (node) => !!node.initializer && !(ts.isArrowFunction(node.initializer) && ts.isBlock(node.initializer.body))
1798
+ ),
1799
+ head,
1800
+ map(
1801
+ (node) => ({
1802
+ kind: "refactor.rewrite.effect.toggleLazyConst",
1803
+ description: "Toggle lazy const",
1804
+ apply: (changeTracker) => {
1805
+ const initializer = node.initializer;
1806
+ if (ts.isArrowFunction(initializer) && initializer.parameters.length === 0) {
1807
+ changeTracker.deleteRange(sourceFile, {
1808
+ pos: initializer.body.end,
1809
+ end: initializer.end
1810
+ });
1811
+ changeTracker.deleteRange(sourceFile, {
1812
+ pos: initializer.pos,
1813
+ end: initializer.body.pos
1814
+ });
1815
+ return;
1816
+ }
1817
+ changeTracker.insertText(sourceFile, initializer.pos, " () =>");
1818
+ }
1819
+ })
1820
+ )
1821
+ )
1822
+ });
1823
+
1824
+ // src/refactors/toggleReturnTypeAnnotation.ts
1825
+ var toggleReturnTypeAnnotation = createRefactor({
1826
+ name: "effect/toggleReturnTypeAnnotation",
1827
+ description: "Toggle return type annotation",
1828
+ apply: (ts, program) => (sourceFile, textRange) => {
1829
+ function isConvertibleDeclaration(node) {
1830
+ switch (node.kind) {
1831
+ case ts.SyntaxKind.FunctionDeclaration:
1832
+ case ts.SyntaxKind.FunctionExpression:
1833
+ case ts.SyntaxKind.ArrowFunction:
1834
+ case ts.SyntaxKind.MethodDeclaration:
1835
+ return true;
1836
+ default:
1837
+ return false;
1838
+ }
1839
+ }
1840
+ return pipe(
1841
+ getNodesContainingRange(ts)(sourceFile, textRange),
1842
+ filter(isConvertibleDeclaration),
1843
+ head,
1844
+ map(
1845
+ (node) => ({
1846
+ kind: "refactor.rewrite.effect.toggleReturnTypeAnnotation",
1847
+ description: "Toggle return type annotation",
1848
+ apply: (changeTracker) => {
1849
+ const typeChecker = program.getTypeChecker();
1850
+ if (node.type) {
1851
+ removeReturnTypeAnnotation(ts, changeTracker)(sourceFile, node);
1852
+ return;
1853
+ }
1854
+ const callableType = typeChecker.getTypeAtLocation(node);
1855
+ const returnTypes = callableType.getCallSignatures().map((s) => s.getReturnType());
1856
+ const returnTypeNodes = returnTypes.map(
1857
+ (type) => typeChecker.typeToTypeNode(type, node, ts.NodeBuilderFlags.NoTruncation)
1858
+ ).filter((node2) => !!node2);
1859
+ if (returnTypeNodes.length === 0) return;
1860
+ const returnTypeNode = returnTypeNodes.length === 1 ? returnTypeNodes[0] : ts.factory.createUnionTypeNode(returnTypeNodes);
1861
+ addReturnTypeAnnotation(ts, changeTracker)(
1862
+ sourceFile,
1863
+ node,
1864
+ simplifyTypeNode(ts)(returnTypeNode)
1865
+ );
1866
+ }
1867
+ })
1868
+ )
1869
+ );
1870
+ }
1871
+ });
1872
+
1873
+ // src/refactors/toggleTypeAnnotation.ts
1874
+ var toggleTypeAnnotation = createRefactor({
1875
+ name: "effect/toggleTypeAnnotation",
1876
+ description: "Toggle type annotation",
1877
+ apply: (ts, program) => (sourceFile, textRange) => pipe(
1878
+ getNodesContainingRange(ts)(sourceFile, textRange),
1879
+ filter(
1880
+ (node) => ts.isVariableDeclaration(node) || ts.isPropertyDeclaration(node)
1881
+ ),
1882
+ filter((node) => isNodeInRange(textRange)(node.name)),
1883
+ filter((node) => !!node.initializer),
1884
+ head,
1885
+ map(
1886
+ (node) => ({
1887
+ kind: "refactor.rewrite.effect.toggleTypeAnnotation",
1888
+ description: "Toggle type annotation",
1889
+ apply: (changeTracker) => {
1890
+ const typeChecker = program.getTypeChecker();
1891
+ if (node.type) {
1892
+ changeTracker.deleteRange(sourceFile, { pos: node.name.end, end: node.type.end });
1893
+ return;
1894
+ }
1895
+ const initializer = node.initializer;
1896
+ const initializerType = typeChecker.getTypeAtLocation(initializer);
1897
+ const initializerTypeNode = typeChecker.typeToTypeNode(
1898
+ initializerType,
1899
+ node,
1900
+ ts.NodeBuilderFlags.NoTruncation
1901
+ );
1902
+ if (initializerTypeNode) {
1903
+ changeTracker.insertNodeAt(
1904
+ sourceFile,
1905
+ node.name.end,
1906
+ simplifyTypeNode(ts)(initializerTypeNode),
1907
+ {
1908
+ prefix: ": "
1909
+ }
1910
+ );
1911
+ }
1912
+ }
1913
+ })
1914
+ )
1915
+ )
1916
+ });
1917
+
1918
+ // src/refactors/wrapWithPipe.ts
1919
+ var wrapWithPipe = createRefactor({
1920
+ name: "effect/wrapWithPipe",
1921
+ description: "Wrap with pipe",
1922
+ apply: () => (sourceFile, textRange) => {
1923
+ if (textRange.end - textRange.pos === 0) return none2();
1924
+ return some2({
1925
+ kind: "refactor.rewrite.effect.wrapWithPipe",
1926
+ description: `Wrap with pipe(...)`,
1927
+ apply: (changeTracker) => {
1928
+ changeTracker.insertText(sourceFile, textRange.pos, "pipe(");
1929
+ changeTracker.insertText(sourceFile, textRange.end, ")");
1930
+ }
1931
+ });
1932
+ }
1933
+ });
1934
+
1935
+ // src/refactors.ts
1936
+ var refactors = {
1937
+ asyncAwaitToGen,
1938
+ asyncAwaitToGenTryPromise,
1939
+ functionToArrow,
1940
+ pipeableToDatafirst,
1941
+ toggleLazyConst,
1942
+ toggleReturnTypeAnnotation,
1943
+ toggleTypeAnnotation,
1944
+ wrapWithPipe
1945
+ };
1946
+
1947
+ // src/index.ts
1948
+ var init = (modules) => {
1949
+ const ts = modules.typescript;
1950
+ function create(info) {
1951
+ const languageService = info.languageService;
1952
+ const pluginOptions = {
1953
+ diagnostics: info.config && "diagnostics" in info.config && typeof info.config.diagnostics === "boolean" ? info.config.diagnostics : true,
1954
+ quickinfo: info.config && "quickinfo" in info.config && typeof info.config.quickinfo === "boolean" ? info.config.quickinfo : true
1955
+ };
1956
+ const proxy = /* @__PURE__ */ Object.create(null);
1957
+ for (const k of Object.keys(info.languageService)) {
1958
+ proxy[k] = (...args) => languageService[k].apply(languageService, args);
1959
+ }
1960
+ proxy.getSemanticDiagnostics = (fileName, ...args) => {
1961
+ const applicableDiagnostics = languageService.getSemanticDiagnostics(fileName, ...args);
1962
+ const program = languageService.getProgram();
1963
+ if (pluginOptions.diagnostics && program) {
1964
+ const effectDiagnostics = pipe(
1965
+ fromNullable(program.getSourceFile(fileName)),
1966
+ map(
1967
+ (sourceFile) => pipe(
1968
+ Object.values(diagnostics).map(
1969
+ (diagnostic) => pipe(
1970
+ diagnostic.apply(modules.typescript, program, pluginOptions)(
1971
+ sourceFile,
1972
+ applicableDiagnostics
1973
+ ).map((_) => ({
1974
+ file: sourceFile,
1975
+ start: _.node.getStart(sourceFile),
1976
+ length: _.node.getEnd() - _.node.getStart(sourceFile),
1977
+ messageText: _.messageText,
1978
+ category: _.category,
1979
+ code: diagnostic.code,
1980
+ source: "effect"
1981
+ }))
1982
+ )
1983
+ ),
1984
+ (_) => _.reduce(
1985
+ (arr, maybeRefactor) => arr.concat(maybeRefactor),
1986
+ []
1987
+ )
1988
+ )
1989
+ ),
1990
+ getOrElse(() => [])
1991
+ );
1992
+ return effectDiagnostics.concat(applicableDiagnostics);
1993
+ }
1994
+ return applicableDiagnostics;
1995
+ };
1996
+ proxy.getApplicableRefactors = (...args) => {
1997
+ const applicableRefactors = languageService.getApplicableRefactors(...args);
1998
+ const [fileName, positionOrRange] = args;
1999
+ const program = languageService.getProgram();
2000
+ if (program) {
2001
+ const textRange = toTextRange(positionOrRange);
2002
+ const effectRefactors = pipe(
2003
+ fromNullable(program.getSourceFile(fileName)),
2004
+ map(
2005
+ (sourceFile) => pipe(
2006
+ Object.values(refactors).map(
2007
+ (refactor) => pipe(
2008
+ refactor.apply(modules.typescript, program, pluginOptions)(
2009
+ sourceFile,
2010
+ textRange
2011
+ ),
2012
+ map((_) => ({
2013
+ name: refactor.name,
2014
+ description: refactor.description,
2015
+ actions: [{
2016
+ name: refactor.name,
2017
+ description: _.description,
2018
+ kind: _.kind
2019
+ }]
2020
+ }))
2021
+ )
2022
+ ),
2023
+ (_) => _.reduce(
2024
+ (arr, maybeRefactor) => arr.concat(isSome2(maybeRefactor) ? [maybeRefactor.value] : []),
2025
+ []
2026
+ )
2027
+ )
2028
+ ),
2029
+ getOrElse(() => [])
2030
+ );
2031
+ info.project.projectService.logger.info(
2032
+ "[@effect/language-service] possible refactors are " + JSON.stringify(effectRefactors)
2033
+ );
2034
+ return applicableRefactors.concat(effectRefactors);
2035
+ }
2036
+ return applicableRefactors;
2037
+ };
2038
+ proxy.getEditsForRefactor = (fileName, formatOptions, positionOrRange, refactorName, actionName, preferences, ...args) => {
2039
+ const program = languageService.getProgram();
2040
+ if (program) {
2041
+ for (const refactor of Object.values(refactors)) {
2042
+ if (refactor.name === refactorName) {
2043
+ const textRange = toTextRange(positionOrRange);
2044
+ const possibleRefactor = pipe(
2045
+ fromNullable(program.getSourceFile(fileName)),
2046
+ flatMap(
2047
+ (sourceFile) => refactor.apply(modules.typescript, program, pluginOptions)(
2048
+ sourceFile,
2049
+ textRange
2050
+ )
2051
+ )
2052
+ );
2053
+ if (isNone2(possibleRefactor)) {
2054
+ info.project.projectService.logger.info(
2055
+ "[@effect/language-service] requested refactor " + refactorName + " is not applicable"
2056
+ );
2057
+ return { edits: [] };
2058
+ }
2059
+ const formatContext = ts.formatting.getFormatContext(
2060
+ formatOptions,
2061
+ info.languageServiceHost
2062
+ );
2063
+ const edits = ts.textChanges.ChangeTracker.with(
2064
+ {
2065
+ formatContext,
2066
+ host: info.languageServiceHost,
2067
+ preferences: preferences || {}
2068
+ },
2069
+ (changeTracker) => possibleRefactor.value.apply(changeTracker)
2070
+ );
2071
+ return { edits };
2072
+ }
2073
+ }
2074
+ }
2075
+ return languageService.getEditsForRefactor(
2076
+ fileName,
2077
+ formatOptions,
2078
+ positionOrRange,
2079
+ refactorName,
2080
+ actionName,
2081
+ preferences,
2082
+ ...args
2083
+ );
2084
+ };
2085
+ proxy.getQuickInfoAtPosition = (fileName, position, ...args) => {
2086
+ const quickInfo = languageService.getQuickInfoAtPosition(fileName, position, ...args);
2087
+ if (pluginOptions.quickinfo && quickInfo) {
2088
+ const dedupedTagsQuickInfo = dedupeJsDocTags(quickInfo);
2089
+ const program = languageService.getProgram();
2090
+ if (program) {
2091
+ return prependEffectTypeArguments(ts, program)(fileName, position, dedupedTagsQuickInfo);
2092
+ }
2093
+ return dedupedTagsQuickInfo;
2094
+ }
2095
+ return quickInfo;
2096
+ };
2097
+ return proxy;
2098
+ }
2099
+ return { create };
2100
+ };
2101
+ module.exports = init;
2102
+ //# sourceMappingURL=index.js.map