@effect/language-service 0.5.0 → 0.6.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/index.js +154 -22
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -64,6 +64,8 @@ var dual = function(arity, body) {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
var identity = (a) => a;
|
|
67
|
+
var constant = (value) => () => value;
|
|
68
|
+
var constUndefined = /* @__PURE__ */ constant(void 0);
|
|
67
69
|
function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
|
|
68
70
|
switch (arguments.length) {
|
|
69
71
|
case 1:
|
|
@@ -113,6 +115,7 @@ var globalValue = (id, compute) => {
|
|
|
113
115
|
};
|
|
114
116
|
|
|
115
117
|
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Predicate.js
|
|
118
|
+
var isBoolean = (input) => typeof input === "boolean";
|
|
116
119
|
var isFunction2 = isFunction;
|
|
117
120
|
var isRecordOrArray = (input) => typeof input === "object" && input !== null;
|
|
118
121
|
var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
|
|
@@ -649,6 +652,7 @@ var isSome2 = isSome;
|
|
|
649
652
|
var getOrElse = /* @__PURE__ */ dual(2, (self, onNone) => isNone2(self) ? onNone() : self.value);
|
|
650
653
|
var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : self);
|
|
651
654
|
var fromNullable = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
|
|
655
|
+
var getOrUndefined = /* @__PURE__ */ getOrElse(constUndefined);
|
|
652
656
|
var map = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() : some2(f(self.value)));
|
|
653
657
|
var flatMap = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() : f(self.value));
|
|
654
658
|
var all = (input) => {
|
|
@@ -811,12 +815,14 @@ function effectGen(ts, typeChecker) {
|
|
|
811
815
|
if (!ts.isPropertyAccessExpression(node.expression)) return yield* none2();
|
|
812
816
|
const propertyAccess = node.expression;
|
|
813
817
|
if (propertyAccess.name.text !== "gen") return yield* none2();
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
818
|
+
const effectModule = yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression);
|
|
819
|
+
return {
|
|
820
|
+
node,
|
|
821
|
+
effectModule,
|
|
822
|
+
generatorFunction,
|
|
823
|
+
body: generatorFunction.body,
|
|
824
|
+
functionStar: generatorFunction.getFirstToken()
|
|
825
|
+
};
|
|
820
826
|
});
|
|
821
827
|
}
|
|
822
828
|
function effectFnUntracedGen(ts, typeChecker) {
|
|
@@ -829,12 +835,14 @@ function effectFnUntracedGen(ts, typeChecker) {
|
|
|
829
835
|
if (!ts.isPropertyAccessExpression(node.expression)) return yield* none2();
|
|
830
836
|
const propertyAccess = node.expression;
|
|
831
837
|
if (propertyAccess.name.text !== "fnUntraced") return yield* none2();
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
+
const effectModule = yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression);
|
|
839
|
+
return {
|
|
840
|
+
node,
|
|
841
|
+
effectModule,
|
|
842
|
+
generatorFunction,
|
|
843
|
+
body: generatorFunction.body,
|
|
844
|
+
functionStar: generatorFunction.getFirstToken()
|
|
845
|
+
};
|
|
838
846
|
});
|
|
839
847
|
}
|
|
840
848
|
function effectFnGen(ts, typeChecker) {
|
|
@@ -848,12 +856,14 @@ function effectFnGen(ts, typeChecker) {
|
|
|
848
856
|
if (!ts.isPropertyAccessExpression(expressionToTest)) return yield* none2();
|
|
849
857
|
const propertyAccess = expressionToTest;
|
|
850
858
|
if (propertyAccess.name.text !== "fn") return yield* none2();
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
859
|
+
const effectModule = yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression);
|
|
860
|
+
return {
|
|
861
|
+
node,
|
|
862
|
+
generatorFunction,
|
|
863
|
+
effectModule,
|
|
864
|
+
body: generatorFunction.body,
|
|
865
|
+
functionStar: generatorFunction.getFirstToken()
|
|
866
|
+
};
|
|
857
867
|
});
|
|
858
868
|
}
|
|
859
869
|
function expectedAndRealType(ts, typeChecker) {
|
|
@@ -955,6 +965,25 @@ var floatingEffect = createDiagnostic({
|
|
|
955
965
|
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/array.js
|
|
956
966
|
var isNonEmptyArray = (self) => self.length > 0;
|
|
957
967
|
|
|
968
|
+
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Iterable.js
|
|
969
|
+
var findFirst = /* @__PURE__ */ dual(2, (self, f) => {
|
|
970
|
+
let i = 0;
|
|
971
|
+
for (const a of self) {
|
|
972
|
+
const o = f(a, i);
|
|
973
|
+
if (isBoolean(o)) {
|
|
974
|
+
if (o) {
|
|
975
|
+
return some2(a);
|
|
976
|
+
}
|
|
977
|
+
} else {
|
|
978
|
+
if (isSome2(o)) {
|
|
979
|
+
return o;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
i++;
|
|
983
|
+
}
|
|
984
|
+
return none2();
|
|
985
|
+
});
|
|
986
|
+
|
|
958
987
|
// node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Array.js
|
|
959
988
|
var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
|
|
960
989
|
var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
|
|
@@ -976,6 +1005,7 @@ var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
|
|
|
976
1005
|
var head = /* @__PURE__ */ get(0);
|
|
977
1006
|
var headNonEmpty = /* @__PURE__ */ unsafeGet(0);
|
|
978
1007
|
var tailNonEmpty = (self) => self.slice(1);
|
|
1008
|
+
var findFirst2 = findFirst;
|
|
979
1009
|
var sort = /* @__PURE__ */ dual(2, (self, O) => {
|
|
980
1010
|
const out = Array.from(self);
|
|
981
1011
|
out.sort(O);
|
|
@@ -1541,7 +1571,9 @@ var asyncAwaitToGen = createRefactor({
|
|
|
1541
1571
|
description: "Convert to Effect.gen",
|
|
1542
1572
|
apply: (ts, program) => (sourceFile, textRange) => pipe(
|
|
1543
1573
|
getNodesContainingRange(ts)(sourceFile, textRange),
|
|
1544
|
-
filter(
|
|
1574
|
+
filter(
|
|
1575
|
+
(node) => ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)
|
|
1576
|
+
),
|
|
1545
1577
|
filter((node) => !!node.body),
|
|
1546
1578
|
filter(
|
|
1547
1579
|
(node) => !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)
|
|
@@ -1587,7 +1619,9 @@ var asyncAwaitToGenTryPromise = createRefactor({
|
|
|
1587
1619
|
description: "Convert to Effect.gen with failures",
|
|
1588
1620
|
apply: (ts, program) => (sourceFile, textRange) => pipe(
|
|
1589
1621
|
getNodesContainingRange(ts)(sourceFile, textRange),
|
|
1590
|
-
filter(
|
|
1622
|
+
filter(
|
|
1623
|
+
(node) => ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)
|
|
1624
|
+
),
|
|
1591
1625
|
filter((node) => !!node.body),
|
|
1592
1626
|
filter(
|
|
1593
1627
|
(node) => !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)
|
|
@@ -1657,6 +1691,94 @@ var asyncAwaitToGenTryPromise = createRefactor({
|
|
|
1657
1691
|
)
|
|
1658
1692
|
});
|
|
1659
1693
|
|
|
1694
|
+
// src/refactors/effectGenToFn.ts
|
|
1695
|
+
var effectGenToFn = createRefactor({
|
|
1696
|
+
name: "effect/effectGenToFn",
|
|
1697
|
+
description: "Convert to Effect.fn",
|
|
1698
|
+
apply: (ts, program) => (sourceFile, textRange) => pipe(
|
|
1699
|
+
getNodesContainingRange(ts)(sourceFile, textRange),
|
|
1700
|
+
findFirst2(
|
|
1701
|
+
(node) => gen(function* () {
|
|
1702
|
+
const effectGen2 = yield* effectGen(ts, program.getTypeChecker())(node);
|
|
1703
|
+
let pipeArgs = ts.factory.createNodeArray([]);
|
|
1704
|
+
let nodeToReplace = node.parent;
|
|
1705
|
+
if (ts.isPropertyAccessExpression(node.parent) && node.parent.name.text === "pipe" && ts.isCallExpression(node.parent.parent)) {
|
|
1706
|
+
pipeArgs = node.parent.parent.arguments;
|
|
1707
|
+
nodeToReplace = node.parent.parent.parent;
|
|
1708
|
+
}
|
|
1709
|
+
while (nodeToReplace) {
|
|
1710
|
+
if (ts.isArrowFunction(nodeToReplace) || ts.isFunctionDeclaration(nodeToReplace)) {
|
|
1711
|
+
return { ...effectGen2, pipeArgs, nodeToReplace };
|
|
1712
|
+
}
|
|
1713
|
+
if (ts.isConciseBody(nodeToReplace) || ts.isReturnStatement(nodeToReplace)) {
|
|
1714
|
+
nodeToReplace = nodeToReplace.parent;
|
|
1715
|
+
continue;
|
|
1716
|
+
}
|
|
1717
|
+
if (ts.isBlock(nodeToReplace) && nodeToReplace.statements.length === 1) {
|
|
1718
|
+
nodeToReplace = nodeToReplace.parent;
|
|
1719
|
+
continue;
|
|
1720
|
+
}
|
|
1721
|
+
break;
|
|
1722
|
+
}
|
|
1723
|
+
return yield* none2();
|
|
1724
|
+
})
|
|
1725
|
+
),
|
|
1726
|
+
map(
|
|
1727
|
+
({ effectModule, generatorFunction, nodeToReplace, pipeArgs }) => ({
|
|
1728
|
+
kind: "refactor.rewrite.effect.effectGenToFn",
|
|
1729
|
+
description: "Convert to Effect.fn",
|
|
1730
|
+
apply: (changeTracker) => {
|
|
1731
|
+
const effectFn = nodeToReplace.name ? ts.factory.createCallExpression(
|
|
1732
|
+
ts.factory.createPropertyAccessExpression(
|
|
1733
|
+
effectModule,
|
|
1734
|
+
"fn"
|
|
1735
|
+
),
|
|
1736
|
+
void 0,
|
|
1737
|
+
[ts.factory.createStringLiteral(nodeToReplace.name.text)]
|
|
1738
|
+
) : ts.factory.createPropertyAccessExpression(
|
|
1739
|
+
effectModule,
|
|
1740
|
+
"fn"
|
|
1741
|
+
);
|
|
1742
|
+
const effectFnCallWithGenerator = ts.factory.createCallExpression(
|
|
1743
|
+
effectFn,
|
|
1744
|
+
void 0,
|
|
1745
|
+
[ts.factory.createFunctionExpression(
|
|
1746
|
+
void 0,
|
|
1747
|
+
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
1748
|
+
void 0,
|
|
1749
|
+
nodeToReplace.typeParameters,
|
|
1750
|
+
nodeToReplace.parameters,
|
|
1751
|
+
nodeToReplace.type,
|
|
1752
|
+
generatorFunction.body
|
|
1753
|
+
)].concat(pipeArgs)
|
|
1754
|
+
);
|
|
1755
|
+
if (!ts.isArrowFunction(nodeToReplace) && nodeToReplace.name) {
|
|
1756
|
+
const variableDeclaration = ts.factory.createVariableStatement(
|
|
1757
|
+
nodeToReplace.modifiers,
|
|
1758
|
+
ts.factory.createVariableDeclarationList(
|
|
1759
|
+
[ts.factory.createVariableDeclaration(
|
|
1760
|
+
nodeToReplace.name,
|
|
1761
|
+
void 0,
|
|
1762
|
+
void 0,
|
|
1763
|
+
effectFnCallWithGenerator
|
|
1764
|
+
)],
|
|
1765
|
+
ts.NodeFlags.Const
|
|
1766
|
+
)
|
|
1767
|
+
);
|
|
1768
|
+
changeTracker.replaceNode(
|
|
1769
|
+
sourceFile,
|
|
1770
|
+
nodeToReplace,
|
|
1771
|
+
variableDeclaration
|
|
1772
|
+
);
|
|
1773
|
+
} else {
|
|
1774
|
+
changeTracker.replaceNode(sourceFile, nodeToReplace, effectFnCallWithGenerator);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
})
|
|
1778
|
+
)
|
|
1779
|
+
)
|
|
1780
|
+
});
|
|
1781
|
+
|
|
1660
1782
|
// src/refactors/functionToArrow.ts
|
|
1661
1783
|
var functionToArrow = createRefactor({
|
|
1662
1784
|
name: "effect/functionToArrow",
|
|
@@ -1894,10 +2016,19 @@ var toggleTypeAnnotation = createRefactor({
|
|
|
1894
2016
|
}
|
|
1895
2017
|
const initializer = node.initializer;
|
|
1896
2018
|
const initializerType = typeChecker.getTypeAtLocation(initializer);
|
|
1897
|
-
const initializerTypeNode = typeChecker.typeToTypeNode(
|
|
2019
|
+
const initializerTypeNode = fromNullable(typeChecker.typeToTypeNode(
|
|
1898
2020
|
initializerType,
|
|
1899
2021
|
node,
|
|
1900
2022
|
ts.NodeBuilderFlags.NoTruncation
|
|
2023
|
+
)).pipe(
|
|
2024
|
+
orElse(
|
|
2025
|
+
() => fromNullable(typeChecker.typeToTypeNode(
|
|
2026
|
+
initializerType,
|
|
2027
|
+
void 0,
|
|
2028
|
+
ts.NodeBuilderFlags.NoTruncation
|
|
2029
|
+
))
|
|
2030
|
+
),
|
|
2031
|
+
getOrUndefined
|
|
1901
2032
|
);
|
|
1902
2033
|
if (initializerTypeNode) {
|
|
1903
2034
|
changeTracker.insertNodeAt(
|
|
@@ -1941,7 +2072,8 @@ var refactors = {
|
|
|
1941
2072
|
toggleLazyConst,
|
|
1942
2073
|
toggleReturnTypeAnnotation,
|
|
1943
2074
|
toggleTypeAnnotation,
|
|
1944
|
-
wrapWithPipe
|
|
2075
|
+
wrapWithPipe,
|
|
2076
|
+
effectGenToFn
|
|
1945
2077
|
};
|
|
1946
2078
|
|
|
1947
2079
|
// src/index.ts
|