@effect/language-service 0.28.3 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/cli.js +1081 -673
- package/cli.js.map +1 -1
- package/index.js +1352 -1250
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +1083 -679
- package/transform.js.map +1 -1
package/cli.js
CHANGED
|
@@ -16666,8 +16666,8 @@ var go = (ast, isDecoding) => {
|
|
|
16666
16666
|
return (i, options3) => handleForbidden(flatMap10(mapError3(from(i, options3), (e) => new Transformation2(ast, i, isDecoding ? "Encoded" : "Type", e)), (a) => flatMap10(mapError3(transform3(a, options3 ?? defaultParseOption, ast, i), (e) => new Transformation2(ast, i, "Transformation", e)), (i2) => mapError3(to(i2, options3), (e) => new Transformation2(ast, i, isDecoding ? "Type" : "Encoded", e)))), ast, i, options3);
|
|
16667
16667
|
}
|
|
16668
16668
|
case "Declaration": {
|
|
16669
|
-
const
|
|
16670
|
-
return (i, options3) => handleForbidden(
|
|
16669
|
+
const parse6 = isDecoding ? ast.decodeUnknown(...ast.typeParameters) : ast.encodeUnknown(...ast.typeParameters);
|
|
16670
|
+
return (i, options3) => handleForbidden(parse6(i, options3 ?? defaultParseOption, ast), ast, i, options3);
|
|
16671
16671
|
}
|
|
16672
16672
|
case "Literal":
|
|
16673
16673
|
return fromRefinement(ast, (u) => u === ast.literal);
|
|
@@ -24040,7 +24040,7 @@ var validateInternal = (self, value5, config2) => {
|
|
|
24040
24040
|
}
|
|
24041
24041
|
}
|
|
24042
24042
|
};
|
|
24043
|
-
var attempt = (option5, typeName,
|
|
24043
|
+
var attempt = (option5, typeName, parse6) => orElseFail2(option5, () => `${typeName} options do not have a default value`).pipe(flatMap9((value5) => orElseFail2(parse6(value5), () => `'${value5}' is not a ${typeName}`)));
|
|
24044
24044
|
var validatePathExistence = (path2, shouldPathExist, pathExists) => {
|
|
24045
24045
|
if (shouldPathExist === "no" && pathExists) {
|
|
24046
24046
|
return fail7(`Path '${path2}' must not exist`);
|
|
@@ -26628,7 +26628,7 @@ var parseConfig = (config2) => {
|
|
|
26628
26628
|
let argsIndex = 0;
|
|
26629
26629
|
const options3 = [];
|
|
26630
26630
|
let optionsIndex = 0;
|
|
26631
|
-
function
|
|
26631
|
+
function parse6(config3) {
|
|
26632
26632
|
const tree = {};
|
|
26633
26633
|
for (const key in config3) {
|
|
26634
26634
|
tree[key] = parseValue(config3[key]);
|
|
@@ -26656,14 +26656,14 @@ var parseConfig = (config2) => {
|
|
|
26656
26656
|
} else {
|
|
26657
26657
|
return {
|
|
26658
26658
|
_tag: "ParsedConfig",
|
|
26659
|
-
tree:
|
|
26659
|
+
tree: parse6(value5)
|
|
26660
26660
|
};
|
|
26661
26661
|
}
|
|
26662
26662
|
}
|
|
26663
26663
|
return {
|
|
26664
26664
|
args: args3,
|
|
26665
26665
|
options: options3,
|
|
26666
|
-
tree:
|
|
26666
|
+
tree: parse6(config2)
|
|
26667
26667
|
};
|
|
26668
26668
|
};
|
|
26669
26669
|
var reconstructConfigTree = (tree, args3, options3) => {
|
|
@@ -28794,44 +28794,50 @@ function parse4(config2) {
|
|
|
28794
28794
|
var TypeScriptApi = Tag4("TypeScriptApi");
|
|
28795
28795
|
var TypeScriptProgram = Tag4("TypeScriptProgram");
|
|
28796
28796
|
var ChangeTracker = Tag4("ChangeTracker");
|
|
28797
|
-
|
|
28798
|
-
|
|
28799
|
-
|
|
28800
|
-
|
|
28801
|
-
|
|
28802
|
-
|
|
28803
|
-
|
|
28804
|
-
|
|
28805
|
-
|
|
28806
|
-
|
|
28807
|
-
|
|
28808
|
-
|
|
28809
|
-
|
|
28810
|
-
|
|
28811
|
-
|
|
28812
|
-
|
|
28813
|
-
|
|
28814
|
-
|
|
28815
|
-
|
|
28816
|
-
|
|
28817
|
-
|
|
28818
|
-
|
|
28819
|
-
|
|
28820
|
-
|
|
28821
|
-
|
|
28822
|
-
|
|
28823
|
-
|
|
28824
|
-
|
|
28825
|
-
|
|
28826
|
-
|
|
28827
|
-
|
|
28828
|
-
|
|
28829
|
-
|
|
28830
|
-
|
|
28831
|
-
|
|
28832
|
-
|
|
28797
|
+
|
|
28798
|
+
// src/core/TypeScriptUtils.ts
|
|
28799
|
+
var TypeScriptUtils = Tag4("TypeScriptUtils");
|
|
28800
|
+
var nanoLayer = (fa) => pipe(
|
|
28801
|
+
service2(TypeScriptApi),
|
|
28802
|
+
flatMap18((ts2) => pipe(fa, provideService7(TypeScriptUtils, makeTypeScriptUtils(ts2))))
|
|
28803
|
+
);
|
|
28804
|
+
function makeTypeScriptUtils(ts2) {
|
|
28805
|
+
function parsePackageContentNameAndVersionFromScope(v) {
|
|
28806
|
+
if (!isObject(v)) return;
|
|
28807
|
+
if (!hasProperty(v, "packageJsonScope")) return;
|
|
28808
|
+
if (!v.packageJsonScope) return;
|
|
28809
|
+
const packageJsonScope = v.packageJsonScope;
|
|
28810
|
+
if (!hasProperty(packageJsonScope, "contents")) return;
|
|
28811
|
+
if (!hasProperty(packageJsonScope.contents, "packageJsonContent")) return;
|
|
28812
|
+
const packageJsonContent = packageJsonScope.contents.packageJsonContent;
|
|
28813
|
+
if (!hasProperty(packageJsonContent, "name")) return;
|
|
28814
|
+
if (!hasProperty(packageJsonContent, "version")) return;
|
|
28815
|
+
if (!hasProperty(packageJsonScope, "packageDirectory")) return;
|
|
28816
|
+
if (!isString(packageJsonScope.packageDirectory)) return;
|
|
28817
|
+
const { name, version } = packageJsonContent;
|
|
28818
|
+
if (!isString(name)) return;
|
|
28819
|
+
if (!isString(version)) return;
|
|
28820
|
+
const hasEffectInPeerDependencies = hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) && hasProperty(packageJsonContent.peerDependencies, "effect");
|
|
28821
|
+
const referencedPackages = Object.keys({
|
|
28822
|
+
...hasProperty(packageJsonContent, "dependencies") && isObject(packageJsonContent.dependencies) ? packageJsonContent.dependencies : {},
|
|
28823
|
+
...hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) ? packageJsonContent.peerDependencies : {},
|
|
28824
|
+
...hasProperty(packageJsonContent, "devDependencies") && isObject(packageJsonContent.devDependencies) ? packageJsonContent.devDependencies : {}
|
|
28825
|
+
});
|
|
28826
|
+
const exportsKeys = Object.keys(
|
|
28827
|
+
hasProperty(packageJsonContent, "exports") && isObject(packageJsonContent.exports) ? packageJsonContent.exports : {}
|
|
28828
|
+
);
|
|
28829
|
+
return {
|
|
28830
|
+
name: name.toLowerCase(),
|
|
28831
|
+
version: version.toLowerCase(),
|
|
28832
|
+
hasEffectInPeerDependencies,
|
|
28833
|
+
contents: packageJsonContent,
|
|
28834
|
+
packageDirectory: packageJsonScope.packageDirectory,
|
|
28835
|
+
referencedPackages,
|
|
28836
|
+
exportsKeys
|
|
28837
|
+
};
|
|
28838
|
+
}
|
|
28839
|
+
function resolveModulePattern(sourceFile, pattern2) {
|
|
28833
28840
|
if (pattern2.indexOf("*") === -1) return [pattern2.toLowerCase()];
|
|
28834
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
28835
28841
|
const packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
|
|
28836
28842
|
const referencedPackages = [];
|
|
28837
28843
|
for (const statement of sourceFile.statements) {
|
|
@@ -28850,19 +28856,338 @@ var resolveModulePattern = fn("resolveModulePattern")(
|
|
|
28850
28856
|
)
|
|
28851
28857
|
);
|
|
28852
28858
|
}
|
|
28853
|
-
)
|
|
28854
|
-
|
|
28855
|
-
|
|
28856
|
-
|
|
28857
|
-
|
|
28858
|
-
|
|
28859
|
-
|
|
28860
|
-
|
|
28861
|
-
|
|
28862
|
-
|
|
28863
|
-
|
|
28864
|
-
|
|
28859
|
+
function makeGetModuleSpecifier() {
|
|
28860
|
+
if (!(hasProperty(ts2, "moduleSpecifiers") && hasProperty(ts2.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts2.moduleSpecifiers.getModuleSpecifier))) return;
|
|
28861
|
+
const _internal = ts2.moduleSpecifiers.getModuleSpecifier;
|
|
28862
|
+
return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options3) => {
|
|
28863
|
+
return _internal(
|
|
28864
|
+
compilerOptions,
|
|
28865
|
+
importingSourceFile,
|
|
28866
|
+
importingSourceFileName,
|
|
28867
|
+
toFileName,
|
|
28868
|
+
host,
|
|
28869
|
+
options3
|
|
28870
|
+
);
|
|
28871
|
+
};
|
|
28872
|
+
}
|
|
28873
|
+
function findNodeWithLeadingCommentAtPosition(sourceFile, position) {
|
|
28874
|
+
const sourceText = sourceFile.text;
|
|
28875
|
+
let result;
|
|
28876
|
+
function find3(node) {
|
|
28877
|
+
const leading = ts2.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
28878
|
+
if (leading) {
|
|
28879
|
+
for (const commentRange of leading) {
|
|
28880
|
+
if (commentRange.pos <= position && position < commentRange.end) {
|
|
28881
|
+
result = { node, commentRange };
|
|
28882
|
+
return;
|
|
28883
|
+
}
|
|
28884
|
+
}
|
|
28885
|
+
}
|
|
28886
|
+
if (node.getFullStart() <= position && position < node.getEnd()) {
|
|
28887
|
+
node.forEachChild(find3);
|
|
28888
|
+
}
|
|
28889
|
+
}
|
|
28890
|
+
find3(sourceFile);
|
|
28891
|
+
return result;
|
|
28892
|
+
}
|
|
28893
|
+
function collectSelfAndAncestorNodesInRange(node, textRange) {
|
|
28894
|
+
let result = empty2();
|
|
28895
|
+
let parent = node;
|
|
28896
|
+
while (parent) {
|
|
28897
|
+
if (parent.end >= textRange.end) {
|
|
28898
|
+
result = pipe(result, append(parent));
|
|
28899
|
+
}
|
|
28900
|
+
parent = parent.parent;
|
|
28901
|
+
}
|
|
28902
|
+
return result;
|
|
28903
|
+
}
|
|
28904
|
+
function findNodeAtPosition(sourceFile, position) {
|
|
28905
|
+
function find3(node) {
|
|
28906
|
+
if (position >= node.getStart() && position < node.getEnd()) {
|
|
28907
|
+
return ts2.forEachChild(node, find3) || node;
|
|
28908
|
+
}
|
|
28909
|
+
return void 0;
|
|
28910
|
+
}
|
|
28911
|
+
return find3(sourceFile);
|
|
28912
|
+
}
|
|
28913
|
+
function findNodeAtPositionIncludingTrivia(sourceFile, position) {
|
|
28914
|
+
function find3(node) {
|
|
28915
|
+
if (position >= node.pos && position < node.end) {
|
|
28916
|
+
return ts2.forEachChild(node, find3) || node;
|
|
28917
|
+
}
|
|
28918
|
+
return void 0;
|
|
28919
|
+
}
|
|
28920
|
+
return find3(sourceFile);
|
|
28921
|
+
}
|
|
28922
|
+
function getAncestorNodesInRange(sourceFile, textRange) {
|
|
28923
|
+
const nodeAtPosition = findNodeAtPosition(sourceFile, textRange.pos);
|
|
28924
|
+
if (!nodeAtPosition) return empty2();
|
|
28925
|
+
return collectSelfAndAncestorNodesInRange(nodeAtPosition, textRange);
|
|
28926
|
+
}
|
|
28927
|
+
function getCommentAtPosition(sourceFile, pos) {
|
|
28928
|
+
const token = findNodeAtPositionIncludingTrivia(sourceFile, pos);
|
|
28929
|
+
if (token === void 0 || token.kind === ts2.SyntaxKind.JsxText || pos >= token.end - (ts2.tokenToString(token.kind) || "").length) {
|
|
28930
|
+
return;
|
|
28931
|
+
}
|
|
28932
|
+
const startPos = token.pos === 0 ? (ts2.getShebang(sourceFile.text) || "").length : token.pos;
|
|
28933
|
+
if (startPos === 0) return;
|
|
28934
|
+
const result = ts2.forEachTrailingCommentRange(sourceFile.text, startPos, isCommentInRange, pos) || ts2.forEachLeadingCommentRange(sourceFile.text, startPos, isCommentInRange, pos);
|
|
28935
|
+
return result;
|
|
28936
|
+
}
|
|
28937
|
+
function isCommentInRange(pos, end5, kind, _nl, at) {
|
|
28938
|
+
return at >= pos && at < end5 ? { pos, end: end5, kind } : void 0;
|
|
28939
|
+
}
|
|
28940
|
+
function toTextRange(positionOrRange) {
|
|
28941
|
+
return typeof positionOrRange === "number" ? { end: positionOrRange, pos: positionOrRange } : positionOrRange;
|
|
28942
|
+
}
|
|
28943
|
+
function isNodeInRange(textRange) {
|
|
28944
|
+
return (node) => node.pos <= textRange.pos && node.end >= textRange.end;
|
|
28945
|
+
}
|
|
28946
|
+
function transformAsyncAwaitToEffectGen(node, effectModuleName, onAwait) {
|
|
28947
|
+
function visitor(_) {
|
|
28948
|
+
if (ts2.isAwaitExpression(_)) {
|
|
28949
|
+
const expression = ts2.visitEachChild(_.expression, visitor, ts2.nullTransformationContext);
|
|
28950
|
+
return ts2.factory.createYieldExpression(
|
|
28951
|
+
ts2.factory.createToken(ts2.SyntaxKind.AsteriskToken),
|
|
28952
|
+
onAwait(expression)
|
|
28953
|
+
);
|
|
28954
|
+
}
|
|
28955
|
+
return ts2.visitEachChild(_, visitor, ts2.nullTransformationContext);
|
|
28956
|
+
}
|
|
28957
|
+
const generatorBody = visitor(node.body);
|
|
28958
|
+
const effectGenCallExp = createEffectGenCallExpression(effectModuleName, generatorBody);
|
|
28959
|
+
let currentFlags = ts2.getCombinedModifierFlags(node);
|
|
28960
|
+
currentFlags &= ~ts2.ModifierFlags.Async;
|
|
28961
|
+
const newModifiers = ts2.factory.createModifiersFromModifierFlags(currentFlags);
|
|
28962
|
+
if (ts2.isArrowFunction(node)) {
|
|
28963
|
+
return ts2.factory.createArrowFunction(
|
|
28964
|
+
newModifiers,
|
|
28965
|
+
node.typeParameters,
|
|
28966
|
+
node.parameters,
|
|
28967
|
+
void 0,
|
|
28968
|
+
node.equalsGreaterThanToken,
|
|
28969
|
+
effectGenCallExp
|
|
28970
|
+
);
|
|
28971
|
+
}
|
|
28972
|
+
const newBody = ts2.factory.createBlock([
|
|
28973
|
+
ts2.factory.createReturnStatement(effectGenCallExp)
|
|
28974
|
+
]);
|
|
28975
|
+
if (ts2.isFunctionDeclaration(node)) {
|
|
28976
|
+
return ts2.factory.createFunctionDeclaration(
|
|
28977
|
+
newModifiers,
|
|
28978
|
+
node.asteriskToken,
|
|
28979
|
+
node.name,
|
|
28980
|
+
node.typeParameters,
|
|
28981
|
+
node.parameters,
|
|
28982
|
+
void 0,
|
|
28983
|
+
newBody
|
|
28984
|
+
);
|
|
28985
|
+
}
|
|
28986
|
+
return ts2.factory.createFunctionExpression(
|
|
28987
|
+
newModifiers,
|
|
28988
|
+
node.asteriskToken,
|
|
28989
|
+
node.name,
|
|
28990
|
+
node.typeParameters,
|
|
28991
|
+
node.parameters,
|
|
28992
|
+
void 0,
|
|
28993
|
+
newBody
|
|
28994
|
+
);
|
|
28995
|
+
}
|
|
28996
|
+
function findImportedModuleIdentifier(sourceFile, test) {
|
|
28997
|
+
for (const statement of sourceFile.statements) {
|
|
28998
|
+
if (!ts2.isImportDeclaration(statement)) continue;
|
|
28999
|
+
const importClause = statement.importClause;
|
|
29000
|
+
if (!importClause) continue;
|
|
29001
|
+
const namedBindings = importClause.namedBindings;
|
|
29002
|
+
if (!namedBindings) continue;
|
|
29003
|
+
if (ts2.isNamespaceImport(namedBindings)) {
|
|
29004
|
+
if (test(namedBindings.name, statement.moduleSpecifier, none2())) {
|
|
29005
|
+
return namedBindings.name.text;
|
|
29006
|
+
}
|
|
29007
|
+
} else if (ts2.isNamedImports(namedBindings)) {
|
|
29008
|
+
for (const importSpecifier of namedBindings.elements) {
|
|
29009
|
+
const importProperty = fromNullable(importSpecifier.propertyName).pipe(
|
|
29010
|
+
orElse(() => some2(importSpecifier.name))
|
|
29011
|
+
);
|
|
29012
|
+
if (test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
|
|
29013
|
+
return importSpecifier.name.text;
|
|
29014
|
+
}
|
|
29015
|
+
}
|
|
29016
|
+
}
|
|
29017
|
+
}
|
|
29018
|
+
}
|
|
29019
|
+
function findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, packageName, moduleName) {
|
|
29020
|
+
return findImportedModuleIdentifier(
|
|
29021
|
+
sourceFile,
|
|
29022
|
+
(_, fromModule, importProperty) => {
|
|
29023
|
+
if (isNone2(importProperty) && ts2.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
|
|
29024
|
+
return true;
|
|
29025
|
+
}
|
|
29026
|
+
if (isSome2(importProperty) && ts2.isIdentifier(importProperty.value) && importProperty.value.text === moduleName && ts2.isStringLiteral(fromModule) && fromModule.text === packageName) {
|
|
29027
|
+
return true;
|
|
29028
|
+
}
|
|
29029
|
+
return false;
|
|
29030
|
+
}
|
|
29031
|
+
);
|
|
29032
|
+
}
|
|
29033
|
+
function simplifyTypeNode(typeNode) {
|
|
29034
|
+
function collectCallable(typeNode2) {
|
|
29035
|
+
if (ts2.isParenthesizedTypeNode(typeNode2)) return collectCallable(typeNode2.type);
|
|
29036
|
+
if (ts2.isFunctionTypeNode(typeNode2)) {
|
|
29037
|
+
return some2([
|
|
29038
|
+
ts2.factory.createCallSignature(typeNode2.typeParameters, typeNode2.parameters, typeNode2.type)
|
|
29039
|
+
]);
|
|
29040
|
+
}
|
|
29041
|
+
if (ts2.isTypeLiteralNode(typeNode2)) {
|
|
29042
|
+
const allCallSignatures = typeNode2.members.every(ts2.isCallSignatureDeclaration);
|
|
29043
|
+
if (allCallSignatures) {
|
|
29044
|
+
return some2(typeNode2.members);
|
|
29045
|
+
}
|
|
29046
|
+
}
|
|
29047
|
+
if (ts2.isIntersectionTypeNode(typeNode2)) {
|
|
29048
|
+
const members = typeNode2.types.map((node) => collectCallable(node));
|
|
29049
|
+
if (members.every(isSome2)) {
|
|
29050
|
+
return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
|
|
29051
|
+
}
|
|
29052
|
+
}
|
|
29053
|
+
return none2();
|
|
29054
|
+
}
|
|
29055
|
+
const callSignatures = collectCallable(typeNode);
|
|
29056
|
+
if (isSome2(callSignatures) && callSignatures.value.length > 1) {
|
|
29057
|
+
return ts2.factory.createTypeLiteralNode(callSignatures.value);
|
|
29058
|
+
}
|
|
29059
|
+
return typeNode;
|
|
29060
|
+
}
|
|
29061
|
+
function tryPreserveDeclarationSemantics(nodeToReplace, node) {
|
|
29062
|
+
if (!ts2.isExpression(node)) return node;
|
|
29063
|
+
if (ts2.isFunctionDeclaration(nodeToReplace)) {
|
|
29064
|
+
if (!nodeToReplace.name) return node;
|
|
29065
|
+
return ts2.factory.createVariableStatement(
|
|
29066
|
+
nodeToReplace.modifiers,
|
|
29067
|
+
ts2.factory.createVariableDeclarationList(
|
|
29068
|
+
[ts2.factory.createVariableDeclaration(
|
|
29069
|
+
nodeToReplace.name,
|
|
29070
|
+
void 0,
|
|
29071
|
+
void 0,
|
|
29072
|
+
node
|
|
29073
|
+
)],
|
|
29074
|
+
ts2.NodeFlags.Const
|
|
29075
|
+
)
|
|
29076
|
+
);
|
|
29077
|
+
} else if (ts2.isMethodDeclaration(nodeToReplace)) {
|
|
29078
|
+
return ts2.factory.createPropertyDeclaration(
|
|
29079
|
+
nodeToReplace.modifiers,
|
|
29080
|
+
nodeToReplace.name,
|
|
29081
|
+
void 0,
|
|
29082
|
+
void 0,
|
|
29083
|
+
node
|
|
29084
|
+
);
|
|
29085
|
+
}
|
|
29086
|
+
return node;
|
|
29087
|
+
}
|
|
29088
|
+
function parseAccessedExpressionForCompletion(sourceFile, position) {
|
|
29089
|
+
const precedingToken = ts2.findPrecedingToken(position, sourceFile, void 0, true);
|
|
29090
|
+
if (!precedingToken) return;
|
|
29091
|
+
let accessedObject = precedingToken;
|
|
29092
|
+
let replacementSpan = ts2.createTextSpan(position, 0);
|
|
29093
|
+
let outerNode = precedingToken;
|
|
29094
|
+
if (ts2.isIdentifier(precedingToken) && precedingToken.parent && ts2.isPropertyAccessExpression(precedingToken.parent)) {
|
|
29095
|
+
replacementSpan = ts2.createTextSpan(
|
|
29096
|
+
precedingToken.parent.getStart(sourceFile),
|
|
29097
|
+
precedingToken.end - precedingToken.parent.getStart(sourceFile)
|
|
29098
|
+
);
|
|
29099
|
+
accessedObject = precedingToken.parent.expression;
|
|
29100
|
+
outerNode = precedingToken.parent;
|
|
29101
|
+
} else if (ts2.isToken(precedingToken) && precedingToken.kind === ts2.SyntaxKind.DotToken && ts2.isPropertyAccessExpression(precedingToken.parent)) {
|
|
29102
|
+
replacementSpan = ts2.createTextSpan(
|
|
29103
|
+
precedingToken.parent.getStart(sourceFile),
|
|
29104
|
+
precedingToken.end - precedingToken.parent.getStart(sourceFile)
|
|
29105
|
+
);
|
|
29106
|
+
accessedObject = precedingToken.parent.expression;
|
|
29107
|
+
outerNode = precedingToken.parent;
|
|
29108
|
+
} else if (ts2.isIdentifier(precedingToken) && precedingToken.parent) {
|
|
29109
|
+
replacementSpan = ts2.createTextSpan(
|
|
29110
|
+
precedingToken.getStart(sourceFile),
|
|
29111
|
+
precedingToken.end - precedingToken.getStart(sourceFile)
|
|
29112
|
+
);
|
|
29113
|
+
accessedObject = precedingToken;
|
|
29114
|
+
outerNode = precedingToken;
|
|
29115
|
+
} else {
|
|
29116
|
+
return;
|
|
29117
|
+
}
|
|
29118
|
+
return { accessedObject, outerNode, replacementSpan };
|
|
29119
|
+
}
|
|
29120
|
+
function parseDataForExtendsClassCompletion(sourceFile, position) {
|
|
29121
|
+
const maybeInfos = parseAccessedExpressionForCompletion(sourceFile, position);
|
|
29122
|
+
if (!maybeInfos) return;
|
|
29123
|
+
const { accessedObject, outerNode, replacementSpan } = maybeInfos;
|
|
29124
|
+
if (!ts2.isIdentifier(accessedObject)) return;
|
|
29125
|
+
let classDeclaration = outerNode.parent;
|
|
29126
|
+
while (ts2.isExpressionWithTypeArguments(classDeclaration) || ts2.isHeritageClause(classDeclaration)) {
|
|
29127
|
+
if (!classDeclaration.parent) break;
|
|
29128
|
+
classDeclaration = classDeclaration.parent;
|
|
29129
|
+
}
|
|
29130
|
+
if (!ts2.isClassDeclaration(classDeclaration)) return;
|
|
29131
|
+
if (!classDeclaration.name) return;
|
|
29132
|
+
return {
|
|
29133
|
+
accessedObject,
|
|
29134
|
+
classDeclaration,
|
|
29135
|
+
className: classDeclaration.name,
|
|
29136
|
+
replacementSpan
|
|
29137
|
+
};
|
|
29138
|
+
}
|
|
29139
|
+
function createEffectGenCallExpression(effectModuleIdentifierName, node) {
|
|
29140
|
+
const generator = ts2.factory.createFunctionExpression(
|
|
29141
|
+
void 0,
|
|
29142
|
+
ts2.factory.createToken(ts2.SyntaxKind.AsteriskToken),
|
|
29143
|
+
void 0,
|
|
29144
|
+
[],
|
|
29145
|
+
[],
|
|
29146
|
+
void 0,
|
|
29147
|
+
node
|
|
29148
|
+
// NOTE(mattia): intended, to use same routine for both ConciseBody and Body
|
|
29149
|
+
);
|
|
29150
|
+
return ts2.factory.createCallExpression(
|
|
29151
|
+
ts2.factory.createPropertyAccessExpression(
|
|
29152
|
+
ts2.factory.createIdentifier(effectModuleIdentifierName),
|
|
29153
|
+
"gen"
|
|
29154
|
+
),
|
|
29155
|
+
void 0,
|
|
29156
|
+
[generator]
|
|
29157
|
+
);
|
|
29158
|
+
}
|
|
29159
|
+
function createEffectGenCallExpressionWithBlock(effectModuleIdentifierName, statement) {
|
|
29160
|
+
return createEffectGenCallExpression(
|
|
29161
|
+
effectModuleIdentifierName,
|
|
29162
|
+
ts2.factory.createBlock(isArray(statement) ? statement : [statement], false)
|
|
28865
29163
|
);
|
|
29164
|
+
}
|
|
29165
|
+
function createReturnYieldStarStatement(expr) {
|
|
29166
|
+
return ts2.factory.createReturnStatement(
|
|
29167
|
+
ts2.factory.createYieldExpression(
|
|
29168
|
+
ts2.factory.createToken(ts2.SyntaxKind.AsteriskToken),
|
|
29169
|
+
expr
|
|
29170
|
+
)
|
|
29171
|
+
);
|
|
29172
|
+
}
|
|
29173
|
+
return {
|
|
29174
|
+
findNodeAtPositionIncludingTrivia,
|
|
29175
|
+
parsePackageContentNameAndVersionFromScope,
|
|
29176
|
+
resolveModulePattern,
|
|
29177
|
+
findNodeWithLeadingCommentAtPosition,
|
|
29178
|
+
getCommentAtPosition,
|
|
29179
|
+
getAncestorNodesInRange,
|
|
29180
|
+
toTextRange,
|
|
29181
|
+
isNodeInRange,
|
|
29182
|
+
transformAsyncAwaitToEffectGen,
|
|
29183
|
+
findImportedModuleIdentifierByPackageAndNameOrBarrel,
|
|
29184
|
+
simplifyTypeNode,
|
|
29185
|
+
tryPreserveDeclarationSemantics,
|
|
29186
|
+
parseDataForExtendsClassCompletion,
|
|
29187
|
+
createEffectGenCallExpressionWithBlock,
|
|
29188
|
+
createReturnYieldStarStatement,
|
|
29189
|
+
makeGetModuleSpecifier,
|
|
29190
|
+
parseAccessedExpressionForCompletion
|
|
28866
29191
|
};
|
|
28867
29192
|
}
|
|
28868
29193
|
|
|
@@ -28870,6 +29195,9 @@ function makeGetModuleSpecifier(ts2) {
|
|
|
28870
29195
|
var RefactorNotApplicableError = class {
|
|
28871
29196
|
_tag = "@effect/language-service/RefactorNotApplicableError";
|
|
28872
29197
|
};
|
|
29198
|
+
function createRefactor(definition) {
|
|
29199
|
+
return definition;
|
|
29200
|
+
}
|
|
28873
29201
|
function createDiagnostic(definition) {
|
|
28874
29202
|
return definition;
|
|
28875
29203
|
}
|
|
@@ -28932,27 +29260,8 @@ var getCompletionsAtPosition = fn("LSP.getCompletionsAtPosition")(function* (com
|
|
|
28932
29260
|
var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
28933
29261
|
function* (sourceFile) {
|
|
28934
29262
|
const ts2 = yield* service2(TypeScriptApi);
|
|
29263
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
28935
29264
|
const pluginOptions = yield* service2(LanguageServicePluginOptions);
|
|
28936
|
-
function findNodeWithLeadingCommentAtPosition(position) {
|
|
28937
|
-
const sourceText = sourceFile.text;
|
|
28938
|
-
let result;
|
|
28939
|
-
function find3(node) {
|
|
28940
|
-
const leading = ts2.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
28941
|
-
if (leading) {
|
|
28942
|
-
for (const r of leading) {
|
|
28943
|
-
if (r.pos <= position && position < r.end) {
|
|
28944
|
-
result = node;
|
|
28945
|
-
return;
|
|
28946
|
-
}
|
|
28947
|
-
}
|
|
28948
|
-
}
|
|
28949
|
-
if (node.getFullStart() <= position && position < node.getEnd()) {
|
|
28950
|
-
node.forEachChild(find3);
|
|
28951
|
-
}
|
|
28952
|
-
}
|
|
28953
|
-
find3(sourceFile);
|
|
28954
|
-
return result;
|
|
28955
|
-
}
|
|
28956
29265
|
function findParentStatementForDisableNextLine(node) {
|
|
28957
29266
|
let result;
|
|
28958
29267
|
function find3(node2) {
|
|
@@ -28985,12 +29294,12 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
28985
29294
|
if (ruleLevel === "skip-file") skippedRules.push(ruleName);
|
|
28986
29295
|
const isOverrideNextLine = nextLineCaptureGroup && nextLineCaptureGroup.trim().toLowerCase() === "-next-line";
|
|
28987
29296
|
if (isOverrideNextLine) {
|
|
28988
|
-
const
|
|
28989
|
-
if (
|
|
29297
|
+
const foundNode = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, match18.index);
|
|
29298
|
+
if (foundNode) {
|
|
28990
29299
|
lineOverrides[ruleName] = lineOverrides[ruleName] || [];
|
|
28991
29300
|
lineOverrides[ruleName].unshift({
|
|
28992
|
-
pos: node.getFullStart(),
|
|
28993
|
-
end: node.end,
|
|
29301
|
+
pos: foundNode.node.getFullStart(),
|
|
29302
|
+
end: foundNode.node.end,
|
|
28994
29303
|
level: ruleLevel
|
|
28995
29304
|
});
|
|
28996
29305
|
}
|
|
@@ -29012,7 +29321,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
29012
29321
|
message: ts2.DiagnosticCategory.Message,
|
|
29013
29322
|
suggestion: ts2.DiagnosticCategory.Suggestion
|
|
29014
29323
|
};
|
|
29015
|
-
const execute2 =
|
|
29324
|
+
const execute2 = (rule) => gen3(function* () {
|
|
29016
29325
|
const diagnostics2 = [];
|
|
29017
29326
|
const codeFixes = [];
|
|
29018
29327
|
const ruleNameLowered = rule.name.toLowerCase();
|
|
@@ -29021,13 +29330,13 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
29021
29330
|
if (defaultLevel === "off" && (lineOverrides[ruleNameLowered] || sectionOverrides[ruleNameLowered] || []).length === 0) {
|
|
29022
29331
|
return { diagnostics: diagnostics2, codeFixes };
|
|
29023
29332
|
}
|
|
29024
|
-
const fixByDisableNextLine = (
|
|
29333
|
+
const fixByDisableNextLine = (node) => ({
|
|
29025
29334
|
fixName: rule.name + "_skipNextLine",
|
|
29026
29335
|
description: "Disable " + rule.name + " for this line",
|
|
29027
29336
|
apply: flatMap18(
|
|
29028
29337
|
service2(ChangeTracker),
|
|
29029
|
-
(changeTracker) =>
|
|
29030
|
-
const disableAtNode = findParentStatementForDisableNextLine(
|
|
29338
|
+
(changeTracker) => gen3(function* () {
|
|
29339
|
+
const disableAtNode = findParentStatementForDisableNextLine(node);
|
|
29031
29340
|
const { line: line4 } = ts2.getLineAndCharacterOfPosition(sourceFile, disableAtNode.getStart());
|
|
29032
29341
|
changeTracker.insertCommentBeforeLine(
|
|
29033
29342
|
sourceFile,
|
|
@@ -29055,29 +29364,30 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
29055
29364
|
};
|
|
29056
29365
|
const applicableDiagnostics = [];
|
|
29057
29366
|
yield* rule.apply(sourceFile, (entry) => {
|
|
29367
|
+
const range3 = "getEnd" in entry.location ? { pos: entry.location.getStart(sourceFile), end: entry.location.getEnd() } : entry.location;
|
|
29368
|
+
const node = "getEnd" in entry.location ? entry.location : tsUtils.findNodeAtPositionIncludingTrivia(sourceFile, entry.location.pos);
|
|
29058
29369
|
applicableDiagnostics.push({
|
|
29059
|
-
|
|
29060
|
-
|
|
29370
|
+
range: range3,
|
|
29371
|
+
messageText: entry.messageText,
|
|
29372
|
+
fixes: entry.fixes.concat(node ? [fixByDisableNextLine(node)] : []).concat([fixByDisableEntireFile])
|
|
29061
29373
|
});
|
|
29062
29374
|
});
|
|
29063
29375
|
for (const emitted of applicableDiagnostics.slice(0)) {
|
|
29064
29376
|
let newLevel = defaultLevel;
|
|
29065
29377
|
const lineOverride = (lineOverrides[ruleNameLowered] || []).find(
|
|
29066
|
-
(_) => _.pos < emitted.
|
|
29378
|
+
(_) => _.pos < emitted.range.pos && _.end >= emitted.range.end
|
|
29067
29379
|
);
|
|
29068
29380
|
if (lineOverride) {
|
|
29069
29381
|
newLevel = lineOverride.level;
|
|
29070
29382
|
} else {
|
|
29071
|
-
const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find(
|
|
29072
|
-
(_) => _.pos < emitted.node.getStart(sourceFile)
|
|
29073
|
-
);
|
|
29383
|
+
const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find((_) => _.pos < emitted.range.pos);
|
|
29074
29384
|
if (sectionOverride) newLevel = sectionOverride.level;
|
|
29075
29385
|
}
|
|
29076
29386
|
if (!(newLevel in levelToDiagnosticCategory)) continue;
|
|
29077
29387
|
diagnostics2.push({
|
|
29078
29388
|
file: sourceFile,
|
|
29079
|
-
start: emitted.
|
|
29080
|
-
length: emitted.
|
|
29389
|
+
start: emitted.range.pos,
|
|
29390
|
+
length: emitted.range.end - emitted.range.pos,
|
|
29081
29391
|
messageText: emitted.messageText,
|
|
29082
29392
|
category: levelToDiagnosticCategory[newLevel],
|
|
29083
29393
|
code: rule.code,
|
|
@@ -29087,8 +29397,8 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
29087
29397
|
codeFixes.push({
|
|
29088
29398
|
...fix,
|
|
29089
29399
|
code: rule.code,
|
|
29090
|
-
start: emitted.
|
|
29091
|
-
end: emitted.
|
|
29400
|
+
start: emitted.range.pos,
|
|
29401
|
+
end: emitted.range.end
|
|
29092
29402
|
});
|
|
29093
29403
|
}
|
|
29094
29404
|
}
|
|
@@ -29097,15 +29407,85 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
29097
29407
|
return { execute: execute2 };
|
|
29098
29408
|
}
|
|
29099
29409
|
);
|
|
29410
|
+
var cyrb53 = (str, seed = 0) => {
|
|
29411
|
+
let h12 = 3735928559 ^ seed, h2 = 1103547991 ^ seed;
|
|
29412
|
+
for (let i = 0, ch; i < str.length; i++) {
|
|
29413
|
+
ch = str.charCodeAt(i);
|
|
29414
|
+
h12 = Math.imul(h12 ^ ch, 2654435761);
|
|
29415
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
29416
|
+
}
|
|
29417
|
+
h12 = Math.imul(h12 ^ h12 >>> 16, 2246822507);
|
|
29418
|
+
h12 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
29419
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
|
|
29420
|
+
h2 ^= Math.imul(h12 ^ h12 >>> 13, 3266489909);
|
|
29421
|
+
return (h2 >>> 0).toString(16).padStart(8, "0") + (h12 >>> 0).toString(16).padStart(8, "0");
|
|
29422
|
+
};
|
|
29423
|
+
var CodegenNotApplicableError = class {
|
|
29424
|
+
constructor(cause2) {
|
|
29425
|
+
this.cause = cause2;
|
|
29426
|
+
}
|
|
29427
|
+
_tag = "@effect/language-service/CodegenNotApplicableError";
|
|
29428
|
+
};
|
|
29429
|
+
function createCodegen(definition) {
|
|
29430
|
+
return definition;
|
|
29431
|
+
}
|
|
29432
|
+
var getCodegensForSourceFile = fn("LSP.getApplicableCodegens")(function* (codegens2, sourceFile) {
|
|
29433
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
29434
|
+
const result = [];
|
|
29435
|
+
const regex = /@effect-codegens((?:\s[a-zA-Z0-9]+(?::(?:[a-zA-Z0-9]+))?)+)+/gmid;
|
|
29436
|
+
let match18;
|
|
29437
|
+
while ((match18 = regex.exec(sourceFile.text)) !== null) {
|
|
29438
|
+
const pos = match18.indices?.[0]?.[0];
|
|
29439
|
+
if (!pos) continue;
|
|
29440
|
+
const commentRange = tsUtils.getCommentAtPosition(sourceFile, pos);
|
|
29441
|
+
if (!commentRange) continue;
|
|
29442
|
+
const commentText = sourceFile.text.slice(pos, commentRange.end);
|
|
29443
|
+
const codegenRegex = /(\s+)(\w+)(?::(\w+))?/gmi;
|
|
29444
|
+
let codegenMatch;
|
|
29445
|
+
while ((codegenMatch = codegenRegex.exec(commentText)) !== null) {
|
|
29446
|
+
const whitespace = codegenMatch[1] || "";
|
|
29447
|
+
const codegenName = codegenMatch[2] || "";
|
|
29448
|
+
const codegenHash = codegenMatch[3] || "";
|
|
29449
|
+
const range3 = {
|
|
29450
|
+
pos: codegenMatch.index + pos + whitespace.length,
|
|
29451
|
+
end: codegenMatch.index + pos + codegenMatch[0].length
|
|
29452
|
+
};
|
|
29453
|
+
const codegen = codegens2.find((codegen2) => codegen2.name === codegenName);
|
|
29454
|
+
if (!codegen) continue;
|
|
29455
|
+
result.push({ codegen, hash: codegenHash, range: range3 });
|
|
29456
|
+
}
|
|
29457
|
+
}
|
|
29458
|
+
return result;
|
|
29459
|
+
});
|
|
29460
|
+
var getEditsForCodegen = fn("LSP.getEditsForCodegen")(function* (codegens2, sourceFile, textRange) {
|
|
29461
|
+
const applicableCodegens = yield* getCodegensForSourceFile(codegens2, sourceFile);
|
|
29462
|
+
const inRangeCodegens = applicableCodegens.filter(
|
|
29463
|
+
(codegen2) => codegen2.range.pos <= textRange.pos && codegen2.range.end >= textRange.end
|
|
29464
|
+
);
|
|
29465
|
+
if (inRangeCodegens.length !== 1) {
|
|
29466
|
+
return yield* fail18(new CodegenNotApplicableError("zero or multiple codegens in range"));
|
|
29467
|
+
}
|
|
29468
|
+
const { codegen, range: range3 } = inRangeCodegens[0];
|
|
29469
|
+
const edit = yield* codegen.apply(sourceFile, range3);
|
|
29470
|
+
const updateHashComment = pipe(
|
|
29471
|
+
service2(ChangeTracker),
|
|
29472
|
+
map33((changeTracker) => {
|
|
29473
|
+
changeTracker.deleteRange(sourceFile, range3);
|
|
29474
|
+
changeTracker.insertText(sourceFile, range3.pos, `${codegen.name}:${edit.hash}`);
|
|
29475
|
+
})
|
|
29476
|
+
);
|
|
29477
|
+
return {
|
|
29478
|
+
...edit,
|
|
29479
|
+
apply: pipe(
|
|
29480
|
+
edit.apply,
|
|
29481
|
+
flatMap18(() => updateHashComment)
|
|
29482
|
+
),
|
|
29483
|
+
ignore: updateHashComment
|
|
29484
|
+
};
|
|
29485
|
+
});
|
|
29100
29486
|
|
|
29101
29487
|
// src/core/TypeCheckerApi.ts
|
|
29102
29488
|
var TypeCheckerApi = Tag4("TypeChecker");
|
|
29103
|
-
var TypeCheckerApiCache = Tag4("TypeCheckerApiCache");
|
|
29104
|
-
function makeTypeCheckerApiCache() {
|
|
29105
|
-
return {
|
|
29106
|
-
expectedAndRealType: /* @__PURE__ */ new WeakMap()
|
|
29107
|
-
};
|
|
29108
|
-
}
|
|
29109
29489
|
var deterministicTypeOrder = gen3(function* () {
|
|
29110
29490
|
const typeChecker = yield* service2(TypeCheckerApi);
|
|
29111
29491
|
return make2((a, b) => {
|
|
@@ -29204,517 +29584,184 @@ var getInferredReturnType = fn("TypeCheckerApi.getInferredReturnType")(function*
|
|
|
29204
29584
|
}
|
|
29205
29585
|
return returnType;
|
|
29206
29586
|
});
|
|
29207
|
-
var expectedAndRealType =
|
|
29208
|
-
|
|
29209
|
-
const resultCached = cache.expectedAndRealType.get(sourceFile);
|
|
29210
|
-
if (resultCached) return resultCached;
|
|
29211
|
-
const typeChecker = yield* service2(TypeCheckerApi);
|
|
29212
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29213
|
-
const result = [];
|
|
29214
|
-
const nodeToVisit = [sourceFile];
|
|
29215
|
-
const appendNodeToVisit = (node) => {
|
|
29216
|
-
nodeToVisit.push(node);
|
|
29217
|
-
return void 0;
|
|
29218
|
-
};
|
|
29219
|
-
while (nodeToVisit.length > 0) {
|
|
29220
|
-
const node = nodeToVisit.shift();
|
|
29221
|
-
if (ts2.isVariableDeclaration(node) && node.initializer) {
|
|
29222
|
-
const expectedType = typeChecker.getTypeAtLocation(node.name);
|
|
29223
|
-
const realType = typeChecker.getTypeAtLocation(node.initializer);
|
|
29224
|
-
result.push([node.name, expectedType, node.initializer, realType]);
|
|
29225
|
-
appendNodeToVisit(node.initializer);
|
|
29226
|
-
continue;
|
|
29227
|
-
} else if (ts2.isCallExpression(node)) {
|
|
29228
|
-
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
29229
|
-
if (resolvedSignature) {
|
|
29230
|
-
resolvedSignature.getParameters().map((parameter, index) => {
|
|
29231
|
-
const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
|
|
29232
|
-
const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
|
|
29233
|
-
result.push([
|
|
29234
|
-
node.arguments[index],
|
|
29235
|
-
expectedType,
|
|
29236
|
-
node.arguments[index],
|
|
29237
|
-
realType
|
|
29238
|
-
]);
|
|
29239
|
-
});
|
|
29240
|
-
}
|
|
29241
|
-
ts2.forEachChild(node, appendNodeToVisit);
|
|
29242
|
-
continue;
|
|
29243
|
-
} else if (ts2.isIdentifier(node) || ts2.isStringLiteral(node) || ts2.isNumericLiteral(node) || ts2.isNoSubstitutionTemplateLiteral(node)) {
|
|
29244
|
-
const parent = node.parent;
|
|
29245
|
-
if (ts2.isObjectLiteralElement(parent)) {
|
|
29246
|
-
if (ts2.isObjectLiteralExpression(parent.parent) && parent.name === node) {
|
|
29247
|
-
const type2 = typeChecker.getContextualType(parent.parent);
|
|
29248
|
-
if (type2) {
|
|
29249
|
-
const symbol3 = typeChecker.getPropertyOfType(type2, node.text);
|
|
29250
|
-
if (symbol3) {
|
|
29251
|
-
const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
|
|
29252
|
-
const realType = typeChecker.getTypeAtLocation(node);
|
|
29253
|
-
result.push([node, expectedType, node, realType]);
|
|
29254
|
-
}
|
|
29255
|
-
}
|
|
29256
|
-
}
|
|
29257
|
-
}
|
|
29258
|
-
ts2.forEachChild(node, appendNodeToVisit);
|
|
29259
|
-
continue;
|
|
29260
|
-
} else if (ts2.isBinaryExpression(node) && node.operatorToken.kind === ts2.SyntaxKind.EqualsToken) {
|
|
29261
|
-
const expectedType = typeChecker.getTypeAtLocation(node.left);
|
|
29262
|
-
const realType = typeChecker.getTypeAtLocation(node.right);
|
|
29263
|
-
result.push([node.left, expectedType, node.right, realType]);
|
|
29264
|
-
appendNodeToVisit(node.right);
|
|
29265
|
-
continue;
|
|
29266
|
-
} else if (ts2.isReturnStatement(node) && node.expression) {
|
|
29267
|
-
const parentDeclaration = yield* option4(getAncestorConvertibleDeclaration(node));
|
|
29268
|
-
if (isSome2(parentDeclaration)) {
|
|
29269
|
-
const expectedType = yield* option4(getInferredReturnType(parentDeclaration.value));
|
|
29270
|
-
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
29271
|
-
if (isSome2(expectedType)) {
|
|
29272
|
-
result.push([node, expectedType.value, node, realType]);
|
|
29273
|
-
}
|
|
29274
|
-
}
|
|
29275
|
-
ts2.forEachChild(node, appendNodeToVisit);
|
|
29276
|
-
continue;
|
|
29277
|
-
} else if (ts2.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts2.isExpression(node.body)) {
|
|
29278
|
-
const body = node.body;
|
|
29279
|
-
const expectedType = typeChecker.getContextualType(body);
|
|
29280
|
-
const realType = typeChecker.getTypeAtLocation(body);
|
|
29281
|
-
if (expectedType) {
|
|
29282
|
-
result.push([body, expectedType, body, realType]);
|
|
29283
|
-
}
|
|
29284
|
-
ts2.forEachChild(body, appendNodeToVisit);
|
|
29285
|
-
continue;
|
|
29286
|
-
} else if (ts2.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts2.isExpression(node.body)) {
|
|
29287
|
-
const body = node.body;
|
|
29288
|
-
const expectedType = yield* option4(getInferredReturnType(node));
|
|
29289
|
-
const realType = typeChecker.getTypeAtLocation(body);
|
|
29290
|
-
if (isSome2(expectedType)) {
|
|
29291
|
-
result.push([body, expectedType.value, body, realType]);
|
|
29292
|
-
}
|
|
29293
|
-
ts2.forEachChild(body, appendNodeToVisit);
|
|
29294
|
-
continue;
|
|
29295
|
-
} else if (ts2.isSatisfiesExpression(node)) {
|
|
29296
|
-
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
29297
|
-
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
29298
|
-
result.push([node.expression, expectedType, node.expression, realType]);
|
|
29299
|
-
appendNodeToVisit(node.expression);
|
|
29300
|
-
continue;
|
|
29301
|
-
}
|
|
29302
|
-
ts2.forEachChild(node, appendNodeToVisit);
|
|
29303
|
-
}
|
|
29304
|
-
cache.expectedAndRealType.set(sourceFile, result);
|
|
29305
|
-
return result;
|
|
29306
|
-
});
|
|
29307
|
-
var unrollUnionMembers = (type2) => {
|
|
29308
|
-
const result = [];
|
|
29309
|
-
let toTest = [type2];
|
|
29310
|
-
while (toTest.length > 0) {
|
|
29311
|
-
const type3 = toTest.pop();
|
|
29312
|
-
if (type3.isUnion()) {
|
|
29313
|
-
toTest = toTest.concat(type3.types);
|
|
29314
|
-
} else {
|
|
29315
|
-
result.push(type3);
|
|
29316
|
-
}
|
|
29317
|
-
}
|
|
29318
|
-
return result;
|
|
29319
|
-
};
|
|
29320
|
-
var appendToUniqueTypesMap = fn(
|
|
29321
|
-
"TypeCheckerApi.appendToUniqueTypesMap"
|
|
29322
|
-
)(
|
|
29323
|
-
function* (memory, initialType, shouldExclude) {
|
|
29587
|
+
var expectedAndRealType = cachedBy(
|
|
29588
|
+
fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
|
|
29324
29589
|
const typeChecker = yield* service2(TypeCheckerApi);
|
|
29325
|
-
const
|
|
29326
|
-
const
|
|
29327
|
-
|
|
29328
|
-
|
|
29329
|
-
|
|
29330
|
-
|
|
29331
|
-
|
|
29590
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
29591
|
+
const result = [];
|
|
29592
|
+
const nodeToVisit = [sourceFile];
|
|
29593
|
+
const appendNodeToVisit = (node) => {
|
|
29594
|
+
nodeToVisit.push(node);
|
|
29595
|
+
return void 0;
|
|
29596
|
+
};
|
|
29597
|
+
while (nodeToVisit.length > 0) {
|
|
29598
|
+
const node = nodeToVisit.shift();
|
|
29599
|
+
if (ts2.isVariableDeclaration(node) && node.initializer) {
|
|
29600
|
+
const expectedType = typeChecker.getTypeAtLocation(node.name);
|
|
29601
|
+
const realType = typeChecker.getTypeAtLocation(node.initializer);
|
|
29602
|
+
result.push([node.name, expectedType, node.initializer, realType]);
|
|
29603
|
+
appendNodeToVisit(node.initializer);
|
|
29332
29604
|
continue;
|
|
29333
|
-
}
|
|
29334
|
-
|
|
29335
|
-
|
|
29336
|
-
|
|
29337
|
-
|
|
29338
|
-
|
|
29339
|
-
|
|
29340
|
-
|
|
29341
|
-
|
|
29342
|
-
|
|
29343
|
-
|
|
29344
|
-
|
|
29345
|
-
|
|
29346
|
-
const newId = "t" + (memory.size + 1);
|
|
29347
|
-
memory.set(newId, type2);
|
|
29348
|
-
newIndexes.add(newId);
|
|
29349
|
-
} else {
|
|
29350
|
-
knownIndexes.add(foundMatch[0]);
|
|
29605
|
+
} else if (ts2.isCallExpression(node)) {
|
|
29606
|
+
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
29607
|
+
if (resolvedSignature) {
|
|
29608
|
+
resolvedSignature.getParameters().map((parameter, index) => {
|
|
29609
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
|
|
29610
|
+
const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
|
|
29611
|
+
result.push([
|
|
29612
|
+
node.arguments[index],
|
|
29613
|
+
expectedType,
|
|
29614
|
+
node.arguments[index],
|
|
29615
|
+
realType
|
|
29616
|
+
]);
|
|
29617
|
+
});
|
|
29351
29618
|
}
|
|
29352
|
-
|
|
29353
|
-
|
|
29354
|
-
|
|
29355
|
-
|
|
29356
|
-
|
|
29357
|
-
|
|
29358
|
-
|
|
29359
|
-
|
|
29360
|
-
|
|
29361
|
-
|
|
29362
|
-
|
|
29363
|
-
);
|
|
29364
|
-
|
|
29365
|
-
|
|
29366
|
-
|
|
29367
|
-
|
|
29368
|
-
const _internal = typeChecker.resolveExternalModuleName;
|
|
29369
|
-
return (moduleSpecifier) => {
|
|
29370
|
-
return _internal(moduleSpecifier);
|
|
29371
|
-
};
|
|
29372
|
-
}
|
|
29373
|
-
|
|
29374
|
-
// src/core/AST.ts
|
|
29375
|
-
function collectSelfAndAncestorNodesInRange(node, textRange) {
|
|
29376
|
-
return sync11(() => {
|
|
29377
|
-
let result = empty2();
|
|
29378
|
-
let parent = node;
|
|
29379
|
-
while (parent) {
|
|
29380
|
-
if (parent.end >= textRange.end) {
|
|
29381
|
-
result = pipe(result, append(parent));
|
|
29382
|
-
}
|
|
29383
|
-
parent = parent.parent;
|
|
29384
|
-
}
|
|
29385
|
-
return result;
|
|
29386
|
-
});
|
|
29387
|
-
}
|
|
29388
|
-
var getAncestorNodesInRange = fn("AST.getAncestorNodesInRange")(function* (sourceFile, textRange) {
|
|
29389
|
-
const nodeAtPosition = yield* option4(findNodeAtPosition(sourceFile, textRange.pos));
|
|
29390
|
-
if (isNone2(nodeAtPosition)) return empty2();
|
|
29391
|
-
return yield* collectSelfAndAncestorNodesInRange(nodeAtPosition.value, textRange);
|
|
29392
|
-
});
|
|
29393
|
-
var NodeNotFoundError = class {
|
|
29394
|
-
_tag = "@effect/language-service/NodeNotFoundError";
|
|
29395
|
-
};
|
|
29396
|
-
var findNodeAtPosition = fn("AST.findNodeAtPosition")(function* (sourceFile, position) {
|
|
29397
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29398
|
-
function find3(node) {
|
|
29399
|
-
if (position >= node.getStart() && position < node.getEnd()) {
|
|
29400
|
-
return ts2.forEachChild(node, find3) || node;
|
|
29401
|
-
}
|
|
29402
|
-
return void 0;
|
|
29403
|
-
}
|
|
29404
|
-
const result = find3(sourceFile);
|
|
29405
|
-
if (!result) return yield* fail18(new NodeNotFoundError());
|
|
29406
|
-
return result;
|
|
29407
|
-
});
|
|
29408
|
-
var getCommentAtPosition = fn("TypeScriptApi.getCommentAtPosition")(function* (sourceFile, pos) {
|
|
29409
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29410
|
-
const token = yield* findNodeAtPosition(sourceFile, pos);
|
|
29411
|
-
if (token === void 0 || token.kind === ts2.SyntaxKind.JsxText || pos >= token.end - (ts2.tokenToString(token.kind) || "").length) {
|
|
29412
|
-
return yield* fail18(new NodeNotFoundError());
|
|
29413
|
-
}
|
|
29414
|
-
const startPos = token.pos === 0 ? (ts2.getShebang(sourceFile.text) || "").length : token.pos;
|
|
29415
|
-
if (startPos === 0) return yield* fail18(new NodeNotFoundError());
|
|
29416
|
-
const result = ts2.forEachTrailingCommentRange(sourceFile.text, startPos, isCommentInRange, pos) || ts2.forEachLeadingCommentRange(sourceFile.text, startPos, isCommentInRange, pos);
|
|
29417
|
-
if (!result) return yield* fail18(new NodeNotFoundError());
|
|
29418
|
-
return result;
|
|
29419
|
-
});
|
|
29420
|
-
function isCommentInRange(pos, end5, kind, _nl, at) {
|
|
29421
|
-
return at >= pos && at < end5 ? { pos, end: end5, kind } : void 0;
|
|
29422
|
-
}
|
|
29423
|
-
var transformAsyncAwaitToEffectGen = fn("AST.transformAsyncAwaitToEffectGen")(
|
|
29424
|
-
function* (node, effectModuleName, onAwait) {
|
|
29425
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29426
|
-
function visitor(_) {
|
|
29427
|
-
if (ts2.isAwaitExpression(_)) {
|
|
29428
|
-
const expression = ts2.visitEachChild(_.expression, visitor, ts2.nullTransformationContext);
|
|
29429
|
-
return ts2.factory.createYieldExpression(
|
|
29430
|
-
ts2.factory.createToken(ts2.SyntaxKind.AsteriskToken),
|
|
29431
|
-
onAwait(expression)
|
|
29432
|
-
);
|
|
29433
|
-
}
|
|
29434
|
-
return ts2.visitEachChild(_, visitor, ts2.nullTransformationContext);
|
|
29435
|
-
}
|
|
29436
|
-
const generatorBody = visitor(node.body);
|
|
29437
|
-
const effectGenCallExp = yield* createEffectGenCallExpression(effectModuleName, generatorBody);
|
|
29438
|
-
let currentFlags = ts2.getCombinedModifierFlags(node);
|
|
29439
|
-
currentFlags &= ~ts2.ModifierFlags.Async;
|
|
29440
|
-
const newModifiers = ts2.factory.createModifiersFromModifierFlags(currentFlags);
|
|
29441
|
-
if (ts2.isArrowFunction(node)) {
|
|
29442
|
-
return ts2.factory.createArrowFunction(
|
|
29443
|
-
newModifiers,
|
|
29444
|
-
node.typeParameters,
|
|
29445
|
-
node.parameters,
|
|
29446
|
-
void 0,
|
|
29447
|
-
node.equalsGreaterThanToken,
|
|
29448
|
-
effectGenCallExp
|
|
29449
|
-
);
|
|
29450
|
-
}
|
|
29451
|
-
const newBody = ts2.factory.createBlock([
|
|
29452
|
-
ts2.factory.createReturnStatement(effectGenCallExp)
|
|
29453
|
-
]);
|
|
29454
|
-
if (ts2.isFunctionDeclaration(node)) {
|
|
29455
|
-
return ts2.factory.createFunctionDeclaration(
|
|
29456
|
-
newModifiers,
|
|
29457
|
-
node.asteriskToken,
|
|
29458
|
-
node.name,
|
|
29459
|
-
node.typeParameters,
|
|
29460
|
-
node.parameters,
|
|
29461
|
-
void 0,
|
|
29462
|
-
newBody
|
|
29463
|
-
);
|
|
29464
|
-
}
|
|
29465
|
-
return ts2.factory.createFunctionExpression(
|
|
29466
|
-
newModifiers,
|
|
29467
|
-
node.asteriskToken,
|
|
29468
|
-
node.name,
|
|
29469
|
-
node.typeParameters,
|
|
29470
|
-
node.parameters,
|
|
29471
|
-
void 0,
|
|
29472
|
-
newBody
|
|
29473
|
-
);
|
|
29474
|
-
}
|
|
29475
|
-
);
|
|
29476
|
-
var addReturnTypeAnnotation = fn("AST.addReturnTypeAnnotation")(function* (sourceFile, declaration, typeNode) {
|
|
29477
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29478
|
-
const changes2 = yield* service2(ChangeTracker);
|
|
29479
|
-
const closeParen = ts2.findChildOfKind(declaration, ts2.SyntaxKind.CloseParenToken, sourceFile);
|
|
29480
|
-
const needParens = ts2.isArrowFunction(declaration) && closeParen === void 0;
|
|
29481
|
-
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
29482
|
-
if (endNode) {
|
|
29483
|
-
if (needParens) {
|
|
29484
|
-
changes2.insertNodeBefore(
|
|
29485
|
-
sourceFile,
|
|
29486
|
-
endNode,
|
|
29487
|
-
ts2.factory.createToken(ts2.SyntaxKind.OpenParenToken)
|
|
29488
|
-
);
|
|
29489
|
-
changes2.insertNodeAfter(
|
|
29490
|
-
sourceFile,
|
|
29491
|
-
endNode,
|
|
29492
|
-
ts2.factory.createToken(ts2.SyntaxKind.CloseParenToken)
|
|
29493
|
-
);
|
|
29494
|
-
}
|
|
29495
|
-
changes2.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: ": " });
|
|
29496
|
-
}
|
|
29497
|
-
});
|
|
29498
|
-
var removeReturnTypeAnnotation = fn("AST.removeReturnTypeAnnotation")(function* (sourceFile, declaration) {
|
|
29499
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29500
|
-
const changes2 = yield* service2(ChangeTracker);
|
|
29501
|
-
const closeParen = ts2.findChildOfKind(declaration, ts2.SyntaxKind.CloseParenToken, sourceFile);
|
|
29502
|
-
const needParens = ts2.isArrowFunction(declaration) && closeParen === void 0;
|
|
29503
|
-
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
29504
|
-
if (endNode && declaration.type) {
|
|
29505
|
-
changes2.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end });
|
|
29506
|
-
}
|
|
29507
|
-
});
|
|
29508
|
-
var ImportModuleIdentifierNotFoundError = class {
|
|
29509
|
-
_tag = "@effect/language-service/ImportModuleIdentifierNotFoundError";
|
|
29510
|
-
};
|
|
29511
|
-
var findImportedModuleIdentifier = fn("AST.findImportedModuleIdentifier")(
|
|
29512
|
-
function* (sourceFile, test) {
|
|
29513
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29514
|
-
for (const statement of sourceFile.statements) {
|
|
29515
|
-
if (!ts2.isImportDeclaration(statement)) continue;
|
|
29516
|
-
const importClause = statement.importClause;
|
|
29517
|
-
if (!importClause) continue;
|
|
29518
|
-
const namedBindings = importClause.namedBindings;
|
|
29519
|
-
if (!namedBindings) continue;
|
|
29520
|
-
if (ts2.isNamespaceImport(namedBindings)) {
|
|
29521
|
-
if (yield* test(namedBindings.name, statement.moduleSpecifier, none2())) {
|
|
29522
|
-
return namedBindings.name;
|
|
29619
|
+
ts2.forEachChild(node, appendNodeToVisit);
|
|
29620
|
+
continue;
|
|
29621
|
+
} else if (ts2.isIdentifier(node) || ts2.isStringLiteral(node) || ts2.isNumericLiteral(node) || ts2.isNoSubstitutionTemplateLiteral(node)) {
|
|
29622
|
+
const parent = node.parent;
|
|
29623
|
+
if (ts2.isObjectLiteralElement(parent)) {
|
|
29624
|
+
if (ts2.isObjectLiteralExpression(parent.parent) && parent.name === node) {
|
|
29625
|
+
const type2 = typeChecker.getContextualType(parent.parent);
|
|
29626
|
+
if (type2) {
|
|
29627
|
+
const symbol3 = typeChecker.getPropertyOfType(type2, node.text);
|
|
29628
|
+
if (symbol3) {
|
|
29629
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
|
|
29630
|
+
const realType = typeChecker.getTypeAtLocation(node);
|
|
29631
|
+
result.push([node, expectedType, node, realType]);
|
|
29632
|
+
}
|
|
29633
|
+
}
|
|
29634
|
+
}
|
|
29523
29635
|
}
|
|
29524
|
-
|
|
29525
|
-
|
|
29526
|
-
|
|
29527
|
-
|
|
29528
|
-
|
|
29529
|
-
|
|
29530
|
-
|
|
29636
|
+
ts2.forEachChild(node, appendNodeToVisit);
|
|
29637
|
+
continue;
|
|
29638
|
+
} else if (ts2.isBinaryExpression(node) && node.operatorToken.kind === ts2.SyntaxKind.EqualsToken) {
|
|
29639
|
+
const expectedType = typeChecker.getTypeAtLocation(node.left);
|
|
29640
|
+
const realType = typeChecker.getTypeAtLocation(node.right);
|
|
29641
|
+
result.push([node.left, expectedType, node.right, realType]);
|
|
29642
|
+
appendNodeToVisit(node.right);
|
|
29643
|
+
continue;
|
|
29644
|
+
} else if (ts2.isReturnStatement(node) && node.expression) {
|
|
29645
|
+
const parentDeclaration = yield* option4(getAncestorConvertibleDeclaration(node));
|
|
29646
|
+
if (isSome2(parentDeclaration)) {
|
|
29647
|
+
const expectedType = yield* option4(getInferredReturnType(parentDeclaration.value));
|
|
29648
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
29649
|
+
if (isSome2(expectedType)) {
|
|
29650
|
+
result.push([node, expectedType.value, node, realType]);
|
|
29531
29651
|
}
|
|
29532
29652
|
}
|
|
29533
|
-
|
|
29534
|
-
|
|
29535
|
-
|
|
29536
|
-
|
|
29537
|
-
);
|
|
29538
|
-
|
|
29539
|
-
|
|
29540
|
-
|
|
29541
|
-
|
|
29542
|
-
|
|
29543
|
-
|
|
29544
|
-
|
|
29545
|
-
|
|
29546
|
-
|
|
29547
|
-
|
|
29548
|
-
|
|
29549
|
-
|
|
29550
|
-
|
|
29551
|
-
|
|
29552
|
-
|
|
29553
|
-
|
|
29554
|
-
|
|
29555
|
-
|
|
29556
|
-
|
|
29557
|
-
|
|
29558
|
-
|
|
29559
|
-
|
|
29560
|
-
|
|
29561
|
-
ts2.factory.createCallSignature(typeNode2.typeParameters, typeNode2.parameters, typeNode2.type)
|
|
29562
|
-
]);
|
|
29563
|
-
}
|
|
29564
|
-
if (ts2.isTypeLiteralNode(typeNode2)) {
|
|
29565
|
-
const allCallSignatures = typeNode2.members.every(ts2.isCallSignatureDeclaration);
|
|
29566
|
-
if (allCallSignatures) {
|
|
29567
|
-
return some2(typeNode2.members);
|
|
29568
|
-
}
|
|
29569
|
-
}
|
|
29570
|
-
if (ts2.isIntersectionTypeNode(typeNode2)) {
|
|
29571
|
-
const members = typeNode2.types.map((node) => collectCallable(node));
|
|
29572
|
-
if (members.every(isSome2)) {
|
|
29573
|
-
return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
|
|
29574
|
-
}
|
|
29575
|
-
}
|
|
29576
|
-
return none2();
|
|
29577
|
-
}
|
|
29578
|
-
const callSignatures = collectCallable(typeNode);
|
|
29579
|
-
if (isSome2(callSignatures) && callSignatures.value.length > 1) {
|
|
29580
|
-
return ts2.factory.createTypeLiteralNode(callSignatures.value);
|
|
29581
|
-
}
|
|
29582
|
-
return typeNode;
|
|
29583
|
-
});
|
|
29584
|
-
var tryPreserveDeclarationSemantics = fn("AST.tryPreserveDeclarationSemantics")(
|
|
29585
|
-
function* (nodeToReplace, node) {
|
|
29586
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29587
|
-
if (!ts2.isExpression(node)) return node;
|
|
29588
|
-
if (ts2.isFunctionDeclaration(nodeToReplace)) {
|
|
29589
|
-
if (!nodeToReplace.name) return node;
|
|
29590
|
-
return ts2.factory.createVariableStatement(
|
|
29591
|
-
nodeToReplace.modifiers,
|
|
29592
|
-
ts2.factory.createVariableDeclarationList(
|
|
29593
|
-
[ts2.factory.createVariableDeclaration(
|
|
29594
|
-
nodeToReplace.name,
|
|
29595
|
-
void 0,
|
|
29596
|
-
void 0,
|
|
29597
|
-
node
|
|
29598
|
-
)],
|
|
29599
|
-
ts2.NodeFlags.Const
|
|
29600
|
-
)
|
|
29601
|
-
);
|
|
29602
|
-
} else if (ts2.isMethodDeclaration(nodeToReplace)) {
|
|
29603
|
-
return ts2.factory.createPropertyDeclaration(
|
|
29604
|
-
nodeToReplace.modifiers,
|
|
29605
|
-
nodeToReplace.name,
|
|
29606
|
-
void 0,
|
|
29607
|
-
void 0,
|
|
29608
|
-
node
|
|
29609
|
-
);
|
|
29653
|
+
ts2.forEachChild(node, appendNodeToVisit);
|
|
29654
|
+
continue;
|
|
29655
|
+
} else if (ts2.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts2.isExpression(node.body)) {
|
|
29656
|
+
const body = node.body;
|
|
29657
|
+
const expectedType = typeChecker.getContextualType(body);
|
|
29658
|
+
const realType = typeChecker.getTypeAtLocation(body);
|
|
29659
|
+
if (expectedType) {
|
|
29660
|
+
result.push([body, expectedType, body, realType]);
|
|
29661
|
+
}
|
|
29662
|
+
ts2.forEachChild(body, appendNodeToVisit);
|
|
29663
|
+
continue;
|
|
29664
|
+
} else if (ts2.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts2.isExpression(node.body)) {
|
|
29665
|
+
const body = node.body;
|
|
29666
|
+
const expectedType = yield* option4(getInferredReturnType(node));
|
|
29667
|
+
const realType = typeChecker.getTypeAtLocation(body);
|
|
29668
|
+
if (isSome2(expectedType)) {
|
|
29669
|
+
result.push([body, expectedType.value, body, realType]);
|
|
29670
|
+
}
|
|
29671
|
+
ts2.forEachChild(body, appendNodeToVisit);
|
|
29672
|
+
continue;
|
|
29673
|
+
} else if (ts2.isSatisfiesExpression(node)) {
|
|
29674
|
+
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
29675
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
29676
|
+
result.push([node.expression, expectedType, node.expression, realType]);
|
|
29677
|
+
appendNodeToVisit(node.expression);
|
|
29678
|
+
continue;
|
|
29679
|
+
}
|
|
29680
|
+
ts2.forEachChild(node, appendNodeToVisit);
|
|
29610
29681
|
}
|
|
29611
|
-
return
|
|
29612
|
-
}
|
|
29682
|
+
return result;
|
|
29683
|
+
}),
|
|
29684
|
+
"TypeCheckerApi.expectedAndRealType",
|
|
29685
|
+
(sourceFile) => sourceFile
|
|
29613
29686
|
);
|
|
29614
|
-
var
|
|
29615
|
-
|
|
29616
|
-
|
|
29617
|
-
|
|
29618
|
-
const
|
|
29619
|
-
|
|
29620
|
-
|
|
29621
|
-
let accessedObject = precedingToken;
|
|
29622
|
-
let replacementSpan = ts2.createTextSpan(position, 0);
|
|
29623
|
-
let outerNode = precedingToken;
|
|
29624
|
-
if (ts2.isIdentifier(precedingToken) && precedingToken.parent && ts2.isPropertyAccessExpression(precedingToken.parent)) {
|
|
29625
|
-
replacementSpan = ts2.createTextSpan(
|
|
29626
|
-
precedingToken.parent.getStart(sourceFile),
|
|
29627
|
-
precedingToken.end - precedingToken.parent.getStart(sourceFile)
|
|
29628
|
-
);
|
|
29629
|
-
accessedObject = precedingToken.parent.expression;
|
|
29630
|
-
outerNode = precedingToken.parent;
|
|
29631
|
-
} else if (ts2.isToken(precedingToken) && precedingToken.kind === ts2.SyntaxKind.DotToken && ts2.isPropertyAccessExpression(precedingToken.parent)) {
|
|
29632
|
-
replacementSpan = ts2.createTextSpan(
|
|
29633
|
-
precedingToken.parent.getStart(sourceFile),
|
|
29634
|
-
precedingToken.end - precedingToken.parent.getStart(sourceFile)
|
|
29635
|
-
);
|
|
29636
|
-
accessedObject = precedingToken.parent.expression;
|
|
29637
|
-
outerNode = precedingToken.parent;
|
|
29638
|
-
} else if (ts2.isIdentifier(precedingToken) && precedingToken.parent) {
|
|
29639
|
-
replacementSpan = ts2.createTextSpan(
|
|
29640
|
-
precedingToken.getStart(sourceFile),
|
|
29641
|
-
precedingToken.end - precedingToken.getStart(sourceFile)
|
|
29642
|
-
);
|
|
29643
|
-
accessedObject = precedingToken;
|
|
29644
|
-
outerNode = precedingToken;
|
|
29687
|
+
var unrollUnionMembers = (type2) => {
|
|
29688
|
+
const result = [];
|
|
29689
|
+
let toTest = [type2];
|
|
29690
|
+
while (toTest.length > 0) {
|
|
29691
|
+
const type3 = toTest.pop();
|
|
29692
|
+
if (type3.isUnion()) {
|
|
29693
|
+
toTest = toTest.concat(type3.types);
|
|
29645
29694
|
} else {
|
|
29646
|
-
|
|
29695
|
+
result.push(type3);
|
|
29647
29696
|
}
|
|
29648
|
-
return { accessedObject, outerNode, replacementSpan };
|
|
29649
29697
|
}
|
|
29650
|
-
|
|
29651
|
-
|
|
29652
|
-
|
|
29653
|
-
|
|
29654
|
-
|
|
29655
|
-
|
|
29656
|
-
|
|
29657
|
-
|
|
29658
|
-
|
|
29659
|
-
|
|
29660
|
-
|
|
29661
|
-
|
|
29662
|
-
|
|
29663
|
-
|
|
29664
|
-
|
|
29665
|
-
|
|
29666
|
-
|
|
29667
|
-
|
|
29668
|
-
|
|
29669
|
-
|
|
29670
|
-
|
|
29671
|
-
|
|
29672
|
-
|
|
29673
|
-
|
|
29674
|
-
|
|
29675
|
-
|
|
29676
|
-
|
|
29677
|
-
|
|
29678
|
-
|
|
29679
|
-
|
|
29680
|
-
|
|
29681
|
-
|
|
29682
|
-
|
|
29683
|
-
|
|
29684
|
-
|
|
29685
|
-
|
|
29686
|
-
|
|
29687
|
-
|
|
29688
|
-
|
|
29689
|
-
|
|
29690
|
-
|
|
29691
|
-
|
|
29692
|
-
[generator]
|
|
29693
|
-
);
|
|
29694
|
-
});
|
|
29695
|
-
var createEffectGenCallExpressionWithBlock = fn(
|
|
29696
|
-
"AST.createEffectGenCallExpressionWithBlock"
|
|
29697
|
-
)(function* (effectModuleIdentifierName, statement) {
|
|
29698
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29699
|
-
return yield* createEffectGenCallExpression(
|
|
29700
|
-
effectModuleIdentifierName,
|
|
29701
|
-
ts2.factory.createBlock(Array.isArray(statement) ? statement : [statement], false)
|
|
29702
|
-
);
|
|
29703
|
-
});
|
|
29704
|
-
var createReturnYieldStarStatement = fn("AST.createReturnYieldStarStatement")(
|
|
29705
|
-
function* (expr) {
|
|
29706
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29707
|
-
return ts2.factory.createReturnStatement(
|
|
29708
|
-
ts2.factory.createYieldExpression(
|
|
29709
|
-
ts2.factory.createToken(ts2.SyntaxKind.AsteriskToken),
|
|
29710
|
-
expr
|
|
29698
|
+
return result;
|
|
29699
|
+
};
|
|
29700
|
+
var appendToUniqueTypesMap = fn(
|
|
29701
|
+
"TypeCheckerApi.appendToUniqueTypesMap"
|
|
29702
|
+
)(
|
|
29703
|
+
function* (memory, initialType, shouldExclude) {
|
|
29704
|
+
const typeChecker = yield* service2(TypeCheckerApi);
|
|
29705
|
+
const newIndexes = /* @__PURE__ */ new Set();
|
|
29706
|
+
const knownIndexes = /* @__PURE__ */ new Set();
|
|
29707
|
+
let toTest = [initialType];
|
|
29708
|
+
while (toTest.length > 0) {
|
|
29709
|
+
const type2 = toTest.pop();
|
|
29710
|
+
if (!type2) break;
|
|
29711
|
+
if (yield* shouldExclude(type2)) {
|
|
29712
|
+
continue;
|
|
29713
|
+
}
|
|
29714
|
+
if (type2.isUnion()) {
|
|
29715
|
+
toTest = toTest.concat(type2.types);
|
|
29716
|
+
} else {
|
|
29717
|
+
const foundMatch = [];
|
|
29718
|
+
for (const [typeId, knownType] of memory.entries()) {
|
|
29719
|
+
const areSame = typeChecker.isTypeAssignableTo(knownType, type2) && typeChecker.isTypeAssignableTo(type2, knownType);
|
|
29720
|
+
if (areSame) {
|
|
29721
|
+
foundMatch.push(typeId);
|
|
29722
|
+
break;
|
|
29723
|
+
}
|
|
29724
|
+
}
|
|
29725
|
+
if (foundMatch.length === 0) {
|
|
29726
|
+
const newId = "t" + (memory.size + 1);
|
|
29727
|
+
memory.set(newId, type2);
|
|
29728
|
+
newIndexes.add(newId);
|
|
29729
|
+
} else {
|
|
29730
|
+
knownIndexes.add(foundMatch[0]);
|
|
29731
|
+
}
|
|
29732
|
+
}
|
|
29733
|
+
}
|
|
29734
|
+
return {
|
|
29735
|
+
newIndexes,
|
|
29736
|
+
knownIndexes,
|
|
29737
|
+
allIndexes: pipe(
|
|
29738
|
+
fromIterable(newIndexes),
|
|
29739
|
+
appendAll(fromIterable(knownIndexes))
|
|
29711
29740
|
)
|
|
29712
|
-
|
|
29741
|
+
};
|
|
29713
29742
|
}
|
|
29714
29743
|
);
|
|
29744
|
+
function makeResolveExternalModuleName(typeChecker) {
|
|
29745
|
+
if (!(hasProperty(typeChecker, "resolveExternalModuleName") && isFunction(typeChecker.resolveExternalModuleName))) {
|
|
29746
|
+
return;
|
|
29747
|
+
}
|
|
29748
|
+
const _internal = typeChecker.resolveExternalModuleName;
|
|
29749
|
+
return (moduleSpecifier) => {
|
|
29750
|
+
return _internal(moduleSpecifier);
|
|
29751
|
+
};
|
|
29752
|
+
}
|
|
29715
29753
|
|
|
29716
29754
|
// src/core/TypeParser.ts
|
|
29717
29755
|
var TypeParser = Tag4("@effect/language-service/TypeParser");
|
|
29756
|
+
var nanoLayer2 = (fa) => gen3(function* () {
|
|
29757
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
29758
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
29759
|
+
const typeChecker = yield* service2(TypeCheckerApi);
|
|
29760
|
+
return yield* pipe(
|
|
29761
|
+
fa,
|
|
29762
|
+
provideService7(TypeParser, make64(ts2, tsUtils, typeChecker))
|
|
29763
|
+
);
|
|
29764
|
+
});
|
|
29718
29765
|
var TypeParserIssue = class _TypeParserIssue {
|
|
29719
29766
|
_tag = "@effect/language-service/TypeParserIssue";
|
|
29720
29767
|
static issue = fail18(new _TypeParserIssue());
|
|
@@ -29722,7 +29769,7 @@ var TypeParserIssue = class _TypeParserIssue {
|
|
|
29722
29769
|
function typeParserIssue(_message, _type, _node) {
|
|
29723
29770
|
return TypeParserIssue.issue;
|
|
29724
29771
|
}
|
|
29725
|
-
function make64(ts2, typeChecker) {
|
|
29772
|
+
function make64(ts2, tsUtils, typeChecker) {
|
|
29726
29773
|
function covariantTypeArgument(type2) {
|
|
29727
29774
|
const signatures = type2.getCallSignatures();
|
|
29728
29775
|
if (signatures.length !== 1) {
|
|
@@ -30064,15 +30111,11 @@ function make64(ts2, typeChecker) {
|
|
|
30064
30111
|
if (!explicitReturn && !(successType.flags & ts2.TypeFlags.VoidLike)) {
|
|
30065
30112
|
replacementNode = pipe(
|
|
30066
30113
|
gen3(function* () {
|
|
30067
|
-
const effectIdentifier =
|
|
30068
|
-
|
|
30069
|
-
|
|
30070
|
-
|
|
30071
|
-
|
|
30072
|
-
onNone: () => "Effect",
|
|
30073
|
-
onSome: (_) => _.text
|
|
30074
|
-
})
|
|
30075
|
-
);
|
|
30114
|
+
const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
30115
|
+
node.getSourceFile(),
|
|
30116
|
+
"effect",
|
|
30117
|
+
"Effect"
|
|
30118
|
+
) || "Effect";
|
|
30076
30119
|
return ts2.factory.createCallExpression(
|
|
30077
30120
|
ts2.factory.createPropertyAccessExpression(
|
|
30078
30121
|
ts2.factory.createIdentifier(effectIdentifier),
|
|
@@ -30240,6 +30283,64 @@ function make64(ts2, typeChecker) {
|
|
|
30240
30283
|
"TypeParser.promiseLike",
|
|
30241
30284
|
(type2) => type2
|
|
30242
30285
|
);
|
|
30286
|
+
const extendsEffectService = cachedBy(
|
|
30287
|
+
fn("TypeParser.extendsEffectService")(function* (atLocation) {
|
|
30288
|
+
if (!atLocation.name) {
|
|
30289
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
30290
|
+
}
|
|
30291
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
30292
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
30293
|
+
const type2 = typeChecker.getTypeOfSymbol(classSym);
|
|
30294
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
30295
|
+
if (!heritageClauses) {
|
|
30296
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
30297
|
+
}
|
|
30298
|
+
for (const heritageClause of heritageClauses) {
|
|
30299
|
+
for (const typeX of heritageClause.types) {
|
|
30300
|
+
if (ts2.isExpressionWithTypeArguments(typeX)) {
|
|
30301
|
+
const wholeCall = typeX.expression;
|
|
30302
|
+
if (ts2.isCallExpression(wholeCall)) {
|
|
30303
|
+
const effectServiceCall = wholeCall.expression;
|
|
30304
|
+
if (ts2.isCallExpression(effectServiceCall) && effectServiceCall.typeArguments && effectServiceCall.typeArguments.length > 0) {
|
|
30305
|
+
const effectServiceIdentifier = effectServiceCall.expression;
|
|
30306
|
+
const selfTypeNode = effectServiceCall.typeArguments[0];
|
|
30307
|
+
if (ts2.isPropertyAccessExpression(effectServiceIdentifier) && ts2.isIdentifier(effectServiceIdentifier.name) && effectServiceIdentifier.name.text === "Service") {
|
|
30308
|
+
const parsedContextTag = yield* pipe(
|
|
30309
|
+
importedEffectModule(effectServiceIdentifier.expression),
|
|
30310
|
+
flatMap18(() => contextTag(type2, atLocation)),
|
|
30311
|
+
option4
|
|
30312
|
+
);
|
|
30313
|
+
if (isSome2(parsedContextTag)) {
|
|
30314
|
+
let accessors2 = void 0;
|
|
30315
|
+
if (wholeCall.arguments.length >= 2) {
|
|
30316
|
+
const args3 = wholeCall.arguments[1];
|
|
30317
|
+
if (ts2.isObjectLiteralExpression(args3)) {
|
|
30318
|
+
for (const property of args3.properties) {
|
|
30319
|
+
if (ts2.isPropertyAssignment(property) && property.name && ts2.isIdentifier(property.name) && property.name.text === "accessors" && property.initializer && property.initializer.kind === ts2.SyntaxKind.TrueKeyword) {
|
|
30320
|
+
accessors2 = true;
|
|
30321
|
+
}
|
|
30322
|
+
}
|
|
30323
|
+
}
|
|
30324
|
+
}
|
|
30325
|
+
return {
|
|
30326
|
+
...parsedContextTag.value,
|
|
30327
|
+
className: atLocation.name,
|
|
30328
|
+
selfTypeNode,
|
|
30329
|
+
args: wholeCall.arguments,
|
|
30330
|
+
accessors: accessors2
|
|
30331
|
+
};
|
|
30332
|
+
}
|
|
30333
|
+
}
|
|
30334
|
+
}
|
|
30335
|
+
}
|
|
30336
|
+
}
|
|
30337
|
+
}
|
|
30338
|
+
}
|
|
30339
|
+
return yield* typeParserIssue("Class does not extend Effect.Service", void 0, atLocation);
|
|
30340
|
+
}),
|
|
30341
|
+
"TypeParser.extendsEffectService",
|
|
30342
|
+
(atLocation) => atLocation
|
|
30343
|
+
);
|
|
30243
30344
|
return {
|
|
30244
30345
|
effectType,
|
|
30245
30346
|
strictEffectType,
|
|
@@ -30256,7 +30357,8 @@ function make64(ts2, typeChecker) {
|
|
|
30256
30357
|
pipeableType,
|
|
30257
30358
|
pipeCall,
|
|
30258
30359
|
scopeType,
|
|
30259
|
-
promiseLike
|
|
30360
|
+
promiseLike,
|
|
30361
|
+
extendsEffectService
|
|
30260
30362
|
};
|
|
30261
30363
|
}
|
|
30262
30364
|
|
|
@@ -30269,6 +30371,7 @@ var duplicatePackage = createDiagnostic({
|
|
|
30269
30371
|
severity: "warning",
|
|
30270
30372
|
apply: fn("duplicatePackage.apply")(function* (sourceFile, report) {
|
|
30271
30373
|
const program = yield* service2(TypeScriptProgram);
|
|
30374
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
30272
30375
|
const options3 = yield* service2(LanguageServicePluginOptions);
|
|
30273
30376
|
if (sourceFile.statements.length < 1) return;
|
|
30274
30377
|
let resolvedPackages = checkedPackagesCache.get(sourceFile.fileName) || {};
|
|
@@ -30278,7 +30381,7 @@ var duplicatePackage = createDiagnostic({
|
|
|
30278
30381
|
const seenPackages = /* @__PURE__ */ new Set();
|
|
30279
30382
|
resolvedPackages = {};
|
|
30280
30383
|
program.getSourceFiles().map((_) => {
|
|
30281
|
-
const packageInfo = parsePackageContentNameAndVersionFromScope(_);
|
|
30384
|
+
const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(_);
|
|
30282
30385
|
if (!packageInfo) return;
|
|
30283
30386
|
const packageNameAndVersion = packageInfo.name + "@" + packageInfo.version;
|
|
30284
30387
|
if (seenPackages.has(packageNameAndVersion)) return;
|
|
@@ -30295,7 +30398,7 @@ var duplicatePackage = createDiagnostic({
|
|
|
30295
30398
|
if (Object.keys(resolvedPackages[packageName]).length > 1) {
|
|
30296
30399
|
const versions = Object.keys(resolvedPackages[packageName]);
|
|
30297
30400
|
report({
|
|
30298
|
-
|
|
30401
|
+
location: sourceFile.statements[0],
|
|
30299
30402
|
messageText: `Package ${packageName} is referenced multiple times with different versions (${versions.join(", ")}) and may cause unexpected type errors.
|
|
30300
30403
|
Cleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.
|
|
30301
30404
|
If this is intended set the LSP config "allowedDuplicatedPackages" to ${JSON.stringify(options3.allowedDuplicatedPackages.concat([packageName]))}.
|
|
@@ -30342,7 +30445,7 @@ var effectInVoidSuccess = createDiagnostic({
|
|
|
30342
30445
|
map33(({ voidedEffect }) => {
|
|
30343
30446
|
report(
|
|
30344
30447
|
{
|
|
30345
|
-
node,
|
|
30448
|
+
location: node,
|
|
30346
30449
|
messageText: `There is a nested '${typeChecker.typeToString(voidedEffect)}' in the 'void' success channel, beware that this could lead to nested Effect<Effect<...>> that won't be executed.`,
|
|
30347
30450
|
fixes: []
|
|
30348
30451
|
}
|
|
@@ -30391,7 +30494,7 @@ var floatingEffect = createDiagnostic({
|
|
|
30391
30494
|
);
|
|
30392
30495
|
if (isNone2(allowedFloatingEffects)) {
|
|
30393
30496
|
report({
|
|
30394
|
-
node,
|
|
30497
|
+
location: node,
|
|
30395
30498
|
messageText: `Effect must be yielded or assigned to a variable.`,
|
|
30396
30499
|
fixes: []
|
|
30397
30500
|
});
|
|
@@ -30434,7 +30537,7 @@ var genericEffectServices = createDiagnostic({
|
|
|
30434
30537
|
typeParser.contextTag(type2, node),
|
|
30435
30538
|
map33(() => {
|
|
30436
30539
|
report({
|
|
30437
|
-
|
|
30540
|
+
location: reportAt,
|
|
30438
30541
|
messageText: `Effect Services with type parameters are not supported because they cannot be properly discriminated at runtime, which may cause unexpected behavior.`,
|
|
30439
30542
|
fixes: []
|
|
30440
30543
|
});
|
|
@@ -30456,17 +30559,16 @@ var importFromBarrel = createDiagnostic({
|
|
|
30456
30559
|
const languageServicePluginOptions = yield* service2(LanguageServicePluginOptions);
|
|
30457
30560
|
if (languageServicePluginOptions.namespaceImportPackages.length === 0) return;
|
|
30458
30561
|
const ts2 = yield* service2(TypeScriptApi);
|
|
30562
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
30459
30563
|
const typeChecker = yield* service2(TypeCheckerApi);
|
|
30460
30564
|
const program = yield* service2(TypeScriptProgram);
|
|
30461
30565
|
const packageNamesToCheck = flatten(
|
|
30462
|
-
|
|
30463
|
-
|
|
30464
|
-
(packageName) => resolveModulePattern(sourceFile, packageName)
|
|
30465
|
-
)
|
|
30566
|
+
languageServicePluginOptions.namespaceImportPackages.map(
|
|
30567
|
+
(packageName) => tsUtils.resolveModulePattern(sourceFile, packageName)
|
|
30466
30568
|
)
|
|
30467
30569
|
);
|
|
30468
30570
|
const isImportedFromBarrelExport = (element) => {
|
|
30469
|
-
const getModuleSpecifier = makeGetModuleSpecifier(
|
|
30571
|
+
const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
|
|
30470
30572
|
const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
|
|
30471
30573
|
if (!(getModuleSpecifier && resolveExternalModuleName)) return;
|
|
30472
30574
|
const importDeclaration = ts2.findAncestor(element, (node) => ts2.isImportDeclaration(node));
|
|
@@ -30542,7 +30644,7 @@ var importFromBarrel = createDiagnostic({
|
|
|
30542
30644
|
unbarrelledFileName
|
|
30543
30645
|
} = result;
|
|
30544
30646
|
report({
|
|
30545
|
-
node,
|
|
30647
|
+
location: node,
|
|
30546
30648
|
messageText: `Importing from barrel module ${barrelModuleName} is not allowed.`,
|
|
30547
30649
|
fixes: [
|
|
30548
30650
|
{
|
|
@@ -30656,7 +30758,7 @@ var leakingRequirements = createDiagnostic({
|
|
|
30656
30758
|
function reportLeakingRequirements(node, requirements) {
|
|
30657
30759
|
if (requirements.length === 0) return;
|
|
30658
30760
|
report({
|
|
30659
|
-
node,
|
|
30761
|
+
location: node,
|
|
30660
30762
|
messageText: `This Service is leaking the ${requirements.map((_) => typeChecker.typeToString(_)).join(" | ")} requirement.
|
|
30661
30763
|
If these requirements cannot be cached and are expected to be provided per method invocation (e.g. HttpServerRequest), you can safely disable this diagnostic for this line through quickfixes.
|
|
30662
30764
|
More info at https://effect.website/docs/requirements-management/layers/#avoiding-requirement-leakage`,
|
|
@@ -30736,7 +30838,7 @@ var missingEffectContext = createDiagnostic({
|
|
|
30736
30838
|
map33(
|
|
30737
30839
|
(missingTypes) => missingTypes.length > 0 ? report(
|
|
30738
30840
|
{
|
|
30739
|
-
node,
|
|
30841
|
+
location: node,
|
|
30740
30842
|
messageText: `Missing '${sortTypes(missingTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect context.`,
|
|
30741
30843
|
fixes: []
|
|
30742
30844
|
}
|
|
@@ -30756,18 +30858,15 @@ var missingEffectError = createDiagnostic({
|
|
|
30756
30858
|
severity: "error",
|
|
30757
30859
|
apply: fn("missingEffectError.apply")(function* (sourceFile, report) {
|
|
30758
30860
|
const ts2 = yield* service2(TypeScriptApi);
|
|
30861
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
30759
30862
|
const typeChecker = yield* service2(TypeCheckerApi);
|
|
30760
30863
|
const typeParser = yield* service2(TypeParser);
|
|
30761
30864
|
const typeOrder = yield* deterministicTypeOrder;
|
|
30762
|
-
const effectModuleIdentifier =
|
|
30763
|
-
|
|
30764
|
-
|
|
30765
|
-
|
|
30766
|
-
|
|
30767
|
-
),
|
|
30768
|
-
map33((_) => _.text),
|
|
30769
|
-
orElse14(() => succeed17("Effect"))
|
|
30770
|
-
);
|
|
30865
|
+
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
30866
|
+
sourceFile,
|
|
30867
|
+
"effect",
|
|
30868
|
+
"Effect"
|
|
30869
|
+
) || "Effect";
|
|
30771
30870
|
const createDieMessage = (message) => ts2.factory.createCallExpression(
|
|
30772
30871
|
ts2.factory.createPropertyAccessExpression(
|
|
30773
30872
|
ts2.factory.createIdentifier(effectModuleIdentifier),
|
|
@@ -30869,7 +30968,7 @@ var missingEffectError = createDiagnostic({
|
|
|
30869
30968
|
}
|
|
30870
30969
|
report(
|
|
30871
30970
|
{
|
|
30872
|
-
node,
|
|
30971
|
+
location: node,
|
|
30873
30972
|
messageText: `Missing '${sortTypes(result.missingErrorTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect errors.`,
|
|
30874
30973
|
fixes
|
|
30875
30974
|
}
|
|
@@ -30933,7 +31032,7 @@ var missingReturnYieldStar = createDiagnostic({
|
|
|
30933
31032
|
})
|
|
30934
31033
|
}] : [];
|
|
30935
31034
|
report({
|
|
30936
|
-
node,
|
|
31035
|
+
location: node,
|
|
30937
31036
|
messageText: `Yielded Effect never succeeds, so it is best to use a 'return yield*' instead.`,
|
|
30938
31037
|
fixes: fix
|
|
30939
31038
|
});
|
|
@@ -30989,7 +31088,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
30989
31088
|
}
|
|
30990
31089
|
brokenGenerators.forEach(
|
|
30991
31090
|
(node) => report({
|
|
30992
|
-
node,
|
|
31091
|
+
location: node,
|
|
30993
31092
|
messageText: `Seems like you used yield instead of yield* inside this Effect.gen.`,
|
|
30994
31093
|
fixes: []
|
|
30995
31094
|
})
|
|
@@ -31011,7 +31110,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
31011
31110
|
})
|
|
31012
31111
|
}] : [];
|
|
31013
31112
|
report({
|
|
31014
|
-
node,
|
|
31113
|
+
location: node,
|
|
31015
31114
|
messageText: `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`,
|
|
31016
31115
|
fixes: fix
|
|
31017
31116
|
});
|
|
@@ -31026,26 +31125,19 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
31026
31125
|
severity: "warning",
|
|
31027
31126
|
apply: fn("multipleEffectProvide.apply")(function* (sourceFile, report) {
|
|
31028
31127
|
const ts2 = yield* service2(TypeScriptApi);
|
|
31128
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
31029
31129
|
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31030
31130
|
const typeParser = yield* service2(TypeParser);
|
|
31031
|
-
const effectModuleIdentifier =
|
|
31032
|
-
|
|
31033
|
-
|
|
31034
|
-
|
|
31035
|
-
|
|
31036
|
-
|
|
31037
|
-
|
|
31038
|
-
|
|
31039
|
-
|
|
31040
|
-
|
|
31041
|
-
findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
31042
|
-
sourceFile,
|
|
31043
|
-
"effect",
|
|
31044
|
-
"Layer"
|
|
31045
|
-
),
|
|
31046
|
-
map33((_) => _.text),
|
|
31047
|
-
orElse14(() => succeed17("Layer"))
|
|
31048
|
-
);
|
|
31131
|
+
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
31132
|
+
sourceFile,
|
|
31133
|
+
"effect",
|
|
31134
|
+
"Effect"
|
|
31135
|
+
) || "Effect";
|
|
31136
|
+
const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
31137
|
+
sourceFile,
|
|
31138
|
+
"effect",
|
|
31139
|
+
"Layer"
|
|
31140
|
+
) || "Layer";
|
|
31049
31141
|
const parseEffectProvideLayer = (node) => {
|
|
31050
31142
|
if (ts2.isCallExpression(node) && ts2.isPropertyAccessExpression(node.expression) && ts2.isIdentifier(node.expression.name) && node.expression.name.text === "provide" && node.arguments.length > 0) {
|
|
31051
31143
|
const layer12 = node.arguments[0];
|
|
@@ -31075,7 +31167,7 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
31075
31167
|
for (const chunk4 of previousLayers) {
|
|
31076
31168
|
if (chunk4.length < 2) continue;
|
|
31077
31169
|
report({
|
|
31078
|
-
|
|
31170
|
+
location: chunk4[0].node,
|
|
31079
31171
|
messageText: "Avoid chaining Effect.provide calls, as this can lead to service lifecycle issues. Instead, merge layers and provide them in a single call.",
|
|
31080
31172
|
fixes: [{
|
|
31081
31173
|
fixName: "multipleEffectProvide_fix",
|
|
@@ -31123,6 +31215,327 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
31123
31215
|
})
|
|
31124
31216
|
});
|
|
31125
31217
|
|
|
31218
|
+
// src/refactors/writeTagClassAccessors.ts
|
|
31219
|
+
var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, service3, className, atLocation, involvedMembers) {
|
|
31220
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
31221
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
31222
|
+
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31223
|
+
const typeParser = yield* service2(TypeParser);
|
|
31224
|
+
const changeTracker = yield* service2(ChangeTracker);
|
|
31225
|
+
const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.getEnd() - 1;
|
|
31226
|
+
const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
31227
|
+
sourceFile,
|
|
31228
|
+
"effect",
|
|
31229
|
+
"Effect"
|
|
31230
|
+
) || "Effect";
|
|
31231
|
+
const createFunctionProperty = (className2, propertyName, type2, forceAny) => {
|
|
31232
|
+
const arrowBody = ts2.factory.createCallExpression(
|
|
31233
|
+
ts2.factory.createPropertyAccessExpression(
|
|
31234
|
+
ts2.factory.createIdentifier(effectIdentifier),
|
|
31235
|
+
"andThen"
|
|
31236
|
+
),
|
|
31237
|
+
void 0,
|
|
31238
|
+
[
|
|
31239
|
+
ts2.factory.createIdentifier(className2.text),
|
|
31240
|
+
ts2.factory.createArrowFunction(
|
|
31241
|
+
void 0,
|
|
31242
|
+
void 0,
|
|
31243
|
+
[ts2.factory.createParameterDeclaration(
|
|
31244
|
+
void 0,
|
|
31245
|
+
void 0,
|
|
31246
|
+
"_",
|
|
31247
|
+
void 0,
|
|
31248
|
+
forceAny ? ts2.factory.createTypeReferenceNode("any") : void 0
|
|
31249
|
+
)],
|
|
31250
|
+
void 0,
|
|
31251
|
+
void 0,
|
|
31252
|
+
ts2.factory.createCallExpression(
|
|
31253
|
+
ts2.factory.createPropertyAccessExpression(
|
|
31254
|
+
ts2.factory.createIdentifier("_"),
|
|
31255
|
+
propertyName
|
|
31256
|
+
),
|
|
31257
|
+
void 0,
|
|
31258
|
+
[
|
|
31259
|
+
ts2.factory.createSpreadElement(ts2.factory.createIdentifier("args"))
|
|
31260
|
+
]
|
|
31261
|
+
)
|
|
31262
|
+
)
|
|
31263
|
+
]
|
|
31264
|
+
);
|
|
31265
|
+
return ts2.factory.createPropertyDeclaration(
|
|
31266
|
+
[ts2.factory.createModifier(ts2.SyntaxKind.StaticKeyword)],
|
|
31267
|
+
propertyName,
|
|
31268
|
+
void 0,
|
|
31269
|
+
type2,
|
|
31270
|
+
ts2.factory.createArrowFunction(
|
|
31271
|
+
void 0,
|
|
31272
|
+
void 0,
|
|
31273
|
+
[ts2.factory.createParameterDeclaration(
|
|
31274
|
+
void 0,
|
|
31275
|
+
ts2.factory.createToken(ts2.SyntaxKind.DotDotDotToken),
|
|
31276
|
+
"args",
|
|
31277
|
+
void 0,
|
|
31278
|
+
forceAny ? ts2.factory.createArrayTypeNode(ts2.factory.createTypeReferenceNode("any")) : void 0
|
|
31279
|
+
)],
|
|
31280
|
+
void 0,
|
|
31281
|
+
void 0,
|
|
31282
|
+
forceAny ? ts2.factory.createAsExpression(arrowBody, ts2.factory.createTypeReferenceNode("any")) : arrowBody
|
|
31283
|
+
)
|
|
31284
|
+
);
|
|
31285
|
+
};
|
|
31286
|
+
const generateReturnType = (type2, atLocation2, className2) => pipe(
|
|
31287
|
+
typeParser.effectType(type2, atLocation2),
|
|
31288
|
+
flatMap18((returnedEffect) => {
|
|
31289
|
+
const contextType = returnedEffect.R.flags & ts2.TypeFlags.Never ? ts2.factory.createTypeReferenceNode(className2.text) : ts2.factory.createUnionTypeNode(
|
|
31290
|
+
[
|
|
31291
|
+
ts2.factory.createTypeReferenceNode(className2.text),
|
|
31292
|
+
typeChecker.typeToTypeNode(returnedEffect.R, atLocation2, ts2.NodeBuilderFlags.NoTruncation)
|
|
31293
|
+
]
|
|
31294
|
+
);
|
|
31295
|
+
const successType = typeChecker.typeToTypeNode(
|
|
31296
|
+
returnedEffect.A,
|
|
31297
|
+
atLocation2,
|
|
31298
|
+
ts2.NodeBuilderFlags.NoTruncation
|
|
31299
|
+
);
|
|
31300
|
+
if (!successType) return fail18("error generating success type");
|
|
31301
|
+
const failureType = typeChecker.typeToTypeNode(
|
|
31302
|
+
returnedEffect.E,
|
|
31303
|
+
atLocation2,
|
|
31304
|
+
ts2.NodeBuilderFlags.NoTruncation
|
|
31305
|
+
);
|
|
31306
|
+
if (!failureType) return fail18("error generating failure type");
|
|
31307
|
+
const typeNode = ts2.factory.createTypeReferenceNode(
|
|
31308
|
+
ts2.factory.createQualifiedName(
|
|
31309
|
+
ts2.factory.createIdentifier(effectIdentifier),
|
|
31310
|
+
ts2.factory.createIdentifier("Effect")
|
|
31311
|
+
),
|
|
31312
|
+
[successType, failureType, contextType]
|
|
31313
|
+
);
|
|
31314
|
+
return succeed17(typeNode);
|
|
31315
|
+
}),
|
|
31316
|
+
orElse14(
|
|
31317
|
+
() => pipe(
|
|
31318
|
+
typeParser.promiseLike(type2, atLocation2),
|
|
31319
|
+
flatMap18(({ type: type3 }) => {
|
|
31320
|
+
const successType = typeChecker.typeToTypeNode(
|
|
31321
|
+
type3,
|
|
31322
|
+
atLocation2,
|
|
31323
|
+
ts2.NodeBuilderFlags.NoTruncation
|
|
31324
|
+
);
|
|
31325
|
+
if (!successType) return fail18("error generating success type");
|
|
31326
|
+
return succeed17(ts2.factory.createTypeReferenceNode(
|
|
31327
|
+
ts2.factory.createQualifiedName(
|
|
31328
|
+
ts2.factory.createIdentifier(effectIdentifier),
|
|
31329
|
+
ts2.factory.createIdentifier("Effect")
|
|
31330
|
+
),
|
|
31331
|
+
[
|
|
31332
|
+
successType,
|
|
31333
|
+
ts2.factory.createTypeReferenceNode(
|
|
31334
|
+
ts2.factory.createQualifiedName(
|
|
31335
|
+
ts2.factory.createIdentifier("Cause"),
|
|
31336
|
+
ts2.factory.createIdentifier("UnknownException")
|
|
31337
|
+
)
|
|
31338
|
+
),
|
|
31339
|
+
ts2.factory.createTypeReferenceNode(className2.text)
|
|
31340
|
+
]
|
|
31341
|
+
));
|
|
31342
|
+
})
|
|
31343
|
+
)
|
|
31344
|
+
),
|
|
31345
|
+
orElse14(() => {
|
|
31346
|
+
const successType = typeChecker.typeToTypeNode(type2, atLocation2, ts2.NodeBuilderFlags.NoTruncation);
|
|
31347
|
+
if (!successType) return fail18("error generating success type");
|
|
31348
|
+
const typeNode = ts2.factory.createTypeReferenceNode(
|
|
31349
|
+
ts2.factory.createQualifiedName(
|
|
31350
|
+
ts2.factory.createIdentifier(effectIdentifier),
|
|
31351
|
+
ts2.factory.createIdentifier("Effect")
|
|
31352
|
+
),
|
|
31353
|
+
[
|
|
31354
|
+
successType,
|
|
31355
|
+
ts2.factory.createTypeReferenceNode("never"),
|
|
31356
|
+
ts2.factory.createTypeReferenceNode(className2.text)
|
|
31357
|
+
]
|
|
31358
|
+
);
|
|
31359
|
+
return succeed17(typeNode);
|
|
31360
|
+
})
|
|
31361
|
+
);
|
|
31362
|
+
const proxySignature = (signature, atLocation2, className2) => gen3(function* () {
|
|
31363
|
+
const signatureDeclaration = typeChecker.signatureToSignatureDeclaration(
|
|
31364
|
+
signature,
|
|
31365
|
+
ts2.SyntaxKind.FunctionType,
|
|
31366
|
+
atLocation2,
|
|
31367
|
+
ts2.NodeBuilderFlags.NoTruncation
|
|
31368
|
+
);
|
|
31369
|
+
if (!signatureDeclaration) return yield* fail18("error generating signature");
|
|
31370
|
+
const returnType = yield* generateReturnType(signature.getReturnType(), atLocation2, className2);
|
|
31371
|
+
return ts2.factory.createFunctionTypeNode(
|
|
31372
|
+
signatureDeclaration.typeParameters,
|
|
31373
|
+
signatureDeclaration.parameters,
|
|
31374
|
+
returnType
|
|
31375
|
+
);
|
|
31376
|
+
});
|
|
31377
|
+
for (const { property, propertyType } of involvedMembers) {
|
|
31378
|
+
const callSignatures = [];
|
|
31379
|
+
let propertyDeclaration = void 0;
|
|
31380
|
+
for (const signature of propertyType.getCallSignatures()) {
|
|
31381
|
+
yield* pipe(
|
|
31382
|
+
proxySignature(signature, atLocation, className),
|
|
31383
|
+
map33((sig) => {
|
|
31384
|
+
callSignatures.push(sig);
|
|
31385
|
+
}),
|
|
31386
|
+
ignore3
|
|
31387
|
+
);
|
|
31388
|
+
}
|
|
31389
|
+
const allSignatures = ts2.factory.createIntersectionTypeNode(callSignatures);
|
|
31390
|
+
const type2 = tsUtils.simplifyTypeNode(allSignatures);
|
|
31391
|
+
propertyDeclaration = createFunctionProperty(className, property.getName(), type2, callSignatures.length > 1);
|
|
31392
|
+
const oldProperty = atLocation.members.filter(ts2.isPropertyDeclaration).find((p2) => {
|
|
31393
|
+
const symbol3 = typeChecker.getSymbolAtLocation(p2.name);
|
|
31394
|
+
return symbol3?.getName() === property.getName();
|
|
31395
|
+
});
|
|
31396
|
+
if (oldProperty) {
|
|
31397
|
+
changeTracker.deleteRange(sourceFile, {
|
|
31398
|
+
pos: oldProperty.getStart(sourceFile),
|
|
31399
|
+
end: oldProperty.getEnd()
|
|
31400
|
+
});
|
|
31401
|
+
changeTracker.insertNodeAt(sourceFile, oldProperty.getStart(sourceFile), propertyDeclaration);
|
|
31402
|
+
} else {
|
|
31403
|
+
changeTracker.insertNodeAt(sourceFile, insertLocation, propertyDeclaration, { suffix: "\n" });
|
|
31404
|
+
}
|
|
31405
|
+
}
|
|
31406
|
+
});
|
|
31407
|
+
var parse5 = fn("writeTagClassAccessors.parse")(function* (node) {
|
|
31408
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
31409
|
+
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31410
|
+
const typeParser = yield* service2(TypeParser);
|
|
31411
|
+
if (!ts2.isClassDeclaration(node)) return yield* fail18("not a class declaration");
|
|
31412
|
+
const { Service, accessors: accessors2, className } = yield* pipe(
|
|
31413
|
+
typeParser.extendsEffectService(node),
|
|
31414
|
+
orElse14(() => fail18("not a class extending Effect.Service call"))
|
|
31415
|
+
);
|
|
31416
|
+
if (accessors2 !== true) return yield* fail18("accessors are not enabled in the Effect.Service call");
|
|
31417
|
+
const involvedMembers = [];
|
|
31418
|
+
for (const property of typeChecker.getPropertiesOfType(Service)) {
|
|
31419
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, node);
|
|
31420
|
+
const callSignatures = propertyType.getCallSignatures();
|
|
31421
|
+
if (callSignatures.length > 0) {
|
|
31422
|
+
const withTypeParameters = callSignatures.filter((_) => _.typeParameters && _.typeParameters.length > 0);
|
|
31423
|
+
if (callSignatures.length > 1 || withTypeParameters.length > 0) involvedMembers.push({ property, propertyType });
|
|
31424
|
+
}
|
|
31425
|
+
}
|
|
31426
|
+
const hash2 = involvedMembers.map(({ property, propertyType }) => {
|
|
31427
|
+
return property.getName() + ": " + typeChecker.typeToString(propertyType);
|
|
31428
|
+
}).concat([className.text]).join("\n");
|
|
31429
|
+
return { Service, className, atLocation: node, hash: cyrb53(hash2), involvedMembers };
|
|
31430
|
+
});
|
|
31431
|
+
var writeTagClassAccessors = createRefactor({
|
|
31432
|
+
name: "writeTagClassAccessors",
|
|
31433
|
+
description: "Implement accessors methods with generics or multiple signatures",
|
|
31434
|
+
apply: fn("writeTagClassAccessors.apply")(function* (sourceFile, textRange) {
|
|
31435
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
31436
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
31437
|
+
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31438
|
+
const typeParser = yield* service2(TypeParser);
|
|
31439
|
+
const parseNode = (node) => pipe(
|
|
31440
|
+
parse5(node),
|
|
31441
|
+
map33(({ Service, atLocation, className, involvedMembers }) => ({
|
|
31442
|
+
kind: "refactor.rewrite.effect.writeTagClassAccessors",
|
|
31443
|
+
description: "Implement Service accessors",
|
|
31444
|
+
apply: pipe(
|
|
31445
|
+
generate(sourceFile, Service, className, atLocation, involvedMembers),
|
|
31446
|
+
provideService7(TypeScriptUtils, tsUtils),
|
|
31447
|
+
provideService7(TypeParser, typeParser),
|
|
31448
|
+
provideService7(TypeCheckerApi, typeChecker),
|
|
31449
|
+
provideService7(TypeScriptApi, ts2)
|
|
31450
|
+
)
|
|
31451
|
+
}))
|
|
31452
|
+
);
|
|
31453
|
+
const parentNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange);
|
|
31454
|
+
return yield* pipe(
|
|
31455
|
+
firstSuccessOf2(parentNodes.map(parseNode)),
|
|
31456
|
+
orElse14(() => fail18(new RefactorNotApplicableError()))
|
|
31457
|
+
);
|
|
31458
|
+
})
|
|
31459
|
+
});
|
|
31460
|
+
|
|
31461
|
+
// src/codegens/accessors.ts
|
|
31462
|
+
var accessors = createCodegen({
|
|
31463
|
+
name: "accessors",
|
|
31464
|
+
apply: fn("accessors.apply")(function* (sourceFile, textRange) {
|
|
31465
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
31466
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
31467
|
+
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31468
|
+
const typeParser = yield* service2(TypeParser);
|
|
31469
|
+
const nodeAndCommentRange = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, textRange.pos);
|
|
31470
|
+
if (!nodeAndCommentRange) return yield* fail18(new CodegenNotApplicableError("no node and comment range"));
|
|
31471
|
+
return yield* pipe(
|
|
31472
|
+
parse5(nodeAndCommentRange.node),
|
|
31473
|
+
map33(
|
|
31474
|
+
(_) => ({
|
|
31475
|
+
hash: _.hash,
|
|
31476
|
+
description: "Generate accessors for the service",
|
|
31477
|
+
apply: pipe(
|
|
31478
|
+
generate(sourceFile, _.Service, _.className, _.atLocation, _.involvedMembers),
|
|
31479
|
+
provideService7(TypeScriptApi, ts2),
|
|
31480
|
+
provideService7(TypeScriptUtils, tsUtils),
|
|
31481
|
+
provideService7(TypeCheckerApi, typeChecker),
|
|
31482
|
+
provideService7(TypeParser, typeParser)
|
|
31483
|
+
)
|
|
31484
|
+
})
|
|
31485
|
+
),
|
|
31486
|
+
orElse14((cause2) => fail18(new CodegenNotApplicableError(cause2)))
|
|
31487
|
+
);
|
|
31488
|
+
})
|
|
31489
|
+
});
|
|
31490
|
+
|
|
31491
|
+
// src/codegens.ts
|
|
31492
|
+
var codegens = [accessors];
|
|
31493
|
+
|
|
31494
|
+
// src/diagnostics/outdatedEffectCodegen.ts
|
|
31495
|
+
var outdatedEffectCodegen = createDiagnostic({
|
|
31496
|
+
name: "outdatedEffectCodegen",
|
|
31497
|
+
code: 19,
|
|
31498
|
+
severity: "warning",
|
|
31499
|
+
apply: fn("outdatedEffectCodegen.apply")(function* (sourceFile, _report) {
|
|
31500
|
+
const codegensWithRanges = yield* getCodegensForSourceFile(codegens, sourceFile);
|
|
31501
|
+
for (const { codegen, hash: hash2, range: range3 } of codegensWithRanges) {
|
|
31502
|
+
yield* pipe(
|
|
31503
|
+
getEditsForCodegen([codegen], sourceFile, range3),
|
|
31504
|
+
map33((applicable) => {
|
|
31505
|
+
if (applicable.hash !== hash2) {
|
|
31506
|
+
_report({
|
|
31507
|
+
location: range3,
|
|
31508
|
+
messageText: `Codegen ${codegen.name} result is outdated`,
|
|
31509
|
+
fixes: [
|
|
31510
|
+
{
|
|
31511
|
+
fixName: "outdatedEffectCodegen_fix",
|
|
31512
|
+
description: `Re-run ${codegen.name}`,
|
|
31513
|
+
apply: applicable.apply
|
|
31514
|
+
},
|
|
31515
|
+
{
|
|
31516
|
+
fixName: "outdatedEffectCodegen_ignore",
|
|
31517
|
+
description: `Ignore this ${codegen.name} update`,
|
|
31518
|
+
apply: applicable.ignore
|
|
31519
|
+
}
|
|
31520
|
+
]
|
|
31521
|
+
});
|
|
31522
|
+
}
|
|
31523
|
+
}),
|
|
31524
|
+
orElse14(
|
|
31525
|
+
(e) => sync11(() => {
|
|
31526
|
+
_report({
|
|
31527
|
+
location: range3,
|
|
31528
|
+
messageText: `Codegen ${codegen.name} is not applicable here: ${e.cause}`,
|
|
31529
|
+
fixes: []
|
|
31530
|
+
});
|
|
31531
|
+
})
|
|
31532
|
+
),
|
|
31533
|
+
ignore3
|
|
31534
|
+
);
|
|
31535
|
+
}
|
|
31536
|
+
})
|
|
31537
|
+
});
|
|
31538
|
+
|
|
31126
31539
|
// src/diagnostics/returnEffectInGen.ts
|
|
31127
31540
|
var returnEffectInGen = createDiagnostic({
|
|
31128
31541
|
name: "returnEffectInGen",
|
|
@@ -31174,7 +31587,7 @@ var returnEffectInGen = createDiagnostic({
|
|
|
31174
31587
|
})
|
|
31175
31588
|
}] : [];
|
|
31176
31589
|
report({
|
|
31177
|
-
node,
|
|
31590
|
+
location: node,
|
|
31178
31591
|
messageText: `You are returning an Effect-able type inside a generator function, and will result in nested Effect<Effect<...>>.
|
|
31179
31592
|
Maybe you wanted to return yield* instead?
|
|
31180
31593
|
Nested Effect-able types may be intended if you plan to later manually flatten or unwrap this Effect, if so you can safely disable this diagnostic for this line through quickfixes.`,
|
|
@@ -31197,17 +31610,14 @@ var scopeInLayerEffect = createDiagnostic({
|
|
|
31197
31610
|
severity: "warning",
|
|
31198
31611
|
apply: fn("scopeInLayerEffect.apply")(function* (sourceFile, report) {
|
|
31199
31612
|
const ts2 = yield* service2(TypeScriptApi);
|
|
31613
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
31200
31614
|
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31201
31615
|
const typeParser = yield* service2(TypeParser);
|
|
31202
|
-
const layerModuleIdentifier =
|
|
31203
|
-
|
|
31204
|
-
|
|
31205
|
-
|
|
31206
|
-
|
|
31207
|
-
),
|
|
31208
|
-
map33((_) => _.text),
|
|
31209
|
-
orElse14(() => succeed17("Layer"))
|
|
31210
|
-
);
|
|
31616
|
+
const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
31617
|
+
sourceFile,
|
|
31618
|
+
"effect",
|
|
31619
|
+
"Layer"
|
|
31620
|
+
) || "Layer";
|
|
31211
31621
|
function parseLayerEffectApiCall(node) {
|
|
31212
31622
|
if (!ts2.isCallExpression(node)) return;
|
|
31213
31623
|
const expression = node.expression;
|
|
@@ -31233,7 +31643,7 @@ var scopeInLayerEffect = createDiagnostic({
|
|
|
31233
31643
|
firstSuccessOf2(entries2.map((type3) => typeParser.scopeType(type3, node))),
|
|
31234
31644
|
map33(
|
|
31235
31645
|
() => report({
|
|
31236
|
-
node,
|
|
31646
|
+
location: node,
|
|
31237
31647
|
messageText: `Seems like you are constructing a layer with a scope in the requirements.
|
|
31238
31648
|
Consider using "scoped" instead to get rid of the scope in the requirements.`,
|
|
31239
31649
|
fixes: methodIdentifier ? [{
|
|
@@ -31349,7 +31759,7 @@ var strictBooleanExpressions = createDiagnostic({
|
|
|
31349
31759
|
if (type2.flags & ts2.TypeFlags.BooleanLiteral) continue;
|
|
31350
31760
|
const typeName = typeChecker.typeToString(type2);
|
|
31351
31761
|
report({
|
|
31352
|
-
|
|
31762
|
+
location: nodeToCheck,
|
|
31353
31763
|
messageText: `Unexpected \`${typeName}\` type in condition, expected strictly a boolean instead.`,
|
|
31354
31764
|
fixes: []
|
|
31355
31765
|
});
|
|
@@ -31391,7 +31801,7 @@ var tryCatchInEffectGen = createDiagnostic({
|
|
|
31391
31801
|
orElse14(() => typeParser.effectFnGen(effectGenNode)),
|
|
31392
31802
|
map33(() => {
|
|
31393
31803
|
report({
|
|
31394
|
-
node,
|
|
31804
|
+
location: node,
|
|
31395
31805
|
messageText: "Avoid using try/catch inside Effect generators. Use Effect's error handling mechanisms instead (e.g., Effect.try, Effect.tryPromise, Effect.catchAll, Effect.catchTag).",
|
|
31396
31806
|
fixes: []
|
|
31397
31807
|
});
|
|
@@ -31426,7 +31836,7 @@ var unnecessaryEffectGen = createDiagnostic({
|
|
|
31426
31836
|
typeParser.unnecessaryEffectGen(node),
|
|
31427
31837
|
map33(
|
|
31428
31838
|
({ replacementNode }) => report({
|
|
31429
|
-
node,
|
|
31839
|
+
location: node,
|
|
31430
31840
|
messageText: `This Effect.gen contains a single return statement.`,
|
|
31431
31841
|
fixes: [{
|
|
31432
31842
|
fixName: "unnecessaryEffectGen_fix",
|
|
@@ -31470,7 +31880,7 @@ var unnecessaryPipe = createDiagnostic({
|
|
|
31470
31880
|
map33(({ args: args3, subject }) => {
|
|
31471
31881
|
if (args3.length === 0) {
|
|
31472
31882
|
report({
|
|
31473
|
-
node,
|
|
31883
|
+
location: node,
|
|
31474
31884
|
messageText: `This pipe call contains no arguments.`,
|
|
31475
31885
|
fixes: [{
|
|
31476
31886
|
fixName: "unnecessaryPipe_fix",
|
|
@@ -31517,7 +31927,7 @@ var unnecessaryPipeChain = createDiagnostic({
|
|
|
31517
31927
|
),
|
|
31518
31928
|
map33(({ innerCall, pipeCall }) => {
|
|
31519
31929
|
report({
|
|
31520
|
-
node,
|
|
31930
|
+
location: node,
|
|
31521
31931
|
messageText: `Chained pipe calls can be simplified to a single pipe call`,
|
|
31522
31932
|
fixes: [{
|
|
31523
31933
|
fixName: "unnecessaryPipeChain_fix",
|
|
@@ -31585,7 +31995,8 @@ var diagnostics = [
|
|
|
31585
31995
|
effectInVoidSuccess,
|
|
31586
31996
|
unnecessaryPipeChain,
|
|
31587
31997
|
strictBooleanExpressions,
|
|
31588
|
-
multipleEffectProvide
|
|
31998
|
+
multipleEffectProvide,
|
|
31999
|
+
outdatedEffectCodegen
|
|
31589
32000
|
];
|
|
31590
32001
|
|
|
31591
32002
|
// src/cli.ts
|
|
@@ -31728,14 +32139,11 @@ var checkEffect2 = (format6, file3) => gen2(function* () {
|
|
|
31728
32139
|
for (const sourceFile of sourceFiles) {
|
|
31729
32140
|
const outputDiagnostics = pipe(
|
|
31730
32141
|
getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),
|
|
31731
|
-
|
|
31732
|
-
provideService7(TypeScriptProgram, program),
|
|
32142
|
+
nanoLayer2,
|
|
31733
32143
|
provideService7(TypeCheckerApi, program.getTypeChecker()),
|
|
31734
|
-
provideService7(
|
|
31735
|
-
|
|
31736
|
-
|
|
31737
|
-
makeTypeCheckerApiCache()
|
|
31738
|
-
),
|
|
32144
|
+
provideService7(TypeScriptProgram, program),
|
|
32145
|
+
nanoLayer,
|
|
32146
|
+
provideService7(TypeScriptApi, ts),
|
|
31739
32147
|
provideService7(
|
|
31740
32148
|
LanguageServicePluginOptions,
|
|
31741
32149
|
parse4(pluginOptions)
|