@effect/language-service 0.28.3 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/cli.js +1398 -615
- package/cli.js.map +1 -1
- package/index.js +1779 -1302
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +1398 -619
- package/transform.js.map +1 -1
package/index.js
CHANGED
|
@@ -735,104 +735,12 @@ var none2 = () => none;
|
|
|
735
735
|
var some2 = some;
|
|
736
736
|
var isNone2 = isNone;
|
|
737
737
|
var isSome2 = isSome;
|
|
738
|
-
var match = /* @__PURE__ */ dual(2, (self, {
|
|
739
|
-
onNone,
|
|
740
|
-
onSome
|
|
741
|
-
}) => isNone2(self) ? onNone() : onSome(self.value));
|
|
742
738
|
var getOrElse2 = /* @__PURE__ */ dual(2, (self, onNone) => isNone2(self) ? onNone() : self.value);
|
|
743
739
|
var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : self);
|
|
744
740
|
var fromNullable = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
|
|
745
741
|
var getOrUndefined = /* @__PURE__ */ getOrElse2(constUndefined);
|
|
746
742
|
var map2 = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() : some2(f(self.value)));
|
|
747
743
|
|
|
748
|
-
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/array.js
|
|
749
|
-
var isNonEmptyArray = (self) => self.length > 0;
|
|
750
|
-
|
|
751
|
-
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Array.js
|
|
752
|
-
var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
|
|
753
|
-
var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
|
|
754
|
-
var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
|
|
755
|
-
var isArray = Array.isArray;
|
|
756
|
-
var isEmptyArray = (self) => self.length === 0;
|
|
757
|
-
var isEmptyReadonlyArray = isEmptyArray;
|
|
758
|
-
var isNonEmptyReadonlyArray = isNonEmptyArray;
|
|
759
|
-
var isOutOfBounds = (i, as) => i < 0 || i >= as.length;
|
|
760
|
-
var get = /* @__PURE__ */ dual(2, (self, index) => {
|
|
761
|
-
const i = Math.floor(index);
|
|
762
|
-
return isOutOfBounds(i, self) ? none2() : some2(self[i]);
|
|
763
|
-
});
|
|
764
|
-
var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
|
|
765
|
-
const i = Math.floor(index);
|
|
766
|
-
if (isOutOfBounds(i, self)) {
|
|
767
|
-
throw new Error(`Index ${i} out of bounds`);
|
|
768
|
-
}
|
|
769
|
-
return self[i];
|
|
770
|
-
});
|
|
771
|
-
var head = /* @__PURE__ */ get(0);
|
|
772
|
-
var headNonEmpty = /* @__PURE__ */ unsafeGet(0);
|
|
773
|
-
var tailNonEmpty = (self) => self.slice(1);
|
|
774
|
-
var sort = /* @__PURE__ */ dual(2, (self, O) => {
|
|
775
|
-
const out = Array.from(self);
|
|
776
|
-
out.sort(O);
|
|
777
|
-
return out;
|
|
778
|
-
});
|
|
779
|
-
var containsWith = (isEquivalent) => dual(2, (self, a) => {
|
|
780
|
-
for (const i of self) {
|
|
781
|
-
if (isEquivalent(a, i)) {
|
|
782
|
-
return true;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
return false;
|
|
786
|
-
});
|
|
787
|
-
var _equivalence = /* @__PURE__ */ equivalence();
|
|
788
|
-
var intersectionWith = (isEquivalent) => {
|
|
789
|
-
const has = containsWith(isEquivalent);
|
|
790
|
-
return dual(2, (self, that) => fromIterable(self).filter((a) => has(that, a)));
|
|
791
|
-
};
|
|
792
|
-
var intersection = /* @__PURE__ */ intersectionWith(_equivalence);
|
|
793
|
-
var empty = () => [];
|
|
794
|
-
var map3 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
|
|
795
|
-
var flatMap = /* @__PURE__ */ dual(2, (self, f) => {
|
|
796
|
-
if (isEmptyReadonlyArray(self)) {
|
|
797
|
-
return [];
|
|
798
|
-
}
|
|
799
|
-
const out = [];
|
|
800
|
-
for (let i = 0; i < self.length; i++) {
|
|
801
|
-
const inner = f(self[i], i);
|
|
802
|
-
for (let j = 0; j < inner.length; j++) {
|
|
803
|
-
out.push(inner[j]);
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
return out;
|
|
807
|
-
});
|
|
808
|
-
var flatten = /* @__PURE__ */ flatMap(identity);
|
|
809
|
-
var filter = /* @__PURE__ */ dual(2, (self, predicate) => {
|
|
810
|
-
const as = fromIterable(self);
|
|
811
|
-
const out = [];
|
|
812
|
-
for (let i = 0; i < as.length; i++) {
|
|
813
|
-
if (predicate(as[i], i)) {
|
|
814
|
-
out.push(as[i]);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
return out;
|
|
818
|
-
});
|
|
819
|
-
var every = /* @__PURE__ */ dual(2, (self, refinement) => self.every(refinement));
|
|
820
|
-
var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
|
|
821
|
-
const input = fromIterable(self);
|
|
822
|
-
if (isNonEmptyReadonlyArray(input)) {
|
|
823
|
-
const out = [headNonEmpty(input)];
|
|
824
|
-
const rest = tailNonEmpty(input);
|
|
825
|
-
for (const r of rest) {
|
|
826
|
-
if (out.every((a) => !isEquivalent(r, a))) {
|
|
827
|
-
out.push(r);
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
return out;
|
|
831
|
-
}
|
|
832
|
-
return [];
|
|
833
|
-
});
|
|
834
|
-
var dedupe = (self) => dedupeWith(self, equivalence());
|
|
835
|
-
|
|
836
744
|
// src/core/Nano.ts
|
|
837
745
|
var NanoTag = class {
|
|
838
746
|
constructor(key) {
|
|
@@ -950,13 +858,13 @@ var OnSuccessProto = {
|
|
|
950
858
|
return this[args];
|
|
951
859
|
}
|
|
952
860
|
};
|
|
953
|
-
var
|
|
861
|
+
var flatMap = dual(2, (fa, f) => {
|
|
954
862
|
const nano = Object.create(OnSuccessProto);
|
|
955
863
|
nano[args] = fa;
|
|
956
864
|
nano[contA] = f;
|
|
957
865
|
return nano;
|
|
958
866
|
});
|
|
959
|
-
var
|
|
867
|
+
var map3 = dual(2, (fa, f) => flatMap(fa, (_) => succeed(f(_))));
|
|
960
868
|
var SyncProto = {
|
|
961
869
|
...PrimitiveProto,
|
|
962
870
|
[evaluate](fiber) {
|
|
@@ -997,7 +905,7 @@ var MatchProto = {
|
|
|
997
905
|
return this[args];
|
|
998
906
|
}
|
|
999
907
|
};
|
|
1000
|
-
var
|
|
908
|
+
var match = (fa, opts) => {
|
|
1001
909
|
const nano = Object.create(MatchProto);
|
|
1002
910
|
nano[args] = fa;
|
|
1003
911
|
nano[contA] = opts.onSuccess;
|
|
@@ -1020,7 +928,7 @@ var ProvideServiceProto = {
|
|
|
1020
928
|
...fiber._services,
|
|
1021
929
|
[tag.key]: value
|
|
1022
930
|
};
|
|
1023
|
-
return
|
|
931
|
+
return match(fa, {
|
|
1024
932
|
onSuccess: (_) => {
|
|
1025
933
|
fiber._services = prevServices;
|
|
1026
934
|
return succeed(_);
|
|
@@ -1063,7 +971,7 @@ var CachedProto = {
|
|
|
1063
971
|
fiber._cache[type] = cache;
|
|
1064
972
|
const cached2 = cache.get(key);
|
|
1065
973
|
if (cached2) return cached2;
|
|
1066
|
-
return
|
|
974
|
+
return match(fa, {
|
|
1067
975
|
onSuccess: (_) => {
|
|
1068
976
|
cache.set(key, succeed(_));
|
|
1069
977
|
return succeed(_);
|
|
@@ -1111,44 +1019,138 @@ var all = fn("all")(
|
|
|
1111
1019
|
var TypeScriptApi = Tag("TypeScriptApi");
|
|
1112
1020
|
var TypeScriptProgram = Tag("TypeScriptProgram");
|
|
1113
1021
|
var ChangeTracker = Tag("ChangeTracker");
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1022
|
+
|
|
1023
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/array.js
|
|
1024
|
+
var isNonEmptyArray = (self) => self.length > 0;
|
|
1025
|
+
|
|
1026
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Array.js
|
|
1027
|
+
var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
|
|
1028
|
+
var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
|
|
1029
|
+
var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
|
|
1030
|
+
var isArray = Array.isArray;
|
|
1031
|
+
var isEmptyArray = (self) => self.length === 0;
|
|
1032
|
+
var isEmptyReadonlyArray = isEmptyArray;
|
|
1033
|
+
var isNonEmptyReadonlyArray = isNonEmptyArray;
|
|
1034
|
+
var isOutOfBounds = (i, as) => i < 0 || i >= as.length;
|
|
1035
|
+
var get = /* @__PURE__ */ dual(2, (self, index) => {
|
|
1036
|
+
const i = Math.floor(index);
|
|
1037
|
+
return isOutOfBounds(i, self) ? none2() : some2(self[i]);
|
|
1038
|
+
});
|
|
1039
|
+
var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
|
|
1040
|
+
const i = Math.floor(index);
|
|
1041
|
+
if (isOutOfBounds(i, self)) {
|
|
1042
|
+
throw new Error(`Index ${i} out of bounds`);
|
|
1043
|
+
}
|
|
1044
|
+
return self[i];
|
|
1045
|
+
});
|
|
1046
|
+
var head = /* @__PURE__ */ get(0);
|
|
1047
|
+
var headNonEmpty = /* @__PURE__ */ unsafeGet(0);
|
|
1048
|
+
var tailNonEmpty = (self) => self.slice(1);
|
|
1049
|
+
var sort = /* @__PURE__ */ dual(2, (self, O) => {
|
|
1050
|
+
const out = Array.from(self);
|
|
1051
|
+
out.sort(O);
|
|
1052
|
+
return out;
|
|
1053
|
+
});
|
|
1054
|
+
var containsWith = (isEquivalent) => dual(2, (self, a) => {
|
|
1055
|
+
for (const i of self) {
|
|
1056
|
+
if (isEquivalent(a, i)) {
|
|
1057
|
+
return true;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
return false;
|
|
1061
|
+
});
|
|
1062
|
+
var _equivalence = /* @__PURE__ */ equivalence();
|
|
1063
|
+
var intersectionWith = (isEquivalent) => {
|
|
1064
|
+
const has = containsWith(isEquivalent);
|
|
1065
|
+
return dual(2, (self, that) => fromIterable(self).filter((a) => has(that, a)));
|
|
1066
|
+
};
|
|
1067
|
+
var intersection = /* @__PURE__ */ intersectionWith(_equivalence);
|
|
1068
|
+
var empty = () => [];
|
|
1069
|
+
var map4 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
|
|
1070
|
+
var flatMap2 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
1071
|
+
if (isEmptyReadonlyArray(self)) {
|
|
1072
|
+
return [];
|
|
1073
|
+
}
|
|
1074
|
+
const out = [];
|
|
1075
|
+
for (let i = 0; i < self.length; i++) {
|
|
1076
|
+
const inner = f(self[i], i);
|
|
1077
|
+
for (let j = 0; j < inner.length; j++) {
|
|
1078
|
+
out.push(inner[j]);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return out;
|
|
1082
|
+
});
|
|
1083
|
+
var flatten = /* @__PURE__ */ flatMap2(identity);
|
|
1084
|
+
var filter = /* @__PURE__ */ dual(2, (self, predicate) => {
|
|
1085
|
+
const as = fromIterable(self);
|
|
1086
|
+
const out = [];
|
|
1087
|
+
for (let i = 0; i < as.length; i++) {
|
|
1088
|
+
if (predicate(as[i], i)) {
|
|
1089
|
+
out.push(as[i]);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
return out;
|
|
1093
|
+
});
|
|
1094
|
+
var every = /* @__PURE__ */ dual(2, (self, refinement) => self.every(refinement));
|
|
1095
|
+
var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
|
|
1096
|
+
const input = fromIterable(self);
|
|
1097
|
+
if (isNonEmptyReadonlyArray(input)) {
|
|
1098
|
+
const out = [headNonEmpty(input)];
|
|
1099
|
+
const rest = tailNonEmpty(input);
|
|
1100
|
+
for (const r of rest) {
|
|
1101
|
+
if (out.every((a) => !isEquivalent(r, a))) {
|
|
1102
|
+
out.push(r);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
return out;
|
|
1106
|
+
}
|
|
1107
|
+
return [];
|
|
1108
|
+
});
|
|
1109
|
+
var dedupe = (self) => dedupeWith(self, equivalence());
|
|
1110
|
+
|
|
1111
|
+
// src/core/TypeScriptUtils.ts
|
|
1112
|
+
var TypeScriptUtils = Tag("TypeScriptUtils");
|
|
1113
|
+
var nanoLayer = (fa) => pipe(
|
|
1114
|
+
service(TypeScriptApi),
|
|
1115
|
+
flatMap((ts) => pipe(fa, provideService(TypeScriptUtils, makeTypeScriptUtils(ts))))
|
|
1116
|
+
);
|
|
1117
|
+
function makeTypeScriptUtils(ts) {
|
|
1118
|
+
function parsePackageContentNameAndVersionFromScope(v) {
|
|
1119
|
+
if (!isObject(v)) return;
|
|
1120
|
+
if (!hasProperty(v, "packageJsonScope")) return;
|
|
1121
|
+
if (!v.packageJsonScope) return;
|
|
1122
|
+
const packageJsonScope = v.packageJsonScope;
|
|
1123
|
+
if (!hasProperty(packageJsonScope, "contents")) return;
|
|
1124
|
+
if (!hasProperty(packageJsonScope.contents, "packageJsonContent")) return;
|
|
1125
|
+
const packageJsonContent = packageJsonScope.contents.packageJsonContent;
|
|
1126
|
+
if (!hasProperty(packageJsonContent, "name")) return;
|
|
1127
|
+
if (!hasProperty(packageJsonContent, "version")) return;
|
|
1128
|
+
if (!hasProperty(packageJsonScope, "packageDirectory")) return;
|
|
1129
|
+
if (!isString(packageJsonScope.packageDirectory)) return;
|
|
1130
|
+
const { name, version } = packageJsonContent;
|
|
1131
|
+
if (!isString(name)) return;
|
|
1132
|
+
if (!isString(version)) return;
|
|
1133
|
+
const hasEffectInPeerDependencies = hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) && hasProperty(packageJsonContent.peerDependencies, "effect");
|
|
1134
|
+
const referencedPackages = Object.keys({
|
|
1135
|
+
...hasProperty(packageJsonContent, "dependencies") && isObject(packageJsonContent.dependencies) ? packageJsonContent.dependencies : {},
|
|
1136
|
+
...hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) ? packageJsonContent.peerDependencies : {},
|
|
1137
|
+
...hasProperty(packageJsonContent, "devDependencies") && isObject(packageJsonContent.devDependencies) ? packageJsonContent.devDependencies : {}
|
|
1138
|
+
});
|
|
1139
|
+
const exportsKeys = Object.keys(
|
|
1140
|
+
hasProperty(packageJsonContent, "exports") && isObject(packageJsonContent.exports) ? packageJsonContent.exports : {}
|
|
1141
|
+
);
|
|
1142
|
+
return {
|
|
1143
|
+
name: name.toLowerCase(),
|
|
1144
|
+
version: version.toLowerCase(),
|
|
1145
|
+
hasEffectInPeerDependencies,
|
|
1146
|
+
contents: packageJsonContent,
|
|
1147
|
+
packageDirectory: packageJsonScope.packageDirectory,
|
|
1148
|
+
referencedPackages,
|
|
1149
|
+
exportsKeys
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
function resolveModulePattern(sourceFile, pattern) {
|
|
1150
1153
|
if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
|
|
1151
|
-
const ts = yield* service(TypeScriptApi);
|
|
1152
1154
|
const packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
|
|
1153
1155
|
const referencedPackages = [];
|
|
1154
1156
|
for (const statement of sourceFile.statements) {
|
|
@@ -1161,31 +1163,47 @@ var resolveModulePattern = fn("resolveModulePattern")(
|
|
|
1161
1163
|
return pipe(
|
|
1162
1164
|
referencedPackages.concat(packageJsonScope?.referencedPackages || []),
|
|
1163
1165
|
dedupe,
|
|
1164
|
-
|
|
1166
|
+
map4((packageName) => packageName.toLowerCase()),
|
|
1165
1167
|
filter(
|
|
1166
1168
|
(packageName) => pattern.endsWith("*") && packageName.startsWith(pattern.toLowerCase().substring(0, pattern.length - 1))
|
|
1167
1169
|
)
|
|
1168
1170
|
);
|
|
1169
1171
|
}
|
|
1170
|
-
)
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
function
|
|
1188
|
-
|
|
1172
|
+
function makeGetModuleSpecifier() {
|
|
1173
|
+
if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
|
|
1174
|
+
const _internal = ts.moduleSpecifiers.getModuleSpecifier;
|
|
1175
|
+
return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options) => {
|
|
1176
|
+
return _internal(
|
|
1177
|
+
compilerOptions,
|
|
1178
|
+
importingSourceFile,
|
|
1179
|
+
importingSourceFileName,
|
|
1180
|
+
toFileName,
|
|
1181
|
+
host,
|
|
1182
|
+
options
|
|
1183
|
+
);
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
function findNodeWithLeadingCommentAtPosition(sourceFile, position) {
|
|
1187
|
+
const sourceText = sourceFile.text;
|
|
1188
|
+
let result;
|
|
1189
|
+
function find(node) {
|
|
1190
|
+
const leading = ts.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1191
|
+
if (leading) {
|
|
1192
|
+
for (const commentRange of leading) {
|
|
1193
|
+
if (commentRange.pos <= position && position < commentRange.end) {
|
|
1194
|
+
result = { node, commentRange };
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
if (node.getFullStart() <= position && position < node.getEnd()) {
|
|
1200
|
+
node.forEachChild(find);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
find(sourceFile);
|
|
1204
|
+
return result;
|
|
1205
|
+
}
|
|
1206
|
+
function collectSelfAndAncestorNodesInRange(node, textRange) {
|
|
1189
1207
|
let result = empty();
|
|
1190
1208
|
let parent = node;
|
|
1191
1209
|
while (parent) {
|
|
@@ -1195,52 +1213,50 @@ function collectSelfAndAncestorNodesInRange(node, textRange) {
|
|
|
1195
1213
|
parent = parent.parent;
|
|
1196
1214
|
}
|
|
1197
1215
|
return result;
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
var NodeNotFoundError = class {
|
|
1206
|
-
_tag = "@effect/language-service/NodeNotFoundError";
|
|
1207
|
-
};
|
|
1208
|
-
var findNodeAtPosition = fn("AST.findNodeAtPosition")(function* (sourceFile, position) {
|
|
1209
|
-
const ts = yield* service(TypeScriptApi);
|
|
1210
|
-
function find(node) {
|
|
1211
|
-
if (position >= node.getStart() && position < node.getEnd()) {
|
|
1212
|
-
return ts.forEachChild(node, find) || node;
|
|
1216
|
+
}
|
|
1217
|
+
function findNodeAtPosition(sourceFile, position) {
|
|
1218
|
+
function find(node) {
|
|
1219
|
+
if (position >= node.getStart() && position < node.getEnd()) {
|
|
1220
|
+
return ts.forEachChild(node, find) || node;
|
|
1221
|
+
}
|
|
1222
|
+
return void 0;
|
|
1213
1223
|
}
|
|
1214
|
-
return
|
|
1224
|
+
return find(sourceFile);
|
|
1215
1225
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1226
|
+
function findNodeAtPositionIncludingTrivia(sourceFile, position) {
|
|
1227
|
+
function find(node) {
|
|
1228
|
+
if (position >= node.pos && position < node.end) {
|
|
1229
|
+
return ts.forEachChild(node, find) || node;
|
|
1230
|
+
}
|
|
1231
|
+
return void 0;
|
|
1232
|
+
}
|
|
1233
|
+
return find(sourceFile);
|
|
1234
|
+
}
|
|
1235
|
+
function getAncestorNodesInRange(sourceFile, textRange) {
|
|
1236
|
+
const nodeAtPosition = findNodeAtPosition(sourceFile, textRange.pos);
|
|
1237
|
+
if (!nodeAtPosition) return empty();
|
|
1238
|
+
return collectSelfAndAncestorNodesInRange(nodeAtPosition, textRange);
|
|
1239
|
+
}
|
|
1240
|
+
function getCommentAtPosition(sourceFile, pos) {
|
|
1241
|
+
const token = findNodeAtPositionIncludingTrivia(sourceFile, pos);
|
|
1242
|
+
if (token === void 0 || token.kind === ts.SyntaxKind.JsxText || pos >= token.end - (ts.tokenToString(token.kind) || "").length) {
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
const startPos = token.pos === 0 ? (ts.getShebang(sourceFile.text) || "").length : token.pos;
|
|
1246
|
+
if (startPos === 0) return;
|
|
1247
|
+
const result = ts.forEachTrailingCommentRange(sourceFile.text, startPos, isCommentInRange, pos) || ts.forEachLeadingCommentRange(sourceFile.text, startPos, isCommentInRange, pos);
|
|
1248
|
+
return result;
|
|
1249
|
+
}
|
|
1250
|
+
function isCommentInRange(pos, end, kind, _nl, at) {
|
|
1251
|
+
return at >= pos && at < end ? { pos, end, kind } : void 0;
|
|
1252
|
+
}
|
|
1253
|
+
function toTextRange(positionOrRange) {
|
|
1254
|
+
return typeof positionOrRange === "number" ? { end: positionOrRange, pos: positionOrRange } : positionOrRange;
|
|
1255
|
+
}
|
|
1256
|
+
function isNodeInRange(textRange) {
|
|
1257
|
+
return (node) => node.pos <= textRange.pos && node.end >= textRange.end;
|
|
1258
|
+
}
|
|
1259
|
+
function transformAsyncAwaitToEffectGen(node, effectModuleName, onAwait) {
|
|
1244
1260
|
function visitor(_) {
|
|
1245
1261
|
if (ts.isAwaitExpression(_)) {
|
|
1246
1262
|
const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext);
|
|
@@ -1252,7 +1268,7 @@ var transformAsyncAwaitToEffectGen = fn("AST.transformAsyncAwaitToEffectGen")(
|
|
|
1252
1268
|
return ts.visitEachChild(_, visitor, ts.nullTransformationContext);
|
|
1253
1269
|
}
|
|
1254
1270
|
const generatorBody = visitor(node.body);
|
|
1255
|
-
const effectGenCallExp =
|
|
1271
|
+
const effectGenCallExp = createEffectGenCallExpression(effectModuleName, generatorBody);
|
|
1256
1272
|
let currentFlags = ts.getCombinedModifierFlags(node);
|
|
1257
1273
|
currentFlags &= ~ts.ModifierFlags.Async;
|
|
1258
1274
|
const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags);
|
|
@@ -1290,45 +1306,7 @@ var transformAsyncAwaitToEffectGen = fn("AST.transformAsyncAwaitToEffectGen")(
|
|
|
1290
1306
|
newBody
|
|
1291
1307
|
);
|
|
1292
1308
|
}
|
|
1293
|
-
)
|
|
1294
|
-
var addReturnTypeAnnotation = fn("AST.addReturnTypeAnnotation")(function* (sourceFile, declaration, typeNode) {
|
|
1295
|
-
const ts = yield* service(TypeScriptApi);
|
|
1296
|
-
const changes = yield* service(ChangeTracker);
|
|
1297
|
-
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
|
|
1298
|
-
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
1299
|
-
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
1300
|
-
if (endNode) {
|
|
1301
|
-
if (needParens) {
|
|
1302
|
-
changes.insertNodeBefore(
|
|
1303
|
-
sourceFile,
|
|
1304
|
-
endNode,
|
|
1305
|
-
ts.factory.createToken(ts.SyntaxKind.OpenParenToken)
|
|
1306
|
-
);
|
|
1307
|
-
changes.insertNodeAfter(
|
|
1308
|
-
sourceFile,
|
|
1309
|
-
endNode,
|
|
1310
|
-
ts.factory.createToken(ts.SyntaxKind.CloseParenToken)
|
|
1311
|
-
);
|
|
1312
|
-
}
|
|
1313
|
-
changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: ": " });
|
|
1314
|
-
}
|
|
1315
|
-
});
|
|
1316
|
-
var removeReturnTypeAnnotation = fn("AST.removeReturnTypeAnnotation")(function* (sourceFile, declaration) {
|
|
1317
|
-
const ts = yield* service(TypeScriptApi);
|
|
1318
|
-
const changes = yield* service(ChangeTracker);
|
|
1319
|
-
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile);
|
|
1320
|
-
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
1321
|
-
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
1322
|
-
if (endNode && declaration.type) {
|
|
1323
|
-
changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end });
|
|
1324
|
-
}
|
|
1325
|
-
});
|
|
1326
|
-
var ImportModuleIdentifierNotFoundError = class {
|
|
1327
|
-
_tag = "@effect/language-service/ImportModuleIdentifierNotFoundError";
|
|
1328
|
-
};
|
|
1329
|
-
var findImportedModuleIdentifier = fn("AST.findImportedModuleIdentifier")(
|
|
1330
|
-
function* (sourceFile, test) {
|
|
1331
|
-
const ts = yield* service(TypeScriptApi);
|
|
1309
|
+
function findImportedModuleIdentifier(sourceFile, test) {
|
|
1332
1310
|
for (const statement of sourceFile.statements) {
|
|
1333
1311
|
if (!ts.isImportDeclaration(statement)) continue;
|
|
1334
1312
|
const importClause = statement.importClause;
|
|
@@ -1336,72 +1314,64 @@ var findImportedModuleIdentifier = fn("AST.findImportedModuleIdentifier")(
|
|
|
1336
1314
|
const namedBindings = importClause.namedBindings;
|
|
1337
1315
|
if (!namedBindings) continue;
|
|
1338
1316
|
if (ts.isNamespaceImport(namedBindings)) {
|
|
1339
|
-
if (
|
|
1340
|
-
return namedBindings.name;
|
|
1317
|
+
if (test(namedBindings.name, statement.moduleSpecifier, none2())) {
|
|
1318
|
+
return namedBindings.name.text;
|
|
1341
1319
|
}
|
|
1342
1320
|
} else if (ts.isNamedImports(namedBindings)) {
|
|
1343
1321
|
for (const importSpecifier of namedBindings.elements) {
|
|
1344
1322
|
const importProperty = fromNullable(importSpecifier.propertyName).pipe(
|
|
1345
1323
|
orElse(() => some2(importSpecifier.name))
|
|
1346
1324
|
);
|
|
1347
|
-
if (
|
|
1348
|
-
return importSpecifier.name;
|
|
1325
|
+
if (test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
|
|
1326
|
+
return importSpecifier.name.text;
|
|
1349
1327
|
}
|
|
1350
1328
|
}
|
|
1351
1329
|
}
|
|
1352
1330
|
}
|
|
1353
|
-
return yield* fail(new ImportModuleIdentifierNotFoundError());
|
|
1354
1331
|
}
|
|
1355
|
-
)
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1332
|
+
function findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, packageName, moduleName) {
|
|
1333
|
+
return findImportedModuleIdentifier(
|
|
1334
|
+
sourceFile,
|
|
1335
|
+
(_, fromModule, importProperty) => {
|
|
1336
|
+
if (isNone2(importProperty) && ts.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
|
|
1337
|
+
return true;
|
|
1338
|
+
}
|
|
1339
|
+
if (isSome2(importProperty) && ts.isIdentifier(importProperty.value) && importProperty.value.text === moduleName && ts.isStringLiteral(fromModule) && fromModule.text === packageName) {
|
|
1340
|
+
return true;
|
|
1341
|
+
}
|
|
1342
|
+
return false;
|
|
1365
1343
|
}
|
|
1366
|
-
|
|
1367
|
-
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1346
|
+
function simplifyTypeNode(typeNode) {
|
|
1347
|
+
function collectCallable(typeNode2) {
|
|
1348
|
+
if (ts.isParenthesizedTypeNode(typeNode2)) return collectCallable(typeNode2.type);
|
|
1349
|
+
if (ts.isFunctionTypeNode(typeNode2)) {
|
|
1350
|
+
return some2([
|
|
1351
|
+
ts.factory.createCallSignature(typeNode2.typeParameters, typeNode2.parameters, typeNode2.type)
|
|
1352
|
+
]);
|
|
1353
|
+
}
|
|
1354
|
+
if (ts.isTypeLiteralNode(typeNode2)) {
|
|
1355
|
+
const allCallSignatures = typeNode2.members.every(ts.isCallSignatureDeclaration);
|
|
1356
|
+
if (allCallSignatures) {
|
|
1357
|
+
return some2(typeNode2.members);
|
|
1358
|
+
}
|
|
1368
1359
|
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
const ts = yield* service(TypeScriptApi);
|
|
1375
|
-
function collectCallable(typeNode2) {
|
|
1376
|
-
if (ts.isParenthesizedTypeNode(typeNode2)) return collectCallable(typeNode2.type);
|
|
1377
|
-
if (ts.isFunctionTypeNode(typeNode2)) {
|
|
1378
|
-
return some2([
|
|
1379
|
-
ts.factory.createCallSignature(typeNode2.typeParameters, typeNode2.parameters, typeNode2.type)
|
|
1380
|
-
]);
|
|
1381
|
-
}
|
|
1382
|
-
if (ts.isTypeLiteralNode(typeNode2)) {
|
|
1383
|
-
const allCallSignatures = typeNode2.members.every(ts.isCallSignatureDeclaration);
|
|
1384
|
-
if (allCallSignatures) {
|
|
1385
|
-
return some2(typeNode2.members);
|
|
1360
|
+
if (ts.isIntersectionTypeNode(typeNode2)) {
|
|
1361
|
+
const members = typeNode2.types.map((node) => collectCallable(node));
|
|
1362
|
+
if (members.every(isSome2)) {
|
|
1363
|
+
return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
|
|
1364
|
+
}
|
|
1386
1365
|
}
|
|
1366
|
+
return none2();
|
|
1387
1367
|
}
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
return some2(members.map((_) => isSome2(_) ? _.value : []).flat());
|
|
1392
|
-
}
|
|
1368
|
+
const callSignatures = collectCallable(typeNode);
|
|
1369
|
+
if (isSome2(callSignatures) && callSignatures.value.length > 1) {
|
|
1370
|
+
return ts.factory.createTypeLiteralNode(callSignatures.value);
|
|
1393
1371
|
}
|
|
1394
|
-
return
|
|
1395
|
-
}
|
|
1396
|
-
const callSignatures = collectCallable(typeNode);
|
|
1397
|
-
if (isSome2(callSignatures) && callSignatures.value.length > 1) {
|
|
1398
|
-
return ts.factory.createTypeLiteralNode(callSignatures.value);
|
|
1372
|
+
return typeNode;
|
|
1399
1373
|
}
|
|
1400
|
-
|
|
1401
|
-
});
|
|
1402
|
-
var tryPreserveDeclarationSemantics = fn("AST.tryPreserveDeclarationSemantics")(
|
|
1403
|
-
function* (nodeToReplace, node) {
|
|
1404
|
-
const ts = yield* service(TypeScriptApi);
|
|
1374
|
+
function tryPreserveDeclarationSemantics(nodeToReplace, node) {
|
|
1405
1375
|
if (!ts.isExpression(node)) return node;
|
|
1406
1376
|
if (ts.isFunctionDeclaration(nodeToReplace)) {
|
|
1407
1377
|
if (!nodeToReplace.name) return node;
|
|
@@ -1428,14 +1398,9 @@ var tryPreserveDeclarationSemantics = fn("AST.tryPreserveDeclarationSemantics")(
|
|
|
1428
1398
|
}
|
|
1429
1399
|
return node;
|
|
1430
1400
|
}
|
|
1431
|
-
)
|
|
1432
|
-
var parseAccessedExpressionForCompletion = fn(
|
|
1433
|
-
"AST.parseAccessedExpressionForCompletion"
|
|
1434
|
-
)(
|
|
1435
|
-
function* (sourceFile, position) {
|
|
1436
|
-
const ts = yield* service(TypeScriptApi);
|
|
1401
|
+
function parseAccessedExpressionForCompletion(sourceFile, position) {
|
|
1437
1402
|
const precedingToken = ts.findPrecedingToken(position, sourceFile, void 0, true);
|
|
1438
|
-
if (!precedingToken) return
|
|
1403
|
+
if (!precedingToken) return;
|
|
1439
1404
|
let accessedObject = precedingToken;
|
|
1440
1405
|
let replacementSpan = ts.createTextSpan(position, 0);
|
|
1441
1406
|
let outerNode = precedingToken;
|
|
@@ -1461,67 +1426,56 @@ var parseAccessedExpressionForCompletion = fn(
|
|
|
1461
1426
|
accessedObject = precedingToken;
|
|
1462
1427
|
outerNode = precedingToken;
|
|
1463
1428
|
} else {
|
|
1464
|
-
return
|
|
1429
|
+
return;
|
|
1465
1430
|
}
|
|
1466
1431
|
return { accessedObject, outerNode, replacementSpan };
|
|
1467
1432
|
}
|
|
1468
|
-
)
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
}
|
|
1513
|
-
|
|
1514
|
-
"AST.createEffectGenCallExpressionWithBlock"
|
|
1515
|
-
)(function* (effectModuleIdentifierName, statement) {
|
|
1516
|
-
const ts = yield* service(TypeScriptApi);
|
|
1517
|
-
return yield* createEffectGenCallExpression(
|
|
1518
|
-
effectModuleIdentifierName,
|
|
1519
|
-
ts.factory.createBlock(Array.isArray(statement) ? statement : [statement], false)
|
|
1520
|
-
);
|
|
1521
|
-
});
|
|
1522
|
-
var createReturnYieldStarStatement = fn("AST.createReturnYieldStarStatement")(
|
|
1523
|
-
function* (expr) {
|
|
1524
|
-
const ts = yield* service(TypeScriptApi);
|
|
1433
|
+
function parseDataForExtendsClassCompletion(sourceFile, position) {
|
|
1434
|
+
const maybeInfos = parseAccessedExpressionForCompletion(sourceFile, position);
|
|
1435
|
+
if (!maybeInfos) return;
|
|
1436
|
+
const { accessedObject, outerNode, replacementSpan } = maybeInfos;
|
|
1437
|
+
if (!ts.isIdentifier(accessedObject)) return;
|
|
1438
|
+
let classDeclaration = outerNode.parent;
|
|
1439
|
+
while (ts.isExpressionWithTypeArguments(classDeclaration) || ts.isHeritageClause(classDeclaration)) {
|
|
1440
|
+
if (!classDeclaration.parent) break;
|
|
1441
|
+
classDeclaration = classDeclaration.parent;
|
|
1442
|
+
}
|
|
1443
|
+
if (!ts.isClassDeclaration(classDeclaration)) return;
|
|
1444
|
+
if (!classDeclaration.name) return;
|
|
1445
|
+
return {
|
|
1446
|
+
accessedObject,
|
|
1447
|
+
classDeclaration,
|
|
1448
|
+
className: classDeclaration.name,
|
|
1449
|
+
replacementSpan
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
function createEffectGenCallExpression(effectModuleIdentifierName, node) {
|
|
1453
|
+
const generator = ts.factory.createFunctionExpression(
|
|
1454
|
+
void 0,
|
|
1455
|
+
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
1456
|
+
void 0,
|
|
1457
|
+
[],
|
|
1458
|
+
[],
|
|
1459
|
+
void 0,
|
|
1460
|
+
node
|
|
1461
|
+
// NOTE(mattia): intended, to use same routine for both ConciseBody and Body
|
|
1462
|
+
);
|
|
1463
|
+
return ts.factory.createCallExpression(
|
|
1464
|
+
ts.factory.createPropertyAccessExpression(
|
|
1465
|
+
ts.factory.createIdentifier(effectModuleIdentifierName),
|
|
1466
|
+
"gen"
|
|
1467
|
+
),
|
|
1468
|
+
void 0,
|
|
1469
|
+
[generator]
|
|
1470
|
+
);
|
|
1471
|
+
}
|
|
1472
|
+
function createEffectGenCallExpressionWithBlock(effectModuleIdentifierName, statement) {
|
|
1473
|
+
return createEffectGenCallExpression(
|
|
1474
|
+
effectModuleIdentifierName,
|
|
1475
|
+
ts.factory.createBlock(isArray(statement) ? statement : [statement], false)
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1478
|
+
function createReturnYieldStarStatement(expr) {
|
|
1525
1479
|
return ts.factory.createReturnStatement(
|
|
1526
1480
|
ts.factory.createYieldExpression(
|
|
1527
1481
|
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
@@ -1529,7 +1483,26 @@ var createReturnYieldStarStatement = fn("AST.createReturnYieldStarStatement")(
|
|
|
1529
1483
|
)
|
|
1530
1484
|
);
|
|
1531
1485
|
}
|
|
1532
|
-
|
|
1486
|
+
return {
|
|
1487
|
+
findNodeAtPositionIncludingTrivia,
|
|
1488
|
+
parsePackageContentNameAndVersionFromScope,
|
|
1489
|
+
resolveModulePattern,
|
|
1490
|
+
findNodeWithLeadingCommentAtPosition,
|
|
1491
|
+
getCommentAtPosition,
|
|
1492
|
+
getAncestorNodesInRange,
|
|
1493
|
+
toTextRange,
|
|
1494
|
+
isNodeInRange,
|
|
1495
|
+
transformAsyncAwaitToEffectGen,
|
|
1496
|
+
findImportedModuleIdentifierByPackageAndNameOrBarrel,
|
|
1497
|
+
simplifyTypeNode,
|
|
1498
|
+
tryPreserveDeclarationSemantics,
|
|
1499
|
+
parseDataForExtendsClassCompletion,
|
|
1500
|
+
createEffectGenCallExpressionWithBlock,
|
|
1501
|
+
createReturnYieldStarStatement,
|
|
1502
|
+
makeGetModuleSpecifier,
|
|
1503
|
+
parseAccessedExpressionForCompletion
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1533
1506
|
|
|
1534
1507
|
// src/core/LanguageServicePluginOptions.ts
|
|
1535
1508
|
var LanguageServicePluginOptions = Tag("PluginOptions");
|
|
@@ -1539,7 +1512,7 @@ function parseDiagnosticSeverity(config) {
|
|
|
1539
1512
|
pipe(
|
|
1540
1513
|
Object.entries(config),
|
|
1541
1514
|
filter(([key, value]) => isString(key) && isString(value)),
|
|
1542
|
-
|
|
1515
|
+
map4(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),
|
|
1543
1516
|
filter(
|
|
1544
1517
|
([_, value]) => value === "off" || value === "error" || value === "warning" || value === "message" || value === "suggestion"
|
|
1545
1518
|
)
|
|
@@ -1631,27 +1604,8 @@ var getCompletionsAtPosition = fn("LSP.getCompletionsAtPosition")(function* (com
|
|
|
1631
1604
|
var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
1632
1605
|
function* (sourceFile) {
|
|
1633
1606
|
const ts = yield* service(TypeScriptApi);
|
|
1607
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
1634
1608
|
const pluginOptions = yield* service(LanguageServicePluginOptions);
|
|
1635
|
-
function findNodeWithLeadingCommentAtPosition(position) {
|
|
1636
|
-
const sourceText = sourceFile.text;
|
|
1637
|
-
let result;
|
|
1638
|
-
function find(node) {
|
|
1639
|
-
const leading = ts.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1640
|
-
if (leading) {
|
|
1641
|
-
for (const r of leading) {
|
|
1642
|
-
if (r.pos <= position && position < r.end) {
|
|
1643
|
-
result = node;
|
|
1644
|
-
return;
|
|
1645
|
-
}
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
if (node.getFullStart() <= position && position < node.getEnd()) {
|
|
1649
|
-
node.forEachChild(find);
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
find(sourceFile);
|
|
1653
|
-
return result;
|
|
1654
|
-
}
|
|
1655
1609
|
function findParentStatementForDisableNextLine(node) {
|
|
1656
1610
|
let result;
|
|
1657
1611
|
function find(node2) {
|
|
@@ -1669,10 +1623,10 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1669
1623
|
const sectionOverrides = {};
|
|
1670
1624
|
const skippedRules = [];
|
|
1671
1625
|
const regex = /@effect-diagnostics(-next-line)?((?:\s[a-zA-Z0-9/]+:(?:off|warning|error|message|suggestion|skip-file))+)?/gm;
|
|
1672
|
-
let
|
|
1673
|
-
while ((
|
|
1674
|
-
const nextLineCaptureGroup =
|
|
1675
|
-
const rulesCaptureGroup =
|
|
1626
|
+
let match2;
|
|
1627
|
+
while ((match2 = regex.exec(sourceFile.text)) !== null) {
|
|
1628
|
+
const nextLineCaptureGroup = match2[1];
|
|
1629
|
+
const rulesCaptureGroup = match2[2];
|
|
1676
1630
|
if (rulesCaptureGroup) {
|
|
1677
1631
|
const trimmedRuleString = rulesCaptureGroup.trim();
|
|
1678
1632
|
if (trimmedRuleString) {
|
|
@@ -1684,19 +1638,19 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1684
1638
|
if (ruleLevel === "skip-file") skippedRules.push(ruleName);
|
|
1685
1639
|
const isOverrideNextLine = nextLineCaptureGroup && nextLineCaptureGroup.trim().toLowerCase() === "-next-line";
|
|
1686
1640
|
if (isOverrideNextLine) {
|
|
1687
|
-
const
|
|
1688
|
-
if (
|
|
1641
|
+
const foundNode = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, match2.index);
|
|
1642
|
+
if (foundNode) {
|
|
1689
1643
|
lineOverrides[ruleName] = lineOverrides[ruleName] || [];
|
|
1690
1644
|
lineOverrides[ruleName].unshift({
|
|
1691
|
-
pos: node.getFullStart(),
|
|
1692
|
-
end: node.end,
|
|
1645
|
+
pos: foundNode.node.getFullStart(),
|
|
1646
|
+
end: foundNode.node.end,
|
|
1693
1647
|
level: ruleLevel
|
|
1694
1648
|
});
|
|
1695
1649
|
}
|
|
1696
1650
|
} else {
|
|
1697
1651
|
sectionOverrides[ruleName] = sectionOverrides[ruleName] || [];
|
|
1698
1652
|
sectionOverrides[ruleName].unshift({
|
|
1699
|
-
pos:
|
|
1653
|
+
pos: match2.index,
|
|
1700
1654
|
level: ruleLevel
|
|
1701
1655
|
});
|
|
1702
1656
|
}
|
|
@@ -1711,7 +1665,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1711
1665
|
message: ts.DiagnosticCategory.Message,
|
|
1712
1666
|
suggestion: ts.DiagnosticCategory.Suggestion
|
|
1713
1667
|
};
|
|
1714
|
-
const execute =
|
|
1668
|
+
const execute = (rule) => gen(function* () {
|
|
1715
1669
|
const diagnostics2 = [];
|
|
1716
1670
|
const codeFixes = [];
|
|
1717
1671
|
const ruleNameLowered = rule.name.toLowerCase();
|
|
@@ -1720,13 +1674,13 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1720
1674
|
if (defaultLevel === "off" && (lineOverrides[ruleNameLowered] || sectionOverrides[ruleNameLowered] || []).length === 0) {
|
|
1721
1675
|
return { diagnostics: diagnostics2, codeFixes };
|
|
1722
1676
|
}
|
|
1723
|
-
const fixByDisableNextLine = (
|
|
1677
|
+
const fixByDisableNextLine = (node) => ({
|
|
1724
1678
|
fixName: rule.name + "_skipNextLine",
|
|
1725
1679
|
description: "Disable " + rule.name + " for this line",
|
|
1726
|
-
apply:
|
|
1680
|
+
apply: flatMap(
|
|
1727
1681
|
service(ChangeTracker),
|
|
1728
|
-
(changeTracker) =>
|
|
1729
|
-
const disableAtNode = findParentStatementForDisableNextLine(
|
|
1682
|
+
(changeTracker) => gen(function* () {
|
|
1683
|
+
const disableAtNode = findParentStatementForDisableNextLine(node);
|
|
1730
1684
|
const { line } = ts.getLineAndCharacterOfPosition(sourceFile, disableAtNode.getStart());
|
|
1731
1685
|
changeTracker.insertCommentBeforeLine(
|
|
1732
1686
|
sourceFile,
|
|
@@ -1740,7 +1694,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1740
1694
|
const fixByDisableEntireFile = {
|
|
1741
1695
|
fixName: rule.name + "_skipFile",
|
|
1742
1696
|
description: "Disable " + rule.name + " for this entire file",
|
|
1743
|
-
apply:
|
|
1697
|
+
apply: flatMap(
|
|
1744
1698
|
service(ChangeTracker),
|
|
1745
1699
|
(changeTracker) => sync(
|
|
1746
1700
|
() => changeTracker.insertText(
|
|
@@ -1754,29 +1708,30 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1754
1708
|
};
|
|
1755
1709
|
const applicableDiagnostics = [];
|
|
1756
1710
|
yield* rule.apply(sourceFile, (entry) => {
|
|
1711
|
+
const range = "getEnd" in entry.location ? { pos: entry.location.getStart(sourceFile), end: entry.location.getEnd() } : entry.location;
|
|
1712
|
+
const node = "getEnd" in entry.location ? entry.location : tsUtils.findNodeAtPositionIncludingTrivia(sourceFile, entry.location.pos);
|
|
1757
1713
|
applicableDiagnostics.push({
|
|
1758
|
-
|
|
1759
|
-
|
|
1714
|
+
range,
|
|
1715
|
+
messageText: entry.messageText,
|
|
1716
|
+
fixes: entry.fixes.concat(node ? [fixByDisableNextLine(node)] : []).concat([fixByDisableEntireFile])
|
|
1760
1717
|
});
|
|
1761
1718
|
});
|
|
1762
1719
|
for (const emitted of applicableDiagnostics.slice(0)) {
|
|
1763
1720
|
let newLevel = defaultLevel;
|
|
1764
1721
|
const lineOverride = (lineOverrides[ruleNameLowered] || []).find(
|
|
1765
|
-
(_) => _.pos < emitted.
|
|
1722
|
+
(_) => _.pos < emitted.range.pos && _.end >= emitted.range.end
|
|
1766
1723
|
);
|
|
1767
1724
|
if (lineOverride) {
|
|
1768
1725
|
newLevel = lineOverride.level;
|
|
1769
1726
|
} else {
|
|
1770
|
-
const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find(
|
|
1771
|
-
(_) => _.pos < emitted.node.getStart(sourceFile)
|
|
1772
|
-
);
|
|
1727
|
+
const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find((_) => _.pos < emitted.range.pos);
|
|
1773
1728
|
if (sectionOverride) newLevel = sectionOverride.level;
|
|
1774
1729
|
}
|
|
1775
1730
|
if (!(newLevel in levelToDiagnosticCategory)) continue;
|
|
1776
1731
|
diagnostics2.push({
|
|
1777
1732
|
file: sourceFile,
|
|
1778
|
-
start: emitted.
|
|
1779
|
-
length: emitted.
|
|
1733
|
+
start: emitted.range.pos,
|
|
1734
|
+
length: emitted.range.end - emitted.range.pos,
|
|
1780
1735
|
messageText: emitted.messageText,
|
|
1781
1736
|
category: levelToDiagnosticCategory[newLevel],
|
|
1782
1737
|
code: rule.code,
|
|
@@ -1786,8 +1741,8 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1786
1741
|
codeFixes.push({
|
|
1787
1742
|
...fix,
|
|
1788
1743
|
code: rule.code,
|
|
1789
|
-
start: emitted.
|
|
1790
|
-
end: emitted.
|
|
1744
|
+
start: emitted.range.pos,
|
|
1745
|
+
end: emitted.range.end
|
|
1791
1746
|
});
|
|
1792
1747
|
}
|
|
1793
1748
|
}
|
|
@@ -1796,28 +1751,97 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1796
1751
|
return { execute };
|
|
1797
1752
|
}
|
|
1798
1753
|
);
|
|
1754
|
+
var cyrb53 = (str, seed = 0) => {
|
|
1755
|
+
let h1 = 3735928559 ^ seed, h2 = 1103547991 ^ seed;
|
|
1756
|
+
for (let i = 0, ch; i < str.length; i++) {
|
|
1757
|
+
ch = str.charCodeAt(i);
|
|
1758
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
1759
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
1760
|
+
}
|
|
1761
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507);
|
|
1762
|
+
h1 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
1763
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
|
|
1764
|
+
h2 ^= Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
1765
|
+
return (h2 >>> 0).toString(16).padStart(8, "0") + (h1 >>> 0).toString(16).padStart(8, "0");
|
|
1766
|
+
};
|
|
1767
|
+
var CodegenNotApplicableError = class {
|
|
1768
|
+
constructor(cause) {
|
|
1769
|
+
this.cause = cause;
|
|
1770
|
+
}
|
|
1771
|
+
_tag = "@effect/language-service/CodegenNotApplicableError";
|
|
1772
|
+
};
|
|
1773
|
+
function createCodegen(definition) {
|
|
1774
|
+
return definition;
|
|
1775
|
+
}
|
|
1776
|
+
var getCodegensForSourceFile = fn("LSP.getApplicableCodegens")(function* (codegens2, sourceFile) {
|
|
1777
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
1778
|
+
const result = [];
|
|
1779
|
+
const regex = /@effect-codegens((?:\s[a-zA-Z0-9]+(?::(?:[a-zA-Z0-9]+))?)+)+/gmid;
|
|
1780
|
+
let match2;
|
|
1781
|
+
while ((match2 = regex.exec(sourceFile.text)) !== null) {
|
|
1782
|
+
const pos = match2.indices?.[0]?.[0];
|
|
1783
|
+
if (!pos) continue;
|
|
1784
|
+
const commentRange = tsUtils.getCommentAtPosition(sourceFile, pos);
|
|
1785
|
+
if (!commentRange) continue;
|
|
1786
|
+
const commentText = sourceFile.text.slice(pos, commentRange.end);
|
|
1787
|
+
const codegenRegex = /(\s+)(\w+)(?::(\w+))?/gmi;
|
|
1788
|
+
let codegenMatch;
|
|
1789
|
+
while ((codegenMatch = codegenRegex.exec(commentText)) !== null) {
|
|
1790
|
+
const whitespace = codegenMatch[1] || "";
|
|
1791
|
+
const codegenName = codegenMatch[2] || "";
|
|
1792
|
+
const codegenHash = codegenMatch[3] || "";
|
|
1793
|
+
const range = {
|
|
1794
|
+
pos: codegenMatch.index + pos + whitespace.length,
|
|
1795
|
+
end: codegenMatch.index + pos + codegenMatch[0].length
|
|
1796
|
+
};
|
|
1797
|
+
const codegen = codegens2.find((codegen2) => codegen2.name === codegenName);
|
|
1798
|
+
if (!codegen) continue;
|
|
1799
|
+
result.push({ codegen, hash: codegenHash, range });
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
return result;
|
|
1803
|
+
});
|
|
1804
|
+
var getEditsForCodegen = fn("LSP.getEditsForCodegen")(function* (codegens2, sourceFile, textRange) {
|
|
1805
|
+
const applicableCodegens = yield* getCodegensForSourceFile(codegens2, sourceFile);
|
|
1806
|
+
const inRangeCodegens = applicableCodegens.filter(
|
|
1807
|
+
(codegen2) => codegen2.range.pos <= textRange.pos && codegen2.range.end >= textRange.end
|
|
1808
|
+
);
|
|
1809
|
+
if (inRangeCodegens.length !== 1) {
|
|
1810
|
+
return yield* fail(new CodegenNotApplicableError("zero or multiple codegens in range"));
|
|
1811
|
+
}
|
|
1812
|
+
const { codegen, range } = inRangeCodegens[0];
|
|
1813
|
+
const edit = yield* codegen.apply(sourceFile, range);
|
|
1814
|
+
const updateHashComment = pipe(
|
|
1815
|
+
service(ChangeTracker),
|
|
1816
|
+
map3((changeTracker) => {
|
|
1817
|
+
changeTracker.deleteRange(sourceFile, range);
|
|
1818
|
+
changeTracker.insertText(sourceFile, range.pos, `${codegen.name}:${edit.hash}`);
|
|
1819
|
+
})
|
|
1820
|
+
);
|
|
1821
|
+
return {
|
|
1822
|
+
...edit,
|
|
1823
|
+
apply: pipe(
|
|
1824
|
+
edit.apply,
|
|
1825
|
+
flatMap(() => updateHashComment)
|
|
1826
|
+
),
|
|
1827
|
+
ignore: updateHashComment
|
|
1828
|
+
};
|
|
1829
|
+
});
|
|
1799
1830
|
|
|
1800
1831
|
// src/completions/contextSelfInClasses.ts
|
|
1801
1832
|
var contextSelfInClasses = createCompletion({
|
|
1802
1833
|
name: "contextSelfInClasses",
|
|
1803
1834
|
apply: fn("contextSelfInClasses")(function* (sourceFile, position) {
|
|
1804
1835
|
const ts = yield* service(TypeScriptApi);
|
|
1805
|
-
const
|
|
1806
|
-
|
|
1807
|
-
);
|
|
1808
|
-
|
|
1809
|
-
const
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
"Context"
|
|
1815
|
-
)
|
|
1816
|
-
);
|
|
1817
|
-
const contextIdentifier = match(contextName, {
|
|
1818
|
-
onNone: () => "Context",
|
|
1819
|
-
onSome: (_) => _.text
|
|
1820
|
-
});
|
|
1836
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
1837
|
+
const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
|
|
1838
|
+
if (!maybeInfos) return [];
|
|
1839
|
+
const { accessedObject, className, replacementSpan } = maybeInfos;
|
|
1840
|
+
const contextIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
1841
|
+
sourceFile,
|
|
1842
|
+
"effect",
|
|
1843
|
+
"Context"
|
|
1844
|
+
) || "Context";
|
|
1821
1845
|
if (contextIdentifier !== accessedObject.text) return [];
|
|
1822
1846
|
const name = className.text;
|
|
1823
1847
|
return [{
|
|
@@ -1832,12 +1856,6 @@ var contextSelfInClasses = createCompletion({
|
|
|
1832
1856
|
|
|
1833
1857
|
// src/core/TypeCheckerApi.ts
|
|
1834
1858
|
var TypeCheckerApi = Tag("TypeChecker");
|
|
1835
|
-
var TypeCheckerApiCache = Tag("TypeCheckerApiCache");
|
|
1836
|
-
function makeTypeCheckerApiCache() {
|
|
1837
|
-
return {
|
|
1838
|
-
expectedAndRealType: /* @__PURE__ */ new WeakMap()
|
|
1839
|
-
};
|
|
1840
|
-
}
|
|
1841
1859
|
var deterministicTypeOrder = gen(function* () {
|
|
1842
1860
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
1843
1861
|
return make2((a, b) => {
|
|
@@ -1936,106 +1954,106 @@ var getInferredReturnType = fn("TypeCheckerApi.getInferredReturnType")(function*
|
|
|
1936
1954
|
}
|
|
1937
1955
|
return returnType;
|
|
1938
1956
|
});
|
|
1939
|
-
var expectedAndRealType =
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
ts.
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
result.push([node, expectedType, node, realType]);
|
|
1957
|
+
var expectedAndRealType = cachedBy(
|
|
1958
|
+
fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
|
|
1959
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
1960
|
+
const ts = yield* service(TypeScriptApi);
|
|
1961
|
+
const result = [];
|
|
1962
|
+
const nodeToVisit = [sourceFile];
|
|
1963
|
+
const appendNodeToVisit = (node) => {
|
|
1964
|
+
nodeToVisit.push(node);
|
|
1965
|
+
return void 0;
|
|
1966
|
+
};
|
|
1967
|
+
while (nodeToVisit.length > 0) {
|
|
1968
|
+
const node = nodeToVisit.shift();
|
|
1969
|
+
if (ts.isVariableDeclaration(node) && node.initializer) {
|
|
1970
|
+
const expectedType = typeChecker.getTypeAtLocation(node.name);
|
|
1971
|
+
const realType = typeChecker.getTypeAtLocation(node.initializer);
|
|
1972
|
+
result.push([node.name, expectedType, node.initializer, realType]);
|
|
1973
|
+
appendNodeToVisit(node.initializer);
|
|
1974
|
+
continue;
|
|
1975
|
+
} else if (ts.isCallExpression(node)) {
|
|
1976
|
+
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
1977
|
+
if (resolvedSignature) {
|
|
1978
|
+
resolvedSignature.getParameters().map((parameter, index) => {
|
|
1979
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
|
|
1980
|
+
const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
|
|
1981
|
+
result.push([
|
|
1982
|
+
node.arguments[index],
|
|
1983
|
+
expectedType,
|
|
1984
|
+
node.arguments[index],
|
|
1985
|
+
realType
|
|
1986
|
+
]);
|
|
1987
|
+
});
|
|
1988
|
+
}
|
|
1989
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
1990
|
+
continue;
|
|
1991
|
+
} else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
1992
|
+
const parent = node.parent;
|
|
1993
|
+
if (ts.isObjectLiteralElement(parent)) {
|
|
1994
|
+
if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
|
|
1995
|
+
const type = typeChecker.getContextualType(parent.parent);
|
|
1996
|
+
if (type) {
|
|
1997
|
+
const symbol3 = typeChecker.getPropertyOfType(type, node.text);
|
|
1998
|
+
if (symbol3) {
|
|
1999
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
|
|
2000
|
+
const realType = typeChecker.getTypeAtLocation(node);
|
|
2001
|
+
result.push([node, expectedType, node, realType]);
|
|
2002
|
+
}
|
|
1986
2003
|
}
|
|
1987
2004
|
}
|
|
1988
2005
|
}
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2006
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2007
|
+
continue;
|
|
2008
|
+
} else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
2009
|
+
const expectedType = typeChecker.getTypeAtLocation(node.left);
|
|
2010
|
+
const realType = typeChecker.getTypeAtLocation(node.right);
|
|
2011
|
+
result.push([node.left, expectedType, node.right, realType]);
|
|
2012
|
+
appendNodeToVisit(node.right);
|
|
2013
|
+
continue;
|
|
2014
|
+
} else if (ts.isReturnStatement(node) && node.expression) {
|
|
2015
|
+
const parentDeclaration = yield* option(getAncestorConvertibleDeclaration(node));
|
|
2016
|
+
if (isSome2(parentDeclaration)) {
|
|
2017
|
+
const expectedType = yield* option(getInferredReturnType(parentDeclaration.value));
|
|
2018
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2019
|
+
if (isSome2(expectedType)) {
|
|
2020
|
+
result.push([node, expectedType.value, node, realType]);
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2024
|
+
continue;
|
|
2025
|
+
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
|
|
2026
|
+
const body = node.body;
|
|
2027
|
+
const expectedType = typeChecker.getContextualType(body);
|
|
2028
|
+
const realType = typeChecker.getTypeAtLocation(body);
|
|
2029
|
+
if (expectedType) {
|
|
2030
|
+
result.push([body, expectedType, body, realType]);
|
|
2031
|
+
}
|
|
2032
|
+
ts.forEachChild(body, appendNodeToVisit);
|
|
2033
|
+
continue;
|
|
2034
|
+
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
|
|
2035
|
+
const body = node.body;
|
|
2036
|
+
const expectedType = yield* option(getInferredReturnType(node));
|
|
2037
|
+
const realType = typeChecker.getTypeAtLocation(body);
|
|
2003
2038
|
if (isSome2(expectedType)) {
|
|
2004
|
-
result.push([
|
|
2039
|
+
result.push([body, expectedType.value, body, realType]);
|
|
2005
2040
|
}
|
|
2041
|
+
ts.forEachChild(body, appendNodeToVisit);
|
|
2042
|
+
continue;
|
|
2043
|
+
} else if (ts.isSatisfiesExpression(node)) {
|
|
2044
|
+
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
2045
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2046
|
+
result.push([node.expression, expectedType, node.expression, realType]);
|
|
2047
|
+
appendNodeToVisit(node.expression);
|
|
2048
|
+
continue;
|
|
2006
2049
|
}
|
|
2007
2050
|
ts.forEachChild(node, appendNodeToVisit);
|
|
2008
|
-
continue;
|
|
2009
|
-
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
|
|
2010
|
-
const body = node.body;
|
|
2011
|
-
const expectedType = typeChecker.getContextualType(body);
|
|
2012
|
-
const realType = typeChecker.getTypeAtLocation(body);
|
|
2013
|
-
if (expectedType) {
|
|
2014
|
-
result.push([body, expectedType, body, realType]);
|
|
2015
|
-
}
|
|
2016
|
-
ts.forEachChild(body, appendNodeToVisit);
|
|
2017
|
-
continue;
|
|
2018
|
-
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
|
|
2019
|
-
const body = node.body;
|
|
2020
|
-
const expectedType = yield* option(getInferredReturnType(node));
|
|
2021
|
-
const realType = typeChecker.getTypeAtLocation(body);
|
|
2022
|
-
if (isSome2(expectedType)) {
|
|
2023
|
-
result.push([body, expectedType.value, body, realType]);
|
|
2024
|
-
}
|
|
2025
|
-
ts.forEachChild(body, appendNodeToVisit);
|
|
2026
|
-
continue;
|
|
2027
|
-
} else if (ts.isSatisfiesExpression(node)) {
|
|
2028
|
-
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
2029
|
-
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2030
|
-
result.push([node.expression, expectedType, node.expression, realType]);
|
|
2031
|
-
appendNodeToVisit(node.expression);
|
|
2032
|
-
continue;
|
|
2033
2051
|
}
|
|
2034
|
-
|
|
2035
|
-
}
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2052
|
+
return result;
|
|
2053
|
+
}),
|
|
2054
|
+
"TypeCheckerApi.expectedAndRealType",
|
|
2055
|
+
(sourceFile) => sourceFile
|
|
2056
|
+
);
|
|
2039
2057
|
var unrollUnionMembers = (type) => {
|
|
2040
2058
|
const result = [];
|
|
2041
2059
|
let toTest = [type];
|
|
@@ -2131,109 +2149,31 @@ var durationInput = createCompletion({
|
|
|
2131
2149
|
(name) => ({
|
|
2132
2150
|
name,
|
|
2133
2151
|
kind: ts.ScriptElementKind.string,
|
|
2134
|
-
insertText: `${"${0}"} ${name}`,
|
|
2135
|
-
isSnippet: true
|
|
2136
|
-
})
|
|
2137
|
-
);
|
|
2138
|
-
}
|
|
2139
|
-
}
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
}
|
|
2144
|
-
return [];
|
|
2145
|
-
})
|
|
2146
|
-
});
|
|
2147
|
-
|
|
2148
|
-
// src/completions/effectDataClasses.ts
|
|
2149
|
-
var effectDataClasses = createCompletion({
|
|
2150
|
-
name: "effectDataClasses",
|
|
2151
|
-
apply: fn("effectDataClasses")(function* (sourceFile, position) {
|
|
2152
|
-
const ts = yield* service(TypeScriptApi);
|
|
2153
|
-
const maybeInfos = yield* option(
|
|
2154
|
-
parseDataForExtendsClassCompletion(sourceFile, position)
|
|
2155
|
-
);
|
|
2156
|
-
if (isNone2(maybeInfos)) return [];
|
|
2157
|
-
const { accessedObject, className, replacementSpan } = maybeInfos.value;
|
|
2158
|
-
const dataName = yield* option(
|
|
2159
|
-
findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
2160
|
-
sourceFile,
|
|
2161
|
-
"effect",
|
|
2162
|
-
"Data"
|
|
2163
|
-
)
|
|
2164
|
-
);
|
|
2165
|
-
const effectDataIdentifier = match(dataName, {
|
|
2166
|
-
onNone: () => "Data",
|
|
2167
|
-
onSome: (_) => _.text
|
|
2168
|
-
});
|
|
2169
|
-
if (effectDataIdentifier !== accessedObject.text) return [];
|
|
2170
|
-
const name = className.text;
|
|
2171
|
-
return [{
|
|
2172
|
-
name: `TaggedError("${name}")`,
|
|
2173
|
-
kind: ts.ScriptElementKind.constElement,
|
|
2174
|
-
insertText: `${effectDataIdentifier}.TaggedError("${name}")<{${"${0}"}}>{}`,
|
|
2175
|
-
replacementSpan,
|
|
2176
|
-
isSnippet: true
|
|
2177
|
-
}, {
|
|
2178
|
-
name: `TaggedClass("${name}")`,
|
|
2179
|
-
kind: ts.ScriptElementKind.constElement,
|
|
2180
|
-
insertText: `${effectDataIdentifier}.TaggedClass("${name}")<{${"${0}"}}>{}`,
|
|
2181
|
-
replacementSpan,
|
|
2182
|
-
isSnippet: true
|
|
2183
|
-
}];
|
|
2184
|
-
})
|
|
2185
|
-
});
|
|
2186
|
-
|
|
2187
|
-
// src/diagnostics/duplicatePackage.ts
|
|
2188
|
-
var checkedPackagesCache = /* @__PURE__ */ new Map();
|
|
2189
|
-
var programResolvedCacheSize = /* @__PURE__ */ new Map();
|
|
2190
|
-
var duplicatePackage = createDiagnostic({
|
|
2191
|
-
name: "duplicatePackage",
|
|
2192
|
-
code: 6,
|
|
2193
|
-
severity: "warning",
|
|
2194
|
-
apply: fn("duplicatePackage.apply")(function* (sourceFile, report) {
|
|
2195
|
-
const program = yield* service(TypeScriptProgram);
|
|
2196
|
-
const options = yield* service(LanguageServicePluginOptions);
|
|
2197
|
-
if (sourceFile.statements.length < 1) return;
|
|
2198
|
-
let resolvedPackages = checkedPackagesCache.get(sourceFile.fileName) || {};
|
|
2199
|
-
const newResolvedModuleSize = hasProperty(program, "resolvedModules") && hasProperty(program.resolvedModules, "size") && isNumber(program.resolvedModules.size) ? program.resolvedModules.size : 0;
|
|
2200
|
-
const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1;
|
|
2201
|
-
if (newResolvedModuleSize !== oldResolvedSize) {
|
|
2202
|
-
const seenPackages = /* @__PURE__ */ new Set();
|
|
2203
|
-
resolvedPackages = {};
|
|
2204
|
-
program.getSourceFiles().map((_) => {
|
|
2205
|
-
const packageInfo = parsePackageContentNameAndVersionFromScope(_);
|
|
2206
|
-
if (!packageInfo) return;
|
|
2207
|
-
const packageNameAndVersion = packageInfo.name + "@" + packageInfo.version;
|
|
2208
|
-
if (seenPackages.has(packageNameAndVersion)) return;
|
|
2209
|
-
seenPackages.add(packageNameAndVersion);
|
|
2210
|
-
if (!(packageInfo.name === "effect" || packageInfo.hasEffectInPeerDependencies)) return;
|
|
2211
|
-
if (options.allowedDuplicatedPackages.indexOf(packageInfo.name) > -1) return;
|
|
2212
|
-
resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {};
|
|
2213
|
-
resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.packageDirectory;
|
|
2214
|
-
});
|
|
2215
|
-
checkedPackagesCache.set(sourceFile.fileName, resolvedPackages);
|
|
2216
|
-
programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize);
|
|
2217
|
-
}
|
|
2218
|
-
for (const packageName of Object.keys(resolvedPackages)) {
|
|
2219
|
-
if (Object.keys(resolvedPackages[packageName]).length > 1) {
|
|
2220
|
-
const versions = Object.keys(resolvedPackages[packageName]);
|
|
2221
|
-
report({
|
|
2222
|
-
node: sourceFile.statements[0],
|
|
2223
|
-
messageText: `Package ${packageName} is referenced multiple times with different versions (${versions.join(", ")}) and may cause unexpected type errors.
|
|
2224
|
-
Cleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.
|
|
2225
|
-
If this is intended set the LSP config "allowedDuplicatedPackages" to ${JSON.stringify(options.allowedDuplicatedPackages.concat([packageName]))}.
|
|
2226
|
-
|
|
2227
|
-
${versions.map((version) => `- found ${version} at ${resolvedPackages[packageName][version]}`).join("\n")}`,
|
|
2228
|
-
fixes: []
|
|
2229
|
-
});
|
|
2152
|
+
insertText: `${"${0}"} ${name}`,
|
|
2153
|
+
isSnippet: true
|
|
2154
|
+
})
|
|
2155
|
+
);
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2230
2160
|
}
|
|
2231
2161
|
}
|
|
2162
|
+
return [];
|
|
2232
2163
|
})
|
|
2233
2164
|
});
|
|
2234
2165
|
|
|
2235
2166
|
// src/core/TypeParser.ts
|
|
2236
2167
|
var TypeParser = Tag("@effect/language-service/TypeParser");
|
|
2168
|
+
var nanoLayer2 = (fa) => gen(function* () {
|
|
2169
|
+
const ts = yield* service(TypeScriptApi);
|
|
2170
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
2171
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
2172
|
+
return yield* pipe(
|
|
2173
|
+
fa,
|
|
2174
|
+
provideService(TypeParser, make3(ts, tsUtils, typeChecker))
|
|
2175
|
+
);
|
|
2176
|
+
});
|
|
2237
2177
|
var TypeParserIssue = class _TypeParserIssue {
|
|
2238
2178
|
_tag = "@effect/language-service/TypeParserIssue";
|
|
2239
2179
|
static issue = fail(new _TypeParserIssue());
|
|
@@ -2241,7 +2181,7 @@ var TypeParserIssue = class _TypeParserIssue {
|
|
|
2241
2181
|
function typeParserIssue(_message, _type, _node) {
|
|
2242
2182
|
return TypeParserIssue.issue;
|
|
2243
2183
|
}
|
|
2244
|
-
function make3(ts, typeChecker) {
|
|
2184
|
+
function make3(ts, tsUtils, typeChecker) {
|
|
2245
2185
|
function covariantTypeArgument(type) {
|
|
2246
2186
|
const signatures = type.getCallSignatures();
|
|
2247
2187
|
if (signatures.length !== 1) {
|
|
@@ -2303,7 +2243,7 @@ function make3(ts, typeChecker) {
|
|
|
2303
2243
|
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
2304
2244
|
return invariantTypeArgument(propertyType);
|
|
2305
2245
|
};
|
|
2306
|
-
const effectVarianceStruct = (type, atLocation) =>
|
|
2246
|
+
const effectVarianceStruct = (type, atLocation) => map3(
|
|
2307
2247
|
all(
|
|
2308
2248
|
varianceStructCovariantType(type, atLocation, "_A"),
|
|
2309
2249
|
varianceStructCovariantType(type, atLocation, "_E"),
|
|
@@ -2311,7 +2251,7 @@ function make3(ts, typeChecker) {
|
|
|
2311
2251
|
),
|
|
2312
2252
|
([A, E, R]) => ({ A, E, R })
|
|
2313
2253
|
);
|
|
2314
|
-
const layerVarianceStruct = (type, atLocation) =>
|
|
2254
|
+
const layerVarianceStruct = (type, atLocation) => map3(
|
|
2315
2255
|
all(
|
|
2316
2256
|
varianceStructContravariantType(type, atLocation, "_ROut"),
|
|
2317
2257
|
varianceStructCovariantType(type, atLocation, "_E"),
|
|
@@ -2399,6 +2339,36 @@ function make3(ts, typeChecker) {
|
|
|
2399
2339
|
"TypeParser.effectSubtype",
|
|
2400
2340
|
(type) => type
|
|
2401
2341
|
);
|
|
2342
|
+
const importedSchemaModule = cachedBy(
|
|
2343
|
+
fn("TypeParser.importedSchemaModule")(function* (node) {
|
|
2344
|
+
const type = typeChecker.getTypeAtLocation(node);
|
|
2345
|
+
const propertySymbol = typeChecker.getPropertyOfType(type, "Class");
|
|
2346
|
+
if (!propertySymbol) {
|
|
2347
|
+
return yield* typeParserIssue("Type has no 'Class' property", type, node);
|
|
2348
|
+
}
|
|
2349
|
+
if (!ts.isExpression(node)) {
|
|
2350
|
+
return yield* typeParserIssue("Node is not an expression", type, node);
|
|
2351
|
+
}
|
|
2352
|
+
return node;
|
|
2353
|
+
}),
|
|
2354
|
+
"TypeParser.importedSchemaModule",
|
|
2355
|
+
(node) => node
|
|
2356
|
+
);
|
|
2357
|
+
const importedContextModule = cachedBy(
|
|
2358
|
+
fn("TypeParser.importedContextModule")(function* (node) {
|
|
2359
|
+
const type = typeChecker.getTypeAtLocation(node);
|
|
2360
|
+
const propertySymbol = typeChecker.getPropertyOfType(type, "Tag");
|
|
2361
|
+
if (!propertySymbol) {
|
|
2362
|
+
return yield* typeParserIssue("Type has no 'Tag' property", type, node);
|
|
2363
|
+
}
|
|
2364
|
+
if (!ts.isExpression(node)) {
|
|
2365
|
+
return yield* typeParserIssue("Node is not an expression", type, node);
|
|
2366
|
+
}
|
|
2367
|
+
return node;
|
|
2368
|
+
}),
|
|
2369
|
+
"TypeParser.importedContextModule",
|
|
2370
|
+
(node) => node
|
|
2371
|
+
);
|
|
2402
2372
|
const importedEffectModule = cachedBy(
|
|
2403
2373
|
fn("TypeParser.importedEffectModule")(function* (node) {
|
|
2404
2374
|
const type = typeChecker.getTypeAtLocation(node);
|
|
@@ -2440,7 +2410,7 @@ function make3(ts, typeChecker) {
|
|
|
2440
2410
|
}
|
|
2441
2411
|
return pipe(
|
|
2442
2412
|
importedEffectModule(propertyAccess.expression),
|
|
2443
|
-
|
|
2413
|
+
map3((effectModule) => ({
|
|
2444
2414
|
node,
|
|
2445
2415
|
effectModule,
|
|
2446
2416
|
generatorFunction,
|
|
@@ -2488,7 +2458,7 @@ function make3(ts, typeChecker) {
|
|
|
2488
2458
|
}
|
|
2489
2459
|
return pipe(
|
|
2490
2460
|
importedEffectModule(propertyAccess.expression),
|
|
2491
|
-
|
|
2461
|
+
map3((effectModule) => ({
|
|
2492
2462
|
node,
|
|
2493
2463
|
effectModule,
|
|
2494
2464
|
generatorFunction,
|
|
@@ -2541,7 +2511,7 @@ function make3(ts, typeChecker) {
|
|
|
2541
2511
|
}
|
|
2542
2512
|
return pipe(
|
|
2543
2513
|
importedEffectModule(propertyAccess.expression),
|
|
2544
|
-
|
|
2514
|
+
map3((effectModule) => ({
|
|
2545
2515
|
node,
|
|
2546
2516
|
generatorFunction,
|
|
2547
2517
|
effectModule,
|
|
@@ -2583,15 +2553,11 @@ function make3(ts, typeChecker) {
|
|
|
2583
2553
|
if (!explicitReturn && !(successType.flags & ts.TypeFlags.VoidLike)) {
|
|
2584
2554
|
replacementNode = pipe(
|
|
2585
2555
|
gen(function* () {
|
|
2586
|
-
const effectIdentifier =
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
onNone: () => "Effect",
|
|
2592
|
-
onSome: (_) => _.text
|
|
2593
|
-
})
|
|
2594
|
-
);
|
|
2556
|
+
const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
2557
|
+
node.getSourceFile(),
|
|
2558
|
+
"effect",
|
|
2559
|
+
"Effect"
|
|
2560
|
+
) || "Effect";
|
|
2595
2561
|
return ts.factory.createCallExpression(
|
|
2596
2562
|
ts.factory.createPropertyAccessExpression(
|
|
2597
2563
|
ts.factory.createIdentifier(effectIdentifier),
|
|
@@ -2619,7 +2585,7 @@ function make3(ts, typeChecker) {
|
|
|
2619
2585
|
"TypeParser.unnecessaryEffectGen",
|
|
2620
2586
|
(node) => node
|
|
2621
2587
|
);
|
|
2622
|
-
const effectSchemaVarianceStruct = (type, atLocation) =>
|
|
2588
|
+
const effectSchemaVarianceStruct = (type, atLocation) => map3(
|
|
2623
2589
|
all(
|
|
2624
2590
|
varianceStructInvariantType(type, atLocation, "_A"),
|
|
2625
2591
|
varianceStructInvariantType(type, atLocation, "_I"),
|
|
@@ -2651,7 +2617,7 @@ function make3(ts, typeChecker) {
|
|
|
2651
2617
|
"TypeParser.effectSchemaType",
|
|
2652
2618
|
(type) => type
|
|
2653
2619
|
);
|
|
2654
|
-
const contextTagVarianceStruct = (type, atLocation) =>
|
|
2620
|
+
const contextTagVarianceStruct = (type, atLocation) => map3(
|
|
2655
2621
|
all(
|
|
2656
2622
|
varianceStructInvariantType(type, atLocation, "_Identifier"),
|
|
2657
2623
|
varianceStructInvariantType(type, atLocation, "_Service")
|
|
@@ -2745,39 +2711,805 @@ function make3(ts, typeChecker) {
|
|
|
2745
2711
|
if (!callbackParameter) {
|
|
2746
2712
|
continue;
|
|
2747
2713
|
}
|
|
2748
|
-
const callbackParameterType = callableType.getTypeParameterAtPosition(0);
|
|
2749
|
-
if (!callbackParameterType) {
|
|
2750
|
-
continue;
|
|
2714
|
+
const callbackParameterType = callableType.getTypeParameterAtPosition(0);
|
|
2715
|
+
if (!callbackParameterType) {
|
|
2716
|
+
continue;
|
|
2717
|
+
}
|
|
2718
|
+
return succeed({
|
|
2719
|
+
type: callbackParameterType
|
|
2720
|
+
});
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
return typeParserIssue("not a promise", type, atLocation);
|
|
2724
|
+
},
|
|
2725
|
+
"TypeParser.promiseLike",
|
|
2726
|
+
(type) => type
|
|
2727
|
+
);
|
|
2728
|
+
const extendsSchemaClass = cachedBy(
|
|
2729
|
+
fn("TypeParser.extendsSchemaClass")(function* (atLocation) {
|
|
2730
|
+
if (!atLocation.name) {
|
|
2731
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
2732
|
+
}
|
|
2733
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
2734
|
+
if (!heritageClauses) {
|
|
2735
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
2736
|
+
}
|
|
2737
|
+
for (const heritageClause of heritageClauses) {
|
|
2738
|
+
for (const typeX of heritageClause.types) {
|
|
2739
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2740
|
+
const expression = typeX.expression;
|
|
2741
|
+
if (ts.isCallExpression(expression)) {
|
|
2742
|
+
const schemaCall = expression.expression;
|
|
2743
|
+
if (ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {
|
|
2744
|
+
const selfTypeNode = schemaCall.typeArguments[0];
|
|
2745
|
+
const schemaIdentifier = schemaCall.expression;
|
|
2746
|
+
if (ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) && schemaIdentifier.name.text === "Class") {
|
|
2747
|
+
const parsedSchemaModule = yield* pipe(
|
|
2748
|
+
importedSchemaModule(schemaIdentifier.expression),
|
|
2749
|
+
option
|
|
2750
|
+
);
|
|
2751
|
+
if (isSome2(parsedSchemaModule)) {
|
|
2752
|
+
return {
|
|
2753
|
+
className: atLocation.name,
|
|
2754
|
+
selfTypeNode,
|
|
2755
|
+
Schema: parsedSchemaModule.value
|
|
2756
|
+
};
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
return yield* typeParserIssue("Class does not extend Schema.Class", void 0, atLocation);
|
|
2765
|
+
}),
|
|
2766
|
+
"TypeParser.extendsSchemaClass",
|
|
2767
|
+
(atLocation) => atLocation
|
|
2768
|
+
);
|
|
2769
|
+
const extendsSchemaTaggedClass = cachedBy(
|
|
2770
|
+
fn("TypeParser.extendsSchemaTaggedClass")(function* (atLocation) {
|
|
2771
|
+
if (!atLocation.name) {
|
|
2772
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
2773
|
+
}
|
|
2774
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
2775
|
+
if (!heritageClauses) {
|
|
2776
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
2777
|
+
}
|
|
2778
|
+
for (const heritageClause of heritageClauses) {
|
|
2779
|
+
for (const typeX of heritageClause.types) {
|
|
2780
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2781
|
+
const expression = typeX.expression;
|
|
2782
|
+
if (ts.isCallExpression(expression)) {
|
|
2783
|
+
const tagCall = expression.expression;
|
|
2784
|
+
if (ts.isCallExpression(tagCall)) {
|
|
2785
|
+
const schemaCall = tagCall.expression;
|
|
2786
|
+
if (ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {
|
|
2787
|
+
const selfTypeNode = schemaCall.typeArguments[0];
|
|
2788
|
+
const schemaIdentifier = schemaCall.expression;
|
|
2789
|
+
if (ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) && schemaIdentifier.name.text === "TaggedClass") {
|
|
2790
|
+
const parsedSchemaModule = yield* pipe(
|
|
2791
|
+
importedSchemaModule(schemaIdentifier.expression),
|
|
2792
|
+
option
|
|
2793
|
+
);
|
|
2794
|
+
if (isSome2(parsedSchemaModule)) {
|
|
2795
|
+
return {
|
|
2796
|
+
className: atLocation.name,
|
|
2797
|
+
selfTypeNode,
|
|
2798
|
+
Schema: parsedSchemaModule.value
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
return yield* typeParserIssue("Class does not extend Schema.TaggedClass", void 0, atLocation);
|
|
2809
|
+
}),
|
|
2810
|
+
"TypeParser.extendsSchemaTaggedClass",
|
|
2811
|
+
(atLocation) => atLocation
|
|
2812
|
+
);
|
|
2813
|
+
const extendsSchemaTaggedError = cachedBy(
|
|
2814
|
+
fn("TypeParser.extendsSchemaTaggedError")(function* (atLocation) {
|
|
2815
|
+
if (!atLocation.name) {
|
|
2816
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
2817
|
+
}
|
|
2818
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
2819
|
+
if (!heritageClauses) {
|
|
2820
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
2821
|
+
}
|
|
2822
|
+
for (const heritageClause of heritageClauses) {
|
|
2823
|
+
for (const typeX of heritageClause.types) {
|
|
2824
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2825
|
+
const expression = typeX.expression;
|
|
2826
|
+
if (ts.isCallExpression(expression)) {
|
|
2827
|
+
const tagCall = expression.expression;
|
|
2828
|
+
if (ts.isCallExpression(tagCall)) {
|
|
2829
|
+
const schemaCall = tagCall.expression;
|
|
2830
|
+
if (ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {
|
|
2831
|
+
const selfTypeNode = schemaCall.typeArguments[0];
|
|
2832
|
+
const schemaIdentifier = schemaCall.expression;
|
|
2833
|
+
if (ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) && schemaIdentifier.name.text === "TaggedError") {
|
|
2834
|
+
const parsedSchemaModule = yield* pipe(
|
|
2835
|
+
importedSchemaModule(schemaIdentifier.expression),
|
|
2836
|
+
option
|
|
2837
|
+
);
|
|
2838
|
+
if (isSome2(parsedSchemaModule)) {
|
|
2839
|
+
return {
|
|
2840
|
+
className: atLocation.name,
|
|
2841
|
+
selfTypeNode,
|
|
2842
|
+
Schema: parsedSchemaModule.value
|
|
2843
|
+
};
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
return yield* typeParserIssue("Class does not extend Schema.TaggedError", void 0, atLocation);
|
|
2853
|
+
}),
|
|
2854
|
+
"TypeParser.extendsSchemaTaggedError",
|
|
2855
|
+
(atLocation) => atLocation
|
|
2856
|
+
);
|
|
2857
|
+
const extendsSchemaTaggedRequest = cachedBy(
|
|
2858
|
+
fn("TypeParser.extendsSchemaTaggedRequest")(function* (atLocation) {
|
|
2859
|
+
if (!atLocation.name) {
|
|
2860
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
2861
|
+
}
|
|
2862
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
2863
|
+
if (!heritageClauses) {
|
|
2864
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
2865
|
+
}
|
|
2866
|
+
for (const heritageClause of heritageClauses) {
|
|
2867
|
+
for (const typeX of heritageClause.types) {
|
|
2868
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2869
|
+
const expression = typeX.expression;
|
|
2870
|
+
if (ts.isCallExpression(expression)) {
|
|
2871
|
+
const tagCall = expression.expression;
|
|
2872
|
+
if (ts.isCallExpression(tagCall)) {
|
|
2873
|
+
const schemaCall = tagCall.expression;
|
|
2874
|
+
if (ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {
|
|
2875
|
+
const selfTypeNode = schemaCall.typeArguments[0];
|
|
2876
|
+
const schemaIdentifier = schemaCall.expression;
|
|
2877
|
+
if (ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) && schemaIdentifier.name.text === "TaggedRequest") {
|
|
2878
|
+
const parsedSchemaModule = yield* pipe(
|
|
2879
|
+
importedSchemaModule(schemaIdentifier.expression),
|
|
2880
|
+
option
|
|
2881
|
+
);
|
|
2882
|
+
if (isSome2(parsedSchemaModule)) {
|
|
2883
|
+
return {
|
|
2884
|
+
className: atLocation.name,
|
|
2885
|
+
selfTypeNode,
|
|
2886
|
+
Schema: parsedSchemaModule.value
|
|
2887
|
+
};
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
return yield* typeParserIssue("Class does not extend Schema.TaggedRequest", void 0, atLocation);
|
|
2897
|
+
}),
|
|
2898
|
+
"TypeParser.extendsSchemaTaggedRequest",
|
|
2899
|
+
(atLocation) => atLocation
|
|
2900
|
+
);
|
|
2901
|
+
const extendsContextTag = cachedBy(
|
|
2902
|
+
fn("TypeParser.extendsContextTag")(function* (atLocation) {
|
|
2903
|
+
if (!atLocation.name) {
|
|
2904
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
2905
|
+
}
|
|
2906
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
2907
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
2908
|
+
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
2909
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
2910
|
+
if (!heritageClauses) {
|
|
2911
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
2912
|
+
}
|
|
2913
|
+
for (const heritageClause of heritageClauses) {
|
|
2914
|
+
for (const typeX of heritageClause.types) {
|
|
2915
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2916
|
+
const wholeCall = typeX.expression;
|
|
2917
|
+
if (ts.isCallExpression(wholeCall)) {
|
|
2918
|
+
const contextTagCall = wholeCall.expression;
|
|
2919
|
+
if (ts.isCallExpression(contextTagCall) && wholeCall.typeArguments && wholeCall.typeArguments.length > 0) {
|
|
2920
|
+
const contextTagIdentifier = contextTagCall.expression;
|
|
2921
|
+
const selfTypeNode = wholeCall.typeArguments[0];
|
|
2922
|
+
if (ts.isPropertyAccessExpression(contextTagIdentifier) && ts.isIdentifier(contextTagIdentifier.name) && contextTagIdentifier.name.text === "Tag") {
|
|
2923
|
+
const parsedContextModule = yield* pipe(
|
|
2924
|
+
importedContextModule(contextTagIdentifier.expression),
|
|
2925
|
+
option
|
|
2926
|
+
);
|
|
2927
|
+
if (isSome2(parsedContextModule)) {
|
|
2928
|
+
const tagType = yield* contextTag(type, atLocation);
|
|
2929
|
+
return {
|
|
2930
|
+
className: atLocation.name,
|
|
2931
|
+
selfTypeNode,
|
|
2932
|
+
args: contextTagCall.arguments,
|
|
2933
|
+
Identifier: tagType.Identifier,
|
|
2934
|
+
Tag: parsedContextModule.value
|
|
2935
|
+
};
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
return yield* typeParserIssue("Class does not extend Context.Tag", void 0, atLocation);
|
|
2944
|
+
}),
|
|
2945
|
+
"TypeParser.extendsContextTag",
|
|
2946
|
+
(atLocation) => atLocation
|
|
2947
|
+
);
|
|
2948
|
+
const extendsEffectService = cachedBy(
|
|
2949
|
+
fn("TypeParser.extendsEffectService")(function* (atLocation) {
|
|
2950
|
+
if (!atLocation.name) {
|
|
2951
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
2952
|
+
}
|
|
2953
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
2954
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
2955
|
+
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
2956
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
2957
|
+
if (!heritageClauses) {
|
|
2958
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
2959
|
+
}
|
|
2960
|
+
for (const heritageClause of heritageClauses) {
|
|
2961
|
+
for (const typeX of heritageClause.types) {
|
|
2962
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2963
|
+
const wholeCall = typeX.expression;
|
|
2964
|
+
if (ts.isCallExpression(wholeCall)) {
|
|
2965
|
+
const effectServiceCall = wholeCall.expression;
|
|
2966
|
+
if (ts.isCallExpression(effectServiceCall) && effectServiceCall.typeArguments && effectServiceCall.typeArguments.length > 0) {
|
|
2967
|
+
const effectServiceIdentifier = effectServiceCall.expression;
|
|
2968
|
+
const selfTypeNode = effectServiceCall.typeArguments[0];
|
|
2969
|
+
if (ts.isPropertyAccessExpression(effectServiceIdentifier) && ts.isIdentifier(effectServiceIdentifier.name) && effectServiceIdentifier.name.text === "Service") {
|
|
2970
|
+
const parsedContextTag = yield* pipe(
|
|
2971
|
+
importedEffectModule(effectServiceIdentifier.expression),
|
|
2972
|
+
flatMap(() => contextTag(type, atLocation)),
|
|
2973
|
+
option
|
|
2974
|
+
);
|
|
2975
|
+
if (isSome2(parsedContextTag)) {
|
|
2976
|
+
let accessors2 = void 0;
|
|
2977
|
+
if (wholeCall.arguments.length >= 2) {
|
|
2978
|
+
const args2 = wholeCall.arguments[1];
|
|
2979
|
+
if (ts.isObjectLiteralExpression(args2)) {
|
|
2980
|
+
for (const property of args2.properties) {
|
|
2981
|
+
if (ts.isPropertyAssignment(property) && property.name && ts.isIdentifier(property.name) && property.name.text === "accessors" && property.initializer && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
2982
|
+
accessors2 = true;
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
return {
|
|
2988
|
+
...parsedContextTag.value,
|
|
2989
|
+
className: atLocation.name,
|
|
2990
|
+
selfTypeNode,
|
|
2991
|
+
args: wholeCall.arguments,
|
|
2992
|
+
accessors: accessors2
|
|
2993
|
+
};
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
return yield* typeParserIssue("Class does not extend Effect.Service", void 0, atLocation);
|
|
3002
|
+
}),
|
|
3003
|
+
"TypeParser.extendsEffectService",
|
|
3004
|
+
(atLocation) => atLocation
|
|
3005
|
+
);
|
|
3006
|
+
return {
|
|
3007
|
+
effectType,
|
|
3008
|
+
strictEffectType,
|
|
3009
|
+
layerType,
|
|
3010
|
+
fiberType,
|
|
3011
|
+
effectSubtype,
|
|
3012
|
+
importedEffectModule,
|
|
3013
|
+
effectGen,
|
|
3014
|
+
effectFnUntracedGen,
|
|
3015
|
+
effectFnGen,
|
|
3016
|
+
unnecessaryEffectGen: unnecessaryEffectGen2,
|
|
3017
|
+
effectSchemaType,
|
|
3018
|
+
contextTag,
|
|
3019
|
+
pipeableType,
|
|
3020
|
+
pipeCall,
|
|
3021
|
+
scopeType,
|
|
3022
|
+
promiseLike,
|
|
3023
|
+
extendsEffectService,
|
|
3024
|
+
extendsContextTag,
|
|
3025
|
+
extendsSchemaClass,
|
|
3026
|
+
extendsSchemaTaggedClass,
|
|
3027
|
+
extendsSchemaTaggedError,
|
|
3028
|
+
extendsSchemaTaggedRequest
|
|
3029
|
+
};
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
// src/refactors/writeTagClassAccessors.ts
|
|
3033
|
+
var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, service2, className, atLocation, involvedMembers) {
|
|
3034
|
+
const ts = yield* service(TypeScriptApi);
|
|
3035
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3036
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3037
|
+
const typeParser = yield* service(TypeParser);
|
|
3038
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
3039
|
+
const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.getEnd() - 1;
|
|
3040
|
+
const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3041
|
+
sourceFile,
|
|
3042
|
+
"effect",
|
|
3043
|
+
"Effect"
|
|
3044
|
+
) || "Effect";
|
|
3045
|
+
const createFunctionProperty = (className2, propertyName, type, forceAny) => {
|
|
3046
|
+
const arrowBody = ts.factory.createCallExpression(
|
|
3047
|
+
ts.factory.createPropertyAccessExpression(
|
|
3048
|
+
ts.factory.createIdentifier(effectIdentifier),
|
|
3049
|
+
"andThen"
|
|
3050
|
+
),
|
|
3051
|
+
void 0,
|
|
3052
|
+
[
|
|
3053
|
+
ts.factory.createIdentifier(className2.text),
|
|
3054
|
+
ts.factory.createArrowFunction(
|
|
3055
|
+
void 0,
|
|
3056
|
+
void 0,
|
|
3057
|
+
[ts.factory.createParameterDeclaration(
|
|
3058
|
+
void 0,
|
|
3059
|
+
void 0,
|
|
3060
|
+
"_",
|
|
3061
|
+
void 0,
|
|
3062
|
+
forceAny ? ts.factory.createTypeReferenceNode("any") : void 0
|
|
3063
|
+
)],
|
|
3064
|
+
void 0,
|
|
3065
|
+
void 0,
|
|
3066
|
+
ts.factory.createCallExpression(
|
|
3067
|
+
ts.factory.createPropertyAccessExpression(
|
|
3068
|
+
ts.factory.createIdentifier("_"),
|
|
3069
|
+
propertyName
|
|
3070
|
+
),
|
|
3071
|
+
void 0,
|
|
3072
|
+
[
|
|
3073
|
+
ts.factory.createSpreadElement(ts.factory.createIdentifier("args"))
|
|
3074
|
+
]
|
|
3075
|
+
)
|
|
3076
|
+
)
|
|
3077
|
+
]
|
|
3078
|
+
);
|
|
3079
|
+
return ts.factory.createPropertyDeclaration(
|
|
3080
|
+
[ts.factory.createModifier(ts.SyntaxKind.StaticKeyword)],
|
|
3081
|
+
propertyName,
|
|
3082
|
+
void 0,
|
|
3083
|
+
type,
|
|
3084
|
+
ts.factory.createArrowFunction(
|
|
3085
|
+
void 0,
|
|
3086
|
+
void 0,
|
|
3087
|
+
[ts.factory.createParameterDeclaration(
|
|
3088
|
+
void 0,
|
|
3089
|
+
ts.factory.createToken(ts.SyntaxKind.DotDotDotToken),
|
|
3090
|
+
"args",
|
|
3091
|
+
void 0,
|
|
3092
|
+
forceAny ? ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode("any")) : void 0
|
|
3093
|
+
)],
|
|
3094
|
+
void 0,
|
|
3095
|
+
void 0,
|
|
3096
|
+
forceAny ? ts.factory.createAsExpression(arrowBody, ts.factory.createTypeReferenceNode("any")) : arrowBody
|
|
3097
|
+
)
|
|
3098
|
+
);
|
|
3099
|
+
};
|
|
3100
|
+
const generateReturnType = (type, atLocation2, className2) => pipe(
|
|
3101
|
+
typeParser.effectType(type, atLocation2),
|
|
3102
|
+
flatMap((returnedEffect) => {
|
|
3103
|
+
const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(className2.text) : ts.factory.createUnionTypeNode(
|
|
3104
|
+
[
|
|
3105
|
+
ts.factory.createTypeReferenceNode(className2.text),
|
|
3106
|
+
typeChecker.typeToTypeNode(returnedEffect.R, atLocation2, ts.NodeBuilderFlags.NoTruncation)
|
|
3107
|
+
]
|
|
3108
|
+
);
|
|
3109
|
+
const successType = typeChecker.typeToTypeNode(
|
|
3110
|
+
returnedEffect.A,
|
|
3111
|
+
atLocation2,
|
|
3112
|
+
ts.NodeBuilderFlags.NoTruncation
|
|
3113
|
+
);
|
|
3114
|
+
if (!successType) return fail("error generating success type");
|
|
3115
|
+
const failureType = typeChecker.typeToTypeNode(
|
|
3116
|
+
returnedEffect.E,
|
|
3117
|
+
atLocation2,
|
|
3118
|
+
ts.NodeBuilderFlags.NoTruncation
|
|
3119
|
+
);
|
|
3120
|
+
if (!failureType) return fail("error generating failure type");
|
|
3121
|
+
const typeNode = ts.factory.createTypeReferenceNode(
|
|
3122
|
+
ts.factory.createQualifiedName(
|
|
3123
|
+
ts.factory.createIdentifier(effectIdentifier),
|
|
3124
|
+
ts.factory.createIdentifier("Effect")
|
|
3125
|
+
),
|
|
3126
|
+
[successType, failureType, contextType]
|
|
3127
|
+
);
|
|
3128
|
+
return succeed(typeNode);
|
|
3129
|
+
}),
|
|
3130
|
+
orElse2(
|
|
3131
|
+
() => pipe(
|
|
3132
|
+
typeParser.promiseLike(type, atLocation2),
|
|
3133
|
+
flatMap(({ type: type2 }) => {
|
|
3134
|
+
const successType = typeChecker.typeToTypeNode(
|
|
3135
|
+
type2,
|
|
3136
|
+
atLocation2,
|
|
3137
|
+
ts.NodeBuilderFlags.NoTruncation
|
|
3138
|
+
);
|
|
3139
|
+
if (!successType) return fail("error generating success type");
|
|
3140
|
+
return succeed(ts.factory.createTypeReferenceNode(
|
|
3141
|
+
ts.factory.createQualifiedName(
|
|
3142
|
+
ts.factory.createIdentifier(effectIdentifier),
|
|
3143
|
+
ts.factory.createIdentifier("Effect")
|
|
3144
|
+
),
|
|
3145
|
+
[
|
|
3146
|
+
successType,
|
|
3147
|
+
ts.factory.createTypeReferenceNode(
|
|
3148
|
+
ts.factory.createQualifiedName(
|
|
3149
|
+
ts.factory.createIdentifier("Cause"),
|
|
3150
|
+
ts.factory.createIdentifier("UnknownException")
|
|
3151
|
+
)
|
|
3152
|
+
),
|
|
3153
|
+
ts.factory.createTypeReferenceNode(className2.text)
|
|
3154
|
+
]
|
|
3155
|
+
));
|
|
3156
|
+
})
|
|
3157
|
+
)
|
|
3158
|
+
),
|
|
3159
|
+
orElse2(() => {
|
|
3160
|
+
const successType = typeChecker.typeToTypeNode(type, atLocation2, ts.NodeBuilderFlags.NoTruncation);
|
|
3161
|
+
if (!successType) return fail("error generating success type");
|
|
3162
|
+
const typeNode = ts.factory.createTypeReferenceNode(
|
|
3163
|
+
ts.factory.createQualifiedName(
|
|
3164
|
+
ts.factory.createIdentifier(effectIdentifier),
|
|
3165
|
+
ts.factory.createIdentifier("Effect")
|
|
3166
|
+
),
|
|
3167
|
+
[
|
|
3168
|
+
successType,
|
|
3169
|
+
ts.factory.createTypeReferenceNode("never"),
|
|
3170
|
+
ts.factory.createTypeReferenceNode(className2.text)
|
|
3171
|
+
]
|
|
3172
|
+
);
|
|
3173
|
+
return succeed(typeNode);
|
|
3174
|
+
})
|
|
3175
|
+
);
|
|
3176
|
+
const proxySignature = (signature, atLocation2, className2) => gen(function* () {
|
|
3177
|
+
const signatureDeclaration = typeChecker.signatureToSignatureDeclaration(
|
|
3178
|
+
signature,
|
|
3179
|
+
ts.SyntaxKind.FunctionType,
|
|
3180
|
+
atLocation2,
|
|
3181
|
+
ts.NodeBuilderFlags.NoTruncation
|
|
3182
|
+
);
|
|
3183
|
+
if (!signatureDeclaration) return yield* fail("error generating signature");
|
|
3184
|
+
const returnType = yield* generateReturnType(signature.getReturnType(), atLocation2, className2);
|
|
3185
|
+
return ts.factory.createFunctionTypeNode(
|
|
3186
|
+
signatureDeclaration.typeParameters,
|
|
3187
|
+
signatureDeclaration.parameters,
|
|
3188
|
+
returnType
|
|
3189
|
+
);
|
|
3190
|
+
});
|
|
3191
|
+
for (const { property, propertyType } of involvedMembers) {
|
|
3192
|
+
const callSignatures = [];
|
|
3193
|
+
let propertyDeclaration = void 0;
|
|
3194
|
+
for (const signature of propertyType.getCallSignatures()) {
|
|
3195
|
+
yield* pipe(
|
|
3196
|
+
proxySignature(signature, atLocation, className),
|
|
3197
|
+
map3((sig) => {
|
|
3198
|
+
callSignatures.push(sig);
|
|
3199
|
+
}),
|
|
3200
|
+
ignore
|
|
3201
|
+
);
|
|
3202
|
+
}
|
|
3203
|
+
const allSignatures = ts.factory.createIntersectionTypeNode(callSignatures);
|
|
3204
|
+
const type = tsUtils.simplifyTypeNode(allSignatures);
|
|
3205
|
+
propertyDeclaration = createFunctionProperty(className, property.getName(), type, callSignatures.length > 1);
|
|
3206
|
+
const oldProperty = atLocation.members.filter(ts.isPropertyDeclaration).find((p) => {
|
|
3207
|
+
const symbol3 = typeChecker.getSymbolAtLocation(p.name);
|
|
3208
|
+
return symbol3?.getName() === property.getName();
|
|
3209
|
+
});
|
|
3210
|
+
if (oldProperty) {
|
|
3211
|
+
changeTracker.deleteRange(sourceFile, {
|
|
3212
|
+
pos: oldProperty.getStart(sourceFile),
|
|
3213
|
+
end: oldProperty.getEnd()
|
|
3214
|
+
});
|
|
3215
|
+
changeTracker.insertNodeAt(sourceFile, oldProperty.getStart(sourceFile), propertyDeclaration);
|
|
3216
|
+
} else {
|
|
3217
|
+
changeTracker.insertNodeAt(sourceFile, insertLocation, propertyDeclaration, { suffix: "\n" });
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
});
|
|
3221
|
+
var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
|
|
3222
|
+
const ts = yield* service(TypeScriptApi);
|
|
3223
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3224
|
+
const typeParser = yield* service(TypeParser);
|
|
3225
|
+
if (!ts.isClassDeclaration(node)) return yield* fail("not a class declaration");
|
|
3226
|
+
const { Service, accessors: accessors2, className } = yield* pipe(
|
|
3227
|
+
typeParser.extendsEffectService(node),
|
|
3228
|
+
orElse2(() => fail("not a class extending Effect.Service call"))
|
|
3229
|
+
);
|
|
3230
|
+
if (accessors2 !== true) return yield* fail("accessors are not enabled in the Effect.Service call");
|
|
3231
|
+
const involvedMembers = [];
|
|
3232
|
+
for (const property of typeChecker.getPropertiesOfType(Service)) {
|
|
3233
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, node);
|
|
3234
|
+
const callSignatures = propertyType.getCallSignatures();
|
|
3235
|
+
if (callSignatures.length > 0) {
|
|
3236
|
+
const withTypeParameters = callSignatures.filter((_) => _.typeParameters && _.typeParameters.length > 0);
|
|
3237
|
+
if (callSignatures.length > 1 || withTypeParameters.length > 0) involvedMembers.push({ property, propertyType });
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
const hash2 = involvedMembers.map(({ property, propertyType }) => {
|
|
3241
|
+
return property.getName() + ": " + typeChecker.typeToString(propertyType);
|
|
3242
|
+
}).concat([className.text]).join("\n");
|
|
3243
|
+
return { Service, className, atLocation: node, hash: cyrb53(hash2), involvedMembers };
|
|
3244
|
+
});
|
|
3245
|
+
var writeTagClassAccessors = createRefactor({
|
|
3246
|
+
name: "writeTagClassAccessors",
|
|
3247
|
+
description: "Implement accessors methods with generics or multiple signatures",
|
|
3248
|
+
apply: fn("writeTagClassAccessors.apply")(function* (sourceFile, textRange) {
|
|
3249
|
+
const ts = yield* service(TypeScriptApi);
|
|
3250
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3251
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3252
|
+
const typeParser = yield* service(TypeParser);
|
|
3253
|
+
const parseNode = (node) => pipe(
|
|
3254
|
+
parse2(node),
|
|
3255
|
+
map3(({ Service, atLocation, className, involvedMembers }) => ({
|
|
3256
|
+
kind: "refactor.rewrite.effect.writeTagClassAccessors",
|
|
3257
|
+
description: "Implement Service accessors",
|
|
3258
|
+
apply: pipe(
|
|
3259
|
+
generate(sourceFile, Service, className, atLocation, involvedMembers),
|
|
3260
|
+
provideService(TypeScriptUtils, tsUtils),
|
|
3261
|
+
provideService(TypeParser, typeParser),
|
|
3262
|
+
provideService(TypeCheckerApi, typeChecker),
|
|
3263
|
+
provideService(TypeScriptApi, ts)
|
|
3264
|
+
)
|
|
3265
|
+
}))
|
|
3266
|
+
);
|
|
3267
|
+
const parentNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange);
|
|
3268
|
+
return yield* pipe(
|
|
3269
|
+
firstSuccessOf(parentNodes.map(parseNode)),
|
|
3270
|
+
orElse2(() => fail(new RefactorNotApplicableError()))
|
|
3271
|
+
);
|
|
3272
|
+
})
|
|
3273
|
+
});
|
|
3274
|
+
|
|
3275
|
+
// src/codegens/accessors.ts
|
|
3276
|
+
var accessors = createCodegen({
|
|
3277
|
+
name: "accessors",
|
|
3278
|
+
apply: fn("accessors.apply")(function* (sourceFile, textRange) {
|
|
3279
|
+
const ts = yield* service(TypeScriptApi);
|
|
3280
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3281
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3282
|
+
const typeParser = yield* service(TypeParser);
|
|
3283
|
+
const nodeAndCommentRange = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, textRange.pos);
|
|
3284
|
+
if (!nodeAndCommentRange) return yield* fail(new CodegenNotApplicableError("no node and comment range"));
|
|
3285
|
+
return yield* pipe(
|
|
3286
|
+
parse2(nodeAndCommentRange.node),
|
|
3287
|
+
map3(
|
|
3288
|
+
(_) => ({
|
|
3289
|
+
hash: _.hash,
|
|
3290
|
+
description: "Generate accessors for the service",
|
|
3291
|
+
apply: pipe(
|
|
3292
|
+
generate(sourceFile, _.Service, _.className, _.atLocation, _.involvedMembers),
|
|
3293
|
+
provideService(TypeScriptApi, ts),
|
|
3294
|
+
provideService(TypeScriptUtils, tsUtils),
|
|
3295
|
+
provideService(TypeCheckerApi, typeChecker),
|
|
3296
|
+
provideService(TypeParser, typeParser)
|
|
3297
|
+
)
|
|
3298
|
+
})
|
|
3299
|
+
),
|
|
3300
|
+
orElse2((cause) => fail(new CodegenNotApplicableError(cause)))
|
|
3301
|
+
);
|
|
3302
|
+
})
|
|
3303
|
+
});
|
|
3304
|
+
|
|
3305
|
+
// src/codegens.ts
|
|
3306
|
+
var codegens = [accessors];
|
|
3307
|
+
|
|
3308
|
+
// src/completions/effectCodegensComment.ts
|
|
3309
|
+
var effectCodegensComment = createCompletion({
|
|
3310
|
+
name: "effectCodegensComment",
|
|
3311
|
+
apply: fn("effectCodegensComment")(function* (sourceFile, position) {
|
|
3312
|
+
const ts = yield* service(TypeScriptApi);
|
|
3313
|
+
const sourceText = sourceFile.text;
|
|
3314
|
+
const match2 = /(\/\/|\/\*(?:\*?))\s*(@)\s*$/id.exec(sourceText.substring(0, position));
|
|
3315
|
+
if (match2 && match2.indices) {
|
|
3316
|
+
const lastIndex = match2.indices[2][0];
|
|
3317
|
+
const replacementSpan = {
|
|
3318
|
+
start: lastIndex,
|
|
3319
|
+
length: Math.max(0, position - lastIndex)
|
|
3320
|
+
};
|
|
3321
|
+
const allCodegens = sort(Object.values(codegens).map((codegen) => codegen.name), string2).join(",");
|
|
3322
|
+
const enableSnippet = "${1|" + allCodegens + "|} $0";
|
|
3323
|
+
return [{
|
|
3324
|
+
name: `@effect-codegens`,
|
|
3325
|
+
kind: ts.ScriptElementKind.string,
|
|
3326
|
+
insertText: "@effect-codegens " + enableSnippet,
|
|
3327
|
+
isSnippet: true,
|
|
3328
|
+
replacementSpan
|
|
3329
|
+
}];
|
|
3330
|
+
}
|
|
3331
|
+
return [];
|
|
3332
|
+
})
|
|
3333
|
+
});
|
|
3334
|
+
|
|
3335
|
+
// src/completions/effectDataClasses.ts
|
|
3336
|
+
var effectDataClasses = createCompletion({
|
|
3337
|
+
name: "effectDataClasses",
|
|
3338
|
+
apply: fn("effectDataClasses")(function* (sourceFile, position) {
|
|
3339
|
+
const ts = yield* service(TypeScriptApi);
|
|
3340
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3341
|
+
const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
|
|
3342
|
+
if (!maybeInfos) return [];
|
|
3343
|
+
const { accessedObject, className, replacementSpan } = maybeInfos;
|
|
3344
|
+
const effectDataIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3345
|
+
sourceFile,
|
|
3346
|
+
"effect",
|
|
3347
|
+
"Data"
|
|
3348
|
+
) || "Data";
|
|
3349
|
+
if (effectDataIdentifier !== accessedObject.text) return [];
|
|
3350
|
+
const name = className.text;
|
|
3351
|
+
return [{
|
|
3352
|
+
name: `TaggedError("${name}")`,
|
|
3353
|
+
kind: ts.ScriptElementKind.constElement,
|
|
3354
|
+
insertText: `${effectDataIdentifier}.TaggedError("${name}")<{${"${0}"}}>{}`,
|
|
3355
|
+
replacementSpan,
|
|
3356
|
+
isSnippet: true
|
|
3357
|
+
}, {
|
|
3358
|
+
name: `TaggedClass("${name}")`,
|
|
3359
|
+
kind: ts.ScriptElementKind.constElement,
|
|
3360
|
+
insertText: `${effectDataIdentifier}.TaggedClass("${name}")<{${"${0}"}}>{}`,
|
|
3361
|
+
replacementSpan,
|
|
3362
|
+
isSnippet: true
|
|
3363
|
+
}];
|
|
3364
|
+
})
|
|
3365
|
+
});
|
|
3366
|
+
|
|
3367
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/encoding/common.js
|
|
3368
|
+
var encoder = /* @__PURE__ */ new TextEncoder();
|
|
3369
|
+
|
|
3370
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/encoding/base64.js
|
|
3371
|
+
var encode = (bytes) => {
|
|
3372
|
+
const length = bytes.length;
|
|
3373
|
+
let result = "";
|
|
3374
|
+
let i;
|
|
3375
|
+
for (i = 2; i < length; i += 3) {
|
|
3376
|
+
result += base64abc[bytes[i - 2] >> 2];
|
|
3377
|
+
result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4];
|
|
3378
|
+
result += base64abc[(bytes[i - 1] & 15) << 2 | bytes[i] >> 6];
|
|
3379
|
+
result += base64abc[bytes[i] & 63];
|
|
3380
|
+
}
|
|
3381
|
+
if (i === length + 1) {
|
|
3382
|
+
result += base64abc[bytes[i - 2] >> 2];
|
|
3383
|
+
result += base64abc[(bytes[i - 2] & 3) << 4];
|
|
3384
|
+
result += "==";
|
|
3385
|
+
}
|
|
3386
|
+
if (i === length) {
|
|
3387
|
+
result += base64abc[bytes[i - 2] >> 2];
|
|
3388
|
+
result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4];
|
|
3389
|
+
result += base64abc[(bytes[i - 1] & 15) << 2];
|
|
3390
|
+
result += "=";
|
|
3391
|
+
}
|
|
3392
|
+
return result;
|
|
3393
|
+
};
|
|
3394
|
+
var base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"];
|
|
3395
|
+
|
|
3396
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/encoding/base64Url.js
|
|
3397
|
+
var encode2 = (data) => encode(data).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
3398
|
+
|
|
3399
|
+
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Encoding.js
|
|
3400
|
+
var encodeBase64Url = (input) => typeof input === "string" ? encode2(encoder.encode(input)) : encode2(input);
|
|
3401
|
+
|
|
3402
|
+
// src/diagnostics/classSelfMismatch.ts
|
|
3403
|
+
var classSelfMismatch = createDiagnostic({
|
|
3404
|
+
name: "classSelfMismatch",
|
|
3405
|
+
code: 20,
|
|
3406
|
+
severity: "error",
|
|
3407
|
+
apply: fn("classSelfMismatch.apply")(function* (sourceFile, report) {
|
|
3408
|
+
const ts = yield* service(TypeScriptApi);
|
|
3409
|
+
const typeParser = yield* service(TypeParser);
|
|
3410
|
+
const nodeToVisit = [];
|
|
3411
|
+
const appendNodeToVisit = (node) => {
|
|
3412
|
+
nodeToVisit.push(node);
|
|
3413
|
+
return void 0;
|
|
3414
|
+
};
|
|
3415
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
3416
|
+
while (nodeToVisit.length > 0) {
|
|
3417
|
+
const node = nodeToVisit.shift();
|
|
3418
|
+
if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {
|
|
3419
|
+
const result = yield* pipe(
|
|
3420
|
+
typeParser.extendsEffectService(node),
|
|
3421
|
+
orElse2(() => typeParser.extendsContextTag(node)),
|
|
3422
|
+
orElse2(() => typeParser.extendsSchemaClass(node)),
|
|
3423
|
+
orElse2(() => typeParser.extendsSchemaTaggedClass(node)),
|
|
3424
|
+
orElse2(() => typeParser.extendsSchemaTaggedError(node)),
|
|
3425
|
+
orElse2(() => typeParser.extendsSchemaTaggedRequest(node)),
|
|
3426
|
+
orElse2(() => void_)
|
|
3427
|
+
);
|
|
3428
|
+
if (result) {
|
|
3429
|
+
const { className, selfTypeNode } = result;
|
|
3430
|
+
let actualName = "";
|
|
3431
|
+
if (ts.isTypeReferenceNode(selfTypeNode)) {
|
|
3432
|
+
if (ts.isIdentifier(selfTypeNode.typeName)) {
|
|
3433
|
+
actualName = selfTypeNode.typeName.text;
|
|
3434
|
+
} else if (ts.isQualifiedName(selfTypeNode.typeName)) {
|
|
3435
|
+
actualName = selfTypeNode.typeName.right.text;
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3438
|
+
const expectedName = className.text;
|
|
3439
|
+
if (actualName !== expectedName) {
|
|
3440
|
+
report({
|
|
3441
|
+
location: selfTypeNode,
|
|
3442
|
+
messageText: `Self type parameter should be '${expectedName}'`,
|
|
3443
|
+
fixes: [{
|
|
3444
|
+
fixName: "classSelfMismatch_fix",
|
|
3445
|
+
description: `Replace '${actualName}' with '${expectedName}'`,
|
|
3446
|
+
apply: gen(function* () {
|
|
3447
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
3448
|
+
const typeArgs = ts.isTypeReferenceNode(selfTypeNode) ? selfTypeNode.typeArguments : void 0;
|
|
3449
|
+
const newTypeReference = ts.factory.createTypeReferenceNode(
|
|
3450
|
+
ts.factory.createIdentifier(expectedName),
|
|
3451
|
+
typeArgs
|
|
3452
|
+
);
|
|
3453
|
+
changeTracker.replaceNode(sourceFile, selfTypeNode, newTypeReference);
|
|
3454
|
+
})
|
|
3455
|
+
}]
|
|
3456
|
+
});
|
|
2751
3457
|
}
|
|
2752
|
-
return succeed({
|
|
2753
|
-
type: callbackParameterType
|
|
2754
|
-
});
|
|
2755
3458
|
}
|
|
2756
3459
|
}
|
|
2757
|
-
|
|
2758
|
-
}
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
3460
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
3461
|
+
}
|
|
3462
|
+
})
|
|
3463
|
+
});
|
|
3464
|
+
|
|
3465
|
+
// src/diagnostics/duplicatePackage.ts
|
|
3466
|
+
var checkedPackagesCache = /* @__PURE__ */ new Map();
|
|
3467
|
+
var programResolvedCacheSize = /* @__PURE__ */ new Map();
|
|
3468
|
+
var duplicatePackage = createDiagnostic({
|
|
3469
|
+
name: "duplicatePackage",
|
|
3470
|
+
code: 6,
|
|
3471
|
+
severity: "warning",
|
|
3472
|
+
apply: fn("duplicatePackage.apply")(function* (sourceFile, report) {
|
|
3473
|
+
const program = yield* service(TypeScriptProgram);
|
|
3474
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3475
|
+
const options = yield* service(LanguageServicePluginOptions);
|
|
3476
|
+
if (sourceFile.statements.length < 1) return;
|
|
3477
|
+
let resolvedPackages = checkedPackagesCache.get(sourceFile.fileName) || {};
|
|
3478
|
+
const newResolvedModuleSize = hasProperty(program, "resolvedModules") && hasProperty(program.resolvedModules, "size") && isNumber(program.resolvedModules.size) ? program.resolvedModules.size : 0;
|
|
3479
|
+
const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1;
|
|
3480
|
+
if (newResolvedModuleSize !== oldResolvedSize) {
|
|
3481
|
+
const seenPackages = /* @__PURE__ */ new Set();
|
|
3482
|
+
resolvedPackages = {};
|
|
3483
|
+
program.getSourceFiles().map((_) => {
|
|
3484
|
+
const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(_);
|
|
3485
|
+
if (!packageInfo) return;
|
|
3486
|
+
const packageNameAndVersion = packageInfo.name + "@" + packageInfo.version;
|
|
3487
|
+
if (seenPackages.has(packageNameAndVersion)) return;
|
|
3488
|
+
seenPackages.add(packageNameAndVersion);
|
|
3489
|
+
if (!(packageInfo.name === "effect" || packageInfo.hasEffectInPeerDependencies)) return;
|
|
3490
|
+
if (options.allowedDuplicatedPackages.indexOf(packageInfo.name) > -1) return;
|
|
3491
|
+
resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {};
|
|
3492
|
+
resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.packageDirectory;
|
|
3493
|
+
});
|
|
3494
|
+
checkedPackagesCache.set(sourceFile.fileName, resolvedPackages);
|
|
3495
|
+
programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize);
|
|
3496
|
+
}
|
|
3497
|
+
for (const packageName of Object.keys(resolvedPackages)) {
|
|
3498
|
+
if (Object.keys(resolvedPackages[packageName]).length > 1) {
|
|
3499
|
+
const versions = Object.keys(resolvedPackages[packageName]);
|
|
3500
|
+
report({
|
|
3501
|
+
location: sourceFile.statements[0],
|
|
3502
|
+
messageText: `Package ${packageName} is referenced multiple times with different versions (${versions.join(", ")}) and may cause unexpected type errors.
|
|
3503
|
+
Cleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.
|
|
3504
|
+
If this is intended set the LSP config "allowedDuplicatedPackages" to ${JSON.stringify(options.allowedDuplicatedPackages.concat([packageName]))}.
|
|
3505
|
+
|
|
3506
|
+
${versions.map((version) => `- found ${version} at ${resolvedPackages[packageName][version]}`).join("\n")}`,
|
|
3507
|
+
fixes: []
|
|
3508
|
+
});
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
})
|
|
3512
|
+
});
|
|
2781
3513
|
|
|
2782
3514
|
// src/diagnostics/effectInVoidSuccess.ts
|
|
2783
3515
|
var effectInVoidSuccess = createDiagnostic({
|
|
@@ -2794,7 +3526,7 @@ var effectInVoidSuccess = createDiagnostic({
|
|
|
2794
3526
|
if (expectedEffect.A.flags & ts.TypeFlags.Void) {
|
|
2795
3527
|
const voidValueTypes = unrollUnionMembers(realEffect.A);
|
|
2796
3528
|
const voidedEffect = yield* firstSuccessOf(
|
|
2797
|
-
voidValueTypes.map((_) =>
|
|
3529
|
+
voidValueTypes.map((_) => map3(typeParser.strictEffectType(_, node), () => _))
|
|
2798
3530
|
);
|
|
2799
3531
|
return { voidedEffect };
|
|
2800
3532
|
}
|
|
@@ -2810,10 +3542,10 @@ var effectInVoidSuccess = createDiagnostic({
|
|
|
2810
3542
|
valueNode,
|
|
2811
3543
|
realType
|
|
2812
3544
|
),
|
|
2813
|
-
|
|
3545
|
+
map3(({ voidedEffect }) => {
|
|
2814
3546
|
report(
|
|
2815
3547
|
{
|
|
2816
|
-
node,
|
|
3548
|
+
location: node,
|
|
2817
3549
|
messageText: `There is a nested '${typeChecker.typeToString(voidedEffect)}' in the 'void' success channel, beware that this could lead to nested Effect<Effect<...>> that won't be executed.`,
|
|
2818
3550
|
fixes: []
|
|
2819
3551
|
}
|
|
@@ -2862,7 +3594,7 @@ var floatingEffect = createDiagnostic({
|
|
|
2862
3594
|
);
|
|
2863
3595
|
if (isNone2(allowedFloatingEffects)) {
|
|
2864
3596
|
report({
|
|
2865
|
-
node,
|
|
3597
|
+
location: node,
|
|
2866
3598
|
messageText: `Effect must be yielded or assigned to a variable.`,
|
|
2867
3599
|
fixes: []
|
|
2868
3600
|
});
|
|
@@ -2903,9 +3635,9 @@ var genericEffectServices = createDiagnostic({
|
|
|
2903
3635
|
for (const [type, reportAt] of typesToCheck) {
|
|
2904
3636
|
yield* pipe(
|
|
2905
3637
|
typeParser.contextTag(type, node),
|
|
2906
|
-
|
|
3638
|
+
map3(() => {
|
|
2907
3639
|
report({
|
|
2908
|
-
|
|
3640
|
+
location: reportAt,
|
|
2909
3641
|
messageText: `Effect Services with type parameters are not supported because they cannot be properly discriminated at runtime, which may cause unexpected behavior.`,
|
|
2910
3642
|
fixes: []
|
|
2911
3643
|
});
|
|
@@ -2927,17 +3659,16 @@ var importFromBarrel = createDiagnostic({
|
|
|
2927
3659
|
const languageServicePluginOptions = yield* service(LanguageServicePluginOptions);
|
|
2928
3660
|
if (languageServicePluginOptions.namespaceImportPackages.length === 0) return;
|
|
2929
3661
|
const ts = yield* service(TypeScriptApi);
|
|
3662
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
2930
3663
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
2931
3664
|
const program = yield* service(TypeScriptProgram);
|
|
2932
3665
|
const packageNamesToCheck = flatten(
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
(packageName) => resolveModulePattern(sourceFile, packageName)
|
|
2936
|
-
)
|
|
3666
|
+
languageServicePluginOptions.namespaceImportPackages.map(
|
|
3667
|
+
(packageName) => tsUtils.resolveModulePattern(sourceFile, packageName)
|
|
2937
3668
|
)
|
|
2938
3669
|
);
|
|
2939
3670
|
const isImportedFromBarrelExport = (element) => {
|
|
2940
|
-
const getModuleSpecifier = makeGetModuleSpecifier(
|
|
3671
|
+
const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
|
|
2941
3672
|
const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
|
|
2942
3673
|
if (!(getModuleSpecifier && resolveExternalModuleName)) return;
|
|
2943
3674
|
const importDeclaration = ts.findAncestor(element, (node) => ts.isImportDeclaration(node));
|
|
@@ -3013,7 +3744,7 @@ var importFromBarrel = createDiagnostic({
|
|
|
3013
3744
|
unbarrelledFileName
|
|
3014
3745
|
} = result;
|
|
3015
3746
|
report({
|
|
3016
|
-
node,
|
|
3747
|
+
location: node,
|
|
3017
3748
|
messageText: `Importing from barrel module ${barrelModuleName} is not allowed.`,
|
|
3018
3749
|
fixes: [
|
|
3019
3750
|
{
|
|
@@ -3078,13 +3809,13 @@ var leakingRequirements = createDiagnostic({
|
|
|
3078
3809
|
let effectContextType = void 0;
|
|
3079
3810
|
yield* pipe(
|
|
3080
3811
|
typeParser.effectType(servicePropertyType, atLocation),
|
|
3081
|
-
|
|
3812
|
+
map3((_) => effectContextType = _.R),
|
|
3082
3813
|
orElse2(() => {
|
|
3083
3814
|
const servicePropertyCallSignatures = servicePropertyType.getCallSignatures();
|
|
3084
3815
|
if (servicePropertyCallSignatures.length === 1) {
|
|
3085
3816
|
return pipe(
|
|
3086
3817
|
typeParser.effectType(servicePropertyCallSignatures[0].getReturnType(), atLocation),
|
|
3087
|
-
|
|
3818
|
+
map3((_) => {
|
|
3088
3819
|
effectContextType = _.R;
|
|
3089
3820
|
})
|
|
3090
3821
|
);
|
|
@@ -3102,7 +3833,7 @@ var leakingRequirements = createDiagnostic({
|
|
|
3102
3833
|
if (type.flags & ts.TypeFlags.Never) return succeed(true);
|
|
3103
3834
|
return pipe(
|
|
3104
3835
|
typeParser.scopeType(type, atLocation),
|
|
3105
|
-
|
|
3836
|
+
map3(() => true),
|
|
3106
3837
|
orElse2(() => succeed(false))
|
|
3107
3838
|
);
|
|
3108
3839
|
}
|
|
@@ -3127,7 +3858,7 @@ var leakingRequirements = createDiagnostic({
|
|
|
3127
3858
|
function reportLeakingRequirements(node, requirements) {
|
|
3128
3859
|
if (requirements.length === 0) return;
|
|
3129
3860
|
report({
|
|
3130
|
-
node,
|
|
3861
|
+
location: node,
|
|
3131
3862
|
messageText: `This Service is leaking the ${requirements.map((_) => typeChecker.typeToString(_)).join(" | ")} requirement.
|
|
3132
3863
|
If these requirements cannot be cached and are expected to be provided per method invocation (e.g. HttpServerRequest), you can safely disable this diagnostic for this line through quickfixes.
|
|
3133
3864
|
More info at https://effect.website/docs/requirements-management/layers/#avoiding-requirement-leakage`,
|
|
@@ -3158,10 +3889,10 @@ More info at https://effect.website/docs/requirements-management/layers/#avoidin
|
|
|
3158
3889
|
for (const [type, reportAt] of typesToCheck) {
|
|
3159
3890
|
yield* pipe(
|
|
3160
3891
|
typeParser.contextTag(type, node),
|
|
3161
|
-
|
|
3892
|
+
flatMap(
|
|
3162
3893
|
({ Service }) => pipe(
|
|
3163
3894
|
parseLeakedRequirements(Service, node),
|
|
3164
|
-
|
|
3895
|
+
map3((requirements) => reportLeakingRequirements(reportAt, sort(requirements, typeOrder)))
|
|
3165
3896
|
)
|
|
3166
3897
|
),
|
|
3167
3898
|
orElse2(() => sync(() => ts.forEachChild(node, appendNodeToVisit))),
|
|
@@ -3186,7 +3917,7 @@ var missingEffectContext = createDiagnostic({
|
|
|
3186
3917
|
typeParser.effectType(expectedType, node),
|
|
3187
3918
|
typeParser.effectType(realType, valueNode)
|
|
3188
3919
|
),
|
|
3189
|
-
|
|
3920
|
+
flatMap(
|
|
3190
3921
|
([expectedEffect, realEffect]) => getMissingTypeEntriesInTargetType(
|
|
3191
3922
|
realEffect.R,
|
|
3192
3923
|
expectedEffect.R
|
|
@@ -3204,10 +3935,10 @@ var missingEffectContext = createDiagnostic({
|
|
|
3204
3935
|
valueNode,
|
|
3205
3936
|
realType
|
|
3206
3937
|
),
|
|
3207
|
-
|
|
3938
|
+
map3(
|
|
3208
3939
|
(missingTypes) => missingTypes.length > 0 ? report(
|
|
3209
3940
|
{
|
|
3210
|
-
node,
|
|
3941
|
+
location: node,
|
|
3211
3942
|
messageText: `Missing '${sortTypes(missingTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect context.`,
|
|
3212
3943
|
fixes: []
|
|
3213
3944
|
}
|
|
@@ -3227,18 +3958,15 @@ var missingEffectError = createDiagnostic({
|
|
|
3227
3958
|
severity: "error",
|
|
3228
3959
|
apply: fn("missingEffectError.apply")(function* (sourceFile, report) {
|
|
3229
3960
|
const ts = yield* service(TypeScriptApi);
|
|
3961
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3230
3962
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3231
3963
|
const typeParser = yield* service(TypeParser);
|
|
3232
3964
|
const typeOrder = yield* deterministicTypeOrder;
|
|
3233
|
-
const effectModuleIdentifier =
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
),
|
|
3239
|
-
map4((_) => _.text),
|
|
3240
|
-
orElse2(() => succeed("Effect"))
|
|
3241
|
-
);
|
|
3965
|
+
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3966
|
+
sourceFile,
|
|
3967
|
+
"effect",
|
|
3968
|
+
"Effect"
|
|
3969
|
+
) || "Effect";
|
|
3242
3970
|
const createDieMessage = (message) => ts.factory.createCallExpression(
|
|
3243
3971
|
ts.factory.createPropertyAccessExpression(
|
|
3244
3972
|
ts.factory.createIdentifier(effectModuleIdentifier),
|
|
@@ -3252,13 +3980,13 @@ var missingEffectError = createDiagnostic({
|
|
|
3252
3980
|
typeParser.effectType(expectedType, node),
|
|
3253
3981
|
typeParser.effectType(realType, valueNode)
|
|
3254
3982
|
),
|
|
3255
|
-
|
|
3983
|
+
flatMap(
|
|
3256
3984
|
([expectedEffect, realEffect]) => pipe(
|
|
3257
3985
|
getMissingTypeEntriesInTargetType(
|
|
3258
3986
|
realEffect.E,
|
|
3259
3987
|
expectedEffect.E
|
|
3260
3988
|
),
|
|
3261
|
-
|
|
3989
|
+
map3((missingErrorTypes) => ({ missingErrorTypes, expectedErrorType: expectedEffect.E }))
|
|
3262
3990
|
)
|
|
3263
3991
|
)
|
|
3264
3992
|
);
|
|
@@ -3273,7 +4001,7 @@ var missingEffectError = createDiagnostic({
|
|
|
3273
4001
|
valueNode,
|
|
3274
4002
|
realType
|
|
3275
4003
|
),
|
|
3276
|
-
|
|
4004
|
+
map3((result) => {
|
|
3277
4005
|
if (result.missingErrorTypes.length === 0) return;
|
|
3278
4006
|
const fixes = [];
|
|
3279
4007
|
if (ts.isExpression(valueNode) && result.expectedErrorType.flags & ts.TypeFlags.Never) {
|
|
@@ -3296,17 +4024,17 @@ var missingEffectError = createDiagnostic({
|
|
|
3296
4024
|
if (ts.isExpression(valueNode)) {
|
|
3297
4025
|
const propertyAssignments = pipe(
|
|
3298
4026
|
result.missingErrorTypes,
|
|
3299
|
-
|
|
4027
|
+
map4((_) => typeChecker.getPropertyOfType(_, "_tag")),
|
|
3300
4028
|
filter((_) => !!_),
|
|
3301
|
-
|
|
4029
|
+
map4((_) => typeChecker.getTypeOfSymbolAtLocation(_, valueNode)),
|
|
3302
4030
|
filter((_) => !!(_.flags & ts.TypeFlags.Literal)),
|
|
3303
|
-
|
|
4031
|
+
map4((_) => typeChecker.typeToTypeNode(_, void 0, ts.NodeBuilderFlags.NoTruncation)),
|
|
3304
4032
|
filter((_) => !!_ && ts.isLiteralTypeNode(_)),
|
|
3305
|
-
|
|
4033
|
+
map4((_) => _.literal),
|
|
3306
4034
|
filter((_) => ts.isLiteralExpression(_)),
|
|
3307
|
-
|
|
4035
|
+
map4((_) => _.text),
|
|
3308
4036
|
sort(string2),
|
|
3309
|
-
|
|
4037
|
+
map4(
|
|
3310
4038
|
(_) => ts.factory.createPropertyAssignment(
|
|
3311
4039
|
ts.factory.createIdentifier(_),
|
|
3312
4040
|
ts.factory.createArrowFunction(
|
|
@@ -3340,7 +4068,7 @@ var missingEffectError = createDiagnostic({
|
|
|
3340
4068
|
}
|
|
3341
4069
|
report(
|
|
3342
4070
|
{
|
|
3343
|
-
node,
|
|
4071
|
+
location: node,
|
|
3344
4072
|
messageText: `Missing '${sortTypes(result.missingErrorTypes).map((_) => typeChecker.typeToString(_)).join(" | ")}' in the expected Effect errors.`,
|
|
3345
4073
|
fixes
|
|
3346
4074
|
}
|
|
@@ -3404,7 +4132,7 @@ var missingReturnYieldStar = createDiagnostic({
|
|
|
3404
4132
|
})
|
|
3405
4133
|
}] : [];
|
|
3406
4134
|
report({
|
|
3407
|
-
node,
|
|
4135
|
+
location: node,
|
|
3408
4136
|
messageText: `Yielded Effect never succeeds, so it is best to use a 'return yield*' instead.`,
|
|
3409
4137
|
fixes: fix
|
|
3410
4138
|
});
|
|
@@ -3447,7 +4175,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
3447
4175
|
typeParser.effectGen(effectGenNode),
|
|
3448
4176
|
orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
|
|
3449
4177
|
orElse2(() => typeParser.effectFnGen(effectGenNode)),
|
|
3450
|
-
|
|
4178
|
+
map3(({ functionStar }) => {
|
|
3451
4179
|
if (functionStar) {
|
|
3452
4180
|
brokenGenerators.add(functionStar);
|
|
3453
4181
|
}
|
|
@@ -3460,7 +4188,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
3460
4188
|
}
|
|
3461
4189
|
brokenGenerators.forEach(
|
|
3462
4190
|
(node) => report({
|
|
3463
|
-
node,
|
|
4191
|
+
location: node,
|
|
3464
4192
|
messageText: `Seems like you used yield instead of yield* inside this Effect.gen.`,
|
|
3465
4193
|
fixes: []
|
|
3466
4194
|
})
|
|
@@ -3482,7 +4210,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
3482
4210
|
})
|
|
3483
4211
|
}] : [];
|
|
3484
4212
|
report({
|
|
3485
|
-
node,
|
|
4213
|
+
location: node,
|
|
3486
4214
|
messageText: `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`,
|
|
3487
4215
|
fixes: fix
|
|
3488
4216
|
});
|
|
@@ -3497,34 +4225,27 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
3497
4225
|
severity: "warning",
|
|
3498
4226
|
apply: fn("multipleEffectProvide.apply")(function* (sourceFile, report) {
|
|
3499
4227
|
const ts = yield* service(TypeScriptApi);
|
|
4228
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3500
4229
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3501
4230
|
const typeParser = yield* service(TypeParser);
|
|
3502
|
-
const effectModuleIdentifier =
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3513
|
-
sourceFile,
|
|
3514
|
-
"effect",
|
|
3515
|
-
"Layer"
|
|
3516
|
-
),
|
|
3517
|
-
map4((_) => _.text),
|
|
3518
|
-
orElse2(() => succeed("Layer"))
|
|
3519
|
-
);
|
|
4231
|
+
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4232
|
+
sourceFile,
|
|
4233
|
+
"effect",
|
|
4234
|
+
"Effect"
|
|
4235
|
+
) || "Effect";
|
|
4236
|
+
const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4237
|
+
sourceFile,
|
|
4238
|
+
"effect",
|
|
4239
|
+
"Layer"
|
|
4240
|
+
) || "Layer";
|
|
3520
4241
|
const parseEffectProvideLayer = (node) => {
|
|
3521
4242
|
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && node.expression.name.text === "provide" && node.arguments.length > 0) {
|
|
3522
4243
|
const layer = node.arguments[0];
|
|
3523
4244
|
const type = typeChecker.getTypeAtLocation(layer);
|
|
3524
4245
|
return pipe(
|
|
3525
4246
|
typeParser.importedEffectModule(node.expression.expression),
|
|
3526
|
-
|
|
3527
|
-
|
|
4247
|
+
flatMap(() => typeParser.layerType(type, layer)),
|
|
4248
|
+
map3(() => ({ layer, node })),
|
|
3528
4249
|
orElse2(() => void_)
|
|
3529
4250
|
);
|
|
3530
4251
|
}
|
|
@@ -3546,7 +4267,7 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
3546
4267
|
for (const chunk of previousLayers) {
|
|
3547
4268
|
if (chunk.length < 2) continue;
|
|
3548
4269
|
report({
|
|
3549
|
-
|
|
4270
|
+
location: chunk[0].node,
|
|
3550
4271
|
messageText: "Avoid chaining Effect.provide calls, as this can lead to service lifecycle issues. Instead, merge layers and provide them in a single call.",
|
|
3551
4272
|
fixes: [{
|
|
3552
4273
|
fixName: "multipleEffectProvide_fix",
|
|
@@ -3594,6 +4315,51 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
3594
4315
|
})
|
|
3595
4316
|
});
|
|
3596
4317
|
|
|
4318
|
+
// src/diagnostics/outdatedEffectCodegen.ts
|
|
4319
|
+
var outdatedEffectCodegen = createDiagnostic({
|
|
4320
|
+
name: "outdatedEffectCodegen",
|
|
4321
|
+
code: 19,
|
|
4322
|
+
severity: "warning",
|
|
4323
|
+
apply: fn("outdatedEffectCodegen.apply")(function* (sourceFile, _report) {
|
|
4324
|
+
const codegensWithRanges = yield* getCodegensForSourceFile(codegens, sourceFile);
|
|
4325
|
+
for (const { codegen, hash: hash2, range } of codegensWithRanges) {
|
|
4326
|
+
yield* pipe(
|
|
4327
|
+
getEditsForCodegen([codegen], sourceFile, range),
|
|
4328
|
+
map3((applicable) => {
|
|
4329
|
+
if (applicable.hash !== hash2) {
|
|
4330
|
+
_report({
|
|
4331
|
+
location: range,
|
|
4332
|
+
messageText: `Codegen ${codegen.name} result is outdated`,
|
|
4333
|
+
fixes: [
|
|
4334
|
+
{
|
|
4335
|
+
fixName: "outdatedEffectCodegen_fix",
|
|
4336
|
+
description: `Re-run ${codegen.name}`,
|
|
4337
|
+
apply: applicable.apply
|
|
4338
|
+
},
|
|
4339
|
+
{
|
|
4340
|
+
fixName: "outdatedEffectCodegen_ignore",
|
|
4341
|
+
description: `Ignore this ${codegen.name} update`,
|
|
4342
|
+
apply: applicable.ignore
|
|
4343
|
+
}
|
|
4344
|
+
]
|
|
4345
|
+
});
|
|
4346
|
+
}
|
|
4347
|
+
}),
|
|
4348
|
+
orElse2(
|
|
4349
|
+
(e) => sync(() => {
|
|
4350
|
+
_report({
|
|
4351
|
+
location: range,
|
|
4352
|
+
messageText: `Codegen ${codegen.name} is not applicable here: ${e.cause}`,
|
|
4353
|
+
fixes: []
|
|
4354
|
+
});
|
|
4355
|
+
})
|
|
4356
|
+
),
|
|
4357
|
+
ignore
|
|
4358
|
+
);
|
|
4359
|
+
}
|
|
4360
|
+
})
|
|
4361
|
+
});
|
|
4362
|
+
|
|
3597
4363
|
// src/diagnostics/returnEffectInGen.ts
|
|
3598
4364
|
var returnEffectInGen = createDiagnostic({
|
|
3599
4365
|
name: "returnEffectInGen",
|
|
@@ -3628,7 +4394,7 @@ var returnEffectInGen = createDiagnostic({
|
|
|
3628
4394
|
typeParser.effectGen(effectGenNode),
|
|
3629
4395
|
orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
|
|
3630
4396
|
orElse2(() => typeParser.effectFnGen(effectGenNode)),
|
|
3631
|
-
|
|
4397
|
+
map3(() => {
|
|
3632
4398
|
const fix = node.expression ? [{
|
|
3633
4399
|
fixName: "returnEffectInGen_fix",
|
|
3634
4400
|
description: "Add yield* statement",
|
|
@@ -3645,7 +4411,7 @@ var returnEffectInGen = createDiagnostic({
|
|
|
3645
4411
|
})
|
|
3646
4412
|
}] : [];
|
|
3647
4413
|
report({
|
|
3648
|
-
node,
|
|
4414
|
+
location: node,
|
|
3649
4415
|
messageText: `You are returning an Effect-able type inside a generator function, and will result in nested Effect<Effect<...>>.
|
|
3650
4416
|
Maybe you wanted to return yield* instead?
|
|
3651
4417
|
Nested Effect-able types may be intended if you plan to later manually flatten or unwrap this Effect, if so you can safely disable this diagnostic for this line through quickfixes.`,
|
|
@@ -3668,17 +4434,14 @@ var scopeInLayerEffect = createDiagnostic({
|
|
|
3668
4434
|
severity: "warning",
|
|
3669
4435
|
apply: fn("scopeInLayerEffect.apply")(function* (sourceFile, report) {
|
|
3670
4436
|
const ts = yield* service(TypeScriptApi);
|
|
4437
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3671
4438
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3672
4439
|
const typeParser = yield* service(TypeParser);
|
|
3673
|
-
const layerModuleIdentifier =
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
),
|
|
3679
|
-
map4((_) => _.text),
|
|
3680
|
-
orElse2(() => succeed("Layer"))
|
|
3681
|
-
);
|
|
4440
|
+
const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4441
|
+
sourceFile,
|
|
4442
|
+
"effect",
|
|
4443
|
+
"Layer"
|
|
4444
|
+
) || "Layer";
|
|
3682
4445
|
function parseLayerEffectApiCall(node) {
|
|
3683
4446
|
if (!ts.isCallExpression(node)) return;
|
|
3684
4447
|
const expression = node.expression;
|
|
@@ -3702,9 +4465,9 @@ var scopeInLayerEffect = createDiagnostic({
|
|
|
3702
4465
|
}
|
|
3703
4466
|
return pipe(
|
|
3704
4467
|
firstSuccessOf(entries.map((type2) => typeParser.scopeType(type2, node))),
|
|
3705
|
-
|
|
4468
|
+
map3(
|
|
3706
4469
|
() => report({
|
|
3707
|
-
node,
|
|
4470
|
+
location: node,
|
|
3708
4471
|
messageText: `Seems like you are constructing a layer with a scope in the requirements.
|
|
3709
4472
|
Consider using "scoped" instead to get rid of the scope in the requirements.`,
|
|
3710
4473
|
fixes: methodIdentifier ? [{
|
|
@@ -3737,7 +4500,7 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
|
|
|
3737
4500
|
const type = typeChecker.getTypeAtLocation(node);
|
|
3738
4501
|
yield* pipe(
|
|
3739
4502
|
typeParser.layerType(type, node),
|
|
3740
|
-
|
|
4503
|
+
flatMap(({ RIn }) => reportIfLayerRequireScope(RIn, node, layerEffectApiCall.methodIdentifier)),
|
|
3741
4504
|
ignore
|
|
3742
4505
|
);
|
|
3743
4506
|
continue;
|
|
@@ -3751,7 +4514,7 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
|
|
|
3751
4514
|
const type = typeChecker.getTypeOfSymbolAtLocation(defaultLayer, node);
|
|
3752
4515
|
yield* pipe(
|
|
3753
4516
|
typeParser.layerType(type, node),
|
|
3754
|
-
|
|
4517
|
+
flatMap(({ RIn }) => reportIfLayerRequireScope(RIn, node, void 0)),
|
|
3755
4518
|
ignore
|
|
3756
4519
|
);
|
|
3757
4520
|
continue;
|
|
@@ -3820,7 +4583,7 @@ var strictBooleanExpressions = createDiagnostic({
|
|
|
3820
4583
|
if (type.flags & ts.TypeFlags.BooleanLiteral) continue;
|
|
3821
4584
|
const typeName = typeChecker.typeToString(type);
|
|
3822
4585
|
report({
|
|
3823
|
-
|
|
4586
|
+
location: nodeToCheck,
|
|
3824
4587
|
messageText: `Unexpected \`${typeName}\` type in condition, expected strictly a boolean instead.`,
|
|
3825
4588
|
fixes: []
|
|
3826
4589
|
});
|
|
@@ -3860,9 +4623,9 @@ var tryCatchInEffectGen = createDiagnostic({
|
|
|
3860
4623
|
typeParser.effectGen(effectGenNode),
|
|
3861
4624
|
orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
|
|
3862
4625
|
orElse2(() => typeParser.effectFnGen(effectGenNode)),
|
|
3863
|
-
|
|
4626
|
+
map3(() => {
|
|
3864
4627
|
report({
|
|
3865
|
-
node,
|
|
4628
|
+
location: node,
|
|
3866
4629
|
messageText: "Avoid using try/catch inside Effect generators. Use Effect's error handling mechanisms instead (e.g., Effect.try, Effect.tryPromise, Effect.catchAll, Effect.catchTag).",
|
|
3867
4630
|
fixes: []
|
|
3868
4631
|
});
|
|
@@ -3895,9 +4658,9 @@ var unnecessaryEffectGen = createDiagnostic({
|
|
|
3895
4658
|
if (ts.isCallExpression(node)) {
|
|
3896
4659
|
yield* pipe(
|
|
3897
4660
|
typeParser.unnecessaryEffectGen(node),
|
|
3898
|
-
|
|
4661
|
+
map3(
|
|
3899
4662
|
({ replacementNode }) => report({
|
|
3900
|
-
node,
|
|
4663
|
+
location: node,
|
|
3901
4664
|
messageText: `This Effect.gen contains a single return statement.`,
|
|
3902
4665
|
fixes: [{
|
|
3903
4666
|
fixName: "unnecessaryEffectGen_fix",
|
|
@@ -3938,10 +4701,10 @@ var unnecessaryPipe = createDiagnostic({
|
|
|
3938
4701
|
if (ts.isCallExpression(node)) {
|
|
3939
4702
|
yield* pipe(
|
|
3940
4703
|
typeParser.pipeCall(node),
|
|
3941
|
-
|
|
4704
|
+
map3(({ args: args2, subject }) => {
|
|
3942
4705
|
if (args2.length === 0) {
|
|
3943
4706
|
report({
|
|
3944
|
-
node,
|
|
4707
|
+
location: node,
|
|
3945
4708
|
messageText: `This pipe call contains no arguments.`,
|
|
3946
4709
|
fixes: [{
|
|
3947
4710
|
fixName: "unnecessaryPipe_fix",
|
|
@@ -3983,12 +4746,12 @@ var unnecessaryPipeChain = createDiagnostic({
|
|
|
3983
4746
|
if (ts.isCallExpression(node)) {
|
|
3984
4747
|
yield* pipe(
|
|
3985
4748
|
typeParser.pipeCall(node),
|
|
3986
|
-
|
|
3987
|
-
(pipeCall) =>
|
|
4749
|
+
flatMap(
|
|
4750
|
+
(pipeCall) => map3(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))
|
|
3988
4751
|
),
|
|
3989
|
-
|
|
4752
|
+
map3(({ innerCall, pipeCall }) => {
|
|
3990
4753
|
report({
|
|
3991
|
-
node,
|
|
4754
|
+
location: node,
|
|
3992
4755
|
messageText: `Chained pipe calls can be simplified to a single pipe call`,
|
|
3993
4756
|
fixes: [{
|
|
3994
4757
|
fixName: "unnecessaryPipeChain_fix",
|
|
@@ -4029,9 +4792,64 @@ var unnecessaryPipeChain = createDiagnostic({
|
|
|
4029
4792
|
})
|
|
4030
4793
|
}]
|
|
4031
4794
|
});
|
|
4032
|
-
}),
|
|
4033
|
-
ignore
|
|
4034
|
-
);
|
|
4795
|
+
}),
|
|
4796
|
+
ignore
|
|
4797
|
+
);
|
|
4798
|
+
}
|
|
4799
|
+
}
|
|
4800
|
+
})
|
|
4801
|
+
});
|
|
4802
|
+
|
|
4803
|
+
// src/diagnostics/unsupportedServiceAccessors.ts
|
|
4804
|
+
var unsupportedServiceAccessors = createDiagnostic({
|
|
4805
|
+
name: "unsupportedServiceAccessors",
|
|
4806
|
+
code: 21,
|
|
4807
|
+
severity: "warning",
|
|
4808
|
+
apply: fn("unsupportedServiceAccessors.apply")(function* (sourceFile, report) {
|
|
4809
|
+
const ts = yield* service(TypeScriptApi);
|
|
4810
|
+
const nodeToVisit = [];
|
|
4811
|
+
const appendNodeToVisit = (node) => {
|
|
4812
|
+
nodeToVisit.push(node);
|
|
4813
|
+
return void 0;
|
|
4814
|
+
};
|
|
4815
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
4816
|
+
while (nodeToVisit.length > 0) {
|
|
4817
|
+
const node = nodeToVisit.shift();
|
|
4818
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
4819
|
+
if (ts.isClassDeclaration(node)) {
|
|
4820
|
+
const parseResult = yield* pipe(
|
|
4821
|
+
parse2(node),
|
|
4822
|
+
orElse2(() => succeed(null))
|
|
4823
|
+
);
|
|
4824
|
+
if (parseResult && parseResult.involvedMembers.length > 0) {
|
|
4825
|
+
const existingStaticMembers = /* @__PURE__ */ new Set();
|
|
4826
|
+
node.members?.forEach((member) => {
|
|
4827
|
+
if (ts.isPropertyDeclaration(member) && member.modifiers?.some((mod) => mod.kind === ts.SyntaxKind.StaticKeyword)) {
|
|
4828
|
+
if (member.name && ts.isIdentifier(member.name)) {
|
|
4829
|
+
existingStaticMembers.add(member.name.text);
|
|
4830
|
+
}
|
|
4831
|
+
}
|
|
4832
|
+
});
|
|
4833
|
+
const missingMembers = parseResult.involvedMembers.filter(
|
|
4834
|
+
({ property }) => !existingStaticMembers.has(property.getName())
|
|
4835
|
+
);
|
|
4836
|
+
if (missingMembers.length > 0) {
|
|
4837
|
+
const memberNames = missingMembers.map(({ property }) => `'${property.getName()}'`).join(", ");
|
|
4838
|
+
report({
|
|
4839
|
+
location: parseResult.className,
|
|
4840
|
+
messageText: `Even if accessors are enabled, accessors for ${memberNames} won't be available because the signature have generic type parameters or multiple call signatures.`,
|
|
4841
|
+
fixes: [{
|
|
4842
|
+
fixName: "unsupportedServiceAccessors_enableCodegen",
|
|
4843
|
+
description: "Enable accessors codegen",
|
|
4844
|
+
apply: gen(function* () {
|
|
4845
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
4846
|
+
const comment = "// @effect-codegens accessors\n";
|
|
4847
|
+
changeTracker.insertText(sourceFile, node.getStart(sourceFile), comment);
|
|
4848
|
+
})
|
|
4849
|
+
}]
|
|
4850
|
+
});
|
|
4851
|
+
}
|
|
4852
|
+
}
|
|
4035
4853
|
}
|
|
4036
4854
|
}
|
|
4037
4855
|
})
|
|
@@ -4039,6 +4857,7 @@ var unnecessaryPipeChain = createDiagnostic({
|
|
|
4039
4857
|
|
|
4040
4858
|
// src/diagnostics.ts
|
|
4041
4859
|
var diagnostics = [
|
|
4860
|
+
classSelfMismatch,
|
|
4042
4861
|
duplicatePackage,
|
|
4043
4862
|
missingEffectContext,
|
|
4044
4863
|
missingEffectError,
|
|
@@ -4056,7 +4875,9 @@ var diagnostics = [
|
|
|
4056
4875
|
effectInVoidSuccess,
|
|
4057
4876
|
unnecessaryPipeChain,
|
|
4058
4877
|
strictBooleanExpressions,
|
|
4059
|
-
multipleEffectProvide
|
|
4878
|
+
multipleEffectProvide,
|
|
4879
|
+
outdatedEffectCodegen,
|
|
4880
|
+
unsupportedServiceAccessors
|
|
4060
4881
|
];
|
|
4061
4882
|
|
|
4062
4883
|
// src/completions/effectDiagnosticsComment.ts
|
|
@@ -4065,9 +4886,9 @@ var effectDiagnosticsComment = createCompletion({
|
|
|
4065
4886
|
apply: fn("effectDiagnosticsComment")(function* (sourceFile, position) {
|
|
4066
4887
|
const ts = yield* service(TypeScriptApi);
|
|
4067
4888
|
const sourceText = sourceFile.text;
|
|
4068
|
-
const
|
|
4069
|
-
if (
|
|
4070
|
-
const lastIndex =
|
|
4889
|
+
const match2 = /(\/\/|\/\*(?:\*?))\s*(@)\s*$/id.exec(sourceText.substring(0, position));
|
|
4890
|
+
if (match2 && match2.indices) {
|
|
4891
|
+
const lastIndex = match2.indices[2][0];
|
|
4071
4892
|
const replacementSpan = {
|
|
4072
4893
|
start: lastIndex,
|
|
4073
4894
|
length: Math.max(0, position - lastIndex)
|
|
@@ -4097,22 +4918,15 @@ var effectSchemaSelfInClasses = createCompletion({
|
|
|
4097
4918
|
name: "effectSchemaSelfInClasses",
|
|
4098
4919
|
apply: fn("effectSchemaSelfInClasses")(function* (sourceFile, position) {
|
|
4099
4920
|
const ts = yield* service(TypeScriptApi);
|
|
4100
|
-
const
|
|
4101
|
-
|
|
4102
|
-
);
|
|
4103
|
-
|
|
4104
|
-
const
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
"Schema"
|
|
4110
|
-
)
|
|
4111
|
-
);
|
|
4112
|
-
const schemaIdentifier = match(effectSchemaName, {
|
|
4113
|
-
onNone: () => "Schema",
|
|
4114
|
-
onSome: (_) => _.text
|
|
4115
|
-
});
|
|
4921
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4922
|
+
const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
|
|
4923
|
+
if (!maybeInfos) return [];
|
|
4924
|
+
const { accessedObject, className, replacementSpan } = maybeInfos;
|
|
4925
|
+
const schemaIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4926
|
+
sourceFile,
|
|
4927
|
+
"effect",
|
|
4928
|
+
"Schema"
|
|
4929
|
+
) || "Schema";
|
|
4116
4930
|
if (schemaIdentifier !== accessedObject.text) return [];
|
|
4117
4931
|
const name = className.text;
|
|
4118
4932
|
return [{
|
|
@@ -4148,22 +4962,15 @@ var effectSelfInClasses = createCompletion({
|
|
|
4148
4962
|
name: "effectSelfInClasses",
|
|
4149
4963
|
apply: fn("effectSelfInClasses")(function* (sourceFile, position) {
|
|
4150
4964
|
const ts = yield* service(TypeScriptApi);
|
|
4151
|
-
const
|
|
4152
|
-
|
|
4153
|
-
);
|
|
4154
|
-
|
|
4155
|
-
const
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
"Effect"
|
|
4161
|
-
)
|
|
4162
|
-
);
|
|
4163
|
-
const effectIdentifier = match(effectName, {
|
|
4164
|
-
onNone: () => "Effect",
|
|
4165
|
-
onSome: (_) => _.text
|
|
4166
|
-
});
|
|
4965
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4966
|
+
const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
|
|
4967
|
+
if (!maybeInfos) return [];
|
|
4968
|
+
const { accessedObject, className, replacementSpan } = maybeInfos;
|
|
4969
|
+
const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
4970
|
+
sourceFile,
|
|
4971
|
+
"effect",
|
|
4972
|
+
"Effect"
|
|
4973
|
+
) || "Effect";
|
|
4167
4974
|
if (effectIdentifier !== accessedObject.text) return [];
|
|
4168
4975
|
const name = className.text;
|
|
4169
4976
|
return [{
|
|
@@ -4181,12 +4988,11 @@ var fnFunctionStar = createCompletion({
|
|
|
4181
4988
|
name: "fnFunctionStar",
|
|
4182
4989
|
apply: fn("fnFunctionStar")(function* (sourceFile, position) {
|
|
4183
4990
|
const ts = yield* service(TypeScriptApi);
|
|
4991
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4184
4992
|
const typeParser = yield* service(TypeParser);
|
|
4185
|
-
const maybeInfos =
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
if (isNone2(maybeInfos)) return [];
|
|
4189
|
-
const { accessedObject } = maybeInfos.value;
|
|
4993
|
+
const maybeInfos = tsUtils.parseAccessedExpressionForCompletion(sourceFile, position);
|
|
4994
|
+
if (!maybeInfos) return [];
|
|
4995
|
+
const { accessedObject } = maybeInfos;
|
|
4190
4996
|
const isEffectModule = yield* option(typeParser.importedEffectModule(accessedObject));
|
|
4191
4997
|
if (isNone2(isEffectModule)) return [];
|
|
4192
4998
|
const span = ts.createTextSpan(
|
|
@@ -4194,9 +5000,9 @@ var fnFunctionStar = createCompletion({
|
|
|
4194
5000
|
Math.max(0, position - accessedObject.end - 1)
|
|
4195
5001
|
);
|
|
4196
5002
|
const maybeFnName = pipe(
|
|
4197
|
-
|
|
5003
|
+
tsUtils.getAncestorNodesInRange(sourceFile, tsUtils.toTextRange(accessedObject.pos)),
|
|
4198
5004
|
filter(ts.isVariableDeclaration),
|
|
4199
|
-
|
|
5005
|
+
map4((_) => _.name && ts.isIdentifier(_.name) ? _.name.text : ""),
|
|
4200
5006
|
filter((_) => _.length > 0),
|
|
4201
5007
|
head,
|
|
4202
5008
|
map2((name) => [
|
|
@@ -4231,12 +5037,11 @@ var genFunctionStar = createCompletion({
|
|
|
4231
5037
|
name: "genFunctionStar",
|
|
4232
5038
|
apply: fn("genFunctionStar")(function* (sourceFile, position) {
|
|
4233
5039
|
const ts = yield* service(TypeScriptApi);
|
|
5040
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4234
5041
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
4235
|
-
const maybeInfos =
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
if (isNone2(maybeInfos)) return [];
|
|
4239
|
-
const { accessedObject } = maybeInfos.value;
|
|
5042
|
+
const maybeInfos = tsUtils.parseAccessedExpressionForCompletion(sourceFile, position);
|
|
5043
|
+
if (!maybeInfos) return [];
|
|
5044
|
+
const { accessedObject } = maybeInfos;
|
|
4240
5045
|
const type = typeChecker.getTypeAtLocation(accessedObject);
|
|
4241
5046
|
const genMemberSymbol = type.getProperty("gen");
|
|
4242
5047
|
if (!genMemberSymbol) return [];
|
|
@@ -4261,22 +5066,15 @@ var rpcMakeClasses = createCompletion({
|
|
|
4261
5066
|
name: "rpcMakeClasses",
|
|
4262
5067
|
apply: fn("rpcMakeClasses")(function* (sourceFile, position) {
|
|
4263
5068
|
const ts = yield* service(TypeScriptApi);
|
|
4264
|
-
const
|
|
4265
|
-
|
|
4266
|
-
);
|
|
4267
|
-
|
|
4268
|
-
const
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
"Rpc"
|
|
4274
|
-
)
|
|
4275
|
-
);
|
|
4276
|
-
const rpcIdentifier = match(rpcName, {
|
|
4277
|
-
onNone: () => "Rpc",
|
|
4278
|
-
onSome: (_) => _.text
|
|
4279
|
-
});
|
|
5069
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
5070
|
+
const maybeInfos = tsUtils.parseDataForExtendsClassCompletion(sourceFile, position);
|
|
5071
|
+
if (!maybeInfos) return [];
|
|
5072
|
+
const { accessedObject, className, replacementSpan } = maybeInfos;
|
|
5073
|
+
const rpcIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
5074
|
+
sourceFile,
|
|
5075
|
+
"@effect/rpc",
|
|
5076
|
+
"Rpc"
|
|
5077
|
+
) || "Rpc";
|
|
4280
5078
|
if (rpcIdentifier !== accessedObject.text) return [];
|
|
4281
5079
|
const name = className.text;
|
|
4282
5080
|
return [{
|
|
@@ -4294,34 +5092,25 @@ var schemaBrand = createCompletion({
|
|
|
4294
5092
|
name: "schemaBrand",
|
|
4295
5093
|
apply: fn("schemaBrand")(function* (sourceFile, position) {
|
|
4296
5094
|
const ts = yield* service(TypeScriptApi);
|
|
4297
|
-
const
|
|
4298
|
-
|
|
4299
|
-
);
|
|
4300
|
-
|
|
4301
|
-
const { accessedObject } = maybeInfos.value;
|
|
5095
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
5096
|
+
const maybeInfos = tsUtils.parseAccessedExpressionForCompletion(sourceFile, position);
|
|
5097
|
+
if (!maybeInfos) return [];
|
|
5098
|
+
const { accessedObject } = maybeInfos;
|
|
4302
5099
|
if (!ts.isIdentifier(accessedObject)) return [];
|
|
4303
|
-
const schemaName =
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
"Schema"
|
|
4309
|
-
)
|
|
4310
|
-
),
|
|
4311
|
-
{
|
|
4312
|
-
onNone: () => "Schema",
|
|
4313
|
-
onSome: (_) => _.text
|
|
4314
|
-
}
|
|
4315
|
-
);
|
|
5100
|
+
const schemaName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
5101
|
+
sourceFile,
|
|
5102
|
+
"effect",
|
|
5103
|
+
"Schema"
|
|
5104
|
+
) || "Schema";
|
|
4316
5105
|
if (schemaName !== accessedObject.text) return [];
|
|
4317
5106
|
const span = ts.createTextSpan(
|
|
4318
5107
|
accessedObject.end + 1,
|
|
4319
5108
|
Math.max(0, position - accessedObject.end - 1)
|
|
4320
5109
|
);
|
|
4321
5110
|
return pipe(
|
|
4322
|
-
|
|
5111
|
+
tsUtils.getAncestorNodesInRange(sourceFile, tsUtils.toTextRange(accessedObject.pos)),
|
|
4323
5112
|
filter(ts.isVariableDeclaration),
|
|
4324
|
-
|
|
5113
|
+
map4((_) => _.name && ts.isIdentifier(_.name) ? _.name.text : ""),
|
|
4325
5114
|
filter((_) => _.length > 0),
|
|
4326
5115
|
head,
|
|
4327
5116
|
map2((name) => [
|
|
@@ -4348,6 +5137,7 @@ var completions = [
|
|
|
4348
5137
|
fnFunctionStar,
|
|
4349
5138
|
effectDataClasses,
|
|
4350
5139
|
effectDiagnosticsComment,
|
|
5140
|
+
effectCodegensComment,
|
|
4351
5141
|
durationInput,
|
|
4352
5142
|
schemaBrand
|
|
4353
5143
|
];
|
|
@@ -4355,10 +5145,11 @@ var completions = [
|
|
|
4355
5145
|
// src/core/AutoImport.ts
|
|
4356
5146
|
var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
4357
5147
|
const ts = yield* service(TypeScriptApi);
|
|
5148
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4358
5149
|
const program = yield* service(TypeScriptProgram);
|
|
4359
5150
|
const languageServicePluginOptions = yield* service(LanguageServicePluginOptions);
|
|
4360
5151
|
const host = program;
|
|
4361
|
-
const getModuleSpecifier = makeGetModuleSpecifier(
|
|
5152
|
+
const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
|
|
4362
5153
|
function collectSourceFileReexports(sourceFile) {
|
|
4363
5154
|
const namespaceExports = [];
|
|
4364
5155
|
const namedExports = [];
|
|
@@ -4412,7 +5203,7 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
4412
5203
|
if (!isArray(_entrypoints)) return;
|
|
4413
5204
|
if (!every(isString)) return;
|
|
4414
5205
|
const entrypoints = _entrypoints.map((_) => String(_));
|
|
4415
|
-
const info = parsePackageContentNameAndVersionFromScope({ packageJsonScope: packageJsonInfo });
|
|
5206
|
+
const info = tsUtils.parsePackageContentNameAndVersionFromScope({ packageJsonScope: packageJsonInfo });
|
|
4416
5207
|
if (!info) return { entrypoints, exportedKeys: [] };
|
|
4417
5208
|
return { entrypoints, exportedKeys: info.exportsKeys };
|
|
4418
5209
|
} catch (_) {
|
|
@@ -4442,7 +5233,7 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
|
|
|
4442
5233
|
const collectImportCache = fn("TypeScriptApi")(
|
|
4443
5234
|
function* (packagePatterns, kind) {
|
|
4444
5235
|
for (const packagePattern of packagePatterns) {
|
|
4445
|
-
const packageNames =
|
|
5236
|
+
const packageNames = tsUtils.resolveModulePattern(fromSourceFile, packagePattern);
|
|
4446
5237
|
for (const packageName of packageNames) {
|
|
4447
5238
|
const packageInfo = getPackageInfo(fromSourceFile.fileName, packageName);
|
|
4448
5239
|
if (!packageInfo) continue;
|
|
@@ -4574,6 +5365,7 @@ var getOrMakeAutoImportProvider = fn("getOrMakeAutoImportProvider")(function* (s
|
|
|
4574
5365
|
});
|
|
4575
5366
|
var parseImportOnlyChanges = fn("parseImportOnlyChanges")(function* (sourceFile, changes) {
|
|
4576
5367
|
const ts = yield* service(TypeScriptApi);
|
|
5368
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4577
5369
|
const deletions = [];
|
|
4578
5370
|
const imports = [];
|
|
4579
5371
|
for (const change of changes) {
|
|
@@ -4609,7 +5401,7 @@ var parseImportOnlyChanges = fn("parseImportOnlyChanges")(function* (sourceFile,
|
|
|
4609
5401
|
return;
|
|
4610
5402
|
}
|
|
4611
5403
|
} else {
|
|
4612
|
-
const ancestorNodes =
|
|
5404
|
+
const ancestorNodes = tsUtils.getAncestorNodesInRange(sourceFile, {
|
|
4613
5405
|
pos: change.span.start,
|
|
4614
5406
|
end: change.span.start
|
|
4615
5407
|
});
|
|
@@ -4903,12 +5695,13 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
4903
5695
|
return gen(function* () {
|
|
4904
5696
|
const program = yield* service(TypeScriptProgram);
|
|
4905
5697
|
const ts = yield* service(TypeScriptApi);
|
|
5698
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
4906
5699
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
4907
|
-
const textRange = toTextRange(position);
|
|
5700
|
+
const textRange = tsUtils.toTextRange(position);
|
|
4908
5701
|
function isSymbolFromEffectRpcModule(symbol3) {
|
|
4909
5702
|
if (symbol3.valueDeclaration) {
|
|
4910
5703
|
const sourceFile2 = symbol3.valueDeclaration.getSourceFile();
|
|
4911
|
-
const packageInfo = parsePackageContentNameAndVersionFromScope(sourceFile2);
|
|
5704
|
+
const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(sourceFile2);
|
|
4912
5705
|
if (packageInfo && packageInfo.name === "@effect/rpc") {
|
|
4913
5706
|
const fileSymbol = typeChecker.getSymbolAtLocation(sourceFile2);
|
|
4914
5707
|
return fileSymbol && fileSymbol.exports && fileSymbol.exports.has("isRpc") && fileSymbol.exports.has("make") && fileSymbol.exports.has("fromTaggedRequest");
|
|
@@ -4919,7 +5712,7 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
4919
5712
|
function isSymbolFromEffectRpcClientModule(symbol3) {
|
|
4920
5713
|
if (symbol3.valueDeclaration) {
|
|
4921
5714
|
const sourceFile2 = symbol3.valueDeclaration.getSourceFile();
|
|
4922
|
-
const packageInfo = parsePackageContentNameAndVersionFromScope(sourceFile2);
|
|
5715
|
+
const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(sourceFile2);
|
|
4923
5716
|
if (packageInfo && packageInfo.name === "@effect/rpc") {
|
|
4924
5717
|
const fileSymbol = typeChecker.getSymbolAtLocation(sourceFile2);
|
|
4925
5718
|
return fileSymbol && fileSymbol.exports && fileSymbol.exports.has("RpcClient") && fileSymbol.exports.has("make");
|
|
@@ -4929,8 +5722,8 @@ function effectRpcDefinition(applicableGotoDefinition, sourceFile, position) {
|
|
|
4929
5722
|
}
|
|
4930
5723
|
let rpcName = null;
|
|
4931
5724
|
let callNode = null;
|
|
4932
|
-
for (const node of
|
|
4933
|
-
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && isNodeInRange(textRange)(node.name)) {
|
|
5725
|
+
for (const node of tsUtils.getAncestorNodesInRange(sourceFile, textRange)) {
|
|
5726
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && tsUtils.isNodeInRange(textRange)(node.name)) {
|
|
4934
5727
|
const type = typeChecker.getTypeAtLocation(node);
|
|
4935
5728
|
for (const callSig of type.getCallSignatures()) {
|
|
4936
5729
|
if (callSig.parameters.length >= 2 && isSymbolFromEffectRpcClientModule(callSig.parameters[1])) {
|
|
@@ -5082,7 +5875,7 @@ function effectTypeArgs(sourceFile, position, quickInfo2) {
|
|
|
5082
5875
|
type,
|
|
5083
5876
|
atLocation
|
|
5084
5877
|
),
|
|
5085
|
-
|
|
5878
|
+
map3((_) => makeSymbolDisplayParts("Effect Type Parameters", _.A, _.E, _.R)),
|
|
5086
5879
|
orElse2(() => {
|
|
5087
5880
|
const callSignatues = type.getCallSignatures();
|
|
5088
5881
|
if (callSignatues.length !== 1) return succeed([]);
|
|
@@ -5092,7 +5885,7 @@ function effectTypeArgs(sourceFile, position, quickInfo2) {
|
|
|
5092
5885
|
returnType,
|
|
5093
5886
|
atLocation
|
|
5094
5887
|
),
|
|
5095
|
-
|
|
5888
|
+
map3((_) => makeSymbolDisplayParts("Returned Effect Type Parameters", _.A, _.E, _.R))
|
|
5096
5889
|
);
|
|
5097
5890
|
})
|
|
5098
5891
|
);
|
|
@@ -5121,41 +5914,6 @@ function effectTypeArgs(sourceFile, position, quickInfo2) {
|
|
|
5121
5914
|
);
|
|
5122
5915
|
}
|
|
5123
5916
|
|
|
5124
|
-
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/encoding/common.js
|
|
5125
|
-
var encoder = /* @__PURE__ */ new TextEncoder();
|
|
5126
|
-
|
|
5127
|
-
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/encoding/base64.js
|
|
5128
|
-
var encode = (bytes) => {
|
|
5129
|
-
const length = bytes.length;
|
|
5130
|
-
let result = "";
|
|
5131
|
-
let i;
|
|
5132
|
-
for (i = 2; i < length; i += 3) {
|
|
5133
|
-
result += base64abc[bytes[i - 2] >> 2];
|
|
5134
|
-
result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4];
|
|
5135
|
-
result += base64abc[(bytes[i - 1] & 15) << 2 | bytes[i] >> 6];
|
|
5136
|
-
result += base64abc[bytes[i] & 63];
|
|
5137
|
-
}
|
|
5138
|
-
if (i === length + 1) {
|
|
5139
|
-
result += base64abc[bytes[i - 2] >> 2];
|
|
5140
|
-
result += base64abc[(bytes[i - 2] & 3) << 4];
|
|
5141
|
-
result += "==";
|
|
5142
|
-
}
|
|
5143
|
-
if (i === length) {
|
|
5144
|
-
result += base64abc[bytes[i - 2] >> 2];
|
|
5145
|
-
result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4];
|
|
5146
|
-
result += base64abc[(bytes[i - 1] & 15) << 2];
|
|
5147
|
-
result += "=";
|
|
5148
|
-
}
|
|
5149
|
-
return result;
|
|
5150
|
-
};
|
|
5151
|
-
var base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"];
|
|
5152
|
-
|
|
5153
|
-
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/encoding/base64Url.js
|
|
5154
|
-
var encode2 = (data) => encode(data).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
5155
|
-
|
|
5156
|
-
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Encoding.js
|
|
5157
|
-
var encodeBase64Url = (input) => typeof input === "string" ? encode2(encoder.encode(input)) : encode2(input);
|
|
5158
|
-
|
|
5159
5917
|
// node_modules/.pnpm/pako@2.1.0/node_modules/pako/dist/pako.esm.mjs
|
|
5160
5918
|
var Z_FIXED$1 = 4;
|
|
5161
5919
|
var Z_BINARY = 0;
|
|
@@ -6025,7 +6783,7 @@ var read_buf = (strm, buf, start, size) => {
|
|
|
6025
6783
|
var longest_match = (s, cur_match) => {
|
|
6026
6784
|
let chain_length = s.max_chain_length;
|
|
6027
6785
|
let scan = s.strstart;
|
|
6028
|
-
let
|
|
6786
|
+
let match2;
|
|
6029
6787
|
let len;
|
|
6030
6788
|
let best_len = s.prev_length;
|
|
6031
6789
|
let nice_match = s.nice_match;
|
|
@@ -6043,14 +6801,14 @@ var longest_match = (s, cur_match) => {
|
|
|
6043
6801
|
nice_match = s.lookahead;
|
|
6044
6802
|
}
|
|
6045
6803
|
do {
|
|
6046
|
-
|
|
6047
|
-
if (_win[
|
|
6804
|
+
match2 = cur_match;
|
|
6805
|
+
if (_win[match2 + best_len] !== scan_end || _win[match2 + best_len - 1] !== scan_end1 || _win[match2] !== _win[scan] || _win[++match2] !== _win[scan + 1]) {
|
|
6048
6806
|
continue;
|
|
6049
6807
|
}
|
|
6050
6808
|
scan += 2;
|
|
6051
|
-
|
|
6809
|
+
match2++;
|
|
6052
6810
|
do {
|
|
6053
|
-
} while (_win[++scan] === _win[++
|
|
6811
|
+
} while (_win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && _win[++scan] === _win[++match2] && scan < strend);
|
|
6054
6812
|
len = MAX_MATCH - (strend - scan);
|
|
6055
6813
|
scan = strend - MAX_MATCH;
|
|
6056
6814
|
if (len > best_len) {
|
|
@@ -7751,7 +8509,7 @@ var inflate_table = (type, lens, lens_index, codes, table, table_index, work, op
|
|
|
7751
8509
|
let mask;
|
|
7752
8510
|
let next;
|
|
7753
8511
|
let base = null;
|
|
7754
|
-
let
|
|
8512
|
+
let match2;
|
|
7755
8513
|
const count = new Uint16Array(MAXBITS + 1);
|
|
7756
8514
|
const offs = new Uint16Array(MAXBITS + 1);
|
|
7757
8515
|
let extra = null;
|
|
@@ -7807,15 +8565,15 @@ var inflate_table = (type, lens, lens_index, codes, table, table_index, work, op
|
|
|
7807
8565
|
}
|
|
7808
8566
|
if (type === CODES$1) {
|
|
7809
8567
|
base = extra = work;
|
|
7810
|
-
|
|
8568
|
+
match2 = 20;
|
|
7811
8569
|
} else if (type === LENS$1) {
|
|
7812
8570
|
base = lbase;
|
|
7813
8571
|
extra = lext;
|
|
7814
|
-
|
|
8572
|
+
match2 = 257;
|
|
7815
8573
|
} else {
|
|
7816
8574
|
base = dbase;
|
|
7817
8575
|
extra = dext;
|
|
7818
|
-
|
|
8576
|
+
match2 = 0;
|
|
7819
8577
|
}
|
|
7820
8578
|
huff = 0;
|
|
7821
8579
|
sym = 0;
|
|
@@ -7831,12 +8589,12 @@ var inflate_table = (type, lens, lens_index, codes, table, table_index, work, op
|
|
|
7831
8589
|
}
|
|
7832
8590
|
for (; ; ) {
|
|
7833
8591
|
here_bits = len - drop;
|
|
7834
|
-
if (work[sym] + 1 <
|
|
8592
|
+
if (work[sym] + 1 < match2) {
|
|
7835
8593
|
here_op = 0;
|
|
7836
8594
|
here_val = work[sym];
|
|
7837
|
-
} else if (work[sym] >=
|
|
7838
|
-
here_op = extra[work[sym] -
|
|
7839
|
-
here_val = base[work[sym] -
|
|
8595
|
+
} else if (work[sym] >= match2) {
|
|
8596
|
+
here_op = extra[work[sym] - match2];
|
|
8597
|
+
here_val = base[work[sym] - match2];
|
|
7840
8598
|
} else {
|
|
7841
8599
|
here_op = 32 + 64;
|
|
7842
8600
|
here_val = 0;
|
|
@@ -9599,13 +10357,14 @@ function layerInfo(sourceFile, position, quickInfo2) {
|
|
|
9599
10357
|
return pipe(
|
|
9600
10358
|
gen(function* () {
|
|
9601
10359
|
const ts = yield* service(TypeScriptApi);
|
|
10360
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
9602
10361
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
9603
10362
|
const typeParser = yield* service(TypeParser);
|
|
9604
|
-
const range = toTextRange(position);
|
|
10363
|
+
const range = tsUtils.toTextRange(position);
|
|
9605
10364
|
const maybeNode = pipe(
|
|
9606
|
-
|
|
10365
|
+
tsUtils.getAncestorNodesInRange(sourceFile, range),
|
|
9607
10366
|
filter((_) => ts.isVariableDeclaration(_) || ts.isPropertyDeclaration(_)),
|
|
9608
|
-
filter((_) => isNodeInRange(range)(_.name)),
|
|
10367
|
+
filter((_) => tsUtils.isNodeInRange(range)(_.name)),
|
|
9609
10368
|
head
|
|
9610
10369
|
);
|
|
9611
10370
|
if (isNone2(maybeNode)) return quickInfo2;
|
|
@@ -9622,7 +10381,7 @@ function layerInfo(sourceFile, position, quickInfo2) {
|
|
|
9622
10381
|
};
|
|
9623
10382
|
const layerInfoDisplayParts = yield* pipe(
|
|
9624
10383
|
processLayerGraphNode(graphCtx, layerNode, void 0),
|
|
9625
|
-
|
|
10384
|
+
flatMap(
|
|
9626
10385
|
(rootNode) => gen(function* () {
|
|
9627
10386
|
yield* succeed(void 0);
|
|
9628
10387
|
const lines = [];
|
|
@@ -9715,10 +10474,10 @@ var asyncAwaitToGen = createRefactor({
|
|
|
9715
10474
|
description: "Convert to Effect.gen",
|
|
9716
10475
|
apply: fn("asyncAwaitToGen.apply")(function* (sourceFile, textRange) {
|
|
9717
10476
|
const ts = yield* service(TypeScriptApi);
|
|
10477
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
9718
10478
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
9719
|
-
const typeParser = yield* service(TypeParser);
|
|
9720
10479
|
const maybeNode = pipe(
|
|
9721
|
-
|
|
10480
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
9722
10481
|
filter(
|
|
9723
10482
|
(node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
|
|
9724
10483
|
),
|
|
@@ -9734,23 +10493,12 @@ var asyncAwaitToGen = createRefactor({
|
|
|
9734
10493
|
apply: pipe(
|
|
9735
10494
|
gen(function* () {
|
|
9736
10495
|
const changeTracker = yield* service(ChangeTracker);
|
|
9737
|
-
const effectModuleIdentifierName =
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9742
|
-
|
|
9743
|
-
option,
|
|
9744
|
-
map4(isSome2)
|
|
9745
|
-
)
|
|
9746
|
-
)
|
|
9747
|
-
),
|
|
9748
|
-
{
|
|
9749
|
-
onNone: () => "Effect",
|
|
9750
|
-
onSome: (node2) => node2.text
|
|
9751
|
-
}
|
|
9752
|
-
);
|
|
9753
|
-
const newDeclaration = yield* transformAsyncAwaitToEffectGen(
|
|
10496
|
+
const effectModuleIdentifierName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
10497
|
+
sourceFile,
|
|
10498
|
+
"effect",
|
|
10499
|
+
"Effect"
|
|
10500
|
+
) || "Effect";
|
|
10501
|
+
const newDeclaration = tsUtils.transformAsyncAwaitToEffectGen(
|
|
9754
10502
|
node,
|
|
9755
10503
|
effectModuleIdentifierName,
|
|
9756
10504
|
(expression) => ts.factory.createCallExpression(
|
|
@@ -9786,10 +10534,10 @@ var asyncAwaitToGenTryPromise = createRefactor({
|
|
|
9786
10534
|
description: "Convert to Effect.gen with failures",
|
|
9787
10535
|
apply: fn("asyncAwaitToGenTryPromise.apply")(function* (sourceFile, textRange) {
|
|
9788
10536
|
const ts = yield* service(TypeScriptApi);
|
|
10537
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
9789
10538
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
9790
|
-
const typeParser = yield* service(TypeParser);
|
|
9791
10539
|
const maybeNode = pipe(
|
|
9792
|
-
|
|
10540
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
9793
10541
|
filter(
|
|
9794
10542
|
(node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
|
|
9795
10543
|
),
|
|
@@ -9805,22 +10553,11 @@ var asyncAwaitToGenTryPromise = createRefactor({
|
|
|
9805
10553
|
apply: pipe(
|
|
9806
10554
|
gen(function* () {
|
|
9807
10555
|
const changeTracker = yield* service(ChangeTracker);
|
|
9808
|
-
const effectModuleIdentifierName =
|
|
9809
|
-
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
|
|
9813
|
-
typeParser.importedEffectModule(node2),
|
|
9814
|
-
option,
|
|
9815
|
-
map4(isSome2)
|
|
9816
|
-
)
|
|
9817
|
-
)
|
|
9818
|
-
),
|
|
9819
|
-
{
|
|
9820
|
-
onNone: () => "Effect",
|
|
9821
|
-
onSome: (node2) => node2.text
|
|
9822
|
-
}
|
|
9823
|
-
);
|
|
10556
|
+
const effectModuleIdentifierName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
10557
|
+
sourceFile,
|
|
10558
|
+
"effect",
|
|
10559
|
+
"Effect"
|
|
10560
|
+
) || "Effect";
|
|
9824
10561
|
let errorCount = 0;
|
|
9825
10562
|
function createErrorADT() {
|
|
9826
10563
|
errorCount++;
|
|
@@ -9835,7 +10572,7 @@ var asyncAwaitToGenTryPromise = createRefactor({
|
|
|
9835
10572
|
ts.factory.createShorthandPropertyAssignment("error")
|
|
9836
10573
|
]);
|
|
9837
10574
|
}
|
|
9838
|
-
const newDeclaration =
|
|
10575
|
+
const newDeclaration = tsUtils.transformAsyncAwaitToEffectGen(
|
|
9839
10576
|
node,
|
|
9840
10577
|
effectModuleIdentifierName,
|
|
9841
10578
|
(expression) => ts.factory.createCallExpression(
|
|
@@ -9887,6 +10624,7 @@ var effectGenToFn = createRefactor({
|
|
|
9887
10624
|
description: "Convert to Effect.fn",
|
|
9888
10625
|
apply: fn("effectGenToFn.apply")(function* (sourceFile, textRange) {
|
|
9889
10626
|
const ts = yield* service(TypeScriptApi);
|
|
10627
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
9890
10628
|
const typeParser = yield* service(TypeParser);
|
|
9891
10629
|
const parseEffectGenNode = fn("asyncAwaitToGen.apply")(function* (node) {
|
|
9892
10630
|
const effectGen = yield* typeParser.effectGen(node);
|
|
@@ -9923,8 +10661,8 @@ var effectGenToFn = createRefactor({
|
|
|
9923
10661
|
return yield* fail(new RefactorNotApplicableError());
|
|
9924
10662
|
});
|
|
9925
10663
|
const maybeNode = yield* pipe(
|
|
9926
|
-
|
|
9927
|
-
|
|
10664
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10665
|
+
map4(parseEffectGenNode),
|
|
9928
10666
|
firstSuccessOf,
|
|
9929
10667
|
option
|
|
9930
10668
|
);
|
|
@@ -9963,7 +10701,7 @@ var effectGenToFn = createRefactor({
|
|
|
9963
10701
|
changeTracker.replaceNode(
|
|
9964
10702
|
sourceFile,
|
|
9965
10703
|
nodeToReplace,
|
|
9966
|
-
|
|
10704
|
+
tsUtils.tryPreserveDeclarationSemantics(nodeToReplace, effectFnCallWithGenerator)
|
|
9967
10705
|
);
|
|
9968
10706
|
}),
|
|
9969
10707
|
provideService(TypeScriptApi, ts)
|
|
@@ -9978,11 +10716,12 @@ var functionToArrow = createRefactor({
|
|
|
9978
10716
|
description: "Convert to arrow",
|
|
9979
10717
|
apply: fn("functionToArrow.apply")(function* (sourceFile, textRange) {
|
|
9980
10718
|
const ts = yield* service(TypeScriptApi);
|
|
10719
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
9981
10720
|
const maybeNode = pipe(
|
|
9982
|
-
|
|
10721
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
9983
10722
|
filter((_) => ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_)),
|
|
9984
10723
|
filter((_) => !!_.body),
|
|
9985
|
-
filter((_) => !!_.name && isNodeInRange(textRange)(_.name)),
|
|
10724
|
+
filter((_) => !!_.name && tsUtils.isNodeInRange(textRange)(_.name)),
|
|
9986
10725
|
head
|
|
9987
10726
|
);
|
|
9988
10727
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -10013,7 +10752,7 @@ var functionToArrow = createRefactor({
|
|
|
10013
10752
|
ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
|
10014
10753
|
newBody
|
|
10015
10754
|
);
|
|
10016
|
-
const newDeclaration =
|
|
10755
|
+
const newDeclaration = tsUtils.tryPreserveDeclarationSemantics(
|
|
10017
10756
|
node,
|
|
10018
10757
|
arrowFunction
|
|
10019
10758
|
);
|
|
@@ -10034,6 +10773,7 @@ var _findSchemaVariableDeclaration = fn(
|
|
|
10034
10773
|
)(
|
|
10035
10774
|
function* (sourceFile, textRange) {
|
|
10036
10775
|
const ts = yield* service(TypeScriptApi);
|
|
10776
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10037
10777
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
10038
10778
|
const typeParser = yield* service(TypeParser);
|
|
10039
10779
|
const findSchema = fn("makeSchemaOpaque.apply.findSchema")(
|
|
@@ -10059,8 +10799,8 @@ var _findSchemaVariableDeclaration = fn(
|
|
|
10059
10799
|
}
|
|
10060
10800
|
);
|
|
10061
10801
|
return yield* pipe(
|
|
10062
|
-
|
|
10063
|
-
|
|
10802
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10803
|
+
map4(findSchema),
|
|
10064
10804
|
firstSuccessOf,
|
|
10065
10805
|
option
|
|
10066
10806
|
);
|
|
@@ -10147,6 +10887,7 @@ var makeSchemaOpaque = createRefactor({
|
|
|
10147
10887
|
description: "Make Schema opaque",
|
|
10148
10888
|
apply: fn("makeSchemaOpaque.apply")(function* (sourceFile, textRange) {
|
|
10149
10889
|
const ts = yield* service(TypeScriptApi);
|
|
10890
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10150
10891
|
const maybeNode = yield* _findSchemaVariableDeclaration(sourceFile, textRange);
|
|
10151
10892
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
10152
10893
|
const { identifier, types, variableDeclarationList, variableStatement } = maybeNode.value;
|
|
@@ -10156,19 +10897,11 @@ var makeSchemaOpaque = createRefactor({
|
|
|
10156
10897
|
apply: pipe(
|
|
10157
10898
|
gen(function* () {
|
|
10158
10899
|
const changeTracker = yield* service(ChangeTracker);
|
|
10159
|
-
const effectSchemaName =
|
|
10160
|
-
|
|
10161
|
-
|
|
10162
|
-
|
|
10163
|
-
|
|
10164
|
-
"Schema"
|
|
10165
|
-
)
|
|
10166
|
-
),
|
|
10167
|
-
{
|
|
10168
|
-
onNone: () => "Schema",
|
|
10169
|
-
onSome: (_) => _.text
|
|
10170
|
-
}
|
|
10171
|
-
);
|
|
10900
|
+
const effectSchemaName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
10901
|
+
sourceFile,
|
|
10902
|
+
"effect",
|
|
10903
|
+
"Schema"
|
|
10904
|
+
) || "Schema";
|
|
10172
10905
|
const newIdentifier = ts.factory.createIdentifier(identifier.text + "_");
|
|
10173
10906
|
const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(
|
|
10174
10907
|
effectSchemaName,
|
|
@@ -10225,6 +10958,7 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
10225
10958
|
description: "Make Schema opaque with namespace",
|
|
10226
10959
|
apply: fn("makeSchemaOpaqueWithNs.apply")(function* (sourceFile, textRange) {
|
|
10227
10960
|
const ts = yield* service(TypeScriptApi);
|
|
10961
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10228
10962
|
const maybeNode = yield* _findSchemaVariableDeclaration(sourceFile, textRange);
|
|
10229
10963
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
10230
10964
|
const { identifier, types, variableDeclarationList, variableStatement } = maybeNode.value;
|
|
@@ -10234,19 +10968,11 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
10234
10968
|
apply: pipe(
|
|
10235
10969
|
gen(function* () {
|
|
10236
10970
|
const changeTracker = yield* service(ChangeTracker);
|
|
10237
|
-
const effectSchemaName =
|
|
10238
|
-
|
|
10239
|
-
|
|
10240
|
-
|
|
10241
|
-
|
|
10242
|
-
"Schema"
|
|
10243
|
-
)
|
|
10244
|
-
),
|
|
10245
|
-
{
|
|
10246
|
-
onNone: () => "Schema",
|
|
10247
|
-
onSome: (_) => _.text
|
|
10248
|
-
}
|
|
10249
|
-
);
|
|
10971
|
+
const effectSchemaName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
10972
|
+
sourceFile,
|
|
10973
|
+
"effect",
|
|
10974
|
+
"Schema"
|
|
10975
|
+
) || "Schema";
|
|
10250
10976
|
const newIdentifier = ts.factory.createIdentifier(identifier.text + "_");
|
|
10251
10977
|
const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(
|
|
10252
10978
|
effectSchemaName,
|
|
@@ -10320,6 +11046,7 @@ var pipeableToDatafirst = createRefactor({
|
|
|
10320
11046
|
apply: fn("pipeableToDatafirst.apply")(function* (sourceFile, textRange) {
|
|
10321
11047
|
const ts = yield* service(TypeScriptApi);
|
|
10322
11048
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
11049
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10323
11050
|
function isPipeCall(node2) {
|
|
10324
11051
|
if (!ts.isCallExpression(node2)) return false;
|
|
10325
11052
|
const expression = node2.expression;
|
|
@@ -10347,13 +11074,13 @@ var pipeableToDatafirst = createRefactor({
|
|
|
10347
11074
|
return none2();
|
|
10348
11075
|
}
|
|
10349
11076
|
const maybeNode = pipe(
|
|
10350
|
-
|
|
11077
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10351
11078
|
filter(isPipeCall),
|
|
10352
|
-
filter((node2) => isNodeInRange(textRange)(node2.expression)),
|
|
11079
|
+
filter((node2) => tsUtils.isNodeInRange(textRange)(node2.expression)),
|
|
10353
11080
|
filter(
|
|
10354
11081
|
(node2) => node2.arguments.length > 0
|
|
10355
11082
|
),
|
|
10356
|
-
|
|
11083
|
+
map4((node2) => {
|
|
10357
11084
|
let newNode2 = node2.arguments[0];
|
|
10358
11085
|
let didSomething = false;
|
|
10359
11086
|
for (let i = 1; i < node2.arguments.length; i++) {
|
|
@@ -10380,7 +11107,7 @@ var pipeableToDatafirst = createRefactor({
|
|
|
10380
11107
|
return didSomething ? some2([node2, newNode2]) : none2();
|
|
10381
11108
|
}),
|
|
10382
11109
|
filter(isSome2),
|
|
10383
|
-
|
|
11110
|
+
map4((_) => _.value),
|
|
10384
11111
|
head
|
|
10385
11112
|
);
|
|
10386
11113
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -10401,8 +11128,9 @@ var removeUnnecessaryEffectGen = createRefactor({
|
|
|
10401
11128
|
name: "removeUnnecessaryEffectGen",
|
|
10402
11129
|
description: "Remove unnecessary Effect.gen",
|
|
10403
11130
|
apply: fn("removeUnnecessaryEffectGen.apply")(function* (sourceFile, textRange) {
|
|
11131
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10404
11132
|
const typeParser = yield* service(TypeParser);
|
|
10405
|
-
for (const nodeToReplace of
|
|
11133
|
+
for (const nodeToReplace of tsUtils.getAncestorNodesInRange(sourceFile, textRange)) {
|
|
10406
11134
|
const maybeNode = yield* option(typeParser.unnecessaryEffectGen(nodeToReplace));
|
|
10407
11135
|
if (isNone2(maybeNode)) continue;
|
|
10408
11136
|
const replacementNode = maybeNode.value.replacementNode;
|
|
@@ -10425,10 +11153,11 @@ var toggleLazyConst = createRefactor({
|
|
|
10425
11153
|
description: "Toggle lazy const",
|
|
10426
11154
|
apply: fn("toggleLazyConst.apply")(function* (sourceFile, textRange) {
|
|
10427
11155
|
const ts = yield* service(TypeScriptApi);
|
|
11156
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10428
11157
|
const maybeNode = pipe(
|
|
10429
|
-
|
|
11158
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10430
11159
|
filter(ts.isVariableDeclaration),
|
|
10431
|
-
filter((node2) => isNodeInRange(textRange)(node2.name)),
|
|
11160
|
+
filter((node2) => tsUtils.isNodeInRange(textRange)(node2.name)),
|
|
10432
11161
|
filter(
|
|
10433
11162
|
(node2) => !!node2.initializer && !(ts.isArrowFunction(node2.initializer) && ts.isBlock(node2.initializer.body))
|
|
10434
11163
|
),
|
|
@@ -10467,6 +11196,7 @@ var togglePipeStyle = createRefactor({
|
|
|
10467
11196
|
const ts = yield* service(TypeScriptApi);
|
|
10468
11197
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
10469
11198
|
const typeParser = yield* service(TypeParser);
|
|
11199
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10470
11200
|
const togglePipeStyle2 = (node) => gen(function* () {
|
|
10471
11201
|
const pipeCall = yield* typeParser.pipeCall(node);
|
|
10472
11202
|
switch (pipeCall.kind) {
|
|
@@ -10511,7 +11241,7 @@ var togglePipeStyle = createRefactor({
|
|
|
10511
11241
|
};
|
|
10512
11242
|
}
|
|
10513
11243
|
});
|
|
10514
|
-
const ancestorNodes =
|
|
11244
|
+
const ancestorNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange);
|
|
10515
11245
|
return yield* pipe(
|
|
10516
11246
|
firstSuccessOf(ancestorNodes.map(togglePipeStyle2)),
|
|
10517
11247
|
orElse2(() => fail(new RefactorNotApplicableError()))
|
|
@@ -10525,9 +11255,38 @@ var toggleReturnTypeAnnotation = createRefactor({
|
|
|
10525
11255
|
description: "Toggle return type annotation",
|
|
10526
11256
|
apply: fn("toggleReturnTypeAnnotation.apply")(function* (sourceFile, textRange) {
|
|
10527
11257
|
const ts = yield* service(TypeScriptApi);
|
|
11258
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10528
11259
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
11260
|
+
function addReturnTypeAnnotation(sourceFile2, changeTracker, declaration, typeNode) {
|
|
11261
|
+
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile2);
|
|
11262
|
+
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
11263
|
+
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
11264
|
+
if (endNode) {
|
|
11265
|
+
if (needParens) {
|
|
11266
|
+
changeTracker.insertNodeBefore(
|
|
11267
|
+
sourceFile2,
|
|
11268
|
+
endNode,
|
|
11269
|
+
ts.factory.createToken(ts.SyntaxKind.OpenParenToken)
|
|
11270
|
+
);
|
|
11271
|
+
changeTracker.insertNodeAfter(
|
|
11272
|
+
sourceFile2,
|
|
11273
|
+
endNode,
|
|
11274
|
+
ts.factory.createToken(ts.SyntaxKind.CloseParenToken)
|
|
11275
|
+
);
|
|
11276
|
+
}
|
|
11277
|
+
changeTracker.insertNodeAt(sourceFile2, endNode.end, typeNode, { prefix: ": " });
|
|
11278
|
+
}
|
|
11279
|
+
}
|
|
11280
|
+
function removeReturnTypeAnnotation(sourceFile2, changeTracker, declaration) {
|
|
11281
|
+
const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile2);
|
|
11282
|
+
const needParens = ts.isArrowFunction(declaration) && closeParen === void 0;
|
|
11283
|
+
const endNode = needParens ? declaration.parameters[0] : closeParen;
|
|
11284
|
+
if (endNode && declaration.type) {
|
|
11285
|
+
changeTracker.deleteRange(sourceFile2, { pos: endNode.end, end: declaration.type.end });
|
|
11286
|
+
}
|
|
11287
|
+
}
|
|
10529
11288
|
const maybeNode = pipe(
|
|
10530
|
-
|
|
11289
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10531
11290
|
filter(
|
|
10532
11291
|
(node2) => ts.isFunctionDeclaration(node2) || ts.isFunctionExpression(node2) || ts.isArrowFunction(node2) || ts.isMethodDeclaration(node2)
|
|
10533
11292
|
),
|
|
@@ -10540,8 +11299,8 @@ var toggleReturnTypeAnnotation = createRefactor({
|
|
|
10540
11299
|
kind: "refactor.rewrite.effect.toggleReturnTypeAnnotation",
|
|
10541
11300
|
description: "Toggle return type annotation",
|
|
10542
11301
|
apply: pipe(
|
|
10543
|
-
|
|
10544
|
-
|
|
11302
|
+
service(ChangeTracker),
|
|
11303
|
+
map3((changeTracker) => removeReturnTypeAnnotation(sourceFile, changeTracker, node))
|
|
10545
11304
|
)
|
|
10546
11305
|
};
|
|
10547
11306
|
}
|
|
@@ -10557,13 +11316,10 @@ var toggleReturnTypeAnnotation = createRefactor({
|
|
|
10557
11316
|
kind: "refactor.rewrite.effect.toggleReturnTypeAnnotation",
|
|
10558
11317
|
description: "Toggle return type annotation",
|
|
10559
11318
|
apply: pipe(
|
|
10560
|
-
|
|
10561
|
-
|
|
10562
|
-
node,
|
|
10563
|
-
|
|
10564
|
-
),
|
|
10565
|
-
provideService(TypeCheckerApi, typeChecker),
|
|
10566
|
-
provideService(TypeScriptApi, ts)
|
|
11319
|
+
service(ChangeTracker),
|
|
11320
|
+
map3(
|
|
11321
|
+
(changeTracker) => addReturnTypeAnnotation(sourceFile, changeTracker, node, tsUtils.simplifyTypeNode(returnTypeNode))
|
|
11322
|
+
)
|
|
10567
11323
|
)
|
|
10568
11324
|
};
|
|
10569
11325
|
})
|
|
@@ -10575,11 +11331,12 @@ var toggleTypeAnnotation = createRefactor({
|
|
|
10575
11331
|
description: "Toggle type annotation",
|
|
10576
11332
|
apply: fn("toggleTypeAnnotation.apply")(function* (sourceFile, textRange) {
|
|
10577
11333
|
const ts = yield* service(TypeScriptApi);
|
|
11334
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10578
11335
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
10579
11336
|
const maybeNode = pipe(
|
|
10580
|
-
|
|
11337
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10581
11338
|
filter((node2) => ts.isVariableDeclaration(node2) || ts.isPropertyDeclaration(node2)),
|
|
10582
|
-
filter((node2) => isNodeInRange(textRange)(node2.name)),
|
|
11339
|
+
filter((node2) => tsUtils.isNodeInRange(textRange)(node2.name)),
|
|
10583
11340
|
filter((node2) => !!node2.initializer),
|
|
10584
11341
|
head
|
|
10585
11342
|
);
|
|
@@ -10615,7 +11372,7 @@ var toggleTypeAnnotation = createRefactor({
|
|
|
10615
11372
|
changeTracker.insertNodeAt(
|
|
10616
11373
|
sourceFile,
|
|
10617
11374
|
node.name.end,
|
|
10618
|
-
|
|
11375
|
+
tsUtils.simplifyTypeNode(initializerTypeNode),
|
|
10619
11376
|
{
|
|
10620
11377
|
prefix: ": "
|
|
10621
11378
|
}
|
|
@@ -10667,21 +11424,16 @@ var IndexSignatureWithMoreThanOneParameterError = class {
|
|
|
10667
11424
|
};
|
|
10668
11425
|
var SchemaGenContext = Tag("SchemaGenContext");
|
|
10669
11426
|
var makeSchemaGenContext = fn("SchemaGen.makeSchemaGenContext")(function* (sourceFile) {
|
|
10670
|
-
const
|
|
10671
|
-
|
|
10672
|
-
|
|
10673
|
-
|
|
10674
|
-
|
|
10675
|
-
|
|
10676
|
-
onSome: (_) => _.text
|
|
10677
|
-
})
|
|
10678
|
-
);
|
|
11427
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
11428
|
+
const effectSchemaIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
11429
|
+
sourceFile,
|
|
11430
|
+
"effect",
|
|
11431
|
+
"Schema"
|
|
11432
|
+
) || "Schema";
|
|
10679
11433
|
const moduleToImportedName = {};
|
|
10680
11434
|
for (const moduleName of ["Option", "Either", "Chunk", "Duration"]) {
|
|
10681
|
-
const importedName =
|
|
10682
|
-
|
|
10683
|
-
);
|
|
10684
|
-
if (isSome2(importedName)) moduleToImportedName[moduleName] = importedName.value.text;
|
|
11435
|
+
const importedName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", moduleName);
|
|
11436
|
+
if (importedName) moduleToImportedName[moduleName] = importedName;
|
|
10685
11437
|
}
|
|
10686
11438
|
const ts = yield* service(TypeScriptApi);
|
|
10687
11439
|
return {
|
|
@@ -11065,10 +11817,11 @@ var process = fn("SchemaGen.process")(
|
|
|
11065
11817
|
var findNodeToProcess = fn("SchemaGen.findNodeToProcess")(
|
|
11066
11818
|
function* (sourceFile, textRange) {
|
|
11067
11819
|
const ts = yield* service(TypeScriptApi);
|
|
11820
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
11068
11821
|
return pipe(
|
|
11069
|
-
|
|
11822
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
11070
11823
|
filter((node) => ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)),
|
|
11071
|
-
filter((node) => isNodeInRange(textRange)(node.name)),
|
|
11824
|
+
filter((node) => tsUtils.isNodeInRange(textRange)(node.name)),
|
|
11072
11825
|
filter((node) => (node.typeParameters || []).length === 0),
|
|
11073
11826
|
head
|
|
11074
11827
|
);
|
|
@@ -11101,6 +11854,7 @@ var typeToEffectSchema = createRefactor({
|
|
|
11101
11854
|
description: "Refactor to Schema",
|
|
11102
11855
|
apply: fn("typeToEffectSchema.apply")(function* (sourceFile, textRange) {
|
|
11103
11856
|
const ts = yield* service(TypeScriptApi);
|
|
11857
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
11104
11858
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
11105
11859
|
const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
|
|
11106
11860
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -11111,6 +11865,7 @@ var typeToEffectSchema = createRefactor({
|
|
|
11111
11865
|
apply: pipe(
|
|
11112
11866
|
applyAtNode(sourceFile, node, false),
|
|
11113
11867
|
provideService(TypeCheckerApi, typeChecker),
|
|
11868
|
+
provideService(TypeScriptUtils, tsUtils),
|
|
11114
11869
|
provideService(TypeScriptApi, ts)
|
|
11115
11870
|
)
|
|
11116
11871
|
};
|
|
@@ -11123,6 +11878,7 @@ var typeToEffectSchemaClass = createRefactor({
|
|
|
11123
11878
|
description: "Refactor to Schema.Class",
|
|
11124
11879
|
apply: fn("typeToEffectSchemaClass.apply")(function* (sourceFile, textRange) {
|
|
11125
11880
|
const ts = yield* service(TypeScriptApi);
|
|
11881
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
11126
11882
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
11127
11883
|
const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
|
|
11128
11884
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -11133,6 +11889,7 @@ var typeToEffectSchemaClass = createRefactor({
|
|
|
11133
11889
|
apply: pipe(
|
|
11134
11890
|
applyAtNode(sourceFile, node, true),
|
|
11135
11891
|
provideService(TypeCheckerApi, typeChecker),
|
|
11892
|
+
provideService(TypeScriptUtils, tsUtils),
|
|
11136
11893
|
provideService(TypeScriptApi, ts)
|
|
11137
11894
|
)
|
|
11138
11895
|
};
|
|
@@ -11145,6 +11902,7 @@ var wrapWithEffectGen = createRefactor({
|
|
|
11145
11902
|
description: "Wrap with Effect.gen",
|
|
11146
11903
|
apply: fn("wrapWithEffectGen.apply")(function* (sourceFile, textRange) {
|
|
11147
11904
|
const ts = yield* service(TypeScriptApi);
|
|
11905
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
11148
11906
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
11149
11907
|
const typeParser = yield* service(TypeParser);
|
|
11150
11908
|
const findEffectToWrap = fn("wrapWithEffectGen.apply.findEffectToWrap")(
|
|
@@ -11158,37 +11916,26 @@ var wrapWithEffectGen = createRefactor({
|
|
|
11158
11916
|
}
|
|
11159
11917
|
);
|
|
11160
11918
|
const maybeNode = yield* pipe(
|
|
11161
|
-
|
|
11162
|
-
|
|
11919
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
11920
|
+
map4(findEffectToWrap),
|
|
11163
11921
|
firstSuccessOf,
|
|
11164
11922
|
option
|
|
11165
11923
|
);
|
|
11166
11924
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
11167
|
-
const effectModuleIdentifier =
|
|
11168
|
-
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
|
|
11172
|
-
typeParser.importedEffectModule(node),
|
|
11173
|
-
option,
|
|
11174
|
-
map4(isSome2)
|
|
11175
|
-
)
|
|
11176
|
-
)
|
|
11177
|
-
),
|
|
11178
|
-
{
|
|
11179
|
-
onNone: () => "Effect",
|
|
11180
|
-
onSome: (node) => node.text
|
|
11181
|
-
}
|
|
11182
|
-
);
|
|
11925
|
+
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
11926
|
+
sourceFile,
|
|
11927
|
+
"effect",
|
|
11928
|
+
"Effect"
|
|
11929
|
+
) || "Effect";
|
|
11183
11930
|
return {
|
|
11184
11931
|
kind: "refactor.rewrite.effect.wrapWithEffectGen",
|
|
11185
11932
|
description: `Wrap with Effect.gen`,
|
|
11186
11933
|
apply: pipe(
|
|
11187
11934
|
gen(function* () {
|
|
11188
11935
|
const changeTracker = yield* service(ChangeTracker);
|
|
11189
|
-
const effectGen =
|
|
11936
|
+
const effectGen = tsUtils.createEffectGenCallExpressionWithBlock(
|
|
11190
11937
|
effectModuleIdentifier,
|
|
11191
|
-
|
|
11938
|
+
tsUtils.createReturnYieldStarStatement(maybeNode.value)
|
|
11192
11939
|
);
|
|
11193
11940
|
changeTracker.replaceNode(sourceFile, maybeNode.value, effectGen);
|
|
11194
11941
|
}),
|
|
@@ -11219,273 +11966,6 @@ var wrapWithPipe = createRefactor({
|
|
|
11219
11966
|
})
|
|
11220
11967
|
});
|
|
11221
11968
|
|
|
11222
|
-
// src/refactors/writeTagClassAccessors.ts
|
|
11223
|
-
var writeTagClassAccessors = createRefactor({
|
|
11224
|
-
name: "writeTagClassAccessors",
|
|
11225
|
-
description: "Implement Service accessors",
|
|
11226
|
-
apply: fn("writeTagClassAccessors.apply")(function* (sourceFile, textRange) {
|
|
11227
|
-
const ts = yield* service(TypeScriptApi);
|
|
11228
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
11229
|
-
const typeParser = yield* service(TypeParser);
|
|
11230
|
-
const effectIdentifier = pipe(
|
|
11231
|
-
yield* option(
|
|
11232
|
-
findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", "Effect")
|
|
11233
|
-
),
|
|
11234
|
-
match({
|
|
11235
|
-
onNone: () => "Effect",
|
|
11236
|
-
onSome: (_) => _.text
|
|
11237
|
-
})
|
|
11238
|
-
);
|
|
11239
|
-
const createConstantProperty = (className, propertyName, type) => ts.factory.createPropertyDeclaration(
|
|
11240
|
-
[ts.factory.createModifier(ts.SyntaxKind.StaticKeyword)],
|
|
11241
|
-
propertyName,
|
|
11242
|
-
void 0,
|
|
11243
|
-
type,
|
|
11244
|
-
ts.factory.createCallExpression(
|
|
11245
|
-
ts.factory.createPropertyAccessExpression(
|
|
11246
|
-
ts.factory.createIdentifier(effectIdentifier),
|
|
11247
|
-
"andThen"
|
|
11248
|
-
),
|
|
11249
|
-
void 0,
|
|
11250
|
-
[
|
|
11251
|
-
ts.factory.createIdentifier(className.text),
|
|
11252
|
-
ts.factory.createArrowFunction(
|
|
11253
|
-
void 0,
|
|
11254
|
-
void 0,
|
|
11255
|
-
[ts.factory.createParameterDeclaration(
|
|
11256
|
-
void 0,
|
|
11257
|
-
void 0,
|
|
11258
|
-
"_"
|
|
11259
|
-
)],
|
|
11260
|
-
void 0,
|
|
11261
|
-
void 0,
|
|
11262
|
-
ts.factory.createPropertyAccessExpression(
|
|
11263
|
-
ts.factory.createIdentifier("_"),
|
|
11264
|
-
propertyName
|
|
11265
|
-
)
|
|
11266
|
-
)
|
|
11267
|
-
]
|
|
11268
|
-
)
|
|
11269
|
-
);
|
|
11270
|
-
const createFunctionProperty = (className, propertyName, type, forceAny) => {
|
|
11271
|
-
const arrowBody = ts.factory.createCallExpression(
|
|
11272
|
-
ts.factory.createPropertyAccessExpression(
|
|
11273
|
-
ts.factory.createIdentifier(effectIdentifier),
|
|
11274
|
-
"andThen"
|
|
11275
|
-
),
|
|
11276
|
-
void 0,
|
|
11277
|
-
[
|
|
11278
|
-
ts.factory.createIdentifier(className.text),
|
|
11279
|
-
ts.factory.createArrowFunction(
|
|
11280
|
-
void 0,
|
|
11281
|
-
void 0,
|
|
11282
|
-
[ts.factory.createParameterDeclaration(
|
|
11283
|
-
void 0,
|
|
11284
|
-
void 0,
|
|
11285
|
-
"_",
|
|
11286
|
-
void 0,
|
|
11287
|
-
forceAny ? ts.factory.createTypeReferenceNode("any") : void 0
|
|
11288
|
-
)],
|
|
11289
|
-
void 0,
|
|
11290
|
-
void 0,
|
|
11291
|
-
ts.factory.createCallExpression(
|
|
11292
|
-
ts.factory.createPropertyAccessExpression(
|
|
11293
|
-
ts.factory.createIdentifier("_"),
|
|
11294
|
-
propertyName
|
|
11295
|
-
),
|
|
11296
|
-
void 0,
|
|
11297
|
-
[
|
|
11298
|
-
ts.factory.createSpreadElement(ts.factory.createIdentifier("args"))
|
|
11299
|
-
]
|
|
11300
|
-
)
|
|
11301
|
-
)
|
|
11302
|
-
]
|
|
11303
|
-
);
|
|
11304
|
-
return ts.factory.createPropertyDeclaration(
|
|
11305
|
-
[ts.factory.createModifier(ts.SyntaxKind.StaticKeyword)],
|
|
11306
|
-
propertyName,
|
|
11307
|
-
void 0,
|
|
11308
|
-
type,
|
|
11309
|
-
ts.factory.createArrowFunction(
|
|
11310
|
-
void 0,
|
|
11311
|
-
void 0,
|
|
11312
|
-
[ts.factory.createParameterDeclaration(
|
|
11313
|
-
void 0,
|
|
11314
|
-
ts.factory.createToken(ts.SyntaxKind.DotDotDotToken),
|
|
11315
|
-
"args",
|
|
11316
|
-
void 0,
|
|
11317
|
-
forceAny ? ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode("any")) : void 0
|
|
11318
|
-
)],
|
|
11319
|
-
void 0,
|
|
11320
|
-
void 0,
|
|
11321
|
-
forceAny ? ts.factory.createAsExpression(arrowBody, ts.factory.createTypeReferenceNode("any")) : arrowBody
|
|
11322
|
-
)
|
|
11323
|
-
);
|
|
11324
|
-
};
|
|
11325
|
-
const generateReturnType = (type, atLocation, className) => pipe(
|
|
11326
|
-
typeParser.effectType(type, atLocation),
|
|
11327
|
-
flatMap2((returnedEffect) => {
|
|
11328
|
-
const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(className.text) : ts.factory.createUnionTypeNode(
|
|
11329
|
-
[
|
|
11330
|
-
ts.factory.createTypeReferenceNode(className.text),
|
|
11331
|
-
typeChecker.typeToTypeNode(returnedEffect.R, atLocation, ts.NodeBuilderFlags.NoTruncation)
|
|
11332
|
-
]
|
|
11333
|
-
);
|
|
11334
|
-
const successType = typeChecker.typeToTypeNode(
|
|
11335
|
-
returnedEffect.A,
|
|
11336
|
-
atLocation,
|
|
11337
|
-
ts.NodeBuilderFlags.NoTruncation
|
|
11338
|
-
);
|
|
11339
|
-
if (!successType) return fail("error generating success type");
|
|
11340
|
-
const failureType = typeChecker.typeToTypeNode(
|
|
11341
|
-
returnedEffect.E,
|
|
11342
|
-
atLocation,
|
|
11343
|
-
ts.NodeBuilderFlags.NoTruncation
|
|
11344
|
-
);
|
|
11345
|
-
if (!failureType) return fail("error generating failure type");
|
|
11346
|
-
const typeNode = ts.factory.createTypeReferenceNode(
|
|
11347
|
-
ts.factory.createQualifiedName(
|
|
11348
|
-
ts.factory.createIdentifier(effectIdentifier),
|
|
11349
|
-
ts.factory.createIdentifier("Effect")
|
|
11350
|
-
),
|
|
11351
|
-
[successType, failureType, contextType]
|
|
11352
|
-
);
|
|
11353
|
-
return succeed(typeNode);
|
|
11354
|
-
}),
|
|
11355
|
-
orElse2(
|
|
11356
|
-
() => pipe(
|
|
11357
|
-
typeParser.promiseLike(type, atLocation),
|
|
11358
|
-
flatMap2(({ type: type2 }) => {
|
|
11359
|
-
const successType = typeChecker.typeToTypeNode(
|
|
11360
|
-
type2,
|
|
11361
|
-
atLocation,
|
|
11362
|
-
ts.NodeBuilderFlags.NoTruncation
|
|
11363
|
-
);
|
|
11364
|
-
if (!successType) return fail("error generating success type");
|
|
11365
|
-
return succeed(ts.factory.createTypeReferenceNode(
|
|
11366
|
-
ts.factory.createQualifiedName(
|
|
11367
|
-
ts.factory.createIdentifier(effectIdentifier),
|
|
11368
|
-
ts.factory.createIdentifier("Effect")
|
|
11369
|
-
),
|
|
11370
|
-
[
|
|
11371
|
-
successType,
|
|
11372
|
-
ts.factory.createTypeReferenceNode(
|
|
11373
|
-
ts.factory.createQualifiedName(
|
|
11374
|
-
ts.factory.createIdentifier("Cause"),
|
|
11375
|
-
ts.factory.createIdentifier("UnknownException")
|
|
11376
|
-
)
|
|
11377
|
-
),
|
|
11378
|
-
ts.factory.createTypeReferenceNode(className.text)
|
|
11379
|
-
]
|
|
11380
|
-
));
|
|
11381
|
-
})
|
|
11382
|
-
)
|
|
11383
|
-
),
|
|
11384
|
-
orElse2(() => {
|
|
11385
|
-
const successType = typeChecker.typeToTypeNode(type, atLocation, ts.NodeBuilderFlags.NoTruncation);
|
|
11386
|
-
if (!successType) return fail("error generating success type");
|
|
11387
|
-
const typeNode = ts.factory.createTypeReferenceNode(
|
|
11388
|
-
ts.factory.createQualifiedName(
|
|
11389
|
-
ts.factory.createIdentifier(effectIdentifier),
|
|
11390
|
-
ts.factory.createIdentifier("Effect")
|
|
11391
|
-
),
|
|
11392
|
-
[
|
|
11393
|
-
successType,
|
|
11394
|
-
ts.factory.createTypeReferenceNode("never"),
|
|
11395
|
-
ts.factory.createTypeReferenceNode(className.text)
|
|
11396
|
-
]
|
|
11397
|
-
);
|
|
11398
|
-
return succeed(typeNode);
|
|
11399
|
-
})
|
|
11400
|
-
);
|
|
11401
|
-
const proxySignature = (signature, atLocation, className) => gen(function* () {
|
|
11402
|
-
const signatureDeclaration = typeChecker.signatureToSignatureDeclaration(
|
|
11403
|
-
signature,
|
|
11404
|
-
ts.SyntaxKind.FunctionType,
|
|
11405
|
-
atLocation,
|
|
11406
|
-
ts.NodeBuilderFlags.NoTruncation
|
|
11407
|
-
);
|
|
11408
|
-
if (!signatureDeclaration) return yield* fail("error generating signature");
|
|
11409
|
-
const returnType = yield* generateReturnType(signature.getReturnType(), atLocation, className);
|
|
11410
|
-
return ts.factory.createFunctionTypeNode(
|
|
11411
|
-
signatureDeclaration.typeParameters,
|
|
11412
|
-
signatureDeclaration.parameters,
|
|
11413
|
-
returnType
|
|
11414
|
-
);
|
|
11415
|
-
});
|
|
11416
|
-
const writeAccessors = fn("writeTagClassAccessors.writeAccessors")(
|
|
11417
|
-
function* (service2, className, atLocation) {
|
|
11418
|
-
const changeTracker = yield* service(ChangeTracker);
|
|
11419
|
-
const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.getEnd() - 1;
|
|
11420
|
-
for (const property of typeChecker.getPropertiesOfType(service2)) {
|
|
11421
|
-
const servicePropertyType = typeChecker.getTypeOfSymbolAtLocation(property, atLocation);
|
|
11422
|
-
const callSignatures = [];
|
|
11423
|
-
let propertyDeclaration = void 0;
|
|
11424
|
-
for (const signature of servicePropertyType.getCallSignatures()) {
|
|
11425
|
-
yield* pipe(
|
|
11426
|
-
proxySignature(signature, atLocation, className),
|
|
11427
|
-
map4((sig) => {
|
|
11428
|
-
callSignatures.push(sig);
|
|
11429
|
-
}),
|
|
11430
|
-
ignore
|
|
11431
|
-
);
|
|
11432
|
-
}
|
|
11433
|
-
if (callSignatures.length === 0) {
|
|
11434
|
-
yield* pipe(
|
|
11435
|
-
generateReturnType(servicePropertyType, atLocation, className),
|
|
11436
|
-
map4((type) => {
|
|
11437
|
-
propertyDeclaration = createConstantProperty(className, property.getName(), type);
|
|
11438
|
-
}),
|
|
11439
|
-
ignore
|
|
11440
|
-
);
|
|
11441
|
-
} else {
|
|
11442
|
-
const allSignatures = ts.factory.createIntersectionTypeNode(callSignatures);
|
|
11443
|
-
const type = yield* simplifyTypeNode(allSignatures);
|
|
11444
|
-
propertyDeclaration = createFunctionProperty(className, property.getName(), type, callSignatures.length > 1);
|
|
11445
|
-
}
|
|
11446
|
-
if (propertyDeclaration) {
|
|
11447
|
-
const oldProperty = atLocation.members.filter(ts.isPropertyDeclaration).find((p) => {
|
|
11448
|
-
const symbol3 = typeChecker.getSymbolAtLocation(p.name);
|
|
11449
|
-
return symbol3?.getName() === property.getName();
|
|
11450
|
-
});
|
|
11451
|
-
if (oldProperty) {
|
|
11452
|
-
changeTracker.deleteRange(sourceFile, {
|
|
11453
|
-
pos: oldProperty.getStart(sourceFile),
|
|
11454
|
-
end: oldProperty.getEnd()
|
|
11455
|
-
});
|
|
11456
|
-
changeTracker.insertNodeAt(sourceFile, oldProperty.getStart(sourceFile), propertyDeclaration);
|
|
11457
|
-
} else {
|
|
11458
|
-
changeTracker.insertNodeAt(sourceFile, insertLocation, propertyDeclaration, { suffix: "\n" });
|
|
11459
|
-
}
|
|
11460
|
-
}
|
|
11461
|
-
}
|
|
11462
|
-
}
|
|
11463
|
-
);
|
|
11464
|
-
const writeTagClassAccessors2 = (node) => gen(function* () {
|
|
11465
|
-
if (!ts.isClassDeclaration(node)) return yield* fail(new RefactorNotApplicableError());
|
|
11466
|
-
if (!node.name) return yield* fail(new RefactorNotApplicableError());
|
|
11467
|
-
const classSym = typeChecker.getSymbolAtLocation(node.name);
|
|
11468
|
-
if (!classSym) return yield* fail(new RefactorNotApplicableError());
|
|
11469
|
-
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
11470
|
-
const { Service } = yield* pipe(
|
|
11471
|
-
typeParser.contextTag(type, node),
|
|
11472
|
-
orElse2(() => fail(new RefactorNotApplicableError()))
|
|
11473
|
-
);
|
|
11474
|
-
return {
|
|
11475
|
-
kind: "refactor.rewrite.effect.writeTagClassAccessors",
|
|
11476
|
-
description: "Implement Service accessors",
|
|
11477
|
-
apply: pipe(
|
|
11478
|
-
writeAccessors(Service, node.name, node),
|
|
11479
|
-
provideService(TypeCheckerApi, typeChecker),
|
|
11480
|
-
provideService(TypeScriptApi, ts)
|
|
11481
|
-
)
|
|
11482
|
-
};
|
|
11483
|
-
});
|
|
11484
|
-
const parentNodes = yield* getAncestorNodesInRange(sourceFile, textRange);
|
|
11485
|
-
return yield* firstSuccessOf(parentNodes.map(writeTagClassAccessors2));
|
|
11486
|
-
})
|
|
11487
|
-
});
|
|
11488
|
-
|
|
11489
11969
|
// src/refactors.ts
|
|
11490
11970
|
var refactors = [
|
|
11491
11971
|
asyncAwaitToGen,
|
|
@@ -11536,13 +12016,10 @@ var init = (modules) => {
|
|
|
11536
12016
|
function runNano(program) {
|
|
11537
12017
|
return (fa) => pipe(
|
|
11538
12018
|
fa,
|
|
11539
|
-
|
|
11540
|
-
|
|
12019
|
+
nanoLayer2,
|
|
12020
|
+
nanoLayer,
|
|
11541
12021
|
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
11542
|
-
provideService(
|
|
11543
|
-
TypeCheckerApiCache,
|
|
11544
|
-
makeTypeCheckerApiCache()
|
|
11545
|
-
),
|
|
12022
|
+
provideService(TypeScriptProgram, program),
|
|
11546
12023
|
provideService(TypeScriptApi, modules.typescript),
|
|
11547
12024
|
provideService(
|
|
11548
12025
|
LanguageServicePluginOptions,
|
|
@@ -11626,7 +12103,7 @@ var init = (modules) => {
|
|
|
11626
12103
|
}
|
|
11627
12104
|
return effectCodeFixes;
|
|
11628
12105
|
}),
|
|
11629
|
-
|
|
12106
|
+
flatMap(
|
|
11630
12107
|
(effectCodeFixes) => pipe(
|
|
11631
12108
|
middlewareAutoImportQuickfixes(
|
|
11632
12109
|
sourceFile,
|
|
@@ -11635,7 +12112,7 @@ var init = (modules) => {
|
|
|
11635
12112
|
preferences,
|
|
11636
12113
|
applicableCodeFixes
|
|
11637
12114
|
),
|
|
11638
|
-
|
|
12115
|
+
map3((modifiedCodeFixes) => effectCodeFixes.concat(modifiedCodeFixes))
|
|
11639
12116
|
)
|
|
11640
12117
|
),
|
|
11641
12118
|
runNano(program),
|
|
@@ -11744,7 +12221,7 @@ var init = (modules) => {
|
|
|
11744
12221
|
if (sourceFile) {
|
|
11745
12222
|
return pipe(
|
|
11746
12223
|
appendEffectCompletionEntryData(sourceFile, applicableCompletions),
|
|
11747
|
-
|
|
12224
|
+
flatMap(
|
|
11748
12225
|
(augmentedCompletions) => pipe(
|
|
11749
12226
|
getCompletionsAtPosition(
|
|
11750
12227
|
completions,
|
|
@@ -11753,7 +12230,7 @@ var init = (modules) => {
|
|
|
11753
12230
|
options,
|
|
11754
12231
|
formattingSettings
|
|
11755
12232
|
),
|
|
11756
|
-
|
|
12233
|
+
map3(
|
|
11757
12234
|
(effectCompletions) => augmentedCompletions ? {
|
|
11758
12235
|
...augmentedCompletions,
|
|
11759
12236
|
entries: effectCompletions.concat(augmentedCompletions.entries)
|