@effect/language-service 0.36.0 → 0.38.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 +4 -1
- package/cli.js +108 -25
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +407 -288
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +831 -308
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +377 -262
- package/transform.js.map +1 -1
package/index.js
CHANGED
|
@@ -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
|
};
|
|
@@ -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) {
|
|
@@ -1039,6 +1068,18 @@ var ChangeTracker = Tag("ChangeTracker");
|
|
|
1039
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
|
|
|
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
|
+
|
|
1042
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]);
|
|
@@ -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
|
)
|
|
@@ -1295,7 +1336,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1295
1336
|
fnCall = ts.factory.createCallExpression(
|
|
1296
1337
|
fnCall,
|
|
1297
1338
|
void 0,
|
|
1298
|
-
[ts.factory.createStringLiteral(fnName
|
|
1339
|
+
[ts.factory.createStringLiteral(ts.idText(fnName))]
|
|
1299
1340
|
);
|
|
1300
1341
|
}
|
|
1301
1342
|
return tryPreserveDeclarationSemantics(
|
|
@@ -1367,7 +1408,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1367
1408
|
if (!namedBindings) continue;
|
|
1368
1409
|
if (ts.isNamespaceImport(namedBindings)) {
|
|
1369
1410
|
if (test(namedBindings.name, statement.moduleSpecifier, none2())) {
|
|
1370
|
-
return namedBindings.name
|
|
1411
|
+
return ts.idText(namedBindings.name);
|
|
1371
1412
|
}
|
|
1372
1413
|
} else if (ts.isNamedImports(namedBindings)) {
|
|
1373
1414
|
for (const importSpecifier of namedBindings.elements) {
|
|
@@ -1375,7 +1416,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1375
1416
|
orElse(() => some2(importSpecifier.name))
|
|
1376
1417
|
);
|
|
1377
1418
|
if (test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
|
|
1378
|
-
return importSpecifier.name
|
|
1419
|
+
return ts.idText(importSpecifier.name);
|
|
1379
1420
|
}
|
|
1380
1421
|
}
|
|
1381
1422
|
}
|
|
@@ -1388,7 +1429,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1388
1429
|
if (isNone2(importProperty) && ts.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
|
|
1389
1430
|
return true;
|
|
1390
1431
|
}
|
|
1391
|
-
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) {
|
|
1392
1433
|
return true;
|
|
1393
1434
|
}
|
|
1394
1435
|
return false;
|
|
@@ -1615,7 +1656,7 @@ function parseDiagnosticSeverity(config) {
|
|
|
1615
1656
|
pipe(
|
|
1616
1657
|
Object.entries(config),
|
|
1617
1658
|
filter(([key, value]) => isString(key) && isString(value)),
|
|
1618
|
-
|
|
1659
|
+
map5(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),
|
|
1619
1660
|
filter(
|
|
1620
1661
|
([_, value]) => value === "off" || value === "error" || value === "warning" || value === "message" || value === "suggestion"
|
|
1621
1662
|
)
|
|
@@ -1633,8 +1674,10 @@ var defaults = {
|
|
|
1633
1674
|
inlays: true,
|
|
1634
1675
|
allowedDuplicatedPackages: [],
|
|
1635
1676
|
namespaceImportPackages: [],
|
|
1677
|
+
topLevelNamedReexports: "ignore",
|
|
1636
1678
|
barrelImportPackages: [],
|
|
1637
|
-
|
|
1679
|
+
importAliases: {},
|
|
1680
|
+
renames: true
|
|
1638
1681
|
};
|
|
1639
1682
|
function parse(config) {
|
|
1640
1683
|
return {
|
|
@@ -1649,7 +1692,9 @@ function parse(config) {
|
|
|
1649
1692
|
allowedDuplicatedPackages: isObject(config) && hasProperty(config, "allowedDuplicatedPackages") && isArray(config.allowedDuplicatedPackages) && config.allowedDuplicatedPackages.every(isString) ? config.allowedDuplicatedPackages.map((_) => _.toLowerCase()) : defaults.allowedDuplicatedPackages,
|
|
1650
1693
|
namespaceImportPackages: isObject(config) && hasProperty(config, "namespaceImportPackages") && isArray(config.namespaceImportPackages) && config.namespaceImportPackages.every(isString) ? config.namespaceImportPackages.map((_) => _.toLowerCase()) : defaults.namespaceImportPackages,
|
|
1651
1694
|
barrelImportPackages: isObject(config) && hasProperty(config, "barrelImportPackages") && isArray(config.barrelImportPackages) && config.barrelImportPackages.every(isString) ? config.barrelImportPackages.map((_) => _.toLowerCase()) : defaults.barrelImportPackages,
|
|
1652
|
-
|
|
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
|
|
1653
1698
|
};
|
|
1654
1699
|
}
|
|
1655
1700
|
|
|
@@ -1961,6 +2006,9 @@ var getEditsForCodegen = fn("LSP.getEditsForCodegen")(function* (codegens2, sour
|
|
|
1961
2006
|
ignore: updateHashComment
|
|
1962
2007
|
};
|
|
1963
2008
|
});
|
|
2009
|
+
var getEffectLspPatchSourceFileMetadata = (sourceFile) => {
|
|
2010
|
+
return sourceFile["@effect-lsp-patch/metadata"];
|
|
2011
|
+
};
|
|
1964
2012
|
|
|
1965
2013
|
// src/completions/contextSelfInClasses.ts
|
|
1966
2014
|
var contextSelfInClasses = createCompletion({
|
|
@@ -1990,188 +2038,6 @@ var contextSelfInClasses = createCompletion({
|
|
|
1990
2038
|
|
|
1991
2039
|
// src/core/TypeCheckerApi.ts
|
|
1992
2040
|
var TypeCheckerApi = Tag("TypeChecker");
|
|
1993
|
-
var deterministicTypeOrder = gen(function* () {
|
|
1994
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
1995
|
-
return make2((a, b) => {
|
|
1996
|
-
const aName = typeChecker.typeToString(a);
|
|
1997
|
-
const bName = typeChecker.typeToString(b);
|
|
1998
|
-
if (aName < bName) return -1;
|
|
1999
|
-
if (aName > bName) return 1;
|
|
2000
|
-
return 0;
|
|
2001
|
-
});
|
|
2002
|
-
});
|
|
2003
|
-
var CannotFindAncestorConvertibleDeclarationError = class {
|
|
2004
|
-
constructor(node) {
|
|
2005
|
-
this.node = node;
|
|
2006
|
-
}
|
|
2007
|
-
_tag = "@effect/language-service/CannotFindAncestorConvertibleDeclarationError";
|
|
2008
|
-
};
|
|
2009
|
-
var getAncestorConvertibleDeclaration = fn(
|
|
2010
|
-
"TypeCheckerApi.getAncestorConvertibleDeclaration"
|
|
2011
|
-
)(function* (node) {
|
|
2012
|
-
const ts = yield* service(TypeScriptApi);
|
|
2013
|
-
let current = node;
|
|
2014
|
-
while (current) {
|
|
2015
|
-
if (ts.isFunctionDeclaration(current) || ts.isFunctionExpression(current) || ts.isArrowFunction(current) || ts.isMethodDeclaration(current)) {
|
|
2016
|
-
return current;
|
|
2017
|
-
}
|
|
2018
|
-
current = current.parent;
|
|
2019
|
-
}
|
|
2020
|
-
return yield* fail(new CannotFindAncestorConvertibleDeclarationError(node));
|
|
2021
|
-
});
|
|
2022
|
-
var CannotInferReturnTypeFromEmptyBody = class {
|
|
2023
|
-
constructor(declaration) {
|
|
2024
|
-
this.declaration = declaration;
|
|
2025
|
-
}
|
|
2026
|
-
_tag = "@effect/language-service/CannotInferReturnTypeFromEmptyBody";
|
|
2027
|
-
};
|
|
2028
|
-
var CannotInferReturnType = class {
|
|
2029
|
-
constructor(declaration) {
|
|
2030
|
-
this.declaration = declaration;
|
|
2031
|
-
}
|
|
2032
|
-
_tag = "@effect/language-service/CannotInferReturnType";
|
|
2033
|
-
};
|
|
2034
|
-
var getInferredReturnType = fn("TypeCheckerApi.getInferredReturnType")(function* (declaration) {
|
|
2035
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
2036
|
-
const ts = yield* service(TypeScriptApi);
|
|
2037
|
-
if (!declaration.body) {
|
|
2038
|
-
return yield* fail(
|
|
2039
|
-
new CannotInferReturnTypeFromEmptyBody(declaration)
|
|
2040
|
-
);
|
|
2041
|
-
}
|
|
2042
|
-
let returnType;
|
|
2043
|
-
if (typeChecker.isImplementationOfOverload(declaration)) {
|
|
2044
|
-
const signatures = typeChecker.getSignaturesOfType(
|
|
2045
|
-
typeChecker.getTypeAtLocation(declaration),
|
|
2046
|
-
ts.SignatureKind.Call
|
|
2047
|
-
);
|
|
2048
|
-
if (signatures.length > 1) {
|
|
2049
|
-
returnType = typeChecker.getUnionType(
|
|
2050
|
-
signatures.map((s) => typeChecker.getReturnTypeOfSignature(s)).filter((_) => !!_)
|
|
2051
|
-
);
|
|
2052
|
-
}
|
|
2053
|
-
}
|
|
2054
|
-
if (!returnType) {
|
|
2055
|
-
const signature = typeChecker.getSignatureFromDeclaration(declaration);
|
|
2056
|
-
if (signature) {
|
|
2057
|
-
const typePredicate = typeChecker.getTypePredicateOfSignature(signature);
|
|
2058
|
-
if (typePredicate && typePredicate.type) {
|
|
2059
|
-
return typePredicate.type;
|
|
2060
|
-
} else {
|
|
2061
|
-
returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
if (!returnType) {
|
|
2066
|
-
return yield* fail(
|
|
2067
|
-
new CannotInferReturnType(declaration)
|
|
2068
|
-
);
|
|
2069
|
-
}
|
|
2070
|
-
return returnType;
|
|
2071
|
-
});
|
|
2072
|
-
var expectedAndRealType = cachedBy(
|
|
2073
|
-
fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
|
|
2074
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
2075
|
-
const ts = yield* service(TypeScriptApi);
|
|
2076
|
-
const result = [];
|
|
2077
|
-
const nodeToVisit = [sourceFile];
|
|
2078
|
-
const appendNodeToVisit = (node) => {
|
|
2079
|
-
nodeToVisit.push(node);
|
|
2080
|
-
return void 0;
|
|
2081
|
-
};
|
|
2082
|
-
while (nodeToVisit.length > 0) {
|
|
2083
|
-
const node = nodeToVisit.shift();
|
|
2084
|
-
if (ts.isVariableDeclaration(node) && node.initializer) {
|
|
2085
|
-
const expectedType = typeChecker.getTypeAtLocation(node.name);
|
|
2086
|
-
const realType = typeChecker.getTypeAtLocation(node.initializer);
|
|
2087
|
-
result.push([node.name, expectedType, node.initializer, realType]);
|
|
2088
|
-
appendNodeToVisit(node.initializer);
|
|
2089
|
-
continue;
|
|
2090
|
-
} else if (ts.isCallExpression(node)) {
|
|
2091
|
-
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
2092
|
-
if (resolvedSignature) {
|
|
2093
|
-
resolvedSignature.parameters.map((parameter, index) => {
|
|
2094
|
-
const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
|
|
2095
|
-
const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
|
|
2096
|
-
result.push([
|
|
2097
|
-
node.arguments[index],
|
|
2098
|
-
expectedType,
|
|
2099
|
-
node.arguments[index],
|
|
2100
|
-
realType
|
|
2101
|
-
]);
|
|
2102
|
-
});
|
|
2103
|
-
}
|
|
2104
|
-
ts.forEachChild(node, appendNodeToVisit);
|
|
2105
|
-
continue;
|
|
2106
|
-
} else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
2107
|
-
const parent = node.parent;
|
|
2108
|
-
if (ts.isObjectLiteralElement(parent)) {
|
|
2109
|
-
if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
|
|
2110
|
-
const type = typeChecker.getContextualType(parent.parent);
|
|
2111
|
-
if (type) {
|
|
2112
|
-
const name = ts.isIdentifier(node) ? ts.idText(node) : ts.isStringLiteral(node) ? node.text : void 0;
|
|
2113
|
-
if (name) {
|
|
2114
|
-
const symbol3 = typeChecker.getPropertyOfType(type, name);
|
|
2115
|
-
if (symbol3) {
|
|
2116
|
-
const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
|
|
2117
|
-
const realType = typeChecker.getTypeAtLocation(node);
|
|
2118
|
-
result.push([node, expectedType, node, realType]);
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
}
|
|
2124
|
-
ts.forEachChild(node, appendNodeToVisit);
|
|
2125
|
-
continue;
|
|
2126
|
-
} else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
2127
|
-
const expectedType = typeChecker.getTypeAtLocation(node.left);
|
|
2128
|
-
const realType = typeChecker.getTypeAtLocation(node.right);
|
|
2129
|
-
result.push([node.left, expectedType, node.right, realType]);
|
|
2130
|
-
appendNodeToVisit(node.right);
|
|
2131
|
-
continue;
|
|
2132
|
-
} else if (ts.isReturnStatement(node) && node.expression) {
|
|
2133
|
-
const parentDeclaration = yield* option(getAncestorConvertibleDeclaration(node));
|
|
2134
|
-
if (isSome2(parentDeclaration)) {
|
|
2135
|
-
const expectedType = yield* option(getInferredReturnType(parentDeclaration.value));
|
|
2136
|
-
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2137
|
-
if (isSome2(expectedType)) {
|
|
2138
|
-
result.push([node, expectedType.value, node, realType]);
|
|
2139
|
-
}
|
|
2140
|
-
}
|
|
2141
|
-
ts.forEachChild(node, appendNodeToVisit);
|
|
2142
|
-
continue;
|
|
2143
|
-
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
|
|
2144
|
-
const body = node.body;
|
|
2145
|
-
const expectedType = typeChecker.getContextualType(body);
|
|
2146
|
-
const realType = typeChecker.getTypeAtLocation(body);
|
|
2147
|
-
if (expectedType) {
|
|
2148
|
-
result.push([body, expectedType, body, realType]);
|
|
2149
|
-
}
|
|
2150
|
-
ts.forEachChild(body, appendNodeToVisit);
|
|
2151
|
-
continue;
|
|
2152
|
-
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
|
|
2153
|
-
const body = node.body;
|
|
2154
|
-
const expectedType = yield* option(getInferredReturnType(node));
|
|
2155
|
-
const realType = typeChecker.getTypeAtLocation(body);
|
|
2156
|
-
if (isSome2(expectedType)) {
|
|
2157
|
-
result.push([body, expectedType.value, body, realType]);
|
|
2158
|
-
}
|
|
2159
|
-
ts.forEachChild(body, appendNodeToVisit);
|
|
2160
|
-
continue;
|
|
2161
|
-
} else if (ts.isSatisfiesExpression(node)) {
|
|
2162
|
-
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
2163
|
-
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2164
|
-
result.push([node.expression, expectedType, node.expression, realType]);
|
|
2165
|
-
appendNodeToVisit(node.expression);
|
|
2166
|
-
continue;
|
|
2167
|
-
}
|
|
2168
|
-
ts.forEachChild(node, appendNodeToVisit);
|
|
2169
|
-
}
|
|
2170
|
-
return result;
|
|
2171
|
-
}),
|
|
2172
|
-
"TypeCheckerApi.expectedAndRealType",
|
|
2173
|
-
(sourceFile) => sourceFile
|
|
2174
|
-
);
|
|
2175
2041
|
function makeResolveExternalModuleName(typeChecker) {
|
|
2176
2042
|
if (!(hasProperty(typeChecker, "resolveExternalModuleName") && isFunction(typeChecker.resolveExternalModuleName))) {
|
|
2177
2043
|
return;
|
|
@@ -2284,12 +2150,161 @@ function makeTypeCheckerUtils(ts, typeChecker) {
|
|
|
2284
2150
|
};
|
|
2285
2151
|
}
|
|
2286
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
|
|
2178
|
+
);
|
|
2179
|
+
if (signatures.length > 1) {
|
|
2180
|
+
returnType = typeChecker.getUnionType(
|
|
2181
|
+
signatures.map((s) => typeChecker.getReturnTypeOfSignature(s)).filter((_) => !!_)
|
|
2182
|
+
);
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
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
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
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;
|
|
2202
|
+
const result = [];
|
|
2203
|
+
const nodeToVisit = [sourceFile];
|
|
2204
|
+
const appendNodeToVisit = (node) => {
|
|
2205
|
+
nodeToVisit.push(node);
|
|
2206
|
+
return void 0;
|
|
2207
|
+
};
|
|
2208
|
+
while (nodeToVisit.length > 0) {
|
|
2209
|
+
const node = nodeToVisit.shift();
|
|
2210
|
+
if (ts.isVariableDeclaration(node) && node.initializer) {
|
|
2211
|
+
const expectedType = typeChecker.getTypeAtLocation(node.name);
|
|
2212
|
+
const realType = typeChecker.getTypeAtLocation(node.initializer);
|
|
2213
|
+
result.push([node.name, expectedType, node.initializer, realType]);
|
|
2214
|
+
appendNodeToVisit(node.initializer);
|
|
2215
|
+
continue;
|
|
2216
|
+
} else if (ts.isCallExpression(node)) {
|
|
2217
|
+
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
2218
|
+
if (resolvedSignature) {
|
|
2219
|
+
resolvedSignature.parameters.map((parameter, index) => {
|
|
2220
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
|
|
2221
|
+
const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
|
|
2222
|
+
result.push([
|
|
2223
|
+
node.arguments[index],
|
|
2224
|
+
expectedType,
|
|
2225
|
+
node.arguments[index],
|
|
2226
|
+
realType
|
|
2227
|
+
]);
|
|
2228
|
+
});
|
|
2229
|
+
}
|
|
2230
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2231
|
+
continue;
|
|
2232
|
+
} else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
2233
|
+
const parent = node.parent;
|
|
2234
|
+
if (ts.isObjectLiteralElement(parent)) {
|
|
2235
|
+
if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
|
|
2236
|
+
const type = typeChecker.getContextualType(parent.parent);
|
|
2237
|
+
if (type) {
|
|
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
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2251
|
+
continue;
|
|
2252
|
+
} else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
2253
|
+
const expectedType = typeChecker.getTypeAtLocation(node.left);
|
|
2254
|
+
const realType = typeChecker.getTypeAtLocation(node.right);
|
|
2255
|
+
result.push([node.left, expectedType, node.right, realType]);
|
|
2256
|
+
appendNodeToVisit(node.right);
|
|
2257
|
+
continue;
|
|
2258
|
+
} else if (ts.isReturnStatement(node) && node.expression) {
|
|
2259
|
+
const parentDeclaration = getAncestorConvertibleDeclaration(node);
|
|
2260
|
+
if (parentDeclaration) {
|
|
2261
|
+
const expectedType = getInferredReturnType(parentDeclaration);
|
|
2262
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2263
|
+
if (expectedType) {
|
|
2264
|
+
result.push([node, expectedType, node, realType]);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2268
|
+
continue;
|
|
2269
|
+
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
|
|
2270
|
+
const body = node.body;
|
|
2271
|
+
const expectedType = typeChecker.getContextualType(body);
|
|
2272
|
+
const realType = typeChecker.getTypeAtLocation(body);
|
|
2273
|
+
if (expectedType) {
|
|
2274
|
+
result.push([body, expectedType, body, realType]);
|
|
2275
|
+
}
|
|
2276
|
+
ts.forEachChild(body, appendNodeToVisit);
|
|
2277
|
+
continue;
|
|
2278
|
+
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
|
|
2279
|
+
const body = node.body;
|
|
2280
|
+
const expectedType = getInferredReturnType(node);
|
|
2281
|
+
const realType = typeChecker.getTypeAtLocation(body);
|
|
2282
|
+
if (expectedType) {
|
|
2283
|
+
result.push([body, expectedType, body, realType]);
|
|
2284
|
+
}
|
|
2285
|
+
ts.forEachChild(body, appendNodeToVisit);
|
|
2286
|
+
continue;
|
|
2287
|
+
} else if (ts.isSatisfiesExpression(node)) {
|
|
2288
|
+
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
2289
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2290
|
+
result.push([node.expression, expectedType, node.expression, realType]);
|
|
2291
|
+
appendNodeToVisit(node.expression);
|
|
2292
|
+
continue;
|
|
2293
|
+
}
|
|
2294
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2295
|
+
}
|
|
2296
|
+
expectedAndRealTypeCache.set(sourceFile, result);
|
|
2297
|
+
return result;
|
|
2298
|
+
};
|
|
2287
2299
|
return {
|
|
2288
2300
|
isUnion,
|
|
2289
2301
|
getTypeParameterAtPosition,
|
|
2290
2302
|
getMissingTypeEntriesInTargetType,
|
|
2291
2303
|
unrollUnionMembers,
|
|
2292
|
-
appendToUniqueTypesMap
|
|
2304
|
+
appendToUniqueTypesMap,
|
|
2305
|
+
deterministicTypeOrder,
|
|
2306
|
+
getInferredReturnType,
|
|
2307
|
+
expectedAndRealType
|
|
2293
2308
|
};
|
|
2294
2309
|
}
|
|
2295
2310
|
|
|
@@ -2564,6 +2579,21 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2564
2579
|
"TypeParser.importedEffectModule",
|
|
2565
2580
|
(node) => node
|
|
2566
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
|
+
);
|
|
2567
2597
|
const effectGen = cachedBy(
|
|
2568
2598
|
function(node) {
|
|
2569
2599
|
if (!ts.isCallExpression(node)) {
|
|
@@ -2583,7 +2613,7 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2583
2613
|
return typeParserIssue("Node is not a property access expression", void 0, node);
|
|
2584
2614
|
}
|
|
2585
2615
|
const propertyAccess = node.expression;
|
|
2586
|
-
if (propertyAccess.name.
|
|
2616
|
+
if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "gen")) {
|
|
2587
2617
|
return typeParserIssue("Call expression name is not 'gen'", void 0, node);
|
|
2588
2618
|
}
|
|
2589
2619
|
return pipe(
|
|
@@ -2627,7 +2657,7 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2627
2657
|
);
|
|
2628
2658
|
}
|
|
2629
2659
|
const propertyAccess = node.expression;
|
|
2630
|
-
if (propertyAccess.name.
|
|
2660
|
+
if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "fnUntraced")) {
|
|
2631
2661
|
return typeParserIssue(
|
|
2632
2662
|
"Call expression name is not 'fnUntraced'",
|
|
2633
2663
|
void 0,
|
|
@@ -2680,7 +2710,7 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2680
2710
|
);
|
|
2681
2711
|
}
|
|
2682
2712
|
const propertyAccess = expressionToTest;
|
|
2683
|
-
if (propertyAccess.name.
|
|
2713
|
+
if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "fn")) {
|
|
2684
2714
|
return typeParserIssue(
|
|
2685
2715
|
"Call expression name is not 'fn'",
|
|
2686
2716
|
void 0,
|
|
@@ -2834,7 +2864,7 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2834
2864
|
kind: "pipeable"
|
|
2835
2865
|
});
|
|
2836
2866
|
}
|
|
2837
|
-
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) {
|
|
2838
2868
|
const [subject, ...args2] = node.arguments;
|
|
2839
2869
|
return succeed({ node, subject, args: args2, kind: "pipe" });
|
|
2840
2870
|
}
|
|
@@ -2959,7 +2989,7 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2959
2989
|
for (const typeX of heritageClause.types) {
|
|
2960
2990
|
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2961
2991
|
const expression = typeX.expression;
|
|
2962
|
-
if (ts.isCallExpression(expression)) {
|
|
2992
|
+
if (ts.isCallExpression(expression) && expression.arguments.length > 0) {
|
|
2963
2993
|
const schemaTaggedClassTCall = expression.expression;
|
|
2964
2994
|
if (ts.isCallExpression(schemaTaggedClassTCall) && schemaTaggedClassTCall.typeArguments && schemaTaggedClassTCall.typeArguments.length > 0) {
|
|
2965
2995
|
const selfTypeNode = schemaTaggedClassTCall.typeArguments[0];
|
|
@@ -2973,6 +3003,8 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2973
3003
|
return {
|
|
2974
3004
|
className: atLocation.name,
|
|
2975
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,
|
|
2976
3008
|
Schema: parsedSchemaModule.value
|
|
2977
3009
|
};
|
|
2978
3010
|
}
|
|
@@ -3014,6 +3046,8 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3014
3046
|
return {
|
|
3015
3047
|
className: atLocation.name,
|
|
3016
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,
|
|
3017
3051
|
Schema: parsedSchemaModule.value
|
|
3018
3052
|
};
|
|
3019
3053
|
}
|
|
@@ -3028,6 +3062,82 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3028
3062
|
"TypeParser.extendsSchemaTaggedError",
|
|
3029
3063
|
(atLocation) => atLocation
|
|
3030
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
|
+
);
|
|
3031
3141
|
const extendsSchemaTaggedRequest = cachedBy(
|
|
3032
3142
|
fn("TypeParser.extendsSchemaTaggedRequest")(function* (atLocation) {
|
|
3033
3143
|
if (!atLocation.name) {
|
|
@@ -3055,6 +3165,8 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3055
3165
|
return {
|
|
3056
3166
|
className: atLocation.name,
|
|
3057
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,
|
|
3058
3170
|
Schema: parsedSchemaModule.value
|
|
3059
3171
|
};
|
|
3060
3172
|
}
|
|
@@ -3074,9 +3186,6 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3074
3186
|
if (!atLocation.name) {
|
|
3075
3187
|
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
3076
3188
|
}
|
|
3077
|
-
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
3078
|
-
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
3079
|
-
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
3080
3189
|
const heritageClauses = atLocation.heritageClauses;
|
|
3081
3190
|
if (!heritageClauses) {
|
|
3082
3191
|
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
@@ -3096,10 +3205,14 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3096
3205
|
option
|
|
3097
3206
|
);
|
|
3098
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);
|
|
3099
3211
|
const tagType = yield* contextTag(type, atLocation);
|
|
3100
3212
|
return {
|
|
3101
3213
|
className: atLocation.name,
|
|
3102
3214
|
selfTypeNode,
|
|
3215
|
+
keyStringLiteral: ts.isStringLiteral(contextTagCall.arguments[0]) ? contextTagCall.arguments[0] : void 0,
|
|
3103
3216
|
args: contextTagCall.arguments,
|
|
3104
3217
|
Identifier: tagType.Identifier,
|
|
3105
3218
|
Tag: parsedContextModule.value
|
|
@@ -3121,9 +3234,6 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3121
3234
|
if (!atLocation.name) {
|
|
3122
3235
|
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
3123
3236
|
}
|
|
3124
|
-
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
3125
|
-
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
3126
|
-
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
3127
3237
|
const heritageClauses = atLocation.heritageClauses;
|
|
3128
3238
|
if (!heritageClauses) {
|
|
3129
3239
|
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
@@ -3138,6 +3248,9 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3138
3248
|
const effectServiceIdentifier = effectServiceCall.expression;
|
|
3139
3249
|
const selfTypeNode = effectServiceCall.typeArguments[0];
|
|
3140
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);
|
|
3141
3254
|
const parsedContextTag = yield* pipe(
|
|
3142
3255
|
importedEffectModule(effectServiceIdentifier.expression),
|
|
3143
3256
|
flatMap(() => contextTag(type, atLocation)),
|
|
@@ -3164,6 +3277,7 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3164
3277
|
className: atLocation.name,
|
|
3165
3278
|
selfTypeNode,
|
|
3166
3279
|
args: wholeCall.arguments,
|
|
3280
|
+
keyStringLiteral: ts.isStringLiteral(wholeCall.arguments[0]) ? wholeCall.arguments[0] : void 0,
|
|
3167
3281
|
options: wholeCall.arguments[1],
|
|
3168
3282
|
accessors: accessors2,
|
|
3169
3283
|
dependencies
|
|
@@ -3202,6 +3316,8 @@ function make3(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3202
3316
|
extendsSchemaClass,
|
|
3203
3317
|
extendsSchemaTaggedClass,
|
|
3204
3318
|
extendsSchemaTaggedError,
|
|
3319
|
+
extendsDataTaggedError,
|
|
3320
|
+
extendsDataTaggedClass,
|
|
3205
3321
|
extendsSchemaTaggedRequest
|
|
3206
3322
|
};
|
|
3207
3323
|
}
|
|
@@ -3227,7 +3343,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3227
3343
|
),
|
|
3228
3344
|
void 0,
|
|
3229
3345
|
[
|
|
3230
|
-
ts.factory.createIdentifier(className2
|
|
3346
|
+
ts.factory.createIdentifier(ts.idText(className2)),
|
|
3231
3347
|
ts.factory.createArrowFunction(
|
|
3232
3348
|
void 0,
|
|
3233
3349
|
void 0,
|
|
@@ -3277,9 +3393,9 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3277
3393
|
const generateReturnType = (type, atLocation2, className2) => pipe(
|
|
3278
3394
|
typeParser.effectType(type, atLocation2),
|
|
3279
3395
|
flatMap((returnedEffect) => {
|
|
3280
|
-
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(
|
|
3281
3397
|
[
|
|
3282
|
-
ts.factory.createTypeReferenceNode(className2
|
|
3398
|
+
ts.factory.createTypeReferenceNode(ts.idText(className2)),
|
|
3283
3399
|
typeChecker.typeToTypeNode(returnedEffect.R, atLocation2, ts.NodeBuilderFlags.NoTruncation)
|
|
3284
3400
|
]
|
|
3285
3401
|
);
|
|
@@ -3327,7 +3443,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3327
3443
|
ts.factory.createIdentifier("UnknownException")
|
|
3328
3444
|
)
|
|
3329
3445
|
),
|
|
3330
|
-
ts.factory.createTypeReferenceNode(className2
|
|
3446
|
+
ts.factory.createTypeReferenceNode(ts.idText(className2))
|
|
3331
3447
|
]
|
|
3332
3448
|
));
|
|
3333
3449
|
})
|
|
@@ -3344,7 +3460,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
3344
3460
|
[
|
|
3345
3461
|
successType,
|
|
3346
3462
|
ts.factory.createTypeReferenceNode("never"),
|
|
3347
|
-
ts.factory.createTypeReferenceNode(className2
|
|
3463
|
+
ts.factory.createTypeReferenceNode(ts.idText(className2))
|
|
3348
3464
|
]
|
|
3349
3465
|
);
|
|
3350
3466
|
return succeed(typeNode);
|
|
@@ -3421,7 +3537,7 @@ var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
|
|
|
3421
3537
|
}
|
|
3422
3538
|
const hash2 = involvedMembers.map(({ property, propertyType }) => {
|
|
3423
3539
|
return ts.symbolName(property) + ": " + typeChecker.typeToString(propertyType);
|
|
3424
|
-
}).concat([className
|
|
3540
|
+
}).concat([ts.idText(className)]).join("\n");
|
|
3425
3541
|
return { Service, className, atLocation: node, hash: cyrb53(hash2), involvedMembers };
|
|
3426
3542
|
});
|
|
3427
3543
|
var writeTagClassAccessors = createRefactor({
|
|
@@ -3528,8 +3644,8 @@ var effectDataClasses = createCompletion({
|
|
|
3528
3644
|
"effect",
|
|
3529
3645
|
"Data"
|
|
3530
3646
|
) || "Data";
|
|
3531
|
-
if (effectDataIdentifier !== accessedObject
|
|
3532
|
-
const name = className
|
|
3647
|
+
if (effectDataIdentifier !== ts.idText(accessedObject)) return [];
|
|
3648
|
+
const name = ts.idText(className);
|
|
3533
3649
|
return [{
|
|
3534
3650
|
name: `TaggedError("${name}")`,
|
|
3535
3651
|
kind: ts.ScriptElementKind.constElement,
|
|
@@ -3715,7 +3831,7 @@ var effectInVoidSuccess = createDiagnostic({
|
|
|
3715
3831
|
}
|
|
3716
3832
|
return yield* fail(typeParserIssue("expectedEffect success is not void"));
|
|
3717
3833
|
});
|
|
3718
|
-
const entries =
|
|
3834
|
+
const entries = typeCheckerUtils.expectedAndRealType(sourceFile);
|
|
3719
3835
|
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
3720
3836
|
if (expectedType !== realType) {
|
|
3721
3837
|
yield* pipe(
|
|
@@ -3984,7 +4100,6 @@ var leakingRequirements = createDiagnostic({
|
|
|
3984
4100
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3985
4101
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
3986
4102
|
const typeParser = yield* service(TypeParser);
|
|
3987
|
-
const typeOrder = yield* deterministicTypeOrder;
|
|
3988
4103
|
const parseLeakedRequirements = cachedBy(
|
|
3989
4104
|
fn("leakingServices.checkServiceLeaking")(
|
|
3990
4105
|
function* (service2, atLocation) {
|
|
@@ -4087,7 +4202,9 @@ More info at https://effect.website/docs/requirements-management/layers/#avoidin
|
|
|
4087
4202
|
flatMap(
|
|
4088
4203
|
({ Service }) => pipe(
|
|
4089
4204
|
parseLeakedRequirements(Service, node),
|
|
4090
|
-
map3(
|
|
4205
|
+
map3(
|
|
4206
|
+
(requirements) => reportLeakingRequirements(reportAt, sort(requirements, typeCheckerUtils.deterministicTypeOrder))
|
|
4207
|
+
)
|
|
4091
4208
|
)
|
|
4092
4209
|
),
|
|
4093
4210
|
orElse2(() => sync(() => ts.forEachChild(node, appendNodeToVisit))),
|
|
@@ -4106,7 +4223,6 @@ var missingEffectContext = createDiagnostic({
|
|
|
4106
4223
|
apply: fn("missingEffectContext.apply")(function* (sourceFile, report) {
|
|
4107
4224
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
4108
4225
|
const typeParser = yield* service(TypeParser);
|
|
4109
|
-
const typeOrder = yield* deterministicTypeOrder;
|
|
4110
4226
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
4111
4227
|
const checkForMissingContextTypes = (node, expectedType, valueNode, realType) => pipe(
|
|
4112
4228
|
all(
|
|
@@ -4120,8 +4236,8 @@ var missingEffectContext = createDiagnostic({
|
|
|
4120
4236
|
)
|
|
4121
4237
|
)
|
|
4122
4238
|
);
|
|
4123
|
-
const sortTypes = sort(
|
|
4124
|
-
const entries =
|
|
4239
|
+
const sortTypes = sort(typeCheckerUtils.deterministicTypeOrder);
|
|
4240
|
+
const entries = getEffectLspPatchSourceFileMetadata(sourceFile)?.relationErrors || typeCheckerUtils.expectedAndRealType(sourceFile);
|
|
4125
4241
|
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
4126
4242
|
if (expectedType !== realType) {
|
|
4127
4243
|
yield* pipe(
|
|
@@ -4158,7 +4274,6 @@ var missingEffectError = createDiagnostic({
|
|
|
4158
4274
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
4159
4275
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
4160
4276
|
const typeParser = yield* service(TypeParser);
|
|
4161
|
-
const typeOrder = yield* deterministicTypeOrder;
|
|
4162
4277
|
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4163
4278
|
sourceFile,
|
|
4164
4279
|
"effect",
|
|
@@ -4187,8 +4302,8 @@ var missingEffectError = createDiagnostic({
|
|
|
4187
4302
|
)
|
|
4188
4303
|
)
|
|
4189
4304
|
);
|
|
4190
|
-
const sortTypes = sort(
|
|
4191
|
-
const entries =
|
|
4305
|
+
const sortTypes = sort(typeCheckerUtils.deterministicTypeOrder);
|
|
4306
|
+
const entries = getEffectLspPatchSourceFileMetadata(sourceFile)?.relationErrors || typeCheckerUtils.expectedAndRealType(sourceFile);
|
|
4192
4307
|
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
4193
4308
|
if (expectedType !== realType) {
|
|
4194
4309
|
yield* pipe(
|
|
@@ -4225,17 +4340,17 @@ var missingEffectError = createDiagnostic({
|
|
|
4225
4340
|
if (ts.isExpression(valueNode)) {
|
|
4226
4341
|
const propertyAssignments = pipe(
|
|
4227
4342
|
result.missingErrorTypes,
|
|
4228
|
-
|
|
4343
|
+
map5((_) => typeChecker.getPropertyOfType(_, "_tag")),
|
|
4229
4344
|
filter((_) => !!_),
|
|
4230
|
-
|
|
4345
|
+
map5((_) => typeChecker.getTypeOfSymbolAtLocation(_, valueNode)),
|
|
4231
4346
|
filter((_) => !!(_.flags & ts.TypeFlags.Literal)),
|
|
4232
|
-
|
|
4347
|
+
map5((_) => typeChecker.typeToTypeNode(_, void 0, ts.NodeBuilderFlags.NoTruncation)),
|
|
4233
4348
|
filter((_) => !!_ && ts.isLiteralTypeNode(_)),
|
|
4234
|
-
|
|
4349
|
+
map5((_) => _.literal),
|
|
4235
4350
|
filter((_) => ts.isLiteralExpression(_)),
|
|
4236
|
-
|
|
4351
|
+
map5((_) => _.text),
|
|
4237
4352
|
sort(string2),
|
|
4238
|
-
|
|
4353
|
+
map5(
|
|
4239
4354
|
(_) => ts.factory.createPropertyAssignment(
|
|
4240
4355
|
ts.factory.createIdentifier(_),
|
|
4241
4356
|
ts.factory.createArrowFunction(
|
|
@@ -5280,8 +5395,8 @@ var effectSchemaSelfInClasses = createCompletion({
|
|
|
5280
5395
|
"effect",
|
|
5281
5396
|
"Schema"
|
|
5282
5397
|
) || "Schema";
|
|
5283
|
-
if (schemaIdentifier !== accessedObject
|
|
5284
|
-
const name = className
|
|
5398
|
+
if (schemaIdentifier !== ts.idText(accessedObject)) return [];
|
|
5399
|
+
const name = ts.idText(className);
|
|
5285
5400
|
return [{
|
|
5286
5401
|
name: `Class<${name}>`,
|
|
5287
5402
|
kind: ts.ScriptElementKind.constElement,
|
|
@@ -5324,8 +5439,8 @@ var effectSelfInClasses = createCompletion({
|
|
|
5324
5439
|
"effect",
|
|
5325
5440
|
"Effect"
|
|
5326
5441
|
) || "Effect";
|
|
5327
|
-
if (effectIdentifier !== accessedObject
|
|
5328
|
-
const name = className
|
|
5442
|
+
if (effectIdentifier !== ts.idText(accessedObject)) return [];
|
|
5443
|
+
const name = ts.idText(className);
|
|
5329
5444
|
return [{
|
|
5330
5445
|
name: `Service<${name}>`,
|
|
5331
5446
|
kind: ts.ScriptElementKind.constElement,
|
|
@@ -5355,7 +5470,7 @@ var fnFunctionStar = createCompletion({
|
|
|
5355
5470
|
const maybeFnName = pipe(
|
|
5356
5471
|
tsUtils.getAncestorNodesInRange(sourceFile, tsUtils.toTextRange(accessedObject.pos)),
|
|
5357
5472
|
filter(ts.isVariableDeclaration),
|
|
5358
|
-
|
|
5473
|
+
map5((_) => _.name && ts.isIdentifier(_.name) ? ts.idText(_.name) : ""),
|
|
5359
5474
|
filter((_) => _.length > 0),
|
|
5360
5475
|
head,
|
|
5361
5476
|
map2((name) => [
|
|
@@ -5428,8 +5543,8 @@ var rpcMakeClasses = createCompletion({
|
|
|
5428
5543
|
"@effect/rpc",
|
|
5429
5544
|
"Rpc"
|
|
5430
5545
|
) || "Rpc";
|
|
5431
|
-
if (rpcIdentifier !== accessedObject
|
|
5432
|
-
const name = className
|
|
5546
|
+
if (rpcIdentifier !== ts.idText(accessedObject)) return [];
|
|
5547
|
+
const name = ts.idText(className);
|
|
5433
5548
|
return [{
|
|
5434
5549
|
name: `make("${name}")`,
|
|
5435
5550
|
kind: ts.ScriptElementKind.constElement,
|
|
@@ -5455,7 +5570,7 @@ var schemaBrand = createCompletion({
|
|
|
5455
5570
|
"effect",
|
|
5456
5571
|
"Schema"
|
|
5457
5572
|
) || "Schema";
|
|
5458
|
-
if (schemaName !== accessedObject
|
|
5573
|
+
if (schemaName !== ts.idText(accessedObject)) return [];
|
|
5459
5574
|
const span = ts.createTextSpan(
|
|
5460
5575
|
accessedObject.end + 1,
|
|
5461
5576
|
Math.max(0, position - accessedObject.end - 1)
|
|
@@ -5463,7 +5578,7 @@ var schemaBrand = createCompletion({
|
|
|
5463
5578
|
return pipe(
|
|
5464
5579
|
tsUtils.getAncestorNodesInRange(sourceFile, tsUtils.toTextRange(accessedObject.pos)),
|
|
5465
5580
|
filter(ts.isVariableDeclaration),
|
|
5466
|
-
|
|
5581
|
+
map5((_) => _.name && ts.isIdentifier(_.name) ? ts.idText(_.name) : ""),
|
|
5467
5582
|
filter((_) => _.length > 0),
|
|
5468
5583
|
head,
|
|
5469
5584
|
map2((name) => [
|
|
@@ -5519,7 +5634,7 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5519
5634
|
namespaceExports.push({
|
|
5520
5635
|
moduleSpecifier,
|
|
5521
5636
|
exportClause,
|
|
5522
|
-
name: exportClause.name
|
|
5637
|
+
name: ts.idText(exportClause.name)
|
|
5523
5638
|
});
|
|
5524
5639
|
}
|
|
5525
5640
|
if (ts.isNamedExports(exportClause)) {
|
|
@@ -5530,8 +5645,8 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5530
5645
|
namedExports.push({
|
|
5531
5646
|
moduleSpecifier,
|
|
5532
5647
|
exportClause,
|
|
5533
|
-
name: exportName
|
|
5534
|
-
aliasName: exportSpecifier.name
|
|
5648
|
+
name: ts.idText(exportName),
|
|
5649
|
+
aliasName: ts.idText(exportSpecifier.name)
|
|
5535
5650
|
});
|
|
5536
5651
|
}
|
|
5537
5652
|
}
|
|
@@ -5691,6 +5806,11 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5691
5806
|
if (!moduleSpecifier) return fileName;
|
|
5692
5807
|
return moduleSpecifier;
|
|
5693
5808
|
};
|
|
5809
|
+
const resolveAliasName = (chosenName) => {
|
|
5810
|
+
const aliasName = languageServicePluginOptions.importAliases[chosenName];
|
|
5811
|
+
if (aliasName) return aliasName;
|
|
5812
|
+
return void 0;
|
|
5813
|
+
};
|
|
5694
5814
|
const resolve = (exportFileName, exportName) => {
|
|
5695
5815
|
const excludedExports = mapFilenameToExportExcludes.get(exportFileName);
|
|
5696
5816
|
if (excludedExports && excludedExports.includes(exportName)) return;
|
|
@@ -5702,7 +5822,9 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5702
5822
|
_tag: "NamedImport",
|
|
5703
5823
|
fileName: reexportedFile.fileName,
|
|
5704
5824
|
moduleName: resolveModuleName(reexportedFile.fileName),
|
|
5705
|
-
name: exportName
|
|
5825
|
+
name: exportName,
|
|
5826
|
+
aliasName: resolveAliasName(exportName),
|
|
5827
|
+
introducedPrefix: void 0
|
|
5706
5828
|
};
|
|
5707
5829
|
}
|
|
5708
5830
|
}
|
|
@@ -5717,6 +5839,7 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5717
5839
|
fileName: namespacedFileName,
|
|
5718
5840
|
moduleName: resolveModuleName(namespacedFileName),
|
|
5719
5841
|
name: introducedAlias2,
|
|
5842
|
+
aliasName: resolveAliasName(introducedAlias2),
|
|
5720
5843
|
introducedPrefix: void 0
|
|
5721
5844
|
};
|
|
5722
5845
|
}
|
|
@@ -5729,7 +5852,8 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5729
5852
|
fileName: exportFileName,
|
|
5730
5853
|
moduleName: resolveModuleName(exportFileName),
|
|
5731
5854
|
name: introducedAlias,
|
|
5732
|
-
|
|
5855
|
+
aliasName: resolveAliasName(introducedAlias),
|
|
5856
|
+
introducedPrefix: resolveAliasName(introducedAlias) || introducedAlias
|
|
5733
5857
|
};
|
|
5734
5858
|
}
|
|
5735
5859
|
const mapToBarrel = mapFromNamespaceToBarrel.get(exportFileName);
|
|
@@ -5739,7 +5863,8 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
5739
5863
|
fileName: mapToBarrel.fileName,
|
|
5740
5864
|
moduleName: resolveModuleName(mapToBarrel.fileName),
|
|
5741
5865
|
name: mapToBarrel.alias,
|
|
5742
|
-
|
|
5866
|
+
aliasName: resolveAliasName(mapToBarrel.alias),
|
|
5867
|
+
introducedPrefix: resolveAliasName(mapToBarrel.alias) || mapToBarrel.alias
|
|
5743
5868
|
};
|
|
5744
5869
|
}
|
|
5745
5870
|
};
|
|
@@ -5782,7 +5907,7 @@ var parseImportOnlyChanges = fn("parseImportOnlyChanges")(function* (sourceFile,
|
|
|
5782
5907
|
if (ts.isNamedImports(namedBindings)) {
|
|
5783
5908
|
for (const importSpecifier of namedBindings.elements) {
|
|
5784
5909
|
if (!ts.isIdentifier(importSpecifier.name)) return;
|
|
5785
|
-
const exportName = importSpecifier.name
|
|
5910
|
+
const exportName = ts.idText(importSpecifier.name);
|
|
5786
5911
|
imports.push({ moduleName, exportName });
|
|
5787
5912
|
continue;
|
|
5788
5913
|
}
|
|
@@ -5816,8 +5941,9 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5816
5941
|
let description = "";
|
|
5817
5942
|
switch (effectAutoImport._tag) {
|
|
5818
5943
|
case "NamespaceImport": {
|
|
5944
|
+
const aliasName = effectAutoImport.aliasName || effectAutoImport.name;
|
|
5819
5945
|
const importModule = effectAutoImport.moduleName || effectAutoImport.fileName;
|
|
5820
|
-
description = `Import * as ${
|
|
5946
|
+
description = `Import * as ${aliasName} from "${importModule}"`;
|
|
5821
5947
|
ts.insertImports(
|
|
5822
5948
|
changeTracker,
|
|
5823
5949
|
sourceFile,
|
|
@@ -5826,7 +5952,7 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5826
5952
|
ts.factory.createImportClause(
|
|
5827
5953
|
false,
|
|
5828
5954
|
void 0,
|
|
5829
|
-
ts.factory.createNamespaceImport(ts.factory.createIdentifier(
|
|
5955
|
+
ts.factory.createNamespaceImport(ts.factory.createIdentifier(aliasName))
|
|
5830
5956
|
),
|
|
5831
5957
|
ts.factory.createStringLiteral(importModule)
|
|
5832
5958
|
),
|
|
@@ -5837,7 +5963,11 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5837
5963
|
}
|
|
5838
5964
|
case "NamedImport": {
|
|
5839
5965
|
const importModule = effectAutoImport.moduleName || effectAutoImport.fileName;
|
|
5840
|
-
|
|
5966
|
+
if (effectAutoImport.aliasName) {
|
|
5967
|
+
description = `Import { ${effectAutoImport.name} as ${effectAutoImport.aliasName} } from "${importModule}"`;
|
|
5968
|
+
} else {
|
|
5969
|
+
description = `Import { ${effectAutoImport.name} } from "${importModule}"`;
|
|
5970
|
+
}
|
|
5841
5971
|
let foundImportDeclaration = false;
|
|
5842
5972
|
for (const statement of sourceFile.statements) {
|
|
5843
5973
|
if (ts.isImportDeclaration(statement)) {
|
|
@@ -5846,9 +5976,12 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5846
5976
|
const importClause = statement.importClause;
|
|
5847
5977
|
if (importClause && importClause.namedBindings && ts.isNamedImports(importClause.namedBindings)) {
|
|
5848
5978
|
const namedImports = importClause.namedBindings;
|
|
5849
|
-
const existingImportSpecifier = namedImports.elements.find(
|
|
5850
|
-
(
|
|
5851
|
-
|
|
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
|
+
});
|
|
5852
5985
|
if (existingImportSpecifier) {
|
|
5853
5986
|
foundImportDeclaration = true;
|
|
5854
5987
|
break;
|
|
@@ -5860,8 +5993,8 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5860
5993
|
namedImports.elements.concat([
|
|
5861
5994
|
ts.factory.createImportSpecifier(
|
|
5862
5995
|
false,
|
|
5863
|
-
void 0,
|
|
5864
|
-
ts.factory.createIdentifier(effectAutoImport.name)
|
|
5996
|
+
effectAutoImport.aliasName ? ts.factory.createIdentifier(effectAutoImport.name) : void 0,
|
|
5997
|
+
ts.factory.createIdentifier(effectAutoImport.aliasName || effectAutoImport.name)
|
|
5865
5998
|
)
|
|
5866
5999
|
])
|
|
5867
6000
|
)
|
|
@@ -5885,8 +6018,8 @@ var addImport = (ts, sourceFile, changeTracker, preferences, effectAutoImport) =
|
|
|
5885
6018
|
[
|
|
5886
6019
|
ts.factory.createImportSpecifier(
|
|
5887
6020
|
false,
|
|
5888
|
-
void 0,
|
|
5889
|
-
ts.factory.createIdentifier(effectAutoImport.name)
|
|
6021
|
+
effectAutoImport.aliasName ? ts.factory.createIdentifier(effectAutoImport.name) : void 0,
|
|
6022
|
+
ts.factory.createIdentifier(effectAutoImport.aliasName || effectAutoImport.name)
|
|
5890
6023
|
)
|
|
5891
6024
|
]
|
|
5892
6025
|
)
|
|
@@ -6094,22 +6227,26 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
6094
6227
|
const textRange = tsUtils.toTextRange(position);
|
|
6095
6228
|
function isSymbolFromEffectRpcModule(symbol3) {
|
|
6096
6229
|
if (symbol3.valueDeclaration) {
|
|
6097
|
-
const sourceFile2 = symbol3.valueDeclaration
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
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
|
+
}
|
|
6102
6237
|
}
|
|
6103
6238
|
}
|
|
6104
6239
|
return false;
|
|
6105
6240
|
}
|
|
6106
6241
|
function isSymbolFromEffectRpcClientModule(symbol3) {
|
|
6107
6242
|
if (symbol3.valueDeclaration) {
|
|
6108
|
-
const sourceFile2 = symbol3.valueDeclaration
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
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
|
+
}
|
|
6113
6250
|
}
|
|
6114
6251
|
}
|
|
6115
6252
|
return false;
|
|
@@ -6121,7 +6258,7 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
6121
6258
|
const type = typeChecker.getTypeAtLocation(node);
|
|
6122
6259
|
for (const callSig of typeChecker.getSignaturesOfType(type, ts.SignatureKind.Call)) {
|
|
6123
6260
|
if (callSig.parameters.length >= 2 && isSymbolFromEffectRpcClientModule(callSig.parameters[1])) {
|
|
6124
|
-
rpcName = node.name
|
|
6261
|
+
rpcName = ts.idText(node.name);
|
|
6125
6262
|
callNode = node.name;
|
|
6126
6263
|
}
|
|
6127
6264
|
}
|
|
@@ -6149,7 +6286,7 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
6149
6286
|
ts.forEachChild(fileToTest, appendNodeToVisit);
|
|
6150
6287
|
while (result.length === 0 && nodeToVisit.length > 0) {
|
|
6151
6288
|
const node = nodeToVisit.shift();
|
|
6152
|
-
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")) {
|
|
6153
6290
|
const symbol3 = typeChecker.getSymbolAtLocation(node.expression.name);
|
|
6154
6291
|
if (symbol3 && isSymbolFromEffectRpcModule(symbol3)) {
|
|
6155
6292
|
const type = typeChecker.getTypeAtLocation(node);
|
|
@@ -11273,11 +11410,11 @@ var effectGenToFn = createRefactor({
|
|
|
11273
11410
|
parentNodes,
|
|
11274
11411
|
filter((_) => ts.isVariableDeclaration(_) && _.initializer ? true : false),
|
|
11275
11412
|
filter((_) => tsUtils.isNodeInRange(textRange)(_.name)),
|
|
11276
|
-
|
|
11413
|
+
map5((_) => _.initializer)
|
|
11277
11414
|
);
|
|
11278
11415
|
const maybeNode = yield* pipe(
|
|
11279
11416
|
nodesFromInitializers.concat(parentNodes),
|
|
11280
|
-
|
|
11417
|
+
map5(parseFunctionLikeReturnEffectGen),
|
|
11281
11418
|
firstSuccessOf,
|
|
11282
11419
|
option
|
|
11283
11420
|
);
|
|
@@ -11285,7 +11422,7 @@ var effectGenToFn = createRefactor({
|
|
|
11285
11422
|
const { effectModule, fnIdentifier, generatorFunction, nodeToReplace, pipeArgs } = maybeNode.value;
|
|
11286
11423
|
return {
|
|
11287
11424
|
kind: "refactor.rewrite.effect.effectGenToFn",
|
|
11288
|
-
description: fnIdentifier ? `Convert to Effect.fn("${fnIdentifier
|
|
11425
|
+
description: fnIdentifier ? `Convert to Effect.fn("${ts.idText(fnIdentifier)}")` : "Convert to Effect.fn",
|
|
11289
11426
|
apply: pipe(
|
|
11290
11427
|
gen(function* () {
|
|
11291
11428
|
const changeTracker = yield* service(ChangeTracker);
|
|
@@ -11295,7 +11432,7 @@ var effectGenToFn = createRefactor({
|
|
|
11295
11432
|
"fn"
|
|
11296
11433
|
),
|
|
11297
11434
|
void 0,
|
|
11298
|
-
[ts.factory.createStringLiteral(fnIdentifier
|
|
11435
|
+
[ts.factory.createStringLiteral(ts.idText(fnIdentifier))]
|
|
11299
11436
|
) : ts.factory.createPropertyAccessExpression(
|
|
11300
11437
|
effectModule,
|
|
11301
11438
|
"fn"
|
|
@@ -11383,6 +11520,301 @@ var functionToArrow = createRefactor({
|
|
|
11383
11520
|
})
|
|
11384
11521
|
});
|
|
11385
11522
|
|
|
11523
|
+
// src/refactors/layerMagic.ts
|
|
11524
|
+
function sortDependencies(nodes) {
|
|
11525
|
+
const result = [];
|
|
11526
|
+
const visited = /* @__PURE__ */ new Set();
|
|
11527
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
11528
|
+
const cycles = [];
|
|
11529
|
+
const providesMap = /* @__PURE__ */ new Map();
|
|
11530
|
+
Object.entries(nodes).forEach(([nodeId, node]) => {
|
|
11531
|
+
node.provides.forEach((service2) => {
|
|
11532
|
+
if (!providesMap.has(service2)) {
|
|
11533
|
+
providesMap.set(service2, []);
|
|
11534
|
+
}
|
|
11535
|
+
providesMap.get(service2).push(nodeId);
|
|
11536
|
+
});
|
|
11537
|
+
});
|
|
11538
|
+
providesMap.forEach((nodeIds) => {
|
|
11539
|
+
nodeIds.sort((a, b) => {
|
|
11540
|
+
const nodeA = nodes[a];
|
|
11541
|
+
const nodeB = nodes[b];
|
|
11542
|
+
return nodeA.requires.length - nodeB.requires.length;
|
|
11543
|
+
});
|
|
11544
|
+
});
|
|
11545
|
+
const visit = (nodeId, path) => {
|
|
11546
|
+
if (visited.has(nodeId)) {
|
|
11547
|
+
return;
|
|
11548
|
+
}
|
|
11549
|
+
if (visiting.has(nodeId)) {
|
|
11550
|
+
const cycleStart = path.indexOf(nodeId);
|
|
11551
|
+
const cycle = path.slice(cycleStart).concat([nodeId]);
|
|
11552
|
+
const cycleServices = cycle.map((id) => {
|
|
11553
|
+
const node2 = nodes[id];
|
|
11554
|
+
return `${node2.provides.join(", ")} (requires: ${node2.requires.join(", ")})`;
|
|
11555
|
+
});
|
|
11556
|
+
cycles.push(cycleServices);
|
|
11557
|
+
return;
|
|
11558
|
+
}
|
|
11559
|
+
visiting.add(nodeId);
|
|
11560
|
+
const currentPath = [...path, nodeId];
|
|
11561
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
11562
|
+
const node = nodes[nodeId];
|
|
11563
|
+
node.requires.forEach((requiredService) => {
|
|
11564
|
+
const providers = providesMap.get(requiredService) || [];
|
|
11565
|
+
providers.forEach((providerId) => {
|
|
11566
|
+
if (providerId !== nodeId) {
|
|
11567
|
+
dependencies.add(providerId);
|
|
11568
|
+
}
|
|
11569
|
+
});
|
|
11570
|
+
});
|
|
11571
|
+
dependencies.forEach((depId) => {
|
|
11572
|
+
visit(depId, currentPath);
|
|
11573
|
+
});
|
|
11574
|
+
visiting.delete(nodeId);
|
|
11575
|
+
visited.add(nodeId);
|
|
11576
|
+
result.push(node);
|
|
11577
|
+
};
|
|
11578
|
+
Object.keys(nodes).forEach((nodeId) => {
|
|
11579
|
+
if (!visited.has(nodeId)) {
|
|
11580
|
+
visit(nodeId, []);
|
|
11581
|
+
}
|
|
11582
|
+
});
|
|
11583
|
+
return {
|
|
11584
|
+
sorted: result,
|
|
11585
|
+
cycles,
|
|
11586
|
+
hasCycles: cycles.length > 0
|
|
11587
|
+
};
|
|
11588
|
+
}
|
|
11589
|
+
var layerMagic = createRefactor({
|
|
11590
|
+
name: "layerMagic",
|
|
11591
|
+
description: "Layer Magic",
|
|
11592
|
+
apply: fn("layerMagic.apply")(function* (sourceFile, textRange) {
|
|
11593
|
+
const ts = yield* service(TypeScriptApi);
|
|
11594
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
11595
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
11596
|
+
const typeParser = yield* service(TypeParser);
|
|
11597
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
11598
|
+
const layerIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
11599
|
+
sourceFile,
|
|
11600
|
+
"effect",
|
|
11601
|
+
"Layer"
|
|
11602
|
+
) || "Layer";
|
|
11603
|
+
const extractArrayLiteral = (node) => {
|
|
11604
|
+
if (ts.isArrayLiteralExpression(node)) {
|
|
11605
|
+
return pipe(
|
|
11606
|
+
all(...node.elements.map((element) => extractLayers(element, false))),
|
|
11607
|
+
map3(flatten)
|
|
11608
|
+
);
|
|
11609
|
+
}
|
|
11610
|
+
return TypeParserIssue.issue;
|
|
11611
|
+
};
|
|
11612
|
+
const extractLayerExpression = (node) => {
|
|
11613
|
+
if (ts.isExpression(node)) {
|
|
11614
|
+
return pipe(
|
|
11615
|
+
typeParser.layerType(typeChecker.getTypeAtLocation(node), node),
|
|
11616
|
+
map3((_) => [{ node, ..._ }])
|
|
11617
|
+
);
|
|
11618
|
+
}
|
|
11619
|
+
return TypeParserIssue.issue;
|
|
11620
|
+
};
|
|
11621
|
+
const extractLayerApi = (node) => {
|
|
11622
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && ts.idText(node.expression.expression) === layerIdentifier && ts.isIdentifier(node.expression.name) && ["provide", "provideMerge", "merge", "mergeAll"].map((_) => _.toLowerCase()).indexOf(
|
|
11623
|
+
ts.idText(node.expression.name).toLowerCase()
|
|
11624
|
+
) > -1) {
|
|
11625
|
+
return pipe(
|
|
11626
|
+
all(...node.arguments.map((element) => extractLayers(element, false))),
|
|
11627
|
+
map3(flatten)
|
|
11628
|
+
);
|
|
11629
|
+
}
|
|
11630
|
+
return TypeParserIssue.issue;
|
|
11631
|
+
};
|
|
11632
|
+
const extractPipeSequencing = (node) => {
|
|
11633
|
+
return pipe(
|
|
11634
|
+
typeParser.pipeCall(node),
|
|
11635
|
+
flatMap((_) => {
|
|
11636
|
+
return all(...[_.subject, ..._.args].map((element) => extractLayers(element, true)));
|
|
11637
|
+
}),
|
|
11638
|
+
map3(flatten)
|
|
11639
|
+
);
|
|
11640
|
+
};
|
|
11641
|
+
const extractLayers = cachedBy(
|
|
11642
|
+
fn("layerMagic.apply.extractLayerArray")(function* (node, _inPipeContext) {
|
|
11643
|
+
return yield* pipe(
|
|
11644
|
+
extractArrayLiteral(node),
|
|
11645
|
+
orElse2(() => extractLayerApi(node)),
|
|
11646
|
+
_inPipeContext ? (x) => x : orElse2(() => extractPipeSequencing(node)),
|
|
11647
|
+
orElse2(() => extractLayerExpression(node))
|
|
11648
|
+
);
|
|
11649
|
+
}),
|
|
11650
|
+
"layerMagic.apply.extractLayerArray",
|
|
11651
|
+
(node) => node
|
|
11652
|
+
);
|
|
11653
|
+
const adjustedNode = (node) => {
|
|
11654
|
+
if (ts.isIdentifier(node) && ts.isVariableDeclaration(node.parent) && node.parent.initializer) {
|
|
11655
|
+
return adjustedNode(node.parent.initializer);
|
|
11656
|
+
}
|
|
11657
|
+
if (ts.isIdentifier(node) && ts.isPropertyDeclaration(node.parent) && node.parent.initializer) {
|
|
11658
|
+
return adjustedNode(node.parent.initializer);
|
|
11659
|
+
}
|
|
11660
|
+
return node;
|
|
11661
|
+
};
|
|
11662
|
+
const computeAsAnyAsLayerRefactor = (node) => {
|
|
11663
|
+
const atLocation = adjustedNode(node);
|
|
11664
|
+
return pipe(
|
|
11665
|
+
extractLayers(atLocation, false),
|
|
11666
|
+
flatMap(
|
|
11667
|
+
(extractedLayer) => extractedLayer.length < 1 ? TypeParserIssue.issue : succeed(extractedLayer)
|
|
11668
|
+
),
|
|
11669
|
+
map3((extractedLayers) => ({
|
|
11670
|
+
kind: "refactor.rewrite.effect.layerMagicPrepare",
|
|
11671
|
+
description: "Prepare layers for automatic composition",
|
|
11672
|
+
apply: pipe(
|
|
11673
|
+
gen(function* () {
|
|
11674
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
11675
|
+
const memory = /* @__PURE__ */ new Map();
|
|
11676
|
+
for (const layer of extractedLayers) {
|
|
11677
|
+
yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
11678
|
+
memory,
|
|
11679
|
+
layer.ROut,
|
|
11680
|
+
(_) => succeed((_.flags & ts.TypeFlags.Never) !== 0)
|
|
11681
|
+
);
|
|
11682
|
+
}
|
|
11683
|
+
const typeReferences = pipe(
|
|
11684
|
+
fromIterable(memory.values()),
|
|
11685
|
+
sort(typeCheckerUtils.deterministicTypeOrder),
|
|
11686
|
+
map5((_) => typeChecker.typeToTypeNode(_, void 0, ts.NodeBuilderFlags.NoTruncation)),
|
|
11687
|
+
filter((_) => !!_)
|
|
11688
|
+
);
|
|
11689
|
+
const newDeclaration = ts.factory.createAsExpression(
|
|
11690
|
+
ts.factory.createAsExpression(
|
|
11691
|
+
ts.factory.createArrayLiteralExpression(extractedLayers.map((_) => _.node)),
|
|
11692
|
+
ts.factory.createTypeReferenceNode("any")
|
|
11693
|
+
),
|
|
11694
|
+
ts.factory.createTypeReferenceNode(
|
|
11695
|
+
ts.factory.createQualifiedName(ts.factory.createIdentifier(layerIdentifier), "Layer"),
|
|
11696
|
+
typeReferences.length === 0 ? [
|
|
11697
|
+
ts.factory.createTypeReferenceNode("never")
|
|
11698
|
+
] : [ts.factory.createUnionTypeNode(typeReferences)]
|
|
11699
|
+
)
|
|
11700
|
+
);
|
|
11701
|
+
changeTracker.replaceNode(sourceFile, atLocation, newDeclaration, {
|
|
11702
|
+
leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll,
|
|
11703
|
+
trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Exclude
|
|
11704
|
+
});
|
|
11705
|
+
}),
|
|
11706
|
+
provideService(TypeScriptApi, ts)
|
|
11707
|
+
)
|
|
11708
|
+
}))
|
|
11709
|
+
);
|
|
11710
|
+
};
|
|
11711
|
+
const parseAsAnyAsLayer = (node) => {
|
|
11712
|
+
if (ts.isAsExpression(node) && ts.isTypeReferenceNode(node.type)) {
|
|
11713
|
+
const expression = node.expression;
|
|
11714
|
+
if (ts.isAsExpression(expression) && expression.type.kind === ts.SyntaxKind.AnyKeyword) {
|
|
11715
|
+
return pipe(
|
|
11716
|
+
typeParser.layerType(typeChecker.getTypeAtLocation(node.type), node.type),
|
|
11717
|
+
map3((_) => ({ node, ..._, castedStructure: expression.expression }))
|
|
11718
|
+
);
|
|
11719
|
+
}
|
|
11720
|
+
}
|
|
11721
|
+
return TypeParserIssue.issue;
|
|
11722
|
+
};
|
|
11723
|
+
const computeBuildRefactor = (node) => {
|
|
11724
|
+
const atLocation = adjustedNode(node);
|
|
11725
|
+
return pipe(
|
|
11726
|
+
parseAsAnyAsLayer(atLocation),
|
|
11727
|
+
flatMap(
|
|
11728
|
+
(_targetLayer) => pipe(
|
|
11729
|
+
extractArrayLiteral(_targetLayer.castedStructure),
|
|
11730
|
+
orElse2(() => extractLayers(_targetLayer.castedStructure, false)),
|
|
11731
|
+
flatMap(
|
|
11732
|
+
(extractedLayer) => extractedLayer.length < 1 ? TypeParserIssue.issue : succeed(extractedLayer)
|
|
11733
|
+
),
|
|
11734
|
+
map3((extractedLayers) => ({
|
|
11735
|
+
kind: "refactor.rewrite.effect.layerMagicBuild",
|
|
11736
|
+
description: "Compose layers automatically with target output services",
|
|
11737
|
+
apply: gen(function* () {
|
|
11738
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
11739
|
+
const memory = /* @__PURE__ */ new Map();
|
|
11740
|
+
const { allIndexes: outputIndexes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
11741
|
+
memory,
|
|
11742
|
+
_targetLayer.ROut,
|
|
11743
|
+
(_) => succeed((_.flags & ts.TypeFlags.Never) !== 0)
|
|
11744
|
+
);
|
|
11745
|
+
const nodes = {};
|
|
11746
|
+
for (let i = 0; i < extractedLayers.length; i++) {
|
|
11747
|
+
const layer = extractedLayers[i];
|
|
11748
|
+
const { allIndexes: providedIndexes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
11749
|
+
memory,
|
|
11750
|
+
layer.ROut,
|
|
11751
|
+
(_) => succeed((_.flags & ts.TypeFlags.Never) !== 0)
|
|
11752
|
+
);
|
|
11753
|
+
const { allIndexes: requiredIndexes } = yield* typeCheckerUtils.appendToUniqueTypesMap(
|
|
11754
|
+
memory,
|
|
11755
|
+
layer.RIn,
|
|
11756
|
+
(_) => succeed((_.flags & ts.TypeFlags.Never) !== 0)
|
|
11757
|
+
);
|
|
11758
|
+
nodes[`node_${i}`] = {
|
|
11759
|
+
provides: providedIndexes.filter((_) => requiredIndexes.indexOf(_) === -1),
|
|
11760
|
+
// only provide indexes that are not required
|
|
11761
|
+
requires: requiredIndexes,
|
|
11762
|
+
node: layer.node
|
|
11763
|
+
};
|
|
11764
|
+
}
|
|
11765
|
+
const sortResult = sortDependencies(nodes);
|
|
11766
|
+
const sortedNodes = sortResult.sorted.reverse();
|
|
11767
|
+
const missingOutput = new Set(outputIndexes);
|
|
11768
|
+
const missingInternal = /* @__PURE__ */ new Set();
|
|
11769
|
+
const outputEntry = [];
|
|
11770
|
+
for (const graphNode of sortedNodes) {
|
|
11771
|
+
const mergeOutput = graphNode.provides.filter((_) => missingOutput.has(_));
|
|
11772
|
+
const provideInternal = graphNode.provides.filter((_) => missingInternal.has(_));
|
|
11773
|
+
graphNode.requires.forEach((_) => missingInternal.add(_));
|
|
11774
|
+
mergeOutput.forEach((_) => missingOutput.delete(_));
|
|
11775
|
+
outputEntry.push({
|
|
11776
|
+
merges: mergeOutput.length > 0,
|
|
11777
|
+
provides: provideInternal.length > 0,
|
|
11778
|
+
node: graphNode.node
|
|
11779
|
+
});
|
|
11780
|
+
}
|
|
11781
|
+
const newDeclaration = ts.factory.createCallExpression(
|
|
11782
|
+
ts.factory.createPropertyAccessExpression(
|
|
11783
|
+
outputEntry[0].node,
|
|
11784
|
+
"pipe"
|
|
11785
|
+
),
|
|
11786
|
+
[],
|
|
11787
|
+
outputEntry.slice(1).map(
|
|
11788
|
+
(_) => ts.factory.createCallExpression(
|
|
11789
|
+
ts.factory.createPropertyAccessExpression(
|
|
11790
|
+
ts.factory.createIdentifier(layerIdentifier),
|
|
11791
|
+
_.merges && _.provides ? "provideMerge" : _.merges ? "merge" : "provide"
|
|
11792
|
+
),
|
|
11793
|
+
[],
|
|
11794
|
+
[_.node]
|
|
11795
|
+
)
|
|
11796
|
+
)
|
|
11797
|
+
);
|
|
11798
|
+
changeTracker.replaceNode(sourceFile, atLocation, newDeclaration, {
|
|
11799
|
+
leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll,
|
|
11800
|
+
trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Exclude
|
|
11801
|
+
});
|
|
11802
|
+
})
|
|
11803
|
+
}))
|
|
11804
|
+
)
|
|
11805
|
+
)
|
|
11806
|
+
);
|
|
11807
|
+
};
|
|
11808
|
+
const parentNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange);
|
|
11809
|
+
if (parentNodes.length === 0) return yield* fail(new RefactorNotApplicableError());
|
|
11810
|
+
return yield* pipe(
|
|
11811
|
+
firstSuccessOf(parentNodes.map(computeBuildRefactor)),
|
|
11812
|
+
orElse2(() => firstSuccessOf(parentNodes.map(computeAsAnyAsLayerRefactor))),
|
|
11813
|
+
orElse2(() => fail(new RefactorNotApplicableError()))
|
|
11814
|
+
);
|
|
11815
|
+
})
|
|
11816
|
+
});
|
|
11817
|
+
|
|
11386
11818
|
// src/refactors/makeSchemaOpaque.ts
|
|
11387
11819
|
var _findSchemaVariableDeclaration = fn(
|
|
11388
11820
|
"makeSchemaOpaque._findSchemaVariableDeclaration"
|
|
@@ -11416,7 +11848,7 @@ var _findSchemaVariableDeclaration = fn(
|
|
|
11416
11848
|
);
|
|
11417
11849
|
return yield* pipe(
|
|
11418
11850
|
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
11419
|
-
|
|
11851
|
+
map5(findSchema),
|
|
11420
11852
|
firstSuccessOf,
|
|
11421
11853
|
option
|
|
11422
11854
|
);
|
|
@@ -11518,15 +11950,15 @@ var makeSchemaOpaque = createRefactor({
|
|
|
11518
11950
|
"effect",
|
|
11519
11951
|
"Schema"
|
|
11520
11952
|
) || "Schema";
|
|
11521
|
-
const newIdentifier = ts.factory.createIdentifier(identifier
|
|
11953
|
+
const newIdentifier = ts.factory.createIdentifier(ts.idText(identifier) + "_");
|
|
11522
11954
|
const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(
|
|
11523
11955
|
effectSchemaName,
|
|
11524
|
-
newIdentifier
|
|
11956
|
+
ts.idText(newIdentifier),
|
|
11525
11957
|
types.A,
|
|
11526
|
-
identifier
|
|
11958
|
+
ts.idText(identifier),
|
|
11527
11959
|
types.I,
|
|
11528
|
-
identifier
|
|
11529
|
-
identifier
|
|
11960
|
+
ts.idText(identifier) + "Encoded",
|
|
11961
|
+
ts.idText(identifier) + "Context"
|
|
11530
11962
|
);
|
|
11531
11963
|
changeTracker.replaceNode(
|
|
11532
11964
|
sourceFile,
|
|
@@ -11551,10 +11983,10 @@ var makeSchemaOpaque = createRefactor({
|
|
|
11551
11983
|
variableStatement.modifiers,
|
|
11552
11984
|
ts.factory.createVariableDeclarationList(
|
|
11553
11985
|
[ts.factory.createVariableDeclaration(
|
|
11554
|
-
identifier
|
|
11986
|
+
ts.idText(identifier),
|
|
11555
11987
|
void 0,
|
|
11556
11988
|
newSchemaType,
|
|
11557
|
-
ts.factory.createIdentifier(newIdentifier
|
|
11989
|
+
ts.factory.createIdentifier(ts.idText(newIdentifier))
|
|
11558
11990
|
)],
|
|
11559
11991
|
variableDeclarationList.flags
|
|
11560
11992
|
)
|
|
@@ -11589,19 +12021,19 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
11589
12021
|
"effect",
|
|
11590
12022
|
"Schema"
|
|
11591
12023
|
) || "Schema";
|
|
11592
|
-
const newIdentifier = ts.factory.createIdentifier(identifier
|
|
12024
|
+
const newIdentifier = ts.factory.createIdentifier(ts.idText(identifier) + "_");
|
|
11593
12025
|
const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(
|
|
11594
12026
|
effectSchemaName,
|
|
11595
|
-
newIdentifier
|
|
12027
|
+
ts.idText(newIdentifier),
|
|
11596
12028
|
types.A,
|
|
11597
|
-
identifier
|
|
12029
|
+
ts.idText(identifier),
|
|
11598
12030
|
types.I,
|
|
11599
12031
|
"Encoded",
|
|
11600
12032
|
"Context"
|
|
11601
12033
|
);
|
|
11602
12034
|
const namespace = ts.factory.createModuleDeclaration(
|
|
11603
12035
|
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
11604
|
-
ts.factory.createIdentifier(identifier
|
|
12036
|
+
ts.factory.createIdentifier(ts.idText(identifier)),
|
|
11605
12037
|
ts.factory.createModuleBlock([
|
|
11606
12038
|
encodedType,
|
|
11607
12039
|
contextType
|
|
@@ -11615,6 +12047,7 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
11615
12047
|
);
|
|
11616
12048
|
changeTracker.insertNodeAfter(sourceFile, variableStatement, opaqueType);
|
|
11617
12049
|
changeTracker.insertNodeAfter(sourceFile, variableStatement, namespace);
|
|
12050
|
+
const namespaceName = ts.isStringLiteral(namespace.name) ? namespace.name.text : ts.idText(namespace.name);
|
|
11618
12051
|
const newSchemaType = ts.factory.createTypeReferenceNode(
|
|
11619
12052
|
ts.factory.createQualifiedName(
|
|
11620
12053
|
ts.factory.createIdentifier(effectSchemaName),
|
|
@@ -11624,13 +12057,15 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
11624
12057
|
ts.factory.createTypeReferenceNode(opaqueType.name),
|
|
11625
12058
|
ts.factory.createTypeReferenceNode(
|
|
11626
12059
|
ts.factory.createQualifiedName(
|
|
11627
|
-
ts.factory.createIdentifier(
|
|
11628
|
-
|
|
12060
|
+
ts.factory.createIdentifier(
|
|
12061
|
+
namespaceName
|
|
12062
|
+
),
|
|
12063
|
+
ts.idText(encodedType.name)
|
|
11629
12064
|
)
|
|
11630
12065
|
),
|
|
11631
12066
|
ts.factory.createTypeReferenceNode(ts.factory.createQualifiedName(
|
|
11632
|
-
ts.factory.createIdentifier(
|
|
11633
|
-
contextType.name
|
|
12067
|
+
ts.factory.createIdentifier(namespaceName),
|
|
12068
|
+
ts.idText(contextType.name)
|
|
11634
12069
|
))
|
|
11635
12070
|
]
|
|
11636
12071
|
);
|
|
@@ -11638,10 +12073,10 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
11638
12073
|
variableStatement.modifiers,
|
|
11639
12074
|
ts.factory.createVariableDeclarationList(
|
|
11640
12075
|
[ts.factory.createVariableDeclaration(
|
|
11641
|
-
identifier
|
|
12076
|
+
ts.idText(identifier),
|
|
11642
12077
|
void 0,
|
|
11643
12078
|
newSchemaType,
|
|
11644
|
-
ts.factory.createIdentifier(newIdentifier
|
|
12079
|
+
ts.factory.createIdentifier(ts.idText(newIdentifier))
|
|
11645
12080
|
)],
|
|
11646
12081
|
variableDeclarationList.flags
|
|
11647
12082
|
)
|
|
@@ -11667,7 +12102,7 @@ var pipeableToDatafirst = createRefactor({
|
|
|
11667
12102
|
if (!ts.isCallExpression(node2)) return false;
|
|
11668
12103
|
const expression = node2.expression;
|
|
11669
12104
|
if (!ts.isIdentifier(expression)) return false;
|
|
11670
|
-
if (expression
|
|
12105
|
+
if (ts.idText(expression) !== "pipe") return false;
|
|
11671
12106
|
return true;
|
|
11672
12107
|
}
|
|
11673
12108
|
function asDataFirstExpression(node2, self) {
|
|
@@ -11699,7 +12134,7 @@ var pipeableToDatafirst = createRefactor({
|
|
|
11699
12134
|
filter(
|
|
11700
12135
|
(node2) => node2.arguments.length > 0
|
|
11701
12136
|
),
|
|
11702
|
-
|
|
12137
|
+
map5((node2) => {
|
|
11703
12138
|
let newNode2 = node2.arguments[0];
|
|
11704
12139
|
let didSomething = false;
|
|
11705
12140
|
for (let i = 1; i < node2.arguments.length; i++) {
|
|
@@ -11726,7 +12161,7 @@ var pipeableToDatafirst = createRefactor({
|
|
|
11726
12161
|
return didSomething ? some2([node2, newNode2]) : none2();
|
|
11727
12162
|
}),
|
|
11728
12163
|
filter(isSome2),
|
|
11729
|
-
|
|
12164
|
+
map5((_) => _.value),
|
|
11730
12165
|
head
|
|
11731
12166
|
);
|
|
11732
12167
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -11876,6 +12311,7 @@ var toggleReturnTypeAnnotation = createRefactor({
|
|
|
11876
12311
|
const ts = yield* service(TypeScriptApi);
|
|
11877
12312
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
11878
12313
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
12314
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
11879
12315
|
function addReturnTypeAnnotation(sourceFile2, changeTracker, declaration, typeNode) {
|
|
11880
12316
|
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile2);
|
|
11881
12317
|
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
@@ -11923,10 +12359,10 @@ var toggleReturnTypeAnnotation = createRefactor({
|
|
|
11923
12359
|
)
|
|
11924
12360
|
};
|
|
11925
12361
|
}
|
|
11926
|
-
const returnType =
|
|
11927
|
-
if (
|
|
12362
|
+
const returnType = typeCheckerUtils.getInferredReturnType(node);
|
|
12363
|
+
if (!returnType) return yield* fail(new RefactorNotApplicableError());
|
|
11928
12364
|
const returnTypeNode = typeChecker.typeToTypeNode(
|
|
11929
|
-
returnType
|
|
12365
|
+
returnType,
|
|
11930
12366
|
node,
|
|
11931
12367
|
ts.NodeBuilderFlags.NoTruncation
|
|
11932
12368
|
);
|
|
@@ -12071,12 +12507,12 @@ var makeSchemaGenContext = fn("SchemaGen.makeSchemaGenContext")(function* (sourc
|
|
|
12071
12507
|
),
|
|
12072
12508
|
entityNameToDataTypeName: (name) => {
|
|
12073
12509
|
if (ts.isIdentifier(name)) {
|
|
12074
|
-
switch (name
|
|
12510
|
+
switch (ts.idText(name)) {
|
|
12075
12511
|
case "Date":
|
|
12076
12512
|
case "Pick":
|
|
12077
12513
|
case "Omit":
|
|
12078
12514
|
case "Record":
|
|
12079
|
-
return some2(name
|
|
12515
|
+
return some2(ts.idText(name));
|
|
12080
12516
|
case "ReadonlyArray":
|
|
12081
12517
|
case "Array":
|
|
12082
12518
|
return some2("Array");
|
|
@@ -12085,7 +12521,7 @@ var makeSchemaGenContext = fn("SchemaGen.makeSchemaGenContext")(function* (sourc
|
|
|
12085
12521
|
}
|
|
12086
12522
|
if (!ts.isIdentifier(name.left)) return none2();
|
|
12087
12523
|
for (const moduleName in moduleToImportedName) {
|
|
12088
|
-
if (name.left
|
|
12524
|
+
if (ts.idText(name.left) === moduleToImportedName[moduleName] && ts.idText(name.right) === moduleName) {
|
|
12089
12525
|
return some2(moduleName);
|
|
12090
12526
|
}
|
|
12091
12527
|
}
|
|
@@ -12099,11 +12535,11 @@ var typeEntityNameToNode = fn(
|
|
|
12099
12535
|
)(
|
|
12100
12536
|
function* (entityName) {
|
|
12101
12537
|
const { ts } = yield* service(SchemaGenContext);
|
|
12102
|
-
if (ts.isIdentifier(entityName)) return ts.factory.createIdentifier(entityName
|
|
12538
|
+
if (ts.isIdentifier(entityName)) return ts.factory.createIdentifier(ts.idText(entityName));
|
|
12103
12539
|
const left3 = yield* typeEntityNameToNode(entityName.left);
|
|
12104
12540
|
return ts.factory.createPropertyAccessExpression(
|
|
12105
12541
|
left3,
|
|
12106
|
-
ts.factory.createIdentifier(entityName.right
|
|
12542
|
+
ts.factory.createIdentifier(ts.idText(entityName.right))
|
|
12107
12543
|
);
|
|
12108
12544
|
}
|
|
12109
12545
|
);
|
|
@@ -12348,13 +12784,13 @@ var processInterfaceDeclaration = fn("SchemaGen.processInterfaceDeclaration")(
|
|
|
12348
12784
|
);
|
|
12349
12785
|
const { properties, records } = yield* processMembers(node.members, false);
|
|
12350
12786
|
if (preferClass && records.length === 0) {
|
|
12351
|
-
return yield* createExportSchemaClassDeclaration(node.name
|
|
12787
|
+
return yield* createExportSchemaClassDeclaration(ts.idText(node.name), properties);
|
|
12352
12788
|
}
|
|
12353
12789
|
const schemaStruct = createApiCall(
|
|
12354
12790
|
"Struct",
|
|
12355
12791
|
[ts.factory.createObjectLiteralExpression(properties, true)].concat(records)
|
|
12356
12792
|
);
|
|
12357
|
-
return yield* createExportVariableDeclaration(node.name
|
|
12793
|
+
return yield* createExportVariableDeclaration(ts.idText(node.name), schemaStruct);
|
|
12358
12794
|
}
|
|
12359
12795
|
);
|
|
12360
12796
|
var processTypeAliasDeclaration = fn("SchemaGen.processInterfaceDeclaration")(
|
|
@@ -12366,11 +12802,11 @@ var processTypeAliasDeclaration = fn("SchemaGen.processInterfaceDeclaration")(
|
|
|
12366
12802
|
if (preferClass && ts.isTypeLiteralNode(node.type)) {
|
|
12367
12803
|
const { properties, records } = yield* processMembers(node.type.members, false);
|
|
12368
12804
|
if (records.length === 0) {
|
|
12369
|
-
return yield* createExportSchemaClassDeclaration(node.name
|
|
12805
|
+
return yield* createExportSchemaClassDeclaration(ts.idText(node.name), properties);
|
|
12370
12806
|
}
|
|
12371
12807
|
}
|
|
12372
12808
|
const effectSchema = yield* processNode(node.type, false);
|
|
12373
|
-
return yield* createExportVariableDeclaration(node.name
|
|
12809
|
+
return yield* createExportVariableDeclaration(ts.idText(node.name), effectSchema);
|
|
12374
12810
|
}
|
|
12375
12811
|
);
|
|
12376
12812
|
var createExportVariableDeclaration = fn("SchemaGen.createExportVariableDeclaration")(
|
|
@@ -12475,6 +12911,7 @@ var typeToEffectSchema = createRefactor({
|
|
|
12475
12911
|
const ts = yield* service(TypeScriptApi);
|
|
12476
12912
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
12477
12913
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
12914
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
12478
12915
|
const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
|
|
12479
12916
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
12480
12917
|
const node = maybeNode.value;
|
|
@@ -12485,7 +12922,8 @@ var typeToEffectSchema = createRefactor({
|
|
|
12485
12922
|
applyAtNode(sourceFile, node, false),
|
|
12486
12923
|
provideService(TypeCheckerApi, typeChecker),
|
|
12487
12924
|
provideService(TypeScriptUtils, tsUtils),
|
|
12488
|
-
provideService(TypeScriptApi, ts)
|
|
12925
|
+
provideService(TypeScriptApi, ts),
|
|
12926
|
+
provideService(TypeCheckerUtils, typeCheckerUtils)
|
|
12489
12927
|
)
|
|
12490
12928
|
};
|
|
12491
12929
|
})
|
|
@@ -12499,6 +12937,7 @@ var typeToEffectSchemaClass = createRefactor({
|
|
|
12499
12937
|
const ts = yield* service(TypeScriptApi);
|
|
12500
12938
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
12501
12939
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
12940
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
12502
12941
|
const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
|
|
12503
12942
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
12504
12943
|
const node = maybeNode.value;
|
|
@@ -12509,7 +12948,8 @@ var typeToEffectSchemaClass = createRefactor({
|
|
|
12509
12948
|
applyAtNode(sourceFile, node, true),
|
|
12510
12949
|
provideService(TypeCheckerApi, typeChecker),
|
|
12511
12950
|
provideService(TypeScriptUtils, tsUtils),
|
|
12512
|
-
provideService(TypeScriptApi, ts)
|
|
12951
|
+
provideService(TypeScriptApi, ts),
|
|
12952
|
+
provideService(TypeCheckerUtils, typeCheckerUtils)
|
|
12513
12953
|
)
|
|
12514
12954
|
};
|
|
12515
12955
|
})
|
|
@@ -12536,7 +12976,7 @@ var wrapWithEffectGen = createRefactor({
|
|
|
12536
12976
|
);
|
|
12537
12977
|
const maybeNode = yield* pipe(
|
|
12538
12978
|
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
12539
|
-
|
|
12979
|
+
map5(findEffectToWrap),
|
|
12540
12980
|
firstSuccessOf,
|
|
12541
12981
|
option
|
|
12542
12982
|
);
|
|
@@ -12587,6 +13027,7 @@ var wrapWithPipe = createRefactor({
|
|
|
12587
13027
|
|
|
12588
13028
|
// src/refactors.ts
|
|
12589
13029
|
var refactors = [
|
|
13030
|
+
layerMagic,
|
|
12590
13031
|
asyncAwaitToGen,
|
|
12591
13032
|
asyncAwaitToGenTryPromise,
|
|
12592
13033
|
asyncAwaitToFn,
|
|
@@ -12608,6 +13049,57 @@ var refactors = [
|
|
|
12608
13049
|
writeTagClassAccessors
|
|
12609
13050
|
];
|
|
12610
13051
|
|
|
13052
|
+
// src/renames/keyStrings.ts
|
|
13053
|
+
var renameKeyStrings = (sourceFile, position, _findInStrings, _findInComments, _preferences, renameLocations) => gen(function* () {
|
|
13054
|
+
const ts = yield* service(TypeScriptApi);
|
|
13055
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
13056
|
+
const typeParser = yield* service(TypeParser);
|
|
13057
|
+
const additionalPositions = [];
|
|
13058
|
+
const node = tsUtils.findNodeAtPositionIncludingTrivia(sourceFile, position);
|
|
13059
|
+
if (node && ts.isIdentifier(node)) {
|
|
13060
|
+
const textToReplace = ts.idText(node);
|
|
13061
|
+
const parentClass = node.parent;
|
|
13062
|
+
if (ts.isClassDeclaration(parentClass) && parentClass.name === node) {
|
|
13063
|
+
const baseIdentifier = yield* pipe(
|
|
13064
|
+
map3(typeParser.extendsContextTag(parentClass), (_) => [_.keyStringLiteral]),
|
|
13065
|
+
orElse2(() => map3(typeParser.extendsEffectService(parentClass), (_) => [_.keyStringLiteral])),
|
|
13066
|
+
orElse2(
|
|
13067
|
+
() => map3(typeParser.extendsSchemaTaggedClass(parentClass), (_) => [_.keyStringLiteral, _.tagStringLiteral])
|
|
13068
|
+
),
|
|
13069
|
+
orElse2(
|
|
13070
|
+
() => map3(typeParser.extendsSchemaTaggedError(parentClass), (_) => [_.keyStringLiteral, _.tagStringLiteral])
|
|
13071
|
+
),
|
|
13072
|
+
orElse2(() => map3(typeParser.extendsDataTaggedError(parentClass), (_) => [_.keyStringLiteral])),
|
|
13073
|
+
orElse2(() => map3(typeParser.extendsDataTaggedClass(parentClass), (_) => [_.keyStringLiteral])),
|
|
13074
|
+
orElse2(
|
|
13075
|
+
() => map3(
|
|
13076
|
+
typeParser.extendsSchemaTaggedRequest(parentClass),
|
|
13077
|
+
(_) => [_.keyStringLiteral, _.tagStringLiteral]
|
|
13078
|
+
)
|
|
13079
|
+
),
|
|
13080
|
+
option
|
|
13081
|
+
);
|
|
13082
|
+
if (isSome2(baseIdentifier)) {
|
|
13083
|
+
for (const keyStringLiteral of baseIdentifier.value) {
|
|
13084
|
+
if (!keyStringLiteral) continue;
|
|
13085
|
+
const baseText = sourceFile.text.slice(keyStringLiteral.pos, keyStringLiteral.end);
|
|
13086
|
+
const lastIndex = baseText.lastIndexOf(textToReplace);
|
|
13087
|
+
if (lastIndex !== -1) {
|
|
13088
|
+
additionalPositions.push({
|
|
13089
|
+
fileName: sourceFile.fileName,
|
|
13090
|
+
textSpan: {
|
|
13091
|
+
start: keyStringLiteral.pos + lastIndex,
|
|
13092
|
+
length: textToReplace.length
|
|
13093
|
+
}
|
|
13094
|
+
});
|
|
13095
|
+
}
|
|
13096
|
+
}
|
|
13097
|
+
}
|
|
13098
|
+
}
|
|
13099
|
+
}
|
|
13100
|
+
return additionalPositions.length === 0 ? renameLocations : additionalPositions.concat(renameLocations || []);
|
|
13101
|
+
});
|
|
13102
|
+
|
|
12611
13103
|
// src/index.ts
|
|
12612
13104
|
var LSP_INJECTED_URI = "@effect/language-service/injected";
|
|
12613
13105
|
var init = (modules) => {
|
|
@@ -12940,6 +13432,37 @@ var init = (modules) => {
|
|
|
12940
13432
|
}
|
|
12941
13433
|
return applicableInlayHints;
|
|
12942
13434
|
};
|
|
13435
|
+
proxy.findRenameLocations = (fileName, position, findInStrings, findInComments, userPreferences, ...args2) => {
|
|
13436
|
+
const applicableRenameInfo = languageService.findRenameLocations(
|
|
13437
|
+
fileName,
|
|
13438
|
+
position,
|
|
13439
|
+
findInStrings,
|
|
13440
|
+
findInComments,
|
|
13441
|
+
userPreferences,
|
|
13442
|
+
...args2
|
|
13443
|
+
);
|
|
13444
|
+
if (languageServicePluginOptions.renames) {
|
|
13445
|
+
const program = languageService.getProgram();
|
|
13446
|
+
if (program) {
|
|
13447
|
+
const sourceFile = program.getSourceFile(fileName);
|
|
13448
|
+
if (sourceFile) {
|
|
13449
|
+
return pipe(
|
|
13450
|
+
renameKeyStrings(
|
|
13451
|
+
sourceFile,
|
|
13452
|
+
position,
|
|
13453
|
+
findInStrings,
|
|
13454
|
+
findInComments,
|
|
13455
|
+
userPreferences,
|
|
13456
|
+
applicableRenameInfo
|
|
13457
|
+
),
|
|
13458
|
+
runNano(program),
|
|
13459
|
+
getOrElse(() => applicableRenameInfo)
|
|
13460
|
+
);
|
|
13461
|
+
}
|
|
13462
|
+
}
|
|
13463
|
+
}
|
|
13464
|
+
return applicableRenameInfo;
|
|
13465
|
+
};
|
|
12943
13466
|
return proxy;
|
|
12944
13467
|
}
|
|
12945
13468
|
return { create, onConfigurationChanged };
|