@effect/language-service 0.28.3 → 0.30.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 +6 -0
- package/cli.js +1398 -615
- package/cli.js.map +1 -1
- package/index.js +1779 -1302
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +1398 -619
- 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)
|
|
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
|
+
)
|
|
28865
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,106 +29584,106 @@ var getInferredReturnType = fn("TypeCheckerApi.getInferredReturnType")(function*
|
|
|
29204
29584
|
}
|
|
29205
29585
|
return returnType;
|
|
29206
29586
|
});
|
|
29207
|
-
var expectedAndRealType =
|
|
29208
|
-
|
|
29209
|
-
|
|
29210
|
-
|
|
29211
|
-
|
|
29212
|
-
|
|
29213
|
-
|
|
29214
|
-
|
|
29215
|
-
|
|
29216
|
-
|
|
29217
|
-
|
|
29218
|
-
|
|
29219
|
-
|
|
29220
|
-
|
|
29221
|
-
|
|
29222
|
-
|
|
29223
|
-
|
|
29224
|
-
|
|
29225
|
-
|
|
29226
|
-
|
|
29227
|
-
|
|
29228
|
-
|
|
29229
|
-
|
|
29230
|
-
|
|
29231
|
-
|
|
29232
|
-
|
|
29233
|
-
|
|
29234
|
-
|
|
29235
|
-
|
|
29236
|
-
|
|
29237
|
-
|
|
29238
|
-
|
|
29239
|
-
|
|
29240
|
-
|
|
29241
|
-
ts2.
|
|
29242
|
-
|
|
29243
|
-
|
|
29244
|
-
|
|
29245
|
-
|
|
29246
|
-
|
|
29247
|
-
|
|
29248
|
-
|
|
29249
|
-
|
|
29250
|
-
|
|
29251
|
-
|
|
29252
|
-
|
|
29253
|
-
result.push([node, expectedType, node, realType]);
|
|
29587
|
+
var expectedAndRealType = cachedBy(
|
|
29588
|
+
fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
|
|
29589
|
+
const typeChecker = yield* service2(TypeCheckerApi);
|
|
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);
|
|
29604
|
+
continue;
|
|
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
|
+
});
|
|
29618
|
+
}
|
|
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
|
+
}
|
|
29254
29633
|
}
|
|
29255
29634
|
}
|
|
29256
29635
|
}
|
|
29257
|
-
|
|
29258
|
-
|
|
29259
|
-
|
|
29260
|
-
|
|
29261
|
-
|
|
29262
|
-
|
|
29263
|
-
|
|
29264
|
-
|
|
29265
|
-
|
|
29266
|
-
|
|
29267
|
-
|
|
29268
|
-
|
|
29269
|
-
|
|
29270
|
-
|
|
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]);
|
|
29651
|
+
}
|
|
29652
|
+
}
|
|
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);
|
|
29271
29668
|
if (isSome2(expectedType)) {
|
|
29272
|
-
result.push([
|
|
29669
|
+
result.push([body, expectedType.value, body, realType]);
|
|
29273
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;
|
|
29274
29679
|
}
|
|
29275
29680
|
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
29681
|
}
|
|
29302
|
-
|
|
29303
|
-
}
|
|
29304
|
-
|
|
29305
|
-
|
|
29306
|
-
|
|
29682
|
+
return result;
|
|
29683
|
+
}),
|
|
29684
|
+
"TypeCheckerApi.expectedAndRealType",
|
|
29685
|
+
(sourceFile) => sourceFile
|
|
29686
|
+
);
|
|
29307
29687
|
var unrollUnionMembers = (type2) => {
|
|
29308
29688
|
const result = [];
|
|
29309
29689
|
let toTest = [type2];
|
|
@@ -29371,350 +29751,17 @@ function makeResolveExternalModuleName(typeChecker) {
|
|
|
29371
29751
|
};
|
|
29372
29752
|
}
|
|
29373
29753
|
|
|
29374
|
-
// src/core/
|
|
29375
|
-
|
|
29376
|
-
|
|
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;
|
|
29523
|
-
}
|
|
29524
|
-
} else if (ts2.isNamedImports(namedBindings)) {
|
|
29525
|
-
for (const importSpecifier of namedBindings.elements) {
|
|
29526
|
-
const importProperty = fromNullable(importSpecifier.propertyName).pipe(
|
|
29527
|
-
orElse(() => some2(importSpecifier.name))
|
|
29528
|
-
);
|
|
29529
|
-
if (yield* test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
|
|
29530
|
-
return importSpecifier.name;
|
|
29531
|
-
}
|
|
29532
|
-
}
|
|
29533
|
-
}
|
|
29534
|
-
}
|
|
29535
|
-
return yield* fail18(new ImportModuleIdentifierNotFoundError());
|
|
29536
|
-
}
|
|
29537
|
-
);
|
|
29538
|
-
function findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, packageName, moduleName) {
|
|
29539
|
-
return findImportedModuleIdentifier(
|
|
29540
|
-
sourceFile,
|
|
29541
|
-
fn(
|
|
29542
|
-
"AST.findImportedModuleIdentifierByPackageAndNameOrBarrel.findImportedModuleIdentifier"
|
|
29543
|
-
)(function* (_, fromModule, importProperty) {
|
|
29544
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29545
|
-
if (isNone2(importProperty) && ts2.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
|
|
29546
|
-
return true;
|
|
29547
|
-
}
|
|
29548
|
-
if (isSome2(importProperty) && ts2.isIdentifier(importProperty.value) && importProperty.value.text === moduleName && ts2.isStringLiteral(fromModule) && fromModule.text === packageName) {
|
|
29549
|
-
return true;
|
|
29550
|
-
}
|
|
29551
|
-
return false;
|
|
29552
|
-
})
|
|
29553
|
-
);
|
|
29554
|
-
}
|
|
29555
|
-
var simplifyTypeNode = fn("AST.simplifyTypeNode")(function* (typeNode) {
|
|
29556
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29557
|
-
function collectCallable(typeNode2) {
|
|
29558
|
-
if (ts2.isParenthesizedTypeNode(typeNode2)) return collectCallable(typeNode2.type);
|
|
29559
|
-
if (ts2.isFunctionTypeNode(typeNode2)) {
|
|
29560
|
-
return some2([
|
|
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
|
-
);
|
|
29610
|
-
}
|
|
29611
|
-
return node;
|
|
29612
|
-
}
|
|
29613
|
-
);
|
|
29614
|
-
var parseAccessedExpressionForCompletion = fn(
|
|
29615
|
-
"AST.parseAccessedExpressionForCompletion"
|
|
29616
|
-
)(
|
|
29617
|
-
function* (sourceFile, position) {
|
|
29618
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29619
|
-
const precedingToken = ts2.findPrecedingToken(position, sourceFile, void 0, true);
|
|
29620
|
-
if (!precedingToken) return yield* fail18(new NodeNotFoundError());
|
|
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;
|
|
29645
|
-
} else {
|
|
29646
|
-
return yield* fail18(new NodeNotFoundError());
|
|
29647
|
-
}
|
|
29648
|
-
return { accessedObject, outerNode, replacementSpan };
|
|
29649
|
-
}
|
|
29650
|
-
);
|
|
29651
|
-
var parseDataForExtendsClassCompletion = fn(
|
|
29652
|
-
"AST.parseDataForExtendsClassCompletion"
|
|
29653
|
-
)(function* (sourceFile, position) {
|
|
29654
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29655
|
-
const { accessedObject, outerNode, replacementSpan } = yield* parseAccessedExpressionForCompletion(
|
|
29656
|
-
sourceFile,
|
|
29657
|
-
position
|
|
29658
|
-
);
|
|
29659
|
-
if (!ts2.isIdentifier(accessedObject)) return yield* fail18(new NodeNotFoundError());
|
|
29660
|
-
let classDeclaration = outerNode.parent;
|
|
29661
|
-
while (ts2.isExpressionWithTypeArguments(classDeclaration) || ts2.isHeritageClause(classDeclaration)) {
|
|
29662
|
-
if (!classDeclaration.parent) break;
|
|
29663
|
-
classDeclaration = classDeclaration.parent;
|
|
29664
|
-
}
|
|
29665
|
-
if (!ts2.isClassDeclaration(classDeclaration)) return yield* fail18(new NodeNotFoundError());
|
|
29666
|
-
if (!classDeclaration.name) return yield* fail18(new NodeNotFoundError());
|
|
29667
|
-
return {
|
|
29668
|
-
accessedObject,
|
|
29669
|
-
classDeclaration,
|
|
29670
|
-
className: classDeclaration.name,
|
|
29671
|
-
replacementSpan
|
|
29672
|
-
};
|
|
29673
|
-
});
|
|
29674
|
-
var createEffectGenCallExpression = fn("AST.createEffectGenCallExpression")(function* (effectModuleIdentifierName, node) {
|
|
29675
|
-
const ts2 = yield* service2(TypeScriptApi);
|
|
29676
|
-
const generator = ts2.factory.createFunctionExpression(
|
|
29677
|
-
void 0,
|
|
29678
|
-
ts2.factory.createToken(ts2.SyntaxKind.AsteriskToken),
|
|
29679
|
-
void 0,
|
|
29680
|
-
[],
|
|
29681
|
-
[],
|
|
29682
|
-
void 0,
|
|
29683
|
-
node
|
|
29684
|
-
// NOTE(mattia): intended, to use same routine for both ConciseBody and Body
|
|
29685
|
-
);
|
|
29686
|
-
return ts2.factory.createCallExpression(
|
|
29687
|
-
ts2.factory.createPropertyAccessExpression(
|
|
29688
|
-
ts2.factory.createIdentifier(effectModuleIdentifierName),
|
|
29689
|
-
"gen"
|
|
29690
|
-
),
|
|
29691
|
-
void 0,
|
|
29692
|
-
[generator]
|
|
29693
|
-
);
|
|
29694
|
-
});
|
|
29695
|
-
var createEffectGenCallExpressionWithBlock = fn(
|
|
29696
|
-
"AST.createEffectGenCallExpressionWithBlock"
|
|
29697
|
-
)(function* (effectModuleIdentifierName, statement) {
|
|
29754
|
+
// src/core/TypeParser.ts
|
|
29755
|
+
var TypeParser = Tag4("@effect/language-service/TypeParser");
|
|
29756
|
+
var nanoLayer2 = (fa) => gen3(function* () {
|
|
29698
29757
|
const ts2 = yield* service2(TypeScriptApi);
|
|
29699
|
-
|
|
29700
|
-
|
|
29701
|
-
|
|
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))
|
|
29702
29763
|
);
|
|
29703
29764
|
});
|
|
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
|
|
29711
|
-
)
|
|
29712
|
-
);
|
|
29713
|
-
}
|
|
29714
|
-
);
|
|
29715
|
-
|
|
29716
|
-
// src/core/TypeParser.ts
|
|
29717
|
-
var TypeParser = Tag4("@effect/language-service/TypeParser");
|
|
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) {
|
|
@@ -29875,10 +29922,40 @@ function make64(ts2, typeChecker) {
|
|
|
29875
29922
|
atLocation
|
|
29876
29923
|
);
|
|
29877
29924
|
}
|
|
29878
|
-
return yield* effectType(type2, atLocation);
|
|
29925
|
+
return yield* effectType(type2, atLocation);
|
|
29926
|
+
}),
|
|
29927
|
+
"TypeParser.effectSubtype",
|
|
29928
|
+
(type2) => type2
|
|
29929
|
+
);
|
|
29930
|
+
const importedSchemaModule = cachedBy(
|
|
29931
|
+
fn("TypeParser.importedSchemaModule")(function* (node) {
|
|
29932
|
+
const type2 = typeChecker.getTypeAtLocation(node);
|
|
29933
|
+
const propertySymbol = typeChecker.getPropertyOfType(type2, "Class");
|
|
29934
|
+
if (!propertySymbol) {
|
|
29935
|
+
return yield* typeParserIssue("Type has no 'Class' property", type2, node);
|
|
29936
|
+
}
|
|
29937
|
+
if (!ts2.isExpression(node)) {
|
|
29938
|
+
return yield* typeParserIssue("Node is not an expression", type2, node);
|
|
29939
|
+
}
|
|
29940
|
+
return node;
|
|
29941
|
+
}),
|
|
29942
|
+
"TypeParser.importedSchemaModule",
|
|
29943
|
+
(node) => node
|
|
29944
|
+
);
|
|
29945
|
+
const importedContextModule = cachedBy(
|
|
29946
|
+
fn("TypeParser.importedContextModule")(function* (node) {
|
|
29947
|
+
const type2 = typeChecker.getTypeAtLocation(node);
|
|
29948
|
+
const propertySymbol = typeChecker.getPropertyOfType(type2, "Tag");
|
|
29949
|
+
if (!propertySymbol) {
|
|
29950
|
+
return yield* typeParserIssue("Type has no 'Tag' property", type2, node);
|
|
29951
|
+
}
|
|
29952
|
+
if (!ts2.isExpression(node)) {
|
|
29953
|
+
return yield* typeParserIssue("Node is not an expression", type2, node);
|
|
29954
|
+
}
|
|
29955
|
+
return node;
|
|
29879
29956
|
}),
|
|
29880
|
-
"TypeParser.
|
|
29881
|
-
(
|
|
29957
|
+
"TypeParser.importedContextModule",
|
|
29958
|
+
(node) => node
|
|
29882
29959
|
);
|
|
29883
29960
|
const importedEffectModule = cachedBy(
|
|
29884
29961
|
fn("TypeParser.importedEffectModule")(function* (node) {
|
|
@@ -30064,15 +30141,11 @@ function make64(ts2, typeChecker) {
|
|
|
30064
30141
|
if (!explicitReturn && !(successType.flags & ts2.TypeFlags.VoidLike)) {
|
|
30065
30142
|
replacementNode = pipe(
|
|
30066
30143
|
gen3(function* () {
|
|
30067
|
-
const effectIdentifier =
|
|
30068
|
-
|
|
30069
|
-
|
|
30070
|
-
|
|
30071
|
-
|
|
30072
|
-
onNone: () => "Effect",
|
|
30073
|
-
onSome: (_) => _.text
|
|
30074
|
-
})
|
|
30075
|
-
);
|
|
30144
|
+
const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
30145
|
+
node.getSourceFile(),
|
|
30146
|
+
"effect",
|
|
30147
|
+
"Effect"
|
|
30148
|
+
) || "Effect";
|
|
30076
30149
|
return ts2.factory.createCallExpression(
|
|
30077
30150
|
ts2.factory.createPropertyAccessExpression(
|
|
30078
30151
|
ts2.factory.createIdentifier(effectIdentifier),
|
|
@@ -30240,6 +30313,284 @@ function make64(ts2, typeChecker) {
|
|
|
30240
30313
|
"TypeParser.promiseLike",
|
|
30241
30314
|
(type2) => type2
|
|
30242
30315
|
);
|
|
30316
|
+
const extendsSchemaClass = cachedBy(
|
|
30317
|
+
fn("TypeParser.extendsSchemaClass")(function* (atLocation) {
|
|
30318
|
+
if (!atLocation.name) {
|
|
30319
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
30320
|
+
}
|
|
30321
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
30322
|
+
if (!heritageClauses) {
|
|
30323
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
30324
|
+
}
|
|
30325
|
+
for (const heritageClause of heritageClauses) {
|
|
30326
|
+
for (const typeX of heritageClause.types) {
|
|
30327
|
+
if (ts2.isExpressionWithTypeArguments(typeX)) {
|
|
30328
|
+
const expression = typeX.expression;
|
|
30329
|
+
if (ts2.isCallExpression(expression)) {
|
|
30330
|
+
const schemaCall = expression.expression;
|
|
30331
|
+
if (ts2.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {
|
|
30332
|
+
const selfTypeNode = schemaCall.typeArguments[0];
|
|
30333
|
+
const schemaIdentifier = schemaCall.expression;
|
|
30334
|
+
if (ts2.isPropertyAccessExpression(schemaIdentifier) && ts2.isIdentifier(schemaIdentifier.name) && schemaIdentifier.name.text === "Class") {
|
|
30335
|
+
const parsedSchemaModule = yield* pipe(
|
|
30336
|
+
importedSchemaModule(schemaIdentifier.expression),
|
|
30337
|
+
option4
|
|
30338
|
+
);
|
|
30339
|
+
if (isSome2(parsedSchemaModule)) {
|
|
30340
|
+
return {
|
|
30341
|
+
className: atLocation.name,
|
|
30342
|
+
selfTypeNode,
|
|
30343
|
+
Schema: parsedSchemaModule.value
|
|
30344
|
+
};
|
|
30345
|
+
}
|
|
30346
|
+
}
|
|
30347
|
+
}
|
|
30348
|
+
}
|
|
30349
|
+
}
|
|
30350
|
+
}
|
|
30351
|
+
}
|
|
30352
|
+
return yield* typeParserIssue("Class does not extend Schema.Class", void 0, atLocation);
|
|
30353
|
+
}),
|
|
30354
|
+
"TypeParser.extendsSchemaClass",
|
|
30355
|
+
(atLocation) => atLocation
|
|
30356
|
+
);
|
|
30357
|
+
const extendsSchemaTaggedClass = cachedBy(
|
|
30358
|
+
fn("TypeParser.extendsSchemaTaggedClass")(function* (atLocation) {
|
|
30359
|
+
if (!atLocation.name) {
|
|
30360
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
30361
|
+
}
|
|
30362
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
30363
|
+
if (!heritageClauses) {
|
|
30364
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
30365
|
+
}
|
|
30366
|
+
for (const heritageClause of heritageClauses) {
|
|
30367
|
+
for (const typeX of heritageClause.types) {
|
|
30368
|
+
if (ts2.isExpressionWithTypeArguments(typeX)) {
|
|
30369
|
+
const expression = typeX.expression;
|
|
30370
|
+
if (ts2.isCallExpression(expression)) {
|
|
30371
|
+
const tagCall = expression.expression;
|
|
30372
|
+
if (ts2.isCallExpression(tagCall)) {
|
|
30373
|
+
const schemaCall = tagCall.expression;
|
|
30374
|
+
if (ts2.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {
|
|
30375
|
+
const selfTypeNode = schemaCall.typeArguments[0];
|
|
30376
|
+
const schemaIdentifier = schemaCall.expression;
|
|
30377
|
+
if (ts2.isPropertyAccessExpression(schemaIdentifier) && ts2.isIdentifier(schemaIdentifier.name) && schemaIdentifier.name.text === "TaggedClass") {
|
|
30378
|
+
const parsedSchemaModule = yield* pipe(
|
|
30379
|
+
importedSchemaModule(schemaIdentifier.expression),
|
|
30380
|
+
option4
|
|
30381
|
+
);
|
|
30382
|
+
if (isSome2(parsedSchemaModule)) {
|
|
30383
|
+
return {
|
|
30384
|
+
className: atLocation.name,
|
|
30385
|
+
selfTypeNode,
|
|
30386
|
+
Schema: parsedSchemaModule.value
|
|
30387
|
+
};
|
|
30388
|
+
}
|
|
30389
|
+
}
|
|
30390
|
+
}
|
|
30391
|
+
}
|
|
30392
|
+
}
|
|
30393
|
+
}
|
|
30394
|
+
}
|
|
30395
|
+
}
|
|
30396
|
+
return yield* typeParserIssue("Class does not extend Schema.TaggedClass", void 0, atLocation);
|
|
30397
|
+
}),
|
|
30398
|
+
"TypeParser.extendsSchemaTaggedClass",
|
|
30399
|
+
(atLocation) => atLocation
|
|
30400
|
+
);
|
|
30401
|
+
const extendsSchemaTaggedError = cachedBy(
|
|
30402
|
+
fn("TypeParser.extendsSchemaTaggedError")(function* (atLocation) {
|
|
30403
|
+
if (!atLocation.name) {
|
|
30404
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
30405
|
+
}
|
|
30406
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
30407
|
+
if (!heritageClauses) {
|
|
30408
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
30409
|
+
}
|
|
30410
|
+
for (const heritageClause of heritageClauses) {
|
|
30411
|
+
for (const typeX of heritageClause.types) {
|
|
30412
|
+
if (ts2.isExpressionWithTypeArguments(typeX)) {
|
|
30413
|
+
const expression = typeX.expression;
|
|
30414
|
+
if (ts2.isCallExpression(expression)) {
|
|
30415
|
+
const tagCall = expression.expression;
|
|
30416
|
+
if (ts2.isCallExpression(tagCall)) {
|
|
30417
|
+
const schemaCall = tagCall.expression;
|
|
30418
|
+
if (ts2.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {
|
|
30419
|
+
const selfTypeNode = schemaCall.typeArguments[0];
|
|
30420
|
+
const schemaIdentifier = schemaCall.expression;
|
|
30421
|
+
if (ts2.isPropertyAccessExpression(schemaIdentifier) && ts2.isIdentifier(schemaIdentifier.name) && schemaIdentifier.name.text === "TaggedError") {
|
|
30422
|
+
const parsedSchemaModule = yield* pipe(
|
|
30423
|
+
importedSchemaModule(schemaIdentifier.expression),
|
|
30424
|
+
option4
|
|
30425
|
+
);
|
|
30426
|
+
if (isSome2(parsedSchemaModule)) {
|
|
30427
|
+
return {
|
|
30428
|
+
className: atLocation.name,
|
|
30429
|
+
selfTypeNode,
|
|
30430
|
+
Schema: parsedSchemaModule.value
|
|
30431
|
+
};
|
|
30432
|
+
}
|
|
30433
|
+
}
|
|
30434
|
+
}
|
|
30435
|
+
}
|
|
30436
|
+
}
|
|
30437
|
+
}
|
|
30438
|
+
}
|
|
30439
|
+
}
|
|
30440
|
+
return yield* typeParserIssue("Class does not extend Schema.TaggedError", void 0, atLocation);
|
|
30441
|
+
}),
|
|
30442
|
+
"TypeParser.extendsSchemaTaggedError",
|
|
30443
|
+
(atLocation) => atLocation
|
|
30444
|
+
);
|
|
30445
|
+
const extendsSchemaTaggedRequest = cachedBy(
|
|
30446
|
+
fn("TypeParser.extendsSchemaTaggedRequest")(function* (atLocation) {
|
|
30447
|
+
if (!atLocation.name) {
|
|
30448
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
30449
|
+
}
|
|
30450
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
30451
|
+
if (!heritageClauses) {
|
|
30452
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
30453
|
+
}
|
|
30454
|
+
for (const heritageClause of heritageClauses) {
|
|
30455
|
+
for (const typeX of heritageClause.types) {
|
|
30456
|
+
if (ts2.isExpressionWithTypeArguments(typeX)) {
|
|
30457
|
+
const expression = typeX.expression;
|
|
30458
|
+
if (ts2.isCallExpression(expression)) {
|
|
30459
|
+
const tagCall = expression.expression;
|
|
30460
|
+
if (ts2.isCallExpression(tagCall)) {
|
|
30461
|
+
const schemaCall = tagCall.expression;
|
|
30462
|
+
if (ts2.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {
|
|
30463
|
+
const selfTypeNode = schemaCall.typeArguments[0];
|
|
30464
|
+
const schemaIdentifier = schemaCall.expression;
|
|
30465
|
+
if (ts2.isPropertyAccessExpression(schemaIdentifier) && ts2.isIdentifier(schemaIdentifier.name) && schemaIdentifier.name.text === "TaggedRequest") {
|
|
30466
|
+
const parsedSchemaModule = yield* pipe(
|
|
30467
|
+
importedSchemaModule(schemaIdentifier.expression),
|
|
30468
|
+
option4
|
|
30469
|
+
);
|
|
30470
|
+
if (isSome2(parsedSchemaModule)) {
|
|
30471
|
+
return {
|
|
30472
|
+
className: atLocation.name,
|
|
30473
|
+
selfTypeNode,
|
|
30474
|
+
Schema: parsedSchemaModule.value
|
|
30475
|
+
};
|
|
30476
|
+
}
|
|
30477
|
+
}
|
|
30478
|
+
}
|
|
30479
|
+
}
|
|
30480
|
+
}
|
|
30481
|
+
}
|
|
30482
|
+
}
|
|
30483
|
+
}
|
|
30484
|
+
return yield* typeParserIssue("Class does not extend Schema.TaggedRequest", void 0, atLocation);
|
|
30485
|
+
}),
|
|
30486
|
+
"TypeParser.extendsSchemaTaggedRequest",
|
|
30487
|
+
(atLocation) => atLocation
|
|
30488
|
+
);
|
|
30489
|
+
const extendsContextTag = cachedBy(
|
|
30490
|
+
fn("TypeParser.extendsContextTag")(function* (atLocation) {
|
|
30491
|
+
if (!atLocation.name) {
|
|
30492
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
30493
|
+
}
|
|
30494
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
30495
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
30496
|
+
const type2 = typeChecker.getTypeOfSymbol(classSym);
|
|
30497
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
30498
|
+
if (!heritageClauses) {
|
|
30499
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
30500
|
+
}
|
|
30501
|
+
for (const heritageClause of heritageClauses) {
|
|
30502
|
+
for (const typeX of heritageClause.types) {
|
|
30503
|
+
if (ts2.isExpressionWithTypeArguments(typeX)) {
|
|
30504
|
+
const wholeCall = typeX.expression;
|
|
30505
|
+
if (ts2.isCallExpression(wholeCall)) {
|
|
30506
|
+
const contextTagCall = wholeCall.expression;
|
|
30507
|
+
if (ts2.isCallExpression(contextTagCall) && wholeCall.typeArguments && wholeCall.typeArguments.length > 0) {
|
|
30508
|
+
const contextTagIdentifier = contextTagCall.expression;
|
|
30509
|
+
const selfTypeNode = wholeCall.typeArguments[0];
|
|
30510
|
+
if (ts2.isPropertyAccessExpression(contextTagIdentifier) && ts2.isIdentifier(contextTagIdentifier.name) && contextTagIdentifier.name.text === "Tag") {
|
|
30511
|
+
const parsedContextModule = yield* pipe(
|
|
30512
|
+
importedContextModule(contextTagIdentifier.expression),
|
|
30513
|
+
option4
|
|
30514
|
+
);
|
|
30515
|
+
if (isSome2(parsedContextModule)) {
|
|
30516
|
+
const tagType = yield* contextTag(type2, atLocation);
|
|
30517
|
+
return {
|
|
30518
|
+
className: atLocation.name,
|
|
30519
|
+
selfTypeNode,
|
|
30520
|
+
args: contextTagCall.arguments,
|
|
30521
|
+
Identifier: tagType.Identifier,
|
|
30522
|
+
Tag: parsedContextModule.value
|
|
30523
|
+
};
|
|
30524
|
+
}
|
|
30525
|
+
}
|
|
30526
|
+
}
|
|
30527
|
+
}
|
|
30528
|
+
}
|
|
30529
|
+
}
|
|
30530
|
+
}
|
|
30531
|
+
return yield* typeParserIssue("Class does not extend Context.Tag", void 0, atLocation);
|
|
30532
|
+
}),
|
|
30533
|
+
"TypeParser.extendsContextTag",
|
|
30534
|
+
(atLocation) => atLocation
|
|
30535
|
+
);
|
|
30536
|
+
const extendsEffectService = cachedBy(
|
|
30537
|
+
fn("TypeParser.extendsEffectService")(function* (atLocation) {
|
|
30538
|
+
if (!atLocation.name) {
|
|
30539
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
30540
|
+
}
|
|
30541
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
30542
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
30543
|
+
const type2 = typeChecker.getTypeOfSymbol(classSym);
|
|
30544
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
30545
|
+
if (!heritageClauses) {
|
|
30546
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
30547
|
+
}
|
|
30548
|
+
for (const heritageClause of heritageClauses) {
|
|
30549
|
+
for (const typeX of heritageClause.types) {
|
|
30550
|
+
if (ts2.isExpressionWithTypeArguments(typeX)) {
|
|
30551
|
+
const wholeCall = typeX.expression;
|
|
30552
|
+
if (ts2.isCallExpression(wholeCall)) {
|
|
30553
|
+
const effectServiceCall = wholeCall.expression;
|
|
30554
|
+
if (ts2.isCallExpression(effectServiceCall) && effectServiceCall.typeArguments && effectServiceCall.typeArguments.length > 0) {
|
|
30555
|
+
const effectServiceIdentifier = effectServiceCall.expression;
|
|
30556
|
+
const selfTypeNode = effectServiceCall.typeArguments[0];
|
|
30557
|
+
if (ts2.isPropertyAccessExpression(effectServiceIdentifier) && ts2.isIdentifier(effectServiceIdentifier.name) && effectServiceIdentifier.name.text === "Service") {
|
|
30558
|
+
const parsedContextTag = yield* pipe(
|
|
30559
|
+
importedEffectModule(effectServiceIdentifier.expression),
|
|
30560
|
+
flatMap18(() => contextTag(type2, atLocation)),
|
|
30561
|
+
option4
|
|
30562
|
+
);
|
|
30563
|
+
if (isSome2(parsedContextTag)) {
|
|
30564
|
+
let accessors2 = void 0;
|
|
30565
|
+
if (wholeCall.arguments.length >= 2) {
|
|
30566
|
+
const args3 = wholeCall.arguments[1];
|
|
30567
|
+
if (ts2.isObjectLiteralExpression(args3)) {
|
|
30568
|
+
for (const property of args3.properties) {
|
|
30569
|
+
if (ts2.isPropertyAssignment(property) && property.name && ts2.isIdentifier(property.name) && property.name.text === "accessors" && property.initializer && property.initializer.kind === ts2.SyntaxKind.TrueKeyword) {
|
|
30570
|
+
accessors2 = true;
|
|
30571
|
+
}
|
|
30572
|
+
}
|
|
30573
|
+
}
|
|
30574
|
+
}
|
|
30575
|
+
return {
|
|
30576
|
+
...parsedContextTag.value,
|
|
30577
|
+
className: atLocation.name,
|
|
30578
|
+
selfTypeNode,
|
|
30579
|
+
args: wholeCall.arguments,
|
|
30580
|
+
accessors: accessors2
|
|
30581
|
+
};
|
|
30582
|
+
}
|
|
30583
|
+
}
|
|
30584
|
+
}
|
|
30585
|
+
}
|
|
30586
|
+
}
|
|
30587
|
+
}
|
|
30588
|
+
}
|
|
30589
|
+
return yield* typeParserIssue("Class does not extend Effect.Service", void 0, atLocation);
|
|
30590
|
+
}),
|
|
30591
|
+
"TypeParser.extendsEffectService",
|
|
30592
|
+
(atLocation) => atLocation
|
|
30593
|
+
);
|
|
30243
30594
|
return {
|
|
30244
30595
|
effectType,
|
|
30245
30596
|
strictEffectType,
|
|
@@ -30256,10 +30607,79 @@ function make64(ts2, typeChecker) {
|
|
|
30256
30607
|
pipeableType,
|
|
30257
30608
|
pipeCall,
|
|
30258
30609
|
scopeType,
|
|
30259
|
-
promiseLike
|
|
30610
|
+
promiseLike,
|
|
30611
|
+
extendsEffectService,
|
|
30612
|
+
extendsContextTag,
|
|
30613
|
+
extendsSchemaClass,
|
|
30614
|
+
extendsSchemaTaggedClass,
|
|
30615
|
+
extendsSchemaTaggedError,
|
|
30616
|
+
extendsSchemaTaggedRequest
|
|
30260
30617
|
};
|
|
30261
30618
|
}
|
|
30262
30619
|
|
|
30620
|
+
// src/diagnostics/classSelfMismatch.ts
|
|
30621
|
+
var classSelfMismatch = createDiagnostic({
|
|
30622
|
+
name: "classSelfMismatch",
|
|
30623
|
+
code: 20,
|
|
30624
|
+
severity: "error",
|
|
30625
|
+
apply: fn("classSelfMismatch.apply")(function* (sourceFile, report) {
|
|
30626
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
30627
|
+
const typeParser = yield* service2(TypeParser);
|
|
30628
|
+
const nodeToVisit = [];
|
|
30629
|
+
const appendNodeToVisit = (node) => {
|
|
30630
|
+
nodeToVisit.push(node);
|
|
30631
|
+
return void 0;
|
|
30632
|
+
};
|
|
30633
|
+
ts2.forEachChild(sourceFile, appendNodeToVisit);
|
|
30634
|
+
while (nodeToVisit.length > 0) {
|
|
30635
|
+
const node = nodeToVisit.shift();
|
|
30636
|
+
if (ts2.isClassDeclaration(node) && node.name && node.heritageClauses) {
|
|
30637
|
+
const result = yield* pipe(
|
|
30638
|
+
typeParser.extendsEffectService(node),
|
|
30639
|
+
orElse14(() => typeParser.extendsContextTag(node)),
|
|
30640
|
+
orElse14(() => typeParser.extendsSchemaClass(node)),
|
|
30641
|
+
orElse14(() => typeParser.extendsSchemaTaggedClass(node)),
|
|
30642
|
+
orElse14(() => typeParser.extendsSchemaTaggedError(node)),
|
|
30643
|
+
orElse14(() => typeParser.extendsSchemaTaggedRequest(node)),
|
|
30644
|
+
orElse14(() => void_8)
|
|
30645
|
+
);
|
|
30646
|
+
if (result) {
|
|
30647
|
+
const { className, selfTypeNode } = result;
|
|
30648
|
+
let actualName = "";
|
|
30649
|
+
if (ts2.isTypeReferenceNode(selfTypeNode)) {
|
|
30650
|
+
if (ts2.isIdentifier(selfTypeNode.typeName)) {
|
|
30651
|
+
actualName = selfTypeNode.typeName.text;
|
|
30652
|
+
} else if (ts2.isQualifiedName(selfTypeNode.typeName)) {
|
|
30653
|
+
actualName = selfTypeNode.typeName.right.text;
|
|
30654
|
+
}
|
|
30655
|
+
}
|
|
30656
|
+
const expectedName = className.text;
|
|
30657
|
+
if (actualName !== expectedName) {
|
|
30658
|
+
report({
|
|
30659
|
+
location: selfTypeNode,
|
|
30660
|
+
messageText: `Self type parameter should be '${expectedName}'`,
|
|
30661
|
+
fixes: [{
|
|
30662
|
+
fixName: "classSelfMismatch_fix",
|
|
30663
|
+
description: `Replace '${actualName}' with '${expectedName}'`,
|
|
30664
|
+
apply: gen3(function* () {
|
|
30665
|
+
const changeTracker = yield* service2(ChangeTracker);
|
|
30666
|
+
const typeArgs = ts2.isTypeReferenceNode(selfTypeNode) ? selfTypeNode.typeArguments : void 0;
|
|
30667
|
+
const newTypeReference = ts2.factory.createTypeReferenceNode(
|
|
30668
|
+
ts2.factory.createIdentifier(expectedName),
|
|
30669
|
+
typeArgs
|
|
30670
|
+
);
|
|
30671
|
+
changeTracker.replaceNode(sourceFile, selfTypeNode, newTypeReference);
|
|
30672
|
+
})
|
|
30673
|
+
}]
|
|
30674
|
+
});
|
|
30675
|
+
}
|
|
30676
|
+
}
|
|
30677
|
+
}
|
|
30678
|
+
ts2.forEachChild(node, appendNodeToVisit);
|
|
30679
|
+
}
|
|
30680
|
+
})
|
|
30681
|
+
});
|
|
30682
|
+
|
|
30263
30683
|
// src/diagnostics/duplicatePackage.ts
|
|
30264
30684
|
var checkedPackagesCache = /* @__PURE__ */ new Map();
|
|
30265
30685
|
var programResolvedCacheSize = /* @__PURE__ */ new Map();
|
|
@@ -30269,6 +30689,7 @@ var duplicatePackage = createDiagnostic({
|
|
|
30269
30689
|
severity: "warning",
|
|
30270
30690
|
apply: fn("duplicatePackage.apply")(function* (sourceFile, report) {
|
|
30271
30691
|
const program = yield* service2(TypeScriptProgram);
|
|
30692
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
30272
30693
|
const options3 = yield* service2(LanguageServicePluginOptions);
|
|
30273
30694
|
if (sourceFile.statements.length < 1) return;
|
|
30274
30695
|
let resolvedPackages = checkedPackagesCache.get(sourceFile.fileName) || {};
|
|
@@ -30278,7 +30699,7 @@ var duplicatePackage = createDiagnostic({
|
|
|
30278
30699
|
const seenPackages = /* @__PURE__ */ new Set();
|
|
30279
30700
|
resolvedPackages = {};
|
|
30280
30701
|
program.getSourceFiles().map((_) => {
|
|
30281
|
-
const packageInfo = parsePackageContentNameAndVersionFromScope(_);
|
|
30702
|
+
const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(_);
|
|
30282
30703
|
if (!packageInfo) return;
|
|
30283
30704
|
const packageNameAndVersion = packageInfo.name + "@" + packageInfo.version;
|
|
30284
30705
|
if (seenPackages.has(packageNameAndVersion)) return;
|
|
@@ -30295,7 +30716,7 @@ var duplicatePackage = createDiagnostic({
|
|
|
30295
30716
|
if (Object.keys(resolvedPackages[packageName]).length > 1) {
|
|
30296
30717
|
const versions = Object.keys(resolvedPackages[packageName]);
|
|
30297
30718
|
report({
|
|
30298
|
-
|
|
30719
|
+
location: sourceFile.statements[0],
|
|
30299
30720
|
messageText: `Package ${packageName} is referenced multiple times with different versions (${versions.join(", ")}) and may cause unexpected type errors.
|
|
30300
30721
|
Cleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.
|
|
30301
30722
|
If this is intended set the LSP config "allowedDuplicatedPackages" to ${JSON.stringify(options3.allowedDuplicatedPackages.concat([packageName]))}.
|
|
@@ -30342,7 +30763,7 @@ var effectInVoidSuccess = createDiagnostic({
|
|
|
30342
30763
|
map33(({ voidedEffect }) => {
|
|
30343
30764
|
report(
|
|
30344
30765
|
{
|
|
30345
|
-
node,
|
|
30766
|
+
location: node,
|
|
30346
30767
|
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
30768
|
fixes: []
|
|
30348
30769
|
}
|
|
@@ -30391,7 +30812,7 @@ var floatingEffect = createDiagnostic({
|
|
|
30391
30812
|
);
|
|
30392
30813
|
if (isNone2(allowedFloatingEffects)) {
|
|
30393
30814
|
report({
|
|
30394
|
-
node,
|
|
30815
|
+
location: node,
|
|
30395
30816
|
messageText: `Effect must be yielded or assigned to a variable.`,
|
|
30396
30817
|
fixes: []
|
|
30397
30818
|
});
|
|
@@ -30434,7 +30855,7 @@ var genericEffectServices = createDiagnostic({
|
|
|
30434
30855
|
typeParser.contextTag(type2, node),
|
|
30435
30856
|
map33(() => {
|
|
30436
30857
|
report({
|
|
30437
|
-
|
|
30858
|
+
location: reportAt,
|
|
30438
30859
|
messageText: `Effect Services with type parameters are not supported because they cannot be properly discriminated at runtime, which may cause unexpected behavior.`,
|
|
30439
30860
|
fixes: []
|
|
30440
30861
|
});
|
|
@@ -30456,17 +30877,16 @@ var importFromBarrel = createDiagnostic({
|
|
|
30456
30877
|
const languageServicePluginOptions = yield* service2(LanguageServicePluginOptions);
|
|
30457
30878
|
if (languageServicePluginOptions.namespaceImportPackages.length === 0) return;
|
|
30458
30879
|
const ts2 = yield* service2(TypeScriptApi);
|
|
30880
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
30459
30881
|
const typeChecker = yield* service2(TypeCheckerApi);
|
|
30460
30882
|
const program = yield* service2(TypeScriptProgram);
|
|
30461
30883
|
const packageNamesToCheck = flatten(
|
|
30462
|
-
|
|
30463
|
-
|
|
30464
|
-
(packageName) => resolveModulePattern(sourceFile, packageName)
|
|
30465
|
-
)
|
|
30884
|
+
languageServicePluginOptions.namespaceImportPackages.map(
|
|
30885
|
+
(packageName) => tsUtils.resolveModulePattern(sourceFile, packageName)
|
|
30466
30886
|
)
|
|
30467
30887
|
);
|
|
30468
30888
|
const isImportedFromBarrelExport = (element) => {
|
|
30469
|
-
const getModuleSpecifier = makeGetModuleSpecifier(
|
|
30889
|
+
const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
|
|
30470
30890
|
const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
|
|
30471
30891
|
if (!(getModuleSpecifier && resolveExternalModuleName)) return;
|
|
30472
30892
|
const importDeclaration = ts2.findAncestor(element, (node) => ts2.isImportDeclaration(node));
|
|
@@ -30542,7 +30962,7 @@ var importFromBarrel = createDiagnostic({
|
|
|
30542
30962
|
unbarrelledFileName
|
|
30543
30963
|
} = result;
|
|
30544
30964
|
report({
|
|
30545
|
-
node,
|
|
30965
|
+
location: node,
|
|
30546
30966
|
messageText: `Importing from barrel module ${barrelModuleName} is not allowed.`,
|
|
30547
30967
|
fixes: [
|
|
30548
30968
|
{
|
|
@@ -30656,7 +31076,7 @@ var leakingRequirements = createDiagnostic({
|
|
|
30656
31076
|
function reportLeakingRequirements(node, requirements) {
|
|
30657
31077
|
if (requirements.length === 0) return;
|
|
30658
31078
|
report({
|
|
30659
|
-
node,
|
|
31079
|
+
location: node,
|
|
30660
31080
|
messageText: `This Service is leaking the ${requirements.map((_) => typeChecker.typeToString(_)).join(" | ")} requirement.
|
|
30661
31081
|
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
31082
|
More info at https://effect.website/docs/requirements-management/layers/#avoiding-requirement-leakage`,
|
|
@@ -30736,7 +31156,7 @@ var missingEffectContext = createDiagnostic({
|
|
|
30736
31156
|
map33(
|
|
30737
31157
|
(missingTypes) => missingTypes.length > 0 ? report(
|
|
30738
31158
|
{
|
|
30739
|
-
node,
|
|
31159
|
+
location: node,
|
|
30740
31160
|
messageText: `Missing '${sortTypes(missingTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect context.`,
|
|
30741
31161
|
fixes: []
|
|
30742
31162
|
}
|
|
@@ -30756,18 +31176,15 @@ var missingEffectError = createDiagnostic({
|
|
|
30756
31176
|
severity: "error",
|
|
30757
31177
|
apply: fn("missingEffectError.apply")(function* (sourceFile, report) {
|
|
30758
31178
|
const ts2 = yield* service2(TypeScriptApi);
|
|
31179
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
30759
31180
|
const typeChecker = yield* service2(TypeCheckerApi);
|
|
30760
31181
|
const typeParser = yield* service2(TypeParser);
|
|
30761
31182
|
const typeOrder = yield* deterministicTypeOrder;
|
|
30762
|
-
const effectModuleIdentifier =
|
|
30763
|
-
|
|
30764
|
-
|
|
30765
|
-
|
|
30766
|
-
|
|
30767
|
-
),
|
|
30768
|
-
map33((_) => _.text),
|
|
30769
|
-
orElse14(() => succeed17("Effect"))
|
|
30770
|
-
);
|
|
31183
|
+
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
31184
|
+
sourceFile,
|
|
31185
|
+
"effect",
|
|
31186
|
+
"Effect"
|
|
31187
|
+
) || "Effect";
|
|
30771
31188
|
const createDieMessage = (message) => ts2.factory.createCallExpression(
|
|
30772
31189
|
ts2.factory.createPropertyAccessExpression(
|
|
30773
31190
|
ts2.factory.createIdentifier(effectModuleIdentifier),
|
|
@@ -30869,7 +31286,7 @@ var missingEffectError = createDiagnostic({
|
|
|
30869
31286
|
}
|
|
30870
31287
|
report(
|
|
30871
31288
|
{
|
|
30872
|
-
node,
|
|
31289
|
+
location: node,
|
|
30873
31290
|
messageText: `Missing '${sortTypes(result.missingErrorTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect errors.`,
|
|
30874
31291
|
fixes
|
|
30875
31292
|
}
|
|
@@ -30933,7 +31350,7 @@ var missingReturnYieldStar = createDiagnostic({
|
|
|
30933
31350
|
})
|
|
30934
31351
|
}] : [];
|
|
30935
31352
|
report({
|
|
30936
|
-
node,
|
|
31353
|
+
location: node,
|
|
30937
31354
|
messageText: `Yielded Effect never succeeds, so it is best to use a 'return yield*' instead.`,
|
|
30938
31355
|
fixes: fix
|
|
30939
31356
|
});
|
|
@@ -30989,7 +31406,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
30989
31406
|
}
|
|
30990
31407
|
brokenGenerators.forEach(
|
|
30991
31408
|
(node) => report({
|
|
30992
|
-
node,
|
|
31409
|
+
location: node,
|
|
30993
31410
|
messageText: `Seems like you used yield instead of yield* inside this Effect.gen.`,
|
|
30994
31411
|
fixes: []
|
|
30995
31412
|
})
|
|
@@ -31011,7 +31428,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
31011
31428
|
})
|
|
31012
31429
|
}] : [];
|
|
31013
31430
|
report({
|
|
31014
|
-
node,
|
|
31431
|
+
location: node,
|
|
31015
31432
|
messageText: `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`,
|
|
31016
31433
|
fixes: fix
|
|
31017
31434
|
});
|
|
@@ -31026,26 +31443,19 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
31026
31443
|
severity: "warning",
|
|
31027
31444
|
apply: fn("multipleEffectProvide.apply")(function* (sourceFile, report) {
|
|
31028
31445
|
const ts2 = yield* service2(TypeScriptApi);
|
|
31446
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
31029
31447
|
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31030
31448
|
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
|
-
);
|
|
31449
|
+
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
31450
|
+
sourceFile,
|
|
31451
|
+
"effect",
|
|
31452
|
+
"Effect"
|
|
31453
|
+
) || "Effect";
|
|
31454
|
+
const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
31455
|
+
sourceFile,
|
|
31456
|
+
"effect",
|
|
31457
|
+
"Layer"
|
|
31458
|
+
) || "Layer";
|
|
31049
31459
|
const parseEffectProvideLayer = (node) => {
|
|
31050
31460
|
if (ts2.isCallExpression(node) && ts2.isPropertyAccessExpression(node.expression) && ts2.isIdentifier(node.expression.name) && node.expression.name.text === "provide" && node.arguments.length > 0) {
|
|
31051
31461
|
const layer12 = node.arguments[0];
|
|
@@ -31075,7 +31485,7 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
31075
31485
|
for (const chunk4 of previousLayers) {
|
|
31076
31486
|
if (chunk4.length < 2) continue;
|
|
31077
31487
|
report({
|
|
31078
|
-
|
|
31488
|
+
location: chunk4[0].node,
|
|
31079
31489
|
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
31490
|
fixes: [{
|
|
31081
31491
|
fixName: "multipleEffectProvide_fix",
|
|
@@ -31123,6 +31533,327 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
31123
31533
|
})
|
|
31124
31534
|
});
|
|
31125
31535
|
|
|
31536
|
+
// src/refactors/writeTagClassAccessors.ts
|
|
31537
|
+
var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, service3, className, atLocation, involvedMembers) {
|
|
31538
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
31539
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
31540
|
+
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31541
|
+
const typeParser = yield* service2(TypeParser);
|
|
31542
|
+
const changeTracker = yield* service2(ChangeTracker);
|
|
31543
|
+
const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.getEnd() - 1;
|
|
31544
|
+
const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
31545
|
+
sourceFile,
|
|
31546
|
+
"effect",
|
|
31547
|
+
"Effect"
|
|
31548
|
+
) || "Effect";
|
|
31549
|
+
const createFunctionProperty = (className2, propertyName, type2, forceAny) => {
|
|
31550
|
+
const arrowBody = ts2.factory.createCallExpression(
|
|
31551
|
+
ts2.factory.createPropertyAccessExpression(
|
|
31552
|
+
ts2.factory.createIdentifier(effectIdentifier),
|
|
31553
|
+
"andThen"
|
|
31554
|
+
),
|
|
31555
|
+
void 0,
|
|
31556
|
+
[
|
|
31557
|
+
ts2.factory.createIdentifier(className2.text),
|
|
31558
|
+
ts2.factory.createArrowFunction(
|
|
31559
|
+
void 0,
|
|
31560
|
+
void 0,
|
|
31561
|
+
[ts2.factory.createParameterDeclaration(
|
|
31562
|
+
void 0,
|
|
31563
|
+
void 0,
|
|
31564
|
+
"_",
|
|
31565
|
+
void 0,
|
|
31566
|
+
forceAny ? ts2.factory.createTypeReferenceNode("any") : void 0
|
|
31567
|
+
)],
|
|
31568
|
+
void 0,
|
|
31569
|
+
void 0,
|
|
31570
|
+
ts2.factory.createCallExpression(
|
|
31571
|
+
ts2.factory.createPropertyAccessExpression(
|
|
31572
|
+
ts2.factory.createIdentifier("_"),
|
|
31573
|
+
propertyName
|
|
31574
|
+
),
|
|
31575
|
+
void 0,
|
|
31576
|
+
[
|
|
31577
|
+
ts2.factory.createSpreadElement(ts2.factory.createIdentifier("args"))
|
|
31578
|
+
]
|
|
31579
|
+
)
|
|
31580
|
+
)
|
|
31581
|
+
]
|
|
31582
|
+
);
|
|
31583
|
+
return ts2.factory.createPropertyDeclaration(
|
|
31584
|
+
[ts2.factory.createModifier(ts2.SyntaxKind.StaticKeyword)],
|
|
31585
|
+
propertyName,
|
|
31586
|
+
void 0,
|
|
31587
|
+
type2,
|
|
31588
|
+
ts2.factory.createArrowFunction(
|
|
31589
|
+
void 0,
|
|
31590
|
+
void 0,
|
|
31591
|
+
[ts2.factory.createParameterDeclaration(
|
|
31592
|
+
void 0,
|
|
31593
|
+
ts2.factory.createToken(ts2.SyntaxKind.DotDotDotToken),
|
|
31594
|
+
"args",
|
|
31595
|
+
void 0,
|
|
31596
|
+
forceAny ? ts2.factory.createArrayTypeNode(ts2.factory.createTypeReferenceNode("any")) : void 0
|
|
31597
|
+
)],
|
|
31598
|
+
void 0,
|
|
31599
|
+
void 0,
|
|
31600
|
+
forceAny ? ts2.factory.createAsExpression(arrowBody, ts2.factory.createTypeReferenceNode("any")) : arrowBody
|
|
31601
|
+
)
|
|
31602
|
+
);
|
|
31603
|
+
};
|
|
31604
|
+
const generateReturnType = (type2, atLocation2, className2) => pipe(
|
|
31605
|
+
typeParser.effectType(type2, atLocation2),
|
|
31606
|
+
flatMap18((returnedEffect) => {
|
|
31607
|
+
const contextType = returnedEffect.R.flags & ts2.TypeFlags.Never ? ts2.factory.createTypeReferenceNode(className2.text) : ts2.factory.createUnionTypeNode(
|
|
31608
|
+
[
|
|
31609
|
+
ts2.factory.createTypeReferenceNode(className2.text),
|
|
31610
|
+
typeChecker.typeToTypeNode(returnedEffect.R, atLocation2, ts2.NodeBuilderFlags.NoTruncation)
|
|
31611
|
+
]
|
|
31612
|
+
);
|
|
31613
|
+
const successType = typeChecker.typeToTypeNode(
|
|
31614
|
+
returnedEffect.A,
|
|
31615
|
+
atLocation2,
|
|
31616
|
+
ts2.NodeBuilderFlags.NoTruncation
|
|
31617
|
+
);
|
|
31618
|
+
if (!successType) return fail18("error generating success type");
|
|
31619
|
+
const failureType = typeChecker.typeToTypeNode(
|
|
31620
|
+
returnedEffect.E,
|
|
31621
|
+
atLocation2,
|
|
31622
|
+
ts2.NodeBuilderFlags.NoTruncation
|
|
31623
|
+
);
|
|
31624
|
+
if (!failureType) return fail18("error generating failure type");
|
|
31625
|
+
const typeNode = ts2.factory.createTypeReferenceNode(
|
|
31626
|
+
ts2.factory.createQualifiedName(
|
|
31627
|
+
ts2.factory.createIdentifier(effectIdentifier),
|
|
31628
|
+
ts2.factory.createIdentifier("Effect")
|
|
31629
|
+
),
|
|
31630
|
+
[successType, failureType, contextType]
|
|
31631
|
+
);
|
|
31632
|
+
return succeed17(typeNode);
|
|
31633
|
+
}),
|
|
31634
|
+
orElse14(
|
|
31635
|
+
() => pipe(
|
|
31636
|
+
typeParser.promiseLike(type2, atLocation2),
|
|
31637
|
+
flatMap18(({ type: type3 }) => {
|
|
31638
|
+
const successType = typeChecker.typeToTypeNode(
|
|
31639
|
+
type3,
|
|
31640
|
+
atLocation2,
|
|
31641
|
+
ts2.NodeBuilderFlags.NoTruncation
|
|
31642
|
+
);
|
|
31643
|
+
if (!successType) return fail18("error generating success type");
|
|
31644
|
+
return succeed17(ts2.factory.createTypeReferenceNode(
|
|
31645
|
+
ts2.factory.createQualifiedName(
|
|
31646
|
+
ts2.factory.createIdentifier(effectIdentifier),
|
|
31647
|
+
ts2.factory.createIdentifier("Effect")
|
|
31648
|
+
),
|
|
31649
|
+
[
|
|
31650
|
+
successType,
|
|
31651
|
+
ts2.factory.createTypeReferenceNode(
|
|
31652
|
+
ts2.factory.createQualifiedName(
|
|
31653
|
+
ts2.factory.createIdentifier("Cause"),
|
|
31654
|
+
ts2.factory.createIdentifier("UnknownException")
|
|
31655
|
+
)
|
|
31656
|
+
),
|
|
31657
|
+
ts2.factory.createTypeReferenceNode(className2.text)
|
|
31658
|
+
]
|
|
31659
|
+
));
|
|
31660
|
+
})
|
|
31661
|
+
)
|
|
31662
|
+
),
|
|
31663
|
+
orElse14(() => {
|
|
31664
|
+
const successType = typeChecker.typeToTypeNode(type2, atLocation2, ts2.NodeBuilderFlags.NoTruncation);
|
|
31665
|
+
if (!successType) return fail18("error generating success type");
|
|
31666
|
+
const typeNode = ts2.factory.createTypeReferenceNode(
|
|
31667
|
+
ts2.factory.createQualifiedName(
|
|
31668
|
+
ts2.factory.createIdentifier(effectIdentifier),
|
|
31669
|
+
ts2.factory.createIdentifier("Effect")
|
|
31670
|
+
),
|
|
31671
|
+
[
|
|
31672
|
+
successType,
|
|
31673
|
+
ts2.factory.createTypeReferenceNode("never"),
|
|
31674
|
+
ts2.factory.createTypeReferenceNode(className2.text)
|
|
31675
|
+
]
|
|
31676
|
+
);
|
|
31677
|
+
return succeed17(typeNode);
|
|
31678
|
+
})
|
|
31679
|
+
);
|
|
31680
|
+
const proxySignature = (signature, atLocation2, className2) => gen3(function* () {
|
|
31681
|
+
const signatureDeclaration = typeChecker.signatureToSignatureDeclaration(
|
|
31682
|
+
signature,
|
|
31683
|
+
ts2.SyntaxKind.FunctionType,
|
|
31684
|
+
atLocation2,
|
|
31685
|
+
ts2.NodeBuilderFlags.NoTruncation
|
|
31686
|
+
);
|
|
31687
|
+
if (!signatureDeclaration) return yield* fail18("error generating signature");
|
|
31688
|
+
const returnType = yield* generateReturnType(signature.getReturnType(), atLocation2, className2);
|
|
31689
|
+
return ts2.factory.createFunctionTypeNode(
|
|
31690
|
+
signatureDeclaration.typeParameters,
|
|
31691
|
+
signatureDeclaration.parameters,
|
|
31692
|
+
returnType
|
|
31693
|
+
);
|
|
31694
|
+
});
|
|
31695
|
+
for (const { property, propertyType } of involvedMembers) {
|
|
31696
|
+
const callSignatures = [];
|
|
31697
|
+
let propertyDeclaration = void 0;
|
|
31698
|
+
for (const signature of propertyType.getCallSignatures()) {
|
|
31699
|
+
yield* pipe(
|
|
31700
|
+
proxySignature(signature, atLocation, className),
|
|
31701
|
+
map33((sig) => {
|
|
31702
|
+
callSignatures.push(sig);
|
|
31703
|
+
}),
|
|
31704
|
+
ignore3
|
|
31705
|
+
);
|
|
31706
|
+
}
|
|
31707
|
+
const allSignatures = ts2.factory.createIntersectionTypeNode(callSignatures);
|
|
31708
|
+
const type2 = tsUtils.simplifyTypeNode(allSignatures);
|
|
31709
|
+
propertyDeclaration = createFunctionProperty(className, property.getName(), type2, callSignatures.length > 1);
|
|
31710
|
+
const oldProperty = atLocation.members.filter(ts2.isPropertyDeclaration).find((p2) => {
|
|
31711
|
+
const symbol3 = typeChecker.getSymbolAtLocation(p2.name);
|
|
31712
|
+
return symbol3?.getName() === property.getName();
|
|
31713
|
+
});
|
|
31714
|
+
if (oldProperty) {
|
|
31715
|
+
changeTracker.deleteRange(sourceFile, {
|
|
31716
|
+
pos: oldProperty.getStart(sourceFile),
|
|
31717
|
+
end: oldProperty.getEnd()
|
|
31718
|
+
});
|
|
31719
|
+
changeTracker.insertNodeAt(sourceFile, oldProperty.getStart(sourceFile), propertyDeclaration);
|
|
31720
|
+
} else {
|
|
31721
|
+
changeTracker.insertNodeAt(sourceFile, insertLocation, propertyDeclaration, { suffix: "\n" });
|
|
31722
|
+
}
|
|
31723
|
+
}
|
|
31724
|
+
});
|
|
31725
|
+
var parse5 = fn("writeTagClassAccessors.parse")(function* (node) {
|
|
31726
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
31727
|
+
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31728
|
+
const typeParser = yield* service2(TypeParser);
|
|
31729
|
+
if (!ts2.isClassDeclaration(node)) return yield* fail18("not a class declaration");
|
|
31730
|
+
const { Service, accessors: accessors2, className } = yield* pipe(
|
|
31731
|
+
typeParser.extendsEffectService(node),
|
|
31732
|
+
orElse14(() => fail18("not a class extending Effect.Service call"))
|
|
31733
|
+
);
|
|
31734
|
+
if (accessors2 !== true) return yield* fail18("accessors are not enabled in the Effect.Service call");
|
|
31735
|
+
const involvedMembers = [];
|
|
31736
|
+
for (const property of typeChecker.getPropertiesOfType(Service)) {
|
|
31737
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, node);
|
|
31738
|
+
const callSignatures = propertyType.getCallSignatures();
|
|
31739
|
+
if (callSignatures.length > 0) {
|
|
31740
|
+
const withTypeParameters = callSignatures.filter((_) => _.typeParameters && _.typeParameters.length > 0);
|
|
31741
|
+
if (callSignatures.length > 1 || withTypeParameters.length > 0) involvedMembers.push({ property, propertyType });
|
|
31742
|
+
}
|
|
31743
|
+
}
|
|
31744
|
+
const hash2 = involvedMembers.map(({ property, propertyType }) => {
|
|
31745
|
+
return property.getName() + ": " + typeChecker.typeToString(propertyType);
|
|
31746
|
+
}).concat([className.text]).join("\n");
|
|
31747
|
+
return { Service, className, atLocation: node, hash: cyrb53(hash2), involvedMembers };
|
|
31748
|
+
});
|
|
31749
|
+
var writeTagClassAccessors = createRefactor({
|
|
31750
|
+
name: "writeTagClassAccessors",
|
|
31751
|
+
description: "Implement accessors methods with generics or multiple signatures",
|
|
31752
|
+
apply: fn("writeTagClassAccessors.apply")(function* (sourceFile, textRange) {
|
|
31753
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
31754
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
31755
|
+
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31756
|
+
const typeParser = yield* service2(TypeParser);
|
|
31757
|
+
const parseNode = (node) => pipe(
|
|
31758
|
+
parse5(node),
|
|
31759
|
+
map33(({ Service, atLocation, className, involvedMembers }) => ({
|
|
31760
|
+
kind: "refactor.rewrite.effect.writeTagClassAccessors",
|
|
31761
|
+
description: "Implement Service accessors",
|
|
31762
|
+
apply: pipe(
|
|
31763
|
+
generate(sourceFile, Service, className, atLocation, involvedMembers),
|
|
31764
|
+
provideService7(TypeScriptUtils, tsUtils),
|
|
31765
|
+
provideService7(TypeParser, typeParser),
|
|
31766
|
+
provideService7(TypeCheckerApi, typeChecker),
|
|
31767
|
+
provideService7(TypeScriptApi, ts2)
|
|
31768
|
+
)
|
|
31769
|
+
}))
|
|
31770
|
+
);
|
|
31771
|
+
const parentNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange);
|
|
31772
|
+
return yield* pipe(
|
|
31773
|
+
firstSuccessOf2(parentNodes.map(parseNode)),
|
|
31774
|
+
orElse14(() => fail18(new RefactorNotApplicableError()))
|
|
31775
|
+
);
|
|
31776
|
+
})
|
|
31777
|
+
});
|
|
31778
|
+
|
|
31779
|
+
// src/codegens/accessors.ts
|
|
31780
|
+
var accessors = createCodegen({
|
|
31781
|
+
name: "accessors",
|
|
31782
|
+
apply: fn("accessors.apply")(function* (sourceFile, textRange) {
|
|
31783
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
31784
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
31785
|
+
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31786
|
+
const typeParser = yield* service2(TypeParser);
|
|
31787
|
+
const nodeAndCommentRange = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, textRange.pos);
|
|
31788
|
+
if (!nodeAndCommentRange) return yield* fail18(new CodegenNotApplicableError("no node and comment range"));
|
|
31789
|
+
return yield* pipe(
|
|
31790
|
+
parse5(nodeAndCommentRange.node),
|
|
31791
|
+
map33(
|
|
31792
|
+
(_) => ({
|
|
31793
|
+
hash: _.hash,
|
|
31794
|
+
description: "Generate accessors for the service",
|
|
31795
|
+
apply: pipe(
|
|
31796
|
+
generate(sourceFile, _.Service, _.className, _.atLocation, _.involvedMembers),
|
|
31797
|
+
provideService7(TypeScriptApi, ts2),
|
|
31798
|
+
provideService7(TypeScriptUtils, tsUtils),
|
|
31799
|
+
provideService7(TypeCheckerApi, typeChecker),
|
|
31800
|
+
provideService7(TypeParser, typeParser)
|
|
31801
|
+
)
|
|
31802
|
+
})
|
|
31803
|
+
),
|
|
31804
|
+
orElse14((cause2) => fail18(new CodegenNotApplicableError(cause2)))
|
|
31805
|
+
);
|
|
31806
|
+
})
|
|
31807
|
+
});
|
|
31808
|
+
|
|
31809
|
+
// src/codegens.ts
|
|
31810
|
+
var codegens = [accessors];
|
|
31811
|
+
|
|
31812
|
+
// src/diagnostics/outdatedEffectCodegen.ts
|
|
31813
|
+
var outdatedEffectCodegen = createDiagnostic({
|
|
31814
|
+
name: "outdatedEffectCodegen",
|
|
31815
|
+
code: 19,
|
|
31816
|
+
severity: "warning",
|
|
31817
|
+
apply: fn("outdatedEffectCodegen.apply")(function* (sourceFile, _report) {
|
|
31818
|
+
const codegensWithRanges = yield* getCodegensForSourceFile(codegens, sourceFile);
|
|
31819
|
+
for (const { codegen, hash: hash2, range: range3 } of codegensWithRanges) {
|
|
31820
|
+
yield* pipe(
|
|
31821
|
+
getEditsForCodegen([codegen], sourceFile, range3),
|
|
31822
|
+
map33((applicable) => {
|
|
31823
|
+
if (applicable.hash !== hash2) {
|
|
31824
|
+
_report({
|
|
31825
|
+
location: range3,
|
|
31826
|
+
messageText: `Codegen ${codegen.name} result is outdated`,
|
|
31827
|
+
fixes: [
|
|
31828
|
+
{
|
|
31829
|
+
fixName: "outdatedEffectCodegen_fix",
|
|
31830
|
+
description: `Re-run ${codegen.name}`,
|
|
31831
|
+
apply: applicable.apply
|
|
31832
|
+
},
|
|
31833
|
+
{
|
|
31834
|
+
fixName: "outdatedEffectCodegen_ignore",
|
|
31835
|
+
description: `Ignore this ${codegen.name} update`,
|
|
31836
|
+
apply: applicable.ignore
|
|
31837
|
+
}
|
|
31838
|
+
]
|
|
31839
|
+
});
|
|
31840
|
+
}
|
|
31841
|
+
}),
|
|
31842
|
+
orElse14(
|
|
31843
|
+
(e) => sync11(() => {
|
|
31844
|
+
_report({
|
|
31845
|
+
location: range3,
|
|
31846
|
+
messageText: `Codegen ${codegen.name} is not applicable here: ${e.cause}`,
|
|
31847
|
+
fixes: []
|
|
31848
|
+
});
|
|
31849
|
+
})
|
|
31850
|
+
),
|
|
31851
|
+
ignore3
|
|
31852
|
+
);
|
|
31853
|
+
}
|
|
31854
|
+
})
|
|
31855
|
+
});
|
|
31856
|
+
|
|
31126
31857
|
// src/diagnostics/returnEffectInGen.ts
|
|
31127
31858
|
var returnEffectInGen = createDiagnostic({
|
|
31128
31859
|
name: "returnEffectInGen",
|
|
@@ -31174,7 +31905,7 @@ var returnEffectInGen = createDiagnostic({
|
|
|
31174
31905
|
})
|
|
31175
31906
|
}] : [];
|
|
31176
31907
|
report({
|
|
31177
|
-
node,
|
|
31908
|
+
location: node,
|
|
31178
31909
|
messageText: `You are returning an Effect-able type inside a generator function, and will result in nested Effect<Effect<...>>.
|
|
31179
31910
|
Maybe you wanted to return yield* instead?
|
|
31180
31911
|
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 +31928,14 @@ var scopeInLayerEffect = createDiagnostic({
|
|
|
31197
31928
|
severity: "warning",
|
|
31198
31929
|
apply: fn("scopeInLayerEffect.apply")(function* (sourceFile, report) {
|
|
31199
31930
|
const ts2 = yield* service2(TypeScriptApi);
|
|
31931
|
+
const tsUtils = yield* service2(TypeScriptUtils);
|
|
31200
31932
|
const typeChecker = yield* service2(TypeCheckerApi);
|
|
31201
31933
|
const typeParser = yield* service2(TypeParser);
|
|
31202
|
-
const layerModuleIdentifier =
|
|
31203
|
-
|
|
31204
|
-
|
|
31205
|
-
|
|
31206
|
-
|
|
31207
|
-
),
|
|
31208
|
-
map33((_) => _.text),
|
|
31209
|
-
orElse14(() => succeed17("Layer"))
|
|
31210
|
-
);
|
|
31934
|
+
const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
31935
|
+
sourceFile,
|
|
31936
|
+
"effect",
|
|
31937
|
+
"Layer"
|
|
31938
|
+
) || "Layer";
|
|
31211
31939
|
function parseLayerEffectApiCall(node) {
|
|
31212
31940
|
if (!ts2.isCallExpression(node)) return;
|
|
31213
31941
|
const expression = node.expression;
|
|
@@ -31233,7 +31961,7 @@ var scopeInLayerEffect = createDiagnostic({
|
|
|
31233
31961
|
firstSuccessOf2(entries2.map((type3) => typeParser.scopeType(type3, node))),
|
|
31234
31962
|
map33(
|
|
31235
31963
|
() => report({
|
|
31236
|
-
node,
|
|
31964
|
+
location: node,
|
|
31237
31965
|
messageText: `Seems like you are constructing a layer with a scope in the requirements.
|
|
31238
31966
|
Consider using "scoped" instead to get rid of the scope in the requirements.`,
|
|
31239
31967
|
fixes: methodIdentifier ? [{
|
|
@@ -31349,7 +32077,7 @@ var strictBooleanExpressions = createDiagnostic({
|
|
|
31349
32077
|
if (type2.flags & ts2.TypeFlags.BooleanLiteral) continue;
|
|
31350
32078
|
const typeName = typeChecker.typeToString(type2);
|
|
31351
32079
|
report({
|
|
31352
|
-
|
|
32080
|
+
location: nodeToCheck,
|
|
31353
32081
|
messageText: `Unexpected \`${typeName}\` type in condition, expected strictly a boolean instead.`,
|
|
31354
32082
|
fixes: []
|
|
31355
32083
|
});
|
|
@@ -31391,7 +32119,7 @@ var tryCatchInEffectGen = createDiagnostic({
|
|
|
31391
32119
|
orElse14(() => typeParser.effectFnGen(effectGenNode)),
|
|
31392
32120
|
map33(() => {
|
|
31393
32121
|
report({
|
|
31394
|
-
node,
|
|
32122
|
+
location: node,
|
|
31395
32123
|
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
32124
|
fixes: []
|
|
31397
32125
|
});
|
|
@@ -31426,7 +32154,7 @@ var unnecessaryEffectGen = createDiagnostic({
|
|
|
31426
32154
|
typeParser.unnecessaryEffectGen(node),
|
|
31427
32155
|
map33(
|
|
31428
32156
|
({ replacementNode }) => report({
|
|
31429
|
-
node,
|
|
32157
|
+
location: node,
|
|
31430
32158
|
messageText: `This Effect.gen contains a single return statement.`,
|
|
31431
32159
|
fixes: [{
|
|
31432
32160
|
fixName: "unnecessaryEffectGen_fix",
|
|
@@ -31470,7 +32198,7 @@ var unnecessaryPipe = createDiagnostic({
|
|
|
31470
32198
|
map33(({ args: args3, subject }) => {
|
|
31471
32199
|
if (args3.length === 0) {
|
|
31472
32200
|
report({
|
|
31473
|
-
node,
|
|
32201
|
+
location: node,
|
|
31474
32202
|
messageText: `This pipe call contains no arguments.`,
|
|
31475
32203
|
fixes: [{
|
|
31476
32204
|
fixName: "unnecessaryPipe_fix",
|
|
@@ -31517,7 +32245,7 @@ var unnecessaryPipeChain = createDiagnostic({
|
|
|
31517
32245
|
),
|
|
31518
32246
|
map33(({ innerCall, pipeCall }) => {
|
|
31519
32247
|
report({
|
|
31520
|
-
node,
|
|
32248
|
+
location: node,
|
|
31521
32249
|
messageText: `Chained pipe calls can be simplified to a single pipe call`,
|
|
31522
32250
|
fixes: [{
|
|
31523
32251
|
fixName: "unnecessaryPipeChain_fix",
|
|
@@ -31566,8 +32294,64 @@ var unnecessaryPipeChain = createDiagnostic({
|
|
|
31566
32294
|
})
|
|
31567
32295
|
});
|
|
31568
32296
|
|
|
32297
|
+
// src/diagnostics/unsupportedServiceAccessors.ts
|
|
32298
|
+
var unsupportedServiceAccessors = createDiagnostic({
|
|
32299
|
+
name: "unsupportedServiceAccessors",
|
|
32300
|
+
code: 21,
|
|
32301
|
+
severity: "warning",
|
|
32302
|
+
apply: fn("unsupportedServiceAccessors.apply")(function* (sourceFile, report) {
|
|
32303
|
+
const ts2 = yield* service2(TypeScriptApi);
|
|
32304
|
+
const nodeToVisit = [];
|
|
32305
|
+
const appendNodeToVisit = (node) => {
|
|
32306
|
+
nodeToVisit.push(node);
|
|
32307
|
+
return void 0;
|
|
32308
|
+
};
|
|
32309
|
+
ts2.forEachChild(sourceFile, appendNodeToVisit);
|
|
32310
|
+
while (nodeToVisit.length > 0) {
|
|
32311
|
+
const node = nodeToVisit.shift();
|
|
32312
|
+
ts2.forEachChild(node, appendNodeToVisit);
|
|
32313
|
+
if (ts2.isClassDeclaration(node)) {
|
|
32314
|
+
const parseResult = yield* pipe(
|
|
32315
|
+
parse5(node),
|
|
32316
|
+
orElse14(() => succeed17(null))
|
|
32317
|
+
);
|
|
32318
|
+
if (parseResult && parseResult.involvedMembers.length > 0) {
|
|
32319
|
+
const existingStaticMembers = /* @__PURE__ */ new Set();
|
|
32320
|
+
node.members?.forEach((member) => {
|
|
32321
|
+
if (ts2.isPropertyDeclaration(member) && member.modifiers?.some((mod) => mod.kind === ts2.SyntaxKind.StaticKeyword)) {
|
|
32322
|
+
if (member.name && ts2.isIdentifier(member.name)) {
|
|
32323
|
+
existingStaticMembers.add(member.name.text);
|
|
32324
|
+
}
|
|
32325
|
+
}
|
|
32326
|
+
});
|
|
32327
|
+
const missingMembers = parseResult.involvedMembers.filter(
|
|
32328
|
+
({ property }) => !existingStaticMembers.has(property.getName())
|
|
32329
|
+
);
|
|
32330
|
+
if (missingMembers.length > 0) {
|
|
32331
|
+
const memberNames = missingMembers.map(({ property }) => `'${property.getName()}'`).join(", ");
|
|
32332
|
+
report({
|
|
32333
|
+
location: parseResult.className,
|
|
32334
|
+
messageText: `Even if accessors are enabled, accessors for ${memberNames} won't be available because the signature have generic type parameters or multiple call signatures.`,
|
|
32335
|
+
fixes: [{
|
|
32336
|
+
fixName: "unsupportedServiceAccessors_enableCodegen",
|
|
32337
|
+
description: "Enable accessors codegen",
|
|
32338
|
+
apply: gen3(function* () {
|
|
32339
|
+
const changeTracker = yield* service2(ChangeTracker);
|
|
32340
|
+
const comment = "// @effect-codegens accessors\n";
|
|
32341
|
+
changeTracker.insertText(sourceFile, node.getStart(sourceFile), comment);
|
|
32342
|
+
})
|
|
32343
|
+
}]
|
|
32344
|
+
});
|
|
32345
|
+
}
|
|
32346
|
+
}
|
|
32347
|
+
}
|
|
32348
|
+
}
|
|
32349
|
+
})
|
|
32350
|
+
});
|
|
32351
|
+
|
|
31569
32352
|
// src/diagnostics.ts
|
|
31570
32353
|
var diagnostics = [
|
|
32354
|
+
classSelfMismatch,
|
|
31571
32355
|
duplicatePackage,
|
|
31572
32356
|
missingEffectContext,
|
|
31573
32357
|
missingEffectError,
|
|
@@ -31585,7 +32369,9 @@ var diagnostics = [
|
|
|
31585
32369
|
effectInVoidSuccess,
|
|
31586
32370
|
unnecessaryPipeChain,
|
|
31587
32371
|
strictBooleanExpressions,
|
|
31588
|
-
multipleEffectProvide
|
|
32372
|
+
multipleEffectProvide,
|
|
32373
|
+
outdatedEffectCodegen,
|
|
32374
|
+
unsupportedServiceAccessors
|
|
31589
32375
|
];
|
|
31590
32376
|
|
|
31591
32377
|
// src/cli.ts
|
|
@@ -31728,14 +32514,11 @@ var checkEffect2 = (format6, file3) => gen2(function* () {
|
|
|
31728
32514
|
for (const sourceFile of sourceFiles) {
|
|
31729
32515
|
const outputDiagnostics = pipe(
|
|
31730
32516
|
getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),
|
|
31731
|
-
|
|
31732
|
-
provideService7(TypeScriptProgram, program),
|
|
32517
|
+
nanoLayer2,
|
|
31733
32518
|
provideService7(TypeCheckerApi, program.getTypeChecker()),
|
|
31734
|
-
provideService7(
|
|
31735
|
-
|
|
31736
|
-
|
|
31737
|
-
makeTypeCheckerApiCache()
|
|
31738
|
-
),
|
|
32519
|
+
provideService7(TypeScriptProgram, program),
|
|
32520
|
+
nanoLayer,
|
|
32521
|
+
provideService7(TypeScriptApi, ts),
|
|
31739
32522
|
provideService7(
|
|
31740
32523
|
LanguageServicePluginOptions,
|
|
31741
32524
|
parse4(pluginOptions)
|