@effect/language-service 0.13.0 → 0.14.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 +32 -0
- package/index.js +9 -6
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +1894 -0
- package/transform.js.map +1 -0
package/transform.js
ADDED
|
@@ -0,0 +1,1894 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/transform.ts
|
|
21
|
+
var transform_exports = {};
|
|
22
|
+
__export(transform_exports, {
|
|
23
|
+
default: () => transform_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(transform_exports);
|
|
26
|
+
|
|
27
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Function.js
|
|
28
|
+
var isFunction = (input) => typeof input === "function";
|
|
29
|
+
var dual = function(arity, body) {
|
|
30
|
+
if (typeof arity === "function") {
|
|
31
|
+
return function() {
|
|
32
|
+
if (arity(arguments)) {
|
|
33
|
+
return body.apply(this, arguments);
|
|
34
|
+
}
|
|
35
|
+
return (self) => body(self, ...arguments);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
switch (arity) {
|
|
39
|
+
case 0:
|
|
40
|
+
case 1:
|
|
41
|
+
throw new RangeError(`Invalid arity ${arity}`);
|
|
42
|
+
case 2:
|
|
43
|
+
return function(a, b) {
|
|
44
|
+
if (arguments.length >= 2) {
|
|
45
|
+
return body(a, b);
|
|
46
|
+
}
|
|
47
|
+
return function(self) {
|
|
48
|
+
return body(self, a);
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
case 3:
|
|
52
|
+
return function(a, b, c) {
|
|
53
|
+
if (arguments.length >= 3) {
|
|
54
|
+
return body(a, b, c);
|
|
55
|
+
}
|
|
56
|
+
return function(self) {
|
|
57
|
+
return body(self, a, b);
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
case 4:
|
|
61
|
+
return function(a, b, c, d) {
|
|
62
|
+
if (arguments.length >= 4) {
|
|
63
|
+
return body(a, b, c, d);
|
|
64
|
+
}
|
|
65
|
+
return function(self) {
|
|
66
|
+
return body(self, a, b, c);
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
case 5:
|
|
70
|
+
return function(a, b, c, d, e) {
|
|
71
|
+
if (arguments.length >= 5) {
|
|
72
|
+
return body(a, b, c, d, e);
|
|
73
|
+
}
|
|
74
|
+
return function(self) {
|
|
75
|
+
return body(self, a, b, c, d);
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
default:
|
|
79
|
+
return function() {
|
|
80
|
+
if (arguments.length >= arity) {
|
|
81
|
+
return body.apply(this, arguments);
|
|
82
|
+
}
|
|
83
|
+
const args = arguments;
|
|
84
|
+
return function(self) {
|
|
85
|
+
return body(self, ...args);
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var identity = (a) => a;
|
|
91
|
+
function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
|
|
92
|
+
switch (arguments.length) {
|
|
93
|
+
case 1:
|
|
94
|
+
return a;
|
|
95
|
+
case 2:
|
|
96
|
+
return ab(a);
|
|
97
|
+
case 3:
|
|
98
|
+
return bc(ab(a));
|
|
99
|
+
case 4:
|
|
100
|
+
return cd(bc(ab(a)));
|
|
101
|
+
case 5:
|
|
102
|
+
return de(cd(bc(ab(a))));
|
|
103
|
+
case 6:
|
|
104
|
+
return ef(de(cd(bc(ab(a)))));
|
|
105
|
+
case 7:
|
|
106
|
+
return fg(ef(de(cd(bc(ab(a))))));
|
|
107
|
+
case 8:
|
|
108
|
+
return gh(fg(ef(de(cd(bc(ab(a)))))));
|
|
109
|
+
case 9:
|
|
110
|
+
return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
|
|
111
|
+
default: {
|
|
112
|
+
let ret = arguments[0];
|
|
113
|
+
for (let i = 1; i < arguments.length; i++) {
|
|
114
|
+
ret = arguments[i](ret);
|
|
115
|
+
}
|
|
116
|
+
return ret;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/version.js
|
|
122
|
+
var moduleVersion = "3.12.5";
|
|
123
|
+
var getCurrentVersion = () => moduleVersion;
|
|
124
|
+
|
|
125
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/GlobalValue.js
|
|
126
|
+
var globalStoreId = `effect/GlobalValue/globalStoreId/${/* @__PURE__ */ getCurrentVersion()}`;
|
|
127
|
+
var globalStore;
|
|
128
|
+
var globalValue = (id, compute) => {
|
|
129
|
+
if (!globalStore) {
|
|
130
|
+
globalThis[globalStoreId] ??= /* @__PURE__ */ new Map();
|
|
131
|
+
globalStore = globalThis[globalStoreId];
|
|
132
|
+
}
|
|
133
|
+
if (!globalStore.has(id)) {
|
|
134
|
+
globalStore.set(id, compute());
|
|
135
|
+
}
|
|
136
|
+
return globalStore.get(id);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Predicate.js
|
|
140
|
+
var isFunction2 = isFunction;
|
|
141
|
+
var isRecordOrArray = (input) => typeof input === "object" && input !== null;
|
|
142
|
+
var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
|
|
143
|
+
var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObject(self) && property in self);
|
|
144
|
+
|
|
145
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/errors.js
|
|
146
|
+
var getBugErrorMessage = (message) => `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`;
|
|
147
|
+
|
|
148
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Utils.js
|
|
149
|
+
var GenKindTypeId = /* @__PURE__ */ Symbol.for("effect/Gen/GenKind");
|
|
150
|
+
var isGenKind = (u) => isObject(u) && GenKindTypeId in u;
|
|
151
|
+
var GenKindImpl = class {
|
|
152
|
+
value;
|
|
153
|
+
constructor(value) {
|
|
154
|
+
this.value = value;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* @since 2.0.0
|
|
158
|
+
*/
|
|
159
|
+
get _F() {
|
|
160
|
+
return identity;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* @since 2.0.0
|
|
164
|
+
*/
|
|
165
|
+
get _R() {
|
|
166
|
+
return (_) => _;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* @since 2.0.0
|
|
170
|
+
*/
|
|
171
|
+
get _O() {
|
|
172
|
+
return (_) => _;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* @since 2.0.0
|
|
176
|
+
*/
|
|
177
|
+
get _E() {
|
|
178
|
+
return (_) => _;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @since 2.0.0
|
|
182
|
+
*/
|
|
183
|
+
[GenKindTypeId] = GenKindTypeId;
|
|
184
|
+
/**
|
|
185
|
+
* @since 2.0.0
|
|
186
|
+
*/
|
|
187
|
+
[Symbol.iterator]() {
|
|
188
|
+
return new SingleShotGen(this);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var SingleShotGen = class _SingleShotGen {
|
|
192
|
+
self;
|
|
193
|
+
called = false;
|
|
194
|
+
constructor(self) {
|
|
195
|
+
this.self = self;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @since 2.0.0
|
|
199
|
+
*/
|
|
200
|
+
next(a) {
|
|
201
|
+
return this.called ? {
|
|
202
|
+
value: a,
|
|
203
|
+
done: true
|
|
204
|
+
} : (this.called = true, {
|
|
205
|
+
value: this.self,
|
|
206
|
+
done: false
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @since 2.0.0
|
|
211
|
+
*/
|
|
212
|
+
return(a) {
|
|
213
|
+
return {
|
|
214
|
+
value: a,
|
|
215
|
+
done: true
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* @since 2.0.0
|
|
220
|
+
*/
|
|
221
|
+
throw(e) {
|
|
222
|
+
throw e;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* @since 2.0.0
|
|
226
|
+
*/
|
|
227
|
+
[Symbol.iterator]() {
|
|
228
|
+
return new _SingleShotGen(this.self);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
var MUL_HI = 1481765933 >>> 0;
|
|
232
|
+
var MUL_LO = 1284865837 >>> 0;
|
|
233
|
+
var YieldWrapTypeId = /* @__PURE__ */ Symbol.for("effect/Utils/YieldWrap");
|
|
234
|
+
var YieldWrap = class {
|
|
235
|
+
/**
|
|
236
|
+
* @since 3.0.6
|
|
237
|
+
*/
|
|
238
|
+
#value;
|
|
239
|
+
constructor(value) {
|
|
240
|
+
this.#value = value;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* @since 3.0.6
|
|
244
|
+
*/
|
|
245
|
+
[YieldWrapTypeId]() {
|
|
246
|
+
return this.#value;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
function yieldWrapGet(self) {
|
|
250
|
+
if (typeof self === "object" && self !== null && YieldWrapTypeId in self) {
|
|
251
|
+
return self[YieldWrapTypeId]();
|
|
252
|
+
}
|
|
253
|
+
throw new Error(getBugErrorMessage("yieldWrapGet"));
|
|
254
|
+
}
|
|
255
|
+
var structuralRegionState = /* @__PURE__ */ globalValue("effect/Utils/isStructuralRegion", () => ({
|
|
256
|
+
enabled: false,
|
|
257
|
+
tester: void 0
|
|
258
|
+
}));
|
|
259
|
+
var genConstructor = function* () {
|
|
260
|
+
}.constructor;
|
|
261
|
+
|
|
262
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Hash.js
|
|
263
|
+
var randomHashCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Hash/randomHashCache"), () => /* @__PURE__ */ new WeakMap());
|
|
264
|
+
var symbol = /* @__PURE__ */ Symbol.for("effect/Hash");
|
|
265
|
+
var hash = (self) => {
|
|
266
|
+
if (structuralRegionState.enabled === true) {
|
|
267
|
+
return 0;
|
|
268
|
+
}
|
|
269
|
+
switch (typeof self) {
|
|
270
|
+
case "number":
|
|
271
|
+
return number(self);
|
|
272
|
+
case "bigint":
|
|
273
|
+
return string(self.toString(10));
|
|
274
|
+
case "boolean":
|
|
275
|
+
return string(String(self));
|
|
276
|
+
case "symbol":
|
|
277
|
+
return string(String(self));
|
|
278
|
+
case "string":
|
|
279
|
+
return string(self);
|
|
280
|
+
case "undefined":
|
|
281
|
+
return string("undefined");
|
|
282
|
+
case "function":
|
|
283
|
+
case "object": {
|
|
284
|
+
if (self === null) {
|
|
285
|
+
return string("null");
|
|
286
|
+
} else if (self instanceof Date) {
|
|
287
|
+
return hash(self.toISOString());
|
|
288
|
+
} else if (isHash(self)) {
|
|
289
|
+
return self[symbol]();
|
|
290
|
+
} else {
|
|
291
|
+
return random(self);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
default:
|
|
295
|
+
throw new Error(`BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
var random = (self) => {
|
|
299
|
+
if (!randomHashCache.has(self)) {
|
|
300
|
+
randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)));
|
|
301
|
+
}
|
|
302
|
+
return randomHashCache.get(self);
|
|
303
|
+
};
|
|
304
|
+
var combine = (b) => (self) => self * 53 ^ b;
|
|
305
|
+
var optimize = (n) => n & 3221225471 | n >>> 1 & 1073741824;
|
|
306
|
+
var isHash = (u) => hasProperty(u, symbol);
|
|
307
|
+
var number = (n) => {
|
|
308
|
+
if (n !== n || n === Infinity) {
|
|
309
|
+
return 0;
|
|
310
|
+
}
|
|
311
|
+
let h = n | 0;
|
|
312
|
+
if (h !== n) {
|
|
313
|
+
h ^= n * 4294967295;
|
|
314
|
+
}
|
|
315
|
+
while (n > 4294967295) {
|
|
316
|
+
h ^= n /= 4294967295;
|
|
317
|
+
}
|
|
318
|
+
return optimize(h);
|
|
319
|
+
};
|
|
320
|
+
var string = (str) => {
|
|
321
|
+
let h = 5381, i = str.length;
|
|
322
|
+
while (i) {
|
|
323
|
+
h = h * 33 ^ str.charCodeAt(--i);
|
|
324
|
+
}
|
|
325
|
+
return optimize(h);
|
|
326
|
+
};
|
|
327
|
+
var structureKeys = (o, keys) => {
|
|
328
|
+
let h = 12289;
|
|
329
|
+
for (let i = 0; i < keys.length; i++) {
|
|
330
|
+
h ^= pipe(string(keys[i]), combine(hash(o[keys[i]])));
|
|
331
|
+
}
|
|
332
|
+
return optimize(h);
|
|
333
|
+
};
|
|
334
|
+
var structure = (o) => structureKeys(o, Object.keys(o));
|
|
335
|
+
var cached = function() {
|
|
336
|
+
if (arguments.length === 1) {
|
|
337
|
+
const self2 = arguments[0];
|
|
338
|
+
return function(hash3) {
|
|
339
|
+
Object.defineProperty(self2, symbol, {
|
|
340
|
+
value() {
|
|
341
|
+
return hash3;
|
|
342
|
+
},
|
|
343
|
+
enumerable: false
|
|
344
|
+
});
|
|
345
|
+
return hash3;
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
const self = arguments[0];
|
|
349
|
+
const hash2 = arguments[1];
|
|
350
|
+
Object.defineProperty(self, symbol, {
|
|
351
|
+
value() {
|
|
352
|
+
return hash2;
|
|
353
|
+
},
|
|
354
|
+
enumerable: false
|
|
355
|
+
});
|
|
356
|
+
return hash2;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Equal.js
|
|
360
|
+
var symbol2 = /* @__PURE__ */ Symbol.for("effect/Equal");
|
|
361
|
+
function equals() {
|
|
362
|
+
if (arguments.length === 1) {
|
|
363
|
+
return (self) => compareBoth(self, arguments[0]);
|
|
364
|
+
}
|
|
365
|
+
return compareBoth(arguments[0], arguments[1]);
|
|
366
|
+
}
|
|
367
|
+
function compareBoth(self, that) {
|
|
368
|
+
if (self === that) {
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
const selfType = typeof self;
|
|
372
|
+
if (selfType !== typeof that) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
if (selfType === "object" || selfType === "function") {
|
|
376
|
+
if (self !== null && that !== null) {
|
|
377
|
+
if (isEqual(self) && isEqual(that)) {
|
|
378
|
+
if (hash(self) === hash(that) && self[symbol2](that)) {
|
|
379
|
+
return true;
|
|
380
|
+
} else {
|
|
381
|
+
return structuralRegionState.enabled && structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
|
|
382
|
+
}
|
|
383
|
+
} else if (self instanceof Date && that instanceof Date) {
|
|
384
|
+
return self.toISOString() === that.toISOString();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (structuralRegionState.enabled) {
|
|
388
|
+
if (Array.isArray(self) && Array.isArray(that)) {
|
|
389
|
+
return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]));
|
|
390
|
+
}
|
|
391
|
+
if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {
|
|
392
|
+
const keysSelf = Object.keys(self);
|
|
393
|
+
const keysThat = Object.keys(that);
|
|
394
|
+
if (keysSelf.length === keysThat.length) {
|
|
395
|
+
for (const key of keysSelf) {
|
|
396
|
+
if (!(key in that && compareBoth(self[key], that[key]))) {
|
|
397
|
+
return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return structuralRegionState.enabled && structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
|
|
407
|
+
}
|
|
408
|
+
var isEqual = (u) => hasProperty(u, symbol2);
|
|
409
|
+
|
|
410
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Inspectable.js
|
|
411
|
+
var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
412
|
+
var toJSON = (x) => {
|
|
413
|
+
try {
|
|
414
|
+
if (hasProperty(x, "toJSON") && isFunction2(x["toJSON"]) && x["toJSON"].length === 0) {
|
|
415
|
+
return x.toJSON();
|
|
416
|
+
} else if (Array.isArray(x)) {
|
|
417
|
+
return x.map(toJSON);
|
|
418
|
+
}
|
|
419
|
+
} catch (_) {
|
|
420
|
+
return {};
|
|
421
|
+
}
|
|
422
|
+
return redact(x);
|
|
423
|
+
};
|
|
424
|
+
var format = (x) => JSON.stringify(x, null, 2);
|
|
425
|
+
var BaseProto = {
|
|
426
|
+
toJSON() {
|
|
427
|
+
return toJSON(this);
|
|
428
|
+
},
|
|
429
|
+
[NodeInspectSymbol]() {
|
|
430
|
+
return this.toJSON();
|
|
431
|
+
},
|
|
432
|
+
toString() {
|
|
433
|
+
return format(this.toJSON());
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
var Class = class {
|
|
437
|
+
/**
|
|
438
|
+
* @since 2.0.0
|
|
439
|
+
*/
|
|
440
|
+
[NodeInspectSymbol]() {
|
|
441
|
+
return this.toJSON();
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* @since 2.0.0
|
|
445
|
+
*/
|
|
446
|
+
toString() {
|
|
447
|
+
return format(this.toJSON());
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
var symbolRedactable = /* @__PURE__ */ Symbol.for("effect/Inspectable/Redactable");
|
|
451
|
+
var isRedactable = (u) => typeof u === "object" && u !== null && symbolRedactable in u;
|
|
452
|
+
var redactableState = /* @__PURE__ */ globalValue("effect/Inspectable/redactableState", () => ({
|
|
453
|
+
fiberRefs: void 0
|
|
454
|
+
}));
|
|
455
|
+
var redact = (u) => {
|
|
456
|
+
if (isRedactable(u) && redactableState.fiberRefs !== void 0) {
|
|
457
|
+
return u[symbolRedactable](redactableState.fiberRefs);
|
|
458
|
+
}
|
|
459
|
+
return u;
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Pipeable.js
|
|
463
|
+
var pipeArguments = (self, args) => {
|
|
464
|
+
switch (args.length) {
|
|
465
|
+
case 0:
|
|
466
|
+
return self;
|
|
467
|
+
case 1:
|
|
468
|
+
return args[0](self);
|
|
469
|
+
case 2:
|
|
470
|
+
return args[1](args[0](self));
|
|
471
|
+
case 3:
|
|
472
|
+
return args[2](args[1](args[0](self)));
|
|
473
|
+
case 4:
|
|
474
|
+
return args[3](args[2](args[1](args[0](self))));
|
|
475
|
+
case 5:
|
|
476
|
+
return args[4](args[3](args[2](args[1](args[0](self)))));
|
|
477
|
+
case 6:
|
|
478
|
+
return args[5](args[4](args[3](args[2](args[1](args[0](self))))));
|
|
479
|
+
case 7:
|
|
480
|
+
return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))));
|
|
481
|
+
case 8:
|
|
482
|
+
return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))));
|
|
483
|
+
case 9:
|
|
484
|
+
return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))));
|
|
485
|
+
default: {
|
|
486
|
+
let ret = self;
|
|
487
|
+
for (let i = 0, len = args.length; i < len; i++) {
|
|
488
|
+
ret = args[i](ret);
|
|
489
|
+
}
|
|
490
|
+
return ret;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/opCodes/effect.js
|
|
496
|
+
var OP_COMMIT = "Commit";
|
|
497
|
+
|
|
498
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/effectable.js
|
|
499
|
+
var EffectTypeId = /* @__PURE__ */ Symbol.for("effect/Effect");
|
|
500
|
+
var StreamTypeId = /* @__PURE__ */ Symbol.for("effect/Stream");
|
|
501
|
+
var SinkTypeId = /* @__PURE__ */ Symbol.for("effect/Sink");
|
|
502
|
+
var ChannelTypeId = /* @__PURE__ */ Symbol.for("effect/Channel");
|
|
503
|
+
var effectVariance = {
|
|
504
|
+
/* c8 ignore next */
|
|
505
|
+
_R: (_) => _,
|
|
506
|
+
/* c8 ignore next */
|
|
507
|
+
_E: (_) => _,
|
|
508
|
+
/* c8 ignore next */
|
|
509
|
+
_A: (_) => _,
|
|
510
|
+
_V: /* @__PURE__ */ getCurrentVersion()
|
|
511
|
+
};
|
|
512
|
+
var sinkVariance = {
|
|
513
|
+
/* c8 ignore next */
|
|
514
|
+
_A: (_) => _,
|
|
515
|
+
/* c8 ignore next */
|
|
516
|
+
_In: (_) => _,
|
|
517
|
+
/* c8 ignore next */
|
|
518
|
+
_L: (_) => _,
|
|
519
|
+
/* c8 ignore next */
|
|
520
|
+
_E: (_) => _,
|
|
521
|
+
/* c8 ignore next */
|
|
522
|
+
_R: (_) => _
|
|
523
|
+
};
|
|
524
|
+
var channelVariance = {
|
|
525
|
+
/* c8 ignore next */
|
|
526
|
+
_Env: (_) => _,
|
|
527
|
+
/* c8 ignore next */
|
|
528
|
+
_InErr: (_) => _,
|
|
529
|
+
/* c8 ignore next */
|
|
530
|
+
_InElem: (_) => _,
|
|
531
|
+
/* c8 ignore next */
|
|
532
|
+
_InDone: (_) => _,
|
|
533
|
+
/* c8 ignore next */
|
|
534
|
+
_OutErr: (_) => _,
|
|
535
|
+
/* c8 ignore next */
|
|
536
|
+
_OutElem: (_) => _,
|
|
537
|
+
/* c8 ignore next */
|
|
538
|
+
_OutDone: (_) => _
|
|
539
|
+
};
|
|
540
|
+
var EffectPrototype = {
|
|
541
|
+
[EffectTypeId]: effectVariance,
|
|
542
|
+
[StreamTypeId]: effectVariance,
|
|
543
|
+
[SinkTypeId]: sinkVariance,
|
|
544
|
+
[ChannelTypeId]: channelVariance,
|
|
545
|
+
[symbol2](that) {
|
|
546
|
+
return this === that;
|
|
547
|
+
},
|
|
548
|
+
[symbol]() {
|
|
549
|
+
return cached(this, random(this));
|
|
550
|
+
},
|
|
551
|
+
[Symbol.iterator]() {
|
|
552
|
+
return new SingleShotGen(new YieldWrap(this));
|
|
553
|
+
},
|
|
554
|
+
pipe() {
|
|
555
|
+
return pipeArguments(this, arguments);
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
var StructuralPrototype = {
|
|
559
|
+
[symbol]() {
|
|
560
|
+
return cached(this, structure(this));
|
|
561
|
+
},
|
|
562
|
+
[symbol2](that) {
|
|
563
|
+
const selfKeys = Object.keys(this);
|
|
564
|
+
const thatKeys = Object.keys(that);
|
|
565
|
+
if (selfKeys.length !== thatKeys.length) {
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
for (const key of selfKeys) {
|
|
569
|
+
if (!(key in that && equals(this[key], that[key]))) {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return true;
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
var CommitPrototype = {
|
|
577
|
+
...EffectPrototype,
|
|
578
|
+
_op: OP_COMMIT
|
|
579
|
+
};
|
|
580
|
+
var StructuralCommitPrototype = {
|
|
581
|
+
...CommitPrototype,
|
|
582
|
+
...StructuralPrototype
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/option.js
|
|
586
|
+
var TypeId = /* @__PURE__ */ Symbol.for("effect/Option");
|
|
587
|
+
var CommonProto = {
|
|
588
|
+
...EffectPrototype,
|
|
589
|
+
[TypeId]: {
|
|
590
|
+
_A: (_) => _
|
|
591
|
+
},
|
|
592
|
+
[NodeInspectSymbol]() {
|
|
593
|
+
return this.toJSON();
|
|
594
|
+
},
|
|
595
|
+
toString() {
|
|
596
|
+
return format(this.toJSON());
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
var SomeProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto), {
|
|
600
|
+
_tag: "Some",
|
|
601
|
+
_op: "Some",
|
|
602
|
+
[symbol2](that) {
|
|
603
|
+
return isOption(that) && isSome(that) && equals(this.value, that.value);
|
|
604
|
+
},
|
|
605
|
+
[symbol]() {
|
|
606
|
+
return cached(this, combine(hash(this._tag))(hash(this.value)));
|
|
607
|
+
},
|
|
608
|
+
toJSON() {
|
|
609
|
+
return {
|
|
610
|
+
_id: "Option",
|
|
611
|
+
_tag: this._tag,
|
|
612
|
+
value: toJSON(this.value)
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
var NoneHash = /* @__PURE__ */ hash("None");
|
|
617
|
+
var NoneProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto), {
|
|
618
|
+
_tag: "None",
|
|
619
|
+
_op: "None",
|
|
620
|
+
[symbol2](that) {
|
|
621
|
+
return isOption(that) && isNone(that);
|
|
622
|
+
},
|
|
623
|
+
[symbol]() {
|
|
624
|
+
return NoneHash;
|
|
625
|
+
},
|
|
626
|
+
toJSON() {
|
|
627
|
+
return {
|
|
628
|
+
_id: "Option",
|
|
629
|
+
_tag: this._tag
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
var isOption = (input) => hasProperty(input, TypeId);
|
|
634
|
+
var isNone = (fa) => fa._tag === "None";
|
|
635
|
+
var isSome = (fa) => fa._tag === "Some";
|
|
636
|
+
var none = /* @__PURE__ */ Object.create(NoneProto);
|
|
637
|
+
var some = (value) => {
|
|
638
|
+
const a = Object.create(SomeProto);
|
|
639
|
+
a.value = value;
|
|
640
|
+
return a;
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/either.js
|
|
644
|
+
var TypeId2 = /* @__PURE__ */ Symbol.for("effect/Either");
|
|
645
|
+
var CommonProto2 = {
|
|
646
|
+
...EffectPrototype,
|
|
647
|
+
[TypeId2]: {
|
|
648
|
+
_R: (_) => _
|
|
649
|
+
},
|
|
650
|
+
[NodeInspectSymbol]() {
|
|
651
|
+
return this.toJSON();
|
|
652
|
+
},
|
|
653
|
+
toString() {
|
|
654
|
+
return format(this.toJSON());
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
var RightProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto2), {
|
|
658
|
+
_tag: "Right",
|
|
659
|
+
_op: "Right",
|
|
660
|
+
[symbol2](that) {
|
|
661
|
+
return isEither(that) && isRight(that) && equals(this.right, that.right);
|
|
662
|
+
},
|
|
663
|
+
[symbol]() {
|
|
664
|
+
return combine(hash(this._tag))(hash(this.right));
|
|
665
|
+
},
|
|
666
|
+
toJSON() {
|
|
667
|
+
return {
|
|
668
|
+
_id: "Either",
|
|
669
|
+
_tag: this._tag,
|
|
670
|
+
right: toJSON(this.right)
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
var LeftProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto2), {
|
|
675
|
+
_tag: "Left",
|
|
676
|
+
_op: "Left",
|
|
677
|
+
[symbol2](that) {
|
|
678
|
+
return isEither(that) && isLeft(that) && equals(this.left, that.left);
|
|
679
|
+
},
|
|
680
|
+
[symbol]() {
|
|
681
|
+
return combine(hash(this._tag))(hash(this.left));
|
|
682
|
+
},
|
|
683
|
+
toJSON() {
|
|
684
|
+
return {
|
|
685
|
+
_id: "Either",
|
|
686
|
+
_tag: this._tag,
|
|
687
|
+
left: toJSON(this.left)
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
var isEither = (input) => hasProperty(input, TypeId2);
|
|
692
|
+
var isLeft = (ma) => ma._tag === "Left";
|
|
693
|
+
var isRight = (ma) => ma._tag === "Right";
|
|
694
|
+
var left = (left3) => {
|
|
695
|
+
const a = Object.create(LeftProto);
|
|
696
|
+
a.left = left3;
|
|
697
|
+
return a;
|
|
698
|
+
};
|
|
699
|
+
var right = (right3) => {
|
|
700
|
+
const a = Object.create(RightProto);
|
|
701
|
+
a.right = right3;
|
|
702
|
+
return a;
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Either.js
|
|
706
|
+
var right2 = right;
|
|
707
|
+
var left2 = left;
|
|
708
|
+
var isLeft2 = isLeft;
|
|
709
|
+
var isRight2 = isRight;
|
|
710
|
+
var map = /* @__PURE__ */ dual(2, (self, f) => isRight2(self) ? right2(f(self.right)) : left2(self.left));
|
|
711
|
+
var getOrElse = /* @__PURE__ */ dual(2, (self, onLeft) => isLeft2(self) ? onLeft(self.left) : self.right);
|
|
712
|
+
|
|
713
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Order.js
|
|
714
|
+
var make = (compare) => (self, that) => self === that ? 0 : compare(self, that);
|
|
715
|
+
|
|
716
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Option.js
|
|
717
|
+
var none2 = () => none;
|
|
718
|
+
var some2 = some;
|
|
719
|
+
var isNone2 = isNone;
|
|
720
|
+
var isSome2 = isSome;
|
|
721
|
+
var match = /* @__PURE__ */ dual(2, (self, {
|
|
722
|
+
onNone,
|
|
723
|
+
onSome
|
|
724
|
+
}) => isNone2(self) ? onNone() : onSome(self.value));
|
|
725
|
+
|
|
726
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Array.js
|
|
727
|
+
var isArray = Array.isArray;
|
|
728
|
+
var isEmptyArray = (self) => self.length === 0;
|
|
729
|
+
var isEmptyReadonlyArray = isEmptyArray;
|
|
730
|
+
var sort = /* @__PURE__ */ dual(2, (self, O) => {
|
|
731
|
+
const out = Array.from(self);
|
|
732
|
+
out.sort(O);
|
|
733
|
+
return out;
|
|
734
|
+
});
|
|
735
|
+
var map2 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
|
|
736
|
+
var flatMap = /* @__PURE__ */ dual(2, (self, f) => {
|
|
737
|
+
if (isEmptyReadonlyArray(self)) {
|
|
738
|
+
return [];
|
|
739
|
+
}
|
|
740
|
+
const out = [];
|
|
741
|
+
for (let i = 0; i < self.length; i++) {
|
|
742
|
+
const inner = f(self[i], i);
|
|
743
|
+
for (let j = 0; j < inner.length; j++) {
|
|
744
|
+
out.push(inner[j]);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
return out;
|
|
748
|
+
});
|
|
749
|
+
var flatten = /* @__PURE__ */ flatMap(identity);
|
|
750
|
+
|
|
751
|
+
// src/core/Nano.ts
|
|
752
|
+
var NanoDefectException = class {
|
|
753
|
+
constructor(message) {
|
|
754
|
+
this.message = message;
|
|
755
|
+
}
|
|
756
|
+
_tag = "@effect/language-service/NanoDefectException";
|
|
757
|
+
};
|
|
758
|
+
var NanoTag = class {
|
|
759
|
+
constructor(key) {
|
|
760
|
+
this.key = key;
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
var Tag = (identifier) => new NanoTag(identifier);
|
|
764
|
+
var contextEmpty = { value: {} };
|
|
765
|
+
var contextAdd = (context, tag, value) => ({
|
|
766
|
+
...context,
|
|
767
|
+
value: {
|
|
768
|
+
...context.value,
|
|
769
|
+
[tag.key]: value
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
var contextGet = (context, tag) => {
|
|
773
|
+
if (tag.key in context.value) {
|
|
774
|
+
return some2(context.value[tag.key]);
|
|
775
|
+
}
|
|
776
|
+
return none2();
|
|
777
|
+
};
|
|
778
|
+
var Nano = class {
|
|
779
|
+
constructor(run2) {
|
|
780
|
+
this.run = run2;
|
|
781
|
+
}
|
|
782
|
+
[Symbol.iterator]() {
|
|
783
|
+
return new SingleShotGen(new YieldWrap(this));
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
var unsafeRun = (fa) => {
|
|
787
|
+
const result = fa.run(contextEmpty);
|
|
788
|
+
switch (result._tag) {
|
|
789
|
+
case "Left":
|
|
790
|
+
return left2(result.left);
|
|
791
|
+
case "Defect":
|
|
792
|
+
return left2(new NanoDefectException(result.defect));
|
|
793
|
+
case "Right":
|
|
794
|
+
return right2(result.right);
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
var run = (fa) => {
|
|
798
|
+
try {
|
|
799
|
+
return unsafeRun(fa);
|
|
800
|
+
} catch (e) {
|
|
801
|
+
return left2(new NanoDefectException(e));
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
var succeed = (value) => new Nano(() => ({ _tag: "Right", right: value }));
|
|
805
|
+
var fail = (value) => new Nano(() => ({ _tag: "Left", left: value }));
|
|
806
|
+
var sync = (value) => new Nano(() => ({ _tag: "Right", right: value() }));
|
|
807
|
+
var flatMap2 = dual(2, (fa, f) => new Nano((ctx) => {
|
|
808
|
+
const result = fa.run(ctx);
|
|
809
|
+
if (result._tag !== "Right") return result;
|
|
810
|
+
return f(result.right).run(ctx);
|
|
811
|
+
}));
|
|
812
|
+
var map3 = dual(2, (fa, f) => new Nano((ctx) => {
|
|
813
|
+
const result = fa.run(ctx);
|
|
814
|
+
if (result._tag !== "Right") return result;
|
|
815
|
+
return { _tag: "Right", right: f(result.right) };
|
|
816
|
+
}));
|
|
817
|
+
var orElse = (f) => (fa) => new Nano((ctx) => {
|
|
818
|
+
const result = fa.run(ctx);
|
|
819
|
+
if (result._tag === "Left") return f().run(ctx);
|
|
820
|
+
return result;
|
|
821
|
+
});
|
|
822
|
+
var service = (tag) => new Nano(
|
|
823
|
+
(ctx) => contextGet(ctx, tag).pipe(match({
|
|
824
|
+
onNone: () => ({ _tag: "Defect", defect: `Cannot find service ${tag.key}` }),
|
|
825
|
+
onSome: (value) => ({ _tag: "Right", right: value })
|
|
826
|
+
}))
|
|
827
|
+
);
|
|
828
|
+
var provideService = (tag, value) => (fa) => new Nano((ctx) => {
|
|
829
|
+
return fa.run(contextAdd(ctx, tag, value));
|
|
830
|
+
});
|
|
831
|
+
var gen = (...args) => new Nano((ctx) => {
|
|
832
|
+
const iterator = args[0]();
|
|
833
|
+
let state = iterator.next();
|
|
834
|
+
while (!state.done) {
|
|
835
|
+
const current = isGenKind(state.value) ? state.value.value : yieldWrapGet(state.value);
|
|
836
|
+
const result = current.run(ctx);
|
|
837
|
+
if (result._tag !== "Right") {
|
|
838
|
+
return result;
|
|
839
|
+
}
|
|
840
|
+
state = iterator.next(result.right);
|
|
841
|
+
}
|
|
842
|
+
return { _tag: "Right", right: state.value };
|
|
843
|
+
});
|
|
844
|
+
var fn = (_) => (body) => (...args) => new Nano((ctx) => {
|
|
845
|
+
const iterator = body(...args);
|
|
846
|
+
let state = iterator.next();
|
|
847
|
+
while (!state.done) {
|
|
848
|
+
const current = isGenKind(state.value) ? state.value.value : yieldWrapGet(state.value);
|
|
849
|
+
const result = current.run(ctx);
|
|
850
|
+
if (result._tag !== "Right") {
|
|
851
|
+
return result;
|
|
852
|
+
}
|
|
853
|
+
state = iterator.next(result.right);
|
|
854
|
+
}
|
|
855
|
+
return { _tag: "Right", right: state.value };
|
|
856
|
+
});
|
|
857
|
+
var option = (fa) => new Nano((ctx) => {
|
|
858
|
+
const result = fa.run(ctx);
|
|
859
|
+
switch (result._tag) {
|
|
860
|
+
case "Right":
|
|
861
|
+
return { _tag: "Right", right: some2(result.right) };
|
|
862
|
+
case "Left":
|
|
863
|
+
return { _tag: "Right", right: none2() };
|
|
864
|
+
case "Defect":
|
|
865
|
+
return result;
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
// src/core/TypeScriptApi.ts
|
|
870
|
+
var TypeScriptApi = Tag("TypeScriptApi");
|
|
871
|
+
var TypeScriptProgram = Tag("TypeScriptProgram");
|
|
872
|
+
var ChangeTracker = Tag("ChangeTracker");
|
|
873
|
+
|
|
874
|
+
// src/core/LSP.ts
|
|
875
|
+
var RefactorNotApplicableError = class {
|
|
876
|
+
_tag = "@effect/language-service/RefactorNotApplicableError";
|
|
877
|
+
};
|
|
878
|
+
function createDiagnostic(definition) {
|
|
879
|
+
return definition;
|
|
880
|
+
}
|
|
881
|
+
function parsePluginOptions(config) {
|
|
882
|
+
return {
|
|
883
|
+
diagnostics: config && "diagnostics" in config && typeof config.diagnostics === "boolean" ? config.diagnostics : true,
|
|
884
|
+
quickinfo: config && "quickinfo" in config && typeof config.quickinfo === "boolean" ? config.quickinfo : true,
|
|
885
|
+
completions: config && "completions" in config && typeof config.completions === "boolean" ? config.completions : true,
|
|
886
|
+
multipleEffectCheck: config && "multipleEffectCheck" in config && typeof config.multipleEffectCheck === "boolean" ? config.multipleEffectCheck : true
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
var PluginOptions = Tag("PluginOptions");
|
|
890
|
+
var getSemanticDiagnosticsWithCodeFixes = fn("LSP.getSemanticDiagnostics")(function* (rules, sourceFile) {
|
|
891
|
+
const effectDiagnostics = [];
|
|
892
|
+
const effectCodeFixes = [];
|
|
893
|
+
const executor = yield* createDiagnosticExecutor(sourceFile);
|
|
894
|
+
for (const rule of rules) {
|
|
895
|
+
const result = yield* option(executor.execute(rule));
|
|
896
|
+
if (isSome2(result)) {
|
|
897
|
+
effectDiagnostics.push(
|
|
898
|
+
...pipe(
|
|
899
|
+
result.value,
|
|
900
|
+
map2((_) => ({
|
|
901
|
+
file: sourceFile,
|
|
902
|
+
start: _.node.getStart(sourceFile),
|
|
903
|
+
length: _.node.getEnd() - _.node.getStart(sourceFile),
|
|
904
|
+
messageText: _.messageText,
|
|
905
|
+
category: _.category,
|
|
906
|
+
code: rule.code,
|
|
907
|
+
source: "effect"
|
|
908
|
+
}))
|
|
909
|
+
)
|
|
910
|
+
);
|
|
911
|
+
effectCodeFixes.push(
|
|
912
|
+
...pipe(
|
|
913
|
+
result.value,
|
|
914
|
+
map2(
|
|
915
|
+
(_) => map2(
|
|
916
|
+
_.fixes,
|
|
917
|
+
(fix) => ({
|
|
918
|
+
...fix,
|
|
919
|
+
code: rule.code,
|
|
920
|
+
start: _.node.getStart(sourceFile),
|
|
921
|
+
end: _.node.getEnd()
|
|
922
|
+
})
|
|
923
|
+
)
|
|
924
|
+
),
|
|
925
|
+
flatten
|
|
926
|
+
)
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
return {
|
|
931
|
+
diagnostics: effectDiagnostics,
|
|
932
|
+
codeFixes: effectCodeFixes
|
|
933
|
+
};
|
|
934
|
+
});
|
|
935
|
+
var getApplicableRefactors = fn("LSP.getApplicableRefactors")(function* (refactors, sourceFile, positionOrRange) {
|
|
936
|
+
const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
|
|
937
|
+
const effectRefactors = [];
|
|
938
|
+
for (const refactor of refactors) {
|
|
939
|
+
const result = yield* option(refactor.apply(sourceFile, textRange));
|
|
940
|
+
if (isSome2(result)) {
|
|
941
|
+
effectRefactors.push({
|
|
942
|
+
name: refactor.name,
|
|
943
|
+
description: refactor.description,
|
|
944
|
+
actions: [{
|
|
945
|
+
name: refactor.name,
|
|
946
|
+
description: result.value.description,
|
|
947
|
+
kind: result.value.kind
|
|
948
|
+
}]
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return effectRefactors;
|
|
953
|
+
});
|
|
954
|
+
var getEditsForRefactor = fn("LSP.getEditsForRefactor")(function* (refactors, sourceFile, positionOrRange, refactorName) {
|
|
955
|
+
const refactor = refactors.find((refactor2) => refactor2.name === refactorName);
|
|
956
|
+
if (!refactor) {
|
|
957
|
+
return yield* fail(new RefactorNotApplicableError());
|
|
958
|
+
}
|
|
959
|
+
const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
|
|
960
|
+
return yield* refactor.apply(sourceFile, textRange);
|
|
961
|
+
});
|
|
962
|
+
var getCompletionsAtPosition = fn("LSP.getCompletionsAtPosition")(function* (completions, sourceFile, position, options, formatCodeSettings) {
|
|
963
|
+
const effectCompletions = [];
|
|
964
|
+
for (const completion of completions) {
|
|
965
|
+
const result = yield* completion.apply(sourceFile, position, options, formatCodeSettings);
|
|
966
|
+
effectCompletions.push(
|
|
967
|
+
...result.map((_) => ({ sortText: "11", ..._ }))
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
return effectCompletions;
|
|
971
|
+
});
|
|
972
|
+
var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
973
|
+
function* (sourceFile) {
|
|
974
|
+
const ts = yield* service(TypeScriptApi);
|
|
975
|
+
const ruleOverrides = {};
|
|
976
|
+
const skippedRules = [];
|
|
977
|
+
const regex = /@effect-diagnostics((?:\s[a-zA-Z0-9/]+:(?:off|warning|error|message|suggestion|skip-file))+)?/gm;
|
|
978
|
+
let match2;
|
|
979
|
+
while ((match2 = regex.exec(sourceFile.text)) !== null) {
|
|
980
|
+
const rulesCaptureGroup = match2[1];
|
|
981
|
+
if (rulesCaptureGroup) {
|
|
982
|
+
const trimmedRuleString = rulesCaptureGroup.trim();
|
|
983
|
+
if (trimmedRuleString) {
|
|
984
|
+
const individualRules = trimmedRuleString.split(/\s+/);
|
|
985
|
+
for (const rulePair of individualRules) {
|
|
986
|
+
const [ruleName, ruleLevel] = rulePair.toLowerCase().split(":");
|
|
987
|
+
if (ruleName && ruleLevel) {
|
|
988
|
+
if (ruleLevel === "skip-file") skippedRules.push(ruleName);
|
|
989
|
+
ruleOverrides[ruleName] = ruleOverrides[ruleName] || [];
|
|
990
|
+
const newLength = ruleOverrides[ruleName].push({
|
|
991
|
+
start: match2.index,
|
|
992
|
+
end: Number.MAX_SAFE_INTEGER,
|
|
993
|
+
level: ruleLevel
|
|
994
|
+
});
|
|
995
|
+
if (newLength > 1) ruleOverrides[ruleName][newLength - 2].end = match2.index;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
const levelToDiagnosticCategory = {
|
|
1002
|
+
error: ts.DiagnosticCategory.Error,
|
|
1003
|
+
warning: ts.DiagnosticCategory.Warning,
|
|
1004
|
+
message: ts.DiagnosticCategory.Message,
|
|
1005
|
+
suggestion: ts.DiagnosticCategory.Suggestion
|
|
1006
|
+
};
|
|
1007
|
+
const execute = fn("LSP.ruleExecutor")(function* (rule) {
|
|
1008
|
+
const ruleNameLowered = rule.name.toLowerCase();
|
|
1009
|
+
if (skippedRules.indexOf(ruleNameLowered) > -1) return [];
|
|
1010
|
+
let modifiedDiagnostics = yield* rule.apply(sourceFile);
|
|
1011
|
+
for (const override of ruleOverrides[ruleNameLowered] || []) {
|
|
1012
|
+
if (override.level === "off") {
|
|
1013
|
+
modifiedDiagnostics = modifiedDiagnostics.filter(
|
|
1014
|
+
(_) => !(_.node.getStart(sourceFile) >= override.start && _.node.getEnd() <= override.end)
|
|
1015
|
+
);
|
|
1016
|
+
} else {
|
|
1017
|
+
for (const message of modifiedDiagnostics.filter(
|
|
1018
|
+
(_) => _.node.getStart(sourceFile) >= override.start && _.node.getEnd() <= override.end
|
|
1019
|
+
)) {
|
|
1020
|
+
message.category = override.level in levelToDiagnosticCategory ? levelToDiagnosticCategory[override.level] : message.category;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
const fixByDisableEntireFile = {
|
|
1025
|
+
fixName: rule.name + "_skipFile",
|
|
1026
|
+
description: "Disable " + rule.name + " for this file",
|
|
1027
|
+
apply: flatMap2(
|
|
1028
|
+
service(ChangeTracker),
|
|
1029
|
+
(changeTracker) => sync(
|
|
1030
|
+
() => changeTracker.insertText(
|
|
1031
|
+
sourceFile,
|
|
1032
|
+
0,
|
|
1033
|
+
`/** @effect-diagnostics ${rule.name}:skip-file */
|
|
1034
|
+
`
|
|
1035
|
+
)
|
|
1036
|
+
)
|
|
1037
|
+
)
|
|
1038
|
+
};
|
|
1039
|
+
const rulesWithDisableFix = modifiedDiagnostics.map((diagnostic) => ({
|
|
1040
|
+
...diagnostic,
|
|
1041
|
+
fixes: diagnostic.fixes.concat([fixByDisableEntireFile])
|
|
1042
|
+
}));
|
|
1043
|
+
return rulesWithDisableFix;
|
|
1044
|
+
});
|
|
1045
|
+
return { execute };
|
|
1046
|
+
}
|
|
1047
|
+
);
|
|
1048
|
+
|
|
1049
|
+
// src/core/TypeCheckerApi.ts
|
|
1050
|
+
var TypeCheckerApi = Tag("TypeChecker");
|
|
1051
|
+
var TypeCheckerApiCache = Tag("TypeCheckerApiCache");
|
|
1052
|
+
function makeTypeCheckerApiCache() {
|
|
1053
|
+
return {
|
|
1054
|
+
expectedAndRealType: /* @__PURE__ */ new WeakMap()
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
var deterministicTypeOrder = gen(function* () {
|
|
1058
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1059
|
+
return make((a, b) => {
|
|
1060
|
+
const aName = typeChecker.typeToString(a);
|
|
1061
|
+
const bName = typeChecker.typeToString(b);
|
|
1062
|
+
if (aName < bName) return -1;
|
|
1063
|
+
if (aName > bName) return 1;
|
|
1064
|
+
return 0;
|
|
1065
|
+
});
|
|
1066
|
+
});
|
|
1067
|
+
var getMissingTypeEntriesInTargetType = fn(
|
|
1068
|
+
"TypeCheckerApi.getMissingTypeEntriesInTargetType"
|
|
1069
|
+
)(
|
|
1070
|
+
function* (realType, expectedType) {
|
|
1071
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1072
|
+
const result = [];
|
|
1073
|
+
const toTest = [realType];
|
|
1074
|
+
while (toTest.length > 0) {
|
|
1075
|
+
const type = toTest.pop();
|
|
1076
|
+
if (!type) return result;
|
|
1077
|
+
if (type.isUnion()) {
|
|
1078
|
+
toTest.push(...type.types);
|
|
1079
|
+
} else {
|
|
1080
|
+
const assignable = typeChecker.isTypeAssignableTo(type, expectedType);
|
|
1081
|
+
if (!assignable) {
|
|
1082
|
+
result.push(type);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
return result;
|
|
1087
|
+
}
|
|
1088
|
+
);
|
|
1089
|
+
var CannotFindAncestorConvertibleDeclarationError = class {
|
|
1090
|
+
constructor(node) {
|
|
1091
|
+
this.node = node;
|
|
1092
|
+
}
|
|
1093
|
+
_tag = "@effect/language-service/CannotFindAncestorConvertibleDeclarationError";
|
|
1094
|
+
};
|
|
1095
|
+
var getAncestorConvertibleDeclaration = fn(
|
|
1096
|
+
"TypeCheckerApi.getAncestorConvertibleDeclaration"
|
|
1097
|
+
)(function* (node) {
|
|
1098
|
+
const ts = yield* service(TypeScriptApi);
|
|
1099
|
+
let current = node;
|
|
1100
|
+
while (current) {
|
|
1101
|
+
if (ts.isFunctionDeclaration(current) || ts.isFunctionExpression(current) || ts.isArrowFunction(current) || ts.isMethodDeclaration(current)) {
|
|
1102
|
+
return current;
|
|
1103
|
+
}
|
|
1104
|
+
current = current.parent;
|
|
1105
|
+
}
|
|
1106
|
+
return yield* fail(new CannotFindAncestorConvertibleDeclarationError(node));
|
|
1107
|
+
});
|
|
1108
|
+
var CannotInferReturnTypeFromEmptyBody = class {
|
|
1109
|
+
constructor(declaration) {
|
|
1110
|
+
this.declaration = declaration;
|
|
1111
|
+
}
|
|
1112
|
+
_tag = "@effect/language-service/CannotInferReturnTypeFromEmptyBody";
|
|
1113
|
+
};
|
|
1114
|
+
var CannotInferReturnType = class {
|
|
1115
|
+
constructor(declaration) {
|
|
1116
|
+
this.declaration = declaration;
|
|
1117
|
+
}
|
|
1118
|
+
_tag = "@effect/language-service/CannotInferReturnType";
|
|
1119
|
+
};
|
|
1120
|
+
var getInferredReturnType = fn("TypeCheckerApi.getInferredReturnType")(function* (declaration) {
|
|
1121
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1122
|
+
if (!declaration.body) {
|
|
1123
|
+
return yield* fail(
|
|
1124
|
+
new CannotInferReturnTypeFromEmptyBody(declaration)
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
let returnType;
|
|
1128
|
+
if (typeChecker.isImplementationOfOverload(declaration)) {
|
|
1129
|
+
const signatures = typeChecker.getTypeAtLocation(declaration).getCallSignatures();
|
|
1130
|
+
if (signatures.length > 1) {
|
|
1131
|
+
returnType = typeChecker.getUnionType(
|
|
1132
|
+
signatures.map((s) => s.getReturnType()).filter((_) => !!_)
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
if (!returnType) {
|
|
1137
|
+
const signature = typeChecker.getSignatureFromDeclaration(declaration);
|
|
1138
|
+
if (signature) {
|
|
1139
|
+
const typePredicate = typeChecker.getTypePredicateOfSignature(signature);
|
|
1140
|
+
if (typePredicate && typePredicate.type) {
|
|
1141
|
+
return typePredicate.type;
|
|
1142
|
+
} else {
|
|
1143
|
+
returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
if (!returnType) {
|
|
1148
|
+
return yield* fail(
|
|
1149
|
+
new CannotInferReturnType(declaration)
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
return returnType;
|
|
1153
|
+
});
|
|
1154
|
+
var expectedAndRealType = fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
|
|
1155
|
+
const cache = yield* service(TypeCheckerApiCache);
|
|
1156
|
+
const resultCached = cache.expectedAndRealType.get(sourceFile);
|
|
1157
|
+
if (resultCached) return resultCached;
|
|
1158
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1159
|
+
const ts = yield* service(TypeScriptApi);
|
|
1160
|
+
const result = [];
|
|
1161
|
+
const nodeToVisit = [sourceFile];
|
|
1162
|
+
const appendNodeToVisit = (node) => {
|
|
1163
|
+
nodeToVisit.push(node);
|
|
1164
|
+
return void 0;
|
|
1165
|
+
};
|
|
1166
|
+
while (nodeToVisit.length > 0) {
|
|
1167
|
+
const node = nodeToVisit.shift();
|
|
1168
|
+
if (ts.isVariableDeclaration(node) && node.initializer) {
|
|
1169
|
+
const expectedType = typeChecker.getTypeAtLocation(node.name);
|
|
1170
|
+
const realType = typeChecker.getTypeAtLocation(node.initializer);
|
|
1171
|
+
result.push([node.name, expectedType, node.initializer, realType]);
|
|
1172
|
+
appendNodeToVisit(node.initializer);
|
|
1173
|
+
continue;
|
|
1174
|
+
} else if (ts.isCallExpression(node)) {
|
|
1175
|
+
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
1176
|
+
if (resolvedSignature) {
|
|
1177
|
+
resolvedSignature.getParameters().map((parameter, index) => {
|
|
1178
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
|
|
1179
|
+
const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
|
|
1180
|
+
result.push([
|
|
1181
|
+
node.arguments[index],
|
|
1182
|
+
expectedType,
|
|
1183
|
+
node.arguments[index],
|
|
1184
|
+
realType
|
|
1185
|
+
]);
|
|
1186
|
+
});
|
|
1187
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
1188
|
+
continue;
|
|
1189
|
+
}
|
|
1190
|
+
} else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
1191
|
+
const parent = node.parent;
|
|
1192
|
+
if (ts.isObjectLiteralElement(parent)) {
|
|
1193
|
+
if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
|
|
1194
|
+
const type = typeChecker.getContextualType(parent.parent);
|
|
1195
|
+
if (type) {
|
|
1196
|
+
const symbol3 = typeChecker.getPropertyOfType(type, node.text);
|
|
1197
|
+
if (symbol3) {
|
|
1198
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
|
|
1199
|
+
const realType = typeChecker.getTypeAtLocation(node);
|
|
1200
|
+
result.push([node, expectedType, node, realType]);
|
|
1201
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
} else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
1208
|
+
const expectedType = typeChecker.getTypeAtLocation(node.left);
|
|
1209
|
+
const realType = typeChecker.getTypeAtLocation(node.right);
|
|
1210
|
+
result.push([node.left, expectedType, node.right, realType]);
|
|
1211
|
+
appendNodeToVisit(node.right);
|
|
1212
|
+
continue;
|
|
1213
|
+
} else if (ts.isReturnStatement(node) && node.expression) {
|
|
1214
|
+
const parentDeclaration = yield* option(getAncestorConvertibleDeclaration(node));
|
|
1215
|
+
if (isSome2(parentDeclaration)) {
|
|
1216
|
+
const expectedType = yield* option(getInferredReturnType(parentDeclaration.value));
|
|
1217
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
1218
|
+
if (isSome2(expectedType)) {
|
|
1219
|
+
result.push([node, expectedType.value, node, realType]);
|
|
1220
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
} else if (ts.isArrowFunction(node) && ts.isExpression(node.body)) {
|
|
1225
|
+
const body = node.body;
|
|
1226
|
+
const expectedType = typeChecker.getContextualType(body);
|
|
1227
|
+
const realType = typeChecker.getTypeAtLocation(body);
|
|
1228
|
+
if (expectedType) {
|
|
1229
|
+
result.push([body, expectedType, body, realType]);
|
|
1230
|
+
appendNodeToVisit(body);
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
} else if (ts.isSatisfiesExpression(node)) {
|
|
1234
|
+
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
1235
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
1236
|
+
result.push([node.expression, expectedType, node.expression, realType]);
|
|
1237
|
+
appendNodeToVisit(node.expression);
|
|
1238
|
+
continue;
|
|
1239
|
+
}
|
|
1240
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
1241
|
+
}
|
|
1242
|
+
cache.expectedAndRealType.set(sourceFile, result);
|
|
1243
|
+
return result;
|
|
1244
|
+
});
|
|
1245
|
+
|
|
1246
|
+
// src/utils/TypeParser.ts
|
|
1247
|
+
var TypeParserIssue = class {
|
|
1248
|
+
constructor(type, node, message) {
|
|
1249
|
+
this.type = type;
|
|
1250
|
+
this.node = node;
|
|
1251
|
+
this.message = message;
|
|
1252
|
+
}
|
|
1253
|
+
_tag = "@effect/language-service/TypeParserIssue";
|
|
1254
|
+
};
|
|
1255
|
+
function typeParserIssue(message, type, node) {
|
|
1256
|
+
return fail(new TypeParserIssue(type, node, message));
|
|
1257
|
+
}
|
|
1258
|
+
function covariantTypeArgument(type) {
|
|
1259
|
+
const signatures = type.getCallSignatures();
|
|
1260
|
+
if (signatures.length !== 1) {
|
|
1261
|
+
return typeParserIssue("Covariant type has no call signature", type);
|
|
1262
|
+
}
|
|
1263
|
+
return succeed(signatures[0].getReturnType());
|
|
1264
|
+
}
|
|
1265
|
+
function invariantTypeArgument(type) {
|
|
1266
|
+
const signatures = type.getCallSignatures();
|
|
1267
|
+
if (signatures.length !== 1) {
|
|
1268
|
+
return typeParserIssue("Invariant type has no call signature", type);
|
|
1269
|
+
}
|
|
1270
|
+
return succeed(signatures[0].getReturnType());
|
|
1271
|
+
}
|
|
1272
|
+
var pipeableType = fn("TypeParser.pipeableType")(function* (type, atLocation) {
|
|
1273
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1274
|
+
const pipeSymbol = typeChecker.getPropertyOfType(type, "pipe");
|
|
1275
|
+
if (!pipeSymbol) {
|
|
1276
|
+
return yield* typeParserIssue("Type has no 'pipe' property", type, atLocation);
|
|
1277
|
+
}
|
|
1278
|
+
const pipeType = typeChecker.getTypeOfSymbolAtLocation(pipeSymbol, atLocation);
|
|
1279
|
+
const signatures = pipeType.getCallSignatures();
|
|
1280
|
+
if (signatures.length === 0) {
|
|
1281
|
+
return yield* typeParserIssue("'pipe' property is not callable", type, atLocation);
|
|
1282
|
+
}
|
|
1283
|
+
return type;
|
|
1284
|
+
});
|
|
1285
|
+
var varianceStructCovariantType = fn("TypeParser.varianceStructCovariantType")(
|
|
1286
|
+
function* (type, atLocation, propertyName) {
|
|
1287
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1288
|
+
const propertySymbol = typeChecker.getPropertyOfType(type, propertyName);
|
|
1289
|
+
if (!propertySymbol) {
|
|
1290
|
+
return yield* typeParserIssue(`Type has no '${propertyName}' property`, type, atLocation);
|
|
1291
|
+
}
|
|
1292
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
1293
|
+
return yield* covariantTypeArgument(propertyType);
|
|
1294
|
+
}
|
|
1295
|
+
);
|
|
1296
|
+
var varianceStructInvariantType = fn("TypeParser.varianceStructInvariantType")(
|
|
1297
|
+
function* (type, atLocation, propertyName) {
|
|
1298
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1299
|
+
const propertySymbol = typeChecker.getPropertyOfType(type, propertyName);
|
|
1300
|
+
if (!propertySymbol) {
|
|
1301
|
+
return yield* typeParserIssue(`Type has no '${propertyName}' property`, type, atLocation);
|
|
1302
|
+
}
|
|
1303
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
1304
|
+
return yield* invariantTypeArgument(propertyType);
|
|
1305
|
+
}
|
|
1306
|
+
);
|
|
1307
|
+
var effectVarianceStruct = fn("TypeParser.effectVarianceStruct")(function* (type, atLocation) {
|
|
1308
|
+
return {
|
|
1309
|
+
A: yield* varianceStructCovariantType(type, atLocation, "_A"),
|
|
1310
|
+
E: yield* varianceStructCovariantType(type, atLocation, "_E"),
|
|
1311
|
+
R: yield* varianceStructCovariantType(type, atLocation, "_R")
|
|
1312
|
+
};
|
|
1313
|
+
});
|
|
1314
|
+
var effectType = fn("TypeParser.effectType")(function* (type, atLocation) {
|
|
1315
|
+
const ts = yield* service(TypeScriptApi);
|
|
1316
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1317
|
+
yield* pipeableType(type, atLocation);
|
|
1318
|
+
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
1319
|
+
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional)
|
|
1320
|
+
);
|
|
1321
|
+
propertiesSymbols.sort((a, b) => b.name.indexOf("EffectTypeId") - a.name.indexOf("EffectTypeId"));
|
|
1322
|
+
for (const propertySymbol of propertiesSymbols) {
|
|
1323
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
1324
|
+
const varianceArgs = yield* option(effectVarianceStruct(
|
|
1325
|
+
propertyType,
|
|
1326
|
+
atLocation
|
|
1327
|
+
));
|
|
1328
|
+
if (isSome2(varianceArgs)) {
|
|
1329
|
+
return varianceArgs.value;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
return yield* typeParserIssue("Type has no effect variance struct", type, atLocation);
|
|
1333
|
+
});
|
|
1334
|
+
var fiberType = fn("TypeParser.fiberType")(function* (type, atLocation) {
|
|
1335
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1336
|
+
const awaitSymbol = typeChecker.getPropertyOfType(type, "await");
|
|
1337
|
+
const pollSymbol = typeChecker.getPropertyOfType(type, "poll");
|
|
1338
|
+
if (!awaitSymbol || !pollSymbol) {
|
|
1339
|
+
return yield* typeParserIssue(
|
|
1340
|
+
"Type is not a fiber because it does not have 'await' or 'poll' property",
|
|
1341
|
+
type,
|
|
1342
|
+
atLocation
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1345
|
+
return yield* effectType(type, atLocation);
|
|
1346
|
+
});
|
|
1347
|
+
var effectSubtype = fn("TypeParser.effectSubtype")(function* (type, atLocation) {
|
|
1348
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1349
|
+
const tagSymbol = typeChecker.getPropertyOfType(type, "_tag");
|
|
1350
|
+
if (!tagSymbol) {
|
|
1351
|
+
return yield* typeParserIssue(
|
|
1352
|
+
"Type is not a subtype of effect because it does not have '_tag' property",
|
|
1353
|
+
type,
|
|
1354
|
+
atLocation
|
|
1355
|
+
);
|
|
1356
|
+
}
|
|
1357
|
+
return yield* effectType(type, atLocation);
|
|
1358
|
+
});
|
|
1359
|
+
var importedEffectModule = fn("TypeParser.importedEffectModule")(function* (node) {
|
|
1360
|
+
const ts = yield* service(TypeScriptApi);
|
|
1361
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1362
|
+
const type = typeChecker.getTypeAtLocation(node);
|
|
1363
|
+
const propertySymbol = typeChecker.getPropertyOfType(type, "never");
|
|
1364
|
+
if (!propertySymbol) {
|
|
1365
|
+
return yield* typeParserIssue("Type has no 'never' property", type, node);
|
|
1366
|
+
}
|
|
1367
|
+
if (!ts.isExpression(node)) {
|
|
1368
|
+
return yield* typeParserIssue("Node is not an expression", type, node);
|
|
1369
|
+
}
|
|
1370
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, node);
|
|
1371
|
+
yield* effectType(propertyType, node);
|
|
1372
|
+
return node;
|
|
1373
|
+
});
|
|
1374
|
+
var effectGen = fn("TypeParser.effectGen")(function* (node) {
|
|
1375
|
+
const ts = yield* service(TypeScriptApi);
|
|
1376
|
+
if (!ts.isCallExpression(node)) {
|
|
1377
|
+
return yield* typeParserIssue("Node is not a call expression", void 0, node);
|
|
1378
|
+
}
|
|
1379
|
+
if (node.arguments.length === 0) {
|
|
1380
|
+
return yield* typeParserIssue("Node has no arguments", void 0, node);
|
|
1381
|
+
}
|
|
1382
|
+
const generatorFunction = node.arguments[0];
|
|
1383
|
+
if (!ts.isFunctionExpression(generatorFunction)) {
|
|
1384
|
+
return yield* typeParserIssue("Node is not a function expression", void 0, node);
|
|
1385
|
+
}
|
|
1386
|
+
if (generatorFunction.asteriskToken === void 0) {
|
|
1387
|
+
return yield* typeParserIssue("Node is not a generator function", void 0, node);
|
|
1388
|
+
}
|
|
1389
|
+
if (!ts.isPropertyAccessExpression(node.expression)) {
|
|
1390
|
+
return yield* typeParserIssue("Node is not a property access expression", void 0, node);
|
|
1391
|
+
}
|
|
1392
|
+
const propertyAccess = node.expression;
|
|
1393
|
+
if (propertyAccess.name.text !== "gen") {
|
|
1394
|
+
return yield* typeParserIssue("Call expression name is not 'gen'", void 0, node);
|
|
1395
|
+
}
|
|
1396
|
+
const effectModule = yield* importedEffectModule(propertyAccess.expression);
|
|
1397
|
+
return {
|
|
1398
|
+
node,
|
|
1399
|
+
effectModule,
|
|
1400
|
+
generatorFunction,
|
|
1401
|
+
body: generatorFunction.body,
|
|
1402
|
+
functionStar: generatorFunction.getFirstToken()
|
|
1403
|
+
};
|
|
1404
|
+
});
|
|
1405
|
+
var effectFnUntracedGen = fn("TypeParser.effectFnUntracedGen")(
|
|
1406
|
+
function* (node) {
|
|
1407
|
+
const ts = yield* service(TypeScriptApi);
|
|
1408
|
+
if (!ts.isCallExpression(node)) {
|
|
1409
|
+
return yield* typeParserIssue("Node is not a call expression", void 0, node);
|
|
1410
|
+
}
|
|
1411
|
+
if (node.arguments.length === 0) {
|
|
1412
|
+
return yield* typeParserIssue("Node has no arguments", void 0, node);
|
|
1413
|
+
}
|
|
1414
|
+
const generatorFunction = node.arguments[0];
|
|
1415
|
+
if (!ts.isFunctionExpression(generatorFunction)) {
|
|
1416
|
+
return yield* typeParserIssue("Node is not a function expression", void 0, node);
|
|
1417
|
+
}
|
|
1418
|
+
if (generatorFunction.asteriskToken === void 0) {
|
|
1419
|
+
return yield* typeParserIssue(
|
|
1420
|
+
"Node is not a generator function",
|
|
1421
|
+
void 0,
|
|
1422
|
+
node
|
|
1423
|
+
);
|
|
1424
|
+
}
|
|
1425
|
+
if (!ts.isPropertyAccessExpression(node.expression)) {
|
|
1426
|
+
return yield* typeParserIssue(
|
|
1427
|
+
"Node is not a property access expression",
|
|
1428
|
+
void 0,
|
|
1429
|
+
node
|
|
1430
|
+
);
|
|
1431
|
+
}
|
|
1432
|
+
const propertyAccess = node.expression;
|
|
1433
|
+
if (propertyAccess.name.text !== "fnUntraced") {
|
|
1434
|
+
return yield* typeParserIssue(
|
|
1435
|
+
"Call expression name is not 'fnUntraced'",
|
|
1436
|
+
void 0,
|
|
1437
|
+
node
|
|
1438
|
+
);
|
|
1439
|
+
}
|
|
1440
|
+
const effectModule = yield* importedEffectModule(propertyAccess.expression);
|
|
1441
|
+
return {
|
|
1442
|
+
node,
|
|
1443
|
+
effectModule,
|
|
1444
|
+
generatorFunction,
|
|
1445
|
+
body: generatorFunction.body,
|
|
1446
|
+
functionStar: generatorFunction.getFirstToken()
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
);
|
|
1450
|
+
var effectFnGen = fn("TypeParser.effectFnGen")(function* (node) {
|
|
1451
|
+
const ts = yield* service(TypeScriptApi);
|
|
1452
|
+
if (!ts.isCallExpression(node)) {
|
|
1453
|
+
return yield* typeParserIssue("Node is not a call expression", void 0, node);
|
|
1454
|
+
}
|
|
1455
|
+
if (node.arguments.length === 0) {
|
|
1456
|
+
return yield* typeParserIssue("Node has no arguments", void 0, node);
|
|
1457
|
+
}
|
|
1458
|
+
const generatorFunction = node.arguments[0];
|
|
1459
|
+
if (!ts.isFunctionExpression(generatorFunction)) {
|
|
1460
|
+
return yield* typeParserIssue(
|
|
1461
|
+
"Node is not a function expression",
|
|
1462
|
+
void 0,
|
|
1463
|
+
node
|
|
1464
|
+
);
|
|
1465
|
+
}
|
|
1466
|
+
if (generatorFunction.asteriskToken === void 0) {
|
|
1467
|
+
return yield* typeParserIssue(
|
|
1468
|
+
"Node is not a generator function",
|
|
1469
|
+
void 0,
|
|
1470
|
+
node
|
|
1471
|
+
);
|
|
1472
|
+
}
|
|
1473
|
+
const expressionToTest = ts.isCallExpression(node.expression) ? node.expression.expression : node.expression;
|
|
1474
|
+
if (!ts.isPropertyAccessExpression(expressionToTest)) {
|
|
1475
|
+
return yield* typeParserIssue(
|
|
1476
|
+
"Node is not a property access expression",
|
|
1477
|
+
void 0,
|
|
1478
|
+
node
|
|
1479
|
+
);
|
|
1480
|
+
}
|
|
1481
|
+
const propertyAccess = expressionToTest;
|
|
1482
|
+
if (propertyAccess.name.text !== "fn") {
|
|
1483
|
+
return yield* typeParserIssue(
|
|
1484
|
+
"Call expression name is not 'fn'",
|
|
1485
|
+
void 0,
|
|
1486
|
+
node
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1489
|
+
const effectModule = yield* importedEffectModule(propertyAccess.expression);
|
|
1490
|
+
return {
|
|
1491
|
+
node,
|
|
1492
|
+
generatorFunction,
|
|
1493
|
+
effectModule,
|
|
1494
|
+
body: generatorFunction.body,
|
|
1495
|
+
functionStar: generatorFunction.getFirstToken()
|
|
1496
|
+
};
|
|
1497
|
+
});
|
|
1498
|
+
var returnYieldEffectBlock = fn("TypeParser.returnYieldEffectBlock")(function* (body) {
|
|
1499
|
+
const ts = yield* service(TypeScriptApi);
|
|
1500
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1501
|
+
if (ts.isBlock(body) && body.statements.length === 1 && ts.isReturnStatement(body.statements[0]) && body.statements[0].expression && ts.isYieldExpression(body.statements[0].expression) && body.statements[0].expression.expression) {
|
|
1502
|
+
const nodeToCheck = body.statements[0].expression.expression;
|
|
1503
|
+
const type = typeChecker.getTypeAtLocation(nodeToCheck);
|
|
1504
|
+
yield* effectType(type, nodeToCheck);
|
|
1505
|
+
return nodeToCheck;
|
|
1506
|
+
}
|
|
1507
|
+
return yield* typeParserIssue(
|
|
1508
|
+
"Node is not a return statement with a yield expression",
|
|
1509
|
+
void 0,
|
|
1510
|
+
body
|
|
1511
|
+
);
|
|
1512
|
+
});
|
|
1513
|
+
var effectSchemaVarianceStruct = fn("TypeParser.effectSchemaVarianceStruct")(
|
|
1514
|
+
function* (type, atLocation) {
|
|
1515
|
+
return {
|
|
1516
|
+
A: yield* varianceStructInvariantType(type, atLocation, "_A"),
|
|
1517
|
+
I: yield* varianceStructInvariantType(type, atLocation, "_I"),
|
|
1518
|
+
R: yield* varianceStructCovariantType(type, atLocation, "_R")
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
);
|
|
1522
|
+
var effectSchemaType = fn("TypeParser.effectSchemaType")(function* (type, atLocation) {
|
|
1523
|
+
const ts = yield* service(TypeScriptApi);
|
|
1524
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1525
|
+
yield* pipeableType(type, atLocation);
|
|
1526
|
+
const ast = typeChecker.getPropertyOfType(type, "ast");
|
|
1527
|
+
if (!ast) return yield* typeParserIssue("Has no 'ast' property", type, atLocation);
|
|
1528
|
+
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
1529
|
+
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional)
|
|
1530
|
+
);
|
|
1531
|
+
propertiesSymbols.sort((a, b) => b.name.indexOf("TypeId") - a.name.indexOf("TypeId"));
|
|
1532
|
+
for (const propertySymbol of propertiesSymbols) {
|
|
1533
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
1534
|
+
const varianceArgs = yield* option(effectSchemaVarianceStruct(
|
|
1535
|
+
propertyType,
|
|
1536
|
+
atLocation
|
|
1537
|
+
));
|
|
1538
|
+
if (isSome2(varianceArgs)) {
|
|
1539
|
+
return varianceArgs.value;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
return yield* typeParserIssue("Type has no schema variance struct", type, atLocation);
|
|
1543
|
+
});
|
|
1544
|
+
|
|
1545
|
+
// src/diagnostics/floatingEffect.ts
|
|
1546
|
+
var floatingEffect = createDiagnostic({
|
|
1547
|
+
name: "effect/floatingEffect",
|
|
1548
|
+
code: 3,
|
|
1549
|
+
apply: fn("floatingEffect.apply")(function* (sourceFile) {
|
|
1550
|
+
const ts = yield* service(TypeScriptApi);
|
|
1551
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1552
|
+
function isFloatingExpression(node) {
|
|
1553
|
+
if (!ts.isExpressionStatement(node)) return false;
|
|
1554
|
+
if (!(ts.isBlock(node.parent) || ts.isSourceFile(node.parent))) return false;
|
|
1555
|
+
const expression = node.expression;
|
|
1556
|
+
if (ts.isBinaryExpression(expression) && expression.operatorToken && expression.operatorToken.kind === ts.SyntaxKind.EqualsToken) return false;
|
|
1557
|
+
return true;
|
|
1558
|
+
}
|
|
1559
|
+
const effectDiagnostics = [];
|
|
1560
|
+
const nodeToVisit = [];
|
|
1561
|
+
const appendNodeToVisit = (node) => {
|
|
1562
|
+
nodeToVisit.push(node);
|
|
1563
|
+
return void 0;
|
|
1564
|
+
};
|
|
1565
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
1566
|
+
while (nodeToVisit.length > 0) {
|
|
1567
|
+
const node = nodeToVisit.shift();
|
|
1568
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
1569
|
+
if (!isFloatingExpression(node)) continue;
|
|
1570
|
+
const type = typeChecker.getTypeAtLocation(node.expression);
|
|
1571
|
+
const effect = yield* option(effectType(type, node.expression));
|
|
1572
|
+
if (isSome2(effect)) {
|
|
1573
|
+
const allowedFloatingEffects = yield* pipe(
|
|
1574
|
+
fiberType(type, node.expression),
|
|
1575
|
+
orElse(() => effectSubtype(type, node.expression)),
|
|
1576
|
+
option
|
|
1577
|
+
);
|
|
1578
|
+
if (isNone2(allowedFloatingEffects)) {
|
|
1579
|
+
effectDiagnostics.push({
|
|
1580
|
+
node,
|
|
1581
|
+
category: ts.DiagnosticCategory.Error,
|
|
1582
|
+
messageText: `Effect must be yielded or assigned to a variable.`,
|
|
1583
|
+
fixes: []
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
return effectDiagnostics;
|
|
1589
|
+
})
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
// src/diagnostics/missingEffectContext.ts
|
|
1593
|
+
var missingEffectContext = createDiagnostic({
|
|
1594
|
+
name: "effect/missingEffectContext",
|
|
1595
|
+
code: 1,
|
|
1596
|
+
apply: fn("missingEffectContext.apply")(function* (sourceFile) {
|
|
1597
|
+
const ts = yield* service(TypeScriptApi);
|
|
1598
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1599
|
+
const typeOrder = yield* deterministicTypeOrder;
|
|
1600
|
+
const checkForMissingContextTypes = fn(
|
|
1601
|
+
"missingEffectContext.apply.checkForMissingContextTypes"
|
|
1602
|
+
)(function* (node, expectedType, valueNode, realType) {
|
|
1603
|
+
const expectedEffect = yield* effectType(
|
|
1604
|
+
expectedType,
|
|
1605
|
+
node
|
|
1606
|
+
);
|
|
1607
|
+
const realEffect = yield* effectType(
|
|
1608
|
+
realType,
|
|
1609
|
+
valueNode
|
|
1610
|
+
);
|
|
1611
|
+
return yield* getMissingTypeEntriesInTargetType(
|
|
1612
|
+
realEffect.R,
|
|
1613
|
+
expectedEffect.R
|
|
1614
|
+
);
|
|
1615
|
+
});
|
|
1616
|
+
const effectDiagnostics = [];
|
|
1617
|
+
const sortTypes = sort(typeOrder);
|
|
1618
|
+
const entries = yield* expectedAndRealType(sourceFile);
|
|
1619
|
+
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
1620
|
+
const missingContext = yield* pipe(
|
|
1621
|
+
checkForMissingContextTypes(
|
|
1622
|
+
node,
|
|
1623
|
+
expectedType,
|
|
1624
|
+
valueNode,
|
|
1625
|
+
realType
|
|
1626
|
+
),
|
|
1627
|
+
orElse(() => succeed([]))
|
|
1628
|
+
);
|
|
1629
|
+
if (missingContext.length > 0) {
|
|
1630
|
+
effectDiagnostics.push(
|
|
1631
|
+
{
|
|
1632
|
+
node,
|
|
1633
|
+
category: ts.DiagnosticCategory.Error,
|
|
1634
|
+
messageText: `Missing '${sortTypes(missingContext).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect context.`,
|
|
1635
|
+
fixes: []
|
|
1636
|
+
}
|
|
1637
|
+
);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
return effectDiagnostics;
|
|
1641
|
+
})
|
|
1642
|
+
});
|
|
1643
|
+
|
|
1644
|
+
// src/diagnostics/missingEffectError.ts
|
|
1645
|
+
var missingEffectError = createDiagnostic({
|
|
1646
|
+
name: "effect/missingEffectError",
|
|
1647
|
+
code: 1,
|
|
1648
|
+
apply: fn("missingEffectError.apply")(function* (sourceFile) {
|
|
1649
|
+
const ts = yield* service(TypeScriptApi);
|
|
1650
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1651
|
+
const typeOrder = yield* deterministicTypeOrder;
|
|
1652
|
+
const checkForMissingErrorTypes = fn("missingEffectError.apply.checkForMissingErrorTypes")(
|
|
1653
|
+
function* (node, expectedType, valueNode, realType) {
|
|
1654
|
+
const expectedEffect = yield* effectType(
|
|
1655
|
+
expectedType,
|
|
1656
|
+
node
|
|
1657
|
+
);
|
|
1658
|
+
const realEffect = yield* effectType(
|
|
1659
|
+
realType,
|
|
1660
|
+
valueNode
|
|
1661
|
+
);
|
|
1662
|
+
return yield* getMissingTypeEntriesInTargetType(
|
|
1663
|
+
realEffect.E,
|
|
1664
|
+
expectedEffect.E
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
);
|
|
1668
|
+
const effectDiagnostics = [];
|
|
1669
|
+
const sortTypes = sort(typeOrder);
|
|
1670
|
+
const entries = yield* expectedAndRealType(sourceFile);
|
|
1671
|
+
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
1672
|
+
const missingContext = yield* pipe(
|
|
1673
|
+
checkForMissingErrorTypes(
|
|
1674
|
+
node,
|
|
1675
|
+
expectedType,
|
|
1676
|
+
valueNode,
|
|
1677
|
+
realType
|
|
1678
|
+
),
|
|
1679
|
+
orElse(() => succeed([]))
|
|
1680
|
+
);
|
|
1681
|
+
if (missingContext.length > 0) {
|
|
1682
|
+
effectDiagnostics.push(
|
|
1683
|
+
{
|
|
1684
|
+
node,
|
|
1685
|
+
category: ts.DiagnosticCategory.Error,
|
|
1686
|
+
messageText: `Missing '${sortTypes(missingContext).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect errors.`,
|
|
1687
|
+
fixes: []
|
|
1688
|
+
}
|
|
1689
|
+
);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
return effectDiagnostics;
|
|
1693
|
+
})
|
|
1694
|
+
});
|
|
1695
|
+
|
|
1696
|
+
// src/diagnostics/missingStarInYieldEffectGen.ts
|
|
1697
|
+
var missingStarInYieldEffectGen = createDiagnostic({
|
|
1698
|
+
name: "effect/missingStarInYieldEffectGen",
|
|
1699
|
+
code: 4,
|
|
1700
|
+
apply: fn("missingStarInYieldEffectGen.apply")(function* (sourceFile) {
|
|
1701
|
+
const ts = yield* service(TypeScriptApi);
|
|
1702
|
+
const effectDiagnostics = [];
|
|
1703
|
+
const brokenGenerators = /* @__PURE__ */ new Set();
|
|
1704
|
+
const brokenYields = /* @__PURE__ */ new Set();
|
|
1705
|
+
const nodeToVisit = [];
|
|
1706
|
+
const appendNodeToVisit = (node) => {
|
|
1707
|
+
nodeToVisit.push(node);
|
|
1708
|
+
return void 0;
|
|
1709
|
+
};
|
|
1710
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
1711
|
+
while (nodeToVisit.length > 0) {
|
|
1712
|
+
const node = nodeToVisit.shift();
|
|
1713
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
1714
|
+
if (ts.isYieldExpression(node) && node.expression && node.asteriskToken === void 0) {
|
|
1715
|
+
const functionStarNode = ts.findAncestor(
|
|
1716
|
+
node,
|
|
1717
|
+
(_) => (ts.isFunctionExpression(_) || ts.isMethodDeclaration(_)) && _.asteriskToken !== void 0
|
|
1718
|
+
);
|
|
1719
|
+
if (functionStarNode && functionStarNode.parent) {
|
|
1720
|
+
const effectGenNode = functionStarNode.parent;
|
|
1721
|
+
const effectGenLike = yield* pipe(
|
|
1722
|
+
effectGen(effectGenNode),
|
|
1723
|
+
orElse(() => effectFnUntracedGen(effectGenNode)),
|
|
1724
|
+
orElse(() => effectFnGen(effectGenNode)),
|
|
1725
|
+
option
|
|
1726
|
+
);
|
|
1727
|
+
if (isSome2(effectGenLike)) {
|
|
1728
|
+
if (effectGenLike.value.functionStar) {
|
|
1729
|
+
brokenGenerators.add(effectGenLike.value.functionStar);
|
|
1730
|
+
}
|
|
1731
|
+
brokenYields.add(node);
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
brokenGenerators.forEach(
|
|
1737
|
+
(node) => effectDiagnostics.push({
|
|
1738
|
+
node,
|
|
1739
|
+
category: ts.DiagnosticCategory.Error,
|
|
1740
|
+
messageText: `Seems like you used yield instead of yield* inside this Effect.gen.`,
|
|
1741
|
+
fixes: []
|
|
1742
|
+
})
|
|
1743
|
+
);
|
|
1744
|
+
brokenYields.forEach((node) => {
|
|
1745
|
+
const fix = node.expression ? [{
|
|
1746
|
+
fixName: "missingStarInYieldEffectGen_fix",
|
|
1747
|
+
description: "Replace yield with yield*",
|
|
1748
|
+
apply: gen(function* () {
|
|
1749
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
1750
|
+
changeTracker.replaceNode(
|
|
1751
|
+
sourceFile,
|
|
1752
|
+
node,
|
|
1753
|
+
ts.factory.createYieldExpression(
|
|
1754
|
+
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
1755
|
+
node.expression
|
|
1756
|
+
)
|
|
1757
|
+
);
|
|
1758
|
+
})
|
|
1759
|
+
}] : [];
|
|
1760
|
+
effectDiagnostics.push({
|
|
1761
|
+
node,
|
|
1762
|
+
category: ts.DiagnosticCategory.Error,
|
|
1763
|
+
messageText: `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`,
|
|
1764
|
+
fixes: fix
|
|
1765
|
+
});
|
|
1766
|
+
});
|
|
1767
|
+
return effectDiagnostics;
|
|
1768
|
+
})
|
|
1769
|
+
});
|
|
1770
|
+
|
|
1771
|
+
// src/diagnostics/multipleEffectVersions.ts
|
|
1772
|
+
var effectVersionsCache = /* @__PURE__ */ new Map();
|
|
1773
|
+
var programResolvedCacheSize = /* @__PURE__ */ new Map();
|
|
1774
|
+
var multipleEffectVersions = createDiagnostic({
|
|
1775
|
+
name: "effect/multipleEffectVersions",
|
|
1776
|
+
code: 6,
|
|
1777
|
+
apply: fn("multipleEffectVersions.apply")(function* (sourceFile) {
|
|
1778
|
+
const ts = yield* service(TypeScriptApi);
|
|
1779
|
+
const program = yield* service(TypeScriptProgram);
|
|
1780
|
+
const options = yield* service(PluginOptions);
|
|
1781
|
+
const effectDiagnostics = [];
|
|
1782
|
+
if (!options.multipleEffectCheck) return [];
|
|
1783
|
+
if (sourceFile.statements.length < 1) return [];
|
|
1784
|
+
const effectVersions = effectVersionsCache.get(sourceFile.fileName) || {};
|
|
1785
|
+
const newResolvedModuleSize = "resolvedModules" in program && typeof program.resolvedModules === "object" && "size" in program.resolvedModules ? program.resolvedModules.size : 0;
|
|
1786
|
+
const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || 0;
|
|
1787
|
+
if (newResolvedModuleSize !== oldResolvedSize) {
|
|
1788
|
+
if ("forEachResolvedModule" in program && typeof program.forEachResolvedModule === "function") {
|
|
1789
|
+
program.forEachResolvedModule((_) => {
|
|
1790
|
+
if (_ && _.resolvedModule && _.resolvedModule.packageId && _.resolvedModule.packageId.name === "effect" && !(_.resolvedModule.packageId.version in effectVersions)) {
|
|
1791
|
+
effectVersions[_.resolvedModule.packageId.version] = {
|
|
1792
|
+
resolvedFileName: _.resolvedModule.resolvedFileName
|
|
1793
|
+
};
|
|
1794
|
+
}
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
effectVersionsCache.set(sourceFile.fileName, effectVersions);
|
|
1798
|
+
programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize);
|
|
1799
|
+
}
|
|
1800
|
+
if (Object.keys(effectVersions).length > 1) {
|
|
1801
|
+
const versions = Object.keys(effectVersions).map((version) => `version ${version}`);
|
|
1802
|
+
effectDiagnostics.push({
|
|
1803
|
+
node: sourceFile.statements[0],
|
|
1804
|
+
category: ts.DiagnosticCategory.Warning,
|
|
1805
|
+
messageText: `Seems like in this project there are multiple effect versions loaded (${versions.join(", ")}). This may cause unexpected type errors and runtime behaviours. If you are ok with that, you can disable this warning by adding "multipleEffectCheck": false to the Effect LSP options inside your tsconfig.json`,
|
|
1806
|
+
fixes: []
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
return effectDiagnostics;
|
|
1810
|
+
})
|
|
1811
|
+
});
|
|
1812
|
+
|
|
1813
|
+
// src/diagnostics/unnecessaryEffectGen.ts
|
|
1814
|
+
var unnecessaryEffectGen = createDiagnostic({
|
|
1815
|
+
name: "effect/unnecessaryEffectGen",
|
|
1816
|
+
code: 5,
|
|
1817
|
+
apply: fn("unnecessaryEffectGen.apply")(function* (sourceFile) {
|
|
1818
|
+
const ts = yield* service(TypeScriptApi);
|
|
1819
|
+
const effectDiagnostics = [];
|
|
1820
|
+
const unnecessaryGenerators = /* @__PURE__ */ new Map();
|
|
1821
|
+
const nodeToVisit = [];
|
|
1822
|
+
const appendNodeToVisit = (node) => {
|
|
1823
|
+
nodeToVisit.push(node);
|
|
1824
|
+
return void 0;
|
|
1825
|
+
};
|
|
1826
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
1827
|
+
while (nodeToVisit.length > 0) {
|
|
1828
|
+
const node = nodeToVisit.shift();
|
|
1829
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
1830
|
+
const maybeNode = yield* pipe(
|
|
1831
|
+
effectGen(node),
|
|
1832
|
+
flatMap2(({ body }) => returnYieldEffectBlock(body)),
|
|
1833
|
+
option
|
|
1834
|
+
);
|
|
1835
|
+
if (isSome2(maybeNode)) {
|
|
1836
|
+
if (isSome2(maybeNode)) {
|
|
1837
|
+
unnecessaryGenerators.set(node, maybeNode.value);
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
unnecessaryGenerators.forEach(
|
|
1842
|
+
(yieldedResult, effectGenCall) => effectDiagnostics.push({
|
|
1843
|
+
node: effectGenCall,
|
|
1844
|
+
category: ts.DiagnosticCategory.Suggestion,
|
|
1845
|
+
messageText: `This Effect.gen contains a single return statement.`,
|
|
1846
|
+
fixes: [{
|
|
1847
|
+
fixName: "unnecessaryEffectGen_fix",
|
|
1848
|
+
description: "Remove the Effect.gen, and keep the body",
|
|
1849
|
+
apply: gen(function* () {
|
|
1850
|
+
const textChanges = yield* service(
|
|
1851
|
+
ChangeTracker
|
|
1852
|
+
);
|
|
1853
|
+
textChanges.replaceNode(sourceFile, effectGenCall, yieldedResult);
|
|
1854
|
+
})
|
|
1855
|
+
}]
|
|
1856
|
+
})
|
|
1857
|
+
);
|
|
1858
|
+
return effectDiagnostics;
|
|
1859
|
+
})
|
|
1860
|
+
});
|
|
1861
|
+
|
|
1862
|
+
// src/diagnostics.ts
|
|
1863
|
+
var diagnostics = [
|
|
1864
|
+
multipleEffectVersions,
|
|
1865
|
+
missingEffectContext,
|
|
1866
|
+
missingEffectError,
|
|
1867
|
+
floatingEffect,
|
|
1868
|
+
missingStarInYieldEffectGen,
|
|
1869
|
+
unnecessaryEffectGen
|
|
1870
|
+
];
|
|
1871
|
+
|
|
1872
|
+
// src/transform.ts
|
|
1873
|
+
function transform_default(program, pluginConfig, { addDiagnostic, ts: tsInstance }) {
|
|
1874
|
+
return (_) => {
|
|
1875
|
+
return (sourceFile) => {
|
|
1876
|
+
pipe(
|
|
1877
|
+
getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),
|
|
1878
|
+
provideService(TypeScriptApi, tsInstance),
|
|
1879
|
+
provideService(TypeScriptProgram, program),
|
|
1880
|
+
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
1881
|
+
provideService(
|
|
1882
|
+
TypeCheckerApiCache,
|
|
1883
|
+
makeTypeCheckerApiCache()
|
|
1884
|
+
),
|
|
1885
|
+
provideService(PluginOptions, parsePluginOptions(pluginConfig)),
|
|
1886
|
+
run,
|
|
1887
|
+
map((_2) => _2.diagnostics),
|
|
1888
|
+
getOrElse(() => [])
|
|
1889
|
+
).map(addDiagnostic);
|
|
1890
|
+
return sourceFile;
|
|
1891
|
+
};
|
|
1892
|
+
};
|
|
1893
|
+
}
|
|
1894
|
+
//# sourceMappingURL=transform.js.map
|