@effect/language-service 0.35.2 → 0.37.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 +45 -3
- package/cli.js +1578 -4366
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +5227 -0
- package/effect-lsp-patch-utils.js.map +1 -0
- package/index.js +812 -499
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +604 -420
- package/transform.js.map +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
// node_modules/.pnpm/effect@3.17.
|
|
3
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Function.js
|
|
4
4
|
var isFunction = (input) => typeof input === "function";
|
|
5
5
|
var dual = function(arity, body) {
|
|
6
6
|
if (typeof arity === "function") {
|
|
@@ -96,7 +96,7 @@ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
// node_modules/.pnpm/effect@3.17.
|
|
99
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Equivalence.js
|
|
100
100
|
var make = (isEquivalent) => (self, that) => self === that || isEquivalent(self, that);
|
|
101
101
|
var array = (item) => make((self, that) => {
|
|
102
102
|
if (self.length !== that.length) {
|
|
@@ -111,7 +111,7 @@ var array = (item) => make((self, that) => {
|
|
|
111
111
|
return true;
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
-
// node_modules/.pnpm/effect@3.17.
|
|
114
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/GlobalValue.js
|
|
115
115
|
var globalStoreId = `effect/GlobalValue`;
|
|
116
116
|
var globalStore;
|
|
117
117
|
var globalValue = (id, compute) => {
|
|
@@ -125,7 +125,7 @@ var globalValue = (id, compute) => {
|
|
|
125
125
|
return globalStore.get(id);
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
-
// node_modules/.pnpm/effect@3.17.
|
|
128
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Predicate.js
|
|
129
129
|
var isString = (input) => typeof input === "string";
|
|
130
130
|
var isNumber = (input) => typeof input === "number";
|
|
131
131
|
var isBoolean = (input) => typeof input === "boolean";
|
|
@@ -135,7 +135,7 @@ var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
|
|
|
135
135
|
var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObject(self) && property in self);
|
|
136
136
|
var isRecord = (input) => isRecordOrArray(input) && !Array.isArray(input);
|
|
137
137
|
|
|
138
|
-
// node_modules/.pnpm/effect@3.17.
|
|
138
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Utils.js
|
|
139
139
|
var GenKindTypeId = /* @__PURE__ */ Symbol.for("effect/Gen/GenKind");
|
|
140
140
|
var GenKindImpl = class {
|
|
141
141
|
value;
|
|
@@ -257,7 +257,7 @@ var internalCall = isNotOptimizedAway ? standard.effect_internal_function : forc
|
|
|
257
257
|
var genConstructor = function* () {
|
|
258
258
|
}.constructor;
|
|
259
259
|
|
|
260
|
-
// node_modules/.pnpm/effect@3.17.
|
|
260
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Hash.js
|
|
261
261
|
var randomHashCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Hash/randomHashCache"), () => /* @__PURE__ */ new WeakMap());
|
|
262
262
|
var symbol = /* @__PURE__ */ Symbol.for("effect/Hash");
|
|
263
263
|
var hash = (self) => {
|
|
@@ -324,10 +324,10 @@ var string = (str) => {
|
|
|
324
324
|
}
|
|
325
325
|
return optimize(h);
|
|
326
326
|
};
|
|
327
|
-
var structureKeys = (o,
|
|
327
|
+
var structureKeys = (o, keys2) => {
|
|
328
328
|
let h = 12289;
|
|
329
|
-
for (let i = 0; i <
|
|
330
|
-
h ^= pipe(string(
|
|
329
|
+
for (let i = 0; i < keys2.length; i++) {
|
|
330
|
+
h ^= pipe(string(keys2[i]), combine(hash(o[keys2[i]])));
|
|
331
331
|
}
|
|
332
332
|
return optimize(h);
|
|
333
333
|
};
|
|
@@ -356,7 +356,7 @@ var cached = function() {
|
|
|
356
356
|
return hash2;
|
|
357
357
|
};
|
|
358
358
|
|
|
359
|
-
// node_modules/.pnpm/effect@3.17.
|
|
359
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Equal.js
|
|
360
360
|
var symbol2 = /* @__PURE__ */ Symbol.for("effect/Equal");
|
|
361
361
|
function equals() {
|
|
362
362
|
if (arguments.length === 1) {
|
|
@@ -410,7 +410,7 @@ function compareBoth(self, that) {
|
|
|
410
410
|
var isEqual = (u) => hasProperty(u, symbol2);
|
|
411
411
|
var equivalence = () => equals;
|
|
412
412
|
|
|
413
|
-
// node_modules/.pnpm/effect@3.17.
|
|
413
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Inspectable.js
|
|
414
414
|
var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
415
415
|
var toJSON = (x) => {
|
|
416
416
|
try {
|
|
@@ -462,7 +462,7 @@ var redact = (u) => {
|
|
|
462
462
|
return u;
|
|
463
463
|
};
|
|
464
464
|
|
|
465
|
-
// node_modules/.pnpm/effect@3.17.
|
|
465
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Pipeable.js
|
|
466
466
|
var pipeArguments = (self, args2) => {
|
|
467
467
|
switch (args2.length) {
|
|
468
468
|
case 0:
|
|
@@ -495,14 +495,14 @@ var pipeArguments = (self, args2) => {
|
|
|
495
495
|
}
|
|
496
496
|
};
|
|
497
497
|
|
|
498
|
-
// node_modules/.pnpm/effect@3.17.
|
|
498
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/opCodes/effect.js
|
|
499
499
|
var OP_COMMIT = "Commit";
|
|
500
500
|
|
|
501
|
-
// node_modules/.pnpm/effect@3.17.
|
|
502
|
-
var moduleVersion = "3.17.
|
|
501
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/version.js
|
|
502
|
+
var moduleVersion = "3.17.8";
|
|
503
503
|
var getCurrentVersion = () => moduleVersion;
|
|
504
504
|
|
|
505
|
-
// node_modules/.pnpm/effect@3.17.
|
|
505
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/effectable.js
|
|
506
506
|
var EffectTypeId = /* @__PURE__ */ Symbol.for("effect/Effect");
|
|
507
507
|
var StreamTypeId = /* @__PURE__ */ Symbol.for("effect/Stream");
|
|
508
508
|
var SinkTypeId = /* @__PURE__ */ Symbol.for("effect/Sink");
|
|
@@ -589,7 +589,7 @@ var StructuralCommitPrototype = {
|
|
|
589
589
|
...StructuralPrototype
|
|
590
590
|
};
|
|
591
591
|
|
|
592
|
-
// node_modules/.pnpm/effect@3.17.
|
|
592
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/option.js
|
|
593
593
|
var TypeId = /* @__PURE__ */ Symbol.for("effect/Option");
|
|
594
594
|
var CommonProto = {
|
|
595
595
|
...EffectPrototype,
|
|
@@ -647,7 +647,7 @@ var some = (value) => {
|
|
|
647
647
|
return a;
|
|
648
648
|
};
|
|
649
649
|
|
|
650
|
-
// node_modules/.pnpm/effect@3.17.
|
|
650
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/either.js
|
|
651
651
|
var TypeId2 = /* @__PURE__ */ Symbol.for("effect/Either");
|
|
652
652
|
var CommonProto2 = {
|
|
653
653
|
...EffectPrototype,
|
|
@@ -709,7 +709,7 @@ var right = (right3) => {
|
|
|
709
709
|
return a;
|
|
710
710
|
};
|
|
711
711
|
|
|
712
|
-
// node_modules/.pnpm/effect@3.17.
|
|
712
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Either.js
|
|
713
713
|
var right2 = right;
|
|
714
714
|
var left2 = left;
|
|
715
715
|
var isLeft2 = isLeft;
|
|
@@ -717,11 +717,11 @@ var isRight2 = isRight;
|
|
|
717
717
|
var map = /* @__PURE__ */ dual(2, (self, f) => isRight2(self) ? right2(f(self.right)) : left2(self.left));
|
|
718
718
|
var getOrElse = /* @__PURE__ */ dual(2, (self, onLeft) => isLeft2(self) ? onLeft(self.left) : self.right);
|
|
719
719
|
|
|
720
|
-
// node_modules/.pnpm/effect@3.17.
|
|
720
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Order.js
|
|
721
721
|
var make2 = (compare) => (self, that) => self === that ? 0 : compare(self, that);
|
|
722
722
|
var string2 = /* @__PURE__ */ make2((self, that) => self < that ? -1 : 1);
|
|
723
723
|
|
|
724
|
-
// node_modules/.pnpm/effect@3.17.
|
|
724
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Option.js
|
|
725
725
|
var none2 = () => none;
|
|
726
726
|
var some2 = some;
|
|
727
727
|
var isNone2 = isNone;
|
|
@@ -829,6 +829,7 @@ var NanoFiber = class {
|
|
|
829
829
|
_yielded = void 0;
|
|
830
830
|
_services = {};
|
|
831
831
|
_cache = {};
|
|
832
|
+
_perf = false;
|
|
832
833
|
runLoop(nano) {
|
|
833
834
|
let current = nano;
|
|
834
835
|
while (true) {
|
|
@@ -852,6 +853,34 @@ var NanoFiber = class {
|
|
|
852
853
|
return NanoYield;
|
|
853
854
|
}
|
|
854
855
|
};
|
|
856
|
+
var timings = {};
|
|
857
|
+
var timingsCount = {};
|
|
858
|
+
var WithSpanProto = {
|
|
859
|
+
...PrimitiveProto,
|
|
860
|
+
[evaluate](fiber) {
|
|
861
|
+
const [fa, name] = this[args];
|
|
862
|
+
if (!fiber._perf) return fa;
|
|
863
|
+
const start = performance.now();
|
|
864
|
+
timingsCount[name] = (timingsCount[name] || 0) + 1;
|
|
865
|
+
return match(fa, {
|
|
866
|
+
onSuccess: (_) => {
|
|
867
|
+
const end = performance.now();
|
|
868
|
+
timings[name] = (timings[name] || 0) + (end - start);
|
|
869
|
+
return succeed(_);
|
|
870
|
+
},
|
|
871
|
+
onFailure: (_) => {
|
|
872
|
+
const end = performance.now();
|
|
873
|
+
timings[name] = (timings[name] || 0) + (end - start);
|
|
874
|
+
return fail(_);
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
var withSpan = (name) => (fa) => {
|
|
880
|
+
const nano = Object.create(WithSpanProto);
|
|
881
|
+
nano[args] = [fa, name];
|
|
882
|
+
return nano;
|
|
883
|
+
};
|
|
855
884
|
var unsafeRun = (nano) => {
|
|
856
885
|
const fiber = new NanoFiber();
|
|
857
886
|
const result = fiber.runLoop(nano);
|
|
@@ -913,7 +942,7 @@ var unsafeFromIterator = (iterator, initial) => {
|
|
|
913
942
|
return nano;
|
|
914
943
|
};
|
|
915
944
|
var gen = (...args2) => suspend(() => unsafeFromIterator(args2[0]()));
|
|
916
|
-
var fn = (_) => (body) => (...args2) => suspend(() => unsafeFromIterator(body(...args2)));
|
|
945
|
+
var fn = (_) => (body) => (...args2) => withSpan(_)(suspend(() => unsafeFromIterator(body(...args2))));
|
|
917
946
|
var MatchProto = {
|
|
918
947
|
...PrimitiveProto,
|
|
919
948
|
[evaluate](fiber) {
|
|
@@ -1036,10 +1065,22 @@ var TypeScriptApi = Tag("TypeScriptApi");
|
|
|
1036
1065
|
var TypeScriptProgram = Tag("TypeScriptProgram");
|
|
1037
1066
|
var ChangeTracker = Tag("ChangeTracker");
|
|
1038
1067
|
|
|
1039
|
-
// node_modules/.pnpm/effect@3.17.
|
|
1068
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/array.js
|
|
1040
1069
|
var isNonEmptyArray = (self) => self.length > 0;
|
|
1041
1070
|
|
|
1042
|
-
// node_modules/.pnpm/effect@3.17.
|
|
1071
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Record.js
|
|
1072
|
+
var map4 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
1073
|
+
const out = {
|
|
1074
|
+
...self
|
|
1075
|
+
};
|
|
1076
|
+
for (const key of keys(self)) {
|
|
1077
|
+
out[key] = f(self[key], key);
|
|
1078
|
+
}
|
|
1079
|
+
return out;
|
|
1080
|
+
});
|
|
1081
|
+
var keys = (self) => Object.keys(self);
|
|
1082
|
+
|
|
1083
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Array.js
|
|
1043
1084
|
var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
|
|
1044
1085
|
var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
|
|
1045
1086
|
var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
|
|
@@ -1082,7 +1123,7 @@ var intersectionWith = (isEquivalent) => {
|
|
|
1082
1123
|
};
|
|
1083
1124
|
var intersection = /* @__PURE__ */ intersectionWith(_equivalence);
|
|
1084
1125
|
var empty = () => [];
|
|
1085
|
-
var
|
|
1126
|
+
var map5 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
|
|
1086
1127
|
var flatMap2 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
1087
1128
|
if (isEmptyReadonlyArray(self)) {
|
|
1088
1129
|
return [];
|
|
@@ -1179,7 +1220,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1179
1220
|
return pipe(
|
|
1180
1221
|
referencedPackages.concat(packageJsonScope?.referencedPackages || []),
|
|
1181
1222
|
dedupe,
|
|
1182
|
-
|
|
1223
|
+
map5((packageName) => packageName.toLowerCase()),
|
|
1183
1224
|
filter(
|
|
1184
1225
|
(packageName) => pattern.endsWith("*") && packageName.startsWith(pattern.toLowerCase().substring(0, pattern.length - 1))
|
|
1185
1226
|
)
|
|
@@ -1203,7 +1244,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1203
1244
|
const sourceText = sourceFile.text;
|
|
1204
1245
|
let result;
|
|
1205
1246
|
function find(node) {
|
|
1206
|
-
const leading = ts.getLeadingCommentRanges(sourceText, node.
|
|
1247
|
+
const leading = ts.getLeadingCommentRanges(sourceText, node.pos);
|
|
1207
1248
|
if (leading) {
|
|
1208
1249
|
for (const commentRange of leading) {
|
|
1209
1250
|
if (commentRange.pos <= position && position < commentRange.end) {
|
|
@@ -1212,8 +1253,8 @@ function makeTypeScriptUtils(ts) {
|
|
|
1212
1253
|
}
|
|
1213
1254
|
}
|
|
1214
1255
|
}
|
|
1215
|
-
if (node.
|
|
1216
|
-
|
|
1256
|
+
if (node.pos <= position && position < node.end) {
|
|
1257
|
+
ts.forEachChild(node, find);
|
|
1217
1258
|
}
|
|
1218
1259
|
}
|
|
1219
1260
|
find(sourceFile);
|
|
@@ -1232,7 +1273,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1232
1273
|
}
|
|
1233
1274
|
function findNodeAtPosition(sourceFile, position) {
|
|
1234
1275
|
function find(node) {
|
|
1235
|
-
if (position >=
|
|
1276
|
+
if (position >= ts.getTokenPosOfNode(node, sourceFile) && position < node.end) {
|
|
1236
1277
|
return ts.forEachChild(node, find) || node;
|
|
1237
1278
|
}
|
|
1238
1279
|
return void 0;
|
|
@@ -1259,7 +1300,6 @@ function makeTypeScriptUtils(ts) {
|
|
|
1259
1300
|
return;
|
|
1260
1301
|
}
|
|
1261
1302
|
const startPos = token.pos === 0 ? (ts.getShebang(sourceFile.text) || "").length : token.pos;
|
|
1262
|
-
if (startPos === 0) return;
|
|
1263
1303
|
const result = ts.forEachTrailingCommentRange(sourceFile.text, startPos, isCommentInRange, pos) || ts.forEachLeadingCommentRange(sourceFile.text, startPos, isCommentInRange, pos);
|
|
1264
1304
|
return result;
|
|
1265
1305
|
}
|
|
@@ -1296,7 +1336,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1296
1336
|
fnCall = ts.factory.createCallExpression(
|
|
1297
1337
|
fnCall,
|
|
1298
1338
|
void 0,
|
|
1299
|
-
[ts.factory.createStringLiteral(fnName
|
|
1339
|
+
[ts.factory.createStringLiteral(ts.idText(fnName))]
|
|
1300
1340
|
);
|
|
1301
1341
|
}
|
|
1302
1342
|
return tryPreserveDeclarationSemantics(
|
|
@@ -1368,7 +1408,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1368
1408
|
if (!namedBindings) continue;
|
|
1369
1409
|
if (ts.isNamespaceImport(namedBindings)) {
|
|
1370
1410
|
if (test(namedBindings.name, statement.moduleSpecifier, none2())) {
|
|
1371
|
-
return namedBindings.name
|
|
1411
|
+
return ts.idText(namedBindings.name);
|
|
1372
1412
|
}
|
|
1373
1413
|
} else if (ts.isNamedImports(namedBindings)) {
|
|
1374
1414
|
for (const importSpecifier of namedBindings.elements) {
|
|
@@ -1376,7 +1416,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1376
1416
|
orElse(() => some2(importSpecifier.name))
|
|
1377
1417
|
);
|
|
1378
1418
|
if (test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
|
|
1379
|
-
return importSpecifier.name
|
|
1419
|
+
return ts.idText(importSpecifier.name);
|
|
1380
1420
|
}
|
|
1381
1421
|
}
|
|
1382
1422
|
}
|
|
@@ -1389,7 +1429,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1389
1429
|
if (isNone2(importProperty) && ts.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
|
|
1390
1430
|
return true;
|
|
1391
1431
|
}
|
|
1392
|
-
if (isSome2(importProperty) && ts.isIdentifier(importProperty.value) && importProperty.value
|
|
1432
|
+
if (isSome2(importProperty) && ts.isIdentifier(importProperty.value) && ts.idText(importProperty.value) === moduleName && ts.isStringLiteral(fromModule) && fromModule.text === packageName) {
|
|
1393
1433
|
return true;
|
|
1394
1434
|
}
|
|
1395
1435
|
return false;
|
|
@@ -1464,23 +1504,26 @@ function makeTypeScriptUtils(ts) {
|
|
|
1464
1504
|
let replacementSpan = ts.createTextSpan(position, 0);
|
|
1465
1505
|
let outerNode = precedingToken;
|
|
1466
1506
|
if (ts.isIdentifier(precedingToken) && precedingToken.parent && ts.isPropertyAccessExpression(precedingToken.parent)) {
|
|
1507
|
+
const spanStart = ts.getTokenPosOfNode(precedingToken.parent, sourceFile);
|
|
1467
1508
|
replacementSpan = ts.createTextSpan(
|
|
1468
|
-
|
|
1469
|
-
precedingToken.end -
|
|
1509
|
+
spanStart,
|
|
1510
|
+
precedingToken.end - spanStart
|
|
1470
1511
|
);
|
|
1471
1512
|
accessedObject = precedingToken.parent.expression;
|
|
1472
1513
|
outerNode = precedingToken.parent;
|
|
1473
1514
|
} else if (ts.isToken(precedingToken) && precedingToken.kind === ts.SyntaxKind.DotToken && ts.isPropertyAccessExpression(precedingToken.parent)) {
|
|
1515
|
+
const precedingTokenSpanStart = ts.getTokenPosOfNode(precedingToken.parent, sourceFile);
|
|
1474
1516
|
replacementSpan = ts.createTextSpan(
|
|
1475
|
-
|
|
1476
|
-
precedingToken.end -
|
|
1517
|
+
precedingTokenSpanStart,
|
|
1518
|
+
precedingToken.end - precedingTokenSpanStart
|
|
1477
1519
|
);
|
|
1478
1520
|
accessedObject = precedingToken.parent.expression;
|
|
1479
1521
|
outerNode = precedingToken.parent;
|
|
1480
1522
|
} else if (ts.isIdentifier(precedingToken) && precedingToken.parent) {
|
|
1523
|
+
const precedingTokenSpanStart = ts.getTokenPosOfNode(precedingToken, sourceFile);
|
|
1481
1524
|
replacementSpan = ts.createTextSpan(
|
|
1482
|
-
|
|
1483
|
-
precedingToken.end -
|
|
1525
|
+
precedingTokenSpanStart,
|
|
1526
|
+
precedingToken.end - precedingTokenSpanStart
|
|
1484
1527
|
);
|
|
1485
1528
|
accessedObject = precedingToken;
|
|
1486
1529
|
outerNode = precedingToken;
|
|
@@ -1574,6 +1617,13 @@ function makeTypeScriptUtils(ts) {
|
|
|
1574
1617
|
[]
|
|
1575
1618
|
);
|
|
1576
1619
|
}
|
|
1620
|
+
function getSourceFileOfNode(current) {
|
|
1621
|
+
let node = current;
|
|
1622
|
+
while (node && node.kind !== ts.SyntaxKind.SourceFile) {
|
|
1623
|
+
node = node.parent;
|
|
1624
|
+
}
|
|
1625
|
+
return node;
|
|
1626
|
+
}
|
|
1577
1627
|
return {
|
|
1578
1628
|
findNodeAtPositionIncludingTrivia,
|
|
1579
1629
|
parsePackageContentNameAndVersionFromScope,
|
|
@@ -1593,7 +1643,8 @@ function makeTypeScriptUtils(ts) {
|
|
|
1593
1643
|
createEffectGenCallExpressionWithBlock,
|
|
1594
1644
|
createReturnYieldStarStatement,
|
|
1595
1645
|
makeGetModuleSpecifier,
|
|
1596
|
-
parseAccessedExpressionForCompletion
|
|
1646
|
+
parseAccessedExpressionForCompletion,
|
|
1647
|
+
getSourceFileOfNode
|
|
1597
1648
|
};
|
|
1598
1649
|
}
|
|
1599
1650
|
|
|
@@ -1605,7 +1656,7 @@ function parseDiagnosticSeverity(config) {
|
|
|
1605
1656
|
pipe(
|
|
1606
1657
|
Object.entries(config),
|
|
1607
1658
|
filter(([key, value]) => isString(key) && isString(value)),
|
|
1608
|
-
|
|
1659
|
+
map5(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),
|
|
1609
1660
|
filter(
|
|
1610
1661
|
([_, value]) => value === "off" || value === "error" || value === "warning" || value === "message" || value === "suggestion"
|
|
1611
1662
|
)
|
|
@@ -1623,8 +1674,10 @@ var defaults = {
|
|
|
1623
1674
|
inlays: true,
|
|
1624
1675
|
allowedDuplicatedPackages: [],
|
|
1625
1676
|
namespaceImportPackages: [],
|
|
1677
|
+
topLevelNamedReexports: "ignore",
|
|
1626
1678
|
barrelImportPackages: [],
|
|
1627
|
-
|
|
1679
|
+
importAliases: {},
|
|
1680
|
+
renames: true
|
|
1628
1681
|
};
|
|
1629
1682
|
function parse(config) {
|
|
1630
1683
|
return {
|
|
@@ -1639,7 +1692,9 @@ function parse(config) {
|
|
|
1639
1692
|
allowedDuplicatedPackages: isObject(config) && hasProperty(config, "allowedDuplicatedPackages") && isArray(config.allowedDuplicatedPackages) && config.allowedDuplicatedPackages.every(isString) ? config.allowedDuplicatedPackages.map((_) => _.toLowerCase()) : defaults.allowedDuplicatedPackages,
|
|
1640
1693
|
namespaceImportPackages: isObject(config) && hasProperty(config, "namespaceImportPackages") && isArray(config.namespaceImportPackages) && config.namespaceImportPackages.every(isString) ? config.namespaceImportPackages.map((_) => _.toLowerCase()) : defaults.namespaceImportPackages,
|
|
1641
1694
|
barrelImportPackages: isObject(config) && hasProperty(config, "barrelImportPackages") && isArray(config.barrelImportPackages) && config.barrelImportPackages.every(isString) ? config.barrelImportPackages.map((_) => _.toLowerCase()) : defaults.barrelImportPackages,
|
|
1642
|
-
|
|
1695
|
+
importAliases: isObject(config) && hasProperty(config, "importAliases") && isRecord(config.importAliases) ? map4(config.importAliases, (value) => String(value)) : defaults.importAliases,
|
|
1696
|
+
topLevelNamedReexports: isObject(config) && hasProperty(config, "topLevelNamedReexports") && isString(config.topLevelNamedReexports) && ["ignore", "follow"].includes(config.topLevelNamedReexports.toLowerCase()) ? config.topLevelNamedReexports.toLowerCase() : defaults.topLevelNamedReexports,
|
|
1697
|
+
renames: isObject(config) && hasProperty(config, "renames") && isBoolean(config.renames) ? config.renames : defaults.renames
|
|
1643
1698
|
};
|
|
1644
1699
|
}
|
|
1645
1700
|
|
|
@@ -1653,6 +1708,18 @@ function createRefactor(definition) {
|
|
|
1653
1708
|
function createDiagnostic(definition) {
|
|
1654
1709
|
return definition;
|
|
1655
1710
|
}
|
|
1711
|
+
function concatDiagnostics(fa, fb) {
|
|
1712
|
+
const result = fa.slice(0);
|
|
1713
|
+
for (const b of fb) {
|
|
1714
|
+
const existing = result.find(
|
|
1715
|
+
(a) => a.file === b.file && a.code === b.code && a.source === b.source && a.start === b.start && a.length === b.length && a.messageText === b.messageText
|
|
1716
|
+
);
|
|
1717
|
+
if (!existing) {
|
|
1718
|
+
result.push(b);
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
return result;
|
|
1722
|
+
}
|
|
1656
1723
|
function createCompletion(definition) {
|
|
1657
1724
|
return definition;
|
|
1658
1725
|
}
|
|
@@ -1753,7 +1820,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1753
1820
|
if (foundNode) {
|
|
1754
1821
|
lineOverrides[ruleName] = lineOverrides[ruleName] || [];
|
|
1755
1822
|
lineOverrides[ruleName].unshift({
|
|
1756
|
-
pos: foundNode.node.
|
|
1823
|
+
pos: foundNode.node.pos,
|
|
1757
1824
|
end: foundNode.node.end,
|
|
1758
1825
|
level: ruleLevel
|
|
1759
1826
|
});
|
|
@@ -1792,11 +1859,12 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1792
1859
|
service(ChangeTracker),
|
|
1793
1860
|
(changeTracker) => gen(function* () {
|
|
1794
1861
|
const disableAtNode = findParentStatementForDisableNextLine(node);
|
|
1795
|
-
const
|
|
1862
|
+
const start = ts.getTokenPosOfNode(disableAtNode, sourceFile);
|
|
1863
|
+
const { line } = ts.getLineAndCharacterOfPosition(sourceFile, start);
|
|
1796
1864
|
changeTracker.insertCommentBeforeLine(
|
|
1797
1865
|
sourceFile,
|
|
1798
1866
|
line,
|
|
1799
|
-
|
|
1867
|
+
start,
|
|
1800
1868
|
` @effect-diagnostics-next-line ${rule.name}:off`
|
|
1801
1869
|
);
|
|
1802
1870
|
})
|
|
@@ -1819,8 +1887,8 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1819
1887
|
};
|
|
1820
1888
|
const applicableDiagnostics = [];
|
|
1821
1889
|
yield* rule.apply(sourceFile, (entry) => {
|
|
1822
|
-
const range = "
|
|
1823
|
-
const node = "
|
|
1890
|
+
const range = "kind" in entry.location ? { pos: ts.getTokenPosOfNode(entry.location, sourceFile), end: entry.location.end } : entry.location;
|
|
1891
|
+
const node = "kind" in entry.location ? entry.location : tsUtils.findNodeAtPositionIncludingTrivia(sourceFile, entry.location.pos);
|
|
1824
1892
|
applicableDiagnostics.push({
|
|
1825
1893
|
range,
|
|
1826
1894
|
messageText: entry.messageText,
|
|
@@ -1938,6 +2006,9 @@ var getEditsForCodegen = fn("LSP.getEditsForCodegen")(function* (codegens2, sour
|
|
|
1938
2006
|
ignore: updateHashComment
|
|
1939
2007
|
};
|
|
1940
2008
|
});
|
|
2009
|
+
var getEffectLspPatchSourceFileMetadata = (sourceFile) => {
|
|
2010
|
+
return sourceFile["@effect-lsp-patch/metadata"];
|
|
2011
|
+
};
|
|
1941
2012
|
|
|
1942
2013
|
// src/completions/contextSelfInClasses.ts
|
|
1943
2014
|
var contextSelfInClasses = createCompletion({
|
|
@@ -1953,8 +2024,8 @@ var contextSelfInClasses = createCompletion({
|
|
|
1953
2024
|
"effect",
|
|
1954
2025
|
"Context"
|
|
1955
2026
|
) || "Context";
|
|
1956
|
-
if (contextIdentifier !== accessedObject
|
|
1957
|
-
const name = className
|
|
2027
|
+
if (contextIdentifier !== ts.idText(accessedObject)) return [];
|
|
2028
|
+
const name = ts.idText(className);
|
|
1958
2029
|
return [{
|
|
1959
2030
|
name: `Tag("${name}")`,
|
|
1960
2031
|
kind: ts.ScriptElementKind.constElement,
|
|
@@ -1967,28 +2038,65 @@ var contextSelfInClasses = createCompletion({
|
|
|
1967
2038
|
|
|
1968
2039
|
// src/core/TypeCheckerApi.ts
|
|
1969
2040
|
var TypeCheckerApi = Tag("TypeChecker");
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
)(
|
|
1983
|
-
|
|
2041
|
+
function makeResolveExternalModuleName(typeChecker) {
|
|
2042
|
+
if (!(hasProperty(typeChecker, "resolveExternalModuleName") && isFunction(typeChecker.resolveExternalModuleName))) {
|
|
2043
|
+
return;
|
|
2044
|
+
}
|
|
2045
|
+
const _internal = typeChecker.resolveExternalModuleName;
|
|
2046
|
+
return (moduleSpecifier) => {
|
|
2047
|
+
return _internal(moduleSpecifier);
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
// src/core/TypeCheckerUtils.ts
|
|
2052
|
+
var TypeCheckerUtils = Tag("TypeCheckerUtils");
|
|
2053
|
+
var nanoLayer2 = (fa) => pipe(
|
|
2054
|
+
service(TypeScriptApi),
|
|
2055
|
+
flatMap(
|
|
2056
|
+
(ts) => flatMap(service(TypeCheckerApi), (typeChecker) => pipe(fa, provideService(TypeCheckerUtils, makeTypeCheckerUtils(ts, typeChecker))))
|
|
2057
|
+
)
|
|
2058
|
+
);
|
|
2059
|
+
function makeTypeCheckerUtils(ts, typeChecker) {
|
|
2060
|
+
function isUnion(type) {
|
|
2061
|
+
return !!(type.flags & ts.TypeFlags.Union);
|
|
2062
|
+
}
|
|
2063
|
+
function isIndexType(type) {
|
|
2064
|
+
return !!(type.flags & ts.TypeFlags.Index);
|
|
2065
|
+
}
|
|
2066
|
+
function isThisTypeParameter(type) {
|
|
2067
|
+
return !!(type.flags & ts.TypeFlags.TypeParameter && type.isThisType);
|
|
2068
|
+
}
|
|
2069
|
+
function getTypeParameterAtPosition(signature, pos) {
|
|
2070
|
+
const type = typeChecker.getParameterType(signature, pos);
|
|
2071
|
+
if (isIndexType(type) && isThisTypeParameter(type.type)) {
|
|
2072
|
+
const constraint = typeChecker.getBaseConstraintOfType(type.type);
|
|
2073
|
+
if (constraint) {
|
|
2074
|
+
return typeChecker.getIndexType(constraint);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
return type;
|
|
2078
|
+
}
|
|
2079
|
+
const unrollUnionMembers = (type) => {
|
|
2080
|
+
const result = [];
|
|
2081
|
+
let toTest = [type];
|
|
2082
|
+
while (toTest.length > 0) {
|
|
2083
|
+
const type2 = toTest.pop();
|
|
2084
|
+
if (isUnion(type2)) {
|
|
2085
|
+
toTest = toTest.concat(type2.types);
|
|
2086
|
+
} else {
|
|
2087
|
+
result.push(type2);
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
return result;
|
|
2091
|
+
};
|
|
2092
|
+
const getMissingTypeEntriesInTargetType = function(realType, expectedType) {
|
|
1984
2093
|
if (realType === expectedType) return [];
|
|
1985
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
1986
2094
|
const result = [];
|
|
1987
2095
|
let toTest = [realType];
|
|
1988
2096
|
while (toTest.length > 0) {
|
|
1989
2097
|
const type = toTest.pop();
|
|
1990
2098
|
if (!type) return result;
|
|
1991
|
-
if (
|
|
2099
|
+
if (isUnion(type)) {
|
|
1992
2100
|
toTest = toTest.concat(type.types);
|
|
1993
2101
|
} else {
|
|
1994
2102
|
const assignable = typeChecker.isTypeAssignableTo(type, expectedType);
|
|
@@ -1998,77 +2106,99 @@ var getMissingTypeEntriesInTargetType = fn(
|
|
|
1998
2106
|
}
|
|
1999
2107
|
}
|
|
2000
2108
|
return result;
|
|
2001
|
-
}
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2109
|
+
};
|
|
2110
|
+
const appendToUniqueTypesMap = fn(
|
|
2111
|
+
"TypeCheckerUtils.appendToUniqueTypesMap"
|
|
2112
|
+
)(
|
|
2113
|
+
function* (memory, initialType, shouldExclude) {
|
|
2114
|
+
const newIndexes = /* @__PURE__ */ new Set();
|
|
2115
|
+
const knownIndexes = /* @__PURE__ */ new Set();
|
|
2116
|
+
let toTest = [initialType];
|
|
2117
|
+
while (toTest.length > 0) {
|
|
2118
|
+
const type = toTest.pop();
|
|
2119
|
+
if (!type) break;
|
|
2120
|
+
if (yield* shouldExclude(type)) {
|
|
2121
|
+
continue;
|
|
2122
|
+
}
|
|
2123
|
+
if (isUnion(type)) {
|
|
2124
|
+
toTest = toTest.concat(type.types);
|
|
2125
|
+
} else {
|
|
2126
|
+
const foundMatch = [];
|
|
2127
|
+
for (const [typeId, knownType] of memory.entries()) {
|
|
2128
|
+
const areSame = typeChecker.isTypeAssignableTo(knownType, type) && typeChecker.isTypeAssignableTo(type, knownType);
|
|
2129
|
+
if (areSame) {
|
|
2130
|
+
foundMatch.push(typeId);
|
|
2131
|
+
break;
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
if (foundMatch.length === 0) {
|
|
2135
|
+
const newId = "t" + (memory.size + 1);
|
|
2136
|
+
memory.set(newId, type);
|
|
2137
|
+
newIndexes.add(newId);
|
|
2138
|
+
} else {
|
|
2139
|
+
knownIndexes.add(foundMatch[0]);
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
return {
|
|
2144
|
+
newIndexes,
|
|
2145
|
+
knownIndexes,
|
|
2146
|
+
allIndexes: pipe(
|
|
2147
|
+
fromIterable(newIndexes),
|
|
2148
|
+
appendAll(fromIterable(knownIndexes))
|
|
2149
|
+
)
|
|
2150
|
+
};
|
|
2017
2151
|
}
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2035
|
-
const
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
if (signatures.length > 1) {
|
|
2045
|
-
returnType = typeChecker.getUnionType(
|
|
2046
|
-
signatures.map((s) => s.getReturnType()).filter((_) => !!_)
|
|
2152
|
+
);
|
|
2153
|
+
const deterministicTypeOrder = make2((a, b) => {
|
|
2154
|
+
const aName = typeChecker.typeToString(a);
|
|
2155
|
+
const bName = typeChecker.typeToString(b);
|
|
2156
|
+
if (aName < bName) return -1;
|
|
2157
|
+
if (aName > bName) return 1;
|
|
2158
|
+
return 0;
|
|
2159
|
+
});
|
|
2160
|
+
const getAncestorConvertibleDeclaration = (node) => {
|
|
2161
|
+
let current = node;
|
|
2162
|
+
while (current) {
|
|
2163
|
+
if (ts.isFunctionDeclaration(current) || ts.isFunctionExpression(current) || ts.isArrowFunction(current) || ts.isMethodDeclaration(current)) {
|
|
2164
|
+
return current;
|
|
2165
|
+
}
|
|
2166
|
+
current = current.parent;
|
|
2167
|
+
}
|
|
2168
|
+
};
|
|
2169
|
+
const getInferredReturnType = (declaration) => {
|
|
2170
|
+
if (!declaration.body) {
|
|
2171
|
+
return;
|
|
2172
|
+
}
|
|
2173
|
+
let returnType;
|
|
2174
|
+
if (typeChecker.isImplementationOfOverload(declaration)) {
|
|
2175
|
+
const signatures = typeChecker.getSignaturesOfType(
|
|
2176
|
+
typeChecker.getTypeAtLocation(declaration),
|
|
2177
|
+
ts.SignatureKind.Call
|
|
2047
2178
|
);
|
|
2179
|
+
if (signatures.length > 1) {
|
|
2180
|
+
returnType = typeChecker.getUnionType(
|
|
2181
|
+
signatures.map((s) => typeChecker.getReturnTypeOfSignature(s)).filter((_) => !!_)
|
|
2182
|
+
);
|
|
2183
|
+
}
|
|
2048
2184
|
}
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2185
|
+
if (!returnType) {
|
|
2186
|
+
const signature = typeChecker.getSignatureFromDeclaration(declaration);
|
|
2187
|
+
if (signature) {
|
|
2188
|
+
const typePredicate = typeChecker.getTypePredicateOfSignature(signature);
|
|
2189
|
+
if (typePredicate && typePredicate.type) {
|
|
2190
|
+
return typePredicate.type;
|
|
2191
|
+
} else {
|
|
2192
|
+
returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
2193
|
+
}
|
|
2058
2194
|
}
|
|
2059
2195
|
}
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
);
|
|
2065
|
-
|
|
2066
|
-
return returnType;
|
|
2067
|
-
});
|
|
2068
|
-
var expectedAndRealType = cachedBy(
|
|
2069
|
-
fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
|
|
2070
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
2071
|
-
const ts = yield* service(TypeScriptApi);
|
|
2196
|
+
return returnType;
|
|
2197
|
+
};
|
|
2198
|
+
const expectedAndRealTypeCache = /* @__PURE__ */ new WeakMap();
|
|
2199
|
+
const expectedAndRealType = (sourceFile) => {
|
|
2200
|
+
const cached2 = expectedAndRealTypeCache.get(sourceFile);
|
|
2201
|
+
if (cached2) return cached2;
|
|
2072
2202
|
const result = [];
|
|
2073
2203
|
const nodeToVisit = [sourceFile];
|
|
2074
2204
|
const appendNodeToVisit = (node) => {
|
|
@@ -2086,7 +2216,7 @@ var expectedAndRealType = cachedBy(
|
|
|
2086
2216
|
} else if (ts.isCallExpression(node)) {
|
|
2087
2217
|
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
2088
2218
|
if (resolvedSignature) {
|
|
2089
|
-
resolvedSignature.
|
|
2219
|
+
resolvedSignature.parameters.map((parameter, index) => {
|
|
2090
2220
|
const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
|
|
2091
2221
|
const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
|
|
2092
2222
|
result.push([
|
|
@@ -2105,11 +2235,14 @@ var expectedAndRealType = cachedBy(
|
|
|
2105
2235
|
if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
|
|
2106
2236
|
const type = typeChecker.getContextualType(parent.parent);
|
|
2107
2237
|
if (type) {
|
|
2108
|
-
const
|
|
2109
|
-
if (
|
|
2110
|
-
const
|
|
2111
|
-
|
|
2112
|
-
|
|
2238
|
+
const name = ts.isIdentifier(node) ? ts.idText(node) : ts.isStringLiteral(node) ? node.text : void 0;
|
|
2239
|
+
if (name) {
|
|
2240
|
+
const symbol3 = typeChecker.getPropertyOfType(type, name);
|
|
2241
|
+
if (symbol3) {
|
|
2242
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
|
|
2243
|
+
const realType = typeChecker.getTypeAtLocation(node);
|
|
2244
|
+
result.push([node, expectedType, node, realType]);
|
|
2245
|
+
}
|
|
2113
2246
|
}
|
|
2114
2247
|
}
|
|
2115
2248
|
}
|
|
@@ -2123,12 +2256,12 @@ var expectedAndRealType = cachedBy(
|
|
|
2123
2256
|
appendNodeToVisit(node.right);
|
|
2124
2257
|
continue;
|
|
2125
2258
|
} else if (ts.isReturnStatement(node) && node.expression) {
|
|
2126
|
-
const parentDeclaration =
|
|
2127
|
-
if (
|
|
2128
|
-
const expectedType =
|
|
2259
|
+
const parentDeclaration = getAncestorConvertibleDeclaration(node);
|
|
2260
|
+
if (parentDeclaration) {
|
|
2261
|
+
const expectedType = getInferredReturnType(parentDeclaration);
|
|
2129
2262
|
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2130
|
-
if (
|
|
2131
|
-
result.push([node, expectedType
|
|
2263
|
+
if (expectedType) {
|
|
2264
|
+
result.push([node, expectedType, node, realType]);
|
|
2132
2265
|
}
|
|
2133
2266
|
}
|
|
2134
2267
|
ts.forEachChild(node, appendNodeToVisit);
|
|
@@ -2144,10 +2277,10 @@ var expectedAndRealType = cachedBy(
|
|
|
2144
2277
|
continue;
|
|
2145
2278
|
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
|
|
2146
2279
|
const body = node.body;
|
|
2147
|
-
const expectedType =
|
|
2280
|
+
const expectedType = getInferredReturnType(node);
|
|
2148
2281
|
const realType = typeChecker.getTypeAtLocation(body);
|
|
2149
|
-
if (
|
|
2150
|
-
result.push([body, expectedType
|
|
2282
|
+
if (expectedType) {
|
|
2283
|
+
result.push([body, expectedType, body, realType]);
|
|
2151
2284
|
}
|
|
2152
2285
|
ts.forEachChild(body, appendNodeToVisit);
|
|
2153
2286
|
continue;
|
|
@@ -2160,75 +2293,18 @@ var expectedAndRealType = cachedBy(
|
|
|
2160
2293
|
}
|
|
2161
2294
|
ts.forEachChild(node, appendNodeToVisit);
|
|
2162
2295
|
}
|
|
2296
|
+
expectedAndRealTypeCache.set(sourceFile, result);
|
|
2163
2297
|
return result;
|
|
2164
|
-
}
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
toTest = toTest.concat(type2.types);
|
|
2175
|
-
} else {
|
|
2176
|
-
result.push(type2);
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
return result;
|
|
2180
|
-
};
|
|
2181
|
-
var appendToUniqueTypesMap = fn(
|
|
2182
|
-
"TypeCheckerApi.appendToUniqueTypesMap"
|
|
2183
|
-
)(
|
|
2184
|
-
function* (memory, initialType, shouldExclude) {
|
|
2185
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
2186
|
-
const newIndexes = /* @__PURE__ */ new Set();
|
|
2187
|
-
const knownIndexes = /* @__PURE__ */ new Set();
|
|
2188
|
-
let toTest = [initialType];
|
|
2189
|
-
while (toTest.length > 0) {
|
|
2190
|
-
const type = toTest.pop();
|
|
2191
|
-
if (!type) break;
|
|
2192
|
-
if (yield* shouldExclude(type)) {
|
|
2193
|
-
continue;
|
|
2194
|
-
}
|
|
2195
|
-
if (type.isUnion()) {
|
|
2196
|
-
toTest = toTest.concat(type.types);
|
|
2197
|
-
} else {
|
|
2198
|
-
const foundMatch = [];
|
|
2199
|
-
for (const [typeId, knownType] of memory.entries()) {
|
|
2200
|
-
const areSame = typeChecker.isTypeAssignableTo(knownType, type) && typeChecker.isTypeAssignableTo(type, knownType);
|
|
2201
|
-
if (areSame) {
|
|
2202
|
-
foundMatch.push(typeId);
|
|
2203
|
-
break;
|
|
2204
|
-
}
|
|
2205
|
-
}
|
|
2206
|
-
if (foundMatch.length === 0) {
|
|
2207
|
-
const newId = "t" + (memory.size + 1);
|
|
2208
|
-
memory.set(newId, type);
|
|
2209
|
-
newIndexes.add(newId);
|
|
2210
|
-
} else {
|
|
2211
|
-
knownIndexes.add(foundMatch[0]);
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
return {
|
|
2216
|
-
newIndexes,
|
|
2217
|
-
knownIndexes,
|
|
2218
|
-
allIndexes: pipe(
|
|
2219
|
-
fromIterable(newIndexes),
|
|
2220
|
-
appendAll(fromIterable(knownIndexes))
|
|
2221
|
-
)
|
|
2222
|
-
};
|
|
2223
|
-
}
|
|
2224
|
-
);
|
|
2225
|
-
function makeResolveExternalModuleName(typeChecker) {
|
|
2226
|
-
if (!(hasProperty(typeChecker, "resolveExternalModuleName") && isFunction(typeChecker.resolveExternalModuleName))) {
|
|
2227
|
-
return;
|
|
2228
|
-
}
|
|
2229
|
-
const _internal = typeChecker.resolveExternalModuleName;
|
|
2230
|
-
return (moduleSpecifier) => {
|
|
2231
|
-
return _internal(moduleSpecifier);
|
|
2298
|
+
};
|
|
2299
|
+
return {
|
|
2300
|
+
isUnion,
|
|
2301
|
+
getTypeParameterAtPosition,
|
|
2302
|
+
getMissingTypeEntriesInTargetType,
|
|
2303
|
+
unrollUnionMembers,
|
|
2304
|
+
appendToUniqueTypesMap,
|
|
2305
|
+
deterministicTypeOrder,
|
|
2306
|
+
getInferredReturnType,
|
|
2307
|
+
expectedAndRealType
|
|
2232
2308
|
};
|
|
2233
2309
|
}
|
|
2234
2310
|
|
|
@@ -2238,11 +2314,12 @@ var durationInput = createCompletion({
|
|
|
2238
2314
|
apply: fn("durationInput")(function* (sourceFile, position) {
|
|
2239
2315
|
const ts = yield* service(TypeScriptApi);
|
|
2240
2316
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
2317
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
2241
2318
|
let isInString = false;
|
|
2242
2319
|
const previousToken = ts.findPrecedingToken(position, sourceFile);
|
|
2243
2320
|
if (previousToken && ts.isStringTextContainingNode(previousToken)) {
|
|
2244
|
-
const start =
|
|
2245
|
-
const end = previousToken.
|
|
2321
|
+
const start = ts.getTokenPosOfNode(previousToken, sourceFile);
|
|
2322
|
+
const end = previousToken.end;
|
|
2246
2323
|
if (start < position && position < end) {
|
|
2247
2324
|
isInString = true;
|
|
2248
2325
|
}
|
|
@@ -2252,7 +2329,7 @@ var durationInput = createCompletion({
|
|
|
2252
2329
|
if (isInString && ts.isExpression(previousToken)) {
|
|
2253
2330
|
const type = typeChecker.getContextualType(previousToken);
|
|
2254
2331
|
if (type) {
|
|
2255
|
-
if (!
|
|
2332
|
+
if (!typeCheckerUtils.isUnion(type)) return [];
|
|
2256
2333
|
for (const member of type.types) {
|
|
2257
2334
|
if (member.flags & ts.TypeFlags.TemplateLiteral) {
|
|
2258
2335
|
if (hasProperty(member, "texts") && isArray(member.texts) && member.texts.length === 2 && String(member.texts[1]).trim() === "nanos") {
|
|
@@ -2276,13 +2353,14 @@ var durationInput = createCompletion({
|
|
|
2276
2353
|
|
|
2277
2354
|
// src/core/TypeParser.ts
|
|
2278
2355
|
var TypeParser = Tag("@effect/language-service/TypeParser");
|
|
2279
|
-
var
|
|
2356
|
+
var nanoLayer3 = (fa) => gen(function* () {
|
|
2280
2357
|
const ts = yield* service(TypeScriptApi);
|
|
2281
2358
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
2282
2359
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
2360
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
2283
2361
|
return yield* pipe(
|
|
2284
2362
|
fa,
|
|
2285
|
-
provideService(TypeParser, make3(ts, tsUtils, typeChecker))
|
|
2363
|
+
provideService(TypeParser, make3(ts, tsUtils, typeChecker, typeCheckerUtils))
|
|
2286
2364
|
);
|
|
2287
2365
|
});
|
|
2288
2366
|
var TypeParserIssue = class _TypeParserIssue {
|
|
@@ -2292,27 +2370,27 @@ var TypeParserIssue = class _TypeParserIssue {
|
|
|
2292
2370
|
function typeParserIssue(_message, _type, _node) {
|
|
2293
2371
|
return TypeParserIssue.issue;
|
|
2294
2372
|
}
|
|
2295
|
-
function make3(ts, tsUtils, typeChecker) {
|
|
2373
|
+
function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
2296
2374
|
function covariantTypeArgument(type) {
|
|
2297
|
-
const signatures = type.
|
|
2375
|
+
const signatures = typeChecker.getSignaturesOfType(type, ts.SignatureKind.Call);
|
|
2298
2376
|
if (signatures.length !== 1) {
|
|
2299
2377
|
return typeParserIssue("Covariant type has no call signature", type);
|
|
2300
2378
|
}
|
|
2301
|
-
return succeed(signatures[0]
|
|
2379
|
+
return succeed(typeChecker.getReturnTypeOfSignature(signatures[0]));
|
|
2302
2380
|
}
|
|
2303
2381
|
function contravariantTypeArgument(type) {
|
|
2304
|
-
const signatures = type.
|
|
2382
|
+
const signatures = typeChecker.getSignaturesOfType(type, ts.SignatureKind.Call);
|
|
2305
2383
|
if (signatures.length !== 1) {
|
|
2306
2384
|
return typeParserIssue("Contravariant type has no call signature", type);
|
|
2307
2385
|
}
|
|
2308
|
-
return succeed(signatures[0]
|
|
2386
|
+
return succeed(typeCheckerUtils.getTypeParameterAtPosition(signatures[0], 0));
|
|
2309
2387
|
}
|
|
2310
2388
|
function invariantTypeArgument(type) {
|
|
2311
|
-
const signatures = type.
|
|
2389
|
+
const signatures = typeChecker.getSignaturesOfType(type, ts.SignatureKind.Call);
|
|
2312
2390
|
if (signatures.length !== 1) {
|
|
2313
2391
|
return typeParserIssue("Invariant type has no call signature", type);
|
|
2314
2392
|
}
|
|
2315
|
-
return succeed(signatures[0]
|
|
2393
|
+
return succeed(typeChecker.getReturnTypeOfSignature(signatures[0]));
|
|
2316
2394
|
}
|
|
2317
2395
|
const pipeableType = cachedBy(
|
|
2318
2396
|
function(type, atLocation) {
|
|
@@ -2321,7 +2399,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2321
2399
|
return typeParserIssue("Type has no 'pipe' property", type, atLocation);
|
|
2322
2400
|
}
|
|
2323
2401
|
const pipeType = typeChecker.getTypeOfSymbolAtLocation(pipeSymbol, atLocation);
|
|
2324
|
-
const signatures = pipeType.
|
|
2402
|
+
const signatures = typeChecker.getSignaturesOfType(pipeType, ts.SignatureKind.Call);
|
|
2325
2403
|
if (signatures.length === 0) {
|
|
2326
2404
|
return typeParserIssue("'pipe' property is not callable", type, atLocation);
|
|
2327
2405
|
}
|
|
@@ -2376,7 +2454,9 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2376
2454
|
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
2377
2455
|
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration && ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)
|
|
2378
2456
|
);
|
|
2379
|
-
propertiesSymbols.sort(
|
|
2457
|
+
propertiesSymbols.sort(
|
|
2458
|
+
(a, b) => ts.symbolName(b).indexOf("EffectTypeId") - ts.symbolName(a).indexOf("EffectTypeId")
|
|
2459
|
+
);
|
|
2380
2460
|
for (const propertySymbol of propertiesSymbols) {
|
|
2381
2461
|
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
2382
2462
|
result = pipe(result, orElse2(() => effectVarianceStruct(propertyType, atLocation)));
|
|
@@ -2388,7 +2468,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2388
2468
|
);
|
|
2389
2469
|
const strictEffectType = cachedBy(
|
|
2390
2470
|
fn("TypeParser.strictEffectType")(function* (type, atLocation) {
|
|
2391
|
-
if (!(type.symbol && type.symbol
|
|
2471
|
+
if (!(type.symbol && ts.symbolName(type.symbol) === "Effect" && !type.aliasSymbol)) {
|
|
2392
2472
|
return yield* typeParserIssue("Type name should be Effect with no alias symbol", type, atLocation);
|
|
2393
2473
|
}
|
|
2394
2474
|
return yield* effectType(type, atLocation);
|
|
@@ -2402,7 +2482,9 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2402
2482
|
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
2403
2483
|
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration && ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)
|
|
2404
2484
|
);
|
|
2405
|
-
propertiesSymbols.sort(
|
|
2485
|
+
propertiesSymbols.sort(
|
|
2486
|
+
(a, b) => ts.symbolName(b).indexOf("LayerTypeId") - ts.symbolName(a).indexOf("LayerTypeId")
|
|
2487
|
+
);
|
|
2406
2488
|
for (const propertySymbol of propertiesSymbols) {
|
|
2407
2489
|
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
2408
2490
|
const varianceArgs = yield* option(layerVarianceStruct(
|
|
@@ -2497,6 +2579,21 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2497
2579
|
"TypeParser.importedEffectModule",
|
|
2498
2580
|
(node) => node
|
|
2499
2581
|
);
|
|
2582
|
+
const importedDataModule = cachedBy(
|
|
2583
|
+
fn("TypeParser.importedDataModule")(function* (node) {
|
|
2584
|
+
const type = typeChecker.getTypeAtLocation(node);
|
|
2585
|
+
const propertySymbol = typeChecker.getPropertyOfType(type, "TaggedError");
|
|
2586
|
+
if (!propertySymbol) {
|
|
2587
|
+
return yield* typeParserIssue("Type has no 'TaggedError' property", type, node);
|
|
2588
|
+
}
|
|
2589
|
+
if (!ts.isExpression(node)) {
|
|
2590
|
+
return yield* typeParserIssue("Node is not an expression", type, node);
|
|
2591
|
+
}
|
|
2592
|
+
return node;
|
|
2593
|
+
}),
|
|
2594
|
+
"TypeParser.importedDataModule",
|
|
2595
|
+
(node) => node
|
|
2596
|
+
);
|
|
2500
2597
|
const effectGen = cachedBy(
|
|
2501
2598
|
function(node) {
|
|
2502
2599
|
if (!ts.isCallExpression(node)) {
|
|
@@ -2516,7 +2613,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2516
2613
|
return typeParserIssue("Node is not a property access expression", void 0, node);
|
|
2517
2614
|
}
|
|
2518
2615
|
const propertyAccess = node.expression;
|
|
2519
|
-
if (propertyAccess.name.
|
|
2616
|
+
if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "gen")) {
|
|
2520
2617
|
return typeParserIssue("Call expression name is not 'gen'", void 0, node);
|
|
2521
2618
|
}
|
|
2522
2619
|
return pipe(
|
|
@@ -2560,7 +2657,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2560
2657
|
);
|
|
2561
2658
|
}
|
|
2562
2659
|
const propertyAccess = node.expression;
|
|
2563
|
-
if (propertyAccess.name.
|
|
2660
|
+
if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "fnUntraced")) {
|
|
2564
2661
|
return typeParserIssue(
|
|
2565
2662
|
"Call expression name is not 'fnUntraced'",
|
|
2566
2663
|
void 0,
|
|
@@ -2613,7 +2710,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2613
2710
|
);
|
|
2614
2711
|
}
|
|
2615
2712
|
const propertyAccess = expressionToTest;
|
|
2616
|
-
if (propertyAccess.name.
|
|
2713
|
+
if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "fn")) {
|
|
2617
2714
|
return typeParserIssue(
|
|
2618
2715
|
"Call expression name is not 'fn'",
|
|
2619
2716
|
void 0,
|
|
@@ -2712,7 +2809,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2712
2809
|
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
2713
2810
|
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration && ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)
|
|
2714
2811
|
);
|
|
2715
|
-
propertiesSymbols.sort((a, b) => b.
|
|
2812
|
+
propertiesSymbols.sort((a, b) => ts.symbolName(b).indexOf("TypeId") - ts.symbolName(a).indexOf("TypeId"));
|
|
2716
2813
|
for (const propertySymbol of propertiesSymbols) {
|
|
2717
2814
|
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
2718
2815
|
const varianceArgs = yield* option(effectSchemaVarianceStruct(
|
|
@@ -2741,7 +2838,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2741
2838
|
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
2742
2839
|
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration && ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)
|
|
2743
2840
|
);
|
|
2744
|
-
propertiesSymbols.sort((a, b) => b.
|
|
2841
|
+
propertiesSymbols.sort((a, b) => ts.symbolName(b).indexOf("TypeId") - ts.symbolName(a).indexOf("TypeId"));
|
|
2745
2842
|
for (const propertySymbol of propertiesSymbols) {
|
|
2746
2843
|
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
2747
2844
|
const varianceArgs = yield* option(contextTagVarianceStruct(
|
|
@@ -2759,7 +2856,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2759
2856
|
);
|
|
2760
2857
|
const pipeCall = cachedBy(
|
|
2761
2858
|
function(node) {
|
|
2762
|
-
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && node.expression.name
|
|
2859
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && ts.idText(node.expression.name) === "pipe") {
|
|
2763
2860
|
return succeed({
|
|
2764
2861
|
node,
|
|
2765
2862
|
subject: node.expression.expression,
|
|
@@ -2767,7 +2864,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2767
2864
|
kind: "pipeable"
|
|
2768
2865
|
});
|
|
2769
2866
|
}
|
|
2770
|
-
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression
|
|
2867
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && ts.idText(node.expression) === "pipe" && node.arguments.length > 0) {
|
|
2771
2868
|
const [subject, ...args2] = node.arguments;
|
|
2772
2869
|
return succeed({ node, subject, args: args2, kind: "pipe" });
|
|
2773
2870
|
}
|
|
@@ -2782,11 +2879,13 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2782
2879
|
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
2783
2880
|
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration && ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)
|
|
2784
2881
|
);
|
|
2785
|
-
propertiesSymbols.sort(
|
|
2882
|
+
propertiesSymbols.sort(
|
|
2883
|
+
(a, b) => ts.symbolName(b).indexOf("ScopeTypeId") - ts.symbolName(a).indexOf("ScopeTypeId")
|
|
2884
|
+
);
|
|
2786
2885
|
for (const propertySymbol of propertiesSymbols) {
|
|
2787
2886
|
const computedPropertyExpression = propertySymbol.valueDeclaration.name;
|
|
2788
2887
|
const symbol3 = typeChecker.getSymbolAtLocation(computedPropertyExpression.expression);
|
|
2789
|
-
if (symbol3 && symbol3
|
|
2888
|
+
if (symbol3 && ts.symbolName(symbol3) === "ScopeTypeId") {
|
|
2790
2889
|
return type;
|
|
2791
2890
|
}
|
|
2792
2891
|
}
|
|
@@ -2801,19 +2900,19 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2801
2900
|
if (!thenProperty) return typeParserIssue("not a promise - missing then property", type, atLocation);
|
|
2802
2901
|
const thenType = typeChecker.getTypeOfSymbolAtLocation(thenProperty, atLocation);
|
|
2803
2902
|
if (!thenType) return typeParserIssue("not a promise - missing then property", type, atLocation);
|
|
2804
|
-
for (const callSignature of thenType.
|
|
2903
|
+
for (const callSignature of typeChecker.getSignaturesOfType(thenType, ts.SignatureKind.Call)) {
|
|
2805
2904
|
const parameter = callSignature.parameters[0];
|
|
2806
2905
|
if (!parameter) continue;
|
|
2807
|
-
const parameterType =
|
|
2906
|
+
const parameterType = typeCheckerUtils.getTypeParameterAtPosition(callSignature, 0);
|
|
2808
2907
|
if (!parameterType) continue;
|
|
2809
2908
|
let callbackCallSignatures = [];
|
|
2810
2909
|
let toTest = [parameterType];
|
|
2811
2910
|
while (toTest.length > 0) {
|
|
2812
2911
|
const type2 = toTest.shift();
|
|
2813
2912
|
if (!type2) continue;
|
|
2814
|
-
const callSignatures = type2.
|
|
2913
|
+
const callSignatures = typeChecker.getSignaturesOfType(type2, ts.SignatureKind.Call);
|
|
2815
2914
|
callbackCallSignatures = callbackCallSignatures.concat(callSignatures);
|
|
2816
|
-
if (
|
|
2915
|
+
if (typeCheckerUtils.isUnion(type2)) {
|
|
2817
2916
|
toTest = toTest.concat(type2.types);
|
|
2818
2917
|
}
|
|
2819
2918
|
}
|
|
@@ -2822,7 +2921,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2822
2921
|
if (!callbackParameter) {
|
|
2823
2922
|
continue;
|
|
2824
2923
|
}
|
|
2825
|
-
const callbackParameterType =
|
|
2924
|
+
const callbackParameterType = typeCheckerUtils.getTypeParameterAtPosition(callableType, 0);
|
|
2826
2925
|
if (!callbackParameterType) {
|
|
2827
2926
|
continue;
|
|
2828
2927
|
}
|
|
@@ -2854,7 +2953,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2854
2953
|
if (ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {
|
|
2855
2954
|
const selfTypeNode = schemaCall.typeArguments[0];
|
|
2856
2955
|
const schemaIdentifier = schemaCall.expression;
|
|
2857
|
-
if (ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) && schemaIdentifier.name
|
|
2956
|
+
if (ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) && ts.idText(schemaIdentifier.name) === "Class") {
|
|
2858
2957
|
const parsedSchemaModule = yield* pipe(
|
|
2859
2958
|
importedSchemaModule(schemaIdentifier.expression),
|
|
2860
2959
|
option
|
|
@@ -2890,25 +2989,24 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2890
2989
|
for (const typeX of heritageClause.types) {
|
|
2891
2990
|
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2892
2991
|
const expression = typeX.expression;
|
|
2893
|
-
if (ts.isCallExpression(expression)) {
|
|
2894
|
-
const
|
|
2895
|
-
if (ts.isCallExpression(
|
|
2896
|
-
const
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
const
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
}
|
|
2992
|
+
if (ts.isCallExpression(expression) && expression.arguments.length > 0) {
|
|
2993
|
+
const schemaTaggedClassTCall = expression.expression;
|
|
2994
|
+
if (ts.isCallExpression(schemaTaggedClassTCall) && schemaTaggedClassTCall.typeArguments && schemaTaggedClassTCall.typeArguments.length > 0) {
|
|
2995
|
+
const selfTypeNode = schemaTaggedClassTCall.typeArguments[0];
|
|
2996
|
+
const schemaIdentifier = schemaTaggedClassTCall.expression;
|
|
2997
|
+
if (ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) && ts.idText(schemaIdentifier.name) === "TaggedClass") {
|
|
2998
|
+
const parsedSchemaModule = yield* pipe(
|
|
2999
|
+
importedSchemaModule(schemaIdentifier.expression),
|
|
3000
|
+
option
|
|
3001
|
+
);
|
|
3002
|
+
if (isSome2(parsedSchemaModule)) {
|
|
3003
|
+
return {
|
|
3004
|
+
className: atLocation.name,
|
|
3005
|
+
selfTypeNode,
|
|
3006
|
+
keyStringLiteral: schemaTaggedClassTCall.arguments.length > 0 && ts.isStringLiteral(schemaTaggedClassTCall.arguments[0]) ? schemaTaggedClassTCall.arguments[0] : void 0,
|
|
3007
|
+
tagStringLiteral: expression.arguments.length > 0 && ts.isStringLiteral(expression.arguments[0]) ? expression.arguments[0] : void 0,
|
|
3008
|
+
Schema: parsedSchemaModule.value
|
|
3009
|
+
};
|
|
2912
3010
|
}
|
|
2913
3011
|
}
|
|
2914
3012
|
}
|
|
@@ -2935,24 +3033,23 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2935
3033
|
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2936
3034
|
const expression = typeX.expression;
|
|
2937
3035
|
if (ts.isCallExpression(expression)) {
|
|
2938
|
-
const
|
|
2939
|
-
if (ts.isCallExpression(
|
|
2940
|
-
const
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
const
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
}
|
|
3036
|
+
const schemaTaggedErrorTCall = expression.expression;
|
|
3037
|
+
if (ts.isCallExpression(schemaTaggedErrorTCall) && schemaTaggedErrorTCall.typeArguments && schemaTaggedErrorTCall.typeArguments.length > 0) {
|
|
3038
|
+
const selfTypeNode = schemaTaggedErrorTCall.typeArguments[0];
|
|
3039
|
+
const schemaIdentifier = schemaTaggedErrorTCall.expression;
|
|
3040
|
+
if (ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) && ts.idText(schemaIdentifier.name) === "TaggedError") {
|
|
3041
|
+
const parsedSchemaModule = yield* pipe(
|
|
3042
|
+
importedSchemaModule(schemaIdentifier.expression),
|
|
3043
|
+
option
|
|
3044
|
+
);
|
|
3045
|
+
if (isSome2(parsedSchemaModule)) {
|
|
3046
|
+
return {
|
|
3047
|
+
className: atLocation.name,
|
|
3048
|
+
selfTypeNode,
|
|
3049
|
+
keyStringLiteral: schemaTaggedErrorTCall.arguments.length > 0 && ts.isStringLiteral(schemaTaggedErrorTCall.arguments[0]) ? schemaTaggedErrorTCall.arguments[0] : void 0,
|
|
3050
|
+
tagStringLiteral: expression.arguments.length > 0 && ts.isStringLiteral(expression.arguments[0]) ? expression.arguments[0] : void 0,
|
|
3051
|
+
Schema: parsedSchemaModule.value
|
|
3052
|
+
};
|
|
2956
3053
|
}
|
|
2957
3054
|
}
|
|
2958
3055
|
}
|
|
@@ -2965,6 +3062,82 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2965
3062
|
"TypeParser.extendsSchemaTaggedError",
|
|
2966
3063
|
(atLocation) => atLocation
|
|
2967
3064
|
);
|
|
3065
|
+
const extendsDataTaggedError = cachedBy(
|
|
3066
|
+
fn("TypeParser.extendsDataTaggedError")(function* (atLocation) {
|
|
3067
|
+
if (!atLocation.name) {
|
|
3068
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
3069
|
+
}
|
|
3070
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
3071
|
+
if (!heritageClauses) {
|
|
3072
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
3073
|
+
}
|
|
3074
|
+
for (const heritageClause of heritageClauses) {
|
|
3075
|
+
for (const typeX of heritageClause.types) {
|
|
3076
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
3077
|
+
const expression = typeX.expression;
|
|
3078
|
+
if (ts.isCallExpression(expression)) {
|
|
3079
|
+
const dataTaggedErrorCall = expression;
|
|
3080
|
+
const dataIdentifier = dataTaggedErrorCall.expression;
|
|
3081
|
+
if (ts.isPropertyAccessExpression(dataIdentifier) && ts.isIdentifier(dataIdentifier.name) && ts.idText(dataIdentifier.name) === "TaggedError") {
|
|
3082
|
+
const parsedDataModule = yield* pipe(
|
|
3083
|
+
importedDataModule(dataIdentifier.expression),
|
|
3084
|
+
option
|
|
3085
|
+
);
|
|
3086
|
+
if (isSome2(parsedDataModule)) {
|
|
3087
|
+
return {
|
|
3088
|
+
className: atLocation.name,
|
|
3089
|
+
keyStringLiteral: dataTaggedErrorCall.arguments.length > 0 && ts.isStringLiteral(dataTaggedErrorCall.arguments[0]) ? dataTaggedErrorCall.arguments[0] : void 0,
|
|
3090
|
+
Data: parsedDataModule.value
|
|
3091
|
+
};
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
return yield* typeParserIssue("Class does not extend Data.TaggedError", void 0, atLocation);
|
|
3099
|
+
}),
|
|
3100
|
+
"TypeParser.extendsDataTaggedError",
|
|
3101
|
+
(atLocation) => atLocation
|
|
3102
|
+
);
|
|
3103
|
+
const extendsDataTaggedClass = cachedBy(
|
|
3104
|
+
fn("TypeParser.extendsDataTaggedClass")(function* (atLocation) {
|
|
3105
|
+
if (!atLocation.name) {
|
|
3106
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
3107
|
+
}
|
|
3108
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
3109
|
+
if (!heritageClauses) {
|
|
3110
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
3111
|
+
}
|
|
3112
|
+
for (const heritageClause of heritageClauses) {
|
|
3113
|
+
for (const typeX of heritageClause.types) {
|
|
3114
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
3115
|
+
const expression = typeX.expression;
|
|
3116
|
+
if (ts.isCallExpression(expression)) {
|
|
3117
|
+
const dataTaggedClassCall = expression;
|
|
3118
|
+
const dataIdentifier = dataTaggedClassCall.expression;
|
|
3119
|
+
if (ts.isPropertyAccessExpression(dataIdentifier) && ts.isIdentifier(dataIdentifier.name) && ts.idText(dataIdentifier.name) === "TaggedClass") {
|
|
3120
|
+
const parsedDataModule = yield* pipe(
|
|
3121
|
+
importedDataModule(dataIdentifier.expression),
|
|
3122
|
+
option
|
|
3123
|
+
);
|
|
3124
|
+
if (isSome2(parsedDataModule)) {
|
|
3125
|
+
return {
|
|
3126
|
+
className: atLocation.name,
|
|
3127
|
+
keyStringLiteral: dataTaggedClassCall.arguments.length > 0 && ts.isStringLiteral(dataTaggedClassCall.arguments[0]) ? dataTaggedClassCall.arguments[0] : void 0,
|
|
3128
|
+
Data: parsedDataModule.value
|
|
3129
|
+
};
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
return yield* typeParserIssue("Class does not extend Data.TaggedClass", void 0, atLocation);
|
|
3137
|
+
}),
|
|
3138
|
+
"TypeParser.extendsDataTaggedClass",
|
|
3139
|
+
(atLocation) => atLocation
|
|
3140
|
+
);
|
|
2968
3141
|
const extendsSchemaTaggedRequest = cachedBy(
|
|
2969
3142
|
fn("TypeParser.extendsSchemaTaggedRequest")(function* (atLocation) {
|
|
2970
3143
|
if (!atLocation.name) {
|
|
@@ -2979,24 +3152,23 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
2979
3152
|
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2980
3153
|
const expression = typeX.expression;
|
|
2981
3154
|
if (ts.isCallExpression(expression)) {
|
|
2982
|
-
const
|
|
2983
|
-
if (ts.isCallExpression(
|
|
2984
|
-
const
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
const
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
}
|
|
3155
|
+
const schemaTaggedRequestTCall = expression.expression;
|
|
3156
|
+
if (ts.isCallExpression(schemaTaggedRequestTCall) && schemaTaggedRequestTCall.typeArguments && schemaTaggedRequestTCall.typeArguments.length > 0) {
|
|
3157
|
+
const selfTypeNode = schemaTaggedRequestTCall.typeArguments[0];
|
|
3158
|
+
const schemaIdentifier = schemaTaggedRequestTCall.expression;
|
|
3159
|
+
if (ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) && ts.idText(schemaIdentifier.name) === "TaggedRequest") {
|
|
3160
|
+
const parsedSchemaModule = yield* pipe(
|
|
3161
|
+
importedSchemaModule(schemaIdentifier.expression),
|
|
3162
|
+
option
|
|
3163
|
+
);
|
|
3164
|
+
if (isSome2(parsedSchemaModule)) {
|
|
3165
|
+
return {
|
|
3166
|
+
className: atLocation.name,
|
|
3167
|
+
selfTypeNode,
|
|
3168
|
+
tagStringLiteral: expression.arguments.length > 0 && ts.isStringLiteral(expression.arguments[0]) ? expression.arguments[0] : void 0,
|
|
3169
|
+
keyStringLiteral: schemaTaggedRequestTCall.arguments.length > 0 && ts.isStringLiteral(schemaTaggedRequestTCall.arguments[0]) ? schemaTaggedRequestTCall.arguments[0] : void 0,
|
|
3170
|
+
Schema: parsedSchemaModule.value
|
|
3171
|
+
};
|
|
3000
3172
|
}
|
|
3001
3173
|
}
|
|
3002
3174
|
}
|
|
@@ -3014,9 +3186,6 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
3014
3186
|
if (!atLocation.name) {
|
|
3015
3187
|
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
3016
3188
|
}
|
|
3017
|
-
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
3018
|
-
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
3019
|
-
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
3020
3189
|
const heritageClauses = atLocation.heritageClauses;
|
|
3021
3190
|
if (!heritageClauses) {
|
|
3022
3191
|
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
@@ -3030,16 +3199,20 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
3030
3199
|
if (ts.isCallExpression(contextTagCall) && wholeCall.typeArguments && wholeCall.typeArguments.length > 0) {
|
|
3031
3200
|
const contextTagIdentifier = contextTagCall.expression;
|
|
3032
3201
|
const selfTypeNode = wholeCall.typeArguments[0];
|
|
3033
|
-
if (ts.isPropertyAccessExpression(contextTagIdentifier) && ts.isIdentifier(contextTagIdentifier.name) && contextTagIdentifier.name
|
|
3202
|
+
if (ts.isPropertyAccessExpression(contextTagIdentifier) && ts.isIdentifier(contextTagIdentifier.name) && ts.idText(contextTagIdentifier.name) === "Tag") {
|
|
3034
3203
|
const parsedContextModule = yield* pipe(
|
|
3035
3204
|
importedContextModule(contextTagIdentifier.expression),
|
|
3036
3205
|
option
|
|
3037
3206
|
);
|
|
3038
3207
|
if (isSome2(parsedContextModule)) {
|
|
3208
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
3209
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
3210
|
+
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
3039
3211
|
const tagType = yield* contextTag(type, atLocation);
|
|
3040
3212
|
return {
|
|
3041
3213
|
className: atLocation.name,
|
|
3042
3214
|
selfTypeNode,
|
|
3215
|
+
keyStringLiteral: ts.isStringLiteral(contextTagCall.arguments[0]) ? contextTagCall.arguments[0] : void 0,
|
|
3043
3216
|
args: contextTagCall.arguments,
|
|
3044
3217
|
Identifier: tagType.Identifier,
|
|
3045
3218
|
Tag: parsedContextModule.value
|
|
@@ -3061,9 +3234,6 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
3061
3234
|
if (!atLocation.name) {
|
|
3062
3235
|
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
3063
3236
|
}
|
|
3064
|
-
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
3065
|
-
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
3066
|
-
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
3067
3237
|
const heritageClauses = atLocation.heritageClauses;
|
|
3068
3238
|
if (!heritageClauses) {
|
|
3069
3239
|
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
@@ -3077,7 +3247,10 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
3077
3247
|
if (ts.isCallExpression(effectServiceCall) && effectServiceCall.typeArguments && effectServiceCall.typeArguments.length > 0) {
|
|
3078
3248
|
const effectServiceIdentifier = effectServiceCall.expression;
|
|
3079
3249
|
const selfTypeNode = effectServiceCall.typeArguments[0];
|
|
3080
|
-
if (ts.isPropertyAccessExpression(effectServiceIdentifier) && ts.isIdentifier(effectServiceIdentifier.name) && effectServiceIdentifier.name
|
|
3250
|
+
if (ts.isPropertyAccessExpression(effectServiceIdentifier) && ts.isIdentifier(effectServiceIdentifier.name) && ts.idText(effectServiceIdentifier.name) === "Service") {
|
|
3251
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
3252
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
3253
|
+
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
3081
3254
|
const parsedContextTag = yield* pipe(
|
|
3082
3255
|
importedEffectModule(effectServiceIdentifier.expression),
|
|
3083
3256
|
flatMap(() => contextTag(type, atLocation)),
|
|
@@ -3090,10 +3263,10 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
3090
3263
|
const args2 = wholeCall.arguments[1];
|
|
3091
3264
|
if (ts.isObjectLiteralExpression(args2)) {
|
|
3092
3265
|
for (const property of args2.properties) {
|
|
3093
|
-
if (ts.isPropertyAssignment(property) && property.name && ts.isIdentifier(property.name) && property.name
|
|
3266
|
+
if (ts.isPropertyAssignment(property) && property.name && ts.isIdentifier(property.name) && ts.idText(property.name) === "accessors" && property.initializer && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
3094
3267
|
accessors2 = true;
|
|
3095
3268
|
}
|
|
3096
|
-
if (ts.isPropertyAssignment(property) && property.name && ts.isIdentifier(property.name) && property.name
|
|
3269
|
+
if (ts.isPropertyAssignment(property) && property.name && ts.isIdentifier(property.name) && ts.idText(property.name) === "dependencies" && property.initializer && ts.isArrayLiteralExpression(property.initializer)) {
|
|
3097
3270
|
dependencies = property.initializer.elements;
|
|
3098
3271
|
}
|
|
3099
3272
|
}
|
|
@@ -3104,6 +3277,7 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
3104
3277
|
className: atLocation.name,
|
|
3105
3278
|
selfTypeNode,
|
|
3106
3279
|
args: wholeCall.arguments,
|
|
3280
|
+
keyStringLiteral: ts.isStringLiteral(wholeCall.arguments[0]) ? wholeCall.arguments[0] : void 0,
|
|
3107
3281
|
options: wholeCall.arguments[1],
|
|
3108
3282
|
accessors: accessors2,
|
|
3109
3283
|
dependencies
|
|
@@ -3142,6 +3316,8 @@ function make3(ts, tsUtils, typeChecker) {
|
|
|
3142
3316
|
extendsSchemaClass,
|
|
3143
3317
|
extendsSchemaTaggedClass,
|
|
3144
3318
|
extendsSchemaTaggedError,
|
|
3319
|
+
extendsDataTaggedError,
|
|
3320
|
+
extendsDataTaggedClass,
|
|
3145
3321
|
extendsSchemaTaggedRequest
|
|
3146
3322
|
};
|
|
3147
3323
|
}
|
|
@@ -3153,7 +3329,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3153
3329
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3154
3330
|
const typeParser = yield* service(TypeParser);
|
|
3155
3331
|
const changeTracker = yield* service(ChangeTracker);
|
|
3156
|
-
const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.
|
|
3332
|
+
const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.end - 1;
|
|
3157
3333
|
const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3158
3334
|
sourceFile,
|
|
3159
3335
|
"effect",
|
|
@@ -3167,7 +3343,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3167
3343
|
),
|
|
3168
3344
|
void 0,
|
|
3169
3345
|
[
|
|
3170
|
-
ts.factory.createIdentifier(className2
|
|
3346
|
+
ts.factory.createIdentifier(ts.idText(className2)),
|
|
3171
3347
|
ts.factory.createArrowFunction(
|
|
3172
3348
|
void 0,
|
|
3173
3349
|
void 0,
|
|
@@ -3217,9 +3393,9 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3217
3393
|
const generateReturnType = (type, atLocation2, className2) => pipe(
|
|
3218
3394
|
typeParser.effectType(type, atLocation2),
|
|
3219
3395
|
flatMap((returnedEffect) => {
|
|
3220
|
-
const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(className2
|
|
3396
|
+
const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(ts.idText(className2)) : ts.factory.createUnionTypeNode(
|
|
3221
3397
|
[
|
|
3222
|
-
ts.factory.createTypeReferenceNode(className2
|
|
3398
|
+
ts.factory.createTypeReferenceNode(ts.idText(className2)),
|
|
3223
3399
|
typeChecker.typeToTypeNode(returnedEffect.R, atLocation2, ts.NodeBuilderFlags.NoTruncation)
|
|
3224
3400
|
]
|
|
3225
3401
|
);
|
|
@@ -3267,7 +3443,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3267
3443
|
ts.factory.createIdentifier("UnknownException")
|
|
3268
3444
|
)
|
|
3269
3445
|
),
|
|
3270
|
-
ts.factory.createTypeReferenceNode(className2
|
|
3446
|
+
ts.factory.createTypeReferenceNode(ts.idText(className2))
|
|
3271
3447
|
]
|
|
3272
3448
|
));
|
|
3273
3449
|
})
|
|
@@ -3284,7 +3460,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3284
3460
|
[
|
|
3285
3461
|
successType,
|
|
3286
3462
|
ts.factory.createTypeReferenceNode("never"),
|
|
3287
|
-
ts.factory.createTypeReferenceNode(className2
|
|
3463
|
+
ts.factory.createTypeReferenceNode(ts.idText(className2))
|
|
3288
3464
|
]
|
|
3289
3465
|
);
|
|
3290
3466
|
return succeed(typeNode);
|
|
@@ -3298,7 +3474,11 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3298
3474
|
ts.NodeBuilderFlags.NoTruncation
|
|
3299
3475
|
);
|
|
3300
3476
|
if (!signatureDeclaration) return yield* fail("error generating signature");
|
|
3301
|
-
const returnType = yield* generateReturnType(
|
|
3477
|
+
const returnType = yield* generateReturnType(
|
|
3478
|
+
typeChecker.getReturnTypeOfSignature(signature),
|
|
3479
|
+
atLocation2,
|
|
3480
|
+
className2
|
|
3481
|
+
);
|
|
3302
3482
|
return ts.factory.createFunctionTypeNode(
|
|
3303
3483
|
signatureDeclaration.typeParameters,
|
|
3304
3484
|
signatureDeclaration.parameters,
|
|
@@ -3308,7 +3488,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3308
3488
|
for (const { property, propertyType } of involvedMembers) {
|
|
3309
3489
|
const callSignatures = [];
|
|
3310
3490
|
let propertyDeclaration = void 0;
|
|
3311
|
-
for (const signature of propertyType.
|
|
3491
|
+
for (const signature of typeChecker.getSignaturesOfType(propertyType, ts.SignatureKind.Call)) {
|
|
3312
3492
|
yield* pipe(
|
|
3313
3493
|
proxySignature(signature, atLocation, className),
|
|
3314
3494
|
map3((sig) => {
|
|
@@ -3319,17 +3499,18 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3319
3499
|
}
|
|
3320
3500
|
const allSignatures = ts.factory.createIntersectionTypeNode(callSignatures);
|
|
3321
3501
|
const type = tsUtils.simplifyTypeNode(allSignatures);
|
|
3322
|
-
propertyDeclaration = createFunctionProperty(className,
|
|
3502
|
+
propertyDeclaration = createFunctionProperty(className, ts.symbolName(property), type, callSignatures.length > 1);
|
|
3323
3503
|
const oldProperty = atLocation.members.filter(ts.isPropertyDeclaration).find((p) => {
|
|
3324
3504
|
const symbol3 = typeChecker.getSymbolAtLocation(p.name);
|
|
3325
|
-
return symbol3
|
|
3505
|
+
return symbol3 && ts.symbolName(symbol3) === ts.symbolName(property);
|
|
3326
3506
|
});
|
|
3327
3507
|
if (oldProperty) {
|
|
3508
|
+
const start = ts.getTokenPosOfNode(oldProperty, sourceFile);
|
|
3328
3509
|
changeTracker.deleteRange(sourceFile, {
|
|
3329
|
-
pos:
|
|
3330
|
-
end: oldProperty.
|
|
3510
|
+
pos: start,
|
|
3511
|
+
end: oldProperty.end
|
|
3331
3512
|
});
|
|
3332
|
-
changeTracker.insertNodeAt(sourceFile,
|
|
3513
|
+
changeTracker.insertNodeAt(sourceFile, start, propertyDeclaration);
|
|
3333
3514
|
} else {
|
|
3334
3515
|
changeTracker.insertNodeAt(sourceFile, insertLocation, propertyDeclaration, { suffix: "\n" });
|
|
3335
3516
|
}
|
|
@@ -3348,15 +3529,15 @@ var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
|
|
|
3348
3529
|
const involvedMembers = [];
|
|
3349
3530
|
for (const property of typeChecker.getPropertiesOfType(Service)) {
|
|
3350
3531
|
const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, node);
|
|
3351
|
-
const callSignatures = propertyType.
|
|
3532
|
+
const callSignatures = typeChecker.getSignaturesOfType(propertyType, ts.SignatureKind.Call);
|
|
3352
3533
|
if (callSignatures.length > 0) {
|
|
3353
3534
|
const withTypeParameters = callSignatures.filter((_) => _.typeParameters && _.typeParameters.length > 0);
|
|
3354
3535
|
if (callSignatures.length > 1 || withTypeParameters.length > 0) involvedMembers.push({ property, propertyType });
|
|
3355
3536
|
}
|
|
3356
3537
|
}
|
|
3357
3538
|
const hash2 = involvedMembers.map(({ property, propertyType }) => {
|
|
3358
|
-
return
|
|
3359
|
-
}).concat([className
|
|
3539
|
+
return ts.symbolName(property) + ": " + typeChecker.typeToString(propertyType);
|
|
3540
|
+
}).concat([ts.idText(className)]).join("\n");
|
|
3360
3541
|
return { Service, className, atLocation: node, hash: cyrb53(hash2), involvedMembers };
|
|
3361
3542
|
});
|
|
3362
3543
|
var writeTagClassAccessors = createRefactor({
|
|
@@ -3463,8 +3644,8 @@ var effectDataClasses = createCompletion({
|
|
|
3463
3644
|
"effect",
|
|
3464
3645
|
"Data"
|
|
3465
3646
|
) || "Data";
|
|
3466
|
-
if (effectDataIdentifier !== accessedObject
|
|
3467
|
-
const name = className
|
|
3647
|
+
if (effectDataIdentifier !== ts.idText(accessedObject)) return [];
|
|
3648
|
+
const name = ts.idText(className);
|
|
3468
3649
|
return [{
|
|
3469
3650
|
name: `TaggedError("${name}")`,
|
|
3470
3651
|
kind: ts.ScriptElementKind.constElement,
|
|
@@ -3481,10 +3662,10 @@ var effectDataClasses = createCompletion({
|
|
|
3481
3662
|
})
|
|
3482
3663
|
});
|
|
3483
3664
|
|
|
3484
|
-
// node_modules/.pnpm/effect@3.17.
|
|
3665
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/encoding/common.js
|
|
3485
3666
|
var encoder = /* @__PURE__ */ new TextEncoder();
|
|
3486
3667
|
|
|
3487
|
-
// node_modules/.pnpm/effect@3.17.
|
|
3668
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/encoding/base64.js
|
|
3488
3669
|
var encode = (bytes) => {
|
|
3489
3670
|
const length = bytes.length;
|
|
3490
3671
|
let result = "";
|
|
@@ -3510,10 +3691,10 @@ var encode = (bytes) => {
|
|
|
3510
3691
|
};
|
|
3511
3692
|
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", "+", "/"];
|
|
3512
3693
|
|
|
3513
|
-
// node_modules/.pnpm/effect@3.17.
|
|
3694
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/encoding/base64Url.js
|
|
3514
3695
|
var encode2 = (data) => encode(data).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
3515
3696
|
|
|
3516
|
-
// node_modules/.pnpm/effect@3.17.
|
|
3697
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Encoding.js
|
|
3517
3698
|
var encodeBase64Url = (input) => typeof input === "string" ? encode2(encoder.encode(input)) : encode2(input);
|
|
3518
3699
|
|
|
3519
3700
|
// src/diagnostics/classSelfMismatch.ts
|
|
@@ -3547,12 +3728,12 @@ var classSelfMismatch = createDiagnostic({
|
|
|
3547
3728
|
let actualName = "";
|
|
3548
3729
|
if (ts.isTypeReferenceNode(selfTypeNode)) {
|
|
3549
3730
|
if (ts.isIdentifier(selfTypeNode.typeName)) {
|
|
3550
|
-
actualName = selfTypeNode.typeName
|
|
3731
|
+
actualName = ts.idText(selfTypeNode.typeName);
|
|
3551
3732
|
} else if (ts.isQualifiedName(selfTypeNode.typeName)) {
|
|
3552
|
-
actualName = selfTypeNode.typeName.right
|
|
3733
|
+
actualName = ts.idText(selfTypeNode.typeName.right);
|
|
3553
3734
|
}
|
|
3554
3735
|
}
|
|
3555
|
-
const expectedName = className
|
|
3736
|
+
const expectedName = ts.idText(className);
|
|
3556
3737
|
if (actualName !== expectedName) {
|
|
3557
3738
|
report({
|
|
3558
3739
|
location: selfTypeNode,
|
|
@@ -3637,11 +3818,12 @@ var effectInVoidSuccess = createDiagnostic({
|
|
|
3637
3818
|
const ts = yield* service(TypeScriptApi);
|
|
3638
3819
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3639
3820
|
const typeParser = yield* service(TypeParser);
|
|
3821
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
3640
3822
|
const checkForEffectInVoid = fn("effectInVoidSuccess.checkForEffectInVoid")(function* (node, expectedType, valueNode, realType) {
|
|
3641
3823
|
const expectedEffect = yield* typeParser.effectType(expectedType, node);
|
|
3642
3824
|
const realEffect = yield* typeParser.effectType(realType, valueNode);
|
|
3643
3825
|
if (expectedEffect.A.flags & ts.TypeFlags.Void) {
|
|
3644
|
-
const voidValueTypes = unrollUnionMembers(realEffect.A);
|
|
3826
|
+
const voidValueTypes = typeCheckerUtils.unrollUnionMembers(realEffect.A);
|
|
3645
3827
|
const voidedEffect = yield* firstSuccessOf(
|
|
3646
3828
|
voidValueTypes.map((_) => map3(typeParser.strictEffectType(_, node), () => _))
|
|
3647
3829
|
);
|
|
@@ -3649,7 +3831,7 @@ var effectInVoidSuccess = createDiagnostic({
|
|
|
3649
3831
|
}
|
|
3650
3832
|
return yield* fail(typeParserIssue("expectedEffect success is not void"));
|
|
3651
3833
|
});
|
|
3652
|
-
const entries =
|
|
3834
|
+
const entries = typeCheckerUtils.expectedAndRealType(sourceFile);
|
|
3653
3835
|
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
3654
3836
|
if (expectedType !== realType) {
|
|
3655
3837
|
yield* pipe(
|
|
@@ -3803,12 +3985,14 @@ var importFromBarrel = createDiagnostic({
|
|
|
3803
3985
|
const moduleSymbol = resolveExternalModuleName(importDeclaration.moduleSpecifier);
|
|
3804
3986
|
if (!moduleSymbol) return;
|
|
3805
3987
|
if (!moduleSymbol.exports) return;
|
|
3806
|
-
const sourceFile2 =
|
|
3988
|
+
const sourceFile2 = tsUtils.getSourceFileOfNode(importDeclaration);
|
|
3989
|
+
if (!sourceFile2) return;
|
|
3807
3990
|
const nodeForSymbol = element.propertyName || element.name;
|
|
3808
3991
|
const aliasSymbol = element.name || element.propertyName;
|
|
3809
|
-
const aliasedName = aliasSymbol
|
|
3992
|
+
const aliasedName = ts.idText(aliasSymbol);
|
|
3810
3993
|
if (!ts.isIdentifier(nodeForSymbol)) return;
|
|
3811
|
-
const importedName = nodeForSymbol
|
|
3994
|
+
const importedName = ts.idText(nodeForSymbol);
|
|
3995
|
+
if (!importedName) return;
|
|
3812
3996
|
const reexportedSymbol = moduleSymbol.exports.get(ts.escapeLeadingUnderscores(importedName));
|
|
3813
3997
|
if (!reexportedSymbol) return;
|
|
3814
3998
|
if (!(reexportedSymbol.declarations && reexportedSymbol.declarations.length === 1)) return;
|
|
@@ -3820,7 +4004,8 @@ var importFromBarrel = createDiagnostic({
|
|
|
3820
4004
|
const originalModuleSymbol = resolveExternalModuleName(exportDeclaration.moduleSpecifier);
|
|
3821
4005
|
if (!originalModuleSymbol) return;
|
|
3822
4006
|
if (!originalModuleSymbol.valueDeclaration) return;
|
|
3823
|
-
const originalSourceFile = originalModuleSymbol.valueDeclaration
|
|
4007
|
+
const originalSourceFile = tsUtils.getSourceFileOfNode(originalModuleSymbol.valueDeclaration);
|
|
4008
|
+
if (!originalSourceFile) return;
|
|
3824
4009
|
const unbarrelledFileName = getModuleSpecifier(
|
|
3825
4010
|
program.getCompilerOptions(),
|
|
3826
4011
|
sourceFile2,
|
|
@@ -3913,8 +4098,8 @@ var leakingRequirements = createDiagnostic({
|
|
|
3913
4098
|
apply: fn("leakingRequirements.apply")(function* (sourceFile, report) {
|
|
3914
4099
|
const ts = yield* service(TypeScriptApi);
|
|
3915
4100
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
4101
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
3916
4102
|
const typeParser = yield* service(TypeParser);
|
|
3917
|
-
const typeOrder = yield* deterministicTypeOrder;
|
|
3918
4103
|
const parseLeakedRequirements = cachedBy(
|
|
3919
4104
|
fn("leakingServices.checkServiceLeaking")(
|
|
3920
4105
|
function* (service2, atLocation) {
|
|
@@ -3930,10 +4115,16 @@ var leakingRequirements = createDiagnostic({
|
|
|
3930
4115
|
typeParser.effectType(servicePropertyType, atLocation),
|
|
3931
4116
|
map3((_) => effectContextType = _.R),
|
|
3932
4117
|
orElse2(() => {
|
|
3933
|
-
const servicePropertyCallSignatures =
|
|
4118
|
+
const servicePropertyCallSignatures = typeChecker.getSignaturesOfType(
|
|
4119
|
+
servicePropertyType,
|
|
4120
|
+
ts.SignatureKind.Call
|
|
4121
|
+
);
|
|
3934
4122
|
if (servicePropertyCallSignatures.length === 1) {
|
|
3935
4123
|
return pipe(
|
|
3936
|
-
typeParser.effectType(
|
|
4124
|
+
typeParser.effectType(
|
|
4125
|
+
typeChecker.getReturnTypeOfSignature(servicePropertyCallSignatures[0]),
|
|
4126
|
+
atLocation
|
|
4127
|
+
),
|
|
3937
4128
|
map3((_) => {
|
|
3938
4129
|
effectContextType = _.R;
|
|
3939
4130
|
})
|
|
@@ -3945,7 +4136,7 @@ var leakingRequirements = createDiagnostic({
|
|
|
3945
4136
|
);
|
|
3946
4137
|
if (effectContextType) {
|
|
3947
4138
|
effectMembers++;
|
|
3948
|
-
const { allIndexes } = yield* appendToUniqueTypesMap(
|
|
4139
|
+
const { allIndexes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
3949
4140
|
memory,
|
|
3950
4141
|
effectContextType,
|
|
3951
4142
|
(type) => {
|
|
@@ -3993,7 +4184,7 @@ More info at https://effect.website/docs/requirements-management/layers/#avoidin
|
|
|
3993
4184
|
while (nodeToVisit.length > 0) {
|
|
3994
4185
|
const node = nodeToVisit.shift();
|
|
3995
4186
|
const typesToCheck = [];
|
|
3996
|
-
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && node.expression.name
|
|
4187
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && ts.idText(node.expression.name) === "GenericTag") {
|
|
3997
4188
|
typesToCheck.push([typeChecker.getTypeAtLocation(node), node]);
|
|
3998
4189
|
} else if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {
|
|
3999
4190
|
const classSym = typeChecker.getSymbolAtLocation(node.name);
|
|
@@ -4011,7 +4202,9 @@ More info at https://effect.website/docs/requirements-management/layers/#avoidin
|
|
|
4011
4202
|
flatMap(
|
|
4012
4203
|
({ Service }) => pipe(
|
|
4013
4204
|
parseLeakedRequirements(Service, node),
|
|
4014
|
-
map3(
|
|
4205
|
+
map3(
|
|
4206
|
+
(requirements) => reportLeakingRequirements(reportAt, sort(requirements, typeCheckerUtils.deterministicTypeOrder))
|
|
4207
|
+
)
|
|
4015
4208
|
)
|
|
4016
4209
|
),
|
|
4017
4210
|
orElse2(() => sync(() => ts.forEachChild(node, appendNodeToVisit))),
|
|
@@ -4030,21 +4223,21 @@ var missingEffectContext = createDiagnostic({
|
|
|
4030
4223
|
apply: fn("missingEffectContext.apply")(function* (sourceFile, report) {
|
|
4031
4224
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
4032
4225
|
const typeParser = yield* service(TypeParser);
|
|
4033
|
-
const
|
|
4226
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
4034
4227
|
const checkForMissingContextTypes = (node, expectedType, valueNode, realType) => pipe(
|
|
4035
4228
|
all(
|
|
4036
4229
|
typeParser.effectType(expectedType, node),
|
|
4037
4230
|
typeParser.effectType(realType, valueNode)
|
|
4038
4231
|
),
|
|
4039
|
-
|
|
4040
|
-
([expectedEffect, realEffect]) => getMissingTypeEntriesInTargetType(
|
|
4232
|
+
map3(
|
|
4233
|
+
([expectedEffect, realEffect]) => typeCheckerUtils.getMissingTypeEntriesInTargetType(
|
|
4041
4234
|
realEffect.R,
|
|
4042
4235
|
expectedEffect.R
|
|
4043
4236
|
)
|
|
4044
4237
|
)
|
|
4045
4238
|
);
|
|
4046
|
-
const sortTypes = sort(
|
|
4047
|
-
const entries =
|
|
4239
|
+
const sortTypes = sort(typeCheckerUtils.deterministicTypeOrder);
|
|
4240
|
+
const entries = getEffectLspPatchSourceFileMetadata(sourceFile)?.relationErrors || typeCheckerUtils.expectedAndRealType(sourceFile);
|
|
4048
4241
|
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
4049
4242
|
if (expectedType !== realType) {
|
|
4050
4243
|
yield* pipe(
|
|
@@ -4079,8 +4272,8 @@ var missingEffectError = createDiagnostic({
|
|
|
4079
4272
|
const ts = yield* service(TypeScriptApi);
|
|
4080
4273
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
4081
4274
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
4275
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
4082
4276
|
const typeParser = yield* service(TypeParser);
|
|
4083
|
-
const typeOrder = yield* deterministicTypeOrder;
|
|
4084
4277
|
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4085
4278
|
sourceFile,
|
|
4086
4279
|
"effect",
|
|
@@ -4099,18 +4292,18 @@ var missingEffectError = createDiagnostic({
|
|
|
4099
4292
|
typeParser.effectType(expectedType, node),
|
|
4100
4293
|
typeParser.effectType(realType, valueNode)
|
|
4101
4294
|
),
|
|
4102
|
-
|
|
4295
|
+
map3(
|
|
4103
4296
|
([expectedEffect, realEffect]) => pipe(
|
|
4104
|
-
getMissingTypeEntriesInTargetType(
|
|
4297
|
+
typeCheckerUtils.getMissingTypeEntriesInTargetType(
|
|
4105
4298
|
realEffect.E,
|
|
4106
4299
|
expectedEffect.E
|
|
4107
4300
|
),
|
|
4108
|
-
|
|
4301
|
+
(missingErrorTypes) => ({ missingErrorTypes, expectedErrorType: expectedEffect.E })
|
|
4109
4302
|
)
|
|
4110
4303
|
)
|
|
4111
4304
|
);
|
|
4112
|
-
const sortTypes = sort(
|
|
4113
|
-
const entries =
|
|
4305
|
+
const sortTypes = sort(typeCheckerUtils.deterministicTypeOrder);
|
|
4306
|
+
const entries = getEffectLspPatchSourceFileMetadata(sourceFile)?.relationErrors || typeCheckerUtils.expectedAndRealType(sourceFile);
|
|
4114
4307
|
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
4115
4308
|
if (expectedType !== realType) {
|
|
4116
4309
|
yield* pipe(
|
|
@@ -4129,31 +4322,35 @@ var missingEffectError = createDiagnostic({
|
|
|
4129
4322
|
description: "Catch all errors with Effect.catchAll",
|
|
4130
4323
|
apply: gen(function* () {
|
|
4131
4324
|
const changeTracker = yield* service(ChangeTracker);
|
|
4132
|
-
changeTracker.insertText(
|
|
4133
|
-
|
|
4325
|
+
changeTracker.insertText(
|
|
4326
|
+
sourceFile,
|
|
4327
|
+
ts.getTokenPosOfNode(valueNode, sourceFile),
|
|
4328
|
+
effectModuleIdentifier + ".catchAll("
|
|
4329
|
+
);
|
|
4330
|
+
changeTracker.insertText(sourceFile, valueNode.end, ", () => ");
|
|
4134
4331
|
changeTracker.insertNodeAt(
|
|
4135
4332
|
sourceFile,
|
|
4136
|
-
valueNode.
|
|
4333
|
+
valueNode.end,
|
|
4137
4334
|
createDieMessage("TODO: catchAll not implemented")
|
|
4138
4335
|
);
|
|
4139
|
-
changeTracker.insertText(sourceFile, valueNode.
|
|
4336
|
+
changeTracker.insertText(sourceFile, valueNode.end, ")");
|
|
4140
4337
|
})
|
|
4141
4338
|
});
|
|
4142
4339
|
}
|
|
4143
4340
|
if (ts.isExpression(valueNode)) {
|
|
4144
4341
|
const propertyAssignments = pipe(
|
|
4145
4342
|
result.missingErrorTypes,
|
|
4146
|
-
|
|
4343
|
+
map5((_) => typeChecker.getPropertyOfType(_, "_tag")),
|
|
4147
4344
|
filter((_) => !!_),
|
|
4148
|
-
|
|
4345
|
+
map5((_) => typeChecker.getTypeOfSymbolAtLocation(_, valueNode)),
|
|
4149
4346
|
filter((_) => !!(_.flags & ts.TypeFlags.Literal)),
|
|
4150
|
-
|
|
4347
|
+
map5((_) => typeChecker.typeToTypeNode(_, void 0, ts.NodeBuilderFlags.NoTruncation)),
|
|
4151
4348
|
filter((_) => !!_ && ts.isLiteralTypeNode(_)),
|
|
4152
|
-
|
|
4349
|
+
map5((_) => _.literal),
|
|
4153
4350
|
filter((_) => ts.isLiteralExpression(_)),
|
|
4154
|
-
|
|
4351
|
+
map5((_) => _.text),
|
|
4155
4352
|
sort(string2),
|
|
4156
|
-
|
|
4353
|
+
map5(
|
|
4157
4354
|
(_) => ts.factory.createPropertyAssignment(
|
|
4158
4355
|
ts.factory.createIdentifier(_),
|
|
4159
4356
|
ts.factory.createArrowFunction(
|
|
@@ -4173,22 +4370,27 @@ var missingEffectError = createDiagnostic({
|
|
|
4173
4370
|
description: "Catch unexpected errors with Effect.catchTag",
|
|
4174
4371
|
apply: gen(function* () {
|
|
4175
4372
|
const changeTracker = yield* service(ChangeTracker);
|
|
4176
|
-
changeTracker.insertText(
|
|
4177
|
-
|
|
4373
|
+
changeTracker.insertText(
|
|
4374
|
+
sourceFile,
|
|
4375
|
+
ts.getTokenPosOfNode(valueNode, sourceFile),
|
|
4376
|
+
effectModuleIdentifier + ".catchTags("
|
|
4377
|
+
);
|
|
4378
|
+
changeTracker.insertText(sourceFile, valueNode.end, ", ");
|
|
4178
4379
|
changeTracker.insertNodeAt(
|
|
4179
4380
|
sourceFile,
|
|
4180
|
-
valueNode.
|
|
4381
|
+
valueNode.end,
|
|
4181
4382
|
ts.factory.createObjectLiteralExpression(propertyAssignments)
|
|
4182
4383
|
);
|
|
4183
|
-
changeTracker.insertText(sourceFile, valueNode.
|
|
4384
|
+
changeTracker.insertText(sourceFile, valueNode.end, ")");
|
|
4184
4385
|
})
|
|
4185
4386
|
});
|
|
4186
4387
|
}
|
|
4187
4388
|
}
|
|
4389
|
+
const typeNames = sortTypes(result.missingErrorTypes).map((_) => typeChecker.typeToString(_));
|
|
4188
4390
|
report(
|
|
4189
4391
|
{
|
|
4190
4392
|
location: node,
|
|
4191
|
-
messageText: `Missing '${
|
|
4393
|
+
messageText: `Missing '${typeNames.join(" | ")}' in the expected Effect errors.`,
|
|
4192
4394
|
fixes
|
|
4193
4395
|
}
|
|
4194
4396
|
);
|
|
@@ -4208,6 +4410,7 @@ var missingEffectServiceDependency = createDiagnostic({
|
|
|
4208
4410
|
apply: fn("missingEffectServiceDependency.apply")(function* (sourceFile, report) {
|
|
4209
4411
|
const ts = yield* service(TypeScriptApi);
|
|
4210
4412
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
4413
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
4211
4414
|
const typeParser = yield* service(TypeParser);
|
|
4212
4415
|
const nodeToVisit = [];
|
|
4213
4416
|
const appendNodeToVisit = (node) => {
|
|
@@ -4238,7 +4441,7 @@ var missingEffectServiceDependency = createDiagnostic({
|
|
|
4238
4441
|
if (layerResult) {
|
|
4239
4442
|
const servicesMemory = /* @__PURE__ */ new Map();
|
|
4240
4443
|
const excludeNever = (type) => succeed((type.flags & ts.TypeFlags.Never) !== 0);
|
|
4241
|
-
const { allIndexes: requiredIndexes } = yield* appendToUniqueTypesMap(
|
|
4444
|
+
const { allIndexes: requiredIndexes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
4242
4445
|
servicesMemory,
|
|
4243
4446
|
layerResult.RIn,
|
|
4244
4447
|
excludeNever
|
|
@@ -4249,8 +4452,8 @@ var missingEffectServiceDependency = createDiagnostic({
|
|
|
4249
4452
|
let types = [];
|
|
4250
4453
|
if (dependenciesProperty) {
|
|
4251
4454
|
const dependenciesTypes = typeChecker.getTypeOfSymbolAtLocation(dependenciesProperty, options);
|
|
4252
|
-
const numberIndexType = dependenciesTypes.
|
|
4253
|
-
types = numberIndexType ? unrollUnionMembers(numberIndexType) : [];
|
|
4455
|
+
const numberIndexType = typeChecker.getIndexTypeOfType(dependenciesTypes, ts.IndexKind.Number);
|
|
4456
|
+
types = numberIndexType ? typeCheckerUtils.unrollUnionMembers(numberIndexType) : [];
|
|
4254
4457
|
}
|
|
4255
4458
|
for (const depType of types) {
|
|
4256
4459
|
const depLayerResult = yield* pipe(
|
|
@@ -4258,7 +4461,7 @@ var missingEffectServiceDependency = createDiagnostic({
|
|
|
4258
4461
|
orElse2(() => void_)
|
|
4259
4462
|
);
|
|
4260
4463
|
if (depLayerResult) {
|
|
4261
|
-
const { allIndexes } = yield* appendToUniqueTypesMap(
|
|
4464
|
+
const { allIndexes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
4262
4465
|
servicesMemory,
|
|
4263
4466
|
depLayerResult.ROut,
|
|
4264
4467
|
excludeNever
|
|
@@ -4447,7 +4650,7 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
4447
4650
|
"Layer"
|
|
4448
4651
|
) || "Layer";
|
|
4449
4652
|
const parseEffectProvideLayer = (node) => {
|
|
4450
|
-
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && node.expression.name
|
|
4653
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && ts.idText(node.expression.name) === "provide" && node.arguments.length > 0) {
|
|
4451
4654
|
const layer = node.arguments[0];
|
|
4452
4655
|
const type = typeChecker.getTypeAtLocation(layer);
|
|
4453
4656
|
return pipe(
|
|
@@ -4483,8 +4686,8 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
4483
4686
|
apply: gen(function* () {
|
|
4484
4687
|
const changeTracker = yield* service(ChangeTracker);
|
|
4485
4688
|
changeTracker.deleteRange(sourceFile, {
|
|
4486
|
-
pos: chunk[0].node
|
|
4487
|
-
end: chunk[chunk.length - 1].node.
|
|
4689
|
+
pos: ts.getTokenPosOfNode(chunk[0].node, sourceFile),
|
|
4690
|
+
end: chunk[chunk.length - 1].node.end
|
|
4488
4691
|
});
|
|
4489
4692
|
const newNode = ts.factory.createCallExpression(
|
|
4490
4693
|
ts.factory.createPropertyAccessExpression(
|
|
@@ -4501,7 +4704,7 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
4501
4704
|
chunk.map((c) => c.layer)
|
|
4502
4705
|
)]
|
|
4503
4706
|
);
|
|
4504
|
-
changeTracker.insertNodeAt(sourceFile, chunk[0].node
|
|
4707
|
+
changeTracker.insertNodeAt(sourceFile, ts.getTokenPosOfNode(chunk[0].node, sourceFile), newNode);
|
|
4505
4708
|
})
|
|
4506
4709
|
}]
|
|
4507
4710
|
});
|
|
@@ -4707,6 +4910,7 @@ var scopeInLayerEffect = createDiagnostic({
|
|
|
4707
4910
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
4708
4911
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
4709
4912
|
const typeParser = yield* service(TypeParser);
|
|
4913
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
4710
4914
|
const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4711
4915
|
sourceFile,
|
|
4712
4916
|
"effect",
|
|
@@ -4717,22 +4921,13 @@ var scopeInLayerEffect = createDiagnostic({
|
|
|
4717
4921
|
const expression = node.expression;
|
|
4718
4922
|
if (!ts.isPropertyAccessExpression(expression)) return;
|
|
4719
4923
|
const calledModule = expression.expression;
|
|
4720
|
-
if (!(ts.isIdentifier(calledModule) && calledModule
|
|
4924
|
+
if (!(ts.isIdentifier(calledModule) && ts.idText(calledModule) === layerModuleIdentifier)) return;
|
|
4721
4925
|
const methodIdentifier = expression.name;
|
|
4722
|
-
if (!(ts.isIdentifier(methodIdentifier) && methodIdentifier.
|
|
4926
|
+
if (!(ts.isIdentifier(methodIdentifier) && ts.idText(methodIdentifier).toLowerCase().startsWith("effect"))) return;
|
|
4723
4927
|
return { methodIdentifier };
|
|
4724
4928
|
}
|
|
4725
4929
|
const reportIfLayerRequireScope = (type, node, methodIdentifier) => {
|
|
4726
|
-
|
|
4727
|
-
const entries = [];
|
|
4728
|
-
while (toCheck.length > 0) {
|
|
4729
|
-
const type2 = toCheck.pop();
|
|
4730
|
-
if (type2.isUnion()) {
|
|
4731
|
-
toCheck = toCheck.concat(type2.types);
|
|
4732
|
-
} else {
|
|
4733
|
-
entries.push(type2);
|
|
4734
|
-
}
|
|
4735
|
-
}
|
|
4930
|
+
const entries = typeCheckerUtils.unrollUnionMembers(type);
|
|
4736
4931
|
return pipe(
|
|
4737
4932
|
firstSuccessOf(entries.map((type2) => typeParser.scopeType(type2, node))),
|
|
4738
4933
|
map3(
|
|
@@ -4804,6 +4999,7 @@ var strictBooleanExpressions = createDiagnostic({
|
|
|
4804
4999
|
apply: fn("strictBooleanExpressions.apply")(function* (sourceFile, report) {
|
|
4805
5000
|
const ts = yield* service(TypeScriptApi);
|
|
4806
5001
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
5002
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
4807
5003
|
const conditionChecks = /* @__PURE__ */ new WeakMap();
|
|
4808
5004
|
const nodeToVisit = [];
|
|
4809
5005
|
const appendNodeToVisit = (node) => {
|
|
@@ -4844,7 +5040,7 @@ var strictBooleanExpressions = createDiagnostic({
|
|
|
4844
5040
|
let typesToCheck = [constrainedType || nodeType];
|
|
4845
5041
|
while (typesToCheck.length > 0) {
|
|
4846
5042
|
const type = typesToCheck.pop();
|
|
4847
|
-
if (
|
|
5043
|
+
if (typeCheckerUtils.isUnion(type)) {
|
|
4848
5044
|
typesToCheck = typesToCheck.concat(type.types);
|
|
4849
5045
|
continue;
|
|
4850
5046
|
}
|
|
@@ -5096,15 +5292,15 @@ var unsupportedServiceAccessors = createDiagnostic({
|
|
|
5096
5292
|
node.members?.forEach((member) => {
|
|
5097
5293
|
if (ts.isPropertyDeclaration(member) && member.modifiers?.some((mod) => mod.kind === ts.SyntaxKind.StaticKeyword)) {
|
|
5098
5294
|
if (member.name && ts.isIdentifier(member.name)) {
|
|
5099
|
-
existingStaticMembers.add(member.name
|
|
5295
|
+
existingStaticMembers.add(ts.idText(member.name));
|
|
5100
5296
|
}
|
|
5101
5297
|
}
|
|
5102
5298
|
});
|
|
5103
5299
|
const missingMembers = parseResult.involvedMembers.filter(
|
|
5104
|
-
({ property }) => !existingStaticMembers.has(
|
|
5300
|
+
({ property }) => !existingStaticMembers.has(ts.symbolName(property))
|
|
5105
5301
|
);
|
|
5106
5302
|
if (missingMembers.length > 0) {
|
|
5107
|
-
const memberNames = missingMembers.map(({ property }) => `'${
|
|
5303
|
+
const memberNames = missingMembers.map(({ property }) => `'${ts.symbolName(property)}'`).join(", ");
|
|
5108
5304
|
report({
|
|
5109
5305
|
location: parseResult.className,
|
|
5110
5306
|
messageText: `Even if accessors are enabled, accessors for ${memberNames} won't be available because the signature have generic type parameters or multiple call signatures.`,
|
|
@@ -5114,7 +5310,7 @@ var unsupportedServiceAccessors = createDiagnostic({
|
|
|
5114
5310
|
apply: gen(function* () {
|
|
5115
5311
|
const changeTracker = yield* service(ChangeTracker);
|
|
5116
5312
|
const comment = "// @effect-codegens accessors\n";
|
|
5117
|
-
changeTracker.insertText(sourceFile,
|
|
5313
|
+
changeTracker.insertText(sourceFile, ts.getTokenPosOfNode(node, sourceFile), comment);
|
|
5118
5314
|
})
|
|
5119
5315
|
}]
|
|
5120
5316
|
});
|
|
@@ -5199,8 +5395,8 @@ var effectSchemaSelfInClasses = createCompletion({
|
|
|
5199
5395
|
"effect",
|
|
5200
5396
|
"Schema"
|
|
5201
5397
|
) || "Schema";
|
|
5202
|
-
if (schemaIdentifier !== accessedObject
|
|
5203
|
-
const name = className
|
|
5398
|
+
if (schemaIdentifier !== ts.idText(accessedObject)) return [];
|
|
5399
|
+
const name = ts.idText(className);
|
|
5204
5400
|
return [{
|
|
5205
5401
|
name: `Class<${name}>`,
|
|
5206
5402
|
kind: ts.ScriptElementKind.constElement,
|
|
@@ -5243,8 +5439,8 @@ var effectSelfInClasses = createCompletion({
|
|
|
5243
5439
|
"effect",
|
|
5244
5440
|
"Effect"
|
|
5245
5441
|
) || "Effect";
|
|
5246
|
-
if (effectIdentifier !== accessedObject
|
|
5247
|
-
const name = className
|
|
5442
|
+
if (effectIdentifier !== ts.idText(accessedObject)) return [];
|
|
5443
|
+
const name = ts.idText(className);
|
|
5248
5444
|
return [{
|
|
5249
5445
|
name: `Service<${name}>`,
|
|
5250
5446
|
kind: ts.ScriptElementKind.constElement,
|
|
@@ -5274,7 +5470,7 @@ var fnFunctionStar = createCompletion({
|
|
|
5274
5470
|
const maybeFnName = pipe(
|
|
5275
5471
|
tsUtils.getAncestorNodesInRange(sourceFile, tsUtils.toTextRange(accessedObject.pos)),
|
|
5276
5472
|
filter(ts.isVariableDeclaration),
|
|
5277
|
-
|
|
5473
|
+
map5((_) => _.name && ts.isIdentifier(_.name) ? ts.idText(_.name) : ""),
|
|
5278
5474
|
filter((_) => _.length > 0),
|
|
5279
5475
|
head,
|
|
5280
5476
|
map2((name) => [
|
|
@@ -5318,7 +5514,7 @@ var genFunctionStar = createCompletion({
|
|
|
5318
5514
|
const genMemberSymbol = type.getProperty("gen");
|
|
5319
5515
|
if (!genMemberSymbol) return [];
|
|
5320
5516
|
const genType = typeChecker.getTypeOfSymbolAtLocation(genMemberSymbol, accessedObject);
|
|
5321
|
-
if (genType.
|
|
5517
|
+
if (typeChecker.getSignaturesOfType(genType, ts.SignatureKind.Call).length === 0) return [];
|
|
5322
5518
|
const span = ts.createTextSpan(
|
|
5323
5519
|
accessedObject.end + 1,
|
|
5324
5520
|
Math.max(0, position - accessedObject.end - 1)
|
|
@@ -5347,8 +5543,8 @@ var rpcMakeClasses = createCompletion({
|
|
|
5347
5543
|
"@effect/rpc",
|
|
5348
5544
|
"Rpc"
|
|
5349
5545
|
) || "Rpc";
|
|
5350
|
-
if (rpcIdentifier !== accessedObject
|
|
5351
|
-
const name = className
|
|
5546
|
+
if (rpcIdentifier !== ts.idText(accessedObject)) return [];
|
|
5547
|
+
const name = ts.idText(className);
|
|
5352
5548
|
return [{
|
|
5353
5549
|
name: `make("${name}")`,
|
|
5354
5550
|
kind: ts.ScriptElementKind.constElement,
|
|
@@ -5374,7 +5570,7 @@ var schemaBrand = createCompletion({
|
|
|
5374
5570
|
"effect",
|
|
5375
5571
|
"Schema"
|
|
5376
5572
|
) || "Schema";
|
|
5377
|
-
if (schemaName !== accessedObject
|
|
5573
|
+
if (schemaName !== ts.idText(accessedObject)) return [];
|
|
5378
5574
|
const span = ts.createTextSpan(
|
|
5379
5575
|
accessedObject.end + 1,
|
|
5380
5576
|
Math.max(0, position - accessedObject.end - 1)
|
|
@@ -5382,7 +5578,7 @@ var schemaBrand = createCompletion({
|
|
|
5382
5578
|
return pipe(
|
|
5383
5579
|
tsUtils.getAncestorNodesInRange(sourceFile, tsUtils.toTextRange(accessedObject.pos)),
|
|
5384
5580
|
filter(ts.isVariableDeclaration),
|
|
5385
|
-
|
|
5581
|
+
map5((_) => _.name && ts.isIdentifier(_.name) ? ts.idText(_.name) : ""),
|
|
5386
5582
|
filter((_) => _.length > 0),
|
|
5387
5583
|
head,
|
|
5388
5584
|
map2((name) => [
|
|
@@ -5438,7 +5634,7 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5438
5634
|
namespaceExports.push({
|
|
5439
5635
|
moduleSpecifier,
|
|
5440
5636
|
exportClause,
|
|
5441
|
-
name: exportClause.name
|
|
5637
|
+
name: ts.idText(exportClause.name)
|
|
5442
5638
|
});
|
|
5443
5639
|
}
|
|
5444
5640
|
if (ts.isNamedExports(exportClause)) {
|
|
@@ -5449,8 +5645,8 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5449
5645
|
namedExports.push({
|
|
5450
5646
|
moduleSpecifier,
|
|
5451
5647
|
exportClause,
|
|
5452
|
-
name: exportName
|
|
5453
|
-
aliasName: exportSpecifier.name
|
|
5648
|
+
name: ts.idText(exportName),
|
|
5649
|
+
aliasName: ts.idText(exportSpecifier.name)
|
|
5454
5650
|
});
|
|
5455
5651
|
}
|
|
5456
5652
|
}
|
|
@@ -5610,6 +5806,11 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5610
5806
|
if (!moduleSpecifier) return fileName;
|
|
5611
5807
|
return moduleSpecifier;
|
|
5612
5808
|
};
|
|
5809
|
+
const resolveAliasName = (chosenName) => {
|
|
5810
|
+
const aliasName = languageServicePluginOptions.importAliases[chosenName];
|
|
5811
|
+
if (aliasName) return aliasName;
|
|
5812
|
+
return void 0;
|
|
5813
|
+
};
|
|
5613
5814
|
const resolve = (exportFileName, exportName) => {
|
|
5614
5815
|
const excludedExports = mapFilenameToExportExcludes.get(exportFileName);
|
|
5615
5816
|
if (excludedExports && excludedExports.includes(exportName)) return;
|
|
@@ -5621,7 +5822,9 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5621
5822
|
_tag: "NamedImport",
|
|
5622
5823
|
fileName: reexportedFile.fileName,
|
|
5623
5824
|
moduleName: resolveModuleName(reexportedFile.fileName),
|
|
5624
|
-
name: exportName
|
|
5825
|
+
name: exportName,
|
|
5826
|
+
aliasName: resolveAliasName(exportName),
|
|
5827
|
+
introducedPrefix: void 0
|
|
5625
5828
|
};
|
|
5626
5829
|
}
|
|
5627
5830
|
}
|
|
@@ -5636,6 +5839,7 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5636
5839
|
fileName: namespacedFileName,
|
|
5637
5840
|
moduleName: resolveModuleName(namespacedFileName),
|
|
5638
5841
|
name: introducedAlias2,
|
|
5842
|
+
aliasName: resolveAliasName(introducedAlias2),
|
|
5639
5843
|
introducedPrefix: void 0
|
|
5640
5844
|
};
|
|
5641
5845
|
}
|
|
@@ -5648,7 +5852,8 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5648
5852
|
fileName: exportFileName,
|
|
5649
5853
|
moduleName: resolveModuleName(exportFileName),
|
|
5650
5854
|
name: introducedAlias,
|
|
5651
|
-
|
|
5855
|
+
aliasName: resolveAliasName(introducedAlias),
|
|
5856
|
+
introducedPrefix: resolveAliasName(introducedAlias) || introducedAlias
|
|
5652
5857
|
};
|
|
5653
5858
|
}
|
|
5654
5859
|
const mapToBarrel = mapFromNamespaceToBarrel.get(exportFileName);
|
|
@@ -5658,7 +5863,8 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5658
5863
|
fileName: mapToBarrel.fileName,
|
|
5659
5864
|
moduleName: resolveModuleName(mapToBarrel.fileName),
|
|
5660
5865
|
name: mapToBarrel.alias,
|
|
5661
|
-
|
|
5866
|
+
aliasName: resolveAliasName(mapToBarrel.alias),
|
|
5867
|
+
introducedPrefix: resolveAliasName(mapToBarrel.alias) || mapToBarrel.alias
|
|
5662
5868
|
};
|
|
5663
5869
|
}
|
|
5664
5870
|
};
|
|
@@ -5701,7 +5907,7 @@ var parseImportOnlyChanges = fn("parseImportOnlyChanges")(function* (sourceFile,
|
|
|
5701
5907
|
if (ts.isNamedImports(namedBindings)) {
|
|
5702
5908
|
for (const importSpecifier of namedBindings.elements) {
|
|
5703
5909
|
if (!ts.isIdentifier(importSpecifier.name)) return;
|
|
5704
|
-
const exportName = importSpecifier.name
|
|
5910
|
+
const exportName = ts.idText(importSpecifier.name);
|
|
5705
5911
|
imports.push({ moduleName, exportName });
|
|
5706
5912
|
continue;
|
|
5707
5913
|
}
|
|
@@ -5735,8 +5941,9 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5735
5941
|
let description = "";
|
|
5736
5942
|
switch (effectAutoImport._tag) {
|
|
5737
5943
|
case "NamespaceImport": {
|
|
5944
|
+
const aliasName = effectAutoImport.aliasName || effectAutoImport.name;
|
|
5738
5945
|
const importModule = effectAutoImport.moduleName || effectAutoImport.fileName;
|
|
5739
|
-
description = `Import * as ${
|
|
5946
|
+
description = `Import * as ${aliasName} from "${importModule}"`;
|
|
5740
5947
|
ts.insertImports(
|
|
5741
5948
|
changeTracker,
|
|
5742
5949
|
sourceFile,
|
|
@@ -5745,7 +5952,7 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5745
5952
|
ts.factory.createImportClause(
|
|
5746
5953
|
false,
|
|
5747
5954
|
void 0,
|
|
5748
|
-
ts.factory.createNamespaceImport(ts.factory.createIdentifier(
|
|
5955
|
+
ts.factory.createNamespaceImport(ts.factory.createIdentifier(aliasName))
|
|
5749
5956
|
),
|
|
5750
5957
|
ts.factory.createStringLiteral(importModule)
|
|
5751
5958
|
),
|
|
@@ -5756,7 +5963,11 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5756
5963
|
}
|
|
5757
5964
|
case "NamedImport": {
|
|
5758
5965
|
const importModule = effectAutoImport.moduleName || effectAutoImport.fileName;
|
|
5759
|
-
|
|
5966
|
+
if (effectAutoImport.aliasName) {
|
|
5967
|
+
description = `Import { ${effectAutoImport.name} as ${effectAutoImport.aliasName} } from "${importModule}"`;
|
|
5968
|
+
} else {
|
|
5969
|
+
description = `Import { ${effectAutoImport.name} } from "${importModule}"`;
|
|
5970
|
+
}
|
|
5760
5971
|
let foundImportDeclaration = false;
|
|
5761
5972
|
for (const statement of sourceFile.statements) {
|
|
5762
5973
|
if (ts.isImportDeclaration(statement)) {
|
|
@@ -5765,9 +5976,12 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5765
5976
|
const importClause = statement.importClause;
|
|
5766
5977
|
if (importClause && importClause.namedBindings && ts.isNamedImports(importClause.namedBindings)) {
|
|
5767
5978
|
const namedImports = importClause.namedBindings;
|
|
5768
|
-
const existingImportSpecifier = namedImports.elements.find(
|
|
5769
|
-
(
|
|
5770
|
-
|
|
5979
|
+
const existingImportSpecifier = namedImports.elements.find((element) => {
|
|
5980
|
+
if (effectAutoImport.aliasName) {
|
|
5981
|
+
return ts.idText(element.name) === effectAutoImport.name && element.propertyName && ts.isIdentifier(element.propertyName) && ts.idText(element.propertyName) === effectAutoImport.aliasName;
|
|
5982
|
+
}
|
|
5983
|
+
return ts.idText(element.name) === effectAutoImport.name;
|
|
5984
|
+
});
|
|
5771
5985
|
if (existingImportSpecifier) {
|
|
5772
5986
|
foundImportDeclaration = true;
|
|
5773
5987
|
break;
|
|
@@ -5779,8 +5993,8 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5779
5993
|
namedImports.elements.concat([
|
|
5780
5994
|
ts.factory.createImportSpecifier(
|
|
5781
5995
|
false,
|
|
5782
|
-
void 0,
|
|
5783
|
-
ts.factory.createIdentifier(effectAutoImport.name)
|
|
5996
|
+
effectAutoImport.aliasName ? ts.factory.createIdentifier(effectAutoImport.name) : void 0,
|
|
5997
|
+
ts.factory.createIdentifier(effectAutoImport.aliasName || effectAutoImport.name)
|
|
5784
5998
|
)
|
|
5785
5999
|
])
|
|
5786
6000
|
)
|
|
@@ -5804,8 +6018,8 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5804
6018
|
[
|
|
5805
6019
|
ts.factory.createImportSpecifier(
|
|
5806
6020
|
false,
|
|
5807
|
-
void 0,
|
|
5808
|
-
ts.factory.createIdentifier(effectAutoImport.name)
|
|
6021
|
+
effectAutoImport.aliasName ? ts.factory.createIdentifier(effectAutoImport.name) : void 0,
|
|
6022
|
+
ts.factory.createIdentifier(effectAutoImport.aliasName || effectAutoImport.name)
|
|
5809
6023
|
)
|
|
5810
6024
|
]
|
|
5811
6025
|
)
|
|
@@ -6013,22 +6227,26 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
6013
6227
|
const textRange = tsUtils.toTextRange(position);
|
|
6014
6228
|
function isSymbolFromEffectRpcModule(symbol3) {
|
|
6015
6229
|
if (symbol3.valueDeclaration) {
|
|
6016
|
-
const sourceFile2 = symbol3.valueDeclaration
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6230
|
+
const sourceFile2 = tsUtils.getSourceFileOfNode(symbol3.valueDeclaration);
|
|
6231
|
+
if (sourceFile2) {
|
|
6232
|
+
const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(sourceFile2);
|
|
6233
|
+
if (packageInfo && packageInfo.name === "@effect/rpc") {
|
|
6234
|
+
const fileSymbol = typeChecker.getSymbolAtLocation(sourceFile2);
|
|
6235
|
+
return fileSymbol && fileSymbol.exports && fileSymbol.exports.has("isRpc") && fileSymbol.exports.has("make") && fileSymbol.exports.has("fromTaggedRequest");
|
|
6236
|
+
}
|
|
6021
6237
|
}
|
|
6022
6238
|
}
|
|
6023
6239
|
return false;
|
|
6024
6240
|
}
|
|
6025
6241
|
function isSymbolFromEffectRpcClientModule(symbol3) {
|
|
6026
6242
|
if (symbol3.valueDeclaration) {
|
|
6027
|
-
const sourceFile2 = symbol3.valueDeclaration
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6243
|
+
const sourceFile2 = tsUtils.getSourceFileOfNode(symbol3.valueDeclaration);
|
|
6244
|
+
if (sourceFile2) {
|
|
6245
|
+
const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(sourceFile2);
|
|
6246
|
+
if (packageInfo && packageInfo.name === "@effect/rpc") {
|
|
6247
|
+
const fileSymbol = typeChecker.getSymbolAtLocation(sourceFile2);
|
|
6248
|
+
return fileSymbol && fileSymbol.exports && fileSymbol.exports.has("RpcClient") && fileSymbol.exports.has("make");
|
|
6249
|
+
}
|
|
6032
6250
|
}
|
|
6033
6251
|
}
|
|
6034
6252
|
return false;
|
|
@@ -6038,9 +6256,9 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
6038
6256
|
for (const node of tsUtils.getAncestorNodesInRange(sourceFile, textRange)) {
|
|
6039
6257
|
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && tsUtils.isNodeInRange(textRange)(node.name)) {
|
|
6040
6258
|
const type = typeChecker.getTypeAtLocation(node);
|
|
6041
|
-
for (const callSig of type.
|
|
6259
|
+
for (const callSig of typeChecker.getSignaturesOfType(type, ts.SignatureKind.Call)) {
|
|
6042
6260
|
if (callSig.parameters.length >= 2 && isSymbolFromEffectRpcClientModule(callSig.parameters[1])) {
|
|
6043
|
-
rpcName = node.name
|
|
6261
|
+
rpcName = ts.idText(node.name);
|
|
6044
6262
|
callNode = node.name;
|
|
6045
6263
|
}
|
|
6046
6264
|
}
|
|
@@ -6068,7 +6286,7 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
6068
6286
|
ts.forEachChild(fileToTest, appendNodeToVisit);
|
|
6069
6287
|
while (result.length === 0 && nodeToVisit.length > 0) {
|
|
6070
6288
|
const node = nodeToVisit.shift();
|
|
6071
|
-
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && (node.expression.name
|
|
6289
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && (ts.idText(node.expression.name) === "make" || ts.idText(node.expression.name) === "fromTaggedRequest")) {
|
|
6072
6290
|
const symbol3 = typeChecker.getSymbolAtLocation(node.expression.name);
|
|
6073
6291
|
if (symbol3 && isSymbolFromEffectRpcModule(symbol3)) {
|
|
6074
6292
|
const type = typeChecker.getTypeAtLocation(node);
|
|
@@ -6085,7 +6303,7 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
6085
6303
|
if (result.length === 0) return applicableGotoDefinition;
|
|
6086
6304
|
const effectRpcResult = result.map(([node]) => ({
|
|
6087
6305
|
fileName: node.getSourceFile().fileName,
|
|
6088
|
-
textSpan: ts.createTextSpan(node.getStart(), node.
|
|
6306
|
+
textSpan: ts.createTextSpan(node.getStart(), node.end - node.getStart()),
|
|
6089
6307
|
kind: ts.ScriptElementKind.constElement,
|
|
6090
6308
|
name: rpcName,
|
|
6091
6309
|
containerKind: ts.ScriptElementKind.constElement,
|
|
@@ -6098,7 +6316,7 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
6098
6316
|
};
|
|
6099
6317
|
}
|
|
6100
6318
|
return {
|
|
6101
|
-
textSpan: ts.createTextSpan(callNode.getStart(), callNode.
|
|
6319
|
+
textSpan: ts.createTextSpan(callNode.getStart(), callNode.end - callNode.getStart()),
|
|
6102
6320
|
definitions: effectRpcResult
|
|
6103
6321
|
};
|
|
6104
6322
|
});
|
|
@@ -6134,7 +6352,7 @@ var middlewareGenLike = fn("middlewareGenLike")(function* (sourceFile, _span, pr
|
|
|
6134
6352
|
parseType(possiblyGen),
|
|
6135
6353
|
map3((_) => {
|
|
6136
6354
|
const argsCloseParen = ts.findChildOfKind(_.generatorFunction, ts.SyntaxKind.CloseParenToken, sourceFile);
|
|
6137
|
-
if (argsCloseParen && _.body && inlayHint.position >= argsCloseParen.
|
|
6355
|
+
if (argsCloseParen && _.body && inlayHint.position >= argsCloseParen.end && inlayHint.position <= _.body.getStart(sourceFile)) {
|
|
6138
6356
|
shouldOmit = true;
|
|
6139
6357
|
}
|
|
6140
6358
|
}),
|
|
@@ -6230,9 +6448,9 @@ function effectTypeArgs(sourceFile, position, quickInfo2) {
|
|
|
6230
6448
|
),
|
|
6231
6449
|
map3((_) => makeSymbolDisplayParts("Effect Type Parameters", _.A, _.E, _.R)),
|
|
6232
6450
|
orElse2(() => {
|
|
6233
|
-
const callSignatues = type.
|
|
6451
|
+
const callSignatues = typeChecker.getSignaturesOfType(type, ts.SignatureKind.Call);
|
|
6234
6452
|
if (callSignatues.length !== 1) return succeed([]);
|
|
6235
|
-
const returnType = callSignatues[0]
|
|
6453
|
+
const returnType = typeChecker.getReturnTypeOfSignature(callSignatues[0]);
|
|
6236
6454
|
return pipe(
|
|
6237
6455
|
typeParser.effectType(
|
|
6238
6456
|
returnType,
|
|
@@ -6243,8 +6461,8 @@ function effectTypeArgs(sourceFile, position, quickInfo2) {
|
|
|
6243
6461
|
})
|
|
6244
6462
|
);
|
|
6245
6463
|
if (!quickInfo2) {
|
|
6246
|
-
const start =
|
|
6247
|
-
const end = node.
|
|
6464
|
+
const start = ts.getTokenPosOfNode(node, sourceFile);
|
|
6465
|
+
const end = node.end;
|
|
6248
6466
|
return {
|
|
6249
6467
|
kind: ts.ScriptElementKind.callSignatureElement,
|
|
6250
6468
|
kindModifiers: "",
|
|
@@ -10473,6 +10691,7 @@ function processLayerGraphNode(ctx, node, pipedInGraphNode) {
|
|
|
10473
10691
|
const ts = yield* service(TypeScriptApi);
|
|
10474
10692
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
10475
10693
|
const typeParser = yield* service(TypeParser);
|
|
10694
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
10476
10695
|
const excludeNever = (type) => succeed((type.flags & ts.TypeFlags.Never) !== 0);
|
|
10477
10696
|
const maybePipe = yield* option(typeParser.pipeCall(node));
|
|
10478
10697
|
if (isSome2(maybePipe)) {
|
|
@@ -10490,12 +10709,12 @@ function processLayerGraphNode(ctx, node, pipedInGraphNode) {
|
|
|
10490
10709
|
all(...node.arguments.map((_) => processLayerGraphNode(ctx, _, void 0)))
|
|
10491
10710
|
);
|
|
10492
10711
|
if (isSome2(argNodes) && argNodes.value.length === node.arguments.length) {
|
|
10493
|
-
const { allIndexes: outTypes } = yield* appendToUniqueTypesMap(
|
|
10712
|
+
const { allIndexes: outTypes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
10494
10713
|
ctx.services,
|
|
10495
10714
|
maybeLayer.value.ROut,
|
|
10496
10715
|
excludeNever
|
|
10497
10716
|
);
|
|
10498
|
-
const { allIndexes: inTypes } = yield* appendToUniqueTypesMap(
|
|
10717
|
+
const { allIndexes: inTypes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
10499
10718
|
ctx.services,
|
|
10500
10719
|
maybeLayer.value.RIn,
|
|
10501
10720
|
excludeNever
|
|
@@ -10513,18 +10732,18 @@ function processLayerGraphNode(ctx, node, pipedInGraphNode) {
|
|
|
10513
10732
|
if (pipedInGraphNode && ts.isExpression(node)) {
|
|
10514
10733
|
const type = typeChecker.getContextualType(node);
|
|
10515
10734
|
if (type) {
|
|
10516
|
-
const callSignatures = type.
|
|
10735
|
+
const callSignatures = typeChecker.getSignaturesOfType(type, ts.SignatureKind.Call);
|
|
10517
10736
|
if (callSignatures.length === 1) {
|
|
10518
10737
|
const [signature] = callSignatures;
|
|
10519
|
-
const returnType =
|
|
10738
|
+
const returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
10520
10739
|
const maybeLayer = yield* option(typeParser.layerType(returnType, node));
|
|
10521
10740
|
if (isSome2(maybeLayer)) {
|
|
10522
|
-
const { allIndexes: outTypes } = yield* appendToUniqueTypesMap(
|
|
10741
|
+
const { allIndexes: outTypes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
10523
10742
|
ctx.services,
|
|
10524
10743
|
maybeLayer.value.ROut,
|
|
10525
10744
|
excludeNever
|
|
10526
10745
|
);
|
|
10527
|
-
const { allIndexes: inTypes } = yield* appendToUniqueTypesMap(
|
|
10746
|
+
const { allIndexes: inTypes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
10528
10747
|
ctx.services,
|
|
10529
10748
|
maybeLayer.value.RIn,
|
|
10530
10749
|
excludeNever
|
|
@@ -10569,12 +10788,12 @@ function processLayerGraphNode(ctx, node, pipedInGraphNode) {
|
|
|
10569
10788
|
const type = typeChecker.getTypeAtLocation(node);
|
|
10570
10789
|
const maybeLayer = yield* option(typeParser.layerType(type, node));
|
|
10571
10790
|
if (isSome2(maybeLayer)) {
|
|
10572
|
-
const { allIndexes: outTypes } = yield* appendToUniqueTypesMap(
|
|
10791
|
+
const { allIndexes: outTypes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
10573
10792
|
ctx.services,
|
|
10574
10793
|
maybeLayer.value.ROut,
|
|
10575
10794
|
excludeNever
|
|
10576
10795
|
);
|
|
10577
|
-
const { allIndexes: inTypes } = yield* appendToUniqueTypesMap(
|
|
10796
|
+
const { allIndexes: inTypes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
10578
10797
|
ctx.services,
|
|
10579
10798
|
maybeLayer.value.RIn,
|
|
10580
10799
|
excludeNever
|
|
@@ -10788,8 +11007,8 @@ function layerInfo(sourceFile, position, quickInfo2) {
|
|
|
10788
11007
|
)
|
|
10789
11008
|
);
|
|
10790
11009
|
if (!quickInfo2) {
|
|
10791
|
-
const start =
|
|
10792
|
-
const end = node.
|
|
11010
|
+
const start = ts.getTokenPosOfNode(node, sourceFile);
|
|
11011
|
+
const end = node.end;
|
|
10793
11012
|
return {
|
|
10794
11013
|
kind: ts.ScriptElementKind.callSignatureElement,
|
|
10795
11014
|
kindModifiers: "",
|
|
@@ -11191,11 +11410,11 @@ var effectGenToFn = createRefactor({
|
|
|
11191
11410
|
parentNodes,
|
|
11192
11411
|
filter((_) => ts.isVariableDeclaration(_) && _.initializer ? true : false),
|
|
11193
11412
|
filter((_) => tsUtils.isNodeInRange(textRange)(_.name)),
|
|
11194
|
-
|
|
11413
|
+
map5((_) => _.initializer)
|
|
11195
11414
|
);
|
|
11196
11415
|
const maybeNode = yield* pipe(
|
|
11197
11416
|
nodesFromInitializers.concat(parentNodes),
|
|
11198
|
-
|
|
11417
|
+
map5(parseFunctionLikeReturnEffectGen),
|
|
11199
11418
|
firstSuccessOf,
|
|
11200
11419
|
option
|
|
11201
11420
|
);
|
|
@@ -11203,7 +11422,7 @@ var effectGenToFn = createRefactor({
|
|
|
11203
11422
|
const { effectModule, fnIdentifier, generatorFunction, nodeToReplace, pipeArgs } = maybeNode.value;
|
|
11204
11423
|
return {
|
|
11205
11424
|
kind: "refactor.rewrite.effect.effectGenToFn",
|
|
11206
|
-
description: fnIdentifier ? `Convert to Effect.fn("${fnIdentifier
|
|
11425
|
+
description: fnIdentifier ? `Convert to Effect.fn("${ts.idText(fnIdentifier)}")` : "Convert to Effect.fn",
|
|
11207
11426
|
apply: pipe(
|
|
11208
11427
|
gen(function* () {
|
|
11209
11428
|
const changeTracker = yield* service(ChangeTracker);
|
|
@@ -11213,7 +11432,7 @@ var effectGenToFn = createRefactor({
|
|
|
11213
11432
|
"fn"
|
|
11214
11433
|
),
|
|
11215
11434
|
void 0,
|
|
11216
|
-
[ts.factory.createStringLiteral(fnIdentifier
|
|
11435
|
+
[ts.factory.createStringLiteral(ts.idText(fnIdentifier))]
|
|
11217
11436
|
) : ts.factory.createPropertyAccessExpression(
|
|
11218
11437
|
effectModule,
|
|
11219
11438
|
"fn"
|
|
@@ -11334,7 +11553,7 @@ var _findSchemaVariableDeclaration = fn(
|
|
|
11334
11553
|
);
|
|
11335
11554
|
return yield* pipe(
|
|
11336
11555
|
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
11337
|
-
|
|
11556
|
+
map5(findSchema),
|
|
11338
11557
|
firstSuccessOf,
|
|
11339
11558
|
option
|
|
11340
11559
|
);
|
|
@@ -11436,15 +11655,15 @@ var makeSchemaOpaque = createRefactor({
|
|
|
11436
11655
|
"effect",
|
|
11437
11656
|
"Schema"
|
|
11438
11657
|
) || "Schema";
|
|
11439
|
-
const newIdentifier = ts.factory.createIdentifier(identifier
|
|
11658
|
+
const newIdentifier = ts.factory.createIdentifier(ts.idText(identifier) + "_");
|
|
11440
11659
|
const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(
|
|
11441
11660
|
effectSchemaName,
|
|
11442
|
-
newIdentifier
|
|
11661
|
+
ts.idText(newIdentifier),
|
|
11443
11662
|
types.A,
|
|
11444
|
-
identifier
|
|
11663
|
+
ts.idText(identifier),
|
|
11445
11664
|
types.I,
|
|
11446
|
-
identifier
|
|
11447
|
-
identifier
|
|
11665
|
+
ts.idText(identifier) + "Encoded",
|
|
11666
|
+
ts.idText(identifier) + "Context"
|
|
11448
11667
|
);
|
|
11449
11668
|
changeTracker.replaceNode(
|
|
11450
11669
|
sourceFile,
|
|
@@ -11469,10 +11688,10 @@ var makeSchemaOpaque = createRefactor({
|
|
|
11469
11688
|
variableStatement.modifiers,
|
|
11470
11689
|
ts.factory.createVariableDeclarationList(
|
|
11471
11690
|
[ts.factory.createVariableDeclaration(
|
|
11472
|
-
identifier
|
|
11691
|
+
ts.idText(identifier),
|
|
11473
11692
|
void 0,
|
|
11474
11693
|
newSchemaType,
|
|
11475
|
-
ts.factory.createIdentifier(newIdentifier
|
|
11694
|
+
ts.factory.createIdentifier(ts.idText(newIdentifier))
|
|
11476
11695
|
)],
|
|
11477
11696
|
variableDeclarationList.flags
|
|
11478
11697
|
)
|
|
@@ -11507,19 +11726,19 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
11507
11726
|
"effect",
|
|
11508
11727
|
"Schema"
|
|
11509
11728
|
) || "Schema";
|
|
11510
|
-
const newIdentifier = ts.factory.createIdentifier(identifier
|
|
11729
|
+
const newIdentifier = ts.factory.createIdentifier(ts.idText(identifier) + "_");
|
|
11511
11730
|
const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(
|
|
11512
11731
|
effectSchemaName,
|
|
11513
|
-
newIdentifier
|
|
11732
|
+
ts.idText(newIdentifier),
|
|
11514
11733
|
types.A,
|
|
11515
|
-
identifier
|
|
11734
|
+
ts.idText(identifier),
|
|
11516
11735
|
types.I,
|
|
11517
11736
|
"Encoded",
|
|
11518
11737
|
"Context"
|
|
11519
11738
|
);
|
|
11520
11739
|
const namespace = ts.factory.createModuleDeclaration(
|
|
11521
11740
|
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
11522
|
-
ts.factory.createIdentifier(identifier
|
|
11741
|
+
ts.factory.createIdentifier(ts.idText(identifier)),
|
|
11523
11742
|
ts.factory.createModuleBlock([
|
|
11524
11743
|
encodedType,
|
|
11525
11744
|
contextType
|
|
@@ -11533,6 +11752,7 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
11533
11752
|
);
|
|
11534
11753
|
changeTracker.insertNodeAfter(sourceFile, variableStatement, opaqueType);
|
|
11535
11754
|
changeTracker.insertNodeAfter(sourceFile, variableStatement, namespace);
|
|
11755
|
+
const namespaceName = ts.isStringLiteral(namespace.name) ? namespace.name.text : ts.idText(namespace.name);
|
|
11536
11756
|
const newSchemaType = ts.factory.createTypeReferenceNode(
|
|
11537
11757
|
ts.factory.createQualifiedName(
|
|
11538
11758
|
ts.factory.createIdentifier(effectSchemaName),
|
|
@@ -11542,13 +11762,15 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
11542
11762
|
ts.factory.createTypeReferenceNode(opaqueType.name),
|
|
11543
11763
|
ts.factory.createTypeReferenceNode(
|
|
11544
11764
|
ts.factory.createQualifiedName(
|
|
11545
|
-
ts.factory.createIdentifier(
|
|
11546
|
-
|
|
11765
|
+
ts.factory.createIdentifier(
|
|
11766
|
+
namespaceName
|
|
11767
|
+
),
|
|
11768
|
+
ts.idText(encodedType.name)
|
|
11547
11769
|
)
|
|
11548
11770
|
),
|
|
11549
11771
|
ts.factory.createTypeReferenceNode(ts.factory.createQualifiedName(
|
|
11550
|
-
ts.factory.createIdentifier(
|
|
11551
|
-
contextType.name
|
|
11772
|
+
ts.factory.createIdentifier(namespaceName),
|
|
11773
|
+
ts.idText(contextType.name)
|
|
11552
11774
|
))
|
|
11553
11775
|
]
|
|
11554
11776
|
);
|
|
@@ -11556,10 +11778,10 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
11556
11778
|
variableStatement.modifiers,
|
|
11557
11779
|
ts.factory.createVariableDeclarationList(
|
|
11558
11780
|
[ts.factory.createVariableDeclaration(
|
|
11559
|
-
identifier
|
|
11781
|
+
ts.idText(identifier),
|
|
11560
11782
|
void 0,
|
|
11561
11783
|
newSchemaType,
|
|
11562
|
-
ts.factory.createIdentifier(newIdentifier
|
|
11784
|
+
ts.factory.createIdentifier(ts.idText(newIdentifier))
|
|
11563
11785
|
)],
|
|
11564
11786
|
variableDeclarationList.flags
|
|
11565
11787
|
)
|
|
@@ -11585,14 +11807,17 @@ var pipeableToDatafirst = createRefactor({
|
|
|
11585
11807
|
if (!ts.isCallExpression(node2)) return false;
|
|
11586
11808
|
const expression = node2.expression;
|
|
11587
11809
|
if (!ts.isIdentifier(expression)) return false;
|
|
11588
|
-
if (expression
|
|
11810
|
+
if (ts.idText(expression) !== "pipe") return false;
|
|
11589
11811
|
return true;
|
|
11590
11812
|
}
|
|
11591
11813
|
function asDataFirstExpression(node2, self) {
|
|
11592
11814
|
if (!ts.isCallExpression(node2)) return none2();
|
|
11593
11815
|
const signature = typeChecker.getResolvedSignature(node2);
|
|
11594
11816
|
if (!signature) return none2();
|
|
11595
|
-
const callSignatures = typeChecker.
|
|
11817
|
+
const callSignatures = typeChecker.getSignaturesOfType(
|
|
11818
|
+
typeChecker.getTypeAtLocation(node2.expression),
|
|
11819
|
+
ts.SignatureKind.Call
|
|
11820
|
+
);
|
|
11596
11821
|
for (let i = 0; i < callSignatures.length; i++) {
|
|
11597
11822
|
const callSignature = callSignatures[i];
|
|
11598
11823
|
if (callSignature.parameters.length === node2.arguments.length + 1) {
|
|
@@ -11614,7 +11839,7 @@ var pipeableToDatafirst = createRefactor({
|
|
|
11614
11839
|
filter(
|
|
11615
11840
|
(node2) => node2.arguments.length > 0
|
|
11616
11841
|
),
|
|
11617
|
-
|
|
11842
|
+
map5((node2) => {
|
|
11618
11843
|
let newNode2 = node2.arguments[0];
|
|
11619
11844
|
let didSomething = false;
|
|
11620
11845
|
for (let i = 1; i < node2.arguments.length; i++) {
|
|
@@ -11641,7 +11866,7 @@ var pipeableToDatafirst = createRefactor({
|
|
|
11641
11866
|
return didSomething ? some2([node2, newNode2]) : none2();
|
|
11642
11867
|
}),
|
|
11643
11868
|
filter(isSome2),
|
|
11644
|
-
|
|
11869
|
+
map5((_) => _.value),
|
|
11645
11870
|
head
|
|
11646
11871
|
);
|
|
11647
11872
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -11791,6 +12016,7 @@ var toggleReturnTypeAnnotation = createRefactor({
|
|
|
11791
12016
|
const ts = yield* service(TypeScriptApi);
|
|
11792
12017
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
11793
12018
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
12019
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
11794
12020
|
function addReturnTypeAnnotation(sourceFile2, changeTracker, declaration, typeNode) {
|
|
11795
12021
|
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile2);
|
|
11796
12022
|
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
@@ -11838,10 +12064,10 @@ var toggleReturnTypeAnnotation = createRefactor({
|
|
|
11838
12064
|
)
|
|
11839
12065
|
};
|
|
11840
12066
|
}
|
|
11841
|
-
const returnType =
|
|
11842
|
-
if (
|
|
12067
|
+
const returnType = typeCheckerUtils.getInferredReturnType(node);
|
|
12068
|
+
if (!returnType) return yield* fail(new RefactorNotApplicableError());
|
|
11843
12069
|
const returnTypeNode = typeChecker.typeToTypeNode(
|
|
11844
|
-
returnType
|
|
12070
|
+
returnType,
|
|
11845
12071
|
node,
|
|
11846
12072
|
ts.NodeBuilderFlags.NoTruncation
|
|
11847
12073
|
);
|
|
@@ -11986,12 +12212,12 @@ var makeSchemaGenContext = fn("SchemaGen.makeSchemaGenContext")(function* (sourc
|
|
|
11986
12212
|
),
|
|
11987
12213
|
entityNameToDataTypeName: (name) => {
|
|
11988
12214
|
if (ts.isIdentifier(name)) {
|
|
11989
|
-
switch (name
|
|
12215
|
+
switch (ts.idText(name)) {
|
|
11990
12216
|
case "Date":
|
|
11991
12217
|
case "Pick":
|
|
11992
12218
|
case "Omit":
|
|
11993
12219
|
case "Record":
|
|
11994
|
-
return some2(name
|
|
12220
|
+
return some2(ts.idText(name));
|
|
11995
12221
|
case "ReadonlyArray":
|
|
11996
12222
|
case "Array":
|
|
11997
12223
|
return some2("Array");
|
|
@@ -12000,7 +12226,7 @@ var makeSchemaGenContext = fn("SchemaGen.makeSchemaGenContext")(function* (sourc
|
|
|
12000
12226
|
}
|
|
12001
12227
|
if (!ts.isIdentifier(name.left)) return none2();
|
|
12002
12228
|
for (const moduleName in moduleToImportedName) {
|
|
12003
|
-
if (name.left
|
|
12229
|
+
if (ts.idText(name.left) === moduleToImportedName[moduleName] && ts.idText(name.right) === moduleName) {
|
|
12004
12230
|
return some2(moduleName);
|
|
12005
12231
|
}
|
|
12006
12232
|
}
|
|
@@ -12014,11 +12240,11 @@ var typeEntityNameToNode = fn(
|
|
|
12014
12240
|
)(
|
|
12015
12241
|
function* (entityName) {
|
|
12016
12242
|
const { ts } = yield* service(SchemaGenContext);
|
|
12017
|
-
if (ts.isIdentifier(entityName)) return ts.factory.createIdentifier(entityName
|
|
12243
|
+
if (ts.isIdentifier(entityName)) return ts.factory.createIdentifier(ts.idText(entityName));
|
|
12018
12244
|
const left3 = yield* typeEntityNameToNode(entityName.left);
|
|
12019
12245
|
return ts.factory.createPropertyAccessExpression(
|
|
12020
12246
|
left3,
|
|
12021
|
-
ts.factory.createIdentifier(entityName.right
|
|
12247
|
+
ts.factory.createIdentifier(ts.idText(entityName.right))
|
|
12022
12248
|
);
|
|
12023
12249
|
}
|
|
12024
12250
|
);
|
|
@@ -12263,13 +12489,13 @@ var processInterfaceDeclaration = fn("SchemaGen.processInterfaceDeclaration")(
|
|
|
12263
12489
|
);
|
|
12264
12490
|
const { properties, records } = yield* processMembers(node.members, false);
|
|
12265
12491
|
if (preferClass && records.length === 0) {
|
|
12266
|
-
return yield* createExportSchemaClassDeclaration(node.name
|
|
12492
|
+
return yield* createExportSchemaClassDeclaration(ts.idText(node.name), properties);
|
|
12267
12493
|
}
|
|
12268
12494
|
const schemaStruct = createApiCall(
|
|
12269
12495
|
"Struct",
|
|
12270
12496
|
[ts.factory.createObjectLiteralExpression(properties, true)].concat(records)
|
|
12271
12497
|
);
|
|
12272
|
-
return yield* createExportVariableDeclaration(node.name
|
|
12498
|
+
return yield* createExportVariableDeclaration(ts.idText(node.name), schemaStruct);
|
|
12273
12499
|
}
|
|
12274
12500
|
);
|
|
12275
12501
|
var processTypeAliasDeclaration = fn("SchemaGen.processInterfaceDeclaration")(
|
|
@@ -12281,11 +12507,11 @@ var processTypeAliasDeclaration = fn("SchemaGen.processInterfaceDeclaration")(
|
|
|
12281
12507
|
if (preferClass && ts.isTypeLiteralNode(node.type)) {
|
|
12282
12508
|
const { properties, records } = yield* processMembers(node.type.members, false);
|
|
12283
12509
|
if (records.length === 0) {
|
|
12284
|
-
return yield* createExportSchemaClassDeclaration(node.name
|
|
12510
|
+
return yield* createExportSchemaClassDeclaration(ts.idText(node.name), properties);
|
|
12285
12511
|
}
|
|
12286
12512
|
}
|
|
12287
12513
|
const effectSchema = yield* processNode(node.type, false);
|
|
12288
|
-
return yield* createExportVariableDeclaration(node.name
|
|
12514
|
+
return yield* createExportVariableDeclaration(ts.idText(node.name), effectSchema);
|
|
12289
12515
|
}
|
|
12290
12516
|
);
|
|
12291
12517
|
var createExportVariableDeclaration = fn("SchemaGen.createExportVariableDeclaration")(
|
|
@@ -12390,6 +12616,7 @@ var typeToEffectSchema = createRefactor({
|
|
|
12390
12616
|
const ts = yield* service(TypeScriptApi);
|
|
12391
12617
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
12392
12618
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
12619
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
12393
12620
|
const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
|
|
12394
12621
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
12395
12622
|
const node = maybeNode.value;
|
|
@@ -12400,7 +12627,8 @@ var typeToEffectSchema = createRefactor({
|
|
|
12400
12627
|
applyAtNode(sourceFile, node, false),
|
|
12401
12628
|
provideService(TypeCheckerApi, typeChecker),
|
|
12402
12629
|
provideService(TypeScriptUtils, tsUtils),
|
|
12403
|
-
provideService(TypeScriptApi, ts)
|
|
12630
|
+
provideService(TypeScriptApi, ts),
|
|
12631
|
+
provideService(TypeCheckerUtils, typeCheckerUtils)
|
|
12404
12632
|
)
|
|
12405
12633
|
};
|
|
12406
12634
|
})
|
|
@@ -12414,6 +12642,7 @@ var typeToEffectSchemaClass = createRefactor({
|
|
|
12414
12642
|
const ts = yield* service(TypeScriptApi);
|
|
12415
12643
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
12416
12644
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
12645
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
12417
12646
|
const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
|
|
12418
12647
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
12419
12648
|
const node = maybeNode.value;
|
|
@@ -12424,7 +12653,8 @@ var typeToEffectSchemaClass = createRefactor({
|
|
|
12424
12653
|
applyAtNode(sourceFile, node, true),
|
|
12425
12654
|
provideService(TypeCheckerApi, typeChecker),
|
|
12426
12655
|
provideService(TypeScriptUtils, tsUtils),
|
|
12427
|
-
provideService(TypeScriptApi, ts)
|
|
12656
|
+
provideService(TypeScriptApi, ts),
|
|
12657
|
+
provideService(TypeCheckerUtils, typeCheckerUtils)
|
|
12428
12658
|
)
|
|
12429
12659
|
};
|
|
12430
12660
|
})
|
|
@@ -12451,7 +12681,7 @@ var wrapWithEffectGen = createRefactor({
|
|
|
12451
12681
|
);
|
|
12452
12682
|
const maybeNode = yield* pipe(
|
|
12453
12683
|
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
12454
|
-
|
|
12684
|
+
map5(findEffectToWrap),
|
|
12455
12685
|
firstSuccessOf,
|
|
12456
12686
|
option
|
|
12457
12687
|
);
|
|
@@ -12523,6 +12753,57 @@ var refactors = [
|
|
|
12523
12753
|
writeTagClassAccessors
|
|
12524
12754
|
];
|
|
12525
12755
|
|
|
12756
|
+
// src/renames/keyStrings.ts
|
|
12757
|
+
var renameKeyStrings = (sourceFile, position, _findInStrings, _findInComments, _preferences, renameLocations) => gen(function* () {
|
|
12758
|
+
const ts = yield* service(TypeScriptApi);
|
|
12759
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
12760
|
+
const typeParser = yield* service(TypeParser);
|
|
12761
|
+
const additionalPositions = [];
|
|
12762
|
+
const node = tsUtils.findNodeAtPositionIncludingTrivia(sourceFile, position);
|
|
12763
|
+
if (node && ts.isIdentifier(node)) {
|
|
12764
|
+
const textToReplace = ts.idText(node);
|
|
12765
|
+
const parentClass = node.parent;
|
|
12766
|
+
if (ts.isClassDeclaration(parentClass) && parentClass.name === node) {
|
|
12767
|
+
const baseIdentifier = yield* pipe(
|
|
12768
|
+
map3(typeParser.extendsContextTag(parentClass), (_) => [_.keyStringLiteral]),
|
|
12769
|
+
orElse2(() => map3(typeParser.extendsEffectService(parentClass), (_) => [_.keyStringLiteral])),
|
|
12770
|
+
orElse2(
|
|
12771
|
+
() => map3(typeParser.extendsSchemaTaggedClass(parentClass), (_) => [_.keyStringLiteral, _.tagStringLiteral])
|
|
12772
|
+
),
|
|
12773
|
+
orElse2(
|
|
12774
|
+
() => map3(typeParser.extendsSchemaTaggedError(parentClass), (_) => [_.keyStringLiteral, _.tagStringLiteral])
|
|
12775
|
+
),
|
|
12776
|
+
orElse2(() => map3(typeParser.extendsDataTaggedError(parentClass), (_) => [_.keyStringLiteral])),
|
|
12777
|
+
orElse2(() => map3(typeParser.extendsDataTaggedClass(parentClass), (_) => [_.keyStringLiteral])),
|
|
12778
|
+
orElse2(
|
|
12779
|
+
() => map3(
|
|
12780
|
+
typeParser.extendsSchemaTaggedRequest(parentClass),
|
|
12781
|
+
(_) => [_.keyStringLiteral, _.tagStringLiteral]
|
|
12782
|
+
)
|
|
12783
|
+
),
|
|
12784
|
+
option
|
|
12785
|
+
);
|
|
12786
|
+
if (isSome2(baseIdentifier)) {
|
|
12787
|
+
for (const keyStringLiteral of baseIdentifier.value) {
|
|
12788
|
+
if (!keyStringLiteral) continue;
|
|
12789
|
+
const baseText = sourceFile.text.slice(keyStringLiteral.pos, keyStringLiteral.end);
|
|
12790
|
+
const lastIndex = baseText.lastIndexOf(textToReplace);
|
|
12791
|
+
if (lastIndex !== -1) {
|
|
12792
|
+
additionalPositions.push({
|
|
12793
|
+
fileName: sourceFile.fileName,
|
|
12794
|
+
textSpan: {
|
|
12795
|
+
start: keyStringLiteral.pos + lastIndex,
|
|
12796
|
+
length: textToReplace.length
|
|
12797
|
+
}
|
|
12798
|
+
});
|
|
12799
|
+
}
|
|
12800
|
+
}
|
|
12801
|
+
}
|
|
12802
|
+
}
|
|
12803
|
+
}
|
|
12804
|
+
return additionalPositions.length === 0 ? renameLocations : additionalPositions.concat(renameLocations || []);
|
|
12805
|
+
});
|
|
12806
|
+
|
|
12526
12807
|
// src/index.ts
|
|
12527
12808
|
var LSP_INJECTED_URI = "@effect/language-service/injected";
|
|
12528
12809
|
var init = (modules) => {
|
|
@@ -12552,6 +12833,7 @@ var init = (modules) => {
|
|
|
12552
12833
|
function runNano(program) {
|
|
12553
12834
|
return (fa) => pipe(
|
|
12554
12835
|
fa,
|
|
12836
|
+
nanoLayer3,
|
|
12555
12837
|
nanoLayer2,
|
|
12556
12838
|
nanoLayer,
|
|
12557
12839
|
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
@@ -12586,7 +12868,7 @@ var init = (modules) => {
|
|
|
12586
12868
|
};
|
|
12587
12869
|
proxy.getSemanticDiagnostics = (fileName, ...args2) => {
|
|
12588
12870
|
const applicableDiagnostics = languageService.getSemanticDiagnostics(fileName, ...args2);
|
|
12589
|
-
return runDiagnosticsAndCacheCodeFixes(fileName)
|
|
12871
|
+
return concatDiagnostics(runDiagnosticsAndCacheCodeFixes(fileName), applicableDiagnostics);
|
|
12590
12872
|
};
|
|
12591
12873
|
proxy.getSupportedCodeFixes = (...args2) => languageService.getSupportedCodeFixes(...args2).concat(
|
|
12592
12874
|
diagnosticsErrorCodes.map((_) => "" + _)
|
|
@@ -12854,6 +13136,37 @@ var init = (modules) => {
|
|
|
12854
13136
|
}
|
|
12855
13137
|
return applicableInlayHints;
|
|
12856
13138
|
};
|
|
13139
|
+
proxy.findRenameLocations = (fileName, position, findInStrings, findInComments, userPreferences, ...args2) => {
|
|
13140
|
+
const applicableRenameInfo = languageService.findRenameLocations(
|
|
13141
|
+
fileName,
|
|
13142
|
+
position,
|
|
13143
|
+
findInStrings,
|
|
13144
|
+
findInComments,
|
|
13145
|
+
userPreferences,
|
|
13146
|
+
...args2
|
|
13147
|
+
);
|
|
13148
|
+
if (languageServicePluginOptions.renames) {
|
|
13149
|
+
const program = languageService.getProgram();
|
|
13150
|
+
if (program) {
|
|
13151
|
+
const sourceFile = program.getSourceFile(fileName);
|
|
13152
|
+
if (sourceFile) {
|
|
13153
|
+
return pipe(
|
|
13154
|
+
renameKeyStrings(
|
|
13155
|
+
sourceFile,
|
|
13156
|
+
position,
|
|
13157
|
+
findInStrings,
|
|
13158
|
+
findInComments,
|
|
13159
|
+
userPreferences,
|
|
13160
|
+
applicableRenameInfo
|
|
13161
|
+
),
|
|
13162
|
+
runNano(program),
|
|
13163
|
+
getOrElse(() => applicableRenameInfo)
|
|
13164
|
+
);
|
|
13165
|
+
}
|
|
13166
|
+
}
|
|
13167
|
+
}
|
|
13168
|
+
return applicableRenameInfo;
|
|
13169
|
+
};
|
|
12857
13170
|
return proxy;
|
|
12858
13171
|
}
|
|
12859
13172
|
return { create, onConfigurationChanged };
|