@effect/language-service 0.8.1 → 0.9.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 +953 -709
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2671,8 +2671,6 @@ var TaggedError = (tag) => {
|
|
|
2671
2671
|
};
|
|
2672
2672
|
|
|
2673
2673
|
// src/core/Nano.ts
|
|
2674
|
-
var NanoInterruptedException = class extends TaggedError("NanoInterruptedException") {
|
|
2675
|
-
};
|
|
2676
2674
|
var NanoDefectException = class extends TaggedError("NanoDefectException") {
|
|
2677
2675
|
};
|
|
2678
2676
|
var NanoTag = class {
|
|
@@ -2703,40 +2701,44 @@ var Nano = class {
|
|
|
2703
2701
|
return new SingleShotGen(new YieldWrap(this));
|
|
2704
2702
|
}
|
|
2705
2703
|
};
|
|
2706
|
-
var run = (fa) =>
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
);
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2704
|
+
var run = (fa) => {
|
|
2705
|
+
try {
|
|
2706
|
+
const result = fa.run(contextEmpty);
|
|
2707
|
+
switch (result._tag) {
|
|
2708
|
+
case "Left":
|
|
2709
|
+
return left2(result.left);
|
|
2710
|
+
case "Defect":
|
|
2711
|
+
return left2(new NanoDefectException({ message: result.defect }));
|
|
2712
|
+
case "Right":
|
|
2713
|
+
return right2(result.right);
|
|
2714
|
+
}
|
|
2715
|
+
} catch (e) {
|
|
2716
|
+
return left2(new NanoDefectException({ message: e }));
|
|
2717
|
+
}
|
|
2718
|
+
};
|
|
2719
|
+
var succeed = (value) => new Nano(() => ({ _tag: "Right", right: value }));
|
|
2720
|
+
var fail3 = (value) => new Nano(() => ({ _tag: "Left", left: value }));
|
|
2721
|
+
var sync = (value) => new Nano(() => ({ _tag: "Right", right: value() }));
|
|
2717
2722
|
var flatMap4 = dual(2, (fa, f) => new Nano((ctx) => {
|
|
2718
2723
|
const result = fa.run(ctx);
|
|
2719
|
-
if (
|
|
2720
|
-
|
|
2721
|
-
return f(result.right.right).run(ctx);
|
|
2724
|
+
if (result._tag !== "Right") return result;
|
|
2725
|
+
return f(result.right).run(ctx);
|
|
2722
2726
|
}));
|
|
2723
2727
|
var map7 = dual(2, (fa, f) => new Nano((ctx) => {
|
|
2724
2728
|
const result = fa.run(ctx);
|
|
2725
|
-
if (
|
|
2726
|
-
|
|
2727
|
-
return right2(right2(f(result.right.right)));
|
|
2729
|
+
if (result._tag !== "Right") return result;
|
|
2730
|
+
return { _tag: "Right", right: f(result.right) };
|
|
2728
2731
|
}));
|
|
2729
2732
|
var orElse3 = (f) => (fa) => new Nano((ctx) => {
|
|
2730
2733
|
const result = fa.run(ctx);
|
|
2731
|
-
if (
|
|
2732
|
-
if (isLeft2(result.right)) return f().run(ctx);
|
|
2734
|
+
if (result._tag === "Left") return f().run(ctx);
|
|
2733
2735
|
return result;
|
|
2734
2736
|
});
|
|
2735
2737
|
var firstSuccessOf = (arr) => reduce(arr.slice(1), arr[0], (arr2, fa) => orElse3(() => fa)(arr2));
|
|
2736
2738
|
var service = (tag) => new Nano(
|
|
2737
2739
|
(ctx) => contextGet(ctx, tag).pipe(match2({
|
|
2738
|
-
onNone: () =>
|
|
2739
|
-
onSome: (value) =>
|
|
2740
|
+
onNone: () => ({ _tag: "Defect", defect: `Cannot find service ${tag.key}` }),
|
|
2741
|
+
onSome: (value) => ({ _tag: "Right", right: value })
|
|
2740
2742
|
}))
|
|
2741
2743
|
);
|
|
2742
2744
|
var provideService = (tag, value) => (fa) => new Nano((ctx) => {
|
|
@@ -2748,25 +2750,36 @@ var gen2 = (...args) => new Nano((ctx) => {
|
|
|
2748
2750
|
while (!state.done) {
|
|
2749
2751
|
const current = isGenKind(state.value) ? state.value.value : yieldWrapGet(state.value);
|
|
2750
2752
|
const result = current.run(ctx);
|
|
2751
|
-
if (
|
|
2753
|
+
if (result._tag !== "Right") {
|
|
2752
2754
|
return result;
|
|
2753
2755
|
}
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
+
state = iterator.next(result.right);
|
|
2757
|
+
}
|
|
2758
|
+
return { _tag: "Right", right: state.value };
|
|
2759
|
+
});
|
|
2760
|
+
var fn = (_) => (body) => (...args) => new Nano((ctx) => {
|
|
2761
|
+
const iterator = body(...args);
|
|
2762
|
+
let state = iterator.next();
|
|
2763
|
+
while (!state.done) {
|
|
2764
|
+
const current = isGenKind(state.value) ? state.value.value : yieldWrapGet(state.value);
|
|
2765
|
+
const result = current.run(ctx);
|
|
2766
|
+
if (result._tag !== "Right") {
|
|
2756
2767
|
return result;
|
|
2757
2768
|
}
|
|
2758
|
-
state = iterator.next(
|
|
2769
|
+
state = iterator.next(result.right);
|
|
2759
2770
|
}
|
|
2760
|
-
return
|
|
2771
|
+
return { _tag: "Right", right: state.value };
|
|
2761
2772
|
});
|
|
2762
2773
|
var option = (fa) => new Nano((ctx) => {
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2774
|
+
const result = fa.run(ctx);
|
|
2775
|
+
switch (result._tag) {
|
|
2776
|
+
case "Right":
|
|
2777
|
+
return { _tag: "Right", right: some2(result.right) };
|
|
2778
|
+
case "Left":
|
|
2779
|
+
return { _tag: "Right", right: none2() };
|
|
2780
|
+
case "Defect":
|
|
2781
|
+
return result;
|
|
2782
|
+
}
|
|
2770
2783
|
});
|
|
2771
2784
|
|
|
2772
2785
|
// src/core/LSP.ts
|
|
@@ -2778,89 +2791,514 @@ function createRefactor(definition) {
|
|
|
2778
2791
|
function createDiagnostic(definition) {
|
|
2779
2792
|
return definition;
|
|
2780
2793
|
}
|
|
2794
|
+
function createCompletion(definition) {
|
|
2795
|
+
return definition;
|
|
2796
|
+
}
|
|
2781
2797
|
var PluginOptions = Tag("PluginOptions");
|
|
2782
2798
|
var SourceFileNotFoundError = class extends TaggedError("SourceFileNotFoundError") {
|
|
2783
2799
|
};
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2800
|
+
var getSemanticDiagnostics = fn("LSP.getSemanticDiagnostics")(function* (diagnostics2, sourceFile) {
|
|
2801
|
+
const effectDiagnostics = [];
|
|
2802
|
+
for (const diagnostic of diagnostics2) {
|
|
2803
|
+
const result = yield* option(diagnostic.apply(sourceFile));
|
|
2804
|
+
if (isSome2(result)) {
|
|
2805
|
+
effectDiagnostics.push(...result.value.map((_) => ({
|
|
2806
|
+
file: sourceFile,
|
|
2807
|
+
start: _.node.getStart(sourceFile),
|
|
2808
|
+
length: _.node.getEnd() - _.node.getStart(sourceFile),
|
|
2809
|
+
messageText: _.messageText,
|
|
2810
|
+
category: _.category,
|
|
2811
|
+
code: diagnostic.code,
|
|
2812
|
+
source: "effect"
|
|
2813
|
+
})));
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
return effectDiagnostics;
|
|
2817
|
+
});
|
|
2818
|
+
var getCodeFixesAtPosition = fn("LSP.getCodeFixesAtPosition")(function* (diagnostics2, sourceFile, start, end, errorCodes) {
|
|
2819
|
+
const runnableDiagnostics = diagnostics2.filter((_) => errorCodes.indexOf(_.code) > -1);
|
|
2820
|
+
const applicableFixes = [];
|
|
2821
|
+
for (const diagnostic of runnableDiagnostics) {
|
|
2822
|
+
const result = yield* option(diagnostic.apply(sourceFile));
|
|
2823
|
+
if (isSome2(result)) {
|
|
2824
|
+
applicableFixes.push(
|
|
2825
|
+
...pipe(
|
|
2826
|
+
result.value,
|
|
2827
|
+
filter(
|
|
2828
|
+
(_) => _.node.getStart(sourceFile) === start && _.node.getEnd() === end
|
|
2829
|
+
),
|
|
2830
|
+
map2((_) => _.fix),
|
|
2831
|
+
getSomes
|
|
2832
|
+
)
|
|
2833
|
+
);
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
return applicableFixes;
|
|
2837
|
+
});
|
|
2838
|
+
var getApplicableRefactors = fn("LSP.getApplicableRefactors")(function* (refactors2, sourceFile, positionOrRange) {
|
|
2839
|
+
const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
|
|
2840
|
+
const effectRefactors = [];
|
|
2841
|
+
for (const refactor of refactors2) {
|
|
2842
|
+
const result = yield* option(refactor.apply(sourceFile, textRange));
|
|
2843
|
+
if (isSome2(result)) {
|
|
2844
|
+
effectRefactors.push({
|
|
2845
|
+
name: refactor.name,
|
|
2846
|
+
description: refactor.description,
|
|
2847
|
+
actions: [{
|
|
2848
|
+
name: refactor.name,
|
|
2849
|
+
description: result.value.description,
|
|
2850
|
+
kind: result.value.kind
|
|
2851
|
+
}]
|
|
2852
|
+
});
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
return effectRefactors;
|
|
2856
|
+
});
|
|
2857
|
+
var getEditsForRefactor = fn("LSP.getEditsForRefactor")(function* (refactors2, sourceFile, positionOrRange, refactorName) {
|
|
2858
|
+
const refactor = refactors2.find((refactor2) => refactor2.name === refactorName);
|
|
2859
|
+
if (!refactor) {
|
|
2860
|
+
return yield* fail3(new RefactorNotApplicableError());
|
|
2861
|
+
}
|
|
2862
|
+
const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
|
|
2863
|
+
return yield* refactor.apply(sourceFile, textRange);
|
|
2864
|
+
});
|
|
2865
|
+
var getCompletionsAtPosition = fn("LSP.getCompletionsAtPosition")(function* (completions2, sourceFile, position, options, formatCodeSettings) {
|
|
2866
|
+
const effectCompletions = [];
|
|
2867
|
+
for (const completion of completions2) {
|
|
2868
|
+
const result = yield* completion.apply(sourceFile, position, options, formatCodeSettings);
|
|
2869
|
+
effectCompletions.push(
|
|
2870
|
+
...result.map((_) => ({ sortText: "11", ..._ }))
|
|
2871
|
+
);
|
|
2872
|
+
}
|
|
2873
|
+
return effectCompletions;
|
|
2874
|
+
});
|
|
2875
|
+
|
|
2876
|
+
// src/utils/TypeScriptApi.ts
|
|
2877
|
+
var TypeScriptApi = Tag("TypeScriptApi");
|
|
2878
|
+
var ChangeTracker = Tag("ChangeTracker");
|
|
2879
|
+
|
|
2880
|
+
// src/utils/AST.ts
|
|
2881
|
+
function collectSelfAndAncestorNodesInRange(node, textRange) {
|
|
2882
|
+
return sync(() => {
|
|
2883
|
+
let result = empty();
|
|
2884
|
+
let parent = node;
|
|
2885
|
+
while (parent) {
|
|
2886
|
+
if (parent.end >= textRange.end) {
|
|
2887
|
+
result = pipe(result, append(parent));
|
|
2799
2888
|
}
|
|
2889
|
+
parent = parent.parent;
|
|
2800
2890
|
}
|
|
2801
|
-
return
|
|
2891
|
+
return result;
|
|
2802
2892
|
});
|
|
2803
2893
|
}
|
|
2804
|
-
function
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2894
|
+
var getAncestorNodesInRange = fn("AST.getAncestorNodesInRange")(function* (sourceFile, textRange) {
|
|
2895
|
+
const ts = yield* service(TypeScriptApi);
|
|
2896
|
+
const precedingToken = ts.findPrecedingToken(textRange.pos, sourceFile);
|
|
2897
|
+
if (!precedingToken) return empty();
|
|
2898
|
+
return yield* collectSelfAndAncestorNodesInRange(precedingToken, textRange);
|
|
2899
|
+
});
|
|
2900
|
+
var NodeNotFoundError = class extends TaggedError("@effect/language-service/NodeNotFoundError") {
|
|
2901
|
+
};
|
|
2902
|
+
var findNodeAtPosition = fn("AST.findNodeAtPosition")(function* (sourceFile, position) {
|
|
2903
|
+
const ts = yield* service(TypeScriptApi);
|
|
2904
|
+
function find(node) {
|
|
2905
|
+
if (position >= node.getStart() && position < node.getEnd()) {
|
|
2906
|
+
return ts.forEachChild(node, find) || node;
|
|
2907
|
+
}
|
|
2908
|
+
return void 0;
|
|
2909
|
+
}
|
|
2910
|
+
const result = find(sourceFile);
|
|
2911
|
+
if (!result) return yield* fail3(new NodeNotFoundError());
|
|
2912
|
+
return result;
|
|
2913
|
+
});
|
|
2914
|
+
var collectDescendantsAndAncestorsInRange = fn(
|
|
2915
|
+
"AST.collectDescendantsAndAncestorsInRange"
|
|
2916
|
+
)(function* (sourceFile, textRange) {
|
|
2917
|
+
const nodeAtPosition = yield* option(findNodeAtPosition(sourceFile, textRange.pos));
|
|
2918
|
+
if (isNone2(nodeAtPosition)) return empty();
|
|
2919
|
+
return yield* collectSelfAndAncestorNodesInRange(nodeAtPosition.value, textRange);
|
|
2920
|
+
});
|
|
2921
|
+
function toTextRange(positionOrRange) {
|
|
2922
|
+
return typeof positionOrRange === "number" ? { end: positionOrRange, pos: positionOrRange } : positionOrRange;
|
|
2923
|
+
}
|
|
2924
|
+
function isNodeInRange(textRange) {
|
|
2925
|
+
return (node) => node.pos <= textRange.pos && node.end >= textRange.end;
|
|
2926
|
+
}
|
|
2927
|
+
var transformAsyncAwaitToEffectGen = fn("AST.transformAsyncAwaitToEffectGen")(
|
|
2928
|
+
function* (node, effectModuleName, onAwait) {
|
|
2929
|
+
const ts = yield* service(TypeScriptApi);
|
|
2930
|
+
function visitor(_) {
|
|
2931
|
+
if (ts.isAwaitExpression(_)) {
|
|
2932
|
+
const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext);
|
|
2933
|
+
return ts.factory.createYieldExpression(
|
|
2934
|
+
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
2935
|
+
onAwait(expression)
|
|
2820
2936
|
);
|
|
2821
2937
|
}
|
|
2938
|
+
return ts.visitEachChild(_, visitor, ts.nullTransformationContext);
|
|
2822
2939
|
}
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2940
|
+
const generatorBody = visitor(node.body);
|
|
2941
|
+
const generator = ts.factory.createFunctionExpression(
|
|
2942
|
+
void 0,
|
|
2943
|
+
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
2944
|
+
void 0,
|
|
2945
|
+
[],
|
|
2946
|
+
[],
|
|
2947
|
+
void 0,
|
|
2948
|
+
generatorBody
|
|
2949
|
+
// NOTE(mattia): intended, to use same routine for both ConciseBody and Body
|
|
2950
|
+
);
|
|
2951
|
+
const effectGenCallExp = ts.factory.createCallExpression(
|
|
2952
|
+
ts.factory.createPropertyAccessExpression(
|
|
2953
|
+
ts.factory.createIdentifier(effectModuleName),
|
|
2954
|
+
"gen"
|
|
2955
|
+
),
|
|
2956
|
+
void 0,
|
|
2957
|
+
[generator]
|
|
2958
|
+
);
|
|
2959
|
+
let currentFlags = ts.getCombinedModifierFlags(node);
|
|
2960
|
+
currentFlags &= ~ts.ModifierFlags.Async;
|
|
2961
|
+
const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags);
|
|
2962
|
+
if (ts.isArrowFunction(node)) {
|
|
2963
|
+
return ts.factory.createArrowFunction(
|
|
2964
|
+
newModifiers,
|
|
2965
|
+
node.typeParameters,
|
|
2966
|
+
node.parameters,
|
|
2967
|
+
void 0,
|
|
2968
|
+
node.equalsGreaterThanToken,
|
|
2969
|
+
effectGenCallExp
|
|
2970
|
+
);
|
|
2971
|
+
}
|
|
2972
|
+
const newBody = ts.factory.createBlock([
|
|
2973
|
+
ts.factory.createReturnStatement(effectGenCallExp)
|
|
2974
|
+
]);
|
|
2975
|
+
if (ts.isFunctionDeclaration(node)) {
|
|
2976
|
+
return ts.factory.createFunctionDeclaration(
|
|
2977
|
+
newModifiers,
|
|
2978
|
+
node.asteriskToken,
|
|
2979
|
+
node.name,
|
|
2980
|
+
node.typeParameters,
|
|
2981
|
+
node.parameters,
|
|
2982
|
+
void 0,
|
|
2983
|
+
newBody
|
|
2984
|
+
);
|
|
2985
|
+
}
|
|
2986
|
+
return ts.factory.createFunctionExpression(
|
|
2987
|
+
newModifiers,
|
|
2988
|
+
node.asteriskToken,
|
|
2989
|
+
node.name,
|
|
2990
|
+
node.typeParameters,
|
|
2991
|
+
node.parameters,
|
|
2992
|
+
void 0,
|
|
2993
|
+
newBody
|
|
2994
|
+
);
|
|
2995
|
+
}
|
|
2996
|
+
);
|
|
2997
|
+
var addReturnTypeAnnotation = fn("AST.addReturnTypeAnnotation")(function* (sourceFile, declaration, typeNode) {
|
|
2998
|
+
const ts = yield* service(TypeScriptApi);
|
|
2999
|
+
const changes = yield* service(ChangeTracker);
|
|
3000
|
+
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
|
|
3001
|
+
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
3002
|
+
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
3003
|
+
if (endNode) {
|
|
3004
|
+
if (needParens) {
|
|
3005
|
+
changes.insertNodeBefore(
|
|
3006
|
+
sourceFile,
|
|
3007
|
+
endNode,
|
|
3008
|
+
ts.factory.createToken(ts.SyntaxKind.OpenParenToken)
|
|
3009
|
+
);
|
|
3010
|
+
changes.insertNodeAfter(
|
|
3011
|
+
sourceFile,
|
|
3012
|
+
endNode,
|
|
3013
|
+
ts.factory.createToken(ts.SyntaxKind.CloseParenToken)
|
|
3014
|
+
);
|
|
3015
|
+
}
|
|
3016
|
+
changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: ": " });
|
|
3017
|
+
}
|
|
3018
|
+
});
|
|
3019
|
+
var removeReturnTypeAnnotation = fn("AST.removeReturnTypeAnnotation")(function* (sourceFile, declaration) {
|
|
3020
|
+
const ts = yield* service(TypeScriptApi);
|
|
3021
|
+
const changes = yield* service(ChangeTracker);
|
|
3022
|
+
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
|
|
3023
|
+
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
3024
|
+
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
3025
|
+
if (endNode && declaration.type) {
|
|
3026
|
+
changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end });
|
|
3027
|
+
}
|
|
3028
|
+
});
|
|
3029
|
+
var ImportModuleIdentifierNotFoundError = class extends TaggedError("@effect/language-service/ImportModuleIdentifierNotFoundError") {
|
|
3030
|
+
};
|
|
3031
|
+
var findImportedModuleIdentifier = fn("AST.findImportedModuleIdentifier")(
|
|
3032
|
+
function* (sourceFile, test) {
|
|
3033
|
+
const ts = yield* service(TypeScriptApi);
|
|
3034
|
+
for (const statement of sourceFile.statements) {
|
|
3035
|
+
if (!ts.isImportDeclaration(statement)) continue;
|
|
3036
|
+
const importClause = statement.importClause;
|
|
3037
|
+
if (!importClause) continue;
|
|
3038
|
+
const namedBindings = importClause.namedBindings;
|
|
3039
|
+
if (!namedBindings) continue;
|
|
3040
|
+
if (ts.isNamespaceImport(namedBindings)) {
|
|
3041
|
+
if (yield* test(namedBindings.name, statement.moduleSpecifier, none2())) {
|
|
3042
|
+
return namedBindings.name;
|
|
3043
|
+
}
|
|
3044
|
+
} else if (ts.isNamedImports(namedBindings)) {
|
|
3045
|
+
for (const importSpecifier of namedBindings.elements) {
|
|
3046
|
+
const importProperty = fromNullable2(importSpecifier.propertyName).pipe(
|
|
3047
|
+
orElse2(() => some2(importSpecifier.name))
|
|
3048
|
+
);
|
|
3049
|
+
if (yield* test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
|
|
3050
|
+
return importSpecifier.name;
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
2842
3053
|
}
|
|
2843
3054
|
}
|
|
2844
|
-
return
|
|
2845
|
-
}
|
|
3055
|
+
return yield* fail3(new ImportModuleIdentifierNotFoundError());
|
|
3056
|
+
}
|
|
3057
|
+
);
|
|
3058
|
+
function findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, packageName, moduleName) {
|
|
3059
|
+
return findImportedModuleIdentifier(
|
|
3060
|
+
sourceFile,
|
|
3061
|
+
fn(
|
|
3062
|
+
"AST.findImportedModuleIdentifierByPackageAndNameOrBarrel.findImportedModuleIdentifier"
|
|
3063
|
+
)(function* (_, fromModule, importProperty) {
|
|
3064
|
+
const ts = yield* service(TypeScriptApi);
|
|
3065
|
+
if (isNone2(importProperty) && ts.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
|
|
3066
|
+
return true;
|
|
3067
|
+
}
|
|
3068
|
+
if (isSome2(importProperty) && ts.isIdentifier(importProperty.value) && importProperty.value.text === moduleName && ts.isStringLiteral(fromModule) && fromModule.text === packageName) {
|
|
3069
|
+
return true;
|
|
3070
|
+
}
|
|
3071
|
+
return false;
|
|
3072
|
+
})
|
|
3073
|
+
);
|
|
2846
3074
|
}
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
if (
|
|
2851
|
-
|
|
3075
|
+
var simplifyTypeNode = fn("AST.simplifyTypeNode")(function* (typeNode) {
|
|
3076
|
+
const ts = yield* service(TypeScriptApi);
|
|
3077
|
+
function collectCallable(typeNode2) {
|
|
3078
|
+
if (ts.isParenthesizedTypeNode(typeNode2)) return collectCallable(typeNode2.type);
|
|
3079
|
+
if (ts.isFunctionTypeNode(typeNode2)) {
|
|
3080
|
+
return some2([
|
|
3081
|
+
ts.factory.createCallSignature(typeNode2.typeParameters, typeNode2.parameters, typeNode2.type)
|
|
3082
|
+
]);
|
|
2852
3083
|
}
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
3084
|
+
if (ts.isTypeLiteralNode(typeNode2)) {
|
|
3085
|
+
const allCallSignatures = typeNode2.members.every(ts.isCallSignatureDeclaration);
|
|
3086
|
+
if (allCallSignatures) {
|
|
3087
|
+
return some2(typeNode2.members);
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
if (ts.isIntersectionTypeNode(typeNode2)) {
|
|
3091
|
+
const members = typeNode2.types.map((node) => collectCallable(node));
|
|
3092
|
+
if (members.every(isSome2)) {
|
|
3093
|
+
return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
return none2();
|
|
3097
|
+
}
|
|
3098
|
+
const callSignatures = collectCallable(typeNode);
|
|
3099
|
+
if (isSome2(callSignatures) && callSignatures.value.length > 1) {
|
|
3100
|
+
return ts.factory.createTypeLiteralNode(callSignatures.value);
|
|
3101
|
+
}
|
|
3102
|
+
return typeNode;
|
|
3103
|
+
});
|
|
3104
|
+
var tryPreserveDeclarationSemantics = fn("AST.tryPreserveDeclarationSemantics")(
|
|
3105
|
+
function* (nodeToReplace, node) {
|
|
3106
|
+
const ts = yield* service(TypeScriptApi);
|
|
3107
|
+
if (!ts.isExpression(node)) return node;
|
|
3108
|
+
if (ts.isFunctionDeclaration(nodeToReplace)) {
|
|
3109
|
+
if (!nodeToReplace.name) return node;
|
|
3110
|
+
return ts.factory.createVariableStatement(
|
|
3111
|
+
nodeToReplace.modifiers,
|
|
3112
|
+
ts.factory.createVariableDeclarationList(
|
|
3113
|
+
[ts.factory.createVariableDeclaration(
|
|
3114
|
+
nodeToReplace.name,
|
|
3115
|
+
void 0,
|
|
3116
|
+
void 0,
|
|
3117
|
+
node
|
|
3118
|
+
)],
|
|
3119
|
+
ts.NodeFlags.Const
|
|
3120
|
+
)
|
|
3121
|
+
);
|
|
3122
|
+
} else if (ts.isMethodDeclaration(nodeToReplace)) {
|
|
3123
|
+
return ts.factory.createPropertyDeclaration(
|
|
3124
|
+
nodeToReplace.modifiers,
|
|
3125
|
+
nodeToReplace.name,
|
|
3126
|
+
void 0,
|
|
3127
|
+
void 0,
|
|
3128
|
+
node
|
|
3129
|
+
);
|
|
3130
|
+
}
|
|
3131
|
+
return node;
|
|
3132
|
+
}
|
|
3133
|
+
);
|
|
3134
|
+
var parseDataForExtendsClassCompletion = fn(
|
|
3135
|
+
"AST.parseDataForExtendsClassCompletion"
|
|
3136
|
+
)(function* (sourceFile, position) {
|
|
3137
|
+
const ts = yield* service(TypeScriptApi);
|
|
3138
|
+
const precedingToken = ts.findPrecedingToken(position, sourceFile, void 0, true);
|
|
3139
|
+
if (!precedingToken) return none2();
|
|
3140
|
+
let accessedObject = precedingToken;
|
|
3141
|
+
let replacementSpan = ts.createTextSpan(position, 0);
|
|
3142
|
+
let outerNode = precedingToken;
|
|
3143
|
+
if (ts.isIdentifier(precedingToken) && precedingToken.parent && ts.isPropertyAccessExpression(precedingToken.parent)) {
|
|
3144
|
+
replacementSpan = ts.createTextSpan(
|
|
3145
|
+
precedingToken.parent.getStart(sourceFile),
|
|
3146
|
+
precedingToken.end - precedingToken.parent.getStart(sourceFile)
|
|
3147
|
+
);
|
|
3148
|
+
accessedObject = precedingToken.parent.expression;
|
|
3149
|
+
outerNode = precedingToken.parent;
|
|
3150
|
+
} else if (ts.isToken(precedingToken) && precedingToken.kind === ts.SyntaxKind.DotToken && ts.isPropertyAccessExpression(precedingToken.parent)) {
|
|
3151
|
+
replacementSpan = ts.createTextSpan(
|
|
3152
|
+
precedingToken.parent.getStart(sourceFile),
|
|
3153
|
+
precedingToken.end - precedingToken.parent.getStart(sourceFile)
|
|
3154
|
+
);
|
|
3155
|
+
accessedObject = precedingToken.parent.expression;
|
|
3156
|
+
outerNode = precedingToken.parent;
|
|
3157
|
+
} else if (ts.isIdentifier(precedingToken) && precedingToken.parent) {
|
|
3158
|
+
replacementSpan = ts.createTextSpan(
|
|
3159
|
+
precedingToken.getStart(sourceFile),
|
|
3160
|
+
precedingToken.end - precedingToken.getStart(sourceFile)
|
|
3161
|
+
);
|
|
3162
|
+
accessedObject = precedingToken;
|
|
3163
|
+
outerNode = precedingToken;
|
|
3164
|
+
} else {
|
|
3165
|
+
return none2();
|
|
3166
|
+
}
|
|
3167
|
+
if (!ts.isIdentifier(accessedObject)) return none2();
|
|
3168
|
+
let classDeclaration = outerNode.parent;
|
|
3169
|
+
while (ts.isExpressionWithTypeArguments(classDeclaration) || ts.isHeritageClause(classDeclaration)) {
|
|
3170
|
+
if (!classDeclaration.parent) break;
|
|
3171
|
+
classDeclaration = classDeclaration.parent;
|
|
3172
|
+
}
|
|
3173
|
+
if (!ts.isClassDeclaration(classDeclaration)) return none2();
|
|
3174
|
+
if (!classDeclaration.name) return none2();
|
|
3175
|
+
return some2(
|
|
3176
|
+
{ accessedObject, classDeclaration, className: classDeclaration.name, replacementSpan }
|
|
3177
|
+
);
|
|
3178
|
+
});
|
|
2857
3179
|
|
|
2858
|
-
// src/
|
|
2859
|
-
var
|
|
2860
|
-
|
|
3180
|
+
// src/completions/contextSelfInClasses.ts
|
|
3181
|
+
var contextSelfInClasses = createCompletion({
|
|
3182
|
+
name: "effect/contextSelfInClasses",
|
|
3183
|
+
apply: fn("contextSelfInClasses")(function* (sourceFile, position) {
|
|
3184
|
+
const ts = yield* service(TypeScriptApi);
|
|
3185
|
+
const maybeInfos = yield* parseDataForExtendsClassCompletion(sourceFile, position);
|
|
3186
|
+
if (isNone2(maybeInfos)) return [];
|
|
3187
|
+
const { accessedObject, className, replacementSpan } = maybeInfos.value;
|
|
3188
|
+
const contextName = yield* option(
|
|
3189
|
+
findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3190
|
+
sourceFile,
|
|
3191
|
+
"effect",
|
|
3192
|
+
"Context"
|
|
3193
|
+
)
|
|
3194
|
+
);
|
|
3195
|
+
const contextIdentifier = match2(contextName, {
|
|
3196
|
+
onNone: () => "Context",
|
|
3197
|
+
onSome: (_) => _.text
|
|
3198
|
+
});
|
|
3199
|
+
if (contextIdentifier !== accessedObject.text) return [];
|
|
3200
|
+
const name = className.text;
|
|
3201
|
+
return [{
|
|
3202
|
+
name: `Tag("${name}")`,
|
|
3203
|
+
kind: ts.ScriptElementKind.constElement,
|
|
3204
|
+
insertText: `${contextIdentifier}.Tag("${name}")<${name}, ${"${0}"}>(){}`,
|
|
3205
|
+
replacementSpan,
|
|
3206
|
+
isSnippet: true
|
|
3207
|
+
}];
|
|
3208
|
+
})
|
|
3209
|
+
});
|
|
3210
|
+
|
|
3211
|
+
// src/completions/effectSchemaSelfInClasses.ts
|
|
3212
|
+
var effectSchemaSelfInClasses = createCompletion({
|
|
3213
|
+
name: "effect/effectSchemaSelfInClasses",
|
|
3214
|
+
apply: fn("effectSchemaSelfInClasses")(function* (sourceFile, position) {
|
|
3215
|
+
const ts = yield* service(TypeScriptApi);
|
|
3216
|
+
const maybeInfos = yield* parseDataForExtendsClassCompletion(sourceFile, position);
|
|
3217
|
+
if (isNone2(maybeInfos)) return [];
|
|
3218
|
+
const { accessedObject, className, replacementSpan } = maybeInfos.value;
|
|
3219
|
+
const effectSchemaName = yield* option(
|
|
3220
|
+
findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3221
|
+
sourceFile,
|
|
3222
|
+
"effect",
|
|
3223
|
+
"Schema"
|
|
3224
|
+
)
|
|
3225
|
+
);
|
|
3226
|
+
const schemaIdentifier = match2(effectSchemaName, {
|
|
3227
|
+
onNone: () => "Schema",
|
|
3228
|
+
onSome: (_) => _.text
|
|
3229
|
+
});
|
|
3230
|
+
if (schemaIdentifier !== accessedObject.text) return [];
|
|
3231
|
+
const name = className.text;
|
|
3232
|
+
return [{
|
|
3233
|
+
name: `Class<${name}>`,
|
|
3234
|
+
kind: ts.ScriptElementKind.constElement,
|
|
3235
|
+
insertText: `${schemaIdentifier}.Class<${name}>("${name}")({${"${0}"}}){}`,
|
|
3236
|
+
replacementSpan,
|
|
3237
|
+
isSnippet: true
|
|
3238
|
+
}, {
|
|
3239
|
+
name: `TaggedError<${name}>`,
|
|
3240
|
+
kind: ts.ScriptElementKind.constElement,
|
|
3241
|
+
insertText: `${schemaIdentifier}.TaggedError<${name}>("${name}")("${name}", {${"${0}"}}){}`,
|
|
3242
|
+
replacementSpan,
|
|
3243
|
+
isSnippet: true
|
|
3244
|
+
}, {
|
|
3245
|
+
name: `TaggedClass<${name}>`,
|
|
3246
|
+
kind: ts.ScriptElementKind.constElement,
|
|
3247
|
+
insertText: `${schemaIdentifier}.TaggedClass<${name}>("${name}")("${name}", {${"${0}"}}){}`,
|
|
3248
|
+
replacementSpan,
|
|
3249
|
+
isSnippet: true
|
|
3250
|
+
}, {
|
|
3251
|
+
name: `TaggedRequest<${name}>`,
|
|
3252
|
+
kind: ts.ScriptElementKind.constElement,
|
|
3253
|
+
insertText: `${schemaIdentifier}.TaggedRequest<${name}>("${name}")("${name}", {${"${0}"}}){}`,
|
|
3254
|
+
replacementSpan,
|
|
3255
|
+
isSnippet: true
|
|
3256
|
+
}];
|
|
3257
|
+
})
|
|
3258
|
+
});
|
|
3259
|
+
|
|
3260
|
+
// src/completions/effectSelfInClasses.ts
|
|
3261
|
+
var effectSelfInClasses = createCompletion({
|
|
3262
|
+
name: "effect/effectSelfInClasses",
|
|
3263
|
+
apply: fn("effectSelfInClasses")(function* (sourceFile, position) {
|
|
3264
|
+
const ts = yield* service(TypeScriptApi);
|
|
3265
|
+
const maybeInfos = yield* parseDataForExtendsClassCompletion(sourceFile, position);
|
|
3266
|
+
if (isNone2(maybeInfos)) return [];
|
|
3267
|
+
const { accessedObject, className, replacementSpan } = maybeInfos.value;
|
|
3268
|
+
const effectName = yield* option(
|
|
3269
|
+
findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3270
|
+
sourceFile,
|
|
3271
|
+
"effect",
|
|
3272
|
+
"Effect"
|
|
3273
|
+
)
|
|
3274
|
+
);
|
|
3275
|
+
const effectIdentifier = match2(effectName, {
|
|
3276
|
+
onNone: () => "Effect",
|
|
3277
|
+
onSome: (_) => _.text
|
|
3278
|
+
});
|
|
3279
|
+
if (effectIdentifier !== accessedObject.text) return [];
|
|
3280
|
+
const name = className.text;
|
|
3281
|
+
return [{
|
|
3282
|
+
name: `Service<${name}>`,
|
|
3283
|
+
kind: ts.ScriptElementKind.constElement,
|
|
3284
|
+
insertText: `${effectIdentifier}.Service<${name}>()("${name}", {${"${0}"}}){}`,
|
|
3285
|
+
replacementSpan,
|
|
3286
|
+
isSnippet: true
|
|
3287
|
+
}];
|
|
3288
|
+
})
|
|
3289
|
+
});
|
|
3290
|
+
|
|
3291
|
+
// src/completions.ts
|
|
3292
|
+
var completions = [effectSchemaSelfInClasses, effectSelfInClasses, contextSelfInClasses];
|
|
2861
3293
|
|
|
2862
3294
|
// src/utils/TypeCheckerApi.ts
|
|
2863
3295
|
var TypeCheckerApi = Tag("TypeChecker");
|
|
3296
|
+
var TypeCheckerApiCache = Tag("TypeCheckerApiCache");
|
|
3297
|
+
function makeTypeCheckerApiCache() {
|
|
3298
|
+
return {
|
|
3299
|
+
expectedAndRealType: /* @__PURE__ */ new WeakMap()
|
|
3300
|
+
};
|
|
3301
|
+
}
|
|
2864
3302
|
var deterministicTypeOrder = gen2(function* () {
|
|
2865
3303
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
2866
3304
|
return make2((a, b) => {
|
|
@@ -2871,8 +3309,10 @@ var deterministicTypeOrder = gen2(function* () {
|
|
|
2871
3309
|
return 0;
|
|
2872
3310
|
});
|
|
2873
3311
|
});
|
|
2874
|
-
|
|
2875
|
-
|
|
3312
|
+
var getMissingTypeEntriesInTargetType = fn(
|
|
3313
|
+
"TypeCheckerApi.getMissingTypeEntriesInTargetType"
|
|
3314
|
+
)(
|
|
3315
|
+
function* (realType, expectedType) {
|
|
2876
3316
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
2877
3317
|
const result = [];
|
|
2878
3318
|
const toTest = [realType];
|
|
@@ -2889,83 +3329,98 @@ function getMissingTypeEntriesInTargetType(realType, expectedType) {
|
|
|
2889
3329
|
}
|
|
2890
3330
|
}
|
|
2891
3331
|
return result;
|
|
2892
|
-
}
|
|
2893
|
-
|
|
3332
|
+
}
|
|
3333
|
+
);
|
|
2894
3334
|
var CannotFindAncestorConvertibleDeclarationError = class extends TaggedError("CannotFindAncestorConvertibleDeclarationError") {
|
|
2895
3335
|
};
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
current = current.parent;
|
|
3336
|
+
var getAncestorConvertibleDeclaration = fn(
|
|
3337
|
+
"TypeCheckerApi.getAncestorConvertibleDeclaration"
|
|
3338
|
+
)(function* (node) {
|
|
3339
|
+
const ts = yield* service(TypeScriptApi);
|
|
3340
|
+
let current = node;
|
|
3341
|
+
while (current) {
|
|
3342
|
+
if (ts.isFunctionDeclaration(current) || ts.isFunctionExpression(current) || ts.isArrowFunction(current) || ts.isMethodDeclaration(current)) {
|
|
3343
|
+
return current;
|
|
2905
3344
|
}
|
|
2906
|
-
|
|
2907
|
-
}
|
|
2908
|
-
}
|
|
3345
|
+
current = current.parent;
|
|
3346
|
+
}
|
|
3347
|
+
return yield* fail3(new CannotFindAncestorConvertibleDeclarationError({ node }));
|
|
3348
|
+
});
|
|
2909
3349
|
var CannotInferReturnTypeFromEmptyBody = class extends TaggedError("CannotInferReturnTypeFromEmptyBody") {
|
|
2910
3350
|
};
|
|
2911
3351
|
var CannotInferReturnType = class extends TaggedError("CannotInferReturnType") {
|
|
2912
3352
|
};
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
3353
|
+
var getInferredReturnType = fn("TypeCheckerApi.getInferredReturnType")(function* (declaration) {
|
|
3354
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3355
|
+
if (!declaration.body) {
|
|
3356
|
+
return yield* fail3(
|
|
3357
|
+
new CannotInferReturnTypeFromEmptyBody({ declaration })
|
|
3358
|
+
);
|
|
3359
|
+
}
|
|
3360
|
+
let returnType;
|
|
3361
|
+
if (typeChecker.isImplementationOfOverload(declaration)) {
|
|
3362
|
+
const signatures = typeChecker.getTypeAtLocation(declaration).getCallSignatures();
|
|
3363
|
+
if (signatures.length > 1) {
|
|
3364
|
+
returnType = typeChecker.getUnionType(
|
|
3365
|
+
signatures.map((s) => s.getReturnType()).filter((_) => !!_)
|
|
2919
3366
|
);
|
|
2920
3367
|
}
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
}
|
|
2929
|
-
|
|
2930
|
-
if (!returnType) {
|
|
2931
|
-
const signature = typeChecker.getSignatureFromDeclaration(declaration);
|
|
2932
|
-
if (signature) {
|
|
2933
|
-
const typePredicate = typeChecker.getTypePredicateOfSignature(signature);
|
|
2934
|
-
if (typePredicate && typePredicate.type) {
|
|
2935
|
-
return typePredicate.type;
|
|
2936
|
-
} else {
|
|
2937
|
-
returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
2938
|
-
}
|
|
3368
|
+
}
|
|
3369
|
+
if (!returnType) {
|
|
3370
|
+
const signature = typeChecker.getSignatureFromDeclaration(declaration);
|
|
3371
|
+
if (signature) {
|
|
3372
|
+
const typePredicate = typeChecker.getTypePredicateOfSignature(signature);
|
|
3373
|
+
if (typePredicate && typePredicate.type) {
|
|
3374
|
+
return typePredicate.type;
|
|
3375
|
+
} else {
|
|
3376
|
+
returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
2939
3377
|
}
|
|
2940
3378
|
}
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
)
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
}
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
3379
|
+
}
|
|
3380
|
+
if (!returnType) {
|
|
3381
|
+
return yield* fail3(
|
|
3382
|
+
new CannotInferReturnType({ declaration })
|
|
3383
|
+
);
|
|
3384
|
+
}
|
|
3385
|
+
return returnType;
|
|
3386
|
+
});
|
|
3387
|
+
var expectedAndRealType = fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
|
|
3388
|
+
const cache = yield* service(TypeCheckerApiCache);
|
|
3389
|
+
const resultCached = cache.expectedAndRealType.get(sourceFile);
|
|
3390
|
+
if (resultCached) return resultCached;
|
|
3391
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3392
|
+
const ts = yield* service(TypeScriptApi);
|
|
3393
|
+
const result = [];
|
|
3394
|
+
const nodeToVisit = [];
|
|
3395
|
+
const appendNodeToVisit = (node) => {
|
|
3396
|
+
nodeToVisit.push(node);
|
|
3397
|
+
return void 0;
|
|
3398
|
+
};
|
|
3399
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
3400
|
+
while (nodeToVisit.length > 0) {
|
|
3401
|
+
const node = nodeToVisit.shift();
|
|
3402
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2953
3403
|
if (ts.isVariableDeclaration(node) && node.initializer) {
|
|
2954
3404
|
const expectedType = typeChecker.getTypeAtLocation(node.name);
|
|
2955
3405
|
const realType = typeChecker.getTypeAtLocation(node.initializer);
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
if (ts.isCallExpression(node)) {
|
|
3406
|
+
result.push([node.name, expectedType, node.initializer, realType]);
|
|
3407
|
+
continue;
|
|
3408
|
+
} else if (ts.isCallExpression(node)) {
|
|
2959
3409
|
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
2960
3410
|
if (resolvedSignature) {
|
|
2961
|
-
|
|
3411
|
+
resolvedSignature.getParameters().map((parameter, index) => {
|
|
2962
3412
|
const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
|
|
2963
3413
|
const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
|
|
2964
|
-
|
|
3414
|
+
result.push([
|
|
3415
|
+
node.arguments[index],
|
|
3416
|
+
expectedType,
|
|
3417
|
+
node.arguments[index],
|
|
3418
|
+
realType
|
|
3419
|
+
]);
|
|
2965
3420
|
});
|
|
3421
|
+
continue;
|
|
2966
3422
|
}
|
|
2967
|
-
}
|
|
2968
|
-
if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
3423
|
+
} else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
2969
3424
|
const parent = node.parent;
|
|
2970
3425
|
if (ts.isObjectLiteralElement(parent)) {
|
|
2971
3426
|
if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
|
|
@@ -2975,39 +3430,45 @@ function expectedAndRealType(node) {
|
|
|
2975
3430
|
if (symbol3) {
|
|
2976
3431
|
const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
|
|
2977
3432
|
const realType = typeChecker.getTypeAtLocation(node);
|
|
2978
|
-
|
|
3433
|
+
result.push([node, expectedType, node, realType]);
|
|
3434
|
+
continue;
|
|
2979
3435
|
}
|
|
2980
3436
|
}
|
|
2981
3437
|
}
|
|
2982
3438
|
}
|
|
2983
|
-
}
|
|
2984
|
-
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
3439
|
+
} else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
2985
3440
|
const expectedType = typeChecker.getTypeAtLocation(node.left);
|
|
2986
3441
|
const realType = typeChecker.getTypeAtLocation(node.right);
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
if (ts.isReturnStatement(node) && node.expression) {
|
|
3442
|
+
result.push([node.left, expectedType, node.right, realType]);
|
|
3443
|
+
continue;
|
|
3444
|
+
} else if (ts.isReturnStatement(node) && node.expression) {
|
|
2990
3445
|
const parentDeclaration = yield* option(getAncestorConvertibleDeclaration(node));
|
|
2991
3446
|
if (isSome2(parentDeclaration)) {
|
|
2992
3447
|
const expectedType = yield* option(getInferredReturnType(parentDeclaration.value));
|
|
2993
3448
|
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2994
|
-
if (isSome2(expectedType))
|
|
3449
|
+
if (isSome2(expectedType)) {
|
|
3450
|
+
result.push([node, expectedType.value, node, realType]);
|
|
3451
|
+
continue;
|
|
3452
|
+
}
|
|
2995
3453
|
}
|
|
2996
|
-
}
|
|
2997
|
-
if (ts.isArrowFunction(node) && ts.isExpression(node.body)) {
|
|
3454
|
+
} else if (ts.isArrowFunction(node) && ts.isExpression(node.body)) {
|
|
2998
3455
|
const body = node.body;
|
|
2999
3456
|
const expectedType = typeChecker.getContextualType(body);
|
|
3000
3457
|
const realType = typeChecker.getTypeAtLocation(body);
|
|
3001
|
-
if (expectedType)
|
|
3002
|
-
|
|
3003
|
-
|
|
3458
|
+
if (expectedType) {
|
|
3459
|
+
result.push([body, expectedType, body, realType]);
|
|
3460
|
+
continue;
|
|
3461
|
+
}
|
|
3462
|
+
} else if (ts.isSatisfiesExpression(node)) {
|
|
3004
3463
|
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
3005
3464
|
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
3006
|
-
|
|
3465
|
+
result.push([node.expression, expectedType, node.expression, realType]);
|
|
3466
|
+
continue;
|
|
3007
3467
|
}
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3468
|
+
}
|
|
3469
|
+
cache.expectedAndRealType.set(sourceFile, result);
|
|
3470
|
+
return result;
|
|
3471
|
+
});
|
|
3011
3472
|
|
|
3012
3473
|
// src/utils/TypeParser.ts
|
|
3013
3474
|
var TypeParserIssue = class extends TaggedError("@effect/language-service/TypeParserIssue") {
|
|
@@ -3022,23 +3483,21 @@ function covariantTypeArgument(type) {
|
|
|
3022
3483
|
}
|
|
3023
3484
|
return succeed(signatures[0].getReturnType());
|
|
3024
3485
|
}
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
function varianceStructCovariantType(type, atLocation, propertyName) {
|
|
3041
|
-
return gen2(function* () {
|
|
3486
|
+
var pipeableType = fn("TypeParser.pipeableType")(function* (type, atLocation) {
|
|
3487
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3488
|
+
const pipeSymbol = typeChecker.getPropertyOfType(type, "pipe");
|
|
3489
|
+
if (!pipeSymbol) {
|
|
3490
|
+
return yield* typeParserIssue("Type has no 'pipe' property", type, atLocation);
|
|
3491
|
+
}
|
|
3492
|
+
const pipeType = typeChecker.getTypeOfSymbolAtLocation(pipeSymbol, atLocation);
|
|
3493
|
+
const signatures = pipeType.getCallSignatures();
|
|
3494
|
+
if (signatures.length === 0) {
|
|
3495
|
+
return yield* typeParserIssue("'pipe' property is not callable", type, atLocation);
|
|
3496
|
+
}
|
|
3497
|
+
return type;
|
|
3498
|
+
});
|
|
3499
|
+
var varianceStructCovariantType = fn("TypeParser.varianceStructCovariantType")(
|
|
3500
|
+
function* (type, atLocation, propertyName) {
|
|
3042
3501
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3043
3502
|
const propertySymbol = typeChecker.getPropertyOfType(type, propertyName);
|
|
3044
3503
|
if (!propertySymbol) {
|
|
@@ -3046,115 +3505,108 @@ function varianceStructCovariantType(type, atLocation, propertyName) {
|
|
|
3046
3505
|
}
|
|
3047
3506
|
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
3048
3507
|
return yield* covariantTypeArgument(propertyType);
|
|
3049
|
-
}
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
return
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
return yield* typeParserIssue("Type has no effect variance struct", type, atLocation);
|
|
3075
|
-
});
|
|
3076
|
-
}
|
|
3077
|
-
function fiberType(type, atLocation) {
|
|
3078
|
-
return gen2(function* () {
|
|
3079
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
3080
|
-
const awaitSymbol = typeChecker.getPropertyOfType(type, "await");
|
|
3081
|
-
const pollSymbol = typeChecker.getPropertyOfType(type, "poll");
|
|
3082
|
-
if (!awaitSymbol || !pollSymbol) {
|
|
3083
|
-
return yield* typeParserIssue(
|
|
3084
|
-
"Type is not a fiber because it does not have 'await' or 'poll' property",
|
|
3085
|
-
type,
|
|
3086
|
-
atLocation
|
|
3087
|
-
);
|
|
3088
|
-
}
|
|
3089
|
-
return yield* effectType(type, atLocation);
|
|
3090
|
-
});
|
|
3091
|
-
}
|
|
3092
|
-
function effectSubtype(type, atLocation) {
|
|
3093
|
-
return gen2(function* () {
|
|
3094
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
3095
|
-
const tagSymbol = typeChecker.getPropertyOfType(type, "_tag");
|
|
3096
|
-
if (!tagSymbol) {
|
|
3097
|
-
return yield* typeParserIssue(
|
|
3098
|
-
"Type is not a subtype of effect because it does not have '_tag' property",
|
|
3099
|
-
type,
|
|
3100
|
-
atLocation
|
|
3101
|
-
);
|
|
3102
|
-
}
|
|
3103
|
-
return yield* effectType(type, atLocation);
|
|
3104
|
-
});
|
|
3105
|
-
}
|
|
3106
|
-
function importedEffectModule(node) {
|
|
3107
|
-
return gen2(function* () {
|
|
3108
|
-
const ts = yield* service(TypeScriptApi);
|
|
3109
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
3110
|
-
const type = typeChecker.getTypeAtLocation(node);
|
|
3111
|
-
const propertySymbol = typeChecker.getPropertyOfType(type, "never");
|
|
3112
|
-
if (!propertySymbol) {
|
|
3113
|
-
return yield* typeParserIssue("Type has no 'never' property", type, node);
|
|
3114
|
-
}
|
|
3115
|
-
if (!ts.isExpression(node)) {
|
|
3116
|
-
return yield* typeParserIssue("Node is not an expression", type, node);
|
|
3117
|
-
}
|
|
3118
|
-
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, node);
|
|
3119
|
-
yield* effectType(propertyType, node);
|
|
3120
|
-
return node;
|
|
3121
|
-
});
|
|
3122
|
-
}
|
|
3123
|
-
function effectGen(node) {
|
|
3124
|
-
return gen2(function* () {
|
|
3125
|
-
const ts = yield* service(TypeScriptApi);
|
|
3126
|
-
if (!ts.isCallExpression(node)) {
|
|
3127
|
-
return yield* typeParserIssue("Node is not a call expression", void 0, node);
|
|
3128
|
-
}
|
|
3129
|
-
if (node.arguments.length === 0) {
|
|
3130
|
-
return yield* typeParserIssue("Node has no arguments", void 0, node);
|
|
3131
|
-
}
|
|
3132
|
-
const generatorFunction = node.arguments[0];
|
|
3133
|
-
if (!ts.isFunctionExpression(generatorFunction)) {
|
|
3134
|
-
return yield* typeParserIssue("Node is not a function expression", void 0, node);
|
|
3135
|
-
}
|
|
3136
|
-
if (generatorFunction.asteriskToken === void 0) {
|
|
3137
|
-
return yield* typeParserIssue("Node is not a generator function", void 0, node);
|
|
3138
|
-
}
|
|
3139
|
-
if (!ts.isPropertyAccessExpression(node.expression)) {
|
|
3140
|
-
return yield* typeParserIssue("Node is not a property access expression", void 0, node);
|
|
3141
|
-
}
|
|
3142
|
-
const propertyAccess = node.expression;
|
|
3143
|
-
if (propertyAccess.name.text !== "gen") {
|
|
3144
|
-
return yield* typeParserIssue("Call expression name is not 'gen'", void 0, node);
|
|
3508
|
+
}
|
|
3509
|
+
);
|
|
3510
|
+
var effectVarianceStruct = fn("TypeParser.effectVarianceStruct")(function* (type, atLocation) {
|
|
3511
|
+
return {
|
|
3512
|
+
A: yield* varianceStructCovariantType(type, atLocation, "_A"),
|
|
3513
|
+
E: yield* varianceStructCovariantType(type, atLocation, "_E"),
|
|
3514
|
+
R: yield* varianceStructCovariantType(type, atLocation, "_R")
|
|
3515
|
+
};
|
|
3516
|
+
});
|
|
3517
|
+
var effectType = fn("TypeParser.effectType")(function* (type, atLocation) {
|
|
3518
|
+
const ts = yield* service(TypeScriptApi);
|
|
3519
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3520
|
+
yield* pipeableType(type, atLocation);
|
|
3521
|
+
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
3522
|
+
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional)
|
|
3523
|
+
);
|
|
3524
|
+
propertiesSymbols.sort((a, b) => b.name.indexOf("EffectTypeId") - a.name.indexOf("EffectTypeId"));
|
|
3525
|
+
for (const propertySymbol of propertiesSymbols) {
|
|
3526
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
3527
|
+
const varianceArgs = yield* option(effectVarianceStruct(
|
|
3528
|
+
propertyType,
|
|
3529
|
+
atLocation
|
|
3530
|
+
));
|
|
3531
|
+
if (isSome2(varianceArgs)) {
|
|
3532
|
+
return varianceArgs.value;
|
|
3145
3533
|
}
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3534
|
+
}
|
|
3535
|
+
return yield* typeParserIssue("Type has no effect variance struct", type, atLocation);
|
|
3536
|
+
});
|
|
3537
|
+
var fiberType = fn("TypeParser.fiberType")(function* (type, atLocation) {
|
|
3538
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3539
|
+
const awaitSymbol = typeChecker.getPropertyOfType(type, "await");
|
|
3540
|
+
const pollSymbol = typeChecker.getPropertyOfType(type, "poll");
|
|
3541
|
+
if (!awaitSymbol || !pollSymbol) {
|
|
3542
|
+
return yield* typeParserIssue(
|
|
3543
|
+
"Type is not a fiber because it does not have 'await' or 'poll' property",
|
|
3544
|
+
type,
|
|
3545
|
+
atLocation
|
|
3546
|
+
);
|
|
3547
|
+
}
|
|
3548
|
+
return yield* effectType(type, atLocation);
|
|
3549
|
+
});
|
|
3550
|
+
var effectSubtype = fn("TypeParser.effectSubtype")(function* (type, atLocation) {
|
|
3551
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3552
|
+
const tagSymbol = typeChecker.getPropertyOfType(type, "_tag");
|
|
3553
|
+
if (!tagSymbol) {
|
|
3554
|
+
return yield* typeParserIssue(
|
|
3555
|
+
"Type is not a subtype of effect because it does not have '_tag' property",
|
|
3556
|
+
type,
|
|
3557
|
+
atLocation
|
|
3558
|
+
);
|
|
3559
|
+
}
|
|
3560
|
+
return yield* effectType(type, atLocation);
|
|
3561
|
+
});
|
|
3562
|
+
var importedEffectModule = fn("TypeParser.importedEffectModule")(function* (node) {
|
|
3563
|
+
const ts = yield* service(TypeScriptApi);
|
|
3564
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3565
|
+
const type = typeChecker.getTypeAtLocation(node);
|
|
3566
|
+
const propertySymbol = typeChecker.getPropertyOfType(type, "never");
|
|
3567
|
+
if (!propertySymbol) {
|
|
3568
|
+
return yield* typeParserIssue("Type has no 'never' property", type, node);
|
|
3569
|
+
}
|
|
3570
|
+
if (!ts.isExpression(node)) {
|
|
3571
|
+
return yield* typeParserIssue("Node is not an expression", type, node);
|
|
3572
|
+
}
|
|
3573
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, node);
|
|
3574
|
+
yield* effectType(propertyType, node);
|
|
3575
|
+
return node;
|
|
3576
|
+
});
|
|
3577
|
+
var effectGen = fn("TypeParser.effectGen")(function* (node) {
|
|
3578
|
+
const ts = yield* service(TypeScriptApi);
|
|
3579
|
+
if (!ts.isCallExpression(node)) {
|
|
3580
|
+
return yield* typeParserIssue("Node is not a call expression", void 0, node);
|
|
3581
|
+
}
|
|
3582
|
+
if (node.arguments.length === 0) {
|
|
3583
|
+
return yield* typeParserIssue("Node has no arguments", void 0, node);
|
|
3584
|
+
}
|
|
3585
|
+
const generatorFunction = node.arguments[0];
|
|
3586
|
+
if (!ts.isFunctionExpression(generatorFunction)) {
|
|
3587
|
+
return yield* typeParserIssue("Node is not a function expression", void 0, node);
|
|
3588
|
+
}
|
|
3589
|
+
if (generatorFunction.asteriskToken === void 0) {
|
|
3590
|
+
return yield* typeParserIssue("Node is not a generator function", void 0, node);
|
|
3591
|
+
}
|
|
3592
|
+
if (!ts.isPropertyAccessExpression(node.expression)) {
|
|
3593
|
+
return yield* typeParserIssue("Node is not a property access expression", void 0, node);
|
|
3594
|
+
}
|
|
3595
|
+
const propertyAccess = node.expression;
|
|
3596
|
+
if (propertyAccess.name.text !== "gen") {
|
|
3597
|
+
return yield* typeParserIssue("Call expression name is not 'gen'", void 0, node);
|
|
3598
|
+
}
|
|
3599
|
+
const effectModule = yield* importedEffectModule(propertyAccess.expression);
|
|
3600
|
+
return {
|
|
3601
|
+
node,
|
|
3602
|
+
effectModule,
|
|
3603
|
+
generatorFunction,
|
|
3604
|
+
body: generatorFunction.body,
|
|
3605
|
+
functionStar: generatorFunction.getFirstToken()
|
|
3606
|
+
};
|
|
3607
|
+
});
|
|
3608
|
+
var effectFnUntracedGen = fn("TypeParser.effectFnUntracedGen")(
|
|
3609
|
+
function* (node) {
|
|
3158
3610
|
const ts = yield* service(TypeScriptApi);
|
|
3159
3611
|
if (!ts.isCallExpression(node)) {
|
|
3160
3612
|
return yield* typeParserIssue("Node is not a call expression", void 0, node);
|
|
@@ -3196,82 +3648,77 @@ function effectFnUntracedGen(node) {
|
|
|
3196
3648
|
body: generatorFunction.body,
|
|
3197
3649
|
functionStar: generatorFunction.getFirstToken()
|
|
3198
3650
|
};
|
|
3199
|
-
}
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
if (!ts.isFunctionExpression(generatorFunction)) {
|
|
3212
|
-
return yield* typeParserIssue(
|
|
3213
|
-
"Node is not a function expression",
|
|
3214
|
-
void 0,
|
|
3215
|
-
node
|
|
3216
|
-
);
|
|
3217
|
-
}
|
|
3218
|
-
if (generatorFunction.asteriskToken === void 0) {
|
|
3219
|
-
return yield* typeParserIssue(
|
|
3220
|
-
"Node is not a generator function",
|
|
3221
|
-
void 0,
|
|
3222
|
-
node
|
|
3223
|
-
);
|
|
3224
|
-
}
|
|
3225
|
-
const expressionToTest = ts.isCallExpression(node.expression) ? node.expression.expression : node.expression;
|
|
3226
|
-
if (!ts.isPropertyAccessExpression(expressionToTest)) {
|
|
3227
|
-
return yield* typeParserIssue(
|
|
3228
|
-
"Node is not a property access expression",
|
|
3229
|
-
void 0,
|
|
3230
|
-
node
|
|
3231
|
-
);
|
|
3232
|
-
}
|
|
3233
|
-
const propertyAccess = expressionToTest;
|
|
3234
|
-
if (propertyAccess.name.text !== "fn") {
|
|
3235
|
-
return yield* typeParserIssue(
|
|
3236
|
-
"Call expression name is not 'fn'",
|
|
3237
|
-
void 0,
|
|
3238
|
-
node
|
|
3239
|
-
);
|
|
3240
|
-
}
|
|
3241
|
-
const effectModule = yield* importedEffectModule(propertyAccess.expression);
|
|
3242
|
-
return {
|
|
3243
|
-
node,
|
|
3244
|
-
generatorFunction,
|
|
3245
|
-
effectModule,
|
|
3246
|
-
body: generatorFunction.body,
|
|
3247
|
-
functionStar: generatorFunction.getFirstToken()
|
|
3248
|
-
};
|
|
3249
|
-
});
|
|
3250
|
-
}
|
|
3251
|
-
function returnYieldEffectBlock(body) {
|
|
3252
|
-
return gen2(function* () {
|
|
3253
|
-
const ts = yield* service(TypeScriptApi);
|
|
3254
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
3255
|
-
if (!ts.isBlock(body)) return yield* typeParserIssue("Node is not a block", void 0, body);
|
|
3256
|
-
if (body.statements.length === 1 && ts.isReturnStatement(body.statements[0]) && body.statements[0].expression && ts.isYieldExpression(body.statements[0].expression) && body.statements[0].expression.expression) {
|
|
3257
|
-
const nodeToCheck = body.statements[0].expression.expression;
|
|
3258
|
-
const type = typeChecker.getTypeAtLocation(nodeToCheck);
|
|
3259
|
-
yield* effectType(type, nodeToCheck);
|
|
3260
|
-
return nodeToCheck;
|
|
3261
|
-
}
|
|
3651
|
+
}
|
|
3652
|
+
);
|
|
3653
|
+
var effectFnGen = fn("TypeParser.effectFnGen")(function* (node) {
|
|
3654
|
+
const ts = yield* service(TypeScriptApi);
|
|
3655
|
+
if (!ts.isCallExpression(node)) {
|
|
3656
|
+
return yield* typeParserIssue("Node is not a call expression", void 0, node);
|
|
3657
|
+
}
|
|
3658
|
+
if (node.arguments.length === 0) {
|
|
3659
|
+
return yield* typeParserIssue("Node has no arguments", void 0, node);
|
|
3660
|
+
}
|
|
3661
|
+
const generatorFunction = node.arguments[0];
|
|
3662
|
+
if (!ts.isFunctionExpression(generatorFunction)) {
|
|
3262
3663
|
return yield* typeParserIssue(
|
|
3263
|
-
"Node is not a
|
|
3664
|
+
"Node is not a function expression",
|
|
3264
3665
|
void 0,
|
|
3265
|
-
|
|
3666
|
+
node
|
|
3266
3667
|
);
|
|
3267
|
-
}
|
|
3268
|
-
|
|
3668
|
+
}
|
|
3669
|
+
if (generatorFunction.asteriskToken === void 0) {
|
|
3670
|
+
return yield* typeParserIssue(
|
|
3671
|
+
"Node is not a generator function",
|
|
3672
|
+
void 0,
|
|
3673
|
+
node
|
|
3674
|
+
);
|
|
3675
|
+
}
|
|
3676
|
+
const expressionToTest = ts.isCallExpression(node.expression) ? node.expression.expression : node.expression;
|
|
3677
|
+
if (!ts.isPropertyAccessExpression(expressionToTest)) {
|
|
3678
|
+
return yield* typeParserIssue(
|
|
3679
|
+
"Node is not a property access expression",
|
|
3680
|
+
void 0,
|
|
3681
|
+
node
|
|
3682
|
+
);
|
|
3683
|
+
}
|
|
3684
|
+
const propertyAccess = expressionToTest;
|
|
3685
|
+
if (propertyAccess.name.text !== "fn") {
|
|
3686
|
+
return yield* typeParserIssue(
|
|
3687
|
+
"Call expression name is not 'fn'",
|
|
3688
|
+
void 0,
|
|
3689
|
+
node
|
|
3690
|
+
);
|
|
3691
|
+
}
|
|
3692
|
+
const effectModule = yield* importedEffectModule(propertyAccess.expression);
|
|
3693
|
+
return {
|
|
3694
|
+
node,
|
|
3695
|
+
generatorFunction,
|
|
3696
|
+
effectModule,
|
|
3697
|
+
body: generatorFunction.body,
|
|
3698
|
+
functionStar: generatorFunction.getFirstToken()
|
|
3699
|
+
};
|
|
3700
|
+
});
|
|
3701
|
+
var returnYieldEffectBlock = fn("TypeParser.returnYieldEffectBlock")(function* (body) {
|
|
3702
|
+
const ts = yield* service(TypeScriptApi);
|
|
3703
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3704
|
+
if (ts.isBlock(body) && body.statements.length === 1 && ts.isReturnStatement(body.statements[0]) && body.statements[0].expression && ts.isYieldExpression(body.statements[0].expression) && body.statements[0].expression.expression) {
|
|
3705
|
+
const nodeToCheck = body.statements[0].expression.expression;
|
|
3706
|
+
const type = typeChecker.getTypeAtLocation(nodeToCheck);
|
|
3707
|
+
yield* effectType(type, nodeToCheck);
|
|
3708
|
+
return nodeToCheck;
|
|
3709
|
+
}
|
|
3710
|
+
return yield* typeParserIssue(
|
|
3711
|
+
"Node is not a return statement with a yield expression",
|
|
3712
|
+
void 0,
|
|
3713
|
+
body
|
|
3714
|
+
);
|
|
3715
|
+
});
|
|
3269
3716
|
|
|
3270
3717
|
// src/diagnostics/floatingEffect.ts
|
|
3271
3718
|
var floatingEffect = createDiagnostic({
|
|
3272
3719
|
name: "effect/floatingEffect",
|
|
3273
3720
|
code: 3,
|
|
3274
|
-
apply: (
|
|
3721
|
+
apply: fn("floatingEffect.apply")(function* (sourceFile) {
|
|
3275
3722
|
const ts = yield* service(TypeScriptApi);
|
|
3276
3723
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3277
3724
|
function isFloatingExpression(node) {
|
|
@@ -3318,58 +3765,48 @@ var floatingEffect = createDiagnostic({
|
|
|
3318
3765
|
var missingEffectContext = createDiagnostic({
|
|
3319
3766
|
name: "effect/missingEffectContext",
|
|
3320
3767
|
code: 1,
|
|
3321
|
-
apply: (
|
|
3768
|
+
apply: fn("missingEffectContext.apply")(function* (sourceFile) {
|
|
3322
3769
|
const ts = yield* service(TypeScriptApi);
|
|
3323
3770
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3324
3771
|
const typeOrder = yield* deterministicTypeOrder;
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
}
|
|
3772
|
+
const checkForMissingContextTypes = fn(
|
|
3773
|
+
"missingEffectContext.apply.checkForMissingContextTypes"
|
|
3774
|
+
)(function* (node, expectedType, valueNode, realType) {
|
|
3775
|
+
const expectedEffect = yield* effectType(
|
|
3776
|
+
expectedType,
|
|
3777
|
+
node
|
|
3778
|
+
);
|
|
3779
|
+
const realEffect = yield* effectType(
|
|
3780
|
+
realType,
|
|
3781
|
+
valueNode
|
|
3782
|
+
);
|
|
3783
|
+
return yield* getMissingTypeEntriesInTargetType(
|
|
3784
|
+
realEffect.R,
|
|
3785
|
+
expectedEffect.R
|
|
3786
|
+
);
|
|
3787
|
+
});
|
|
3341
3788
|
const effectDiagnostics = [];
|
|
3342
3789
|
const sortTypes = sort(typeOrder);
|
|
3343
|
-
const
|
|
3344
|
-
const
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3790
|
+
const entries = yield* expectedAndRealType(sourceFile);
|
|
3791
|
+
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
3792
|
+
const missingContext = yield* pipe(
|
|
3793
|
+
checkForMissingContextTypes(
|
|
3794
|
+
node,
|
|
3795
|
+
expectedType,
|
|
3796
|
+
valueNode,
|
|
3797
|
+
realType
|
|
3798
|
+
),
|
|
3799
|
+
orElse3(() => succeed([]))
|
|
3800
|
+
);
|
|
3801
|
+
if (missingContext.length > 0) {
|
|
3802
|
+
effectDiagnostics.push(
|
|
3803
|
+
{
|
|
3804
|
+
node,
|
|
3805
|
+
category: ts.DiagnosticCategory.Error,
|
|
3806
|
+
messageText: `Missing '${sortTypes(missingContext).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect context.`,
|
|
3807
|
+
fix: none2()
|
|
3808
|
+
}
|
|
3362
3809
|
);
|
|
3363
|
-
if (missingContext.length > 0) {
|
|
3364
|
-
effectDiagnostics.push(
|
|
3365
|
-
{
|
|
3366
|
-
node: node2,
|
|
3367
|
-
category: ts.DiagnosticCategory.Error,
|
|
3368
|
-
messageText: `Missing '${sortTypes(missingContext).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect context.`,
|
|
3369
|
-
fix: none2()
|
|
3370
|
-
}
|
|
3371
|
-
);
|
|
3372
|
-
}
|
|
3373
3810
|
}
|
|
3374
3811
|
}
|
|
3375
3812
|
return effectDiagnostics;
|
|
@@ -3380,12 +3817,12 @@ var missingEffectContext = createDiagnostic({
|
|
|
3380
3817
|
var missingEffectError = createDiagnostic({
|
|
3381
3818
|
name: "effect/missingEffectError",
|
|
3382
3819
|
code: 1,
|
|
3383
|
-
apply: (
|
|
3820
|
+
apply: fn("missingEffectError.apply")(function* (sourceFile) {
|
|
3384
3821
|
const ts = yield* service(TypeScriptApi);
|
|
3385
3822
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3386
3823
|
const typeOrder = yield* deterministicTypeOrder;
|
|
3387
|
-
|
|
3388
|
-
|
|
3824
|
+
const checkForMissingErrorTypes = fn("missingEffectError.apply.checkForMissingErrorTypes")(
|
|
3825
|
+
function* (node, expectedType, valueNode, realType) {
|
|
3389
3826
|
const expectedEffect = yield* effectType(
|
|
3390
3827
|
expectedType,
|
|
3391
3828
|
node
|
|
@@ -3395,43 +3832,33 @@ var missingEffectError = createDiagnostic({
|
|
|
3395
3832
|
valueNode
|
|
3396
3833
|
);
|
|
3397
3834
|
return yield* getMissingTypeEntriesInTargetType(
|
|
3398
|
-
realEffect.E,
|
|
3399
|
-
expectedEffect.E
|
|
3400
|
-
);
|
|
3401
|
-
}
|
|
3402
|
-
|
|
3403
|
-
const effectDiagnostics = [];
|
|
3404
|
-
const sortTypes = sort(typeOrder);
|
|
3405
|
-
const
|
|
3406
|
-
const
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3835
|
+
realEffect.E,
|
|
3836
|
+
expectedEffect.E
|
|
3837
|
+
);
|
|
3838
|
+
}
|
|
3839
|
+
);
|
|
3840
|
+
const effectDiagnostics = [];
|
|
3841
|
+
const sortTypes = sort(typeOrder);
|
|
3842
|
+
const entries = yield* expectedAndRealType(sourceFile);
|
|
3843
|
+
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
3844
|
+
const missingContext = yield* pipe(
|
|
3845
|
+
checkForMissingErrorTypes(
|
|
3846
|
+
node,
|
|
3847
|
+
expectedType,
|
|
3848
|
+
valueNode,
|
|
3849
|
+
realType
|
|
3850
|
+
),
|
|
3851
|
+
orElse3(() => succeed([]))
|
|
3852
|
+
);
|
|
3853
|
+
if (missingContext.length > 0) {
|
|
3854
|
+
effectDiagnostics.push(
|
|
3855
|
+
{
|
|
3856
|
+
node,
|
|
3857
|
+
category: ts.DiagnosticCategory.Error,
|
|
3858
|
+
messageText: `Missing '${sortTypes(missingContext).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect errors.`,
|
|
3859
|
+
fix: none2()
|
|
3860
|
+
}
|
|
3424
3861
|
);
|
|
3425
|
-
if (missingContext.length > 0) {
|
|
3426
|
-
effectDiagnostics.push(
|
|
3427
|
-
{
|
|
3428
|
-
node: node2,
|
|
3429
|
-
category: ts.DiagnosticCategory.Error,
|
|
3430
|
-
messageText: `Missing '${sortTypes(missingContext).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect errors.`,
|
|
3431
|
-
fix: none2()
|
|
3432
|
-
}
|
|
3433
|
-
);
|
|
3434
|
-
}
|
|
3435
3862
|
}
|
|
3436
3863
|
}
|
|
3437
3864
|
return effectDiagnostics;
|
|
@@ -3442,7 +3869,7 @@ var missingEffectError = createDiagnostic({
|
|
|
3442
3869
|
var missingStarInYieldEffectGen = createDiagnostic({
|
|
3443
3870
|
name: "effect/missingStarInYieldEffectGen",
|
|
3444
3871
|
code: 4,
|
|
3445
|
-
apply: (
|
|
3872
|
+
apply: fn("missingStarInYieldEffectGen.apply")(function* (sourceFile) {
|
|
3446
3873
|
const ts = yield* service(TypeScriptApi);
|
|
3447
3874
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3448
3875
|
const effectDiagnostics = [];
|
|
@@ -3520,7 +3947,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
3520
3947
|
var unnecessaryEffectGen = createDiagnostic({
|
|
3521
3948
|
name: "effect/unnecessaryEffectGen",
|
|
3522
3949
|
code: 5,
|
|
3523
|
-
apply: (
|
|
3950
|
+
apply: fn("unnecessaryEffectGen.apply")(function* (sourceFile) {
|
|
3524
3951
|
const ts = yield* service(TypeScriptApi);
|
|
3525
3952
|
const effectDiagnostics = [];
|
|
3526
3953
|
const unnecessaryGenerators = /* @__PURE__ */ new Map();
|
|
@@ -3572,254 +3999,6 @@ var diagnostics = [
|
|
|
3572
3999
|
unnecessaryEffectGen
|
|
3573
4000
|
];
|
|
3574
4001
|
|
|
3575
|
-
// src/utils/AST.ts
|
|
3576
|
-
function collectSelfAndAncestorNodesInRange(node, textRange) {
|
|
3577
|
-
return sync(() => {
|
|
3578
|
-
let result = empty();
|
|
3579
|
-
let parent = node;
|
|
3580
|
-
while (parent) {
|
|
3581
|
-
if (parent.end >= textRange.end) {
|
|
3582
|
-
result = pipe(result, append(parent));
|
|
3583
|
-
}
|
|
3584
|
-
parent = parent.parent;
|
|
3585
|
-
}
|
|
3586
|
-
return result;
|
|
3587
|
-
});
|
|
3588
|
-
}
|
|
3589
|
-
function getAncestorNodesInRange(sourceFile, textRange) {
|
|
3590
|
-
return gen2(function* () {
|
|
3591
|
-
const ts = yield* service(TypeScriptApi);
|
|
3592
|
-
const precedingToken = ts.findPrecedingToken(textRange.pos, sourceFile);
|
|
3593
|
-
if (!precedingToken) return empty();
|
|
3594
|
-
return yield* collectSelfAndAncestorNodesInRange(precedingToken, textRange);
|
|
3595
|
-
});
|
|
3596
|
-
}
|
|
3597
|
-
var NodeNotFoundError = class extends TaggedError("@effect/language-service/NodeNotFoundError") {
|
|
3598
|
-
};
|
|
3599
|
-
function findNodeAtPosition(sourceFile, position) {
|
|
3600
|
-
return gen2(function* () {
|
|
3601
|
-
const ts = yield* service(TypeScriptApi);
|
|
3602
|
-
function find(node) {
|
|
3603
|
-
if (position >= node.getStart() && position < node.getEnd()) {
|
|
3604
|
-
return ts.forEachChild(node, find) || node;
|
|
3605
|
-
}
|
|
3606
|
-
return void 0;
|
|
3607
|
-
}
|
|
3608
|
-
const result = find(sourceFile);
|
|
3609
|
-
if (!result) return yield* fail3(new NodeNotFoundError());
|
|
3610
|
-
return result;
|
|
3611
|
-
});
|
|
3612
|
-
}
|
|
3613
|
-
function collectDescendantsAndAncestorsInRange(sourceFile, textRange) {
|
|
3614
|
-
return gen2(function* () {
|
|
3615
|
-
const nodeAtPosition = yield* option(findNodeAtPosition(sourceFile, textRange.pos));
|
|
3616
|
-
if (isNone2(nodeAtPosition)) return empty();
|
|
3617
|
-
return yield* collectSelfAndAncestorNodesInRange(nodeAtPosition.value, textRange);
|
|
3618
|
-
});
|
|
3619
|
-
}
|
|
3620
|
-
function toTextRange(positionOrRange) {
|
|
3621
|
-
return typeof positionOrRange === "number" ? { end: positionOrRange, pos: positionOrRange } : positionOrRange;
|
|
3622
|
-
}
|
|
3623
|
-
function isNodeInRange(textRange) {
|
|
3624
|
-
return (node) => node.pos <= textRange.pos && node.end >= textRange.end;
|
|
3625
|
-
}
|
|
3626
|
-
function transformAsyncAwaitToEffectGen(node, effectModuleName, onAwait) {
|
|
3627
|
-
return gen2(function* () {
|
|
3628
|
-
const ts = yield* service(TypeScriptApi);
|
|
3629
|
-
function visitor(_) {
|
|
3630
|
-
if (ts.isAwaitExpression(_)) {
|
|
3631
|
-
const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext);
|
|
3632
|
-
return ts.factory.createYieldExpression(
|
|
3633
|
-
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
3634
|
-
onAwait(expression)
|
|
3635
|
-
);
|
|
3636
|
-
}
|
|
3637
|
-
return ts.visitEachChild(_, visitor, ts.nullTransformationContext);
|
|
3638
|
-
}
|
|
3639
|
-
const generatorBody = visitor(node.body);
|
|
3640
|
-
const generator = ts.factory.createFunctionExpression(
|
|
3641
|
-
void 0,
|
|
3642
|
-
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
3643
|
-
void 0,
|
|
3644
|
-
[],
|
|
3645
|
-
[],
|
|
3646
|
-
void 0,
|
|
3647
|
-
generatorBody
|
|
3648
|
-
// NOTE(mattia): intended, to use same routine for both ConciseBody and Body
|
|
3649
|
-
);
|
|
3650
|
-
const effectGenCallExp = ts.factory.createCallExpression(
|
|
3651
|
-
ts.factory.createPropertyAccessExpression(
|
|
3652
|
-
ts.factory.createIdentifier(effectModuleName),
|
|
3653
|
-
"gen"
|
|
3654
|
-
),
|
|
3655
|
-
void 0,
|
|
3656
|
-
[generator]
|
|
3657
|
-
);
|
|
3658
|
-
let currentFlags = ts.getCombinedModifierFlags(node);
|
|
3659
|
-
currentFlags &= ~ts.ModifierFlags.Async;
|
|
3660
|
-
const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags);
|
|
3661
|
-
if (ts.isArrowFunction(node)) {
|
|
3662
|
-
return ts.factory.createArrowFunction(
|
|
3663
|
-
newModifiers,
|
|
3664
|
-
node.typeParameters,
|
|
3665
|
-
node.parameters,
|
|
3666
|
-
void 0,
|
|
3667
|
-
node.equalsGreaterThanToken,
|
|
3668
|
-
effectGenCallExp
|
|
3669
|
-
);
|
|
3670
|
-
}
|
|
3671
|
-
const newBody = ts.factory.createBlock([
|
|
3672
|
-
ts.factory.createReturnStatement(effectGenCallExp)
|
|
3673
|
-
]);
|
|
3674
|
-
if (ts.isFunctionDeclaration(node)) {
|
|
3675
|
-
return ts.factory.createFunctionDeclaration(
|
|
3676
|
-
newModifiers,
|
|
3677
|
-
node.asteriskToken,
|
|
3678
|
-
node.name,
|
|
3679
|
-
node.typeParameters,
|
|
3680
|
-
node.parameters,
|
|
3681
|
-
void 0,
|
|
3682
|
-
newBody
|
|
3683
|
-
);
|
|
3684
|
-
}
|
|
3685
|
-
return ts.factory.createFunctionExpression(
|
|
3686
|
-
newModifiers,
|
|
3687
|
-
node.asteriskToken,
|
|
3688
|
-
node.name,
|
|
3689
|
-
node.typeParameters,
|
|
3690
|
-
node.parameters,
|
|
3691
|
-
void 0,
|
|
3692
|
-
newBody
|
|
3693
|
-
);
|
|
3694
|
-
});
|
|
3695
|
-
}
|
|
3696
|
-
function addReturnTypeAnnotation(sourceFile, declaration, typeNode) {
|
|
3697
|
-
return gen2(function* () {
|
|
3698
|
-
const ts = yield* service(TypeScriptApi);
|
|
3699
|
-
const changes = yield* service(ChangeTracker);
|
|
3700
|
-
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
|
|
3701
|
-
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
3702
|
-
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
3703
|
-
if (endNode) {
|
|
3704
|
-
if (needParens) {
|
|
3705
|
-
changes.insertNodeBefore(
|
|
3706
|
-
sourceFile,
|
|
3707
|
-
endNode,
|
|
3708
|
-
ts.factory.createToken(ts.SyntaxKind.OpenParenToken)
|
|
3709
|
-
);
|
|
3710
|
-
changes.insertNodeAfter(
|
|
3711
|
-
sourceFile,
|
|
3712
|
-
endNode,
|
|
3713
|
-
ts.factory.createToken(ts.SyntaxKind.CloseParenToken)
|
|
3714
|
-
);
|
|
3715
|
-
}
|
|
3716
|
-
changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: ": " });
|
|
3717
|
-
}
|
|
3718
|
-
});
|
|
3719
|
-
}
|
|
3720
|
-
function removeReturnTypeAnnotation(sourceFile, declaration) {
|
|
3721
|
-
return gen2(function* () {
|
|
3722
|
-
const ts = yield* service(TypeScriptApi);
|
|
3723
|
-
const changes = yield* service(ChangeTracker);
|
|
3724
|
-
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
|
|
3725
|
-
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
3726
|
-
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
3727
|
-
if (endNode && declaration.type) {
|
|
3728
|
-
changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end });
|
|
3729
|
-
}
|
|
3730
|
-
});
|
|
3731
|
-
}
|
|
3732
|
-
var ImportModuleIdentifierNotFoundError = class extends TaggedError("@effect/language-service/ImportModuleIdentifierNotFoundError") {
|
|
3733
|
-
};
|
|
3734
|
-
function findImportedModuleIdentifier(sourceFile, test) {
|
|
3735
|
-
return gen2(function* () {
|
|
3736
|
-
const ts = yield* service(TypeScriptApi);
|
|
3737
|
-
for (const statement of sourceFile.statements) {
|
|
3738
|
-
if (!ts.isImportDeclaration(statement)) continue;
|
|
3739
|
-
const importClause = statement.importClause;
|
|
3740
|
-
if (!importClause) continue;
|
|
3741
|
-
const namedBindings = importClause.namedBindings;
|
|
3742
|
-
if (!namedBindings) continue;
|
|
3743
|
-
if (ts.isNamespaceImport(namedBindings)) {
|
|
3744
|
-
if (yield* test(namedBindings.name, statement.moduleSpecifier, none2())) {
|
|
3745
|
-
return namedBindings.name;
|
|
3746
|
-
}
|
|
3747
|
-
} else if (ts.isNamedImports(namedBindings)) {
|
|
3748
|
-
for (const importSpecifier of namedBindings.elements) {
|
|
3749
|
-
const importProperty = fromNullable2(importSpecifier.propertyName).pipe(
|
|
3750
|
-
orElse2(() => some2(importSpecifier.name))
|
|
3751
|
-
);
|
|
3752
|
-
if (yield* test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
|
|
3753
|
-
return importSpecifier.name;
|
|
3754
|
-
}
|
|
3755
|
-
}
|
|
3756
|
-
}
|
|
3757
|
-
}
|
|
3758
|
-
return yield* fail3(new ImportModuleIdentifierNotFoundError());
|
|
3759
|
-
});
|
|
3760
|
-
}
|
|
3761
|
-
function simplifyTypeNode(typeNode) {
|
|
3762
|
-
function collectCallable(ts, typeNode2) {
|
|
3763
|
-
if (ts.isParenthesizedTypeNode(typeNode2)) return collectCallable(ts, typeNode2.type);
|
|
3764
|
-
if (ts.isFunctionTypeNode(typeNode2)) {
|
|
3765
|
-
return some2([
|
|
3766
|
-
ts.factory.createCallSignature(typeNode2.typeParameters, typeNode2.parameters, typeNode2.type)
|
|
3767
|
-
]);
|
|
3768
|
-
}
|
|
3769
|
-
if (ts.isTypeLiteralNode(typeNode2)) {
|
|
3770
|
-
const allCallSignatures = typeNode2.members.every(ts.isCallSignatureDeclaration);
|
|
3771
|
-
if (allCallSignatures) {
|
|
3772
|
-
return some2(typeNode2.members);
|
|
3773
|
-
}
|
|
3774
|
-
}
|
|
3775
|
-
if (ts.isIntersectionTypeNode(typeNode2)) {
|
|
3776
|
-
const members = typeNode2.types.map((node) => collectCallable(ts, node));
|
|
3777
|
-
if (members.every(isSome2)) {
|
|
3778
|
-
return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
|
|
3779
|
-
}
|
|
3780
|
-
}
|
|
3781
|
-
return none2();
|
|
3782
|
-
}
|
|
3783
|
-
return gen2(function* () {
|
|
3784
|
-
const ts = yield* service(TypeScriptApi);
|
|
3785
|
-
const callSignatures = collectCallable(ts, typeNode);
|
|
3786
|
-
if (isSome2(callSignatures) && callSignatures.value.length > 1) {
|
|
3787
|
-
return ts.factory.createTypeLiteralNode(callSignatures.value);
|
|
3788
|
-
}
|
|
3789
|
-
return typeNode;
|
|
3790
|
-
});
|
|
3791
|
-
}
|
|
3792
|
-
function tryPreserveDeclarationSemantics(nodeToReplace, node) {
|
|
3793
|
-
return gen2(function* () {
|
|
3794
|
-
const ts = yield* service(TypeScriptApi);
|
|
3795
|
-
if (!ts.isExpression(node)) return node;
|
|
3796
|
-
if (ts.isFunctionDeclaration(nodeToReplace)) {
|
|
3797
|
-
if (!nodeToReplace.name) return node;
|
|
3798
|
-
return ts.factory.createVariableStatement(
|
|
3799
|
-
nodeToReplace.modifiers,
|
|
3800
|
-
ts.factory.createVariableDeclarationList(
|
|
3801
|
-
[ts.factory.createVariableDeclaration(
|
|
3802
|
-
nodeToReplace.name,
|
|
3803
|
-
void 0,
|
|
3804
|
-
void 0,
|
|
3805
|
-
node
|
|
3806
|
-
)],
|
|
3807
|
-
ts.NodeFlags.Const
|
|
3808
|
-
)
|
|
3809
|
-
);
|
|
3810
|
-
} else if (ts.isMethodDeclaration(nodeToReplace)) {
|
|
3811
|
-
return ts.factory.createPropertyDeclaration(
|
|
3812
|
-
nodeToReplace.modifiers,
|
|
3813
|
-
nodeToReplace.name,
|
|
3814
|
-
void 0,
|
|
3815
|
-
void 0,
|
|
3816
|
-
node
|
|
3817
|
-
);
|
|
3818
|
-
}
|
|
3819
|
-
return node;
|
|
3820
|
-
});
|
|
3821
|
-
}
|
|
3822
|
-
|
|
3823
4002
|
// src/quickinfo.ts
|
|
3824
4003
|
var SymbolDisplayPartEq = make(
|
|
3825
4004
|
(fa, fb) => fa.kind === fb.kind && fa.text === fb.text
|
|
@@ -4498,7 +4677,8 @@ var init = (modules) => {
|
|
|
4498
4677
|
const languageService = info.languageService;
|
|
4499
4678
|
const pluginOptions = {
|
|
4500
4679
|
diagnostics: info.config && "diagnostics" in info.config && typeof info.config.diagnostics === "boolean" ? info.config.diagnostics : true,
|
|
4501
|
-
quickinfo: info.config && "quickinfo" in info.config && typeof info.config.quickinfo === "boolean" ? info.config.quickinfo : true
|
|
4680
|
+
quickinfo: info.config && "quickinfo" in info.config && typeof info.config.quickinfo === "boolean" ? info.config.quickinfo : true,
|
|
4681
|
+
completions: info.config && "completions" in info.config && typeof info.config.completions === "boolean" ? info.config.completions : true
|
|
4502
4682
|
};
|
|
4503
4683
|
const proxy = /* @__PURE__ */ Object.create(null);
|
|
4504
4684
|
for (const k of Object.keys(languageService)) {
|
|
@@ -4565,8 +4745,12 @@ var init = (modules) => {
|
|
|
4565
4745
|
}
|
|
4566
4746
|
return effectCodeFixes;
|
|
4567
4747
|
}),
|
|
4568
|
-
provideService(TypeScriptApi, modules.typescript),
|
|
4569
4748
|
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
4749
|
+
provideService(
|
|
4750
|
+
TypeCheckerApiCache,
|
|
4751
|
+
makeTypeCheckerApiCache()
|
|
4752
|
+
),
|
|
4753
|
+
provideService(TypeScriptApi, modules.typescript),
|
|
4570
4754
|
provideService(PluginOptions, pluginOptions),
|
|
4571
4755
|
run,
|
|
4572
4756
|
Either_exports.map((effectCodeFixes) => applicableCodeFixes.concat(effectCodeFixes)),
|
|
@@ -4584,8 +4768,12 @@ var init = (modules) => {
|
|
|
4584
4768
|
if (sourceFile) {
|
|
4585
4769
|
return pipe(
|
|
4586
4770
|
getSemanticDiagnostics(diagnostics, sourceFile),
|
|
4587
|
-
provideService(TypeScriptApi, modules.typescript),
|
|
4588
4771
|
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
4772
|
+
provideService(
|
|
4773
|
+
TypeCheckerApiCache,
|
|
4774
|
+
makeTypeCheckerApiCache()
|
|
4775
|
+
),
|
|
4776
|
+
provideService(TypeScriptApi, modules.typescript),
|
|
4589
4777
|
provideService(PluginOptions, pluginOptions),
|
|
4590
4778
|
run,
|
|
4591
4779
|
Either_exports.map((effectDiagnostics) => effectDiagnostics.concat(applicableDiagnostics)),
|
|
@@ -4604,8 +4792,12 @@ var init = (modules) => {
|
|
|
4604
4792
|
if (sourceFile) {
|
|
4605
4793
|
return pipe(
|
|
4606
4794
|
getApplicableRefactors(refactors, sourceFile, positionOrRange),
|
|
4607
|
-
provideService(TypeScriptApi, modules.typescript),
|
|
4608
4795
|
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
4796
|
+
provideService(
|
|
4797
|
+
TypeCheckerApiCache,
|
|
4798
|
+
makeTypeCheckerApiCache()
|
|
4799
|
+
),
|
|
4800
|
+
provideService(TypeScriptApi, modules.typescript),
|
|
4609
4801
|
provideService(PluginOptions, pluginOptions),
|
|
4610
4802
|
run,
|
|
4611
4803
|
Either_exports.map((effectRefactors) => applicableRefactors.concat(effectRefactors)),
|
|
@@ -4646,8 +4838,12 @@ var init = (modules) => {
|
|
|
4646
4838
|
);
|
|
4647
4839
|
return { edits };
|
|
4648
4840
|
}),
|
|
4649
|
-
provideService(TypeScriptApi, modules.typescript),
|
|
4650
4841
|
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
4842
|
+
provideService(
|
|
4843
|
+
TypeCheckerApiCache,
|
|
4844
|
+
makeTypeCheckerApiCache()
|
|
4845
|
+
),
|
|
4846
|
+
provideService(TypeScriptApi, modules.typescript),
|
|
4651
4847
|
provideService(PluginOptions, pluginOptions),
|
|
4652
4848
|
run
|
|
4653
4849
|
);
|
|
@@ -4678,8 +4874,9 @@ var init = (modules) => {
|
|
|
4678
4874
|
position,
|
|
4679
4875
|
dedupedTagsQuickInfo
|
|
4680
4876
|
),
|
|
4681
|
-
provideService(TypeScriptApi, modules.typescript),
|
|
4682
4877
|
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
4878
|
+
provideService(TypeScriptApi, modules.typescript),
|
|
4879
|
+
provideService(PluginOptions, pluginOptions),
|
|
4683
4880
|
run,
|
|
4684
4881
|
Either_exports.getOrElse(() => dedupedTagsQuickInfo)
|
|
4685
4882
|
);
|
|
@@ -4689,6 +4886,53 @@ var init = (modules) => {
|
|
|
4689
4886
|
}
|
|
4690
4887
|
return quickInfo;
|
|
4691
4888
|
};
|
|
4889
|
+
proxy.getCompletionsAtPosition = (fileName, position, options, formattingSettings, ...args) => {
|
|
4890
|
+
const applicableCompletions = languageService.getCompletionsAtPosition(
|
|
4891
|
+
fileName,
|
|
4892
|
+
position,
|
|
4893
|
+
options,
|
|
4894
|
+
formattingSettings,
|
|
4895
|
+
...args
|
|
4896
|
+
);
|
|
4897
|
+
if (pluginOptions.completions) {
|
|
4898
|
+
const program = languageService.getProgram();
|
|
4899
|
+
if (program) {
|
|
4900
|
+
const sourceFile = program.getSourceFile(fileName);
|
|
4901
|
+
if (sourceFile) {
|
|
4902
|
+
return pipe(
|
|
4903
|
+
getCompletionsAtPosition(
|
|
4904
|
+
completions,
|
|
4905
|
+
sourceFile,
|
|
4906
|
+
position,
|
|
4907
|
+
options,
|
|
4908
|
+
formattingSettings
|
|
4909
|
+
),
|
|
4910
|
+
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
4911
|
+
provideService(
|
|
4912
|
+
TypeCheckerApiCache,
|
|
4913
|
+
makeTypeCheckerApiCache()
|
|
4914
|
+
),
|
|
4915
|
+
provideService(TypeScriptApi, modules.typescript),
|
|
4916
|
+
provideService(PluginOptions, pluginOptions),
|
|
4917
|
+
run,
|
|
4918
|
+
Either_exports.map(
|
|
4919
|
+
(effectCompletions) => applicableCompletions ? {
|
|
4920
|
+
...applicableCompletions,
|
|
4921
|
+
entries: effectCompletions.concat(applicableCompletions.entries)
|
|
4922
|
+
} : effectCompletions.length > 0 ? {
|
|
4923
|
+
entries: effectCompletions,
|
|
4924
|
+
isGlobalCompletion: false,
|
|
4925
|
+
isMemberCompletion: false,
|
|
4926
|
+
isNewIdentifierLocation: false
|
|
4927
|
+
} : void 0
|
|
4928
|
+
),
|
|
4929
|
+
Either_exports.getOrElse(() => applicableCompletions)
|
|
4930
|
+
);
|
|
4931
|
+
}
|
|
4932
|
+
}
|
|
4933
|
+
}
|
|
4934
|
+
return applicableCompletions;
|
|
4935
|
+
};
|
|
4692
4936
|
return proxy;
|
|
4693
4937
|
}
|
|
4694
4938
|
return { create };
|