@effect/language-service 0.28.2 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/cli.js +3497 -4362
- package/cli.js.map +1 -1
- package/index.js +1705 -1599
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +1107 -703
- package/transform.js.map +1 -1
package/index.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __export = (target, all3) => {
|
|
4
|
-
for (var name in all3)
|
|
5
|
-
__defProp(target, name, { get: all3[name], enumerable: true });
|
|
6
|
-
};
|
|
7
2
|
|
|
8
|
-
// node_modules/.pnpm/effect@3.
|
|
3
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Function.js
|
|
9
4
|
var isFunction = (input) => typeof input === "function";
|
|
10
5
|
var dual = function(arity, body) {
|
|
11
6
|
if (typeof arity === "function") {
|
|
@@ -101,7 +96,7 @@ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
|
|
|
101
96
|
}
|
|
102
97
|
}
|
|
103
98
|
|
|
104
|
-
// node_modules/.pnpm/effect@3.
|
|
99
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Equivalence.js
|
|
105
100
|
var make = (isEquivalent) => (self, that) => self === that || isEquivalent(self, that);
|
|
106
101
|
var array = (item) => make((self, that) => {
|
|
107
102
|
if (self.length !== that.length) {
|
|
@@ -116,12 +111,8 @@ var array = (item) => make((self, that) => {
|
|
|
116
111
|
return true;
|
|
117
112
|
});
|
|
118
113
|
|
|
119
|
-
// node_modules/.pnpm/effect@3.
|
|
120
|
-
var
|
|
121
|
-
var getCurrentVersion = () => moduleVersion;
|
|
122
|
-
|
|
123
|
-
// node_modules/.pnpm/effect@3.16.12/node_modules/effect/dist/esm/GlobalValue.js
|
|
124
|
-
var globalStoreId = `effect/GlobalValue/globalStoreId/${/* @__PURE__ */ getCurrentVersion()}`;
|
|
114
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/GlobalValue.js
|
|
115
|
+
var globalStoreId = `effect/GlobalValue`;
|
|
125
116
|
var globalStore;
|
|
126
117
|
var globalValue = (id, compute) => {
|
|
127
118
|
if (!globalStore) {
|
|
@@ -134,156 +125,20 @@ var globalValue = (id, compute) => {
|
|
|
134
125
|
return globalStore.get(id);
|
|
135
126
|
};
|
|
136
127
|
|
|
137
|
-
// node_modules/.pnpm/effect@3.
|
|
138
|
-
var Predicate_exports = {};
|
|
139
|
-
__export(Predicate_exports, {
|
|
140
|
-
all: () => all,
|
|
141
|
-
and: () => and,
|
|
142
|
-
compose: () => compose,
|
|
143
|
-
eqv: () => eqv,
|
|
144
|
-
every: () => every,
|
|
145
|
-
hasProperty: () => hasProperty,
|
|
146
|
-
implies: () => implies,
|
|
147
|
-
isBigInt: () => isBigInt,
|
|
148
|
-
isBoolean: () => isBoolean,
|
|
149
|
-
isDate: () => isDate,
|
|
150
|
-
isError: () => isError,
|
|
151
|
-
isFunction: () => isFunction2,
|
|
152
|
-
isIterable: () => isIterable,
|
|
153
|
-
isMap: () => isMap,
|
|
154
|
-
isNever: () => isNever,
|
|
155
|
-
isNotNull: () => isNotNull,
|
|
156
|
-
isNotNullable: () => isNotNullable,
|
|
157
|
-
isNotUndefined: () => isNotUndefined,
|
|
158
|
-
isNull: () => isNull,
|
|
159
|
-
isNullable: () => isNullable,
|
|
160
|
-
isNumber: () => isNumber,
|
|
161
|
-
isObject: () => isObject,
|
|
162
|
-
isPromise: () => isPromise,
|
|
163
|
-
isPromiseLike: () => isPromiseLike,
|
|
164
|
-
isPropertyKey: () => isPropertyKey,
|
|
165
|
-
isReadonlyRecord: () => isReadonlyRecord,
|
|
166
|
-
isRecord: () => isRecord,
|
|
167
|
-
isRecordOrArray: () => isRecordOrArray,
|
|
168
|
-
isRegExp: () => isRegExp,
|
|
169
|
-
isSet: () => isSet,
|
|
170
|
-
isString: () => isString,
|
|
171
|
-
isSymbol: () => isSymbol,
|
|
172
|
-
isTagged: () => isTagged,
|
|
173
|
-
isTruthy: () => isTruthy,
|
|
174
|
-
isTupleOf: () => isTupleOf,
|
|
175
|
-
isTupleOfAtLeast: () => isTupleOfAtLeast,
|
|
176
|
-
isUint8Array: () => isUint8Array,
|
|
177
|
-
isUndefined: () => isUndefined,
|
|
178
|
-
isUnknown: () => isUnknown,
|
|
179
|
-
mapInput: () => mapInput,
|
|
180
|
-
nand: () => nand,
|
|
181
|
-
nor: () => nor,
|
|
182
|
-
not: () => not,
|
|
183
|
-
or: () => or,
|
|
184
|
-
product: () => product,
|
|
185
|
-
productMany: () => productMany,
|
|
186
|
-
some: () => some,
|
|
187
|
-
struct: () => struct,
|
|
188
|
-
tuple: () => tuple,
|
|
189
|
-
xor: () => xor
|
|
190
|
-
});
|
|
191
|
-
var mapInput = /* @__PURE__ */ dual(2, (self, f) => (b) => self(f(b)));
|
|
192
|
-
var isTupleOf = /* @__PURE__ */ dual(2, (self, n) => self.length === n);
|
|
193
|
-
var isTupleOfAtLeast = /* @__PURE__ */ dual(2, (self, n) => self.length >= n);
|
|
194
|
-
var isTruthy = (input) => !!input;
|
|
195
|
-
var isSet = (input) => input instanceof Set;
|
|
196
|
-
var isMap = (input) => input instanceof Map;
|
|
128
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Predicate.js
|
|
197
129
|
var isString = (input) => typeof input === "string";
|
|
198
130
|
var isNumber = (input) => typeof input === "number";
|
|
199
131
|
var isBoolean = (input) => typeof input === "boolean";
|
|
200
|
-
var isBigInt = (input) => typeof input === "bigint";
|
|
201
|
-
var isSymbol = (input) => typeof input === "symbol";
|
|
202
|
-
var isPropertyKey = (u) => isString(u) || isNumber(u) || isSymbol(u);
|
|
203
132
|
var isFunction2 = isFunction;
|
|
204
|
-
var isUndefined = (input) => input === void 0;
|
|
205
|
-
var isNotUndefined = (input) => input !== void 0;
|
|
206
|
-
var isNull = (input) => input === null;
|
|
207
|
-
var isNotNull = (input) => input !== null;
|
|
208
|
-
var isNever = (_) => false;
|
|
209
|
-
var isUnknown = (_) => true;
|
|
210
133
|
var isRecordOrArray = (input) => typeof input === "object" && input !== null;
|
|
211
134
|
var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
|
|
212
135
|
var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObject(self) && property in self);
|
|
213
|
-
var isTagged = /* @__PURE__ */ dual(2, (self, tag) => hasProperty(self, "_tag") && self["_tag"] === tag);
|
|
214
|
-
var isNullable = (input) => input === null || input === void 0;
|
|
215
|
-
var isNotNullable = (input) => input !== null && input !== void 0;
|
|
216
|
-
var isError = (input) => input instanceof Error;
|
|
217
|
-
var isUint8Array = (input) => input instanceof Uint8Array;
|
|
218
|
-
var isDate = (input) => input instanceof Date;
|
|
219
|
-
var isIterable = (input) => hasProperty(input, Symbol.iterator);
|
|
220
136
|
var isRecord = (input) => isRecordOrArray(input) && !Array.isArray(input);
|
|
221
|
-
var isReadonlyRecord = isRecord;
|
|
222
|
-
var isPromise = (input) => hasProperty(input, "then") && "catch" in input && isFunction2(input.then) && isFunction2(input.catch);
|
|
223
|
-
var isPromiseLike = (input) => hasProperty(input, "then") && isFunction2(input.then);
|
|
224
|
-
var isRegExp = (input) => input instanceof RegExp;
|
|
225
|
-
var compose = /* @__PURE__ */ dual(2, (ab, bc) => (a) => ab(a) && bc(a));
|
|
226
|
-
var product = (self, that) => ([a, b]) => self(a) && that(b);
|
|
227
|
-
var all = (collection) => {
|
|
228
|
-
return (as) => {
|
|
229
|
-
let collectionIndex = 0;
|
|
230
|
-
for (const p of collection) {
|
|
231
|
-
if (collectionIndex >= as.length) {
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
if (p(as[collectionIndex]) === false) {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
collectionIndex++;
|
|
238
|
-
}
|
|
239
|
-
return true;
|
|
240
|
-
};
|
|
241
|
-
};
|
|
242
|
-
var productMany = (self, collection) => {
|
|
243
|
-
const rest = all(collection);
|
|
244
|
-
return ([head2, ...tail]) => self(head2) === false ? false : rest(tail);
|
|
245
|
-
};
|
|
246
|
-
var tuple = (...elements) => all(elements);
|
|
247
|
-
var struct = (fields) => {
|
|
248
|
-
const keys = Object.keys(fields);
|
|
249
|
-
return (a) => {
|
|
250
|
-
for (const key of keys) {
|
|
251
|
-
if (!fields[key](a[key])) {
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return true;
|
|
256
|
-
};
|
|
257
|
-
};
|
|
258
|
-
var not = (self) => (a) => !self(a);
|
|
259
|
-
var or = /* @__PURE__ */ dual(2, (self, that) => (a) => self(a) || that(a));
|
|
260
|
-
var and = /* @__PURE__ */ dual(2, (self, that) => (a) => self(a) && that(a));
|
|
261
|
-
var xor = /* @__PURE__ */ dual(2, (self, that) => (a) => self(a) !== that(a));
|
|
262
|
-
var eqv = /* @__PURE__ */ dual(2, (self, that) => (a) => self(a) === that(a));
|
|
263
|
-
var implies = /* @__PURE__ */ dual(2, (antecedent, consequent) => (a) => antecedent(a) ? consequent(a) : true);
|
|
264
|
-
var nor = /* @__PURE__ */ dual(2, (self, that) => (a) => !(self(a) || that(a)));
|
|
265
|
-
var nand = /* @__PURE__ */ dual(2, (self, that) => (a) => !(self(a) && that(a)));
|
|
266
|
-
var every = (collection) => (a) => {
|
|
267
|
-
for (const p of collection) {
|
|
268
|
-
if (!p(a)) {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return true;
|
|
273
|
-
};
|
|
274
|
-
var some = (collection) => (a) => {
|
|
275
|
-
for (const p of collection) {
|
|
276
|
-
if (p(a)) {
|
|
277
|
-
return true;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return false;
|
|
281
|
-
};
|
|
282
137
|
|
|
283
|
-
// node_modules/.pnpm/effect@3.
|
|
138
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/errors.js
|
|
284
139
|
var getBugErrorMessage = (message) => `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`;
|
|
285
140
|
|
|
286
|
-
// node_modules/.pnpm/effect@3.
|
|
141
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Utils.js
|
|
287
142
|
var GenKindTypeId = /* @__PURE__ */ Symbol.for("effect/Gen/GenKind");
|
|
288
143
|
var GenKindImpl = class {
|
|
289
144
|
value;
|
|
@@ -411,7 +266,7 @@ var internalCall = isNotOptimizedAway ? standard.effect_internal_function : forc
|
|
|
411
266
|
var genConstructor = function* () {
|
|
412
267
|
}.constructor;
|
|
413
268
|
|
|
414
|
-
// node_modules/.pnpm/effect@3.
|
|
269
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Hash.js
|
|
415
270
|
var randomHashCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Hash/randomHashCache"), () => /* @__PURE__ */ new WeakMap());
|
|
416
271
|
var symbol = /* @__PURE__ */ Symbol.for("effect/Hash");
|
|
417
272
|
var hash = (self) => {
|
|
@@ -510,7 +365,7 @@ var cached = function() {
|
|
|
510
365
|
return hash2;
|
|
511
366
|
};
|
|
512
367
|
|
|
513
|
-
// node_modules/.pnpm/effect@3.
|
|
368
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Equal.js
|
|
514
369
|
var symbol2 = /* @__PURE__ */ Symbol.for("effect/Equal");
|
|
515
370
|
function equals() {
|
|
516
371
|
if (arguments.length === 1) {
|
|
@@ -564,7 +419,7 @@ function compareBoth(self, that) {
|
|
|
564
419
|
var isEqual = (u) => hasProperty(u, symbol2);
|
|
565
420
|
var equivalence = () => equals;
|
|
566
421
|
|
|
567
|
-
// node_modules/.pnpm/effect@3.
|
|
422
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Inspectable.js
|
|
568
423
|
var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
569
424
|
var toJSON = (x) => {
|
|
570
425
|
try {
|
|
@@ -616,7 +471,7 @@ var redact = (u) => {
|
|
|
616
471
|
return u;
|
|
617
472
|
};
|
|
618
473
|
|
|
619
|
-
// node_modules/.pnpm/effect@3.
|
|
474
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Pipeable.js
|
|
620
475
|
var pipeArguments = (self, args2) => {
|
|
621
476
|
switch (args2.length) {
|
|
622
477
|
case 0:
|
|
@@ -649,10 +504,14 @@ var pipeArguments = (self, args2) => {
|
|
|
649
504
|
}
|
|
650
505
|
};
|
|
651
506
|
|
|
652
|
-
// node_modules/.pnpm/effect@3.
|
|
507
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/opCodes/effect.js
|
|
653
508
|
var OP_COMMIT = "Commit";
|
|
654
509
|
|
|
655
|
-
// node_modules/.pnpm/effect@3.
|
|
510
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/version.js
|
|
511
|
+
var moduleVersion = "3.17.1";
|
|
512
|
+
var getCurrentVersion = () => moduleVersion;
|
|
513
|
+
|
|
514
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/effectable.js
|
|
656
515
|
var EffectTypeId = /* @__PURE__ */ Symbol.for("effect/Effect");
|
|
657
516
|
var StreamTypeId = /* @__PURE__ */ Symbol.for("effect/Stream");
|
|
658
517
|
var SinkTypeId = /* @__PURE__ */ Symbol.for("effect/Sink");
|
|
@@ -739,7 +598,7 @@ var StructuralCommitPrototype = {
|
|
|
739
598
|
...StructuralPrototype
|
|
740
599
|
};
|
|
741
600
|
|
|
742
|
-
// node_modules/.pnpm/effect@3.
|
|
601
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/option.js
|
|
743
602
|
var TypeId = /* @__PURE__ */ Symbol.for("effect/Option");
|
|
744
603
|
var CommonProto = {
|
|
745
604
|
...EffectPrototype,
|
|
@@ -791,13 +650,13 @@ var isOption = (input) => hasProperty(input, TypeId);
|
|
|
791
650
|
var isNone = (fa) => fa._tag === "None";
|
|
792
651
|
var isSome = (fa) => fa._tag === "Some";
|
|
793
652
|
var none = /* @__PURE__ */ Object.create(NoneProto);
|
|
794
|
-
var
|
|
653
|
+
var some = (value) => {
|
|
795
654
|
const a = Object.create(SomeProto);
|
|
796
655
|
a.value = value;
|
|
797
656
|
return a;
|
|
798
657
|
};
|
|
799
658
|
|
|
800
|
-
// node_modules/.pnpm/effect@3.
|
|
659
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/either.js
|
|
801
660
|
var TypeId2 = /* @__PURE__ */ Symbol.for("effect/Either");
|
|
802
661
|
var CommonProto2 = {
|
|
803
662
|
...EffectPrototype,
|
|
@@ -859,7 +718,7 @@ var right = (right3) => {
|
|
|
859
718
|
return a;
|
|
860
719
|
};
|
|
861
720
|
|
|
862
|
-
// node_modules/.pnpm/effect@3.
|
|
721
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Either.js
|
|
863
722
|
var right2 = right;
|
|
864
723
|
var left2 = left;
|
|
865
724
|
var isLeft2 = isLeft;
|
|
@@ -867,112 +726,20 @@ var isRight2 = isRight;
|
|
|
867
726
|
var map = /* @__PURE__ */ dual(2, (self, f) => isRight2(self) ? right2(f(self.right)) : left2(self.left));
|
|
868
727
|
var getOrElse = /* @__PURE__ */ dual(2, (self, onLeft) => isLeft2(self) ? onLeft(self.left) : self.right);
|
|
869
728
|
|
|
870
|
-
// node_modules/.pnpm/effect@3.
|
|
729
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Order.js
|
|
871
730
|
var make2 = (compare) => (self, that) => self === that ? 0 : compare(self, that);
|
|
872
731
|
var string2 = /* @__PURE__ */ make2((self, that) => self < that ? -1 : 1);
|
|
873
732
|
|
|
874
|
-
// node_modules/.pnpm/effect@3.
|
|
733
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Option.js
|
|
875
734
|
var none2 = () => none;
|
|
876
|
-
var
|
|
735
|
+
var some2 = some;
|
|
877
736
|
var isNone2 = isNone;
|
|
878
737
|
var isSome2 = isSome;
|
|
879
|
-
var match = /* @__PURE__ */ dual(2, (self, {
|
|
880
|
-
onNone,
|
|
881
|
-
onSome
|
|
882
|
-
}) => isNone2(self) ? onNone() : onSome(self.value));
|
|
883
738
|
var getOrElse2 = /* @__PURE__ */ dual(2, (self, onNone) => isNone2(self) ? onNone() : self.value);
|
|
884
739
|
var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : self);
|
|
885
|
-
var fromNullable = (nullableValue) => nullableValue == null ? none2() :
|
|
740
|
+
var fromNullable = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
|
|
886
741
|
var getOrUndefined = /* @__PURE__ */ getOrElse2(constUndefined);
|
|
887
|
-
var map2 = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() :
|
|
888
|
-
|
|
889
|
-
// node_modules/.pnpm/effect@3.16.12/node_modules/effect/dist/esm/internal/array.js
|
|
890
|
-
var isNonEmptyArray = (self) => self.length > 0;
|
|
891
|
-
|
|
892
|
-
// node_modules/.pnpm/effect@3.16.12/node_modules/effect/dist/esm/Array.js
|
|
893
|
-
var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
|
|
894
|
-
var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
|
|
895
|
-
var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
|
|
896
|
-
var isArray = Array.isArray;
|
|
897
|
-
var isEmptyArray = (self) => self.length === 0;
|
|
898
|
-
var isEmptyReadonlyArray = isEmptyArray;
|
|
899
|
-
var isNonEmptyReadonlyArray = isNonEmptyArray;
|
|
900
|
-
var isOutOfBounds = (i, as) => i < 0 || i >= as.length;
|
|
901
|
-
var get = /* @__PURE__ */ dual(2, (self, index) => {
|
|
902
|
-
const i = Math.floor(index);
|
|
903
|
-
return isOutOfBounds(i, self) ? none2() : some3(self[i]);
|
|
904
|
-
});
|
|
905
|
-
var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
|
|
906
|
-
const i = Math.floor(index);
|
|
907
|
-
if (isOutOfBounds(i, self)) {
|
|
908
|
-
throw new Error(`Index ${i} out of bounds`);
|
|
909
|
-
}
|
|
910
|
-
return self[i];
|
|
911
|
-
});
|
|
912
|
-
var head = /* @__PURE__ */ get(0);
|
|
913
|
-
var headNonEmpty = /* @__PURE__ */ unsafeGet(0);
|
|
914
|
-
var tailNonEmpty = (self) => self.slice(1);
|
|
915
|
-
var sort = /* @__PURE__ */ dual(2, (self, O) => {
|
|
916
|
-
const out = Array.from(self);
|
|
917
|
-
out.sort(O);
|
|
918
|
-
return out;
|
|
919
|
-
});
|
|
920
|
-
var containsWith = (isEquivalent) => dual(2, (self, a) => {
|
|
921
|
-
for (const i of self) {
|
|
922
|
-
if (isEquivalent(a, i)) {
|
|
923
|
-
return true;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
return false;
|
|
927
|
-
});
|
|
928
|
-
var _equivalence = /* @__PURE__ */ equivalence();
|
|
929
|
-
var intersectionWith = (isEquivalent) => {
|
|
930
|
-
const has = containsWith(isEquivalent);
|
|
931
|
-
return dual(2, (self, that) => fromIterable(self).filter((a) => has(that, a)));
|
|
932
|
-
};
|
|
933
|
-
var intersection = /* @__PURE__ */ intersectionWith(_equivalence);
|
|
934
|
-
var empty = () => [];
|
|
935
|
-
var map3 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
|
|
936
|
-
var flatMap = /* @__PURE__ */ dual(2, (self, f) => {
|
|
937
|
-
if (isEmptyReadonlyArray(self)) {
|
|
938
|
-
return [];
|
|
939
|
-
}
|
|
940
|
-
const out = [];
|
|
941
|
-
for (let i = 0; i < self.length; i++) {
|
|
942
|
-
const inner = f(self[i], i);
|
|
943
|
-
for (let j = 0; j < inner.length; j++) {
|
|
944
|
-
out.push(inner[j]);
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
return out;
|
|
948
|
-
});
|
|
949
|
-
var flatten = /* @__PURE__ */ flatMap(identity);
|
|
950
|
-
var filter = /* @__PURE__ */ dual(2, (self, predicate) => {
|
|
951
|
-
const as = fromIterable(self);
|
|
952
|
-
const out = [];
|
|
953
|
-
for (let i = 0; i < as.length; i++) {
|
|
954
|
-
if (predicate(as[i], i)) {
|
|
955
|
-
out.push(as[i]);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
return out;
|
|
959
|
-
});
|
|
960
|
-
var every2 = /* @__PURE__ */ dual(2, (self, refinement) => self.every(refinement));
|
|
961
|
-
var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
|
|
962
|
-
const input = fromIterable(self);
|
|
963
|
-
if (isNonEmptyReadonlyArray(input)) {
|
|
964
|
-
const out = [headNonEmpty(input)];
|
|
965
|
-
const rest = tailNonEmpty(input);
|
|
966
|
-
for (const r of rest) {
|
|
967
|
-
if (out.every((a) => !isEquivalent(r, a))) {
|
|
968
|
-
out.push(r);
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
return out;
|
|
972
|
-
}
|
|
973
|
-
return [];
|
|
974
|
-
});
|
|
975
|
-
var dedupe = (self) => dedupeWith(self, equivalence());
|
|
742
|
+
var map2 = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() : some2(f(self.value)));
|
|
976
743
|
|
|
977
744
|
// src/core/Nano.ts
|
|
978
745
|
var NanoTag = class {
|
|
@@ -1091,13 +858,13 @@ var OnSuccessProto = {
|
|
|
1091
858
|
return this[args];
|
|
1092
859
|
}
|
|
1093
860
|
};
|
|
1094
|
-
var
|
|
861
|
+
var flatMap = dual(2, (fa, f) => {
|
|
1095
862
|
const nano = Object.create(OnSuccessProto);
|
|
1096
863
|
nano[args] = fa;
|
|
1097
864
|
nano[contA] = f;
|
|
1098
865
|
return nano;
|
|
1099
866
|
});
|
|
1100
|
-
var
|
|
867
|
+
var map3 = dual(2, (fa, f) => flatMap(fa, (_) => succeed(f(_))));
|
|
1101
868
|
var SyncProto = {
|
|
1102
869
|
...PrimitiveProto,
|
|
1103
870
|
[evaluate](fiber) {
|
|
@@ -1138,7 +905,7 @@ var MatchProto = {
|
|
|
1138
905
|
return this[args];
|
|
1139
906
|
}
|
|
1140
907
|
};
|
|
1141
|
-
var
|
|
908
|
+
var match = (fa, opts) => {
|
|
1142
909
|
const nano = Object.create(MatchProto);
|
|
1143
910
|
nano[args] = fa;
|
|
1144
911
|
nano[contA] = opts.onSuccess;
|
|
@@ -1161,7 +928,7 @@ var ProvideServiceProto = {
|
|
|
1161
928
|
...fiber._services,
|
|
1162
929
|
[tag.key]: value
|
|
1163
930
|
};
|
|
1164
|
-
return
|
|
931
|
+
return match(fa, {
|
|
1165
932
|
onSuccess: (_) => {
|
|
1166
933
|
fiber._services = prevServices;
|
|
1167
934
|
return succeed(_);
|
|
@@ -1204,7 +971,7 @@ var CachedProto = {
|
|
|
1204
971
|
fiber._cache[type] = cache;
|
|
1205
972
|
const cached2 = cache.get(key);
|
|
1206
973
|
if (cached2) return cached2;
|
|
1207
|
-
return
|
|
974
|
+
return match(fa, {
|
|
1208
975
|
onSuccess: (_) => {
|
|
1209
976
|
cache.set(key, succeed(_));
|
|
1210
977
|
return succeed(_);
|
|
@@ -1226,7 +993,7 @@ function cachedBy(fa, type, lookupKey) {
|
|
|
1226
993
|
var option = (fa) => {
|
|
1227
994
|
const nano = Object.create(MatchProto);
|
|
1228
995
|
nano[args] = fa;
|
|
1229
|
-
nano[contA] = (_) => succeed(
|
|
996
|
+
nano[contA] = (_) => succeed(some2(_));
|
|
1230
997
|
nano[contE] = (_) => _ instanceof NanoDefectException ? fail(_) : succeed(none2());
|
|
1231
998
|
return nano;
|
|
1232
999
|
};
|
|
@@ -1237,7 +1004,7 @@ var ignore = (fa) => {
|
|
|
1237
1004
|
nano[contE] = (_) => _ instanceof NanoDefectException ? fail(_) : void_;
|
|
1238
1005
|
return nano;
|
|
1239
1006
|
};
|
|
1240
|
-
var
|
|
1007
|
+
var all = fn("all")(
|
|
1241
1008
|
function* (...args2) {
|
|
1242
1009
|
const results = [];
|
|
1243
1010
|
for (const fa of args2) {
|
|
@@ -1252,44 +1019,138 @@ var all2 = fn("all")(
|
|
|
1252
1019
|
var TypeScriptApi = Tag("TypeScriptApi");
|
|
1253
1020
|
var TypeScriptProgram = Tag("TypeScriptProgram");
|
|
1254
1021
|
var ChangeTracker = Tag("ChangeTracker");
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1022
|
+
|
|
1023
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/array.js
|
|
1024
|
+
var isNonEmptyArray = (self) => self.length > 0;
|
|
1025
|
+
|
|
1026
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Array.js
|
|
1027
|
+
var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
|
|
1028
|
+
var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
|
|
1029
|
+
var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
|
|
1030
|
+
var isArray = Array.isArray;
|
|
1031
|
+
var isEmptyArray = (self) => self.length === 0;
|
|
1032
|
+
var isEmptyReadonlyArray = isEmptyArray;
|
|
1033
|
+
var isNonEmptyReadonlyArray = isNonEmptyArray;
|
|
1034
|
+
var isOutOfBounds = (i, as) => i < 0 || i >= as.length;
|
|
1035
|
+
var get = /* @__PURE__ */ dual(2, (self, index) => {
|
|
1036
|
+
const i = Math.floor(index);
|
|
1037
|
+
return isOutOfBounds(i, self) ? none2() : some2(self[i]);
|
|
1038
|
+
});
|
|
1039
|
+
var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
|
|
1040
|
+
const i = Math.floor(index);
|
|
1041
|
+
if (isOutOfBounds(i, self)) {
|
|
1042
|
+
throw new Error(`Index ${i} out of bounds`);
|
|
1043
|
+
}
|
|
1044
|
+
return self[i];
|
|
1045
|
+
});
|
|
1046
|
+
var head = /* @__PURE__ */ get(0);
|
|
1047
|
+
var headNonEmpty = /* @__PURE__ */ unsafeGet(0);
|
|
1048
|
+
var tailNonEmpty = (self) => self.slice(1);
|
|
1049
|
+
var sort = /* @__PURE__ */ dual(2, (self, O) => {
|
|
1050
|
+
const out = Array.from(self);
|
|
1051
|
+
out.sort(O);
|
|
1052
|
+
return out;
|
|
1053
|
+
});
|
|
1054
|
+
var containsWith = (isEquivalent) => dual(2, (self, a) => {
|
|
1055
|
+
for (const i of self) {
|
|
1056
|
+
if (isEquivalent(a, i)) {
|
|
1057
|
+
return true;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
return false;
|
|
1061
|
+
});
|
|
1062
|
+
var _equivalence = /* @__PURE__ */ equivalence();
|
|
1063
|
+
var intersectionWith = (isEquivalent) => {
|
|
1064
|
+
const has = containsWith(isEquivalent);
|
|
1065
|
+
return dual(2, (self, that) => fromIterable(self).filter((a) => has(that, a)));
|
|
1066
|
+
};
|
|
1067
|
+
var intersection = /* @__PURE__ */ intersectionWith(_equivalence);
|
|
1068
|
+
var empty = () => [];
|
|
1069
|
+
var map4 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
|
|
1070
|
+
var flatMap2 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
1071
|
+
if (isEmptyReadonlyArray(self)) {
|
|
1072
|
+
return [];
|
|
1073
|
+
}
|
|
1074
|
+
const out = [];
|
|
1075
|
+
for (let i = 0; i < self.length; i++) {
|
|
1076
|
+
const inner = f(self[i], i);
|
|
1077
|
+
for (let j = 0; j < inner.length; j++) {
|
|
1078
|
+
out.push(inner[j]);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return out;
|
|
1082
|
+
});
|
|
1083
|
+
var flatten = /* @__PURE__ */ flatMap2(identity);
|
|
1084
|
+
var filter = /* @__PURE__ */ dual(2, (self, predicate) => {
|
|
1085
|
+
const as = fromIterable(self);
|
|
1086
|
+
const out = [];
|
|
1087
|
+
for (let i = 0; i < as.length; i++) {
|
|
1088
|
+
if (predicate(as[i], i)) {
|
|
1089
|
+
out.push(as[i]);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
return out;
|
|
1093
|
+
});
|
|
1094
|
+
var every = /* @__PURE__ */ dual(2, (self, refinement) => self.every(refinement));
|
|
1095
|
+
var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
|
|
1096
|
+
const input = fromIterable(self);
|
|
1097
|
+
if (isNonEmptyReadonlyArray(input)) {
|
|
1098
|
+
const out = [headNonEmpty(input)];
|
|
1099
|
+
const rest = tailNonEmpty(input);
|
|
1100
|
+
for (const r of rest) {
|
|
1101
|
+
if (out.every((a) => !isEquivalent(r, a))) {
|
|
1102
|
+
out.push(r);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
return out;
|
|
1106
|
+
}
|
|
1107
|
+
return [];
|
|
1108
|
+
});
|
|
1109
|
+
var dedupe = (self) => dedupeWith(self, equivalence());
|
|
1110
|
+
|
|
1111
|
+
// src/core/TypeScriptUtils.ts
|
|
1112
|
+
var TypeScriptUtils = Tag("TypeScriptUtils");
|
|
1113
|
+
var nanoLayer = (fa) => pipe(
|
|
1114
|
+
service(TypeScriptApi),
|
|
1115
|
+
flatMap((ts) => pipe(fa, provideService(TypeScriptUtils, makeTypeScriptUtils(ts))))
|
|
1116
|
+
);
|
|
1117
|
+
function makeTypeScriptUtils(ts) {
|
|
1118
|
+
function parsePackageContentNameAndVersionFromScope(v) {
|
|
1119
|
+
if (!isObject(v)) return;
|
|
1120
|
+
if (!hasProperty(v, "packageJsonScope")) return;
|
|
1121
|
+
if (!v.packageJsonScope) return;
|
|
1122
|
+
const packageJsonScope = v.packageJsonScope;
|
|
1123
|
+
if (!hasProperty(packageJsonScope, "contents")) return;
|
|
1124
|
+
if (!hasProperty(packageJsonScope.contents, "packageJsonContent")) return;
|
|
1125
|
+
const packageJsonContent = packageJsonScope.contents.packageJsonContent;
|
|
1126
|
+
if (!hasProperty(packageJsonContent, "name")) return;
|
|
1127
|
+
if (!hasProperty(packageJsonContent, "version")) return;
|
|
1128
|
+
if (!hasProperty(packageJsonScope, "packageDirectory")) return;
|
|
1129
|
+
if (!isString(packageJsonScope.packageDirectory)) return;
|
|
1130
|
+
const { name, version } = packageJsonContent;
|
|
1131
|
+
if (!isString(name)) return;
|
|
1132
|
+
if (!isString(version)) return;
|
|
1133
|
+
const hasEffectInPeerDependencies = hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) && hasProperty(packageJsonContent.peerDependencies, "effect");
|
|
1134
|
+
const referencedPackages = Object.keys({
|
|
1135
|
+
...hasProperty(packageJsonContent, "dependencies") && isObject(packageJsonContent.dependencies) ? packageJsonContent.dependencies : {},
|
|
1136
|
+
...hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) ? packageJsonContent.peerDependencies : {},
|
|
1137
|
+
...hasProperty(packageJsonContent, "devDependencies") && isObject(packageJsonContent.devDependencies) ? packageJsonContent.devDependencies : {}
|
|
1138
|
+
});
|
|
1139
|
+
const exportsKeys = Object.keys(
|
|
1140
|
+
hasProperty(packageJsonContent, "exports") && isObject(packageJsonContent.exports) ? packageJsonContent.exports : {}
|
|
1141
|
+
);
|
|
1142
|
+
return {
|
|
1143
|
+
name: name.toLowerCase(),
|
|
1144
|
+
version: version.toLowerCase(),
|
|
1145
|
+
hasEffectInPeerDependencies,
|
|
1146
|
+
contents: packageJsonContent,
|
|
1147
|
+
packageDirectory: packageJsonScope.packageDirectory,
|
|
1148
|
+
referencedPackages,
|
|
1149
|
+
exportsKeys
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
function resolveModulePattern(sourceFile, pattern) {
|
|
1291
1153
|
if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
|
|
1292
|
-
const ts = yield* service(TypeScriptApi);
|
|
1293
1154
|
const packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
|
|
1294
1155
|
const referencedPackages = [];
|
|
1295
1156
|
for (const statement of sourceFile.statements) {
|
|
@@ -1302,31 +1163,47 @@ var resolveModulePattern = fn("resolveModulePattern")(
|
|
|
1302
1163
|
return pipe(
|
|
1303
1164
|
referencedPackages.concat(packageJsonScope?.referencedPackages || []),
|
|
1304
1165
|
dedupe,
|
|
1305
|
-
|
|
1166
|
+
map4((packageName) => packageName.toLowerCase()),
|
|
1306
1167
|
filter(
|
|
1307
1168
|
(packageName) => pattern.endsWith("*") && packageName.startsWith(pattern.toLowerCase().substring(0, pattern.length - 1))
|
|
1308
1169
|
)
|
|
1309
1170
|
);
|
|
1310
1171
|
}
|
|
1311
|
-
)
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
function
|
|
1329
|
-
|
|
1172
|
+
function makeGetModuleSpecifier() {
|
|
1173
|
+
if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
|
|
1174
|
+
const _internal = ts.moduleSpecifiers.getModuleSpecifier;
|
|
1175
|
+
return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options) => {
|
|
1176
|
+
return _internal(
|
|
1177
|
+
compilerOptions,
|
|
1178
|
+
importingSourceFile,
|
|
1179
|
+
importingSourceFileName,
|
|
1180
|
+
toFileName,
|
|
1181
|
+
host,
|
|
1182
|
+
options
|
|
1183
|
+
);
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
function findNodeWithLeadingCommentAtPosition(sourceFile, position) {
|
|
1187
|
+
const sourceText = sourceFile.text;
|
|
1188
|
+
let result;
|
|
1189
|
+
function find(node) {
|
|
1190
|
+
const leading = ts.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1191
|
+
if (leading) {
|
|
1192
|
+
for (const commentRange of leading) {
|
|
1193
|
+
if (commentRange.pos <= position && position < commentRange.end) {
|
|
1194
|
+
result = { node, commentRange };
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
if (node.getFullStart() <= position && position < node.getEnd()) {
|
|
1200
|
+
node.forEachChild(find);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
find(sourceFile);
|
|
1204
|
+
return result;
|
|
1205
|
+
}
|
|
1206
|
+
function collectSelfAndAncestorNodesInRange(node, textRange) {
|
|
1330
1207
|
let result = empty();
|
|
1331
1208
|
let parent = node;
|
|
1332
1209
|
while (parent) {
|
|
@@ -1336,52 +1213,50 @@ function collectSelfAndAncestorNodesInRange(node, textRange) {
|
|
|
1336
1213
|
parent = parent.parent;
|
|
1337
1214
|
}
|
|
1338
1215
|
return result;
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
var NodeNotFoundError = class {
|
|
1347
|
-
_tag = "@effect/language-service/NodeNotFoundError";
|
|
1348
|
-
};
|
|
1349
|
-
var findNodeAtPosition = fn("AST.findNodeAtPosition")(function* (sourceFile, position) {
|
|
1350
|
-
const ts = yield* service(TypeScriptApi);
|
|
1351
|
-
function find(node) {
|
|
1352
|
-
if (position >= node.getStart() && position < node.getEnd()) {
|
|
1353
|
-
return ts.forEachChild(node, find) || node;
|
|
1216
|
+
}
|
|
1217
|
+
function findNodeAtPosition(sourceFile, position) {
|
|
1218
|
+
function find(node) {
|
|
1219
|
+
if (position >= node.getStart() && position < node.getEnd()) {
|
|
1220
|
+
return ts.forEachChild(node, find) || node;
|
|
1221
|
+
}
|
|
1222
|
+
return void 0;
|
|
1354
1223
|
}
|
|
1355
|
-
return
|
|
1224
|
+
return find(sourceFile);
|
|
1356
1225
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1226
|
+
function findNodeAtPositionIncludingTrivia(sourceFile, position) {
|
|
1227
|
+
function find(node) {
|
|
1228
|
+
if (position >= node.pos && position < node.end) {
|
|
1229
|
+
return ts.forEachChild(node, find) || node;
|
|
1230
|
+
}
|
|
1231
|
+
return void 0;
|
|
1232
|
+
}
|
|
1233
|
+
return find(sourceFile);
|
|
1234
|
+
}
|
|
1235
|
+
function getAncestorNodesInRange(sourceFile, textRange) {
|
|
1236
|
+
const nodeAtPosition = findNodeAtPosition(sourceFile, textRange.pos);
|
|
1237
|
+
if (!nodeAtPosition) return empty();
|
|
1238
|
+
return collectSelfAndAncestorNodesInRange(nodeAtPosition, textRange);
|
|
1239
|
+
}
|
|
1240
|
+
function getCommentAtPosition(sourceFile, pos) {
|
|
1241
|
+
const token = findNodeAtPositionIncludingTrivia(sourceFile, pos);
|
|
1242
|
+
if (token === void 0 || token.kind === ts.SyntaxKind.JsxText || pos >= token.end - (ts.tokenToString(token.kind) || "").length) {
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
const startPos = token.pos === 0 ? (ts.getShebang(sourceFile.text) || "").length : token.pos;
|
|
1246
|
+
if (startPos === 0) return;
|
|
1247
|
+
const result = ts.forEachTrailingCommentRange(sourceFile.text, startPos, isCommentInRange, pos) || ts.forEachLeadingCommentRange(sourceFile.text, startPos, isCommentInRange, pos);
|
|
1248
|
+
return result;
|
|
1249
|
+
}
|
|
1250
|
+
function isCommentInRange(pos, end, kind, _nl, at) {
|
|
1251
|
+
return at >= pos && at < end ? { pos, end, kind } : void 0;
|
|
1252
|
+
}
|
|
1253
|
+
function toTextRange(positionOrRange) {
|
|
1254
|
+
return typeof positionOrRange === "number" ? { end: positionOrRange, pos: positionOrRange } : positionOrRange;
|
|
1255
|
+
}
|
|
1256
|
+
function isNodeInRange(textRange) {
|
|
1257
|
+
return (node) => node.pos <= textRange.pos && node.end >= textRange.end;
|
|
1258
|
+
}
|
|
1259
|
+
function transformAsyncAwaitToEffectGen(node, effectModuleName, onAwait) {
|
|
1385
1260
|
function visitor(_) {
|
|
1386
1261
|
if (ts.isAwaitExpression(_)) {
|
|
1387
1262
|
const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext);
|
|
@@ -1393,7 +1268,7 @@ var transformAsyncAwaitToEffectGen = fn("AST.transformAsyncAwaitToEffectGen")(
|
|
|
1393
1268
|
return ts.visitEachChild(_, visitor, ts.nullTransformationContext);
|
|
1394
1269
|
}
|
|
1395
1270
|
const generatorBody = visitor(node.body);
|
|
1396
|
-
const effectGenCallExp =
|
|
1271
|
+
const effectGenCallExp = createEffectGenCallExpression(effectModuleName, generatorBody);
|
|
1397
1272
|
let currentFlags = ts.getCombinedModifierFlags(node);
|
|
1398
1273
|
currentFlags &= ~ts.ModifierFlags.Async;
|
|
1399
1274
|
const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags);
|
|
@@ -1431,45 +1306,7 @@ var transformAsyncAwaitToEffectGen = fn("AST.transformAsyncAwaitToEffectGen")(
|
|
|
1431
1306
|
newBody
|
|
1432
1307
|
);
|
|
1433
1308
|
}
|
|
1434
|
-
)
|
|
1435
|
-
var addReturnTypeAnnotation = fn("AST.addReturnTypeAnnotation")(function* (sourceFile, declaration, typeNode) {
|
|
1436
|
-
const ts = yield* service(TypeScriptApi);
|
|
1437
|
-
const changes = yield* service(ChangeTracker);
|
|
1438
|
-
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
|
|
1439
|
-
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
1440
|
-
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
1441
|
-
if (endNode) {
|
|
1442
|
-
if (needParens) {
|
|
1443
|
-
changes.insertNodeBefore(
|
|
1444
|
-
sourceFile,
|
|
1445
|
-
endNode,
|
|
1446
|
-
ts.factory.createToken(ts.SyntaxKind.OpenParenToken)
|
|
1447
|
-
);
|
|
1448
|
-
changes.insertNodeAfter(
|
|
1449
|
-
sourceFile,
|
|
1450
|
-
endNode,
|
|
1451
|
-
ts.factory.createToken(ts.SyntaxKind.CloseParenToken)
|
|
1452
|
-
);
|
|
1453
|
-
}
|
|
1454
|
-
changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: ": " });
|
|
1455
|
-
}
|
|
1456
|
-
});
|
|
1457
|
-
var removeReturnTypeAnnotation = fn("AST.removeReturnTypeAnnotation")(function* (sourceFile, declaration) {
|
|
1458
|
-
const ts = yield* service(TypeScriptApi);
|
|
1459
|
-
const changes = yield* service(ChangeTracker);
|
|
1460
|
-
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
|
|
1461
|
-
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
1462
|
-
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
1463
|
-
if (endNode && declaration.type) {
|
|
1464
|
-
changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end });
|
|
1465
|
-
}
|
|
1466
|
-
});
|
|
1467
|
-
var ImportModuleIdentifierNotFoundError = class {
|
|
1468
|
-
_tag = "@effect/language-service/ImportModuleIdentifierNotFoundError";
|
|
1469
|
-
};
|
|
1470
|
-
var findImportedModuleIdentifier = fn("AST.findImportedModuleIdentifier")(
|
|
1471
|
-
function* (sourceFile, test) {
|
|
1472
|
-
const ts = yield* service(TypeScriptApi);
|
|
1309
|
+
function findImportedModuleIdentifier(sourceFile, test) {
|
|
1473
1310
|
for (const statement of sourceFile.statements) {
|
|
1474
1311
|
if (!ts.isImportDeclaration(statement)) continue;
|
|
1475
1312
|
const importClause = statement.importClause;
|
|
@@ -1477,72 +1314,64 @@ var findImportedModuleIdentifier = fn("AST.findImportedModuleIdentifier")(
|
|
|
1477
1314
|
const namedBindings = importClause.namedBindings;
|
|
1478
1315
|
if (!namedBindings) continue;
|
|
1479
1316
|
if (ts.isNamespaceImport(namedBindings)) {
|
|
1480
|
-
if (
|
|
1481
|
-
return namedBindings.name;
|
|
1317
|
+
if (test(namedBindings.name, statement.moduleSpecifier, none2())) {
|
|
1318
|
+
return namedBindings.name.text;
|
|
1482
1319
|
}
|
|
1483
1320
|
} else if (ts.isNamedImports(namedBindings)) {
|
|
1484
1321
|
for (const importSpecifier of namedBindings.elements) {
|
|
1485
1322
|
const importProperty = fromNullable(importSpecifier.propertyName).pipe(
|
|
1486
|
-
orElse(() =>
|
|
1323
|
+
orElse(() => some2(importSpecifier.name))
|
|
1487
1324
|
);
|
|
1488
|
-
if (
|
|
1489
|
-
return importSpecifier.name;
|
|
1325
|
+
if (test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
|
|
1326
|
+
return importSpecifier.name.text;
|
|
1490
1327
|
}
|
|
1491
1328
|
}
|
|
1492
1329
|
}
|
|
1493
1330
|
}
|
|
1494
|
-
return yield* fail(new ImportModuleIdentifierNotFoundError());
|
|
1495
1331
|
}
|
|
1496
|
-
)
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1332
|
+
function findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, packageName, moduleName) {
|
|
1333
|
+
return findImportedModuleIdentifier(
|
|
1334
|
+
sourceFile,
|
|
1335
|
+
(_, fromModule, importProperty) => {
|
|
1336
|
+
if (isNone2(importProperty) && ts.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
|
|
1337
|
+
return true;
|
|
1338
|
+
}
|
|
1339
|
+
if (isSome2(importProperty) && ts.isIdentifier(importProperty.value) && importProperty.value.text === moduleName && ts.isStringLiteral(fromModule) && fromModule.text === packageName) {
|
|
1340
|
+
return true;
|
|
1341
|
+
}
|
|
1342
|
+
return false;
|
|
1506
1343
|
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1346
|
+
function simplifyTypeNode(typeNode) {
|
|
1347
|
+
function collectCallable(typeNode2) {
|
|
1348
|
+
if (ts.isParenthesizedTypeNode(typeNode2)) return collectCallable(typeNode2.type);
|
|
1349
|
+
if (ts.isFunctionTypeNode(typeNode2)) {
|
|
1350
|
+
return some2([
|
|
1351
|
+
ts.factory.createCallSignature(typeNode2.typeParameters, typeNode2.parameters, typeNode2.type)
|
|
1352
|
+
]);
|
|
1353
|
+
}
|
|
1354
|
+
if (ts.isTypeLiteralNode(typeNode2)) {
|
|
1355
|
+
const allCallSignatures = typeNode2.members.every(ts.isCallSignatureDeclaration);
|
|
1356
|
+
if (allCallSignatures) {
|
|
1357
|
+
return some2(typeNode2.members);
|
|
1358
|
+
}
|
|
1509
1359
|
}
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
const ts = yield* service(TypeScriptApi);
|
|
1516
|
-
function collectCallable(typeNode2) {
|
|
1517
|
-
if (ts.isParenthesizedTypeNode(typeNode2)) return collectCallable(typeNode2.type);
|
|
1518
|
-
if (ts.isFunctionTypeNode(typeNode2)) {
|
|
1519
|
-
return some3([
|
|
1520
|
-
ts.factory.createCallSignature(typeNode2.typeParameters, typeNode2.parameters, typeNode2.type)
|
|
1521
|
-
]);
|
|
1522
|
-
}
|
|
1523
|
-
if (ts.isTypeLiteralNode(typeNode2)) {
|
|
1524
|
-
const allCallSignatures = typeNode2.members.every(ts.isCallSignatureDeclaration);
|
|
1525
|
-
if (allCallSignatures) {
|
|
1526
|
-
return some3(typeNode2.members);
|
|
1360
|
+
if (ts.isIntersectionTypeNode(typeNode2)) {
|
|
1361
|
+
const members = typeNode2.types.map((node) => collectCallable(node));
|
|
1362
|
+
if (members.every(isSome2)) {
|
|
1363
|
+
return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
|
|
1364
|
+
}
|
|
1527
1365
|
}
|
|
1366
|
+
return none2();
|
|
1528
1367
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
return some3(members.map((_) => isSome2(_) ? _.value : []).flat());
|
|
1533
|
-
}
|
|
1368
|
+
const callSignatures = collectCallable(typeNode);
|
|
1369
|
+
if (isSome2(callSignatures) && callSignatures.value.length > 1) {
|
|
1370
|
+
return ts.factory.createTypeLiteralNode(callSignatures.value);
|
|
1534
1371
|
}
|
|
1535
|
-
return
|
|
1536
|
-
}
|
|
1537
|
-
const callSignatures = collectCallable(typeNode);
|
|
1538
|
-
if (isSome2(callSignatures) && callSignatures.value.length > 1) {
|
|
1539
|
-
return ts.factory.createTypeLiteralNode(callSignatures.value);
|
|
1372
|
+
return typeNode;
|
|
1540
1373
|
}
|
|
1541
|
-
|
|
1542
|
-
});
|
|
1543
|
-
var tryPreserveDeclarationSemantics = fn("AST.tryPreserveDeclarationSemantics")(
|
|
1544
|
-
function* (nodeToReplace, node) {
|
|
1545
|
-
const ts = yield* service(TypeScriptApi);
|
|
1374
|
+
function tryPreserveDeclarationSemantics(nodeToReplace, node) {
|
|
1546
1375
|
if (!ts.isExpression(node)) return node;
|
|
1547
1376
|
if (ts.isFunctionDeclaration(nodeToReplace)) {
|
|
1548
1377
|
if (!nodeToReplace.name) return node;
|
|
@@ -1569,14 +1398,9 @@ var tryPreserveDeclarationSemantics = fn("AST.tryPreserveDeclarationSemantics")(
|
|
|
1569
1398
|
}
|
|
1570
1399
|
return node;
|
|
1571
1400
|
}
|
|
1572
|
-
)
|
|
1573
|
-
var parseAccessedExpressionForCompletion = fn(
|
|
1574
|
-
"AST.parseAccessedExpressionForCompletion"
|
|
1575
|
-
)(
|
|
1576
|
-
function* (sourceFile, position) {
|
|
1577
|
-
const ts = yield* service(TypeScriptApi);
|
|
1401
|
+
function parseAccessedExpressionForCompletion(sourceFile, position) {
|
|
1578
1402
|
const precedingToken = ts.findPrecedingToken(position, sourceFile, void 0, true);
|
|
1579
|
-
if (!precedingToken) return
|
|
1403
|
+
if (!precedingToken) return;
|
|
1580
1404
|
let accessedObject = precedingToken;
|
|
1581
1405
|
let replacementSpan = ts.createTextSpan(position, 0);
|
|
1582
1406
|
let outerNode = precedingToken;
|
|
@@ -1602,67 +1426,56 @@ var parseAccessedExpressionForCompletion = fn(
|
|
|
1602
1426
|
accessedObject = precedingToken;
|
|
1603
1427
|
outerNode = precedingToken;
|
|
1604
1428
|
} else {
|
|
1605
|
-
return
|
|
1429
|
+
return;
|
|
1606
1430
|
}
|
|
1607
1431
|
return { accessedObject, outerNode, replacementSpan };
|
|
1608
1432
|
}
|
|
1609
|
-
)
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
"AST.createEffectGenCallExpressionWithBlock"
|
|
1656
|
-
)(function* (effectModuleIdentifierName, statement) {
|
|
1657
|
-
const ts = yield* service(TypeScriptApi);
|
|
1658
|
-
return yield* createEffectGenCallExpression(
|
|
1659
|
-
effectModuleIdentifierName,
|
|
1660
|
-
ts.factory.createBlock(Array.isArray(statement) ? statement : [statement], false)
|
|
1661
|
-
);
|
|
1662
|
-
});
|
|
1663
|
-
var createReturnYieldStarStatement = fn("AST.createReturnYieldStarStatement")(
|
|
1664
|
-
function* (expr) {
|
|
1665
|
-
const ts = yield* service(TypeScriptApi);
|
|
1433
|
+
function parseDataForExtendsClassCompletion(sourceFile, position) {
|
|
1434
|
+
const maybeInfos = parseAccessedExpressionForCompletion(sourceFile, position);
|
|
1435
|
+
if (!maybeInfos) return;
|
|
1436
|
+
const { accessedObject, outerNode, replacementSpan } = maybeInfos;
|
|
1437
|
+
if (!ts.isIdentifier(accessedObject)) return;
|
|
1438
|
+
let classDeclaration = outerNode.parent;
|
|
1439
|
+
while (ts.isExpressionWithTypeArguments(classDeclaration) || ts.isHeritageClause(classDeclaration)) {
|
|
1440
|
+
if (!classDeclaration.parent) break;
|
|
1441
|
+
classDeclaration = classDeclaration.parent;
|
|
1442
|
+
}
|
|
1443
|
+
if (!ts.isClassDeclaration(classDeclaration)) return;
|
|
1444
|
+
if (!classDeclaration.name) return;
|
|
1445
|
+
return {
|
|
1446
|
+
accessedObject,
|
|
1447
|
+
classDeclaration,
|
|
1448
|
+
className: classDeclaration.name,
|
|
1449
|
+
replacementSpan
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
function createEffectGenCallExpression(effectModuleIdentifierName, node) {
|
|
1453
|
+
const generator = ts.factory.createFunctionExpression(
|
|
1454
|
+
void 0,
|
|
1455
|
+
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
1456
|
+
void 0,
|
|
1457
|
+
[],
|
|
1458
|
+
[],
|
|
1459
|
+
void 0,
|
|
1460
|
+
node
|
|
1461
|
+
// NOTE(mattia): intended, to use same routine for both ConciseBody and Body
|
|
1462
|
+
);
|
|
1463
|
+
return ts.factory.createCallExpression(
|
|
1464
|
+
ts.factory.createPropertyAccessExpression(
|
|
1465
|
+
ts.factory.createIdentifier(effectModuleIdentifierName),
|
|
1466
|
+
"gen"
|
|
1467
|
+
),
|
|
1468
|
+
void 0,
|
|
1469
|
+
[generator]
|
|
1470
|
+
);
|
|
1471
|
+
}
|
|
1472
|
+
function createEffectGenCallExpressionWithBlock(effectModuleIdentifierName, statement) {
|
|
1473
|
+
return createEffectGenCallExpression(
|
|
1474
|
+
effectModuleIdentifierName,
|
|
1475
|
+
ts.factory.createBlock(isArray(statement) ? statement : [statement], false)
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1478
|
+
function createReturnYieldStarStatement(expr) {
|
|
1666
1479
|
return ts.factory.createReturnStatement(
|
|
1667
1480
|
ts.factory.createYieldExpression(
|
|
1668
1481
|
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
@@ -1670,7 +1483,26 @@ var createReturnYieldStarStatement = fn("AST.createReturnYieldStarStatement")(
|
|
|
1670
1483
|
)
|
|
1671
1484
|
);
|
|
1672
1485
|
}
|
|
1673
|
-
|
|
1486
|
+
return {
|
|
1487
|
+
findNodeAtPositionIncludingTrivia,
|
|
1488
|
+
parsePackageContentNameAndVersionFromScope,
|
|
1489
|
+
resolveModulePattern,
|
|
1490
|
+
findNodeWithLeadingCommentAtPosition,
|
|
1491
|
+
getCommentAtPosition,
|
|
1492
|
+
getAncestorNodesInRange,
|
|
1493
|
+
toTextRange,
|
|
1494
|
+
isNodeInRange,
|
|
1495
|
+
transformAsyncAwaitToEffectGen,
|
|
1496
|
+
findImportedModuleIdentifierByPackageAndNameOrBarrel,
|
|
1497
|
+
simplifyTypeNode,
|
|
1498
|
+
tryPreserveDeclarationSemantics,
|
|
1499
|
+
parseDataForExtendsClassCompletion,
|
|
1500
|
+
createEffectGenCallExpressionWithBlock,
|
|
1501
|
+
createReturnYieldStarStatement,
|
|
1502
|
+
makeGetModuleSpecifier,
|
|
1503
|
+
parseAccessedExpressionForCompletion
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1674
1506
|
|
|
1675
1507
|
// src/core/LanguageServicePluginOptions.ts
|
|
1676
1508
|
var LanguageServicePluginOptions = Tag("PluginOptions");
|
|
@@ -1680,7 +1512,7 @@ function parseDiagnosticSeverity(config) {
|
|
|
1680
1512
|
pipe(
|
|
1681
1513
|
Object.entries(config),
|
|
1682
1514
|
filter(([key, value]) => isString(key) && isString(value)),
|
|
1683
|
-
|
|
1515
|
+
map4(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),
|
|
1684
1516
|
filter(
|
|
1685
1517
|
([_, value]) => value === "off" || value === "error" || value === "warning" || value === "message" || value === "suggestion"
|
|
1686
1518
|
)
|
|
@@ -1772,27 +1604,8 @@ var getCompletionsAtPosition = fn("LSP.getCompletionsAtPosition")(function* (com
|
|
|
1772
1604
|
var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
1773
1605
|
function* (sourceFile) {
|
|
1774
1606
|
const ts = yield* service(TypeScriptApi);
|
|
1607
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
1775
1608
|
const pluginOptions = yield* service(LanguageServicePluginOptions);
|
|
1776
|
-
function findNodeWithLeadingCommentAtPosition(position) {
|
|
1777
|
-
const sourceText = sourceFile.text;
|
|
1778
|
-
let result;
|
|
1779
|
-
function find(node) {
|
|
1780
|
-
const leading = ts.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1781
|
-
if (leading) {
|
|
1782
|
-
for (const r of leading) {
|
|
1783
|
-
if (r.pos <= position && position < r.end) {
|
|
1784
|
-
result = node;
|
|
1785
|
-
return;
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
if (node.getFullStart() <= position && position < node.getEnd()) {
|
|
1790
|
-
node.forEachChild(find);
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
find(sourceFile);
|
|
1794
|
-
return result;
|
|
1795
|
-
}
|
|
1796
1609
|
function findParentStatementForDisableNextLine(node) {
|
|
1797
1610
|
let result;
|
|
1798
1611
|
function find(node2) {
|
|
@@ -1810,10 +1623,10 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1810
1623
|
const sectionOverrides = {};
|
|
1811
1624
|
const skippedRules = [];
|
|
1812
1625
|
const regex = /@effect-diagnostics(-next-line)?((?:\s[a-zA-Z0-9/]+:(?:off|warning|error|message|suggestion|skip-file))+)?/gm;
|
|
1813
|
-
let
|
|
1814
|
-
while ((
|
|
1815
|
-
const nextLineCaptureGroup =
|
|
1816
|
-
const rulesCaptureGroup =
|
|
1626
|
+
let match2;
|
|
1627
|
+
while ((match2 = regex.exec(sourceFile.text)) !== null) {
|
|
1628
|
+
const nextLineCaptureGroup = match2[1];
|
|
1629
|
+
const rulesCaptureGroup = match2[2];
|
|
1817
1630
|
if (rulesCaptureGroup) {
|
|
1818
1631
|
const trimmedRuleString = rulesCaptureGroup.trim();
|
|
1819
1632
|
if (trimmedRuleString) {
|
|
@@ -1825,19 +1638,19 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1825
1638
|
if (ruleLevel === "skip-file") skippedRules.push(ruleName);
|
|
1826
1639
|
const isOverrideNextLine = nextLineCaptureGroup && nextLineCaptureGroup.trim().toLowerCase() === "-next-line";
|
|
1827
1640
|
if (isOverrideNextLine) {
|
|
1828
|
-
const
|
|
1829
|
-
if (
|
|
1641
|
+
const foundNode = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, match2.index);
|
|
1642
|
+
if (foundNode) {
|
|
1830
1643
|
lineOverrides[ruleName] = lineOverrides[ruleName] || [];
|
|
1831
1644
|
lineOverrides[ruleName].unshift({
|
|
1832
|
-
pos: node.getFullStart(),
|
|
1833
|
-
end: node.end,
|
|
1645
|
+
pos: foundNode.node.getFullStart(),
|
|
1646
|
+
end: foundNode.node.end,
|
|
1834
1647
|
level: ruleLevel
|
|
1835
1648
|
});
|
|
1836
1649
|
}
|
|
1837
1650
|
} else {
|
|
1838
1651
|
sectionOverrides[ruleName] = sectionOverrides[ruleName] || [];
|
|
1839
1652
|
sectionOverrides[ruleName].unshift({
|
|
1840
|
-
pos:
|
|
1653
|
+
pos: match2.index,
|
|
1841
1654
|
level: ruleLevel
|
|
1842
1655
|
});
|
|
1843
1656
|
}
|
|
@@ -1852,7 +1665,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1852
1665
|
message: ts.DiagnosticCategory.Message,
|
|
1853
1666
|
suggestion: ts.DiagnosticCategory.Suggestion
|
|
1854
1667
|
};
|
|
1855
|
-
const execute =
|
|
1668
|
+
const execute = (rule) => gen(function* () {
|
|
1856
1669
|
const diagnostics2 = [];
|
|
1857
1670
|
const codeFixes = [];
|
|
1858
1671
|
const ruleNameLowered = rule.name.toLowerCase();
|
|
@@ -1861,13 +1674,13 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1861
1674
|
if (defaultLevel === "off" && (lineOverrides[ruleNameLowered] || sectionOverrides[ruleNameLowered] || []).length === 0) {
|
|
1862
1675
|
return { diagnostics: diagnostics2, codeFixes };
|
|
1863
1676
|
}
|
|
1864
|
-
const fixByDisableNextLine = (
|
|
1677
|
+
const fixByDisableNextLine = (node) => ({
|
|
1865
1678
|
fixName: rule.name + "_skipNextLine",
|
|
1866
1679
|
description: "Disable " + rule.name + " for this line",
|
|
1867
|
-
apply:
|
|
1680
|
+
apply: flatMap(
|
|
1868
1681
|
service(ChangeTracker),
|
|
1869
|
-
(changeTracker) =>
|
|
1870
|
-
const disableAtNode = findParentStatementForDisableNextLine(
|
|
1682
|
+
(changeTracker) => gen(function* () {
|
|
1683
|
+
const disableAtNode = findParentStatementForDisableNextLine(node);
|
|
1871
1684
|
const { line } = ts.getLineAndCharacterOfPosition(sourceFile, disableAtNode.getStart());
|
|
1872
1685
|
changeTracker.insertCommentBeforeLine(
|
|
1873
1686
|
sourceFile,
|
|
@@ -1881,7 +1694,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1881
1694
|
const fixByDisableEntireFile = {
|
|
1882
1695
|
fixName: rule.name + "_skipFile",
|
|
1883
1696
|
description: "Disable " + rule.name + " for this entire file",
|
|
1884
|
-
apply:
|
|
1697
|
+
apply: flatMap(
|
|
1885
1698
|
service(ChangeTracker),
|
|
1886
1699
|
(changeTracker) => sync(
|
|
1887
1700
|
() => changeTracker.insertText(
|
|
@@ -1895,29 +1708,30 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1895
1708
|
};
|
|
1896
1709
|
const applicableDiagnostics = [];
|
|
1897
1710
|
yield* rule.apply(sourceFile, (entry) => {
|
|
1711
|
+
const range = "getEnd" in entry.location ? { pos: entry.location.getStart(sourceFile), end: entry.location.getEnd() } : entry.location;
|
|
1712
|
+
const node = "getEnd" in entry.location ? entry.location : tsUtils.findNodeAtPositionIncludingTrivia(sourceFile, entry.location.pos);
|
|
1898
1713
|
applicableDiagnostics.push({
|
|
1899
|
-
|
|
1900
|
-
|
|
1714
|
+
range,
|
|
1715
|
+
messageText: entry.messageText,
|
|
1716
|
+
fixes: entry.fixes.concat(node ? [fixByDisableNextLine(node)] : []).concat([fixByDisableEntireFile])
|
|
1901
1717
|
});
|
|
1902
1718
|
});
|
|
1903
1719
|
for (const emitted of applicableDiagnostics.slice(0)) {
|
|
1904
1720
|
let newLevel = defaultLevel;
|
|
1905
1721
|
const lineOverride = (lineOverrides[ruleNameLowered] || []).find(
|
|
1906
|
-
(_) => _.pos < emitted.
|
|
1722
|
+
(_) => _.pos < emitted.range.pos && _.end >= emitted.range.end
|
|
1907
1723
|
);
|
|
1908
1724
|
if (lineOverride) {
|
|
1909
1725
|
newLevel = lineOverride.level;
|
|
1910
1726
|
} else {
|
|
1911
|
-
const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find(
|
|
1912
|
-
(_) => _.pos < emitted.node.getStart(sourceFile)
|
|
1913
|
-
);
|
|
1727
|
+
const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find((_) => _.pos < emitted.range.pos);
|
|
1914
1728
|
if (sectionOverride) newLevel = sectionOverride.level;
|
|
1915
1729
|
}
|
|
1916
1730
|
if (!(newLevel in levelToDiagnosticCategory)) continue;
|
|
1917
1731
|
diagnostics2.push({
|
|
1918
1732
|
file: sourceFile,
|
|
1919
|
-
start: emitted.
|
|
1920
|
-
length: emitted.
|
|
1733
|
+
start: emitted.range.pos,
|
|
1734
|
+
length: emitted.range.end - emitted.range.pos,
|
|
1921
1735
|
messageText: emitted.messageText,
|
|
1922
1736
|
category: levelToDiagnosticCategory[newLevel],
|
|
1923
1737
|
code: rule.code,
|
|
@@ -1927,8 +1741,8 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1927
1741
|
codeFixes.push({
|
|
1928
1742
|
...fix,
|
|
1929
1743
|
code: rule.code,
|
|
1930
|
-
start: emitted.
|
|
1931
|
-
end: emitted.
|
|
1744
|
+
start: emitted.range.pos,
|
|
1745
|
+
end: emitted.range.end
|
|
1932
1746
|
});
|
|
1933
1747
|
}
|
|
1934
1748
|
}
|
|
@@ -1937,28 +1751,97 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1937
1751
|
return { execute };
|
|
1938
1752
|
}
|
|
1939
1753
|
);
|
|
1754
|
+
var cyrb53 = (str, seed = 0) => {
|
|
1755
|
+
let h1 = 3735928559 ^ seed, h2 = 1103547991 ^ seed;
|
|
1756
|
+
for (let i = 0, ch; i < str.length; i++) {
|
|
1757
|
+
ch = str.charCodeAt(i);
|
|
1758
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
1759
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
1760
|
+
}
|
|
1761
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507);
|
|
1762
|
+
h1 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
1763
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
|
|
1764
|
+
h2 ^= Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
1765
|
+
return (h2 >>> 0).toString(16).padStart(8, "0") + (h1 >>> 0).toString(16).padStart(8, "0");
|
|
1766
|
+
};
|
|
1767
|
+
var CodegenNotApplicableError = class {
|
|
1768
|
+
constructor(cause) {
|
|
1769
|
+
this.cause = cause;
|
|
1770
|
+
}
|
|
1771
|
+
_tag = "@effect/language-service/CodegenNotApplicableError";
|
|
1772
|
+
};
|
|
1773
|
+
function createCodegen(definition) {
|
|
1774
|
+
return definition;
|
|
1775
|
+
}
|
|
1776
|
+
var getCodegensForSourceFile = fn("LSP.getApplicableCodegens")(function* (codegens2, sourceFile) {
|
|
1777
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
1778
|
+
const result = [];
|
|
1779
|
+
const regex = /@effect-codegens((?:\s[a-zA-Z0-9]+(?::(?:[a-zA-Z0-9]+))?)+)+/gmid;
|
|
1780
|
+
let match2;
|
|
1781
|
+
while ((match2 = regex.exec(sourceFile.text)) !== null) {
|
|
1782
|
+
const pos = match2.indices?.[0]?.[0];
|
|
1783
|
+
if (!pos) continue;
|
|
1784
|
+
const commentRange = tsUtils.getCommentAtPosition(sourceFile, pos);
|
|
1785
|
+
if (!commentRange) continue;
|
|
1786
|
+
const commentText = sourceFile.text.slice(pos, commentRange.end);
|
|
1787
|
+
const codegenRegex = /(\s+)(\w+)(?::(\w+))?/gmi;
|
|
1788
|
+
let codegenMatch;
|
|
1789
|
+
while ((codegenMatch = codegenRegex.exec(commentText)) !== null) {
|
|
1790
|
+
const whitespace = codegenMatch[1] || "";
|
|
1791
|
+
const codegenName = codegenMatch[2] || "";
|
|
1792
|
+
const codegenHash = codegenMatch[3] || "";
|
|
1793
|
+
const range = {
|
|
1794
|
+
pos: codegenMatch.index + pos + whitespace.length,
|
|
1795
|
+
end: codegenMatch.index + pos + codegenMatch[0].length
|
|
1796
|
+
};
|
|
1797
|
+
const codegen = codegens2.find((codegen2) => codegen2.name === codegenName);
|
|
1798
|
+
if (!codegen) continue;
|
|
1799
|
+
result.push({ codegen, hash: codegenHash, range });
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
return result;
|
|
1803
|
+
});
|
|
1804
|
+
var getEditsForCodegen = fn("LSP.getEditsForCodegen")(function* (codegens2, sourceFile, textRange) {
|
|
1805
|
+
const applicableCodegens = yield* getCodegensForSourceFile(codegens2, sourceFile);
|
|
1806
|
+
const inRangeCodegens = applicableCodegens.filter(
|
|
1807
|
+
(codegen2) => codegen2.range.pos <= textRange.pos && codegen2.range.end >= textRange.end
|
|
1808
|
+
);
|
|
1809
|
+
if (inRangeCodegens.length !== 1) {
|
|
1810
|
+
return yield* fail(new CodegenNotApplicableError("zero or multiple codegens in range"));
|
|
1811
|
+
}
|
|
1812
|
+
const { codegen, range } = inRangeCodegens[0];
|
|
1813
|
+
const edit = yield* codegen.apply(sourceFile, range);
|
|
1814
|
+
const updateHashComment = pipe(
|
|
1815
|
+
service(ChangeTracker),
|
|
1816
|
+
map3((changeTracker) => {
|
|
1817
|
+
changeTracker.deleteRange(sourceFile, range);
|
|
1818
|
+
changeTracker.insertText(sourceFile, range.pos, `${codegen.name}:${edit.hash}`);
|
|
1819
|
+
})
|
|
1820
|
+
);
|
|
1821
|
+
return {
|
|
1822
|
+
...edit,
|
|
1823
|
+
apply: pipe(
|
|
1824
|
+
edit.apply,
|
|
1825
|
+
flatMap(() => updateHashComment)
|
|
1826
|
+
),
|
|
1827
|
+
ignore: updateHashComment
|
|
1828
|
+
};
|
|
1829
|
+
});
|
|
1940
1830
|
|
|
1941
1831
|
// src/completions/contextSelfInClasses.ts
|
|
1942
1832
|
var contextSelfInClasses = createCompletion({
|
|
1943
1833
|
name: "contextSelfInClasses",
|
|
1944
1834
|
apply: fn("contextSelfInClasses")(function* (sourceFile, position) {
|
|
1945
1835
|
const ts = yield* service(TypeScriptApi);
|
|
1946
|
-
const
|
|
1947
|
-
|
|
1948
|
-
);
|
|
1949
|
-
|
|
1950
|
-
const
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
"Context"
|
|
1956
|
-
)
|
|
1957
|
-
);
|
|
1958
|
-
const contextIdentifier = match(contextName, {
|
|
1959
|
-
onNone: () => "Context",
|
|
1960
|
-
onSome: (_) => _.text
|
|
1961
|
-
});
|
|
1836
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
1837
|
+
const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
|
|
1838
|
+
if (!maybeInfos) return [];
|
|
1839
|
+
const { accessedObject, className, replacementSpan } = maybeInfos;
|
|
1840
|
+
const contextIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
1841
|
+
sourceFile,
|
|
1842
|
+
"effect",
|
|
1843
|
+
"Context"
|
|
1844
|
+
) || "Context";
|
|
1962
1845
|
if (contextIdentifier !== accessedObject.text) return [];
|
|
1963
1846
|
const name = className.text;
|
|
1964
1847
|
return [{
|
|
@@ -1973,12 +1856,6 @@ var contextSelfInClasses = createCompletion({
|
|
|
1973
1856
|
|
|
1974
1857
|
// src/core/TypeCheckerApi.ts
|
|
1975
1858
|
var TypeCheckerApi = Tag("TypeChecker");
|
|
1976
|
-
var TypeCheckerApiCache = Tag("TypeCheckerApiCache");
|
|
1977
|
-
function makeTypeCheckerApiCache() {
|
|
1978
|
-
return {
|
|
1979
|
-
expectedAndRealType: /* @__PURE__ */ new WeakMap()
|
|
1980
|
-
};
|
|
1981
|
-
}
|
|
1982
1859
|
var deterministicTypeOrder = gen(function* () {
|
|
1983
1860
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
1984
1861
|
return make2((a, b) => {
|
|
@@ -2077,106 +1954,106 @@ var getInferredReturnType = fn("TypeCheckerApi.getInferredReturnType")(function*
|
|
|
2077
1954
|
}
|
|
2078
1955
|
return returnType;
|
|
2079
1956
|
});
|
|
2080
|
-
var expectedAndRealType =
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
ts.
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
result.push([node, expectedType, node, realType]);
|
|
1957
|
+
var expectedAndRealType = cachedBy(
|
|
1958
|
+
fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
|
|
1959
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1960
|
+
const ts = yield* service(TypeScriptApi);
|
|
1961
|
+
const result = [];
|
|
1962
|
+
const nodeToVisit = [sourceFile];
|
|
1963
|
+
const appendNodeToVisit = (node) => {
|
|
1964
|
+
nodeToVisit.push(node);
|
|
1965
|
+
return void 0;
|
|
1966
|
+
};
|
|
1967
|
+
while (nodeToVisit.length > 0) {
|
|
1968
|
+
const node = nodeToVisit.shift();
|
|
1969
|
+
if (ts.isVariableDeclaration(node) && node.initializer) {
|
|
1970
|
+
const expectedType = typeChecker.getTypeAtLocation(node.name);
|
|
1971
|
+
const realType = typeChecker.getTypeAtLocation(node.initializer);
|
|
1972
|
+
result.push([node.name, expectedType, node.initializer, realType]);
|
|
1973
|
+
appendNodeToVisit(node.initializer);
|
|
1974
|
+
continue;
|
|
1975
|
+
} else if (ts.isCallExpression(node)) {
|
|
1976
|
+
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
1977
|
+
if (resolvedSignature) {
|
|
1978
|
+
resolvedSignature.getParameters().map((parameter, index) => {
|
|
1979
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
|
|
1980
|
+
const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
|
|
1981
|
+
result.push([
|
|
1982
|
+
node.arguments[index],
|
|
1983
|
+
expectedType,
|
|
1984
|
+
node.arguments[index],
|
|
1985
|
+
realType
|
|
1986
|
+
]);
|
|
1987
|
+
});
|
|
1988
|
+
}
|
|
1989
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
1990
|
+
continue;
|
|
1991
|
+
} else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
1992
|
+
const parent = node.parent;
|
|
1993
|
+
if (ts.isObjectLiteralElement(parent)) {
|
|
1994
|
+
if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
|
|
1995
|
+
const type = typeChecker.getContextualType(parent.parent);
|
|
1996
|
+
if (type) {
|
|
1997
|
+
const symbol3 = typeChecker.getPropertyOfType(type, node.text);
|
|
1998
|
+
if (symbol3) {
|
|
1999
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
|
|
2000
|
+
const realType = typeChecker.getTypeAtLocation(node);
|
|
2001
|
+
result.push([node, expectedType, node, realType]);
|
|
2002
|
+
}
|
|
2127
2003
|
}
|
|
2128
2004
|
}
|
|
2129
2005
|
}
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2006
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2007
|
+
continue;
|
|
2008
|
+
} else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
2009
|
+
const expectedType = typeChecker.getTypeAtLocation(node.left);
|
|
2010
|
+
const realType = typeChecker.getTypeAtLocation(node.right);
|
|
2011
|
+
result.push([node.left, expectedType, node.right, realType]);
|
|
2012
|
+
appendNodeToVisit(node.right);
|
|
2013
|
+
continue;
|
|
2014
|
+
} else if (ts.isReturnStatement(node) && node.expression) {
|
|
2015
|
+
const parentDeclaration = yield* option(getAncestorConvertibleDeclaration(node));
|
|
2016
|
+
if (isSome2(parentDeclaration)) {
|
|
2017
|
+
const expectedType = yield* option(getInferredReturnType(parentDeclaration.value));
|
|
2018
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2019
|
+
if (isSome2(expectedType)) {
|
|
2020
|
+
result.push([node, expectedType.value, node, realType]);
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2024
|
+
continue;
|
|
2025
|
+
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
|
|
2026
|
+
const body = node.body;
|
|
2027
|
+
const expectedType = typeChecker.getContextualType(body);
|
|
2028
|
+
const realType = typeChecker.getTypeAtLocation(body);
|
|
2029
|
+
if (expectedType) {
|
|
2030
|
+
result.push([body, expectedType, body, realType]);
|
|
2031
|
+
}
|
|
2032
|
+
ts.forEachChild(body, appendNodeToVisit);
|
|
2033
|
+
continue;
|
|
2034
|
+
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
|
|
2035
|
+
const body = node.body;
|
|
2036
|
+
const expectedType = yield* option(getInferredReturnType(node));
|
|
2037
|
+
const realType = typeChecker.getTypeAtLocation(body);
|
|
2144
2038
|
if (isSome2(expectedType)) {
|
|
2145
|
-
result.push([
|
|
2039
|
+
result.push([body, expectedType.value, body, realType]);
|
|
2146
2040
|
}
|
|
2041
|
+
ts.forEachChild(body, appendNodeToVisit);
|
|
2042
|
+
continue;
|
|
2043
|
+
} else if (ts.isSatisfiesExpression(node)) {
|
|
2044
|
+
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
2045
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2046
|
+
result.push([node.expression, expectedType, node.expression, realType]);
|
|
2047
|
+
appendNodeToVisit(node.expression);
|
|
2048
|
+
continue;
|
|
2147
2049
|
}
|
|
2148
2050
|
ts.forEachChild(node, appendNodeToVisit);
|
|
2149
|
-
continue;
|
|
2150
|
-
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
|
|
2151
|
-
const body = node.body;
|
|
2152
|
-
const expectedType = typeChecker.getContextualType(body);
|
|
2153
|
-
const realType = typeChecker.getTypeAtLocation(body);
|
|
2154
|
-
if (expectedType) {
|
|
2155
|
-
result.push([body, expectedType, body, realType]);
|
|
2156
|
-
}
|
|
2157
|
-
ts.forEachChild(body, appendNodeToVisit);
|
|
2158
|
-
continue;
|
|
2159
|
-
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
|
|
2160
|
-
const body = node.body;
|
|
2161
|
-
const expectedType = yield* option(getInferredReturnType(node));
|
|
2162
|
-
const realType = typeChecker.getTypeAtLocation(body);
|
|
2163
|
-
if (isSome2(expectedType)) {
|
|
2164
|
-
result.push([body, expectedType.value, body, realType]);
|
|
2165
|
-
}
|
|
2166
|
-
ts.forEachChild(body, appendNodeToVisit);
|
|
2167
|
-
continue;
|
|
2168
|
-
} else if (ts.isSatisfiesExpression(node)) {
|
|
2169
|
-
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
2170
|
-
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2171
|
-
result.push([node.expression, expectedType, node.expression, realType]);
|
|
2172
|
-
appendNodeToVisit(node.expression);
|
|
2173
|
-
continue;
|
|
2174
2051
|
}
|
|
2175
|
-
|
|
2176
|
-
}
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2052
|
+
return result;
|
|
2053
|
+
}),
|
|
2054
|
+
"TypeCheckerApi.expectedAndRealType",
|
|
2055
|
+
(sourceFile) => sourceFile
|
|
2056
|
+
);
|
|
2180
2057
|
var unrollUnionMembers = (type) => {
|
|
2181
2058
|
const result = [];
|
|
2182
2059
|
let toTest = [type];
|
|
@@ -2286,95 +2163,17 @@ var durationInput = createCompletion({
|
|
|
2286
2163
|
})
|
|
2287
2164
|
});
|
|
2288
2165
|
|
|
2289
|
-
// src/completions/effectDataClasses.ts
|
|
2290
|
-
var effectDataClasses = createCompletion({
|
|
2291
|
-
name: "effectDataClasses",
|
|
2292
|
-
apply: fn("effectDataClasses")(function* (sourceFile, position) {
|
|
2293
|
-
const ts = yield* service(TypeScriptApi);
|
|
2294
|
-
const maybeInfos = yield* option(
|
|
2295
|
-
parseDataForExtendsClassCompletion(sourceFile, position)
|
|
2296
|
-
);
|
|
2297
|
-
if (isNone2(maybeInfos)) return [];
|
|
2298
|
-
const { accessedObject, className, replacementSpan } = maybeInfos.value;
|
|
2299
|
-
const dataName = yield* option(
|
|
2300
|
-
findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
2301
|
-
sourceFile,
|
|
2302
|
-
"effect",
|
|
2303
|
-
"Data"
|
|
2304
|
-
)
|
|
2305
|
-
);
|
|
2306
|
-
const effectDataIdentifier = match(dataName, {
|
|
2307
|
-
onNone: () => "Data",
|
|
2308
|
-
onSome: (_) => _.text
|
|
2309
|
-
});
|
|
2310
|
-
if (effectDataIdentifier !== accessedObject.text) return [];
|
|
2311
|
-
const name = className.text;
|
|
2312
|
-
return [{
|
|
2313
|
-
name: `TaggedError("${name}")`,
|
|
2314
|
-
kind: ts.ScriptElementKind.constElement,
|
|
2315
|
-
insertText: `${effectDataIdentifier}.TaggedError("${name}")<{${"${0}"}}>{}`,
|
|
2316
|
-
replacementSpan,
|
|
2317
|
-
isSnippet: true
|
|
2318
|
-
}, {
|
|
2319
|
-
name: `TaggedClass("${name}")`,
|
|
2320
|
-
kind: ts.ScriptElementKind.constElement,
|
|
2321
|
-
insertText: `${effectDataIdentifier}.TaggedClass("${name}")<{${"${0}"}}>{}`,
|
|
2322
|
-
replacementSpan,
|
|
2323
|
-
isSnippet: true
|
|
2324
|
-
}];
|
|
2325
|
-
})
|
|
2326
|
-
});
|
|
2327
|
-
|
|
2328
|
-
// src/diagnostics/duplicatePackage.ts
|
|
2329
|
-
var checkedPackagesCache = /* @__PURE__ */ new Map();
|
|
2330
|
-
var programResolvedCacheSize = /* @__PURE__ */ new Map();
|
|
2331
|
-
var duplicatePackage = createDiagnostic({
|
|
2332
|
-
name: "duplicatePackage",
|
|
2333
|
-
code: 6,
|
|
2334
|
-
severity: "warning",
|
|
2335
|
-
apply: fn("duplicatePackage.apply")(function* (sourceFile, report) {
|
|
2336
|
-
const program = yield* service(TypeScriptProgram);
|
|
2337
|
-
const options = yield* service(LanguageServicePluginOptions);
|
|
2338
|
-
if (sourceFile.statements.length < 1) return;
|
|
2339
|
-
let resolvedPackages = checkedPackagesCache.get(sourceFile.fileName) || {};
|
|
2340
|
-
const newResolvedModuleSize = hasProperty(program, "resolvedModules") && hasProperty(program.resolvedModules, "size") && isNumber(program.resolvedModules.size) ? program.resolvedModules.size : 0;
|
|
2341
|
-
const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1;
|
|
2342
|
-
if (newResolvedModuleSize !== oldResolvedSize) {
|
|
2343
|
-
const seenPackages = /* @__PURE__ */ new Set();
|
|
2344
|
-
resolvedPackages = {};
|
|
2345
|
-
program.getSourceFiles().map((_) => {
|
|
2346
|
-
const packageInfo = parsePackageContentNameAndVersionFromScope(_);
|
|
2347
|
-
if (!packageInfo) return;
|
|
2348
|
-
const packageNameAndVersion = packageInfo.name + "@" + packageInfo.version;
|
|
2349
|
-
if (seenPackages.has(packageNameAndVersion)) return;
|
|
2350
|
-
seenPackages.add(packageNameAndVersion);
|
|
2351
|
-
if (!(packageInfo.name === "effect" || packageInfo.hasEffectInPeerDependencies)) return;
|
|
2352
|
-
if (options.allowedDuplicatedPackages.indexOf(packageInfo.name) > -1) return;
|
|
2353
|
-
resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {};
|
|
2354
|
-
resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.packageDirectory;
|
|
2355
|
-
});
|
|
2356
|
-
checkedPackagesCache.set(sourceFile.fileName, resolvedPackages);
|
|
2357
|
-
programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize);
|
|
2358
|
-
}
|
|
2359
|
-
for (const packageName of Object.keys(resolvedPackages)) {
|
|
2360
|
-
if (Object.keys(resolvedPackages[packageName]).length > 1) {
|
|
2361
|
-
const versions = Object.keys(resolvedPackages[packageName]);
|
|
2362
|
-
report({
|
|
2363
|
-
node: sourceFile.statements[0],
|
|
2364
|
-
messageText: `Package ${packageName} is referenced multiple times with different versions (${versions.join(", ")}) and may cause unexpected type errors.
|
|
2365
|
-
Cleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.
|
|
2366
|
-
If this is intended set the LSP config "allowedDuplicatedPackages" to ${JSON.stringify(options.allowedDuplicatedPackages.concat([packageName]))}.
|
|
2367
|
-
|
|
2368
|
-
${versions.map((version) => `- found ${version} at ${resolvedPackages[packageName][version]}`).join("\n")}`,
|
|
2369
|
-
fixes: []
|
|
2370
|
-
});
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
})
|
|
2374
|
-
});
|
|
2375
|
-
|
|
2376
2166
|
// src/core/TypeParser.ts
|
|
2377
2167
|
var TypeParser = Tag("@effect/language-service/TypeParser");
|
|
2168
|
+
var nanoLayer2 = (fa) => gen(function* () {
|
|
2169
|
+
const ts = yield* service(TypeScriptApi);
|
|
2170
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
2171
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
2172
|
+
return yield* pipe(
|
|
2173
|
+
fa,
|
|
2174
|
+
provideService(TypeParser, make3(ts, tsUtils, typeChecker))
|
|
2175
|
+
);
|
|
2176
|
+
});
|
|
2378
2177
|
var TypeParserIssue = class _TypeParserIssue {
|
|
2379
2178
|
_tag = "@effect/language-service/TypeParserIssue";
|
|
2380
2179
|
static issue = fail(new _TypeParserIssue());
|
|
@@ -2382,7 +2181,7 @@ var TypeParserIssue = class _TypeParserIssue {
|
|
|
2382
2181
|
function typeParserIssue(_message, _type, _node) {
|
|
2383
2182
|
return TypeParserIssue.issue;
|
|
2384
2183
|
}
|
|
2385
|
-
function make3(ts, typeChecker) {
|
|
2184
|
+
function make3(ts, tsUtils, typeChecker) {
|
|
2386
2185
|
function covariantTypeArgument(type) {
|
|
2387
2186
|
const signatures = type.getCallSignatures();
|
|
2388
2187
|
if (signatures.length !== 1) {
|
|
@@ -2444,16 +2243,16 @@ function make3(ts, typeChecker) {
|
|
|
2444
2243
|
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
2445
2244
|
return invariantTypeArgument(propertyType);
|
|
2446
2245
|
};
|
|
2447
|
-
const effectVarianceStruct = (type, atLocation) =>
|
|
2448
|
-
|
|
2246
|
+
const effectVarianceStruct = (type, atLocation) => map3(
|
|
2247
|
+
all(
|
|
2449
2248
|
varianceStructCovariantType(type, atLocation, "_A"),
|
|
2450
2249
|
varianceStructCovariantType(type, atLocation, "_E"),
|
|
2451
2250
|
varianceStructCovariantType(type, atLocation, "_R")
|
|
2452
2251
|
),
|
|
2453
2252
|
([A, E, R]) => ({ A, E, R })
|
|
2454
2253
|
);
|
|
2455
|
-
const layerVarianceStruct = (type, atLocation) =>
|
|
2456
|
-
|
|
2254
|
+
const layerVarianceStruct = (type, atLocation) => map3(
|
|
2255
|
+
all(
|
|
2457
2256
|
varianceStructContravariantType(type, atLocation, "_ROut"),
|
|
2458
2257
|
varianceStructCovariantType(type, atLocation, "_E"),
|
|
2459
2258
|
varianceStructCovariantType(type, atLocation, "_RIn")
|
|
@@ -2581,7 +2380,7 @@ function make3(ts, typeChecker) {
|
|
|
2581
2380
|
}
|
|
2582
2381
|
return pipe(
|
|
2583
2382
|
importedEffectModule(propertyAccess.expression),
|
|
2584
|
-
|
|
2383
|
+
map3((effectModule) => ({
|
|
2585
2384
|
node,
|
|
2586
2385
|
effectModule,
|
|
2587
2386
|
generatorFunction,
|
|
@@ -2629,7 +2428,7 @@ function make3(ts, typeChecker) {
|
|
|
2629
2428
|
}
|
|
2630
2429
|
return pipe(
|
|
2631
2430
|
importedEffectModule(propertyAccess.expression),
|
|
2632
|
-
|
|
2431
|
+
map3((effectModule) => ({
|
|
2633
2432
|
node,
|
|
2634
2433
|
effectModule,
|
|
2635
2434
|
generatorFunction,
|
|
@@ -2682,7 +2481,7 @@ function make3(ts, typeChecker) {
|
|
|
2682
2481
|
}
|
|
2683
2482
|
return pipe(
|
|
2684
2483
|
importedEffectModule(propertyAccess.expression),
|
|
2685
|
-
|
|
2484
|
+
map3((effectModule) => ({
|
|
2686
2485
|
node,
|
|
2687
2486
|
generatorFunction,
|
|
2688
2487
|
effectModule,
|
|
@@ -2724,15 +2523,11 @@ function make3(ts, typeChecker) {
|
|
|
2724
2523
|
if (!explicitReturn && !(successType.flags & ts.TypeFlags.VoidLike)) {
|
|
2725
2524
|
replacementNode = pipe(
|
|
2726
2525
|
gen(function* () {
|
|
2727
|
-
const effectIdentifier =
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
onNone: () => "Effect",
|
|
2733
|
-
onSome: (_) => _.text
|
|
2734
|
-
})
|
|
2735
|
-
);
|
|
2526
|
+
const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
2527
|
+
node.getSourceFile(),
|
|
2528
|
+
"effect",
|
|
2529
|
+
"Effect"
|
|
2530
|
+
) || "Effect";
|
|
2736
2531
|
return ts.factory.createCallExpression(
|
|
2737
2532
|
ts.factory.createPropertyAccessExpression(
|
|
2738
2533
|
ts.factory.createIdentifier(effectIdentifier),
|
|
@@ -2760,8 +2555,8 @@ function make3(ts, typeChecker) {
|
|
|
2760
2555
|
"TypeParser.unnecessaryEffectGen",
|
|
2761
2556
|
(node) => node
|
|
2762
2557
|
);
|
|
2763
|
-
const effectSchemaVarianceStruct = (type, atLocation) =>
|
|
2764
|
-
|
|
2558
|
+
const effectSchemaVarianceStruct = (type, atLocation) => map3(
|
|
2559
|
+
all(
|
|
2765
2560
|
varianceStructInvariantType(type, atLocation, "_A"),
|
|
2766
2561
|
varianceStructInvariantType(type, atLocation, "_I"),
|
|
2767
2562
|
varianceStructCovariantType(type, atLocation, "_R")
|
|
@@ -2792,8 +2587,8 @@ function make3(ts, typeChecker) {
|
|
|
2792
2587
|
"TypeParser.effectSchemaType",
|
|
2793
2588
|
(type) => type
|
|
2794
2589
|
);
|
|
2795
|
-
const contextTagVarianceStruct = (type, atLocation) =>
|
|
2796
|
-
|
|
2590
|
+
const contextTagVarianceStruct = (type, atLocation) => map3(
|
|
2591
|
+
all(
|
|
2797
2592
|
varianceStructInvariantType(type, atLocation, "_Identifier"),
|
|
2798
2593
|
varianceStructInvariantType(type, atLocation, "_Service")
|
|
2799
2594
|
),
|
|
@@ -2900,6 +2695,64 @@ function make3(ts, typeChecker) {
|
|
|
2900
2695
|
"TypeParser.promiseLike",
|
|
2901
2696
|
(type) => type
|
|
2902
2697
|
);
|
|
2698
|
+
const extendsEffectService = cachedBy(
|
|
2699
|
+
fn("TypeParser.extendsEffectService")(function* (atLocation) {
|
|
2700
|
+
if (!atLocation.name) {
|
|
2701
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
2702
|
+
}
|
|
2703
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
2704
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
2705
|
+
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
2706
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
2707
|
+
if (!heritageClauses) {
|
|
2708
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
2709
|
+
}
|
|
2710
|
+
for (const heritageClause of heritageClauses) {
|
|
2711
|
+
for (const typeX of heritageClause.types) {
|
|
2712
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2713
|
+
const wholeCall = typeX.expression;
|
|
2714
|
+
if (ts.isCallExpression(wholeCall)) {
|
|
2715
|
+
const effectServiceCall = wholeCall.expression;
|
|
2716
|
+
if (ts.isCallExpression(effectServiceCall) && effectServiceCall.typeArguments && effectServiceCall.typeArguments.length > 0) {
|
|
2717
|
+
const effectServiceIdentifier = effectServiceCall.expression;
|
|
2718
|
+
const selfTypeNode = effectServiceCall.typeArguments[0];
|
|
2719
|
+
if (ts.isPropertyAccessExpression(effectServiceIdentifier) && ts.isIdentifier(effectServiceIdentifier.name) && effectServiceIdentifier.name.text === "Service") {
|
|
2720
|
+
const parsedContextTag = yield* pipe(
|
|
2721
|
+
importedEffectModule(effectServiceIdentifier.expression),
|
|
2722
|
+
flatMap(() => contextTag(type, atLocation)),
|
|
2723
|
+
option
|
|
2724
|
+
);
|
|
2725
|
+
if (isSome2(parsedContextTag)) {
|
|
2726
|
+
let accessors2 = void 0;
|
|
2727
|
+
if (wholeCall.arguments.length >= 2) {
|
|
2728
|
+
const args2 = wholeCall.arguments[1];
|
|
2729
|
+
if (ts.isObjectLiteralExpression(args2)) {
|
|
2730
|
+
for (const property of args2.properties) {
|
|
2731
|
+
if (ts.isPropertyAssignment(property) && property.name && ts.isIdentifier(property.name) && property.name.text === "accessors" && property.initializer && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
2732
|
+
accessors2 = true;
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
return {
|
|
2738
|
+
...parsedContextTag.value,
|
|
2739
|
+
className: atLocation.name,
|
|
2740
|
+
selfTypeNode,
|
|
2741
|
+
args: wholeCall.arguments,
|
|
2742
|
+
accessors: accessors2
|
|
2743
|
+
};
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
return yield* typeParserIssue("Class does not extend Effect.Service", void 0, atLocation);
|
|
2752
|
+
}),
|
|
2753
|
+
"TypeParser.extendsEffectService",
|
|
2754
|
+
(atLocation) => atLocation
|
|
2755
|
+
);
|
|
2903
2756
|
return {
|
|
2904
2757
|
effectType,
|
|
2905
2758
|
strictEffectType,
|
|
@@ -2916,10 +2769,395 @@ function make3(ts, typeChecker) {
|
|
|
2916
2769
|
pipeableType,
|
|
2917
2770
|
pipeCall,
|
|
2918
2771
|
scopeType,
|
|
2919
|
-
promiseLike
|
|
2772
|
+
promiseLike,
|
|
2773
|
+
extendsEffectService
|
|
2920
2774
|
};
|
|
2921
2775
|
}
|
|
2922
2776
|
|
|
2777
|
+
// src/refactors/writeTagClassAccessors.ts
|
|
2778
|
+
var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, service2, className, atLocation, involvedMembers) {
|
|
2779
|
+
const ts = yield* service(TypeScriptApi);
|
|
2780
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
2781
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
2782
|
+
const typeParser = yield* service(TypeParser);
|
|
2783
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
2784
|
+
const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.getEnd() - 1;
|
|
2785
|
+
const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
2786
|
+
sourceFile,
|
|
2787
|
+
"effect",
|
|
2788
|
+
"Effect"
|
|
2789
|
+
) || "Effect";
|
|
2790
|
+
const createFunctionProperty = (className2, propertyName, type, forceAny) => {
|
|
2791
|
+
const arrowBody = ts.factory.createCallExpression(
|
|
2792
|
+
ts.factory.createPropertyAccessExpression(
|
|
2793
|
+
ts.factory.createIdentifier(effectIdentifier),
|
|
2794
|
+
"andThen"
|
|
2795
|
+
),
|
|
2796
|
+
void 0,
|
|
2797
|
+
[
|
|
2798
|
+
ts.factory.createIdentifier(className2.text),
|
|
2799
|
+
ts.factory.createArrowFunction(
|
|
2800
|
+
void 0,
|
|
2801
|
+
void 0,
|
|
2802
|
+
[ts.factory.createParameterDeclaration(
|
|
2803
|
+
void 0,
|
|
2804
|
+
void 0,
|
|
2805
|
+
"_",
|
|
2806
|
+
void 0,
|
|
2807
|
+
forceAny ? ts.factory.createTypeReferenceNode("any") : void 0
|
|
2808
|
+
)],
|
|
2809
|
+
void 0,
|
|
2810
|
+
void 0,
|
|
2811
|
+
ts.factory.createCallExpression(
|
|
2812
|
+
ts.factory.createPropertyAccessExpression(
|
|
2813
|
+
ts.factory.createIdentifier("_"),
|
|
2814
|
+
propertyName
|
|
2815
|
+
),
|
|
2816
|
+
void 0,
|
|
2817
|
+
[
|
|
2818
|
+
ts.factory.createSpreadElement(ts.factory.createIdentifier("args"))
|
|
2819
|
+
]
|
|
2820
|
+
)
|
|
2821
|
+
)
|
|
2822
|
+
]
|
|
2823
|
+
);
|
|
2824
|
+
return ts.factory.createPropertyDeclaration(
|
|
2825
|
+
[ts.factory.createModifier(ts.SyntaxKind.StaticKeyword)],
|
|
2826
|
+
propertyName,
|
|
2827
|
+
void 0,
|
|
2828
|
+
type,
|
|
2829
|
+
ts.factory.createArrowFunction(
|
|
2830
|
+
void 0,
|
|
2831
|
+
void 0,
|
|
2832
|
+
[ts.factory.createParameterDeclaration(
|
|
2833
|
+
void 0,
|
|
2834
|
+
ts.factory.createToken(ts.SyntaxKind.DotDotDotToken),
|
|
2835
|
+
"args",
|
|
2836
|
+
void 0,
|
|
2837
|
+
forceAny ? ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode("any")) : void 0
|
|
2838
|
+
)],
|
|
2839
|
+
void 0,
|
|
2840
|
+
void 0,
|
|
2841
|
+
forceAny ? ts.factory.createAsExpression(arrowBody, ts.factory.createTypeReferenceNode("any")) : arrowBody
|
|
2842
|
+
)
|
|
2843
|
+
);
|
|
2844
|
+
};
|
|
2845
|
+
const generateReturnType = (type, atLocation2, className2) => pipe(
|
|
2846
|
+
typeParser.effectType(type, atLocation2),
|
|
2847
|
+
flatMap((returnedEffect) => {
|
|
2848
|
+
const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(className2.text) : ts.factory.createUnionTypeNode(
|
|
2849
|
+
[
|
|
2850
|
+
ts.factory.createTypeReferenceNode(className2.text),
|
|
2851
|
+
typeChecker.typeToTypeNode(returnedEffect.R, atLocation2, ts.NodeBuilderFlags.NoTruncation)
|
|
2852
|
+
]
|
|
2853
|
+
);
|
|
2854
|
+
const successType = typeChecker.typeToTypeNode(
|
|
2855
|
+
returnedEffect.A,
|
|
2856
|
+
atLocation2,
|
|
2857
|
+
ts.NodeBuilderFlags.NoTruncation
|
|
2858
|
+
);
|
|
2859
|
+
if (!successType) return fail("error generating success type");
|
|
2860
|
+
const failureType = typeChecker.typeToTypeNode(
|
|
2861
|
+
returnedEffect.E,
|
|
2862
|
+
atLocation2,
|
|
2863
|
+
ts.NodeBuilderFlags.NoTruncation
|
|
2864
|
+
);
|
|
2865
|
+
if (!failureType) return fail("error generating failure type");
|
|
2866
|
+
const typeNode = ts.factory.createTypeReferenceNode(
|
|
2867
|
+
ts.factory.createQualifiedName(
|
|
2868
|
+
ts.factory.createIdentifier(effectIdentifier),
|
|
2869
|
+
ts.factory.createIdentifier("Effect")
|
|
2870
|
+
),
|
|
2871
|
+
[successType, failureType, contextType]
|
|
2872
|
+
);
|
|
2873
|
+
return succeed(typeNode);
|
|
2874
|
+
}),
|
|
2875
|
+
orElse2(
|
|
2876
|
+
() => pipe(
|
|
2877
|
+
typeParser.promiseLike(type, atLocation2),
|
|
2878
|
+
flatMap(({ type: type2 }) => {
|
|
2879
|
+
const successType = typeChecker.typeToTypeNode(
|
|
2880
|
+
type2,
|
|
2881
|
+
atLocation2,
|
|
2882
|
+
ts.NodeBuilderFlags.NoTruncation
|
|
2883
|
+
);
|
|
2884
|
+
if (!successType) return fail("error generating success type");
|
|
2885
|
+
return succeed(ts.factory.createTypeReferenceNode(
|
|
2886
|
+
ts.factory.createQualifiedName(
|
|
2887
|
+
ts.factory.createIdentifier(effectIdentifier),
|
|
2888
|
+
ts.factory.createIdentifier("Effect")
|
|
2889
|
+
),
|
|
2890
|
+
[
|
|
2891
|
+
successType,
|
|
2892
|
+
ts.factory.createTypeReferenceNode(
|
|
2893
|
+
ts.factory.createQualifiedName(
|
|
2894
|
+
ts.factory.createIdentifier("Cause"),
|
|
2895
|
+
ts.factory.createIdentifier("UnknownException")
|
|
2896
|
+
)
|
|
2897
|
+
),
|
|
2898
|
+
ts.factory.createTypeReferenceNode(className2.text)
|
|
2899
|
+
]
|
|
2900
|
+
));
|
|
2901
|
+
})
|
|
2902
|
+
)
|
|
2903
|
+
),
|
|
2904
|
+
orElse2(() => {
|
|
2905
|
+
const successType = typeChecker.typeToTypeNode(type, atLocation2, ts.NodeBuilderFlags.NoTruncation);
|
|
2906
|
+
if (!successType) return fail("error generating success type");
|
|
2907
|
+
const typeNode = ts.factory.createTypeReferenceNode(
|
|
2908
|
+
ts.factory.createQualifiedName(
|
|
2909
|
+
ts.factory.createIdentifier(effectIdentifier),
|
|
2910
|
+
ts.factory.createIdentifier("Effect")
|
|
2911
|
+
),
|
|
2912
|
+
[
|
|
2913
|
+
successType,
|
|
2914
|
+
ts.factory.createTypeReferenceNode("never"),
|
|
2915
|
+
ts.factory.createTypeReferenceNode(className2.text)
|
|
2916
|
+
]
|
|
2917
|
+
);
|
|
2918
|
+
return succeed(typeNode);
|
|
2919
|
+
})
|
|
2920
|
+
);
|
|
2921
|
+
const proxySignature = (signature, atLocation2, className2) => gen(function* () {
|
|
2922
|
+
const signatureDeclaration = typeChecker.signatureToSignatureDeclaration(
|
|
2923
|
+
signature,
|
|
2924
|
+
ts.SyntaxKind.FunctionType,
|
|
2925
|
+
atLocation2,
|
|
2926
|
+
ts.NodeBuilderFlags.NoTruncation
|
|
2927
|
+
);
|
|
2928
|
+
if (!signatureDeclaration) return yield* fail("error generating signature");
|
|
2929
|
+
const returnType = yield* generateReturnType(signature.getReturnType(), atLocation2, className2);
|
|
2930
|
+
return ts.factory.createFunctionTypeNode(
|
|
2931
|
+
signatureDeclaration.typeParameters,
|
|
2932
|
+
signatureDeclaration.parameters,
|
|
2933
|
+
returnType
|
|
2934
|
+
);
|
|
2935
|
+
});
|
|
2936
|
+
for (const { property, propertyType } of involvedMembers) {
|
|
2937
|
+
const callSignatures = [];
|
|
2938
|
+
let propertyDeclaration = void 0;
|
|
2939
|
+
for (const signature of propertyType.getCallSignatures()) {
|
|
2940
|
+
yield* pipe(
|
|
2941
|
+
proxySignature(signature, atLocation, className),
|
|
2942
|
+
map3((sig) => {
|
|
2943
|
+
callSignatures.push(sig);
|
|
2944
|
+
}),
|
|
2945
|
+
ignore
|
|
2946
|
+
);
|
|
2947
|
+
}
|
|
2948
|
+
const allSignatures = ts.factory.createIntersectionTypeNode(callSignatures);
|
|
2949
|
+
const type = tsUtils.simplifyTypeNode(allSignatures);
|
|
2950
|
+
propertyDeclaration = createFunctionProperty(className, property.getName(), type, callSignatures.length > 1);
|
|
2951
|
+
const oldProperty = atLocation.members.filter(ts.isPropertyDeclaration).find((p) => {
|
|
2952
|
+
const symbol3 = typeChecker.getSymbolAtLocation(p.name);
|
|
2953
|
+
return symbol3?.getName() === property.getName();
|
|
2954
|
+
});
|
|
2955
|
+
if (oldProperty) {
|
|
2956
|
+
changeTracker.deleteRange(sourceFile, {
|
|
2957
|
+
pos: oldProperty.getStart(sourceFile),
|
|
2958
|
+
end: oldProperty.getEnd()
|
|
2959
|
+
});
|
|
2960
|
+
changeTracker.insertNodeAt(sourceFile, oldProperty.getStart(sourceFile), propertyDeclaration);
|
|
2961
|
+
} else {
|
|
2962
|
+
changeTracker.insertNodeAt(sourceFile, insertLocation, propertyDeclaration, { suffix: "\n" });
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
});
|
|
2966
|
+
var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
|
|
2967
|
+
const ts = yield* service(TypeScriptApi);
|
|
2968
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
2969
|
+
const typeParser = yield* service(TypeParser);
|
|
2970
|
+
if (!ts.isClassDeclaration(node)) return yield* fail("not a class declaration");
|
|
2971
|
+
const { Service, accessors: accessors2, className } = yield* pipe(
|
|
2972
|
+
typeParser.extendsEffectService(node),
|
|
2973
|
+
orElse2(() => fail("not a class extending Effect.Service call"))
|
|
2974
|
+
);
|
|
2975
|
+
if (accessors2 !== true) return yield* fail("accessors are not enabled in the Effect.Service call");
|
|
2976
|
+
const involvedMembers = [];
|
|
2977
|
+
for (const property of typeChecker.getPropertiesOfType(Service)) {
|
|
2978
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, node);
|
|
2979
|
+
const callSignatures = propertyType.getCallSignatures();
|
|
2980
|
+
if (callSignatures.length > 0) {
|
|
2981
|
+
const withTypeParameters = callSignatures.filter((_) => _.typeParameters && _.typeParameters.length > 0);
|
|
2982
|
+
if (callSignatures.length > 1 || withTypeParameters.length > 0) involvedMembers.push({ property, propertyType });
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
const hash2 = involvedMembers.map(({ property, propertyType }) => {
|
|
2986
|
+
return property.getName() + ": " + typeChecker.typeToString(propertyType);
|
|
2987
|
+
}).concat([className.text]).join("\n");
|
|
2988
|
+
return { Service, className, atLocation: node, hash: cyrb53(hash2), involvedMembers };
|
|
2989
|
+
});
|
|
2990
|
+
var writeTagClassAccessors = createRefactor({
|
|
2991
|
+
name: "writeTagClassAccessors",
|
|
2992
|
+
description: "Implement accessors methods with generics or multiple signatures",
|
|
2993
|
+
apply: fn("writeTagClassAccessors.apply")(function* (sourceFile, textRange) {
|
|
2994
|
+
const ts = yield* service(TypeScriptApi);
|
|
2995
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
2996
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
2997
|
+
const typeParser = yield* service(TypeParser);
|
|
2998
|
+
const parseNode = (node) => pipe(
|
|
2999
|
+
parse2(node),
|
|
3000
|
+
map3(({ Service, atLocation, className, involvedMembers }) => ({
|
|
3001
|
+
kind: "refactor.rewrite.effect.writeTagClassAccessors",
|
|
3002
|
+
description: "Implement Service accessors",
|
|
3003
|
+
apply: pipe(
|
|
3004
|
+
generate(sourceFile, Service, className, atLocation, involvedMembers),
|
|
3005
|
+
provideService(TypeScriptUtils, tsUtils),
|
|
3006
|
+
provideService(TypeParser, typeParser),
|
|
3007
|
+
provideService(TypeCheckerApi, typeChecker),
|
|
3008
|
+
provideService(TypeScriptApi, ts)
|
|
3009
|
+
)
|
|
3010
|
+
}))
|
|
3011
|
+
);
|
|
3012
|
+
const parentNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange);
|
|
3013
|
+
return yield* pipe(
|
|
3014
|
+
firstSuccessOf(parentNodes.map(parseNode)),
|
|
3015
|
+
orElse2(() => fail(new RefactorNotApplicableError()))
|
|
3016
|
+
);
|
|
3017
|
+
})
|
|
3018
|
+
});
|
|
3019
|
+
|
|
3020
|
+
// src/codegens/accessors.ts
|
|
3021
|
+
var accessors = createCodegen({
|
|
3022
|
+
name: "accessors",
|
|
3023
|
+
apply: fn("accessors.apply")(function* (sourceFile, textRange) {
|
|
3024
|
+
const ts = yield* service(TypeScriptApi);
|
|
3025
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3026
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3027
|
+
const typeParser = yield* service(TypeParser);
|
|
3028
|
+
const nodeAndCommentRange = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, textRange.pos);
|
|
3029
|
+
if (!nodeAndCommentRange) return yield* fail(new CodegenNotApplicableError("no node and comment range"));
|
|
3030
|
+
return yield* pipe(
|
|
3031
|
+
parse2(nodeAndCommentRange.node),
|
|
3032
|
+
map3(
|
|
3033
|
+
(_) => ({
|
|
3034
|
+
hash: _.hash,
|
|
3035
|
+
description: "Generate accessors for the service",
|
|
3036
|
+
apply: pipe(
|
|
3037
|
+
generate(sourceFile, _.Service, _.className, _.atLocation, _.involvedMembers),
|
|
3038
|
+
provideService(TypeScriptApi, ts),
|
|
3039
|
+
provideService(TypeScriptUtils, tsUtils),
|
|
3040
|
+
provideService(TypeCheckerApi, typeChecker),
|
|
3041
|
+
provideService(TypeParser, typeParser)
|
|
3042
|
+
)
|
|
3043
|
+
})
|
|
3044
|
+
),
|
|
3045
|
+
orElse2((cause) => fail(new CodegenNotApplicableError(cause)))
|
|
3046
|
+
);
|
|
3047
|
+
})
|
|
3048
|
+
});
|
|
3049
|
+
|
|
3050
|
+
// src/codegens.ts
|
|
3051
|
+
var codegens = [accessors];
|
|
3052
|
+
|
|
3053
|
+
// src/completions/effectCodegensComment.ts
|
|
3054
|
+
var effectCodegensComment = createCompletion({
|
|
3055
|
+
name: "effectCodegensComment",
|
|
3056
|
+
apply: fn("effectCodegensComment")(function* (sourceFile, position) {
|
|
3057
|
+
const ts = yield* service(TypeScriptApi);
|
|
3058
|
+
const sourceText = sourceFile.text;
|
|
3059
|
+
const match2 = /(\/\/|\/\*(?:\*?))\s*(@)\s*$/id.exec(sourceText.substring(0, position));
|
|
3060
|
+
if (match2 && match2.indices) {
|
|
3061
|
+
const lastIndex = match2.indices[2][0];
|
|
3062
|
+
const replacementSpan = {
|
|
3063
|
+
start: lastIndex,
|
|
3064
|
+
length: Math.max(0, position - lastIndex)
|
|
3065
|
+
};
|
|
3066
|
+
const allCodegens = sort(Object.values(codegens).map((codegen) => codegen.name), string2).join(",");
|
|
3067
|
+
const enableSnippet = "${1|" + allCodegens + "|} $0";
|
|
3068
|
+
return [{
|
|
3069
|
+
name: `@effect-codegens`,
|
|
3070
|
+
kind: ts.ScriptElementKind.string,
|
|
3071
|
+
insertText: "@effect-codegens " + enableSnippet,
|
|
3072
|
+
isSnippet: true,
|
|
3073
|
+
replacementSpan
|
|
3074
|
+
}];
|
|
3075
|
+
}
|
|
3076
|
+
return [];
|
|
3077
|
+
})
|
|
3078
|
+
});
|
|
3079
|
+
|
|
3080
|
+
// src/completions/effectDataClasses.ts
|
|
3081
|
+
var effectDataClasses = createCompletion({
|
|
3082
|
+
name: "effectDataClasses",
|
|
3083
|
+
apply: fn("effectDataClasses")(function* (sourceFile, position) {
|
|
3084
|
+
const ts = yield* service(TypeScriptApi);
|
|
3085
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3086
|
+
const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
|
|
3087
|
+
if (!maybeInfos) return [];
|
|
3088
|
+
const { accessedObject, className, replacementSpan } = maybeInfos;
|
|
3089
|
+
const effectDataIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3090
|
+
sourceFile,
|
|
3091
|
+
"effect",
|
|
3092
|
+
"Data"
|
|
3093
|
+
) || "Data";
|
|
3094
|
+
if (effectDataIdentifier !== accessedObject.text) return [];
|
|
3095
|
+
const name = className.text;
|
|
3096
|
+
return [{
|
|
3097
|
+
name: `TaggedError("${name}")`,
|
|
3098
|
+
kind: ts.ScriptElementKind.constElement,
|
|
3099
|
+
insertText: `${effectDataIdentifier}.TaggedError("${name}")<{${"${0}"}}>{}`,
|
|
3100
|
+
replacementSpan,
|
|
3101
|
+
isSnippet: true
|
|
3102
|
+
}, {
|
|
3103
|
+
name: `TaggedClass("${name}")`,
|
|
3104
|
+
kind: ts.ScriptElementKind.constElement,
|
|
3105
|
+
insertText: `${effectDataIdentifier}.TaggedClass("${name}")<{${"${0}"}}>{}`,
|
|
3106
|
+
replacementSpan,
|
|
3107
|
+
isSnippet: true
|
|
3108
|
+
}];
|
|
3109
|
+
})
|
|
3110
|
+
});
|
|
3111
|
+
|
|
3112
|
+
// src/diagnostics/duplicatePackage.ts
|
|
3113
|
+
var checkedPackagesCache = /* @__PURE__ */ new Map();
|
|
3114
|
+
var programResolvedCacheSize = /* @__PURE__ */ new Map();
|
|
3115
|
+
var duplicatePackage = createDiagnostic({
|
|
3116
|
+
name: "duplicatePackage",
|
|
3117
|
+
code: 6,
|
|
3118
|
+
severity: "warning",
|
|
3119
|
+
apply: fn("duplicatePackage.apply")(function* (sourceFile, report) {
|
|
3120
|
+
const program = yield* service(TypeScriptProgram);
|
|
3121
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3122
|
+
const options = yield* service(LanguageServicePluginOptions);
|
|
3123
|
+
if (sourceFile.statements.length < 1) return;
|
|
3124
|
+
let resolvedPackages = checkedPackagesCache.get(sourceFile.fileName) || {};
|
|
3125
|
+
const newResolvedModuleSize = hasProperty(program, "resolvedModules") && hasProperty(program.resolvedModules, "size") && isNumber(program.resolvedModules.size) ? program.resolvedModules.size : 0;
|
|
3126
|
+
const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1;
|
|
3127
|
+
if (newResolvedModuleSize !== oldResolvedSize) {
|
|
3128
|
+
const seenPackages = /* @__PURE__ */ new Set();
|
|
3129
|
+
resolvedPackages = {};
|
|
3130
|
+
program.getSourceFiles().map((_) => {
|
|
3131
|
+
const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(_);
|
|
3132
|
+
if (!packageInfo) return;
|
|
3133
|
+
const packageNameAndVersion = packageInfo.name + "@" + packageInfo.version;
|
|
3134
|
+
if (seenPackages.has(packageNameAndVersion)) return;
|
|
3135
|
+
seenPackages.add(packageNameAndVersion);
|
|
3136
|
+
if (!(packageInfo.name === "effect" || packageInfo.hasEffectInPeerDependencies)) return;
|
|
3137
|
+
if (options.allowedDuplicatedPackages.indexOf(packageInfo.name) > -1) return;
|
|
3138
|
+
resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {};
|
|
3139
|
+
resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.packageDirectory;
|
|
3140
|
+
});
|
|
3141
|
+
checkedPackagesCache.set(sourceFile.fileName, resolvedPackages);
|
|
3142
|
+
programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize);
|
|
3143
|
+
}
|
|
3144
|
+
for (const packageName of Object.keys(resolvedPackages)) {
|
|
3145
|
+
if (Object.keys(resolvedPackages[packageName]).length > 1) {
|
|
3146
|
+
const versions = Object.keys(resolvedPackages[packageName]);
|
|
3147
|
+
report({
|
|
3148
|
+
location: sourceFile.statements[0],
|
|
3149
|
+
messageText: `Package ${packageName} is referenced multiple times with different versions (${versions.join(", ")}) and may cause unexpected type errors.
|
|
3150
|
+
Cleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.
|
|
3151
|
+
If this is intended set the LSP config "allowedDuplicatedPackages" to ${JSON.stringify(options.allowedDuplicatedPackages.concat([packageName]))}.
|
|
3152
|
+
|
|
3153
|
+
${versions.map((version) => `- found ${version} at ${resolvedPackages[packageName][version]}`).join("\n")}`,
|
|
3154
|
+
fixes: []
|
|
3155
|
+
});
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
})
|
|
3159
|
+
});
|
|
3160
|
+
|
|
2923
3161
|
// src/diagnostics/effectInVoidSuccess.ts
|
|
2924
3162
|
var effectInVoidSuccess = createDiagnostic({
|
|
2925
3163
|
name: "effectInVoidSuccess",
|
|
@@ -2935,7 +3173,7 @@ var effectInVoidSuccess = createDiagnostic({
|
|
|
2935
3173
|
if (expectedEffect.A.flags & ts.TypeFlags.Void) {
|
|
2936
3174
|
const voidValueTypes = unrollUnionMembers(realEffect.A);
|
|
2937
3175
|
const voidedEffect = yield* firstSuccessOf(
|
|
2938
|
-
voidValueTypes.map((_) =>
|
|
3176
|
+
voidValueTypes.map((_) => map3(typeParser.strictEffectType(_, node), () => _))
|
|
2939
3177
|
);
|
|
2940
3178
|
return { voidedEffect };
|
|
2941
3179
|
}
|
|
@@ -2951,10 +3189,10 @@ var effectInVoidSuccess = createDiagnostic({
|
|
|
2951
3189
|
valueNode,
|
|
2952
3190
|
realType
|
|
2953
3191
|
),
|
|
2954
|
-
|
|
3192
|
+
map3(({ voidedEffect }) => {
|
|
2955
3193
|
report(
|
|
2956
3194
|
{
|
|
2957
|
-
node,
|
|
3195
|
+
location: node,
|
|
2958
3196
|
messageText: `There is a nested '${typeChecker.typeToString(voidedEffect)}' in the 'void' success channel, beware that this could lead to nested Effect<Effect<...>> that won't be executed.`,
|
|
2959
3197
|
fixes: []
|
|
2960
3198
|
}
|
|
@@ -3003,7 +3241,7 @@ var floatingEffect = createDiagnostic({
|
|
|
3003
3241
|
);
|
|
3004
3242
|
if (isNone2(allowedFloatingEffects)) {
|
|
3005
3243
|
report({
|
|
3006
|
-
node,
|
|
3244
|
+
location: node,
|
|
3007
3245
|
messageText: `Effect must be yielded or assigned to a variable.`,
|
|
3008
3246
|
fixes: []
|
|
3009
3247
|
});
|
|
@@ -3044,9 +3282,9 @@ var genericEffectServices = createDiagnostic({
|
|
|
3044
3282
|
for (const [type, reportAt] of typesToCheck) {
|
|
3045
3283
|
yield* pipe(
|
|
3046
3284
|
typeParser.contextTag(type, node),
|
|
3047
|
-
|
|
3285
|
+
map3(() => {
|
|
3048
3286
|
report({
|
|
3049
|
-
|
|
3287
|
+
location: reportAt,
|
|
3050
3288
|
messageText: `Effect Services with type parameters are not supported because they cannot be properly discriminated at runtime, which may cause unexpected behavior.`,
|
|
3051
3289
|
fixes: []
|
|
3052
3290
|
});
|
|
@@ -3068,17 +3306,16 @@ var importFromBarrel = createDiagnostic({
|
|
|
3068
3306
|
const languageServicePluginOptions = yield* service(LanguageServicePluginOptions);
|
|
3069
3307
|
if (languageServicePluginOptions.namespaceImportPackages.length === 0) return;
|
|
3070
3308
|
const ts = yield* service(TypeScriptApi);
|
|
3309
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3071
3310
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3072
3311
|
const program = yield* service(TypeScriptProgram);
|
|
3073
3312
|
const packageNamesToCheck = flatten(
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
(packageName) => resolveModulePattern(sourceFile, packageName)
|
|
3077
|
-
)
|
|
3313
|
+
languageServicePluginOptions.namespaceImportPackages.map(
|
|
3314
|
+
(packageName) => tsUtils.resolveModulePattern(sourceFile, packageName)
|
|
3078
3315
|
)
|
|
3079
3316
|
);
|
|
3080
3317
|
const isImportedFromBarrelExport = (element) => {
|
|
3081
|
-
const getModuleSpecifier = makeGetModuleSpecifier(
|
|
3318
|
+
const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
|
|
3082
3319
|
const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
|
|
3083
3320
|
if (!(getModuleSpecifier && resolveExternalModuleName)) return;
|
|
3084
3321
|
const importDeclaration = ts.findAncestor(element, (node) => ts.isImportDeclaration(node));
|
|
@@ -3154,7 +3391,7 @@ var importFromBarrel = createDiagnostic({
|
|
|
3154
3391
|
unbarrelledFileName
|
|
3155
3392
|
} = result;
|
|
3156
3393
|
report({
|
|
3157
|
-
node,
|
|
3394
|
+
location: node,
|
|
3158
3395
|
messageText: `Importing from barrel module ${barrelModuleName} is not allowed.`,
|
|
3159
3396
|
fixes: [
|
|
3160
3397
|
{
|
|
@@ -3219,13 +3456,13 @@ var leakingRequirements = createDiagnostic({
|
|
|
3219
3456
|
let effectContextType = void 0;
|
|
3220
3457
|
yield* pipe(
|
|
3221
3458
|
typeParser.effectType(servicePropertyType, atLocation),
|
|
3222
|
-
|
|
3459
|
+
map3((_) => effectContextType = _.R),
|
|
3223
3460
|
orElse2(() => {
|
|
3224
3461
|
const servicePropertyCallSignatures = servicePropertyType.getCallSignatures();
|
|
3225
3462
|
if (servicePropertyCallSignatures.length === 1) {
|
|
3226
3463
|
return pipe(
|
|
3227
3464
|
typeParser.effectType(servicePropertyCallSignatures[0].getReturnType(), atLocation),
|
|
3228
|
-
|
|
3465
|
+
map3((_) => {
|
|
3229
3466
|
effectContextType = _.R;
|
|
3230
3467
|
})
|
|
3231
3468
|
);
|
|
@@ -3243,7 +3480,7 @@ var leakingRequirements = createDiagnostic({
|
|
|
3243
3480
|
if (type.flags & ts.TypeFlags.Never) return succeed(true);
|
|
3244
3481
|
return pipe(
|
|
3245
3482
|
typeParser.scopeType(type, atLocation),
|
|
3246
|
-
|
|
3483
|
+
map3(() => true),
|
|
3247
3484
|
orElse2(() => succeed(false))
|
|
3248
3485
|
);
|
|
3249
3486
|
}
|
|
@@ -3268,7 +3505,7 @@ var leakingRequirements = createDiagnostic({
|
|
|
3268
3505
|
function reportLeakingRequirements(node, requirements) {
|
|
3269
3506
|
if (requirements.length === 0) return;
|
|
3270
3507
|
report({
|
|
3271
|
-
node,
|
|
3508
|
+
location: node,
|
|
3272
3509
|
messageText: `This Service is leaking the ${requirements.map((_) => typeChecker.typeToString(_)).join(" | ")} requirement.
|
|
3273
3510
|
If these requirements cannot be cached and are expected to be provided per method invocation (e.g. HttpServerRequest), you can safely disable this diagnostic for this line through quickfixes.
|
|
3274
3511
|
More info at https://effect.website/docs/requirements-management/layers/#avoiding-requirement-leakage`,
|
|
@@ -3299,10 +3536,10 @@ More info at https://effect.website/docs/requirements-management/layers/#avoidin
|
|
|
3299
3536
|
for (const [type, reportAt] of typesToCheck) {
|
|
3300
3537
|
yield* pipe(
|
|
3301
3538
|
typeParser.contextTag(type, node),
|
|
3302
|
-
|
|
3539
|
+
flatMap(
|
|
3303
3540
|
({ Service }) => pipe(
|
|
3304
3541
|
parseLeakedRequirements(Service, node),
|
|
3305
|
-
|
|
3542
|
+
map3((requirements) => reportLeakingRequirements(reportAt, sort(requirements, typeOrder)))
|
|
3306
3543
|
)
|
|
3307
3544
|
),
|
|
3308
3545
|
orElse2(() => sync(() => ts.forEachChild(node, appendNodeToVisit))),
|
|
@@ -3323,11 +3560,11 @@ var missingEffectContext = createDiagnostic({
|
|
|
3323
3560
|
const typeParser = yield* service(TypeParser);
|
|
3324
3561
|
const typeOrder = yield* deterministicTypeOrder;
|
|
3325
3562
|
const checkForMissingContextTypes = (node, expectedType, valueNode, realType) => pipe(
|
|
3326
|
-
|
|
3563
|
+
all(
|
|
3327
3564
|
typeParser.effectType(expectedType, node),
|
|
3328
3565
|
typeParser.effectType(realType, valueNode)
|
|
3329
3566
|
),
|
|
3330
|
-
|
|
3567
|
+
flatMap(
|
|
3331
3568
|
([expectedEffect, realEffect]) => getMissingTypeEntriesInTargetType(
|
|
3332
3569
|
realEffect.R,
|
|
3333
3570
|
expectedEffect.R
|
|
@@ -3345,10 +3582,10 @@ var missingEffectContext = createDiagnostic({
|
|
|
3345
3582
|
valueNode,
|
|
3346
3583
|
realType
|
|
3347
3584
|
),
|
|
3348
|
-
|
|
3585
|
+
map3(
|
|
3349
3586
|
(missingTypes) => missingTypes.length > 0 ? report(
|
|
3350
3587
|
{
|
|
3351
|
-
node,
|
|
3588
|
+
location: node,
|
|
3352
3589
|
messageText: `Missing '${sortTypes(missingTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect context.`,
|
|
3353
3590
|
fixes: []
|
|
3354
3591
|
}
|
|
@@ -3368,18 +3605,15 @@ var missingEffectError = createDiagnostic({
|
|
|
3368
3605
|
severity: "error",
|
|
3369
3606
|
apply: fn("missingEffectError.apply")(function* (sourceFile, report) {
|
|
3370
3607
|
const ts = yield* service(TypeScriptApi);
|
|
3608
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3371
3609
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3372
3610
|
const typeParser = yield* service(TypeParser);
|
|
3373
3611
|
const typeOrder = yield* deterministicTypeOrder;
|
|
3374
|
-
const effectModuleIdentifier =
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
),
|
|
3380
|
-
map4((_) => _.text),
|
|
3381
|
-
orElse2(() => succeed("Effect"))
|
|
3382
|
-
);
|
|
3612
|
+
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3613
|
+
sourceFile,
|
|
3614
|
+
"effect",
|
|
3615
|
+
"Effect"
|
|
3616
|
+
) || "Effect";
|
|
3383
3617
|
const createDieMessage = (message) => ts.factory.createCallExpression(
|
|
3384
3618
|
ts.factory.createPropertyAccessExpression(
|
|
3385
3619
|
ts.factory.createIdentifier(effectModuleIdentifier),
|
|
@@ -3389,17 +3623,17 @@ var missingEffectError = createDiagnostic({
|
|
|
3389
3623
|
[ts.factory.createStringLiteral(message)]
|
|
3390
3624
|
);
|
|
3391
3625
|
const checkForMissingErrorTypes = (node, expectedType, valueNode, realType) => pipe(
|
|
3392
|
-
|
|
3626
|
+
all(
|
|
3393
3627
|
typeParser.effectType(expectedType, node),
|
|
3394
3628
|
typeParser.effectType(realType, valueNode)
|
|
3395
3629
|
),
|
|
3396
|
-
|
|
3630
|
+
flatMap(
|
|
3397
3631
|
([expectedEffect, realEffect]) => pipe(
|
|
3398
3632
|
getMissingTypeEntriesInTargetType(
|
|
3399
3633
|
realEffect.E,
|
|
3400
3634
|
expectedEffect.E
|
|
3401
3635
|
),
|
|
3402
|
-
|
|
3636
|
+
map3((missingErrorTypes) => ({ missingErrorTypes, expectedErrorType: expectedEffect.E }))
|
|
3403
3637
|
)
|
|
3404
3638
|
)
|
|
3405
3639
|
);
|
|
@@ -3414,7 +3648,7 @@ var missingEffectError = createDiagnostic({
|
|
|
3414
3648
|
valueNode,
|
|
3415
3649
|
realType
|
|
3416
3650
|
),
|
|
3417
|
-
|
|
3651
|
+
map3((result) => {
|
|
3418
3652
|
if (result.missingErrorTypes.length === 0) return;
|
|
3419
3653
|
const fixes = [];
|
|
3420
3654
|
if (ts.isExpression(valueNode) && result.expectedErrorType.flags & ts.TypeFlags.Never) {
|
|
@@ -3437,17 +3671,17 @@ var missingEffectError = createDiagnostic({
|
|
|
3437
3671
|
if (ts.isExpression(valueNode)) {
|
|
3438
3672
|
const propertyAssignments = pipe(
|
|
3439
3673
|
result.missingErrorTypes,
|
|
3440
|
-
|
|
3674
|
+
map4((_) => typeChecker.getPropertyOfType(_, "_tag")),
|
|
3441
3675
|
filter((_) => !!_),
|
|
3442
|
-
|
|
3676
|
+
map4((_) => typeChecker.getTypeOfSymbolAtLocation(_, valueNode)),
|
|
3443
3677
|
filter((_) => !!(_.flags & ts.TypeFlags.Literal)),
|
|
3444
|
-
|
|
3678
|
+
map4((_) => typeChecker.typeToTypeNode(_, void 0, ts.NodeBuilderFlags.NoTruncation)),
|
|
3445
3679
|
filter((_) => !!_ && ts.isLiteralTypeNode(_)),
|
|
3446
|
-
|
|
3680
|
+
map4((_) => _.literal),
|
|
3447
3681
|
filter((_) => ts.isLiteralExpression(_)),
|
|
3448
|
-
|
|
3682
|
+
map4((_) => _.text),
|
|
3449
3683
|
sort(string2),
|
|
3450
|
-
|
|
3684
|
+
map4(
|
|
3451
3685
|
(_) => ts.factory.createPropertyAssignment(
|
|
3452
3686
|
ts.factory.createIdentifier(_),
|
|
3453
3687
|
ts.factory.createArrowFunction(
|
|
@@ -3481,7 +3715,7 @@ var missingEffectError = createDiagnostic({
|
|
|
3481
3715
|
}
|
|
3482
3716
|
report(
|
|
3483
3717
|
{
|
|
3484
|
-
node,
|
|
3718
|
+
location: node,
|
|
3485
3719
|
messageText: `Missing '${sortTypes(result.missingErrorTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect errors.`,
|
|
3486
3720
|
fixes
|
|
3487
3721
|
}
|
|
@@ -3545,7 +3779,7 @@ var missingReturnYieldStar = createDiagnostic({
|
|
|
3545
3779
|
})
|
|
3546
3780
|
}] : [];
|
|
3547
3781
|
report({
|
|
3548
|
-
node,
|
|
3782
|
+
location: node,
|
|
3549
3783
|
messageText: `Yielded Effect never succeeds, so it is best to use a 'return yield*' instead.`,
|
|
3550
3784
|
fixes: fix
|
|
3551
3785
|
});
|
|
@@ -3588,7 +3822,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
3588
3822
|
typeParser.effectGen(effectGenNode),
|
|
3589
3823
|
orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
|
|
3590
3824
|
orElse2(() => typeParser.effectFnGen(effectGenNode)),
|
|
3591
|
-
|
|
3825
|
+
map3(({ functionStar }) => {
|
|
3592
3826
|
if (functionStar) {
|
|
3593
3827
|
brokenGenerators.add(functionStar);
|
|
3594
3828
|
}
|
|
@@ -3601,7 +3835,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
3601
3835
|
}
|
|
3602
3836
|
brokenGenerators.forEach(
|
|
3603
3837
|
(node) => report({
|
|
3604
|
-
node,
|
|
3838
|
+
location: node,
|
|
3605
3839
|
messageText: `Seems like you used yield instead of yield* inside this Effect.gen.`,
|
|
3606
3840
|
fixes: []
|
|
3607
3841
|
})
|
|
@@ -3623,7 +3857,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
3623
3857
|
})
|
|
3624
3858
|
}] : [];
|
|
3625
3859
|
report({
|
|
3626
|
-
node,
|
|
3860
|
+
location: node,
|
|
3627
3861
|
messageText: `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`,
|
|
3628
3862
|
fixes: fix
|
|
3629
3863
|
});
|
|
@@ -3638,34 +3872,27 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
3638
3872
|
severity: "warning",
|
|
3639
3873
|
apply: fn("multipleEffectProvide.apply")(function* (sourceFile, report) {
|
|
3640
3874
|
const ts = yield* service(TypeScriptApi);
|
|
3875
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3641
3876
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3642
3877
|
const typeParser = yield* service(TypeParser);
|
|
3643
|
-
const effectModuleIdentifier =
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3654
|
-
sourceFile,
|
|
3655
|
-
"effect",
|
|
3656
|
-
"Layer"
|
|
3657
|
-
),
|
|
3658
|
-
map4((_) => _.text),
|
|
3659
|
-
orElse2(() => succeed("Layer"))
|
|
3660
|
-
);
|
|
3878
|
+
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3879
|
+
sourceFile,
|
|
3880
|
+
"effect",
|
|
3881
|
+
"Effect"
|
|
3882
|
+
) || "Effect";
|
|
3883
|
+
const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3884
|
+
sourceFile,
|
|
3885
|
+
"effect",
|
|
3886
|
+
"Layer"
|
|
3887
|
+
) || "Layer";
|
|
3661
3888
|
const parseEffectProvideLayer = (node) => {
|
|
3662
3889
|
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && node.expression.name.text === "provide" && node.arguments.length > 0) {
|
|
3663
3890
|
const layer = node.arguments[0];
|
|
3664
3891
|
const type = typeChecker.getTypeAtLocation(layer);
|
|
3665
3892
|
return pipe(
|
|
3666
3893
|
typeParser.importedEffectModule(node.expression.expression),
|
|
3667
|
-
|
|
3668
|
-
|
|
3894
|
+
flatMap(() => typeParser.layerType(type, layer)),
|
|
3895
|
+
map3(() => ({ layer, node })),
|
|
3669
3896
|
orElse2(() => void_)
|
|
3670
3897
|
);
|
|
3671
3898
|
}
|
|
@@ -3687,8 +3914,8 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
3687
3914
|
for (const chunk of previousLayers) {
|
|
3688
3915
|
if (chunk.length < 2) continue;
|
|
3689
3916
|
report({
|
|
3690
|
-
|
|
3691
|
-
messageText: "
|
|
3917
|
+
location: chunk[0].node,
|
|
3918
|
+
messageText: "Avoid chaining Effect.provide calls, as this can lead to service lifecycle issues. Instead, merge layers and provide them in a single call.",
|
|
3692
3919
|
fixes: [{
|
|
3693
3920
|
fixName: "multipleEffectProvide_fix",
|
|
3694
3921
|
description: "Combine into a single provide",
|
|
@@ -3735,6 +3962,51 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
3735
3962
|
})
|
|
3736
3963
|
});
|
|
3737
3964
|
|
|
3965
|
+
// src/diagnostics/outdatedEffectCodegen.ts
|
|
3966
|
+
var outdatedEffectCodegen = createDiagnostic({
|
|
3967
|
+
name: "outdatedEffectCodegen",
|
|
3968
|
+
code: 19,
|
|
3969
|
+
severity: "warning",
|
|
3970
|
+
apply: fn("outdatedEffectCodegen.apply")(function* (sourceFile, _report) {
|
|
3971
|
+
const codegensWithRanges = yield* getCodegensForSourceFile(codegens, sourceFile);
|
|
3972
|
+
for (const { codegen, hash: hash2, range } of codegensWithRanges) {
|
|
3973
|
+
yield* pipe(
|
|
3974
|
+
getEditsForCodegen([codegen], sourceFile, range),
|
|
3975
|
+
map3((applicable) => {
|
|
3976
|
+
if (applicable.hash !== hash2) {
|
|
3977
|
+
_report({
|
|
3978
|
+
location: range,
|
|
3979
|
+
messageText: `Codegen ${codegen.name} result is outdated`,
|
|
3980
|
+
fixes: [
|
|
3981
|
+
{
|
|
3982
|
+
fixName: "outdatedEffectCodegen_fix",
|
|
3983
|
+
description: `Re-run ${codegen.name}`,
|
|
3984
|
+
apply: applicable.apply
|
|
3985
|
+
},
|
|
3986
|
+
{
|
|
3987
|
+
fixName: "outdatedEffectCodegen_ignore",
|
|
3988
|
+
description: `Ignore this ${codegen.name} update`,
|
|
3989
|
+
apply: applicable.ignore
|
|
3990
|
+
}
|
|
3991
|
+
]
|
|
3992
|
+
});
|
|
3993
|
+
}
|
|
3994
|
+
}),
|
|
3995
|
+
orElse2(
|
|
3996
|
+
(e) => sync(() => {
|
|
3997
|
+
_report({
|
|
3998
|
+
location: range,
|
|
3999
|
+
messageText: `Codegen ${codegen.name} is not applicable here: ${e.cause}`,
|
|
4000
|
+
fixes: []
|
|
4001
|
+
});
|
|
4002
|
+
})
|
|
4003
|
+
),
|
|
4004
|
+
ignore
|
|
4005
|
+
);
|
|
4006
|
+
}
|
|
4007
|
+
})
|
|
4008
|
+
});
|
|
4009
|
+
|
|
3738
4010
|
// src/diagnostics/returnEffectInGen.ts
|
|
3739
4011
|
var returnEffectInGen = createDiagnostic({
|
|
3740
4012
|
name: "returnEffectInGen",
|
|
@@ -3769,7 +4041,7 @@ var returnEffectInGen = createDiagnostic({
|
|
|
3769
4041
|
typeParser.effectGen(effectGenNode),
|
|
3770
4042
|
orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
|
|
3771
4043
|
orElse2(() => typeParser.effectFnGen(effectGenNode)),
|
|
3772
|
-
|
|
4044
|
+
map3(() => {
|
|
3773
4045
|
const fix = node.expression ? [{
|
|
3774
4046
|
fixName: "returnEffectInGen_fix",
|
|
3775
4047
|
description: "Add yield* statement",
|
|
@@ -3786,7 +4058,7 @@ var returnEffectInGen = createDiagnostic({
|
|
|
3786
4058
|
})
|
|
3787
4059
|
}] : [];
|
|
3788
4060
|
report({
|
|
3789
|
-
node,
|
|
4061
|
+
location: node,
|
|
3790
4062
|
messageText: `You are returning an Effect-able type inside a generator function, and will result in nested Effect<Effect<...>>.
|
|
3791
4063
|
Maybe you wanted to return yield* instead?
|
|
3792
4064
|
Nested Effect-able types may be intended if you plan to later manually flatten or unwrap this Effect, if so you can safely disable this diagnostic for this line through quickfixes.`,
|
|
@@ -3809,17 +4081,14 @@ var scopeInLayerEffect = createDiagnostic({
|
|
|
3809
4081
|
severity: "warning",
|
|
3810
4082
|
apply: fn("scopeInLayerEffect.apply")(function* (sourceFile, report) {
|
|
3811
4083
|
const ts = yield* service(TypeScriptApi);
|
|
4084
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3812
4085
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3813
4086
|
const typeParser = yield* service(TypeParser);
|
|
3814
|
-
const layerModuleIdentifier =
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
),
|
|
3820
|
-
map4((_) => _.text),
|
|
3821
|
-
orElse2(() => succeed("Layer"))
|
|
3822
|
-
);
|
|
4087
|
+
const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4088
|
+
sourceFile,
|
|
4089
|
+
"effect",
|
|
4090
|
+
"Layer"
|
|
4091
|
+
) || "Layer";
|
|
3823
4092
|
function parseLayerEffectApiCall(node) {
|
|
3824
4093
|
if (!ts.isCallExpression(node)) return;
|
|
3825
4094
|
const expression = node.expression;
|
|
@@ -3843,9 +4112,9 @@ var scopeInLayerEffect = createDiagnostic({
|
|
|
3843
4112
|
}
|
|
3844
4113
|
return pipe(
|
|
3845
4114
|
firstSuccessOf(entries.map((type2) => typeParser.scopeType(type2, node))),
|
|
3846
|
-
|
|
4115
|
+
map3(
|
|
3847
4116
|
() => report({
|
|
3848
|
-
node,
|
|
4117
|
+
location: node,
|
|
3849
4118
|
messageText: `Seems like you are constructing a layer with a scope in the requirements.
|
|
3850
4119
|
Consider using "scoped" instead to get rid of the scope in the requirements.`,
|
|
3851
4120
|
fixes: methodIdentifier ? [{
|
|
@@ -3878,7 +4147,7 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
|
|
|
3878
4147
|
const type = typeChecker.getTypeAtLocation(node);
|
|
3879
4148
|
yield* pipe(
|
|
3880
4149
|
typeParser.layerType(type, node),
|
|
3881
|
-
|
|
4150
|
+
flatMap(({ RIn }) => reportIfLayerRequireScope(RIn, node, layerEffectApiCall.methodIdentifier)),
|
|
3882
4151
|
ignore
|
|
3883
4152
|
);
|
|
3884
4153
|
continue;
|
|
@@ -3892,7 +4161,7 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
|
|
|
3892
4161
|
const type = typeChecker.getTypeOfSymbolAtLocation(defaultLayer, node);
|
|
3893
4162
|
yield* pipe(
|
|
3894
4163
|
typeParser.layerType(type, node),
|
|
3895
|
-
|
|
4164
|
+
flatMap(({ RIn }) => reportIfLayerRequireScope(RIn, node, void 0)),
|
|
3896
4165
|
ignore
|
|
3897
4166
|
);
|
|
3898
4167
|
continue;
|
|
@@ -3961,7 +4230,7 @@ var strictBooleanExpressions = createDiagnostic({
|
|
|
3961
4230
|
if (type.flags & ts.TypeFlags.BooleanLiteral) continue;
|
|
3962
4231
|
const typeName = typeChecker.typeToString(type);
|
|
3963
4232
|
report({
|
|
3964
|
-
|
|
4233
|
+
location: nodeToCheck,
|
|
3965
4234
|
messageText: `Unexpected \`${typeName}\` type in condition, expected strictly a boolean instead.`,
|
|
3966
4235
|
fixes: []
|
|
3967
4236
|
});
|
|
@@ -4001,9 +4270,9 @@ var tryCatchInEffectGen = createDiagnostic({
|
|
|
4001
4270
|
typeParser.effectGen(effectGenNode),
|
|
4002
4271
|
orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
|
|
4003
4272
|
orElse2(() => typeParser.effectFnGen(effectGenNode)),
|
|
4004
|
-
|
|
4273
|
+
map3(() => {
|
|
4005
4274
|
report({
|
|
4006
|
-
node,
|
|
4275
|
+
location: node,
|
|
4007
4276
|
messageText: "Avoid using try/catch inside Effect generators. Use Effect's error handling mechanisms instead (e.g., Effect.try, Effect.tryPromise, Effect.catchAll, Effect.catchTag).",
|
|
4008
4277
|
fixes: []
|
|
4009
4278
|
});
|
|
@@ -4036,9 +4305,9 @@ var unnecessaryEffectGen = createDiagnostic({
|
|
|
4036
4305
|
if (ts.isCallExpression(node)) {
|
|
4037
4306
|
yield* pipe(
|
|
4038
4307
|
typeParser.unnecessaryEffectGen(node),
|
|
4039
|
-
|
|
4308
|
+
map3(
|
|
4040
4309
|
({ replacementNode }) => report({
|
|
4041
|
-
node,
|
|
4310
|
+
location: node,
|
|
4042
4311
|
messageText: `This Effect.gen contains a single return statement.`,
|
|
4043
4312
|
fixes: [{
|
|
4044
4313
|
fixName: "unnecessaryEffectGen_fix",
|
|
@@ -4079,10 +4348,10 @@ var unnecessaryPipe = createDiagnostic({
|
|
|
4079
4348
|
if (ts.isCallExpression(node)) {
|
|
4080
4349
|
yield* pipe(
|
|
4081
4350
|
typeParser.pipeCall(node),
|
|
4082
|
-
|
|
4351
|
+
map3(({ args: args2, subject }) => {
|
|
4083
4352
|
if (args2.length === 0) {
|
|
4084
4353
|
report({
|
|
4085
|
-
node,
|
|
4354
|
+
location: node,
|
|
4086
4355
|
messageText: `This pipe call contains no arguments.`,
|
|
4087
4356
|
fixes: [{
|
|
4088
4357
|
fixName: "unnecessaryPipe_fix",
|
|
@@ -4124,12 +4393,12 @@ var unnecessaryPipeChain = createDiagnostic({
|
|
|
4124
4393
|
if (ts.isCallExpression(node)) {
|
|
4125
4394
|
yield* pipe(
|
|
4126
4395
|
typeParser.pipeCall(node),
|
|
4127
|
-
|
|
4128
|
-
(pipeCall) =>
|
|
4396
|
+
flatMap(
|
|
4397
|
+
(pipeCall) => map3(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))
|
|
4129
4398
|
),
|
|
4130
|
-
|
|
4399
|
+
map3(({ innerCall, pipeCall }) => {
|
|
4131
4400
|
report({
|
|
4132
|
-
node,
|
|
4401
|
+
location: node,
|
|
4133
4402
|
messageText: `Chained pipe calls can be simplified to a single pipe call`,
|
|
4134
4403
|
fixes: [{
|
|
4135
4404
|
fixName: "unnecessaryPipeChain_fix",
|
|
@@ -4197,7 +4466,8 @@ var diagnostics = [
|
|
|
4197
4466
|
effectInVoidSuccess,
|
|
4198
4467
|
unnecessaryPipeChain,
|
|
4199
4468
|
strictBooleanExpressions,
|
|
4200
|
-
multipleEffectProvide
|
|
4469
|
+
multipleEffectProvide,
|
|
4470
|
+
outdatedEffectCodegen
|
|
4201
4471
|
];
|
|
4202
4472
|
|
|
4203
4473
|
// src/completions/effectDiagnosticsComment.ts
|
|
@@ -4206,9 +4476,9 @@ var effectDiagnosticsComment = createCompletion({
|
|
|
4206
4476
|
apply: fn("effectDiagnosticsComment")(function* (sourceFile, position) {
|
|
4207
4477
|
const ts = yield* service(TypeScriptApi);
|
|
4208
4478
|
const sourceText = sourceFile.text;
|
|
4209
|
-
const
|
|
4210
|
-
if (
|
|
4211
|
-
const lastIndex =
|
|
4479
|
+
const match2 = /(\/\/|\/\*(?:\*?))\s*(@)\s*$/id.exec(sourceText.substring(0, position));
|
|
4480
|
+
if (match2 && match2.indices) {
|
|
4481
|
+
const lastIndex = match2.indices[2][0];
|
|
4212
4482
|
const replacementSpan = {
|
|
4213
4483
|
start: lastIndex,
|
|
4214
4484
|
length: Math.max(0, position - lastIndex)
|
|
@@ -4238,22 +4508,15 @@ var effectSchemaSelfInClasses = createCompletion({
|
|
|
4238
4508
|
name: "effectSchemaSelfInClasses",
|
|
4239
4509
|
apply: fn("effectSchemaSelfInClasses")(function* (sourceFile, position) {
|
|
4240
4510
|
const ts = yield* service(TypeScriptApi);
|
|
4241
|
-
const
|
|
4242
|
-
|
|
4243
|
-
);
|
|
4244
|
-
|
|
4245
|
-
const
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
"Schema"
|
|
4251
|
-
)
|
|
4252
|
-
);
|
|
4253
|
-
const schemaIdentifier = match(effectSchemaName, {
|
|
4254
|
-
onNone: () => "Schema",
|
|
4255
|
-
onSome: (_) => _.text
|
|
4256
|
-
});
|
|
4511
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4512
|
+
const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
|
|
4513
|
+
if (!maybeInfos) return [];
|
|
4514
|
+
const { accessedObject, className, replacementSpan } = maybeInfos;
|
|
4515
|
+
const schemaIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4516
|
+
sourceFile,
|
|
4517
|
+
"effect",
|
|
4518
|
+
"Schema"
|
|
4519
|
+
) || "Schema";
|
|
4257
4520
|
if (schemaIdentifier !== accessedObject.text) return [];
|
|
4258
4521
|
const name = className.text;
|
|
4259
4522
|
return [{
|
|
@@ -4289,22 +4552,15 @@ var effectSelfInClasses = createCompletion({
|
|
|
4289
4552
|
name: "effectSelfInClasses",
|
|
4290
4553
|
apply: fn("effectSelfInClasses")(function* (sourceFile, position) {
|
|
4291
4554
|
const ts = yield* service(TypeScriptApi);
|
|
4292
|
-
const
|
|
4293
|
-
|
|
4294
|
-
);
|
|
4295
|
-
|
|
4296
|
-
const
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
"Effect"
|
|
4302
|
-
)
|
|
4303
|
-
);
|
|
4304
|
-
const effectIdentifier = match(effectName, {
|
|
4305
|
-
onNone: () => "Effect",
|
|
4306
|
-
onSome: (_) => _.text
|
|
4307
|
-
});
|
|
4555
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4556
|
+
const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
|
|
4557
|
+
if (!maybeInfos) return [];
|
|
4558
|
+
const { accessedObject, className, replacementSpan } = maybeInfos;
|
|
4559
|
+
const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4560
|
+
sourceFile,
|
|
4561
|
+
"effect",
|
|
4562
|
+
"Effect"
|
|
4563
|
+
) || "Effect";
|
|
4308
4564
|
if (effectIdentifier !== accessedObject.text) return [];
|
|
4309
4565
|
const name = className.text;
|
|
4310
4566
|
return [{
|
|
@@ -4322,12 +4578,11 @@ var fnFunctionStar = createCompletion({
|
|
|
4322
4578
|
name: "fnFunctionStar",
|
|
4323
4579
|
apply: fn("fnFunctionStar")(function* (sourceFile, position) {
|
|
4324
4580
|
const ts = yield* service(TypeScriptApi);
|
|
4581
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4325
4582
|
const typeParser = yield* service(TypeParser);
|
|
4326
|
-
const maybeInfos =
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
if (isNone2(maybeInfos)) return [];
|
|
4330
|
-
const { accessedObject } = maybeInfos.value;
|
|
4583
|
+
const maybeInfos = tsUtils.parseAccessedExpressionForCompletion(sourceFile, position);
|
|
4584
|
+
if (!maybeInfos) return [];
|
|
4585
|
+
const { accessedObject } = maybeInfos;
|
|
4331
4586
|
const isEffectModule = yield* option(typeParser.importedEffectModule(accessedObject));
|
|
4332
4587
|
if (isNone2(isEffectModule)) return [];
|
|
4333
4588
|
const span = ts.createTextSpan(
|
|
@@ -4335,9 +4590,9 @@ var fnFunctionStar = createCompletion({
|
|
|
4335
4590
|
Math.max(0, position - accessedObject.end - 1)
|
|
4336
4591
|
);
|
|
4337
4592
|
const maybeFnName = pipe(
|
|
4338
|
-
|
|
4593
|
+
tsUtils.getAncestorNodesInRange(sourceFile, tsUtils.toTextRange(accessedObject.pos)),
|
|
4339
4594
|
filter(ts.isVariableDeclaration),
|
|
4340
|
-
|
|
4595
|
+
map4((_) => _.name && ts.isIdentifier(_.name) ? _.name.text : ""),
|
|
4341
4596
|
filter((_) => _.length > 0),
|
|
4342
4597
|
head,
|
|
4343
4598
|
map2((name) => [
|
|
@@ -4372,12 +4627,11 @@ var genFunctionStar = createCompletion({
|
|
|
4372
4627
|
name: "genFunctionStar",
|
|
4373
4628
|
apply: fn("genFunctionStar")(function* (sourceFile, position) {
|
|
4374
4629
|
const ts = yield* service(TypeScriptApi);
|
|
4630
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4375
4631
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
4376
|
-
const maybeInfos =
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
if (isNone2(maybeInfos)) return [];
|
|
4380
|
-
const { accessedObject } = maybeInfos.value;
|
|
4632
|
+
const maybeInfos = tsUtils.parseAccessedExpressionForCompletion(sourceFile, position);
|
|
4633
|
+
if (!maybeInfos) return [];
|
|
4634
|
+
const { accessedObject } = maybeInfos;
|
|
4381
4635
|
const type = typeChecker.getTypeAtLocation(accessedObject);
|
|
4382
4636
|
const genMemberSymbol = type.getProperty("gen");
|
|
4383
4637
|
if (!genMemberSymbol) return [];
|
|
@@ -4402,22 +4656,15 @@ var rpcMakeClasses = createCompletion({
|
|
|
4402
4656
|
name: "rpcMakeClasses",
|
|
4403
4657
|
apply: fn("rpcMakeClasses")(function* (sourceFile, position) {
|
|
4404
4658
|
const ts = yield* service(TypeScriptApi);
|
|
4405
|
-
const
|
|
4406
|
-
|
|
4407
|
-
);
|
|
4408
|
-
|
|
4409
|
-
const
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
"Rpc"
|
|
4415
|
-
)
|
|
4416
|
-
);
|
|
4417
|
-
const rpcIdentifier = match(rpcName, {
|
|
4418
|
-
onNone: () => "Rpc",
|
|
4419
|
-
onSome: (_) => _.text
|
|
4420
|
-
});
|
|
4659
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4660
|
+
const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
|
|
4661
|
+
if (!maybeInfos) return [];
|
|
4662
|
+
const { accessedObject, className, replacementSpan } = maybeInfos;
|
|
4663
|
+
const rpcIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4664
|
+
sourceFile,
|
|
4665
|
+
"@effect/rpc",
|
|
4666
|
+
"Rpc"
|
|
4667
|
+
) || "Rpc";
|
|
4421
4668
|
if (rpcIdentifier !== accessedObject.text) return [];
|
|
4422
4669
|
const name = className.text;
|
|
4423
4670
|
return [{
|
|
@@ -4435,34 +4682,25 @@ var schemaBrand = createCompletion({
|
|
|
4435
4682
|
name: "schemaBrand",
|
|
4436
4683
|
apply: fn("schemaBrand")(function* (sourceFile, position) {
|
|
4437
4684
|
const ts = yield* service(TypeScriptApi);
|
|
4438
|
-
const
|
|
4439
|
-
|
|
4440
|
-
);
|
|
4441
|
-
|
|
4442
|
-
const { accessedObject } = maybeInfos.value;
|
|
4685
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4686
|
+
const maybeInfos = tsUtils.parseAccessedExpressionForCompletion(sourceFile, position);
|
|
4687
|
+
if (!maybeInfos) return [];
|
|
4688
|
+
const { accessedObject } = maybeInfos;
|
|
4443
4689
|
if (!ts.isIdentifier(accessedObject)) return [];
|
|
4444
|
-
const schemaName =
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
"Schema"
|
|
4450
|
-
)
|
|
4451
|
-
),
|
|
4452
|
-
{
|
|
4453
|
-
onNone: () => "Schema",
|
|
4454
|
-
onSome: (_) => _.text
|
|
4455
|
-
}
|
|
4456
|
-
);
|
|
4690
|
+
const schemaName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4691
|
+
sourceFile,
|
|
4692
|
+
"effect",
|
|
4693
|
+
"Schema"
|
|
4694
|
+
) || "Schema";
|
|
4457
4695
|
if (schemaName !== accessedObject.text) return [];
|
|
4458
4696
|
const span = ts.createTextSpan(
|
|
4459
4697
|
accessedObject.end + 1,
|
|
4460
4698
|
Math.max(0, position - accessedObject.end - 1)
|
|
4461
4699
|
);
|
|
4462
4700
|
return pipe(
|
|
4463
|
-
|
|
4701
|
+
tsUtils.getAncestorNodesInRange(sourceFile, tsUtils.toTextRange(accessedObject.pos)),
|
|
4464
4702
|
filter(ts.isVariableDeclaration),
|
|
4465
|
-
|
|
4703
|
+
map4((_) => _.name && ts.isIdentifier(_.name) ? _.name.text : ""),
|
|
4466
4704
|
filter((_) => _.length > 0),
|
|
4467
4705
|
head,
|
|
4468
4706
|
map2((name) => [
|
|
@@ -4489,52 +4727,19 @@ var completions = [
|
|
|
4489
4727
|
fnFunctionStar,
|
|
4490
4728
|
effectDataClasses,
|
|
4491
4729
|
effectDiagnosticsComment,
|
|
4730
|
+
effectCodegensComment,
|
|
4492
4731
|
durationInput,
|
|
4493
4732
|
schemaBrand
|
|
4494
4733
|
];
|
|
4495
4734
|
|
|
4496
|
-
// node_modules/.pnpm/effect@3.16.12/node_modules/effect/dist/esm/internal/encoding/common.js
|
|
4497
|
-
var encoder = /* @__PURE__ */ new TextEncoder();
|
|
4498
|
-
|
|
4499
|
-
// node_modules/.pnpm/effect@3.16.12/node_modules/effect/dist/esm/internal/encoding/base64.js
|
|
4500
|
-
var encode = (bytes) => {
|
|
4501
|
-
const length = bytes.length;
|
|
4502
|
-
let result = "";
|
|
4503
|
-
let i;
|
|
4504
|
-
for (i = 2; i < length; i += 3) {
|
|
4505
|
-
result += base64abc[bytes[i - 2] >> 2];
|
|
4506
|
-
result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4];
|
|
4507
|
-
result += base64abc[(bytes[i - 1] & 15) << 2 | bytes[i] >> 6];
|
|
4508
|
-
result += base64abc[bytes[i] & 63];
|
|
4509
|
-
}
|
|
4510
|
-
if (i === length + 1) {
|
|
4511
|
-
result += base64abc[bytes[i - 2] >> 2];
|
|
4512
|
-
result += base64abc[(bytes[i - 2] & 3) << 4];
|
|
4513
|
-
result += "==";
|
|
4514
|
-
}
|
|
4515
|
-
if (i === length) {
|
|
4516
|
-
result += base64abc[bytes[i - 2] >> 2];
|
|
4517
|
-
result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4];
|
|
4518
|
-
result += base64abc[(bytes[i - 1] & 15) << 2];
|
|
4519
|
-
result += "=";
|
|
4520
|
-
}
|
|
4521
|
-
return result;
|
|
4522
|
-
};
|
|
4523
|
-
var base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"];
|
|
4524
|
-
|
|
4525
|
-
// node_modules/.pnpm/effect@3.16.12/node_modules/effect/dist/esm/internal/encoding/base64Url.js
|
|
4526
|
-
var encode2 = (data) => encode(data).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
4527
|
-
|
|
4528
|
-
// node_modules/.pnpm/effect@3.16.12/node_modules/effect/dist/esm/Encoding.js
|
|
4529
|
-
var encodeBase64Url = (input) => typeof input === "string" ? encode2(encoder.encode(input)) : encode2(input);
|
|
4530
|
-
|
|
4531
4735
|
// src/core/AutoImport.ts
|
|
4532
4736
|
var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
4533
4737
|
const ts = yield* service(TypeScriptApi);
|
|
4738
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4534
4739
|
const program = yield* service(TypeScriptProgram);
|
|
4535
4740
|
const languageServicePluginOptions = yield* service(LanguageServicePluginOptions);
|
|
4536
4741
|
const host = program;
|
|
4537
|
-
const getModuleSpecifier = makeGetModuleSpecifier(
|
|
4742
|
+
const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
|
|
4538
4743
|
function collectSourceFileReexports(sourceFile) {
|
|
4539
4744
|
const namespaceExports = [];
|
|
4540
4745
|
const namedExports = [];
|
|
@@ -4586,9 +4791,9 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
4586
4791
|
);
|
|
4587
4792
|
if (!_entrypoints) return;
|
|
4588
4793
|
if (!isArray(_entrypoints)) return;
|
|
4589
|
-
if (!
|
|
4794
|
+
if (!every(isString)) return;
|
|
4590
4795
|
const entrypoints = _entrypoints.map((_) => String(_));
|
|
4591
|
-
const info = parsePackageContentNameAndVersionFromScope({ packageJsonScope: packageJsonInfo });
|
|
4796
|
+
const info = tsUtils.parsePackageContentNameAndVersionFromScope({ packageJsonScope: packageJsonInfo });
|
|
4592
4797
|
if (!info) return { entrypoints, exportedKeys: [] };
|
|
4593
4798
|
return { entrypoints, exportedKeys: info.exportsKeys };
|
|
4594
4799
|
} catch (_) {
|
|
@@ -4618,7 +4823,7 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
4618
4823
|
const collectImportCache = fn("TypeScriptApi")(
|
|
4619
4824
|
function* (packagePatterns, kind) {
|
|
4620
4825
|
for (const packagePattern of packagePatterns) {
|
|
4621
|
-
const packageNames =
|
|
4826
|
+
const packageNames = tsUtils.resolveModulePattern(fromSourceFile, packagePattern);
|
|
4622
4827
|
for (const packageName of packageNames) {
|
|
4623
4828
|
const packageInfo = getPackageInfo(fromSourceFile.fileName, packageName);
|
|
4624
4829
|
if (!packageInfo) continue;
|
|
@@ -4694,7 +4899,7 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
4694
4899
|
if (!moduleSpecifier) return fileName;
|
|
4695
4900
|
return moduleSpecifier;
|
|
4696
4901
|
};
|
|
4697
|
-
|
|
4902
|
+
const resolve = (exportFileName, exportName) => {
|
|
4698
4903
|
const excludedExports = mapFilenameToExportExcludes.get(exportFileName);
|
|
4699
4904
|
if (excludedExports && excludedExports.includes(exportName)) return;
|
|
4700
4905
|
const mapToNamespace = mapFromBarrelToNamespace.get(exportFileName);
|
|
@@ -4734,10 +4939,167 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
4734
4939
|
};
|
|
4735
4940
|
}
|
|
4736
4941
|
};
|
|
4942
|
+
const sortText = (exportFileName, exportName) => {
|
|
4943
|
+
const excludedExports = mapFilenameToExportExcludes.get(exportFileName);
|
|
4944
|
+
if (excludedExports && excludedExports.includes(exportName)) return;
|
|
4945
|
+
const mapToNamespace = mapFromBarrelToNamespace.get(exportFileName);
|
|
4946
|
+
if (mapToNamespace && exportName in mapToNamespace) return "99";
|
|
4947
|
+
};
|
|
4948
|
+
return { resolve, sortText };
|
|
4949
|
+
});
|
|
4950
|
+
var importProvidersCache = /* @__PURE__ */ new Map();
|
|
4951
|
+
var getOrMakeAutoImportProvider = fn("getOrMakeAutoImportProvider")(function* (sourceFile) {
|
|
4952
|
+
const autoImportProvider = importProvidersCache.get(sourceFile.fileName) || (yield* makeAutoImportProvider(sourceFile));
|
|
4953
|
+
importProvidersCache.set(sourceFile.fileName, autoImportProvider);
|
|
4954
|
+
return autoImportProvider;
|
|
4955
|
+
});
|
|
4956
|
+
var parseImportOnlyChanges = fn("parseImportOnlyChanges")(function* (sourceFile, changes) {
|
|
4957
|
+
const ts = yield* service(TypeScriptApi);
|
|
4958
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4959
|
+
const deletions = [];
|
|
4960
|
+
const imports = [];
|
|
4961
|
+
for (const change of changes) {
|
|
4962
|
+
if (change.newText.length === 0) {
|
|
4963
|
+
deletions.push(change);
|
|
4964
|
+
continue;
|
|
4965
|
+
}
|
|
4966
|
+
if (change.newText.trim().startsWith("import") && change.newText.trim().includes("from")) {
|
|
4967
|
+
try {
|
|
4968
|
+
const parsedImport = ts.createSourceFile("test.ts", change.newText, sourceFile.languageVersion, false);
|
|
4969
|
+
for (const statement of parsedImport.statements) {
|
|
4970
|
+
if (!ts.isImportDeclaration(statement)) return;
|
|
4971
|
+
const moduleSpecifier = statement.moduleSpecifier;
|
|
4972
|
+
if (!ts.isStringLiteral(moduleSpecifier)) return;
|
|
4973
|
+
const moduleName = moduleSpecifier.text;
|
|
4974
|
+
const importClause = statement.importClause;
|
|
4975
|
+
if (!importClause) return;
|
|
4976
|
+
const namedBindings = importClause.namedBindings;
|
|
4977
|
+
if (!namedBindings) return;
|
|
4978
|
+
if (ts.isNamedImports(namedBindings)) {
|
|
4979
|
+
for (const importSpecifier of namedBindings.elements) {
|
|
4980
|
+
if (!ts.isIdentifier(importSpecifier.name)) return;
|
|
4981
|
+
const exportName = importSpecifier.name.text;
|
|
4982
|
+
imports.push({ moduleName, exportName });
|
|
4983
|
+
continue;
|
|
4984
|
+
}
|
|
4985
|
+
} else if (ts.isNamespaceImport(namedBindings)) {
|
|
4986
|
+
imports.push({ moduleName, exportName: void 0 });
|
|
4987
|
+
continue;
|
|
4988
|
+
}
|
|
4989
|
+
}
|
|
4990
|
+
} catch (_) {
|
|
4991
|
+
return;
|
|
4992
|
+
}
|
|
4993
|
+
} else {
|
|
4994
|
+
const ancestorNodes = tsUtils.getAncestorNodesInRange(sourceFile, {
|
|
4995
|
+
pos: change.span.start,
|
|
4996
|
+
end: change.span.start
|
|
4997
|
+
});
|
|
4998
|
+
const importNodes = ancestorNodes.filter((node) => ts.isImportDeclaration(node));
|
|
4999
|
+
const importNode = importNodes[0];
|
|
5000
|
+
if (!importNode) return;
|
|
5001
|
+
const moduleSpecifier = importNode.moduleSpecifier;
|
|
5002
|
+
if (!ts.isStringLiteral(moduleSpecifier)) return;
|
|
5003
|
+
const moduleName = moduleSpecifier.text;
|
|
5004
|
+
const exportName = change.newText.replace(/,/ig, "").trim();
|
|
5005
|
+
if (exportName.length === 0) return;
|
|
5006
|
+
imports.push({ moduleName, exportName });
|
|
5007
|
+
}
|
|
5008
|
+
}
|
|
5009
|
+
return { deletions, imports };
|
|
4737
5010
|
});
|
|
5011
|
+
var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) => {
|
|
5012
|
+
let description = "";
|
|
5013
|
+
switch (effectAutoImport._tag) {
|
|
5014
|
+
case "NamespaceImport": {
|
|
5015
|
+
const importModule = effectAutoImport.moduleName || effectAutoImport.fileName;
|
|
5016
|
+
description = `Import * as ${effectAutoImport.name} from "${importModule}"`;
|
|
5017
|
+
ts.insertImports(
|
|
5018
|
+
changeTracker,
|
|
5019
|
+
sourceFile,
|
|
5020
|
+
ts.factory.createImportDeclaration(
|
|
5021
|
+
void 0,
|
|
5022
|
+
ts.factory.createImportClause(
|
|
5023
|
+
false,
|
|
5024
|
+
void 0,
|
|
5025
|
+
ts.factory.createNamespaceImport(ts.factory.createIdentifier(effectAutoImport.name))
|
|
5026
|
+
),
|
|
5027
|
+
ts.factory.createStringLiteral(importModule)
|
|
5028
|
+
),
|
|
5029
|
+
true,
|
|
5030
|
+
preferences || {}
|
|
5031
|
+
);
|
|
5032
|
+
break;
|
|
5033
|
+
}
|
|
5034
|
+
case "NamedImport": {
|
|
5035
|
+
const importModule = effectAutoImport.moduleName || effectAutoImport.fileName;
|
|
5036
|
+
description = `Import { ${effectAutoImport.name} } from "${importModule}"`;
|
|
5037
|
+
let foundImportDeclaration = false;
|
|
5038
|
+
for (const statement of sourceFile.statements) {
|
|
5039
|
+
if (ts.isImportDeclaration(statement)) {
|
|
5040
|
+
const moduleSpecifier = statement.moduleSpecifier;
|
|
5041
|
+
if (moduleSpecifier && ts.isStringLiteral(moduleSpecifier) && moduleSpecifier.text === importModule) {
|
|
5042
|
+
const importClause = statement.importClause;
|
|
5043
|
+
if (importClause && importClause.namedBindings && ts.isNamedImports(importClause.namedBindings)) {
|
|
5044
|
+
const namedImports = importClause.namedBindings;
|
|
5045
|
+
const existingImportSpecifier = namedImports.elements.find(
|
|
5046
|
+
(element) => element.name.text === effectAutoImport.name
|
|
5047
|
+
);
|
|
5048
|
+
if (existingImportSpecifier) {
|
|
5049
|
+
foundImportDeclaration = true;
|
|
5050
|
+
break;
|
|
5051
|
+
}
|
|
5052
|
+
changeTracker.replaceNode(
|
|
5053
|
+
sourceFile,
|
|
5054
|
+
namedImports,
|
|
5055
|
+
ts.factory.createNamedImports(
|
|
5056
|
+
namedImports.elements.concat([
|
|
5057
|
+
ts.factory.createImportSpecifier(
|
|
5058
|
+
false,
|
|
5059
|
+
void 0,
|
|
5060
|
+
ts.factory.createIdentifier(effectAutoImport.name)
|
|
5061
|
+
)
|
|
5062
|
+
])
|
|
5063
|
+
)
|
|
5064
|
+
);
|
|
5065
|
+
foundImportDeclaration = true;
|
|
5066
|
+
break;
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
}
|
|
5070
|
+
}
|
|
5071
|
+
if (!foundImportDeclaration) {
|
|
5072
|
+
ts.insertImports(
|
|
5073
|
+
changeTracker,
|
|
5074
|
+
sourceFile,
|
|
5075
|
+
ts.factory.createImportDeclaration(
|
|
5076
|
+
void 0,
|
|
5077
|
+
ts.factory.createImportClause(
|
|
5078
|
+
false,
|
|
5079
|
+
void 0,
|
|
5080
|
+
ts.factory.createNamedImports(
|
|
5081
|
+
[
|
|
5082
|
+
ts.factory.createImportSpecifier(
|
|
5083
|
+
false,
|
|
5084
|
+
void 0,
|
|
5085
|
+
ts.factory.createIdentifier(effectAutoImport.name)
|
|
5086
|
+
)
|
|
5087
|
+
]
|
|
5088
|
+
)
|
|
5089
|
+
),
|
|
5090
|
+
ts.factory.createStringLiteral(importModule)
|
|
5091
|
+
),
|
|
5092
|
+
true,
|
|
5093
|
+
preferences || {}
|
|
5094
|
+
);
|
|
5095
|
+
}
|
|
5096
|
+
break;
|
|
5097
|
+
}
|
|
5098
|
+
}
|
|
5099
|
+
return { description };
|
|
5100
|
+
};
|
|
4738
5101
|
|
|
4739
5102
|
// src/completions/middlewareAutoImports.ts
|
|
4740
|
-
var importProvidersCache = /* @__PURE__ */ new Map();
|
|
4741
5103
|
var appendEffectCompletionEntryData = fn("appendEffectCompletionEntryData")(
|
|
4742
5104
|
function* (_sourceFile, applicableCompletions) {
|
|
4743
5105
|
const languageServicePluginOptions = yield* service(LanguageServicePluginOptions);
|
|
@@ -4761,7 +5123,6 @@ var appendEffectCompletionEntryData = fn("appendEffectCompletionEntryData")(
|
|
|
4761
5123
|
);
|
|
4762
5124
|
var isAutoImportOnlyCodeActions = fn("isAutoImportOnlyCodeActions")(
|
|
4763
5125
|
function* (sourceFile, codeActions, exportName) {
|
|
4764
|
-
const ts = yield* service(TypeScriptApi);
|
|
4765
5126
|
if (!codeActions) return;
|
|
4766
5127
|
if (codeActions.length !== 1) return;
|
|
4767
5128
|
const action = codeActions[0];
|
|
@@ -4770,25 +5131,12 @@ var isAutoImportOnlyCodeActions = fn("isAutoImportOnlyCodeActions")(
|
|
|
4770
5131
|
const fileTextChanges = action.changes[0];
|
|
4771
5132
|
if (fileTextChanges.fileName !== sourceFile.fileName) return;
|
|
4772
5133
|
const textChanges = fileTextChanges.textChanges;
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
if (
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
}
|
|
4780
|
-
if (change.newText.indexOf(exportName) > -1) {
|
|
4781
|
-
const ancestorNodes = yield* getAncestorNodesInRange(sourceFile, {
|
|
4782
|
-
pos: change.span.start,
|
|
4783
|
-
end: change.span.start
|
|
4784
|
-
});
|
|
4785
|
-
const importNodes = ancestorNodes.filter((node) => ts.isImportDeclaration(node));
|
|
4786
|
-
if (importNodes.length > 0) {
|
|
4787
|
-
return {
|
|
4788
|
-
type: "update"
|
|
4789
|
-
};
|
|
4790
|
-
}
|
|
4791
|
-
}
|
|
5134
|
+
const parsedImportChanges = yield* parseImportOnlyChanges(sourceFile, textChanges);
|
|
5135
|
+
if (!parsedImportChanges) return;
|
|
5136
|
+
if (parsedImportChanges.deletions.length !== 0) return;
|
|
5137
|
+
if (parsedImportChanges.imports.length !== 1) return;
|
|
5138
|
+
if (parsedImportChanges.imports[0].exportName !== exportName) return;
|
|
5139
|
+
return parsedImportChanges.imports[0];
|
|
4792
5140
|
}
|
|
4793
5141
|
);
|
|
4794
5142
|
var addImportCodeAction = fn("getImportFromNamespaceCodeActions")(function* (formatOptions, preferences, languageServiceHost, sourceFile, effectReplaceSpan, effectAutoImport) {
|
|
@@ -4812,92 +5160,13 @@ var addImportCodeAction = fn("getImportFromNamespaceCodeActions")(function* (for
|
|
|
4812
5160
|
effectAutoImport.introducedPrefix + "."
|
|
4813
5161
|
);
|
|
4814
5162
|
}
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
ts.factory.createImportDeclaration(
|
|
4823
|
-
void 0,
|
|
4824
|
-
ts.factory.createImportClause(
|
|
4825
|
-
false,
|
|
4826
|
-
void 0,
|
|
4827
|
-
ts.factory.createNamespaceImport(ts.factory.createIdentifier(effectAutoImport.name))
|
|
4828
|
-
),
|
|
4829
|
-
ts.factory.createStringLiteral(importModule)
|
|
4830
|
-
),
|
|
4831
|
-
true,
|
|
4832
|
-
preferences || {}
|
|
4833
|
-
);
|
|
4834
|
-
break;
|
|
4835
|
-
}
|
|
4836
|
-
case "NamedImport": {
|
|
4837
|
-
const importModule = effectAutoImport.moduleName || effectAutoImport.fileName;
|
|
4838
|
-
description = `Import { ${effectAutoImport.name} } from "${importModule}"`;
|
|
4839
|
-
let foundImportDeclaration = false;
|
|
4840
|
-
for (const statement of sourceFile.statements) {
|
|
4841
|
-
if (ts.isImportDeclaration(statement)) {
|
|
4842
|
-
const moduleSpecifier = statement.moduleSpecifier;
|
|
4843
|
-
if (moduleSpecifier && ts.isStringLiteral(moduleSpecifier) && moduleSpecifier.text === importModule) {
|
|
4844
|
-
const importClause = statement.importClause;
|
|
4845
|
-
if (importClause && importClause.namedBindings && ts.isNamedImports(importClause.namedBindings)) {
|
|
4846
|
-
const namedImports = importClause.namedBindings;
|
|
4847
|
-
const existingImportSpecifier = namedImports.elements.find(
|
|
4848
|
-
(element) => element.name.text === effectAutoImport.name
|
|
4849
|
-
);
|
|
4850
|
-
if (existingImportSpecifier) {
|
|
4851
|
-
foundImportDeclaration = true;
|
|
4852
|
-
break;
|
|
4853
|
-
}
|
|
4854
|
-
changeTracker.replaceNode(
|
|
4855
|
-
sourceFile,
|
|
4856
|
-
namedImports,
|
|
4857
|
-
ts.factory.createNamedImports(
|
|
4858
|
-
namedImports.elements.concat([
|
|
4859
|
-
ts.factory.createImportSpecifier(
|
|
4860
|
-
false,
|
|
4861
|
-
void 0,
|
|
4862
|
-
ts.factory.createIdentifier(effectAutoImport.name)
|
|
4863
|
-
)
|
|
4864
|
-
])
|
|
4865
|
-
)
|
|
4866
|
-
);
|
|
4867
|
-
foundImportDeclaration = true;
|
|
4868
|
-
break;
|
|
4869
|
-
}
|
|
4870
|
-
}
|
|
4871
|
-
}
|
|
4872
|
-
}
|
|
4873
|
-
if (!foundImportDeclaration) {
|
|
4874
|
-
ts.insertImports(
|
|
4875
|
-
changeTracker,
|
|
4876
|
-
sourceFile,
|
|
4877
|
-
ts.factory.createImportDeclaration(
|
|
4878
|
-
void 0,
|
|
4879
|
-
ts.factory.createImportClause(
|
|
4880
|
-
false,
|
|
4881
|
-
void 0,
|
|
4882
|
-
ts.factory.createNamedImports(
|
|
4883
|
-
[
|
|
4884
|
-
ts.factory.createImportSpecifier(
|
|
4885
|
-
false,
|
|
4886
|
-
void 0,
|
|
4887
|
-
ts.factory.createIdentifier(effectAutoImport.name)
|
|
4888
|
-
)
|
|
4889
|
-
]
|
|
4890
|
-
)
|
|
4891
|
-
),
|
|
4892
|
-
ts.factory.createStringLiteral(importModule)
|
|
4893
|
-
),
|
|
4894
|
-
true,
|
|
4895
|
-
preferences || {}
|
|
4896
|
-
);
|
|
4897
|
-
}
|
|
4898
|
-
break;
|
|
4899
|
-
}
|
|
4900
|
-
}
|
|
5163
|
+
description = addImport(
|
|
5164
|
+
ts,
|
|
5165
|
+
sourceFile,
|
|
5166
|
+
changeTracker,
|
|
5167
|
+
preferences,
|
|
5168
|
+
effectAutoImport
|
|
5169
|
+
).description;
|
|
4901
5170
|
}
|
|
4902
5171
|
);
|
|
4903
5172
|
return [
|
|
@@ -4925,9 +5194,8 @@ var postprocessCompletionEntryDetails = fn("postprocessCompletionEntryDetails")(
|
|
|
4925
5194
|
exportName
|
|
4926
5195
|
);
|
|
4927
5196
|
if (!result) return applicableCompletionEntryDetails;
|
|
4928
|
-
const
|
|
4929
|
-
|
|
4930
|
-
const effectAutoImport = packagesMetadata(fileName, exportName);
|
|
5197
|
+
const autoImportProvider = yield* getOrMakeAutoImportProvider(sourceFile);
|
|
5198
|
+
const effectAutoImport = autoImportProvider.resolve(fileName, exportName);
|
|
4931
5199
|
if (!effectAutoImport) return applicableCompletionEntryDetails;
|
|
4932
5200
|
const codeActions = yield* addImportCodeAction(
|
|
4933
5201
|
formatOptions,
|
|
@@ -4944,17 +5212,86 @@ var postprocessCompletionEntryDetails = fn("postprocessCompletionEntryDetails")(
|
|
|
4944
5212
|
}
|
|
4945
5213
|
);
|
|
4946
5214
|
|
|
5215
|
+
// src/diagnostics/middlewareAutoImportQuickfixes.ts
|
|
5216
|
+
var middlewareAutoImportQuickfixes = fn("middlewareAutoImportQuickfixes")(function* (sourceFile, languageServiceHost, formatOptions, preferences, codeFixes) {
|
|
5217
|
+
const ts = yield* service(TypeScriptApi);
|
|
5218
|
+
const program = yield* service(TypeScriptProgram);
|
|
5219
|
+
const autoImportProvider = yield* getOrMakeAutoImportProvider(sourceFile);
|
|
5220
|
+
const changedCodeFixes = [];
|
|
5221
|
+
const createImportAllChanges = (imports) => gen(function* () {
|
|
5222
|
+
const newImports = [];
|
|
5223
|
+
for (const importToAdd of imports) {
|
|
5224
|
+
if (!importToAdd.exportName) return;
|
|
5225
|
+
const fileName = ts.resolveModuleName(
|
|
5226
|
+
importToAdd.moduleName,
|
|
5227
|
+
sourceFile.fileName,
|
|
5228
|
+
program.getCompilerOptions(),
|
|
5229
|
+
program
|
|
5230
|
+
);
|
|
5231
|
+
if (!fileName.resolvedModule) return;
|
|
5232
|
+
const importKind = autoImportProvider.resolve(fileName.resolvedModule.resolvedFileName, importToAdd.exportName);
|
|
5233
|
+
if (!importKind) return;
|
|
5234
|
+
if (importKind.introducedPrefix) return;
|
|
5235
|
+
newImports.push(importKind);
|
|
5236
|
+
}
|
|
5237
|
+
const formatContext = ts.formatting.getFormatContext(
|
|
5238
|
+
formatOptions,
|
|
5239
|
+
languageServiceHost
|
|
5240
|
+
);
|
|
5241
|
+
const edits = ts.textChanges.ChangeTracker.with(
|
|
5242
|
+
{
|
|
5243
|
+
formatContext,
|
|
5244
|
+
host: languageServiceHost,
|
|
5245
|
+
preferences: preferences || {}
|
|
5246
|
+
},
|
|
5247
|
+
(changeTracker) => newImports.forEach((_) => addImport(ts, sourceFile, changeTracker, preferences, _))
|
|
5248
|
+
);
|
|
5249
|
+
return edits;
|
|
5250
|
+
});
|
|
5251
|
+
for (const codeFix of codeFixes) {
|
|
5252
|
+
const textFileChanges = codeFix.changes;
|
|
5253
|
+
if (textFileChanges.length !== 1) {
|
|
5254
|
+
changedCodeFixes.push(codeFix);
|
|
5255
|
+
continue;
|
|
5256
|
+
}
|
|
5257
|
+
if (textFileChanges[0].fileName !== sourceFile.fileName) {
|
|
5258
|
+
changedCodeFixes.push(codeFix);
|
|
5259
|
+
continue;
|
|
5260
|
+
}
|
|
5261
|
+
const parsedChanges = yield* parseImportOnlyChanges(sourceFile, textFileChanges[0].textChanges);
|
|
5262
|
+
if (!parsedChanges) {
|
|
5263
|
+
changedCodeFixes.push(codeFix);
|
|
5264
|
+
continue;
|
|
5265
|
+
}
|
|
5266
|
+
if (parsedChanges.deletions.length !== 0) {
|
|
5267
|
+
changedCodeFixes.push(codeFix);
|
|
5268
|
+
continue;
|
|
5269
|
+
}
|
|
5270
|
+
const changes = yield* pipe(
|
|
5271
|
+
createImportAllChanges(parsedChanges.imports),
|
|
5272
|
+
orElse2(() => succeed(codeFix.changes))
|
|
5273
|
+
);
|
|
5274
|
+
if (changes) {
|
|
5275
|
+
changedCodeFixes.push({ ...codeFix, changes });
|
|
5276
|
+
} else {
|
|
5277
|
+
changedCodeFixes.push(codeFix);
|
|
5278
|
+
}
|
|
5279
|
+
}
|
|
5280
|
+
return changedCodeFixes;
|
|
5281
|
+
});
|
|
5282
|
+
|
|
4947
5283
|
// src/goto/effectRpcDefinition.ts
|
|
4948
5284
|
function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
4949
5285
|
return gen(function* () {
|
|
4950
5286
|
const program = yield* service(TypeScriptProgram);
|
|
4951
5287
|
const ts = yield* service(TypeScriptApi);
|
|
5288
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4952
5289
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
4953
|
-
const textRange = toTextRange(position);
|
|
5290
|
+
const textRange = tsUtils.toTextRange(position);
|
|
4954
5291
|
function isSymbolFromEffectRpcModule(symbol3) {
|
|
4955
5292
|
if (symbol3.valueDeclaration) {
|
|
4956
5293
|
const sourceFile2 = symbol3.valueDeclaration.getSourceFile();
|
|
4957
|
-
const packageInfo = parsePackageContentNameAndVersionFromScope(sourceFile2);
|
|
5294
|
+
const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(sourceFile2);
|
|
4958
5295
|
if (packageInfo && packageInfo.name === "@effect/rpc") {
|
|
4959
5296
|
const fileSymbol = typeChecker.getSymbolAtLocation(sourceFile2);
|
|
4960
5297
|
return fileSymbol && fileSymbol.exports && fileSymbol.exports.has("isRpc") && fileSymbol.exports.has("make") && fileSymbol.exports.has("fromTaggedRequest");
|
|
@@ -4965,7 +5302,7 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
4965
5302
|
function isSymbolFromEffectRpcClientModule(symbol3) {
|
|
4966
5303
|
if (symbol3.valueDeclaration) {
|
|
4967
5304
|
const sourceFile2 = symbol3.valueDeclaration.getSourceFile();
|
|
4968
|
-
const packageInfo = parsePackageContentNameAndVersionFromScope(sourceFile2);
|
|
5305
|
+
const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(sourceFile2);
|
|
4969
5306
|
if (packageInfo && packageInfo.name === "@effect/rpc") {
|
|
4970
5307
|
const fileSymbol = typeChecker.getSymbolAtLocation(sourceFile2);
|
|
4971
5308
|
return fileSymbol && fileSymbol.exports && fileSymbol.exports.has("RpcClient") && fileSymbol.exports.has("make");
|
|
@@ -4975,8 +5312,8 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
4975
5312
|
}
|
|
4976
5313
|
let rpcName = null;
|
|
4977
5314
|
let callNode = null;
|
|
4978
|
-
for (const node of
|
|
4979
|
-
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && isNodeInRange(textRange)(node.name)) {
|
|
5315
|
+
for (const node of tsUtils.getAncestorNodesInRange(sourceFile, textRange)) {
|
|
5316
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && tsUtils.isNodeInRange(textRange)(node.name)) {
|
|
4980
5317
|
const type = typeChecker.getTypeAtLocation(node);
|
|
4981
5318
|
for (const callSig of type.getCallSignatures()) {
|
|
4982
5319
|
if (callSig.parameters.length >= 2 && isSymbolFromEffectRpcClientModule(callSig.parameters[1])) {
|
|
@@ -5128,7 +5465,7 @@ function effectTypeArgs(sourceFile, position, quickInfo2) {
|
|
|
5128
5465
|
type,
|
|
5129
5466
|
atLocation
|
|
5130
5467
|
),
|
|
5131
|
-
|
|
5468
|
+
map3((_) => makeSymbolDisplayParts("Effect Type Parameters", _.A, _.E, _.R)),
|
|
5132
5469
|
orElse2(() => {
|
|
5133
5470
|
const callSignatues = type.getCallSignatures();
|
|
5134
5471
|
if (callSignatues.length !== 1) return succeed([]);
|
|
@@ -5138,7 +5475,7 @@ function effectTypeArgs(sourceFile, position, quickInfo2) {
|
|
|
5138
5475
|
returnType,
|
|
5139
5476
|
atLocation
|
|
5140
5477
|
),
|
|
5141
|
-
|
|
5478
|
+
map3((_) => makeSymbolDisplayParts("Returned Effect Type Parameters", _.A, _.E, _.R))
|
|
5142
5479
|
);
|
|
5143
5480
|
})
|
|
5144
5481
|
);
|
|
@@ -5167,6 +5504,41 @@ function effectTypeArgs(sourceFile, position, quickInfo2) {
|
|
|
5167
5504
|
);
|
|
5168
5505
|
}
|
|
5169
5506
|
|
|
5507
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/encoding/common.js
|
|
5508
|
+
var encoder = /* @__PURE__ */ new TextEncoder();
|
|
5509
|
+
|
|
5510
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/encoding/base64.js
|
|
5511
|
+
var encode = (bytes) => {
|
|
5512
|
+
const length = bytes.length;
|
|
5513
|
+
let result = "";
|
|
5514
|
+
let i;
|
|
5515
|
+
for (i = 2; i < length; i += 3) {
|
|
5516
|
+
result += base64abc[bytes[i - 2] >> 2];
|
|
5517
|
+
result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4];
|
|
5518
|
+
result += base64abc[(bytes[i - 1] & 15) << 2 | bytes[i] >> 6];
|
|
5519
|
+
result += base64abc[bytes[i] & 63];
|
|
5520
|
+
}
|
|
5521
|
+
if (i === length + 1) {
|
|
5522
|
+
result += base64abc[bytes[i - 2] >> 2];
|
|
5523
|
+
result += base64abc[(bytes[i - 2] & 3) << 4];
|
|
5524
|
+
result += "==";
|
|
5525
|
+
}
|
|
5526
|
+
if (i === length) {
|
|
5527
|
+
result += base64abc[bytes[i - 2] >> 2];
|
|
5528
|
+
result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4];
|
|
5529
|
+
result += base64abc[(bytes[i - 1] & 15) << 2];
|
|
5530
|
+
result += "=";
|
|
5531
|
+
}
|
|
5532
|
+
return result;
|
|
5533
|
+
};
|
|
5534
|
+
var base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"];
|
|
5535
|
+
|
|
5536
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/encoding/base64Url.js
|
|
5537
|
+
var encode2 = (data) => encode(data).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
5538
|
+
|
|
5539
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Encoding.js
|
|
5540
|
+
var encodeBase64Url = (input) => typeof input === "string" ? encode2(encoder.encode(input)) : encode2(input);
|
|
5541
|
+
|
|
5170
5542
|
// node_modules/.pnpm/pako@2.1.0/node_modules/pako/dist/pako.esm.mjs
|
|
5171
5543
|
var Z_FIXED$1 = 4;
|
|
5172
5544
|
var Z_BINARY = 0;
|
|
@@ -6036,7 +6408,7 @@ var read_buf = (strm, buf, start, size) => {
|
|
|
6036
6408
|
var longest_match = (s, cur_match) => {
|
|
6037
6409
|
let chain_length = s.max_chain_length;
|
|
6038
6410
|
let scan = s.strstart;
|
|
6039
|
-
let
|
|
6411
|
+
let match2;
|
|
6040
6412
|
let len;
|
|
6041
6413
|
let best_len = s.prev_length;
|
|
6042
6414
|
let nice_match = s.nice_match;
|
|
@@ -6054,14 +6426,14 @@ var longest_match = (s, cur_match) => {
|
|
|
6054
6426
|
nice_match = s.lookahead;
|
|
6055
6427
|
}
|
|
6056
6428
|
do {
|
|
6057
|
-
|
|
6058
|
-
if (_win[
|
|
6429
|
+
match2 = cur_match;
|
|
6430
|
+
if (_win[match2 + best_len] !== scan_end || _win[match2 + best_len - 1] !== scan_end1 || _win[match2] !== _win[scan] || _win[++match2] !== _win[scan + 1]) {
|
|
6059
6431
|
continue;
|
|
6060
6432
|
}
|
|
6061
6433
|
scan += 2;
|
|
6062
|
-
|
|
6434
|
+
match2++;
|
|
6063
6435
|
do {
|
|
6064
|
-
} while (_win[++scan] === _win[++
|
|
6436
|
+
} while (_win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && scan < strend);
|
|
6065
6437
|
len = MAX_MATCH - (strend - scan);
|
|
6066
6438
|
scan = strend - MAX_MATCH;
|
|
6067
6439
|
if (len > best_len) {
|
|
@@ -7762,7 +8134,7 @@ var inflate_table = (type, lens, lens_index, codes, table, table_index, work, op
|
|
|
7762
8134
|
let mask;
|
|
7763
8135
|
let next;
|
|
7764
8136
|
let base = null;
|
|
7765
|
-
let
|
|
8137
|
+
let match2;
|
|
7766
8138
|
const count = new Uint16Array(MAXBITS + 1);
|
|
7767
8139
|
const offs = new Uint16Array(MAXBITS + 1);
|
|
7768
8140
|
let extra = null;
|
|
@@ -7818,15 +8190,15 @@ var inflate_table = (type, lens, lens_index, codes, table, table_index, work, op
|
|
|
7818
8190
|
}
|
|
7819
8191
|
if (type === CODES$1) {
|
|
7820
8192
|
base = extra = work;
|
|
7821
|
-
|
|
8193
|
+
match2 = 20;
|
|
7822
8194
|
} else if (type === LENS$1) {
|
|
7823
8195
|
base = lbase;
|
|
7824
8196
|
extra = lext;
|
|
7825
|
-
|
|
8197
|
+
match2 = 257;
|
|
7826
8198
|
} else {
|
|
7827
8199
|
base = dbase;
|
|
7828
8200
|
extra = dext;
|
|
7829
|
-
|
|
8201
|
+
match2 = 0;
|
|
7830
8202
|
}
|
|
7831
8203
|
huff = 0;
|
|
7832
8204
|
sym = 0;
|
|
@@ -7842,12 +8214,12 @@ var inflate_table = (type, lens, lens_index, codes, table, table_index, work, op
|
|
|
7842
8214
|
}
|
|
7843
8215
|
for (; ; ) {
|
|
7844
8216
|
here_bits = len - drop;
|
|
7845
|
-
if (work[sym] + 1 <
|
|
8217
|
+
if (work[sym] + 1 < match2) {
|
|
7846
8218
|
here_op = 0;
|
|
7847
8219
|
here_val = work[sym];
|
|
7848
|
-
} else if (work[sym] >=
|
|
7849
|
-
here_op = extra[work[sym] -
|
|
7850
|
-
here_val = base[work[sym] -
|
|
8220
|
+
} else if (work[sym] >= match2) {
|
|
8221
|
+
here_op = extra[work[sym] - match2];
|
|
8222
|
+
here_val = base[work[sym] - match2];
|
|
7851
8223
|
} else {
|
|
7852
8224
|
here_op = 32 + 64;
|
|
7853
8225
|
here_val = 0;
|
|
@@ -9387,7 +9759,7 @@ function processLayerGraphNode(ctx, node, pipedInGraphNode) {
|
|
|
9387
9759
|
const maybeLayer = yield* option(typeParser.layerType(type, node));
|
|
9388
9760
|
if (isSome2(maybeLayer)) {
|
|
9389
9761
|
const argNodes = yield* option(
|
|
9390
|
-
|
|
9762
|
+
all(...node.arguments.map((_) => processLayerGraphNode(ctx, _, void 0)))
|
|
9391
9763
|
);
|
|
9392
9764
|
if (isSome2(argNodes) && argNodes.value.length === node.arguments.length) {
|
|
9393
9765
|
const { allIndexes: outTypes } = yield* appendToUniqueTypesMap(
|
|
@@ -9431,7 +9803,7 @@ function processLayerGraphNode(ctx, node, pipedInGraphNode) {
|
|
|
9431
9803
|
);
|
|
9432
9804
|
if (ts.isCallExpression(node)) {
|
|
9433
9805
|
const argNodes = yield* option(
|
|
9434
|
-
|
|
9806
|
+
all(...node.arguments.map((_) => processLayerGraphNode(ctx, _, void 0)))
|
|
9435
9807
|
);
|
|
9436
9808
|
if (isSome2(argNodes) && argNodes.value.length === node.arguments.length) {
|
|
9437
9809
|
return new GraphNodeCompoundTransform(
|
|
@@ -9561,7 +9933,7 @@ function processNodeMermaid(graph, ctx, ctxL) {
|
|
|
9561
9933
|
return subgraphDefs;
|
|
9562
9934
|
}
|
|
9563
9935
|
case "GraphNodeCompoundTransform": {
|
|
9564
|
-
const childs = flatten(yield*
|
|
9936
|
+
const childs = flatten(yield* all(...graph.args.map((_) => processNodeMermaid(_, ctx, ctxL))));
|
|
9565
9937
|
let currentEdges = [];
|
|
9566
9938
|
const connectedNodes = /* @__PURE__ */ new Set();
|
|
9567
9939
|
for (const requiredServiceKey of graph.rin) {
|
|
@@ -9610,13 +9982,14 @@ function layerInfo(sourceFile, position, quickInfo2) {
|
|
|
9610
9982
|
return pipe(
|
|
9611
9983
|
gen(function* () {
|
|
9612
9984
|
const ts = yield* service(TypeScriptApi);
|
|
9985
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
9613
9986
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
9614
9987
|
const typeParser = yield* service(TypeParser);
|
|
9615
|
-
const range = toTextRange(position);
|
|
9988
|
+
const range = tsUtils.toTextRange(position);
|
|
9616
9989
|
const maybeNode = pipe(
|
|
9617
|
-
|
|
9990
|
+
tsUtils.getAncestorNodesInRange(sourceFile, range),
|
|
9618
9991
|
filter((_) => ts.isVariableDeclaration(_) || ts.isPropertyDeclaration(_)),
|
|
9619
|
-
filter((_) => isNodeInRange(range)(_.name)),
|
|
9992
|
+
filter((_) => tsUtils.isNodeInRange(range)(_.name)),
|
|
9620
9993
|
head
|
|
9621
9994
|
);
|
|
9622
9995
|
if (isNone2(maybeNode)) return quickInfo2;
|
|
@@ -9633,7 +10006,7 @@ function layerInfo(sourceFile, position, quickInfo2) {
|
|
|
9633
10006
|
};
|
|
9634
10007
|
const layerInfoDisplayParts = yield* pipe(
|
|
9635
10008
|
processLayerGraphNode(graphCtx, layerNode, void 0),
|
|
9636
|
-
|
|
10009
|
+
flatMap(
|
|
9637
10010
|
(rootNode) => gen(function* () {
|
|
9638
10011
|
yield* succeed(void 0);
|
|
9639
10012
|
const lines = [];
|
|
@@ -9726,10 +10099,10 @@ var asyncAwaitToGen = createRefactor({
|
|
|
9726
10099
|
description: "Convert to Effect.gen",
|
|
9727
10100
|
apply: fn("asyncAwaitToGen.apply")(function* (sourceFile, textRange) {
|
|
9728
10101
|
const ts = yield* service(TypeScriptApi);
|
|
10102
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
9729
10103
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
9730
|
-
const typeParser = yield* service(TypeParser);
|
|
9731
10104
|
const maybeNode = pipe(
|
|
9732
|
-
|
|
10105
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
9733
10106
|
filter(
|
|
9734
10107
|
(node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
|
|
9735
10108
|
),
|
|
@@ -9745,23 +10118,12 @@ var asyncAwaitToGen = createRefactor({
|
|
|
9745
10118
|
apply: pipe(
|
|
9746
10119
|
gen(function* () {
|
|
9747
10120
|
const changeTracker = yield* service(ChangeTracker);
|
|
9748
|
-
const effectModuleIdentifierName =
|
|
9749
|
-
|
|
9750
|
-
|
|
9751
|
-
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
option,
|
|
9755
|
-
map4(isSome2)
|
|
9756
|
-
)
|
|
9757
|
-
)
|
|
9758
|
-
),
|
|
9759
|
-
{
|
|
9760
|
-
onNone: () => "Effect",
|
|
9761
|
-
onSome: (node2) => node2.text
|
|
9762
|
-
}
|
|
9763
|
-
);
|
|
9764
|
-
const newDeclaration = yield* transformAsyncAwaitToEffectGen(
|
|
10121
|
+
const effectModuleIdentifierName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
10122
|
+
sourceFile,
|
|
10123
|
+
"effect",
|
|
10124
|
+
"Effect"
|
|
10125
|
+
) || "Effect";
|
|
10126
|
+
const newDeclaration = tsUtils.transformAsyncAwaitToEffectGen(
|
|
9765
10127
|
node,
|
|
9766
10128
|
effectModuleIdentifierName,
|
|
9767
10129
|
(expression) => ts.factory.createCallExpression(
|
|
@@ -9797,10 +10159,10 @@ var asyncAwaitToGenTryPromise = createRefactor({
|
|
|
9797
10159
|
description: "Convert to Effect.gen with failures",
|
|
9798
10160
|
apply: fn("asyncAwaitToGenTryPromise.apply")(function* (sourceFile, textRange) {
|
|
9799
10161
|
const ts = yield* service(TypeScriptApi);
|
|
10162
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
9800
10163
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
9801
|
-
const typeParser = yield* service(TypeParser);
|
|
9802
10164
|
const maybeNode = pipe(
|
|
9803
|
-
|
|
10165
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
9804
10166
|
filter(
|
|
9805
10167
|
(node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
|
|
9806
10168
|
),
|
|
@@ -9816,22 +10178,11 @@ var asyncAwaitToGenTryPromise = createRefactor({
|
|
|
9816
10178
|
apply: pipe(
|
|
9817
10179
|
gen(function* () {
|
|
9818
10180
|
const changeTracker = yield* service(ChangeTracker);
|
|
9819
|
-
const effectModuleIdentifierName =
|
|
9820
|
-
|
|
9821
|
-
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
typeParser.importedEffectModule(node2),
|
|
9825
|
-
option,
|
|
9826
|
-
map4(isSome2)
|
|
9827
|
-
)
|
|
9828
|
-
)
|
|
9829
|
-
),
|
|
9830
|
-
{
|
|
9831
|
-
onNone: () => "Effect",
|
|
9832
|
-
onSome: (node2) => node2.text
|
|
9833
|
-
}
|
|
9834
|
-
);
|
|
10181
|
+
const effectModuleIdentifierName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
10182
|
+
sourceFile,
|
|
10183
|
+
"effect",
|
|
10184
|
+
"Effect"
|
|
10185
|
+
) || "Effect";
|
|
9835
10186
|
let errorCount = 0;
|
|
9836
10187
|
function createErrorADT() {
|
|
9837
10188
|
errorCount++;
|
|
@@ -9846,7 +10197,7 @@ var asyncAwaitToGenTryPromise = createRefactor({
|
|
|
9846
10197
|
ts.factory.createShorthandPropertyAssignment("error")
|
|
9847
10198
|
]);
|
|
9848
10199
|
}
|
|
9849
|
-
const newDeclaration =
|
|
10200
|
+
const newDeclaration = tsUtils.transformAsyncAwaitToEffectGen(
|
|
9850
10201
|
node,
|
|
9851
10202
|
effectModuleIdentifierName,
|
|
9852
10203
|
(expression) => ts.factory.createCallExpression(
|
|
@@ -9898,6 +10249,7 @@ var effectGenToFn = createRefactor({
|
|
|
9898
10249
|
description: "Convert to Effect.fn",
|
|
9899
10250
|
apply: fn("effectGenToFn.apply")(function* (sourceFile, textRange) {
|
|
9900
10251
|
const ts = yield* service(TypeScriptApi);
|
|
10252
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
9901
10253
|
const typeParser = yield* service(TypeParser);
|
|
9902
10254
|
const parseEffectGenNode = fn("asyncAwaitToGen.apply")(function* (node) {
|
|
9903
10255
|
const effectGen = yield* typeParser.effectGen(node);
|
|
@@ -9934,8 +10286,8 @@ var effectGenToFn = createRefactor({
|
|
|
9934
10286
|
return yield* fail(new RefactorNotApplicableError());
|
|
9935
10287
|
});
|
|
9936
10288
|
const maybeNode = yield* pipe(
|
|
9937
|
-
|
|
9938
|
-
|
|
10289
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10290
|
+
map4(parseEffectGenNode),
|
|
9939
10291
|
firstSuccessOf,
|
|
9940
10292
|
option
|
|
9941
10293
|
);
|
|
@@ -9974,7 +10326,7 @@ var effectGenToFn = createRefactor({
|
|
|
9974
10326
|
changeTracker.replaceNode(
|
|
9975
10327
|
sourceFile,
|
|
9976
10328
|
nodeToReplace,
|
|
9977
|
-
|
|
10329
|
+
tsUtils.tryPreserveDeclarationSemantics(nodeToReplace, effectFnCallWithGenerator)
|
|
9978
10330
|
);
|
|
9979
10331
|
}),
|
|
9980
10332
|
provideService(TypeScriptApi, ts)
|
|
@@ -9989,11 +10341,12 @@ var functionToArrow = createRefactor({
|
|
|
9989
10341
|
description: "Convert to arrow",
|
|
9990
10342
|
apply: fn("functionToArrow.apply")(function* (sourceFile, textRange) {
|
|
9991
10343
|
const ts = yield* service(TypeScriptApi);
|
|
10344
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
9992
10345
|
const maybeNode = pipe(
|
|
9993
|
-
|
|
10346
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
9994
10347
|
filter((_) => ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_)),
|
|
9995
10348
|
filter((_) => !!_.body),
|
|
9996
|
-
filter((_) => !!_.name && isNodeInRange(textRange)(_.name)),
|
|
10349
|
+
filter((_) => !!_.name && tsUtils.isNodeInRange(textRange)(_.name)),
|
|
9997
10350
|
head
|
|
9998
10351
|
);
|
|
9999
10352
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -10024,7 +10377,7 @@ var functionToArrow = createRefactor({
|
|
|
10024
10377
|
ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
|
10025
10378
|
newBody
|
|
10026
10379
|
);
|
|
10027
|
-
const newDeclaration =
|
|
10380
|
+
const newDeclaration = tsUtils.tryPreserveDeclarationSemantics(
|
|
10028
10381
|
node,
|
|
10029
10382
|
arrowFunction
|
|
10030
10383
|
);
|
|
@@ -10045,6 +10398,7 @@ var _findSchemaVariableDeclaration = fn(
|
|
|
10045
10398
|
)(
|
|
10046
10399
|
function* (sourceFile, textRange) {
|
|
10047
10400
|
const ts = yield* service(TypeScriptApi);
|
|
10401
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10048
10402
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
10049
10403
|
const typeParser = yield* service(TypeParser);
|
|
10050
10404
|
const findSchema = fn("makeSchemaOpaque.apply.findSchema")(
|
|
@@ -10070,8 +10424,8 @@ var _findSchemaVariableDeclaration = fn(
|
|
|
10070
10424
|
}
|
|
10071
10425
|
);
|
|
10072
10426
|
return yield* pipe(
|
|
10073
|
-
|
|
10074
|
-
|
|
10427
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10428
|
+
map4(findSchema),
|
|
10075
10429
|
firstSuccessOf,
|
|
10076
10430
|
option
|
|
10077
10431
|
);
|
|
@@ -10158,6 +10512,7 @@ var makeSchemaOpaque = createRefactor({
|
|
|
10158
10512
|
description: "Make Schema opaque",
|
|
10159
10513
|
apply: fn("makeSchemaOpaque.apply")(function* (sourceFile, textRange) {
|
|
10160
10514
|
const ts = yield* service(TypeScriptApi);
|
|
10515
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10161
10516
|
const maybeNode = yield* _findSchemaVariableDeclaration(sourceFile, textRange);
|
|
10162
10517
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
10163
10518
|
const { identifier, types, variableDeclarationList, variableStatement } = maybeNode.value;
|
|
@@ -10167,19 +10522,11 @@ var makeSchemaOpaque = createRefactor({
|
|
|
10167
10522
|
apply: pipe(
|
|
10168
10523
|
gen(function* () {
|
|
10169
10524
|
const changeTracker = yield* service(ChangeTracker);
|
|
10170
|
-
const effectSchemaName =
|
|
10171
|
-
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
|
|
10175
|
-
"Schema"
|
|
10176
|
-
)
|
|
10177
|
-
),
|
|
10178
|
-
{
|
|
10179
|
-
onNone: () => "Schema",
|
|
10180
|
-
onSome: (_) => _.text
|
|
10181
|
-
}
|
|
10182
|
-
);
|
|
10525
|
+
const effectSchemaName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
10526
|
+
sourceFile,
|
|
10527
|
+
"effect",
|
|
10528
|
+
"Schema"
|
|
10529
|
+
) || "Schema";
|
|
10183
10530
|
const newIdentifier = ts.factory.createIdentifier(identifier.text + "_");
|
|
10184
10531
|
const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(
|
|
10185
10532
|
effectSchemaName,
|
|
@@ -10236,6 +10583,7 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
10236
10583
|
description: "Make Schema opaque with namespace",
|
|
10237
10584
|
apply: fn("makeSchemaOpaqueWithNs.apply")(function* (sourceFile, textRange) {
|
|
10238
10585
|
const ts = yield* service(TypeScriptApi);
|
|
10586
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10239
10587
|
const maybeNode = yield* _findSchemaVariableDeclaration(sourceFile, textRange);
|
|
10240
10588
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
10241
10589
|
const { identifier, types, variableDeclarationList, variableStatement } = maybeNode.value;
|
|
@@ -10245,19 +10593,11 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
10245
10593
|
apply: pipe(
|
|
10246
10594
|
gen(function* () {
|
|
10247
10595
|
const changeTracker = yield* service(ChangeTracker);
|
|
10248
|
-
const effectSchemaName =
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
"Schema"
|
|
10254
|
-
)
|
|
10255
|
-
),
|
|
10256
|
-
{
|
|
10257
|
-
onNone: () => "Schema",
|
|
10258
|
-
onSome: (_) => _.text
|
|
10259
|
-
}
|
|
10260
|
-
);
|
|
10596
|
+
const effectSchemaName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
10597
|
+
sourceFile,
|
|
10598
|
+
"effect",
|
|
10599
|
+
"Schema"
|
|
10600
|
+
) || "Schema";
|
|
10261
10601
|
const newIdentifier = ts.factory.createIdentifier(identifier.text + "_");
|
|
10262
10602
|
const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(
|
|
10263
10603
|
effectSchemaName,
|
|
@@ -10331,6 +10671,7 @@ var pipeableToDatafirst = createRefactor({
|
|
|
10331
10671
|
apply: fn("pipeableToDatafirst.apply")(function* (sourceFile, textRange) {
|
|
10332
10672
|
const ts = yield* service(TypeScriptApi);
|
|
10333
10673
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
10674
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10334
10675
|
function isPipeCall(node2) {
|
|
10335
10676
|
if (!ts.isCallExpression(node2)) return false;
|
|
10336
10677
|
const expression = node2.expression;
|
|
@@ -10346,7 +10687,7 @@ var pipeableToDatafirst = createRefactor({
|
|
|
10346
10687
|
for (let i = 0; i < callSignatures.length; i++) {
|
|
10347
10688
|
const callSignature = callSignatures[i];
|
|
10348
10689
|
if (callSignature.parameters.length === node2.arguments.length + 1) {
|
|
10349
|
-
return
|
|
10690
|
+
return some2(
|
|
10350
10691
|
ts.factory.createCallExpression(
|
|
10351
10692
|
node2.expression,
|
|
10352
10693
|
[],
|
|
@@ -10358,13 +10699,13 @@ var pipeableToDatafirst = createRefactor({
|
|
|
10358
10699
|
return none2();
|
|
10359
10700
|
}
|
|
10360
10701
|
const maybeNode = pipe(
|
|
10361
|
-
|
|
10702
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10362
10703
|
filter(isPipeCall),
|
|
10363
|
-
filter((node2) => isNodeInRange(textRange)(node2.expression)),
|
|
10704
|
+
filter((node2) => tsUtils.isNodeInRange(textRange)(node2.expression)),
|
|
10364
10705
|
filter(
|
|
10365
10706
|
(node2) => node2.arguments.length > 0
|
|
10366
10707
|
),
|
|
10367
|
-
|
|
10708
|
+
map4((node2) => {
|
|
10368
10709
|
let newNode2 = node2.arguments[0];
|
|
10369
10710
|
let didSomething = false;
|
|
10370
10711
|
for (let i = 1; i < node2.arguments.length; i++) {
|
|
@@ -10388,10 +10729,10 @@ var pipeableToDatafirst = createRefactor({
|
|
|
10388
10729
|
}
|
|
10389
10730
|
}
|
|
10390
10731
|
}
|
|
10391
|
-
return didSomething ?
|
|
10732
|
+
return didSomething ? some2([node2, newNode2]) : none2();
|
|
10392
10733
|
}),
|
|
10393
10734
|
filter(isSome2),
|
|
10394
|
-
|
|
10735
|
+
map4((_) => _.value),
|
|
10395
10736
|
head
|
|
10396
10737
|
);
|
|
10397
10738
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -10412,8 +10753,9 @@ var removeUnnecessaryEffectGen = createRefactor({
|
|
|
10412
10753
|
name: "removeUnnecessaryEffectGen",
|
|
10413
10754
|
description: "Remove unnecessary Effect.gen",
|
|
10414
10755
|
apply: fn("removeUnnecessaryEffectGen.apply")(function* (sourceFile, textRange) {
|
|
10756
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10415
10757
|
const typeParser = yield* service(TypeParser);
|
|
10416
|
-
for (const nodeToReplace of
|
|
10758
|
+
for (const nodeToReplace of tsUtils.getAncestorNodesInRange(sourceFile, textRange)) {
|
|
10417
10759
|
const maybeNode = yield* option(typeParser.unnecessaryEffectGen(nodeToReplace));
|
|
10418
10760
|
if (isNone2(maybeNode)) continue;
|
|
10419
10761
|
const replacementNode = maybeNode.value.replacementNode;
|
|
@@ -10436,10 +10778,11 @@ var toggleLazyConst = createRefactor({
|
|
|
10436
10778
|
description: "Toggle lazy const",
|
|
10437
10779
|
apply: fn("toggleLazyConst.apply")(function* (sourceFile, textRange) {
|
|
10438
10780
|
const ts = yield* service(TypeScriptApi);
|
|
10781
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10439
10782
|
const maybeNode = pipe(
|
|
10440
|
-
|
|
10783
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10441
10784
|
filter(ts.isVariableDeclaration),
|
|
10442
|
-
filter((node2) => isNodeInRange(textRange)(node2.name)),
|
|
10785
|
+
filter((node2) => tsUtils.isNodeInRange(textRange)(node2.name)),
|
|
10443
10786
|
filter(
|
|
10444
10787
|
(node2) => !!node2.initializer && !(ts.isArrowFunction(node2.initializer) && ts.isBlock(node2.initializer.body))
|
|
10445
10788
|
),
|
|
@@ -10478,6 +10821,7 @@ var togglePipeStyle = createRefactor({
|
|
|
10478
10821
|
const ts = yield* service(TypeScriptApi);
|
|
10479
10822
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
10480
10823
|
const typeParser = yield* service(TypeParser);
|
|
10824
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10481
10825
|
const togglePipeStyle2 = (node) => gen(function* () {
|
|
10482
10826
|
const pipeCall = yield* typeParser.pipeCall(node);
|
|
10483
10827
|
switch (pipeCall.kind) {
|
|
@@ -10522,7 +10866,7 @@ var togglePipeStyle = createRefactor({
|
|
|
10522
10866
|
};
|
|
10523
10867
|
}
|
|
10524
10868
|
});
|
|
10525
|
-
const ancestorNodes =
|
|
10869
|
+
const ancestorNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange);
|
|
10526
10870
|
return yield* pipe(
|
|
10527
10871
|
firstSuccessOf(ancestorNodes.map(togglePipeStyle2)),
|
|
10528
10872
|
orElse2(() => fail(new RefactorNotApplicableError()))
|
|
@@ -10536,9 +10880,38 @@ var toggleReturnTypeAnnotation = createRefactor({
|
|
|
10536
10880
|
description: "Toggle return type annotation",
|
|
10537
10881
|
apply: fn("toggleReturnTypeAnnotation.apply")(function* (sourceFile, textRange) {
|
|
10538
10882
|
const ts = yield* service(TypeScriptApi);
|
|
10883
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10539
10884
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
10885
|
+
function addReturnTypeAnnotation(sourceFile2, changeTracker, declaration, typeNode) {
|
|
10886
|
+
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile2);
|
|
10887
|
+
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
10888
|
+
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
10889
|
+
if (endNode) {
|
|
10890
|
+
if (needParens) {
|
|
10891
|
+
changeTracker.insertNodeBefore(
|
|
10892
|
+
sourceFile2,
|
|
10893
|
+
endNode,
|
|
10894
|
+
ts.factory.createToken(ts.SyntaxKind.OpenParenToken)
|
|
10895
|
+
);
|
|
10896
|
+
changeTracker.insertNodeAfter(
|
|
10897
|
+
sourceFile2,
|
|
10898
|
+
endNode,
|
|
10899
|
+
ts.factory.createToken(ts.SyntaxKind.CloseParenToken)
|
|
10900
|
+
);
|
|
10901
|
+
}
|
|
10902
|
+
changeTracker.insertNodeAt(sourceFile2, endNode.end, typeNode, { prefix: ": " });
|
|
10903
|
+
}
|
|
10904
|
+
}
|
|
10905
|
+
function removeReturnTypeAnnotation(sourceFile2, changeTracker, declaration) {
|
|
10906
|
+
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile2);
|
|
10907
|
+
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
10908
|
+
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
10909
|
+
if (endNode && declaration.type) {
|
|
10910
|
+
changeTracker.deleteRange(sourceFile2, { pos: endNode.end, end: declaration.type.end });
|
|
10911
|
+
}
|
|
10912
|
+
}
|
|
10540
10913
|
const maybeNode = pipe(
|
|
10541
|
-
|
|
10914
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10542
10915
|
filter(
|
|
10543
10916
|
(node2) => ts.isFunctionDeclaration(node2) || ts.isFunctionExpression(node2) || ts.isArrowFunction(node2) || ts.isMethodDeclaration(node2)
|
|
10544
10917
|
),
|
|
@@ -10551,8 +10924,8 @@ var toggleReturnTypeAnnotation = createRefactor({
|
|
|
10551
10924
|
kind: "refactor.rewrite.effect.toggleReturnTypeAnnotation",
|
|
10552
10925
|
description: "Toggle return type annotation",
|
|
10553
10926
|
apply: pipe(
|
|
10554
|
-
|
|
10555
|
-
|
|
10927
|
+
service(ChangeTracker),
|
|
10928
|
+
map3((changeTracker) => removeReturnTypeAnnotation(sourceFile, changeTracker, node))
|
|
10556
10929
|
)
|
|
10557
10930
|
};
|
|
10558
10931
|
}
|
|
@@ -10568,13 +10941,10 @@ var toggleReturnTypeAnnotation = createRefactor({
|
|
|
10568
10941
|
kind: "refactor.rewrite.effect.toggleReturnTypeAnnotation",
|
|
10569
10942
|
description: "Toggle return type annotation",
|
|
10570
10943
|
apply: pipe(
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
node,
|
|
10574
|
-
|
|
10575
|
-
),
|
|
10576
|
-
provideService(TypeCheckerApi, typeChecker),
|
|
10577
|
-
provideService(TypeScriptApi, ts)
|
|
10944
|
+
service(ChangeTracker),
|
|
10945
|
+
map3(
|
|
10946
|
+
(changeTracker) => addReturnTypeAnnotation(sourceFile, changeTracker, node, tsUtils.simplifyTypeNode(returnTypeNode))
|
|
10947
|
+
)
|
|
10578
10948
|
)
|
|
10579
10949
|
};
|
|
10580
10950
|
})
|
|
@@ -10586,11 +10956,12 @@ var toggleTypeAnnotation = createRefactor({
|
|
|
10586
10956
|
description: "Toggle type annotation",
|
|
10587
10957
|
apply: fn("toggleTypeAnnotation.apply")(function* (sourceFile, textRange) {
|
|
10588
10958
|
const ts = yield* service(TypeScriptApi);
|
|
10959
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10589
10960
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
10590
10961
|
const maybeNode = pipe(
|
|
10591
|
-
|
|
10962
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10592
10963
|
filter((node2) => ts.isVariableDeclaration(node2) || ts.isPropertyDeclaration(node2)),
|
|
10593
|
-
filter((node2) => isNodeInRange(textRange)(node2.name)),
|
|
10964
|
+
filter((node2) => tsUtils.isNodeInRange(textRange)(node2.name)),
|
|
10594
10965
|
filter((node2) => !!node2.initializer),
|
|
10595
10966
|
head
|
|
10596
10967
|
);
|
|
@@ -10626,7 +10997,7 @@ var toggleTypeAnnotation = createRefactor({
|
|
|
10626
10997
|
changeTracker.insertNodeAt(
|
|
10627
10998
|
sourceFile,
|
|
10628
10999
|
node.name.end,
|
|
10629
|
-
|
|
11000
|
+
tsUtils.simplifyTypeNode(initializerTypeNode),
|
|
10630
11001
|
{
|
|
10631
11002
|
prefix: ": "
|
|
10632
11003
|
}
|
|
@@ -10678,21 +11049,16 @@ var IndexSignatureWithMoreThanOneParameterError = class {
|
|
|
10678
11049
|
};
|
|
10679
11050
|
var SchemaGenContext = Tag("SchemaGenContext");
|
|
10680
11051
|
var makeSchemaGenContext = fn("SchemaGen.makeSchemaGenContext")(function* (sourceFile) {
|
|
10681
|
-
const
|
|
10682
|
-
|
|
10683
|
-
|
|
10684
|
-
|
|
10685
|
-
|
|
10686
|
-
|
|
10687
|
-
onSome: (_) => _.text
|
|
10688
|
-
})
|
|
10689
|
-
);
|
|
11052
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
11053
|
+
const effectSchemaIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
11054
|
+
sourceFile,
|
|
11055
|
+
"effect",
|
|
11056
|
+
"Schema"
|
|
11057
|
+
) || "Schema";
|
|
10690
11058
|
const moduleToImportedName = {};
|
|
10691
11059
|
for (const moduleName of ["Option", "Either", "Chunk", "Duration"]) {
|
|
10692
|
-
const importedName =
|
|
10693
|
-
|
|
10694
|
-
);
|
|
10695
|
-
if (isSome2(importedName)) moduleToImportedName[moduleName] = importedName.value.text;
|
|
11060
|
+
const importedName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", moduleName);
|
|
11061
|
+
if (importedName) moduleToImportedName[moduleName] = importedName;
|
|
10696
11062
|
}
|
|
10697
11063
|
const ts = yield* service(TypeScriptApi);
|
|
10698
11064
|
return {
|
|
@@ -10716,17 +11082,17 @@ var makeSchemaGenContext = fn("SchemaGen.makeSchemaGenContext")(function* (sourc
|
|
|
10716
11082
|
case "Pick":
|
|
10717
11083
|
case "Omit":
|
|
10718
11084
|
case "Record":
|
|
10719
|
-
return
|
|
11085
|
+
return some2(name.text);
|
|
10720
11086
|
case "ReadonlyArray":
|
|
10721
11087
|
case "Array":
|
|
10722
|
-
return
|
|
11088
|
+
return some2("Array");
|
|
10723
11089
|
}
|
|
10724
11090
|
return none2();
|
|
10725
11091
|
}
|
|
10726
11092
|
if (!ts.isIdentifier(name.left)) return none2();
|
|
10727
11093
|
for (const moduleName in moduleToImportedName) {
|
|
10728
11094
|
if (name.left.text === moduleToImportedName[moduleName] && name.right.text === moduleName) {
|
|
10729
|
-
return
|
|
11095
|
+
return some2(moduleName);
|
|
10730
11096
|
}
|
|
10731
11097
|
}
|
|
10732
11098
|
return none2();
|
|
@@ -10765,7 +11131,7 @@ var parseAllLiterals = fn(
|
|
|
10765
11131
|
}
|
|
10766
11132
|
}
|
|
10767
11133
|
if (ts.isUnionTypeNode(node)) {
|
|
10768
|
-
return flatten(yield*
|
|
11134
|
+
return flatten(yield* all(...node.types.map((_) => parseAllLiterals(_))));
|
|
10769
11135
|
}
|
|
10770
11136
|
if (ts.isParenthesizedTypeNode(node)) {
|
|
10771
11137
|
return yield* parseAllLiterals(node.type);
|
|
@@ -10812,11 +11178,11 @@ var processNode = (node, isVirtualTypeNode) => gen(function* () {
|
|
|
10812
11178
|
if (ts.isUnionTypeNode(node)) {
|
|
10813
11179
|
const allLiterals = yield* option(parseAllLiterals(node));
|
|
10814
11180
|
if (isSome2(allLiterals)) return createApiCall("Literal", allLiterals.value);
|
|
10815
|
-
const members = yield*
|
|
11181
|
+
const members = yield* all(...node.types.map((_) => processNode(_, isVirtualTypeNode)));
|
|
10816
11182
|
return createApiCall("Union", members);
|
|
10817
11183
|
}
|
|
10818
11184
|
if (ts.isIntersectionTypeNode(node)) {
|
|
10819
|
-
const [firstSchema, ...otherSchemas] = yield*
|
|
11185
|
+
const [firstSchema, ...otherSchemas] = yield* all(
|
|
10820
11186
|
...node.types.map((_) => processNode(_, isVirtualTypeNode))
|
|
10821
11187
|
);
|
|
10822
11188
|
if (otherSchemas.length === 0) return firstSchema;
|
|
@@ -10872,13 +11238,13 @@ var processNode = (node, isVirtualTypeNode) => gen(function* () {
|
|
|
10872
11238
|
case "Option":
|
|
10873
11239
|
case "Chunk":
|
|
10874
11240
|
case "Array": {
|
|
10875
|
-
const elements = yield*
|
|
11241
|
+
const elements = yield* all(
|
|
10876
11242
|
...node.typeArguments ? node.typeArguments.map((_) => processNode(_, isVirtualTypeNode)) : []
|
|
10877
11243
|
);
|
|
10878
11244
|
return createApiCall(parsedName.value, elements);
|
|
10879
11245
|
}
|
|
10880
11246
|
case "Record": {
|
|
10881
|
-
const elements = yield*
|
|
11247
|
+
const elements = yield* all(
|
|
10882
11248
|
...node.typeArguments ? node.typeArguments.map((_) => processNode(_, isVirtualTypeNode)) : []
|
|
10883
11249
|
);
|
|
10884
11250
|
if (elements.length >= 2) {
|
|
@@ -10892,7 +11258,7 @@ var processNode = (node, isVirtualTypeNode) => gen(function* () {
|
|
|
10892
11258
|
return createUnsupportedNodeComment(ts, sourceFile, node);
|
|
10893
11259
|
}
|
|
10894
11260
|
case "Either": {
|
|
10895
|
-
const elements = yield*
|
|
11261
|
+
const elements = yield* all(
|
|
10896
11262
|
...node.typeArguments ? node.typeArguments.map((_) => processNode(_, isVirtualTypeNode)) : []
|
|
10897
11263
|
);
|
|
10898
11264
|
if (elements.length >= 2) {
|
|
@@ -11076,10 +11442,11 @@ var process = fn("SchemaGen.process")(
|
|
|
11076
11442
|
var findNodeToProcess = fn("SchemaGen.findNodeToProcess")(
|
|
11077
11443
|
function* (sourceFile, textRange) {
|
|
11078
11444
|
const ts = yield* service(TypeScriptApi);
|
|
11445
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
11079
11446
|
return pipe(
|
|
11080
|
-
|
|
11447
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
11081
11448
|
filter((node) => ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)),
|
|
11082
|
-
filter((node) => isNodeInRange(textRange)(node.name)),
|
|
11449
|
+
filter((node) => tsUtils.isNodeInRange(textRange)(node.name)),
|
|
11083
11450
|
filter((node) => (node.typeParameters || []).length === 0),
|
|
11084
11451
|
head
|
|
11085
11452
|
);
|
|
@@ -11112,6 +11479,7 @@ var typeToEffectSchema = createRefactor({
|
|
|
11112
11479
|
description: "Refactor to Schema",
|
|
11113
11480
|
apply: fn("typeToEffectSchema.apply")(function* (sourceFile, textRange) {
|
|
11114
11481
|
const ts = yield* service(TypeScriptApi);
|
|
11482
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
11115
11483
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
11116
11484
|
const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
|
|
11117
11485
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -11122,6 +11490,7 @@ var typeToEffectSchema = createRefactor({
|
|
|
11122
11490
|
apply: pipe(
|
|
11123
11491
|
applyAtNode(sourceFile, node, false),
|
|
11124
11492
|
provideService(TypeCheckerApi, typeChecker),
|
|
11493
|
+
provideService(TypeScriptUtils, tsUtils),
|
|
11125
11494
|
provideService(TypeScriptApi, ts)
|
|
11126
11495
|
)
|
|
11127
11496
|
};
|
|
@@ -11134,6 +11503,7 @@ var typeToEffectSchemaClass = createRefactor({
|
|
|
11134
11503
|
description: "Refactor to Schema.Class",
|
|
11135
11504
|
apply: fn("typeToEffectSchemaClass.apply")(function* (sourceFile, textRange) {
|
|
11136
11505
|
const ts = yield* service(TypeScriptApi);
|
|
11506
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
11137
11507
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
11138
11508
|
const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
|
|
11139
11509
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -11144,6 +11514,7 @@ var typeToEffectSchemaClass = createRefactor({
|
|
|
11144
11514
|
apply: pipe(
|
|
11145
11515
|
applyAtNode(sourceFile, node, true),
|
|
11146
11516
|
provideService(TypeCheckerApi, typeChecker),
|
|
11517
|
+
provideService(TypeScriptUtils, tsUtils),
|
|
11147
11518
|
provideService(TypeScriptApi, ts)
|
|
11148
11519
|
)
|
|
11149
11520
|
};
|
|
@@ -11156,6 +11527,7 @@ var wrapWithEffectGen = createRefactor({
|
|
|
11156
11527
|
description: "Wrap with Effect.gen",
|
|
11157
11528
|
apply: fn("wrapWithEffectGen.apply")(function* (sourceFile, textRange) {
|
|
11158
11529
|
const ts = yield* service(TypeScriptApi);
|
|
11530
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
11159
11531
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
11160
11532
|
const typeParser = yield* service(TypeParser);
|
|
11161
11533
|
const findEffectToWrap = fn("wrapWithEffectGen.apply.findEffectToWrap")(
|
|
@@ -11169,37 +11541,26 @@ var wrapWithEffectGen = createRefactor({
|
|
|
11169
11541
|
}
|
|
11170
11542
|
);
|
|
11171
11543
|
const maybeNode = yield* pipe(
|
|
11172
|
-
|
|
11173
|
-
|
|
11544
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
11545
|
+
map4(findEffectToWrap),
|
|
11174
11546
|
firstSuccessOf,
|
|
11175
11547
|
option
|
|
11176
11548
|
);
|
|
11177
11549
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
11178
|
-
const effectModuleIdentifier =
|
|
11179
|
-
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
|
|
11183
|
-
typeParser.importedEffectModule(node),
|
|
11184
|
-
option,
|
|
11185
|
-
map4(isSome2)
|
|
11186
|
-
)
|
|
11187
|
-
)
|
|
11188
|
-
),
|
|
11189
|
-
{
|
|
11190
|
-
onNone: () => "Effect",
|
|
11191
|
-
onSome: (node) => node.text
|
|
11192
|
-
}
|
|
11193
|
-
);
|
|
11550
|
+
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
11551
|
+
sourceFile,
|
|
11552
|
+
"effect",
|
|
11553
|
+
"Effect"
|
|
11554
|
+
) || "Effect";
|
|
11194
11555
|
return {
|
|
11195
11556
|
kind: "refactor.rewrite.effect.wrapWithEffectGen",
|
|
11196
11557
|
description: `Wrap with Effect.gen`,
|
|
11197
11558
|
apply: pipe(
|
|
11198
11559
|
gen(function* () {
|
|
11199
11560
|
const changeTracker = yield* service(ChangeTracker);
|
|
11200
|
-
const effectGen =
|
|
11561
|
+
const effectGen = tsUtils.createEffectGenCallExpressionWithBlock(
|
|
11201
11562
|
effectModuleIdentifier,
|
|
11202
|
-
|
|
11563
|
+
tsUtils.createReturnYieldStarStatement(maybeNode.value)
|
|
11203
11564
|
);
|
|
11204
11565
|
changeTracker.replaceNode(sourceFile, maybeNode.value, effectGen);
|
|
11205
11566
|
}),
|
|
@@ -11230,273 +11591,6 @@ var wrapWithPipe = createRefactor({
|
|
|
11230
11591
|
})
|
|
11231
11592
|
});
|
|
11232
11593
|
|
|
11233
|
-
// src/refactors/writeTagClassAccessors.ts
|
|
11234
|
-
var writeTagClassAccessors = createRefactor({
|
|
11235
|
-
name: "writeTagClassAccessors",
|
|
11236
|
-
description: "Implement Service accessors",
|
|
11237
|
-
apply: fn("writeTagClassAccessors.apply")(function* (sourceFile, textRange) {
|
|
11238
|
-
const ts = yield* service(TypeScriptApi);
|
|
11239
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
11240
|
-
const typeParser = yield* service(TypeParser);
|
|
11241
|
-
const effectIdentifier = pipe(
|
|
11242
|
-
yield* option(
|
|
11243
|
-
findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", "Effect")
|
|
11244
|
-
),
|
|
11245
|
-
match({
|
|
11246
|
-
onNone: () => "Effect",
|
|
11247
|
-
onSome: (_) => _.text
|
|
11248
|
-
})
|
|
11249
|
-
);
|
|
11250
|
-
const createConstantProperty = (className, propertyName, type) => ts.factory.createPropertyDeclaration(
|
|
11251
|
-
[ts.factory.createModifier(ts.SyntaxKind.StaticKeyword)],
|
|
11252
|
-
propertyName,
|
|
11253
|
-
void 0,
|
|
11254
|
-
type,
|
|
11255
|
-
ts.factory.createCallExpression(
|
|
11256
|
-
ts.factory.createPropertyAccessExpression(
|
|
11257
|
-
ts.factory.createIdentifier(effectIdentifier),
|
|
11258
|
-
"andThen"
|
|
11259
|
-
),
|
|
11260
|
-
void 0,
|
|
11261
|
-
[
|
|
11262
|
-
ts.factory.createIdentifier(className.text),
|
|
11263
|
-
ts.factory.createArrowFunction(
|
|
11264
|
-
void 0,
|
|
11265
|
-
void 0,
|
|
11266
|
-
[ts.factory.createParameterDeclaration(
|
|
11267
|
-
void 0,
|
|
11268
|
-
void 0,
|
|
11269
|
-
"_"
|
|
11270
|
-
)],
|
|
11271
|
-
void 0,
|
|
11272
|
-
void 0,
|
|
11273
|
-
ts.factory.createPropertyAccessExpression(
|
|
11274
|
-
ts.factory.createIdentifier("_"),
|
|
11275
|
-
propertyName
|
|
11276
|
-
)
|
|
11277
|
-
)
|
|
11278
|
-
]
|
|
11279
|
-
)
|
|
11280
|
-
);
|
|
11281
|
-
const createFunctionProperty = (className, propertyName, type, forceAny) => {
|
|
11282
|
-
const arrowBody = ts.factory.createCallExpression(
|
|
11283
|
-
ts.factory.createPropertyAccessExpression(
|
|
11284
|
-
ts.factory.createIdentifier(effectIdentifier),
|
|
11285
|
-
"andThen"
|
|
11286
|
-
),
|
|
11287
|
-
void 0,
|
|
11288
|
-
[
|
|
11289
|
-
ts.factory.createIdentifier(className.text),
|
|
11290
|
-
ts.factory.createArrowFunction(
|
|
11291
|
-
void 0,
|
|
11292
|
-
void 0,
|
|
11293
|
-
[ts.factory.createParameterDeclaration(
|
|
11294
|
-
void 0,
|
|
11295
|
-
void 0,
|
|
11296
|
-
"_",
|
|
11297
|
-
void 0,
|
|
11298
|
-
forceAny ? ts.factory.createTypeReferenceNode("any") : void 0
|
|
11299
|
-
)],
|
|
11300
|
-
void 0,
|
|
11301
|
-
void 0,
|
|
11302
|
-
ts.factory.createCallExpression(
|
|
11303
|
-
ts.factory.createPropertyAccessExpression(
|
|
11304
|
-
ts.factory.createIdentifier("_"),
|
|
11305
|
-
propertyName
|
|
11306
|
-
),
|
|
11307
|
-
void 0,
|
|
11308
|
-
[
|
|
11309
|
-
ts.factory.createSpreadElement(ts.factory.createIdentifier("args"))
|
|
11310
|
-
]
|
|
11311
|
-
)
|
|
11312
|
-
)
|
|
11313
|
-
]
|
|
11314
|
-
);
|
|
11315
|
-
return ts.factory.createPropertyDeclaration(
|
|
11316
|
-
[ts.factory.createModifier(ts.SyntaxKind.StaticKeyword)],
|
|
11317
|
-
propertyName,
|
|
11318
|
-
void 0,
|
|
11319
|
-
type,
|
|
11320
|
-
ts.factory.createArrowFunction(
|
|
11321
|
-
void 0,
|
|
11322
|
-
void 0,
|
|
11323
|
-
[ts.factory.createParameterDeclaration(
|
|
11324
|
-
void 0,
|
|
11325
|
-
ts.factory.createToken(ts.SyntaxKind.DotDotDotToken),
|
|
11326
|
-
"args",
|
|
11327
|
-
void 0,
|
|
11328
|
-
forceAny ? ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode("any")) : void 0
|
|
11329
|
-
)],
|
|
11330
|
-
void 0,
|
|
11331
|
-
void 0,
|
|
11332
|
-
forceAny ? ts.factory.createAsExpression(arrowBody, ts.factory.createTypeReferenceNode("any")) : arrowBody
|
|
11333
|
-
)
|
|
11334
|
-
);
|
|
11335
|
-
};
|
|
11336
|
-
const generateReturnType = (type, atLocation, className) => pipe(
|
|
11337
|
-
typeParser.effectType(type, atLocation),
|
|
11338
|
-
flatMap2((returnedEffect) => {
|
|
11339
|
-
const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(className.text) : ts.factory.createUnionTypeNode(
|
|
11340
|
-
[
|
|
11341
|
-
ts.factory.createTypeReferenceNode(className.text),
|
|
11342
|
-
typeChecker.typeToTypeNode(returnedEffect.R, atLocation, ts.NodeBuilderFlags.NoTruncation)
|
|
11343
|
-
]
|
|
11344
|
-
);
|
|
11345
|
-
const successType = typeChecker.typeToTypeNode(
|
|
11346
|
-
returnedEffect.A,
|
|
11347
|
-
atLocation,
|
|
11348
|
-
ts.NodeBuilderFlags.NoTruncation
|
|
11349
|
-
);
|
|
11350
|
-
if (!successType) return fail("error generating success type");
|
|
11351
|
-
const failureType = typeChecker.typeToTypeNode(
|
|
11352
|
-
returnedEffect.E,
|
|
11353
|
-
atLocation,
|
|
11354
|
-
ts.NodeBuilderFlags.NoTruncation
|
|
11355
|
-
);
|
|
11356
|
-
if (!failureType) return fail("error generating failure type");
|
|
11357
|
-
const typeNode = ts.factory.createTypeReferenceNode(
|
|
11358
|
-
ts.factory.createQualifiedName(
|
|
11359
|
-
ts.factory.createIdentifier(effectIdentifier),
|
|
11360
|
-
ts.factory.createIdentifier("Effect")
|
|
11361
|
-
),
|
|
11362
|
-
[successType, failureType, contextType]
|
|
11363
|
-
);
|
|
11364
|
-
return succeed(typeNode);
|
|
11365
|
-
}),
|
|
11366
|
-
orElse2(
|
|
11367
|
-
() => pipe(
|
|
11368
|
-
typeParser.promiseLike(type, atLocation),
|
|
11369
|
-
flatMap2(({ type: type2 }) => {
|
|
11370
|
-
const successType = typeChecker.typeToTypeNode(
|
|
11371
|
-
type2,
|
|
11372
|
-
atLocation,
|
|
11373
|
-
ts.NodeBuilderFlags.NoTruncation
|
|
11374
|
-
);
|
|
11375
|
-
if (!successType) return fail("error generating success type");
|
|
11376
|
-
return succeed(ts.factory.createTypeReferenceNode(
|
|
11377
|
-
ts.factory.createQualifiedName(
|
|
11378
|
-
ts.factory.createIdentifier(effectIdentifier),
|
|
11379
|
-
ts.factory.createIdentifier("Effect")
|
|
11380
|
-
),
|
|
11381
|
-
[
|
|
11382
|
-
successType,
|
|
11383
|
-
ts.factory.createTypeReferenceNode(
|
|
11384
|
-
ts.factory.createQualifiedName(
|
|
11385
|
-
ts.factory.createIdentifier("Cause"),
|
|
11386
|
-
ts.factory.createIdentifier("UnknownException")
|
|
11387
|
-
)
|
|
11388
|
-
),
|
|
11389
|
-
ts.factory.createTypeReferenceNode(className.text)
|
|
11390
|
-
]
|
|
11391
|
-
));
|
|
11392
|
-
})
|
|
11393
|
-
)
|
|
11394
|
-
),
|
|
11395
|
-
orElse2(() => {
|
|
11396
|
-
const successType = typeChecker.typeToTypeNode(type, atLocation, ts.NodeBuilderFlags.NoTruncation);
|
|
11397
|
-
if (!successType) return fail("error generating success type");
|
|
11398
|
-
const typeNode = ts.factory.createTypeReferenceNode(
|
|
11399
|
-
ts.factory.createQualifiedName(
|
|
11400
|
-
ts.factory.createIdentifier(effectIdentifier),
|
|
11401
|
-
ts.factory.createIdentifier("Effect")
|
|
11402
|
-
),
|
|
11403
|
-
[
|
|
11404
|
-
successType,
|
|
11405
|
-
ts.factory.createTypeReferenceNode("never"),
|
|
11406
|
-
ts.factory.createTypeReferenceNode(className.text)
|
|
11407
|
-
]
|
|
11408
|
-
);
|
|
11409
|
-
return succeed(typeNode);
|
|
11410
|
-
})
|
|
11411
|
-
);
|
|
11412
|
-
const proxySignature = (signature, atLocation, className) => gen(function* () {
|
|
11413
|
-
const signatureDeclaration = typeChecker.signatureToSignatureDeclaration(
|
|
11414
|
-
signature,
|
|
11415
|
-
ts.SyntaxKind.FunctionType,
|
|
11416
|
-
atLocation,
|
|
11417
|
-
ts.NodeBuilderFlags.NoTruncation
|
|
11418
|
-
);
|
|
11419
|
-
if (!signatureDeclaration) return yield* fail("error generating signature");
|
|
11420
|
-
const returnType = yield* generateReturnType(signature.getReturnType(), atLocation, className);
|
|
11421
|
-
return ts.factory.createFunctionTypeNode(
|
|
11422
|
-
signatureDeclaration.typeParameters,
|
|
11423
|
-
signatureDeclaration.parameters,
|
|
11424
|
-
returnType
|
|
11425
|
-
);
|
|
11426
|
-
});
|
|
11427
|
-
const writeAccessors = fn("writeTagClassAccessors.writeAccessors")(
|
|
11428
|
-
function* (service2, className, atLocation) {
|
|
11429
|
-
const changeTracker = yield* service(ChangeTracker);
|
|
11430
|
-
const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.getEnd() - 1;
|
|
11431
|
-
for (const property of typeChecker.getPropertiesOfType(service2)) {
|
|
11432
|
-
const servicePropertyType = typeChecker.getTypeOfSymbolAtLocation(property, atLocation);
|
|
11433
|
-
const callSignatures = [];
|
|
11434
|
-
let propertyDeclaration = void 0;
|
|
11435
|
-
for (const signature of servicePropertyType.getCallSignatures()) {
|
|
11436
|
-
yield* pipe(
|
|
11437
|
-
proxySignature(signature, atLocation, className),
|
|
11438
|
-
map4((sig) => {
|
|
11439
|
-
callSignatures.push(sig);
|
|
11440
|
-
}),
|
|
11441
|
-
ignore
|
|
11442
|
-
);
|
|
11443
|
-
}
|
|
11444
|
-
if (callSignatures.length === 0) {
|
|
11445
|
-
yield* pipe(
|
|
11446
|
-
generateReturnType(servicePropertyType, atLocation, className),
|
|
11447
|
-
map4((type) => {
|
|
11448
|
-
propertyDeclaration = createConstantProperty(className, property.getName(), type);
|
|
11449
|
-
}),
|
|
11450
|
-
ignore
|
|
11451
|
-
);
|
|
11452
|
-
} else {
|
|
11453
|
-
const allSignatures = ts.factory.createIntersectionTypeNode(callSignatures);
|
|
11454
|
-
const type = yield* simplifyTypeNode(allSignatures);
|
|
11455
|
-
propertyDeclaration = createFunctionProperty(className, property.getName(), type, callSignatures.length > 1);
|
|
11456
|
-
}
|
|
11457
|
-
if (propertyDeclaration) {
|
|
11458
|
-
const oldProperty = atLocation.members.filter(ts.isPropertyDeclaration).find((p) => {
|
|
11459
|
-
const symbol3 = typeChecker.getSymbolAtLocation(p.name);
|
|
11460
|
-
return symbol3?.getName() === property.getName();
|
|
11461
|
-
});
|
|
11462
|
-
if (oldProperty) {
|
|
11463
|
-
changeTracker.deleteRange(sourceFile, {
|
|
11464
|
-
pos: oldProperty.getStart(sourceFile),
|
|
11465
|
-
end: oldProperty.getEnd()
|
|
11466
|
-
});
|
|
11467
|
-
changeTracker.insertNodeAt(sourceFile, oldProperty.getStart(sourceFile), propertyDeclaration);
|
|
11468
|
-
} else {
|
|
11469
|
-
changeTracker.insertNodeAt(sourceFile, insertLocation, propertyDeclaration, { suffix: "\n" });
|
|
11470
|
-
}
|
|
11471
|
-
}
|
|
11472
|
-
}
|
|
11473
|
-
}
|
|
11474
|
-
);
|
|
11475
|
-
const writeTagClassAccessors2 = (node) => gen(function* () {
|
|
11476
|
-
if (!ts.isClassDeclaration(node)) return yield* fail(new RefactorNotApplicableError());
|
|
11477
|
-
if (!node.name) return yield* fail(new RefactorNotApplicableError());
|
|
11478
|
-
const classSym = typeChecker.getSymbolAtLocation(node.name);
|
|
11479
|
-
if (!classSym) return yield* fail(new RefactorNotApplicableError());
|
|
11480
|
-
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
11481
|
-
const { Service } = yield* pipe(
|
|
11482
|
-
typeParser.contextTag(type, node),
|
|
11483
|
-
orElse2(() => fail(new RefactorNotApplicableError()))
|
|
11484
|
-
);
|
|
11485
|
-
return {
|
|
11486
|
-
kind: "refactor.rewrite.effect.writeTagClassAccessors",
|
|
11487
|
-
description: "Implement Service accessors",
|
|
11488
|
-
apply: pipe(
|
|
11489
|
-
writeAccessors(Service, node.name, node),
|
|
11490
|
-
provideService(TypeCheckerApi, typeChecker),
|
|
11491
|
-
provideService(TypeScriptApi, ts)
|
|
11492
|
-
)
|
|
11493
|
-
};
|
|
11494
|
-
});
|
|
11495
|
-
const parentNodes = yield* getAncestorNodesInRange(sourceFile, textRange);
|
|
11496
|
-
return yield* firstSuccessOf(parentNodes.map(writeTagClassAccessors2));
|
|
11497
|
-
})
|
|
11498
|
-
});
|
|
11499
|
-
|
|
11500
11594
|
// src/refactors.ts
|
|
11501
11595
|
var refactors = [
|
|
11502
11596
|
asyncAwaitToGen,
|
|
@@ -11547,13 +11641,10 @@ var init = (modules) => {
|
|
|
11547
11641
|
function runNano(program) {
|
|
11548
11642
|
return (fa) => pipe(
|
|
11549
11643
|
fa,
|
|
11550
|
-
|
|
11551
|
-
|
|
11644
|
+
nanoLayer2,
|
|
11645
|
+
nanoLayer,
|
|
11552
11646
|
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
11553
|
-
provideService(
|
|
11554
|
-
TypeCheckerApiCache,
|
|
11555
|
-
makeTypeCheckerApiCache()
|
|
11556
|
-
),
|
|
11647
|
+
provideService(TypeScriptProgram, program),
|
|
11557
11648
|
provideService(TypeScriptApi, modules.typescript),
|
|
11558
11649
|
provideService(
|
|
11559
11650
|
LanguageServicePluginOptions,
|
|
@@ -11599,45 +11690,60 @@ var init = (modules) => {
|
|
|
11599
11690
|
preferences,
|
|
11600
11691
|
...args2
|
|
11601
11692
|
);
|
|
11602
|
-
|
|
11603
|
-
|
|
11604
|
-
|
|
11605
|
-
|
|
11606
|
-
|
|
11607
|
-
|
|
11608
|
-
|
|
11609
|
-
|
|
11610
|
-
|
|
11611
|
-
|
|
11612
|
-
|
|
11613
|
-
|
|
11614
|
-
info.languageServiceHost
|
|
11615
|
-
);
|
|
11616
|
-
for (const applicableFix of applicableFixes) {
|
|
11617
|
-
const changes = modules.typescript.textChanges.ChangeTracker.with(
|
|
11618
|
-
{
|
|
11619
|
-
formatContext,
|
|
11620
|
-
host: info.languageServiceHost,
|
|
11621
|
-
preferences: preferences || {}
|
|
11622
|
-
},
|
|
11623
|
-
(changeTracker) => pipe(
|
|
11624
|
-
applicableFix.apply,
|
|
11625
|
-
provideService(ChangeTracker, changeTracker),
|
|
11626
|
-
run
|
|
11627
|
-
)
|
|
11693
|
+
const program = languageService.getProgram();
|
|
11694
|
+
if (languageServicePluginOptions.diagnostics && program) {
|
|
11695
|
+
const sourceFile = program.getSourceFile(fileName);
|
|
11696
|
+
if (sourceFile) {
|
|
11697
|
+
return pipe(
|
|
11698
|
+
sync(() => {
|
|
11699
|
+
const effectCodeFixes = [];
|
|
11700
|
+
if (!effectCodeFixesForFile.has(fileName)) {
|
|
11701
|
+
runDiagnosticsAndCacheCodeFixes(fileName);
|
|
11702
|
+
}
|
|
11703
|
+
const applicableFixes = (effectCodeFixesForFile.get(fileName) || []).filter(
|
|
11704
|
+
(_) => _.start === start && _.end === end && errorCodes.indexOf(_.code) > -1
|
|
11628
11705
|
);
|
|
11629
|
-
|
|
11630
|
-
|
|
11631
|
-
|
|
11632
|
-
|
|
11633
|
-
|
|
11634
|
-
|
|
11635
|
-
|
|
11636
|
-
|
|
11637
|
-
|
|
11638
|
-
|
|
11639
|
-
|
|
11640
|
-
|
|
11706
|
+
const formatContext = modules.typescript.formatting.getFormatContext(
|
|
11707
|
+
formatOptions,
|
|
11708
|
+
info.languageServiceHost
|
|
11709
|
+
);
|
|
11710
|
+
for (const applicableFix of applicableFixes) {
|
|
11711
|
+
const changes = modules.typescript.textChanges.ChangeTracker.with(
|
|
11712
|
+
{
|
|
11713
|
+
formatContext,
|
|
11714
|
+
host: info.languageServiceHost,
|
|
11715
|
+
preferences: preferences || {}
|
|
11716
|
+
},
|
|
11717
|
+
(changeTracker) => pipe(
|
|
11718
|
+
applicableFix.apply,
|
|
11719
|
+
provideService(ChangeTracker, changeTracker),
|
|
11720
|
+
run
|
|
11721
|
+
)
|
|
11722
|
+
);
|
|
11723
|
+
effectCodeFixes.push({
|
|
11724
|
+
fixName: applicableFix.fixName,
|
|
11725
|
+
description: applicableFix.description,
|
|
11726
|
+
changes
|
|
11727
|
+
});
|
|
11728
|
+
}
|
|
11729
|
+
return effectCodeFixes;
|
|
11730
|
+
}),
|
|
11731
|
+
flatMap(
|
|
11732
|
+
(effectCodeFixes) => pipe(
|
|
11733
|
+
middlewareAutoImportQuickfixes(
|
|
11734
|
+
sourceFile,
|
|
11735
|
+
info.languageServiceHost,
|
|
11736
|
+
formatOptions,
|
|
11737
|
+
preferences,
|
|
11738
|
+
applicableCodeFixes
|
|
11739
|
+
),
|
|
11740
|
+
map3((modifiedCodeFixes) => effectCodeFixes.concat(modifiedCodeFixes))
|
|
11741
|
+
)
|
|
11742
|
+
),
|
|
11743
|
+
runNano(program),
|
|
11744
|
+
getOrElse(() => applicableCodeFixes)
|
|
11745
|
+
);
|
|
11746
|
+
}
|
|
11641
11747
|
}
|
|
11642
11748
|
return applicableCodeFixes;
|
|
11643
11749
|
};
|
|
@@ -11740,7 +11846,7 @@ var init = (modules) => {
|
|
|
11740
11846
|
if (sourceFile) {
|
|
11741
11847
|
return pipe(
|
|
11742
11848
|
appendEffectCompletionEntryData(sourceFile, applicableCompletions),
|
|
11743
|
-
|
|
11849
|
+
flatMap(
|
|
11744
11850
|
(augmentedCompletions) => pipe(
|
|
11745
11851
|
getCompletionsAtPosition(
|
|
11746
11852
|
completions,
|
|
@@ -11749,7 +11855,7 @@ var init = (modules) => {
|
|
|
11749
11855
|
options,
|
|
11750
11856
|
formattingSettings
|
|
11751
11857
|
),
|
|
11752
|
-
|
|
11858
|
+
map3(
|
|
11753
11859
|
(effectCompletions) => augmentedCompletions ? {
|
|
11754
11860
|
...augmentedCompletions,
|
|
11755
11861
|
entries: effectCompletions.concat(augmentedCompletions.entries)
|