@effect/language-service 0.17.1 → 0.19.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 +3 -1
- package/index.js +883 -276
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +761 -143
- package/transform.js.map +1 -1
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __export = (target, all3) => {
|
|
|
5
5
|
__defProp(target, name, { get: all3[name], enumerable: true });
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
// node_modules/.pnpm/effect@3.
|
|
8
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Function.js
|
|
9
9
|
var isFunction = (input) => typeof input === "function";
|
|
10
10
|
var dual = function(arity, body) {
|
|
11
11
|
if (typeof arity === "function") {
|
|
@@ -102,7 +102,7 @@ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
// node_modules/.pnpm/effect@3.
|
|
105
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Either.js
|
|
106
106
|
var Either_exports = {};
|
|
107
107
|
__export(Either_exports, {
|
|
108
108
|
Do: () => Do,
|
|
@@ -139,11 +139,14 @@ __export(Either_exports, {
|
|
|
139
139
|
merge: () => merge,
|
|
140
140
|
orElse: () => orElse,
|
|
141
141
|
right: () => right2,
|
|
142
|
+
transposeMapOption: () => transposeMapOption,
|
|
143
|
+
transposeOption: () => transposeOption,
|
|
142
144
|
try: () => try_,
|
|
145
|
+
void: () => void_,
|
|
143
146
|
zipWith: () => zipWith
|
|
144
147
|
});
|
|
145
148
|
|
|
146
|
-
// node_modules/.pnpm/effect@3.
|
|
149
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Equivalence.js
|
|
147
150
|
var make = (isEquivalent) => (self, that) => self === that || isEquivalent(self, that);
|
|
148
151
|
var array = (item) => make((self, that) => {
|
|
149
152
|
if (self.length !== that.length) {
|
|
@@ -158,7 +161,7 @@ var array = (item) => make((self, that) => {
|
|
|
158
161
|
return true;
|
|
159
162
|
});
|
|
160
163
|
|
|
161
|
-
// node_modules/.pnpm/effect@3.
|
|
164
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/internal/doNotation.js
|
|
162
165
|
var let_ = (map5) => dual(3, (self, name, f) => map5(self, (a) => Object.assign({}, a, {
|
|
163
166
|
[name]: f(a)
|
|
164
167
|
})));
|
|
@@ -169,11 +172,11 @@ var bind = (map5, flatMap4) => dual(3, (self, name, f) => flatMap4(self, (a) =>
|
|
|
169
172
|
[name]: b
|
|
170
173
|
}))));
|
|
171
174
|
|
|
172
|
-
// node_modules/.pnpm/effect@3.
|
|
173
|
-
var moduleVersion = "3.
|
|
175
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/internal/version.js
|
|
176
|
+
var moduleVersion = "3.16.3";
|
|
174
177
|
var getCurrentVersion = () => moduleVersion;
|
|
175
178
|
|
|
176
|
-
// node_modules/.pnpm/effect@3.
|
|
179
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/GlobalValue.js
|
|
177
180
|
var globalStoreId = `effect/GlobalValue/globalStoreId/${/* @__PURE__ */ getCurrentVersion()}`;
|
|
178
181
|
var globalStore;
|
|
179
182
|
var globalValue = (id, compute) => {
|
|
@@ -187,16 +190,19 @@ var globalValue = (id, compute) => {
|
|
|
187
190
|
return globalStore.get(id);
|
|
188
191
|
};
|
|
189
192
|
|
|
190
|
-
// node_modules/.pnpm/effect@3.
|
|
193
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Predicate.js
|
|
194
|
+
var isString = (input) => typeof input === "string";
|
|
195
|
+
var isNumber = (input) => typeof input === "number";
|
|
196
|
+
var isBoolean = (input) => typeof input === "boolean";
|
|
191
197
|
var isFunction2 = isFunction;
|
|
192
198
|
var isRecordOrArray = (input) => typeof input === "object" && input !== null;
|
|
193
199
|
var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
|
|
194
200
|
var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObject(self) && property in self);
|
|
195
201
|
|
|
196
|
-
// node_modules/.pnpm/effect@3.
|
|
202
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/internal/errors.js
|
|
197
203
|
var getBugErrorMessage = (message) => `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`;
|
|
198
204
|
|
|
199
|
-
// node_modules/.pnpm/effect@3.
|
|
205
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Utils.js
|
|
200
206
|
var GenKindTypeId = /* @__PURE__ */ Symbol.for("effect/Gen/GenKind");
|
|
201
207
|
var isGenKind = (u) => isObject(u) && GenKindTypeId in u;
|
|
202
208
|
var GenKindImpl = class {
|
|
@@ -314,10 +320,25 @@ var structuralRegionState = /* @__PURE__ */ globalValue("effect/Utils/isStructur
|
|
|
314
320
|
enabled: false,
|
|
315
321
|
tester: void 0
|
|
316
322
|
}));
|
|
323
|
+
var standard = {
|
|
324
|
+
effect_internal_function: (body) => {
|
|
325
|
+
return body();
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
var forced = {
|
|
329
|
+
effect_internal_function: (body) => {
|
|
330
|
+
try {
|
|
331
|
+
return body();
|
|
332
|
+
} finally {
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
var isNotOptimizedAway = /* @__PURE__ */ standard.effect_internal_function(() => new Error().stack)?.includes("effect_internal_function") === true;
|
|
337
|
+
var internalCall = isNotOptimizedAway ? standard.effect_internal_function : forced.effect_internal_function;
|
|
317
338
|
var genConstructor = function* () {
|
|
318
339
|
}.constructor;
|
|
319
340
|
|
|
320
|
-
// node_modules/.pnpm/effect@3.
|
|
341
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Hash.js
|
|
321
342
|
var randomHashCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Hash/randomHashCache"), () => /* @__PURE__ */ new WeakMap());
|
|
322
343
|
var symbol = /* @__PURE__ */ Symbol.for("effect/Hash");
|
|
323
344
|
var hash = (self) => {
|
|
@@ -343,6 +364,8 @@ var hash = (self) => {
|
|
|
343
364
|
return string("null");
|
|
344
365
|
} else if (self instanceof Date) {
|
|
345
366
|
return hash(self.toISOString());
|
|
367
|
+
} else if (self instanceof URL) {
|
|
368
|
+
return hash(self.href);
|
|
346
369
|
} else if (isHash(self)) {
|
|
347
370
|
return self[symbol]();
|
|
348
371
|
} else {
|
|
@@ -414,7 +437,7 @@ var cached = function() {
|
|
|
414
437
|
return hash2;
|
|
415
438
|
};
|
|
416
439
|
|
|
417
|
-
// node_modules/.pnpm/effect@3.
|
|
440
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Equal.js
|
|
418
441
|
var symbol2 = /* @__PURE__ */ Symbol.for("effect/Equal");
|
|
419
442
|
function equals() {
|
|
420
443
|
if (arguments.length === 1) {
|
|
@@ -440,6 +463,8 @@ function compareBoth(self, that) {
|
|
|
440
463
|
}
|
|
441
464
|
} else if (self instanceof Date && that instanceof Date) {
|
|
442
465
|
return self.toISOString() === that.toISOString();
|
|
466
|
+
} else if (self instanceof URL && that instanceof URL) {
|
|
467
|
+
return self.href === that.href;
|
|
443
468
|
}
|
|
444
469
|
}
|
|
445
470
|
if (structuralRegionState.enabled) {
|
|
@@ -465,7 +490,7 @@ function compareBoth(self, that) {
|
|
|
465
490
|
}
|
|
466
491
|
var isEqual = (u) => hasProperty(u, symbol2);
|
|
467
492
|
|
|
468
|
-
// node_modules/.pnpm/effect@3.
|
|
493
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Inspectable.js
|
|
469
494
|
var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
470
495
|
var toJSON = (x) => {
|
|
471
496
|
try {
|
|
@@ -474,7 +499,7 @@ var toJSON = (x) => {
|
|
|
474
499
|
} else if (Array.isArray(x)) {
|
|
475
500
|
return x.map(toJSON);
|
|
476
501
|
}
|
|
477
|
-
} catch
|
|
502
|
+
} catch {
|
|
478
503
|
return {};
|
|
479
504
|
}
|
|
480
505
|
return redact(x);
|
|
@@ -517,7 +542,7 @@ var redact = (u) => {
|
|
|
517
542
|
return u;
|
|
518
543
|
};
|
|
519
544
|
|
|
520
|
-
// node_modules/.pnpm/effect@3.
|
|
545
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Pipeable.js
|
|
521
546
|
var pipeArguments = (self, args) => {
|
|
522
547
|
switch (args.length) {
|
|
523
548
|
case 0:
|
|
@@ -550,10 +575,10 @@ var pipeArguments = (self, args) => {
|
|
|
550
575
|
}
|
|
551
576
|
};
|
|
552
577
|
|
|
553
|
-
// node_modules/.pnpm/effect@3.
|
|
578
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/internal/opCodes/effect.js
|
|
554
579
|
var OP_COMMIT = "Commit";
|
|
555
580
|
|
|
556
|
-
// node_modules/.pnpm/effect@3.
|
|
581
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/internal/effectable.js
|
|
557
582
|
var EffectTypeId = /* @__PURE__ */ Symbol.for("effect/Effect");
|
|
558
583
|
var StreamTypeId = /* @__PURE__ */ Symbol.for("effect/Stream");
|
|
559
584
|
var SinkTypeId = /* @__PURE__ */ Symbol.for("effect/Sink");
|
|
@@ -640,7 +665,7 @@ var StructuralCommitPrototype = {
|
|
|
640
665
|
...StructuralPrototype
|
|
641
666
|
};
|
|
642
667
|
|
|
643
|
-
// node_modules/.pnpm/effect@3.
|
|
668
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/internal/option.js
|
|
644
669
|
var TypeId = /* @__PURE__ */ Symbol.for("effect/Option");
|
|
645
670
|
var CommonProto = {
|
|
646
671
|
...EffectPrototype,
|
|
@@ -698,7 +723,7 @@ var some = (value) => {
|
|
|
698
723
|
return a;
|
|
699
724
|
};
|
|
700
725
|
|
|
701
|
-
// node_modules/.pnpm/effect@3.
|
|
726
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/internal/either.js
|
|
702
727
|
var TypeId2 = /* @__PURE__ */ Symbol.for("effect/Either");
|
|
703
728
|
var CommonProto2 = {
|
|
704
729
|
...EffectPrototype,
|
|
@@ -763,9 +788,10 @@ var getLeft = (self) => isRight(self) ? none : some(self.left);
|
|
|
763
788
|
var getRight = (self) => isLeft(self) ? none : some(self.right);
|
|
764
789
|
var fromOption = /* @__PURE__ */ dual(2, (self, onNone) => isNone(self) ? left(onNone()) : right(self.value));
|
|
765
790
|
|
|
766
|
-
// node_modules/.pnpm/effect@3.
|
|
791
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Either.js
|
|
767
792
|
var TypeId3 = TypeId2;
|
|
768
793
|
var right2 = right;
|
|
794
|
+
var void_ = /* @__PURE__ */ right2(void 0);
|
|
769
795
|
var left2 = left;
|
|
770
796
|
var fromNullable = /* @__PURE__ */ dual(2, (self, onNullable) => self == null ? left2(onNullable(self)) : right2(self));
|
|
771
797
|
var fromOption2 = fromOption;
|
|
@@ -854,47 +880,31 @@ var gen = (...args) => {
|
|
|
854
880
|
const f = args.length === 1 ? args[0] : args[1].bind(args[0]);
|
|
855
881
|
const iterator = f(adapter2);
|
|
856
882
|
let state = iterator.next();
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
} else {
|
|
860
|
-
let current = state.value;
|
|
861
|
-
if (isGenKind(current)) {
|
|
862
|
-
current = current.value;
|
|
863
|
-
} else {
|
|
864
|
-
current = yieldWrapGet(current);
|
|
865
|
-
}
|
|
883
|
+
while (!state.done) {
|
|
884
|
+
const current = isGenKind(state.value) ? state.value.value : yieldWrapGet(state.value);
|
|
866
885
|
if (isLeft2(current)) {
|
|
867
886
|
return current;
|
|
868
887
|
}
|
|
869
|
-
|
|
870
|
-
state = iterator.next(current.right);
|
|
871
|
-
if (!state.done) {
|
|
872
|
-
current = state.value;
|
|
873
|
-
if (isGenKind(current)) {
|
|
874
|
-
current = current.value;
|
|
875
|
-
} else {
|
|
876
|
-
current = yieldWrapGet(current);
|
|
877
|
-
}
|
|
878
|
-
if (isLeft2(current)) {
|
|
879
|
-
return current;
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
return right2(state.value);
|
|
888
|
+
state = iterator.next(current.right);
|
|
884
889
|
}
|
|
890
|
+
return right2(state.value);
|
|
885
891
|
};
|
|
886
892
|
var Do = /* @__PURE__ */ right2({});
|
|
887
893
|
var bind2 = /* @__PURE__ */ bind(map, flatMap);
|
|
888
894
|
var bindTo2 = /* @__PURE__ */ bindTo(map);
|
|
889
895
|
var let_2 = /* @__PURE__ */ let_(map);
|
|
896
|
+
var transposeOption = (self) => {
|
|
897
|
+
return isNone(self) ? right2(none) : map(self.value, some);
|
|
898
|
+
};
|
|
899
|
+
var transposeMapOption = /* @__PURE__ */ dual(2, (self, f) => isNone(self) ? right2(none) : map(f(self.value), some));
|
|
890
900
|
|
|
891
|
-
// node_modules/.pnpm/effect@3.
|
|
901
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/internal/array.js
|
|
892
902
|
var isNonEmptyArray = (self) => self.length > 0;
|
|
893
903
|
|
|
894
|
-
// node_modules/.pnpm/effect@3.
|
|
904
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Order.js
|
|
895
905
|
var make2 = (compare) => (self, that) => self === that ? 0 : compare(self, that);
|
|
896
906
|
|
|
897
|
-
// node_modules/.pnpm/effect@3.
|
|
907
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Option.js
|
|
898
908
|
var none2 = () => none;
|
|
899
909
|
var some2 = some;
|
|
900
910
|
var isNone2 = isNone;
|
|
@@ -909,21 +919,22 @@ var fromNullable2 = (nullableValue) => nullableValue == null ? none2() : some2(n
|
|
|
909
919
|
var getOrUndefined2 = /* @__PURE__ */ getOrElse2(constUndefined);
|
|
910
920
|
var map2 = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() : some2(f(self.value)));
|
|
911
921
|
|
|
912
|
-
// node_modules/.pnpm/effect@3.
|
|
922
|
+
// node_modules/.pnpm/effect@3.16.3/node_modules/effect/dist/esm/Array.js
|
|
913
923
|
var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
|
|
914
924
|
var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
|
|
925
|
+
var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
|
|
915
926
|
var isArray = Array.isArray;
|
|
916
927
|
var isEmptyArray = (self) => self.length === 0;
|
|
917
928
|
var isEmptyReadonlyArray = isEmptyArray;
|
|
918
929
|
var isNonEmptyReadonlyArray = isNonEmptyArray;
|
|
919
|
-
var
|
|
930
|
+
var isOutOfBounds = (i, as) => i < 0 || i >= as.length;
|
|
920
931
|
var get = /* @__PURE__ */ dual(2, (self, index) => {
|
|
921
932
|
const i = Math.floor(index);
|
|
922
|
-
return
|
|
933
|
+
return isOutOfBounds(i, self) ? none2() : some2(self[i]);
|
|
923
934
|
});
|
|
924
935
|
var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
|
|
925
936
|
const i = Math.floor(index);
|
|
926
|
-
if (
|
|
937
|
+
if (isOutOfBounds(i, self)) {
|
|
927
938
|
throw new Error(`Index ${i} out of bounds`);
|
|
928
939
|
}
|
|
929
940
|
return self[i];
|
|
@@ -1414,7 +1425,10 @@ var parseDataForExtendsClassCompletion = fn(
|
|
|
1414
1425
|
"AST.parseDataForExtendsClassCompletion"
|
|
1415
1426
|
)(function* (sourceFile, position) {
|
|
1416
1427
|
const ts = yield* service(TypeScriptApi);
|
|
1417
|
-
const { accessedObject, outerNode, replacementSpan } = yield* parseAccessedExpressionForCompletion(
|
|
1428
|
+
const { accessedObject, outerNode, replacementSpan } = yield* parseAccessedExpressionForCompletion(
|
|
1429
|
+
sourceFile,
|
|
1430
|
+
position
|
|
1431
|
+
);
|
|
1418
1432
|
if (!ts.isIdentifier(accessedObject)) return yield* fail(new NodeNotFoundError());
|
|
1419
1433
|
let classDeclaration = outerNode.parent;
|
|
1420
1434
|
while (ts.isExpressionWithTypeArguments(classDeclaration) || ts.isHeritageClause(classDeclaration)) {
|
|
@@ -1482,29 +1496,20 @@ function createRefactor(definition) {
|
|
|
1482
1496
|
function createDiagnostic(definition) {
|
|
1483
1497
|
return definition;
|
|
1484
1498
|
}
|
|
1485
|
-
function parsePluginOptions(config) {
|
|
1486
|
-
return {
|
|
1487
|
-
diagnostics: config && "diagnostics" in config && typeof config.diagnostics === "boolean" ? config.diagnostics : true,
|
|
1488
|
-
quickinfo: config && "quickinfo" in config && typeof config.quickinfo === "boolean" ? config.quickinfo : true,
|
|
1489
|
-
completions: config && "completions" in config && typeof config.completions === "boolean" ? config.completions : true,
|
|
1490
|
-
multipleEffectCheck: config && "multipleEffectCheck" in config && typeof config.multipleEffectCheck === "boolean" ? config.multipleEffectCheck : true
|
|
1491
|
-
};
|
|
1492
|
-
}
|
|
1493
1499
|
function createCompletion(definition) {
|
|
1494
1500
|
return definition;
|
|
1495
1501
|
}
|
|
1496
|
-
var PluginOptions = Tag("PluginOptions");
|
|
1497
1502
|
var getSemanticDiagnosticsWithCodeFixes = fn(
|
|
1498
1503
|
"LSP.getSemanticDiagnosticsWithCodeFixes"
|
|
1499
1504
|
)(function* (rules, sourceFile) {
|
|
1500
|
-
|
|
1501
|
-
|
|
1505
|
+
let effectDiagnostics = [];
|
|
1506
|
+
let effectCodeFixes = [];
|
|
1502
1507
|
const executor = yield* createDiagnosticExecutor(sourceFile);
|
|
1503
1508
|
for (const rule of rules) {
|
|
1504
1509
|
const result = yield* option(executor.execute(rule));
|
|
1505
1510
|
if (isSome2(result)) {
|
|
1506
|
-
effectDiagnostics.
|
|
1507
|
-
|
|
1511
|
+
effectDiagnostics = effectDiagnostics.concat(
|
|
1512
|
+
pipe(
|
|
1508
1513
|
result.value,
|
|
1509
1514
|
map3((_) => ({
|
|
1510
1515
|
file: sourceFile,
|
|
@@ -1517,8 +1522,8 @@ var getSemanticDiagnosticsWithCodeFixes = fn(
|
|
|
1517
1522
|
}))
|
|
1518
1523
|
)
|
|
1519
1524
|
);
|
|
1520
|
-
effectCodeFixes.
|
|
1521
|
-
|
|
1525
|
+
effectCodeFixes = effectCodeFixes.concat(
|
|
1526
|
+
pipe(
|
|
1522
1527
|
result.value,
|
|
1523
1528
|
map3(
|
|
1524
1529
|
(_) => map3(
|
|
@@ -1541,6 +1546,9 @@ var getSemanticDiagnosticsWithCodeFixes = fn(
|
|
|
1541
1546
|
codeFixes: effectCodeFixes
|
|
1542
1547
|
};
|
|
1543
1548
|
});
|
|
1549
|
+
function refactorNameToFullyQualifiedName(name) {
|
|
1550
|
+
return `@effect/language-service/refactors/${name}`;
|
|
1551
|
+
}
|
|
1544
1552
|
var getApplicableRefactors = fn("LSP.getApplicableRefactors")(function* (refactors2, sourceFile, positionOrRange) {
|
|
1545
1553
|
const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
|
|
1546
1554
|
const effectRefactors = [];
|
|
@@ -1548,10 +1556,10 @@ var getApplicableRefactors = fn("LSP.getApplicableRefactors")(function* (refacto
|
|
|
1548
1556
|
const result = yield* option(refactor.apply(sourceFile, textRange));
|
|
1549
1557
|
if (isSome2(result)) {
|
|
1550
1558
|
effectRefactors.push({
|
|
1551
|
-
name: refactor.name,
|
|
1559
|
+
name: refactorNameToFullyQualifiedName(refactor.name),
|
|
1552
1560
|
description: refactor.description,
|
|
1553
1561
|
actions: [{
|
|
1554
|
-
name: refactor.name,
|
|
1562
|
+
name: refactorNameToFullyQualifiedName(refactor.name),
|
|
1555
1563
|
description: result.value.description,
|
|
1556
1564
|
kind: result.value.kind
|
|
1557
1565
|
}]
|
|
@@ -1561,7 +1569,7 @@ var getApplicableRefactors = fn("LSP.getApplicableRefactors")(function* (refacto
|
|
|
1561
1569
|
return effectRefactors;
|
|
1562
1570
|
});
|
|
1563
1571
|
var getEditsForRefactor = fn("LSP.getEditsForRefactor")(function* (refactors2, sourceFile, positionOrRange, refactorName) {
|
|
1564
|
-
const refactor = refactors2.find((refactor2) => refactor2.name === refactorName);
|
|
1572
|
+
const refactor = refactors2.find((refactor2) => refactorNameToFullyQualifiedName(refactor2.name) === refactorName);
|
|
1565
1573
|
if (!refactor) {
|
|
1566
1574
|
return yield* fail(new RefactorNotApplicableError());
|
|
1567
1575
|
}
|
|
@@ -1569,11 +1577,11 @@ var getEditsForRefactor = fn("LSP.getEditsForRefactor")(function* (refactors2, s
|
|
|
1569
1577
|
return yield* refactor.apply(sourceFile, textRange);
|
|
1570
1578
|
});
|
|
1571
1579
|
var getCompletionsAtPosition = fn("LSP.getCompletionsAtPosition")(function* (completions2, sourceFile, position, options, formatCodeSettings) {
|
|
1572
|
-
|
|
1580
|
+
let effectCompletions = [];
|
|
1573
1581
|
for (const completion of completions2) {
|
|
1574
1582
|
const result = yield* completion.apply(sourceFile, position, options, formatCodeSettings);
|
|
1575
|
-
effectCompletions.
|
|
1576
|
-
|
|
1583
|
+
effectCompletions = effectCompletions.concat(
|
|
1584
|
+
result.map((_) => ({ sortText: "11", ..._ }))
|
|
1577
1585
|
);
|
|
1578
1586
|
}
|
|
1579
1587
|
return effectCompletions;
|
|
@@ -1581,27 +1589,74 @@ var getCompletionsAtPosition = fn("LSP.getCompletionsAtPosition")(function* (com
|
|
|
1581
1589
|
var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
1582
1590
|
function* (sourceFile) {
|
|
1583
1591
|
const ts = yield* service(TypeScriptApi);
|
|
1584
|
-
|
|
1592
|
+
function findNodeWithLeadingCommentAtPosition(position) {
|
|
1593
|
+
const sourceText = sourceFile.text;
|
|
1594
|
+
let result;
|
|
1595
|
+
function find(node) {
|
|
1596
|
+
const leading = ts.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1597
|
+
if (leading) {
|
|
1598
|
+
for (const r of leading) {
|
|
1599
|
+
if (r.pos <= position && position < r.end) {
|
|
1600
|
+
result = node;
|
|
1601
|
+
return;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
if (node.getFullStart() <= position && position < node.getEnd()) {
|
|
1606
|
+
node.forEachChild(find);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
find(sourceFile);
|
|
1610
|
+
return result;
|
|
1611
|
+
}
|
|
1612
|
+
function findParentStatementForDisableNextLine(node) {
|
|
1613
|
+
let result;
|
|
1614
|
+
function find(node2) {
|
|
1615
|
+
if (ts.isStatement(node2)) {
|
|
1616
|
+
result = node2;
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
if (result) return;
|
|
1620
|
+
if (node2.parent) find(node2.parent);
|
|
1621
|
+
}
|
|
1622
|
+
find(node);
|
|
1623
|
+
return result || node;
|
|
1624
|
+
}
|
|
1625
|
+
const lineOverrides = {};
|
|
1626
|
+
const sectionOverrides = {};
|
|
1585
1627
|
const skippedRules = [];
|
|
1586
|
-
const regex = /@effect-diagnostics((?:\s[a-zA-Z0-9/]+:(?:off|warning|error|message|suggestion|skip-file))+)?/gm;
|
|
1628
|
+
const regex = /@effect-diagnostics(-next-line)?((?:\s[a-zA-Z0-9/]+:(?:off|warning|error|message|suggestion|skip-file))+)?/gm;
|
|
1587
1629
|
let match3;
|
|
1588
1630
|
while ((match3 = regex.exec(sourceFile.text)) !== null) {
|
|
1589
|
-
const
|
|
1631
|
+
const nextLineCaptureGroup = match3[1];
|
|
1632
|
+
const rulesCaptureGroup = match3[2];
|
|
1590
1633
|
if (rulesCaptureGroup) {
|
|
1591
1634
|
const trimmedRuleString = rulesCaptureGroup.trim();
|
|
1592
1635
|
if (trimmedRuleString) {
|
|
1593
1636
|
const individualRules = trimmedRuleString.split(/\s+/);
|
|
1594
1637
|
for (const rulePair of individualRules) {
|
|
1595
|
-
const [
|
|
1638
|
+
const [rawRuleName, ruleLevel] = rulePair.toLowerCase().split(":");
|
|
1639
|
+
const ruleName = rawRuleName.startsWith("effect/") ? rawRuleName.substring("effect/".length) : rawRuleName;
|
|
1596
1640
|
if (ruleName && ruleLevel) {
|
|
1597
1641
|
if (ruleLevel === "skip-file") skippedRules.push(ruleName);
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1642
|
+
const isOverrideNextLine = nextLineCaptureGroup && nextLineCaptureGroup.trim().toLowerCase() === "-next-line";
|
|
1643
|
+
if (isOverrideNextLine) {
|
|
1644
|
+
const node = findNodeWithLeadingCommentAtPosition(match3.index);
|
|
1645
|
+
if (node) {
|
|
1646
|
+
lineOverrides[ruleName] = lineOverrides[ruleName] || [];
|
|
1647
|
+
lineOverrides[ruleName].unshift({
|
|
1648
|
+
pos: node.getFullStart(),
|
|
1649
|
+
end: node.end,
|
|
1650
|
+
level: ruleLevel
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
} else {
|
|
1654
|
+
sectionOverrides[ruleName] = sectionOverrides[ruleName] || [];
|
|
1655
|
+
sectionOverrides[ruleName].unshift({
|
|
1656
|
+
pos: match3.index,
|
|
1657
|
+
level: ruleLevel
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1605
1660
|
}
|
|
1606
1661
|
}
|
|
1607
1662
|
}
|
|
@@ -1617,22 +1672,46 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1617
1672
|
const ruleNameLowered = rule.name.toLowerCase();
|
|
1618
1673
|
if (skippedRules.indexOf(ruleNameLowered) > -1) return [];
|
|
1619
1674
|
let modifiedDiagnostics = yield* rule.apply(sourceFile);
|
|
1620
|
-
for (const
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1675
|
+
for (const emitted of modifiedDiagnostics.slice(0)) {
|
|
1676
|
+
let newLevel = void 0;
|
|
1677
|
+
if (!(ruleNameLowered in sectionOverrides || ruleNameLowered in lineOverrides)) continue;
|
|
1678
|
+
const lineOverride = (lineOverrides[ruleNameLowered] || []).find(
|
|
1679
|
+
(_) => _.pos < emitted.node.getStart(sourceFile) && _.end >= emitted.node.getEnd()
|
|
1680
|
+
);
|
|
1681
|
+
if (lineOverride) {
|
|
1682
|
+
newLevel = lineOverride.level;
|
|
1683
|
+
} else {
|
|
1684
|
+
const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find(
|
|
1685
|
+
(_) => _.pos < emitted.node.getStart(sourceFile)
|
|
1624
1686
|
);
|
|
1687
|
+
if (sectionOverride) newLevel = sectionOverride.level;
|
|
1688
|
+
}
|
|
1689
|
+
if (newLevel === "off") {
|
|
1690
|
+
modifiedDiagnostics = modifiedDiagnostics.filter((_) => _ !== emitted);
|
|
1625
1691
|
} else {
|
|
1626
|
-
|
|
1627
|
-
(_) => _.node.getStart(sourceFile) >= override.start && _.node.getEnd() <= override.end
|
|
1628
|
-
)) {
|
|
1629
|
-
message.category = override.level in levelToDiagnosticCategory ? levelToDiagnosticCategory[override.level] : message.category;
|
|
1630
|
-
}
|
|
1692
|
+
emitted.category = newLevel && newLevel in levelToDiagnosticCategory ? levelToDiagnosticCategory[newLevel] : emitted.category;
|
|
1631
1693
|
}
|
|
1632
1694
|
}
|
|
1695
|
+
const fixByDisableNextLine = (_) => ({
|
|
1696
|
+
fixName: rule.name + "_skipNextLine",
|
|
1697
|
+
description: "Disable " + rule.name + " for this line",
|
|
1698
|
+
apply: flatMap3(
|
|
1699
|
+
service(ChangeTracker),
|
|
1700
|
+
(changeTracker) => sync(() => {
|
|
1701
|
+
const disableAtNode = findParentStatementForDisableNextLine(_.node);
|
|
1702
|
+
const { line } = ts.getLineAndCharacterOfPosition(sourceFile, disableAtNode.getStart());
|
|
1703
|
+
changeTracker.insertCommentBeforeLine(
|
|
1704
|
+
sourceFile,
|
|
1705
|
+
line,
|
|
1706
|
+
disableAtNode.getStart(),
|
|
1707
|
+
` @effect-diagnostics-next-line ${rule.name}:off`
|
|
1708
|
+
);
|
|
1709
|
+
})
|
|
1710
|
+
)
|
|
1711
|
+
});
|
|
1633
1712
|
const fixByDisableEntireFile = {
|
|
1634
1713
|
fixName: rule.name + "_skipFile",
|
|
1635
|
-
description: "Disable " + rule.name + " for this file",
|
|
1714
|
+
description: "Disable " + rule.name + " for this entire file",
|
|
1636
1715
|
apply: flatMap3(
|
|
1637
1716
|
service(ChangeTracker),
|
|
1638
1717
|
(changeTracker) => sync(
|
|
@@ -1647,7 +1726,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1647
1726
|
};
|
|
1648
1727
|
const rulesWithDisableFix = modifiedDiagnostics.map((diagnostic) => ({
|
|
1649
1728
|
...diagnostic,
|
|
1650
|
-
fixes: diagnostic.fixes.concat([fixByDisableEntireFile])
|
|
1729
|
+
fixes: diagnostic.fixes.concat([fixByDisableNextLine(diagnostic), fixByDisableEntireFile])
|
|
1651
1730
|
}));
|
|
1652
1731
|
return rulesWithDisableFix;
|
|
1653
1732
|
});
|
|
@@ -1657,7 +1736,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1657
1736
|
|
|
1658
1737
|
// src/completions/contextSelfInClasses.ts
|
|
1659
1738
|
var contextSelfInClasses = createCompletion({
|
|
1660
|
-
name: "
|
|
1739
|
+
name: "contextSelfInClasses",
|
|
1661
1740
|
apply: fn("contextSelfInClasses")(function* (sourceFile, position) {
|
|
1662
1741
|
const ts = yield* service(TypeScriptApi);
|
|
1663
1742
|
const maybeInfos = yield* option(
|
|
@@ -1690,7 +1769,7 @@ var contextSelfInClasses = createCompletion({
|
|
|
1690
1769
|
|
|
1691
1770
|
// src/completions/effectDataClasses.ts
|
|
1692
1771
|
var effectDataClasses = createCompletion({
|
|
1693
|
-
name: "
|
|
1772
|
+
name: "effectDataClasses",
|
|
1694
1773
|
apply: fn("effectDataClasses")(function* (sourceFile, position) {
|
|
1695
1774
|
const ts = yield* service(TypeScriptApi);
|
|
1696
1775
|
const maybeInfos = yield* option(
|
|
@@ -1729,7 +1808,7 @@ var effectDataClasses = createCompletion({
|
|
|
1729
1808
|
|
|
1730
1809
|
// src/completions/effectSchemaSelfInClasses.ts
|
|
1731
1810
|
var effectSchemaSelfInClasses = createCompletion({
|
|
1732
|
-
name: "
|
|
1811
|
+
name: "effectSchemaSelfInClasses",
|
|
1733
1812
|
apply: fn("effectSchemaSelfInClasses")(function* (sourceFile, position) {
|
|
1734
1813
|
const ts = yield* service(TypeScriptApi);
|
|
1735
1814
|
const maybeInfos = yield* option(
|
|
@@ -1780,7 +1859,7 @@ var effectSchemaSelfInClasses = createCompletion({
|
|
|
1780
1859
|
|
|
1781
1860
|
// src/completions/effectSelfInClasses.ts
|
|
1782
1861
|
var effectSelfInClasses = createCompletion({
|
|
1783
|
-
name: "
|
|
1862
|
+
name: "effectSelfInClasses",
|
|
1784
1863
|
apply: fn("effectSelfInClasses")(function* (sourceFile, position) {
|
|
1785
1864
|
const ts = yield* service(TypeScriptApi);
|
|
1786
1865
|
const maybeInfos = yield* option(
|
|
@@ -1835,12 +1914,12 @@ var getMissingTypeEntriesInTargetType = fn(
|
|
|
1835
1914
|
function* (realType, expectedType) {
|
|
1836
1915
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
1837
1916
|
const result = [];
|
|
1838
|
-
|
|
1917
|
+
let toTest = [realType];
|
|
1839
1918
|
while (toTest.length > 0) {
|
|
1840
1919
|
const type = toTest.pop();
|
|
1841
1920
|
if (!type) return result;
|
|
1842
1921
|
if (type.isUnion()) {
|
|
1843
|
-
toTest.
|
|
1922
|
+
toTest = toTest.concat(type.types);
|
|
1844
1923
|
} else {
|
|
1845
1924
|
const assignable = typeChecker.isTypeAssignableTo(type, expectedType);
|
|
1846
1925
|
if (!assignable) {
|
|
@@ -2016,6 +2095,51 @@ var expectedAndRealType = fn("TypeCheckerApi.expectedAndRealType")(function* (so
|
|
|
2016
2095
|
cache.expectedAndRealType.set(sourceFile, result);
|
|
2017
2096
|
return result;
|
|
2018
2097
|
});
|
|
2098
|
+
var appendToUniqueTypesMap = fn(
|
|
2099
|
+
"TypeCheckerApi.appendToUniqueTypesMap"
|
|
2100
|
+
)(
|
|
2101
|
+
function* (memory, initialType, excludeNever) {
|
|
2102
|
+
const ts = yield* service(TypeScriptApi);
|
|
2103
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
2104
|
+
const newIndexes = /* @__PURE__ */ new Set();
|
|
2105
|
+
const knownIndexes = /* @__PURE__ */ new Set();
|
|
2106
|
+
let toTest = [initialType];
|
|
2107
|
+
while (toTest.length > 0) {
|
|
2108
|
+
const type = toTest.pop();
|
|
2109
|
+
if (!type) break;
|
|
2110
|
+
if (excludeNever && type.flags & ts.TypeFlags.Never) {
|
|
2111
|
+
continue;
|
|
2112
|
+
}
|
|
2113
|
+
if (type.isUnion()) {
|
|
2114
|
+
toTest = toTest.concat(type.types);
|
|
2115
|
+
} else {
|
|
2116
|
+
const foundMatch = [];
|
|
2117
|
+
for (const [typeId, knownType] of memory.entries()) {
|
|
2118
|
+
const areSame = typeChecker.isTypeAssignableTo(knownType, type) && typeChecker.isTypeAssignableTo(type, knownType);
|
|
2119
|
+
if (areSame) {
|
|
2120
|
+
foundMatch.push(typeId);
|
|
2121
|
+
break;
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
if (foundMatch.length === 0) {
|
|
2125
|
+
const newId = "t" + (memory.size + 1);
|
|
2126
|
+
memory.set(newId, type);
|
|
2127
|
+
newIndexes.add(newId);
|
|
2128
|
+
} else {
|
|
2129
|
+
knownIndexes.add(foundMatch[0]);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
return {
|
|
2134
|
+
newIndexes,
|
|
2135
|
+
knownIndexes,
|
|
2136
|
+
allIndexes: pipe(
|
|
2137
|
+
fromIterable(newIndexes),
|
|
2138
|
+
appendAll(fromIterable(knownIndexes))
|
|
2139
|
+
)
|
|
2140
|
+
};
|
|
2141
|
+
}
|
|
2142
|
+
);
|
|
2019
2143
|
|
|
2020
2144
|
// src/utils/TypeParser.ts
|
|
2021
2145
|
var TypeParserIssue = class {
|
|
@@ -2036,6 +2160,13 @@ function covariantTypeArgument(type) {
|
|
|
2036
2160
|
}
|
|
2037
2161
|
return succeed(signatures[0].getReturnType());
|
|
2038
2162
|
}
|
|
2163
|
+
function contravariantTypeArgument(type) {
|
|
2164
|
+
const signatures = type.getCallSignatures();
|
|
2165
|
+
if (signatures.length !== 1) {
|
|
2166
|
+
return typeParserIssue("Contravariant type has no call signature", type);
|
|
2167
|
+
}
|
|
2168
|
+
return succeed(signatures[0].getTypeParameterAtPosition(0));
|
|
2169
|
+
}
|
|
2039
2170
|
function invariantTypeArgument(type) {
|
|
2040
2171
|
const signatures = type.getCallSignatures();
|
|
2041
2172
|
if (signatures.length !== 1) {
|
|
@@ -2067,6 +2198,19 @@ var varianceStructCovariantType = fn("TypeParser.varianceStructCovariantType")(
|
|
|
2067
2198
|
return yield* covariantTypeArgument(propertyType);
|
|
2068
2199
|
}
|
|
2069
2200
|
);
|
|
2201
|
+
var varianceStructContravariantType = fn(
|
|
2202
|
+
"TypeParser.varianceStructContravariantType"
|
|
2203
|
+
)(
|
|
2204
|
+
function* (type, atLocation, propertyName) {
|
|
2205
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
2206
|
+
const propertySymbol = typeChecker.getPropertyOfType(type, propertyName);
|
|
2207
|
+
if (!propertySymbol) {
|
|
2208
|
+
return yield* typeParserIssue(`Type has no '${propertyName}' property`, type, atLocation);
|
|
2209
|
+
}
|
|
2210
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
2211
|
+
return yield* contravariantTypeArgument(propertyType);
|
|
2212
|
+
}
|
|
2213
|
+
);
|
|
2070
2214
|
var varianceStructInvariantType = fn("TypeParser.varianceStructInvariantType")(
|
|
2071
2215
|
function* (type, atLocation, propertyName) {
|
|
2072
2216
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
@@ -2085,6 +2229,13 @@ var effectVarianceStruct = fn("TypeParser.effectVarianceStruct")(function* (type
|
|
|
2085
2229
|
R: yield* varianceStructCovariantType(type, atLocation, "_R")
|
|
2086
2230
|
};
|
|
2087
2231
|
});
|
|
2232
|
+
var layerVarianceStruct = fn("TypeParser.layerVarianceStruct")(function* (type, atLocation) {
|
|
2233
|
+
return {
|
|
2234
|
+
ROut: yield* varianceStructContravariantType(type, atLocation, "_ROut"),
|
|
2235
|
+
E: yield* varianceStructCovariantType(type, atLocation, "_E"),
|
|
2236
|
+
RIn: yield* varianceStructCovariantType(type, atLocation, "_RIn")
|
|
2237
|
+
};
|
|
2238
|
+
});
|
|
2088
2239
|
var effectType = fn("TypeParser.effectType")(function* (type, atLocation) {
|
|
2089
2240
|
const ts = yield* service(TypeScriptApi);
|
|
2090
2241
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
@@ -2105,6 +2256,26 @@ var effectType = fn("TypeParser.effectType")(function* (type, atLocation) {
|
|
|
2105
2256
|
}
|
|
2106
2257
|
return yield* typeParserIssue("Type has no effect variance struct", type, atLocation);
|
|
2107
2258
|
});
|
|
2259
|
+
var layerType = fn("TypeParser.layerType")(function* (type, atLocation) {
|
|
2260
|
+
const ts = yield* service(TypeScriptApi);
|
|
2261
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
2262
|
+
yield* pipeableType(type, atLocation);
|
|
2263
|
+
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
2264
|
+
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional)
|
|
2265
|
+
);
|
|
2266
|
+
propertiesSymbols.sort((a, b) => b.name.indexOf("LayerTypeId") - a.name.indexOf("LayerTypeId"));
|
|
2267
|
+
for (const propertySymbol of propertiesSymbols) {
|
|
2268
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
2269
|
+
const varianceArgs = yield* option(layerVarianceStruct(
|
|
2270
|
+
propertyType,
|
|
2271
|
+
atLocation
|
|
2272
|
+
));
|
|
2273
|
+
if (isSome2(varianceArgs)) {
|
|
2274
|
+
return varianceArgs.value;
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
return yield* typeParserIssue("Type has no layer variance struct", type, atLocation);
|
|
2278
|
+
});
|
|
2108
2279
|
var fiberType = fn("TypeParser.fiberType")(function* (type, atLocation) {
|
|
2109
2280
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
2110
2281
|
const awaitSymbol = typeChecker.getPropertyOfType(type, "await");
|
|
@@ -2121,9 +2292,10 @@ var fiberType = fn("TypeParser.fiberType")(function* (type, atLocation) {
|
|
|
2121
2292
|
var effectSubtype = fn("TypeParser.effectSubtype")(function* (type, atLocation) {
|
|
2122
2293
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
2123
2294
|
const tagSymbol = typeChecker.getPropertyOfType(type, "_tag");
|
|
2124
|
-
|
|
2295
|
+
const getSymbol = typeChecker.getPropertyOfType(type, "get");
|
|
2296
|
+
if (!(tagSymbol || getSymbol)) {
|
|
2125
2297
|
return yield* typeParserIssue(
|
|
2126
|
-
"Type is not a subtype of effect because it does not have '_tag' property",
|
|
2298
|
+
"Type is not a subtype of effect because it does not have '_tag' or 'get' property",
|
|
2127
2299
|
type,
|
|
2128
2300
|
atLocation
|
|
2129
2301
|
);
|
|
@@ -2269,19 +2441,68 @@ var effectFnGen = fn("TypeParser.effectFnGen")(function* (node) {
|
|
|
2269
2441
|
functionStar: generatorFunction.getFirstToken()
|
|
2270
2442
|
};
|
|
2271
2443
|
});
|
|
2272
|
-
var
|
|
2444
|
+
var unnecessaryEffectGen = fn("TypeParser.unnecessaryEffectGen")(function* (node) {
|
|
2273
2445
|
const ts = yield* service(TypeScriptApi);
|
|
2274
2446
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2447
|
+
const { body } = yield* effectGen(node);
|
|
2448
|
+
if (body.statements.length !== 1) {
|
|
2449
|
+
return yield* typeParserIssue(
|
|
2450
|
+
"Generator body should have a single statement",
|
|
2451
|
+
void 0,
|
|
2452
|
+
node
|
|
2453
|
+
);
|
|
2454
|
+
}
|
|
2455
|
+
let explicitReturn = false;
|
|
2456
|
+
let nodeToCheck = body.statements[0];
|
|
2457
|
+
while (nodeToCheck) {
|
|
2458
|
+
if (ts.isReturnStatement(nodeToCheck) && nodeToCheck.expression) {
|
|
2459
|
+
nodeToCheck = nodeToCheck.expression;
|
|
2460
|
+
explicitReturn = true;
|
|
2461
|
+
continue;
|
|
2462
|
+
}
|
|
2463
|
+
if (ts.isExpressionStatement(nodeToCheck)) {
|
|
2464
|
+
nodeToCheck = nodeToCheck.expression;
|
|
2465
|
+
continue;
|
|
2466
|
+
}
|
|
2467
|
+
if (ts.isYieldExpression(nodeToCheck) && nodeToCheck.asteriskToken && nodeToCheck.expression) {
|
|
2468
|
+
const yieldedExpression = nodeToCheck.expression;
|
|
2469
|
+
const type = typeChecker.getTypeAtLocation(yieldedExpression);
|
|
2470
|
+
const { A: successType } = yield* effectType(type, yieldedExpression);
|
|
2471
|
+
let replacementNode = succeed(yieldedExpression);
|
|
2472
|
+
if (!explicitReturn && !(successType.flags & ts.TypeFlags.VoidLike)) {
|
|
2473
|
+
replacementNode = pipe(
|
|
2474
|
+
gen2(function* () {
|
|
2475
|
+
const effectIdentifier = pipe(
|
|
2476
|
+
yield* option(
|
|
2477
|
+
findImportedModuleIdentifierByPackageAndNameOrBarrel(node.getSourceFile(), "effect", "Effect")
|
|
2478
|
+
),
|
|
2479
|
+
match2({
|
|
2480
|
+
onNone: () => "Effect",
|
|
2481
|
+
onSome: (_) => _.text
|
|
2482
|
+
})
|
|
2483
|
+
);
|
|
2484
|
+
return ts.factory.createCallExpression(
|
|
2485
|
+
ts.factory.createPropertyAccessExpression(
|
|
2486
|
+
ts.factory.createIdentifier(effectIdentifier),
|
|
2487
|
+
"asVoid"
|
|
2488
|
+
),
|
|
2489
|
+
void 0,
|
|
2490
|
+
[
|
|
2491
|
+
yieldedExpression
|
|
2492
|
+
]
|
|
2493
|
+
);
|
|
2494
|
+
}),
|
|
2495
|
+
provideService(TypeScriptApi, ts)
|
|
2496
|
+
);
|
|
2497
|
+
}
|
|
2498
|
+
return { node, body, yieldedExpression, replacementNode };
|
|
2499
|
+
}
|
|
2500
|
+
break;
|
|
2280
2501
|
}
|
|
2281
2502
|
return yield* typeParserIssue(
|
|
2282
|
-
"
|
|
2503
|
+
"Not an handled node",
|
|
2283
2504
|
void 0,
|
|
2284
|
-
|
|
2505
|
+
node
|
|
2285
2506
|
);
|
|
2286
2507
|
});
|
|
2287
2508
|
var effectSchemaVarianceStruct = fn("TypeParser.effectSchemaVarianceStruct")(
|
|
@@ -2318,7 +2539,7 @@ var effectSchemaType = fn("TypeParser.effectSchemaType")(function* (type, atLoca
|
|
|
2318
2539
|
|
|
2319
2540
|
// src/completions/fnFunctionStar.ts
|
|
2320
2541
|
var fnFunctionStar = createCompletion({
|
|
2321
|
-
name: "
|
|
2542
|
+
name: "fnFunctionStar",
|
|
2322
2543
|
apply: fn("fnFunctionStar")(function* (sourceFile, position) {
|
|
2323
2544
|
const ts = yield* service(TypeScriptApi);
|
|
2324
2545
|
const maybeInfos = yield* option(
|
|
@@ -2367,7 +2588,7 @@ var fnFunctionStar = createCompletion({
|
|
|
2367
2588
|
|
|
2368
2589
|
// src/completions/genFunctionStar.ts
|
|
2369
2590
|
var genFunctionStar = createCompletion({
|
|
2370
|
-
name: "
|
|
2591
|
+
name: "genFunctionStar",
|
|
2371
2592
|
apply: fn("genFunctionStar")(function* (sourceFile, position) {
|
|
2372
2593
|
const ts = yield* service(TypeScriptApi);
|
|
2373
2594
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
@@ -2405,9 +2626,90 @@ var completions = [
|
|
|
2405
2626
|
effectDataClasses
|
|
2406
2627
|
];
|
|
2407
2628
|
|
|
2629
|
+
// src/core/LanguageServicePluginOptions.ts
|
|
2630
|
+
var LanguageServicePluginOptions = Tag("PluginOptions");
|
|
2631
|
+
function parse(config) {
|
|
2632
|
+
return {
|
|
2633
|
+
diagnostics: isObject(config) && hasProperty(config, "diagnostics") && isBoolean(config.diagnostics) ? config.diagnostics : true,
|
|
2634
|
+
quickinfo: isObject(config) && hasProperty(config, "quickinfo") && isBoolean(config.quickinfo) ? config.quickinfo : true,
|
|
2635
|
+
completions: isObject(config) && hasProperty(config, "completions") && isBoolean(config.completions) ? config.completions : true,
|
|
2636
|
+
allowedDuplicatedPackages: isObject(config) && hasProperty(config, "allowedDuplicatedPackages") && isArray(config.allowedDuplicatedPackages) && config.allowedDuplicatedPackages.every(isString) ? config.allowedDuplicatedPackages.map((_) => _.toLowerCase()) : []
|
|
2637
|
+
};
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
// src/diagnostics/duplicatePackage.ts
|
|
2641
|
+
var checkedPackagesCache = /* @__PURE__ */ new Map();
|
|
2642
|
+
var programResolvedCacheSize = /* @__PURE__ */ new Map();
|
|
2643
|
+
function parsePackageContentNameAndVersion(v) {
|
|
2644
|
+
if (!isObject(v)) return;
|
|
2645
|
+
if (!hasProperty(v, "packageJsonScope")) return;
|
|
2646
|
+
if (!v.packageJsonScope) return;
|
|
2647
|
+
const packageJsonScope = v.packageJsonScope;
|
|
2648
|
+
if (!hasProperty(packageJsonScope, "contents")) return;
|
|
2649
|
+
if (!hasProperty(packageJsonScope.contents, "packageJsonContent")) return;
|
|
2650
|
+
const packageJsonContent = packageJsonScope.contents.packageJsonContent;
|
|
2651
|
+
if (!hasProperty(packageJsonContent, "name")) return;
|
|
2652
|
+
if (!hasProperty(packageJsonContent, "version")) return;
|
|
2653
|
+
const { name, version } = packageJsonContent;
|
|
2654
|
+
if (!isString(name)) return;
|
|
2655
|
+
if (!isString(version)) return;
|
|
2656
|
+
const hasEffectInPeerDependencies = hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) && hasProperty(packageJsonContent.peerDependencies, "effect");
|
|
2657
|
+
return {
|
|
2658
|
+
name: name.toLowerCase(),
|
|
2659
|
+
version: version.toLowerCase(),
|
|
2660
|
+
hasEffectInPeerDependencies,
|
|
2661
|
+
contents: packageJsonContent
|
|
2662
|
+
};
|
|
2663
|
+
}
|
|
2664
|
+
var duplicatePackage = createDiagnostic({
|
|
2665
|
+
name: "duplicatePackage",
|
|
2666
|
+
code: 6,
|
|
2667
|
+
apply: fn("duplicatePackage.apply")(function* (sourceFile) {
|
|
2668
|
+
const ts = yield* service(TypeScriptApi);
|
|
2669
|
+
const program = yield* service(TypeScriptProgram);
|
|
2670
|
+
const options = yield* service(LanguageServicePluginOptions);
|
|
2671
|
+
const effectDiagnostics = [];
|
|
2672
|
+
if (sourceFile.statements.length < 1) return [];
|
|
2673
|
+
let resolvedPackages = checkedPackagesCache.get(sourceFile.fileName) || {};
|
|
2674
|
+
const newResolvedModuleSize = hasProperty(program, "resolvedModules") && hasProperty(program.resolvedModules, "size") && isNumber(program.resolvedModules.size) ? program.resolvedModules.size : 0;
|
|
2675
|
+
const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1;
|
|
2676
|
+
if (newResolvedModuleSize !== oldResolvedSize) {
|
|
2677
|
+
const seenPackages = /* @__PURE__ */ new Set();
|
|
2678
|
+
resolvedPackages = {};
|
|
2679
|
+
program.getSourceFiles().map((_) => {
|
|
2680
|
+
const packageInfo = parsePackageContentNameAndVersion(_);
|
|
2681
|
+
if (!packageInfo) return;
|
|
2682
|
+
const packageNameAndVersion = packageInfo.name + "@" + packageInfo.version;
|
|
2683
|
+
if (seenPackages.has(packageNameAndVersion)) return;
|
|
2684
|
+
seenPackages.add(packageNameAndVersion);
|
|
2685
|
+
if (!(packageInfo.name === "effect" || packageInfo.hasEffectInPeerDependencies)) return;
|
|
2686
|
+
if (options.allowedDuplicatedPackages.indexOf(packageInfo.name) > -1) return;
|
|
2687
|
+
resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {};
|
|
2688
|
+
resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.contents;
|
|
2689
|
+
});
|
|
2690
|
+
checkedPackagesCache.set(sourceFile.fileName, resolvedPackages);
|
|
2691
|
+
programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize);
|
|
2692
|
+
}
|
|
2693
|
+
for (const packageName of Object.keys(resolvedPackages)) {
|
|
2694
|
+
if (Object.keys(resolvedPackages[packageName]).length > 1) {
|
|
2695
|
+
const versions = Object.keys(resolvedPackages[packageName]);
|
|
2696
|
+
effectDiagnostics.push({
|
|
2697
|
+
node: sourceFile.statements[0],
|
|
2698
|
+
category: ts.DiagnosticCategory.Warning,
|
|
2699
|
+
messageText: `Package ${packageName} is referenced multiple times with different versions (${versions.join(", ")}) and may cause unexpected type errors.
|
|
2700
|
+
Cleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.
|
|
2701
|
+
If this is intended set the LSP config "allowedDuplicatedPackages" to ${JSON.stringify(options.allowedDuplicatedPackages.concat([packageName]))}.`,
|
|
2702
|
+
fixes: []
|
|
2703
|
+
});
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
return effectDiagnostics;
|
|
2707
|
+
})
|
|
2708
|
+
});
|
|
2709
|
+
|
|
2408
2710
|
// src/diagnostics/floatingEffect.ts
|
|
2409
2711
|
var floatingEffect = createDiagnostic({
|
|
2410
|
-
name: "
|
|
2712
|
+
name: "floatingEffect",
|
|
2411
2713
|
code: 3,
|
|
2412
2714
|
apply: fn("floatingEffect.apply")(function* (sourceFile) {
|
|
2413
2715
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -2416,7 +2718,7 @@ var floatingEffect = createDiagnostic({
|
|
|
2416
2718
|
if (!ts.isExpressionStatement(node)) return false;
|
|
2417
2719
|
if (!(ts.isBlock(node.parent) || ts.isSourceFile(node.parent))) return false;
|
|
2418
2720
|
const expression = node.expression;
|
|
2419
|
-
if (ts.isBinaryExpression(expression) && expression.operatorToken && expression.operatorToken.kind === ts.SyntaxKind.EqualsToken) return false;
|
|
2721
|
+
if (ts.isBinaryExpression(expression) && expression.operatorToken && (expression.operatorToken.kind === ts.SyntaxKind.EqualsToken || expression.operatorToken.kind === ts.SyntaxKind.QuestionQuestionEqualsToken || expression.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandEqualsToken || expression.operatorToken.kind === ts.SyntaxKind.BarBarEqualsToken)) return false;
|
|
2420
2722
|
return true;
|
|
2421
2723
|
}
|
|
2422
2724
|
const effectDiagnostics = [];
|
|
@@ -2454,7 +2756,7 @@ var floatingEffect = createDiagnostic({
|
|
|
2454
2756
|
|
|
2455
2757
|
// src/diagnostics/missingEffectContext.ts
|
|
2456
2758
|
var missingEffectContext = createDiagnostic({
|
|
2457
|
-
name: "
|
|
2759
|
+
name: "missingEffectContext",
|
|
2458
2760
|
code: 1,
|
|
2459
2761
|
apply: fn("missingEffectContext.apply")(function* (sourceFile) {
|
|
2460
2762
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -2506,7 +2808,7 @@ var missingEffectContext = createDiagnostic({
|
|
|
2506
2808
|
|
|
2507
2809
|
// src/diagnostics/missingEffectError.ts
|
|
2508
2810
|
var missingEffectError = createDiagnostic({
|
|
2509
|
-
name: "
|
|
2811
|
+
name: "missingEffectError",
|
|
2510
2812
|
code: 1,
|
|
2511
2813
|
apply: fn("missingEffectError.apply")(function* (sourceFile) {
|
|
2512
2814
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -2558,7 +2860,7 @@ var missingEffectError = createDiagnostic({
|
|
|
2558
2860
|
|
|
2559
2861
|
// src/diagnostics/missingStarInYieldEffectGen.ts
|
|
2560
2862
|
var missingStarInYieldEffectGen = createDiagnostic({
|
|
2561
|
-
name: "
|
|
2863
|
+
name: "missingStarInYieldEffectGen",
|
|
2562
2864
|
code: 4,
|
|
2563
2865
|
apply: fn("missingStarInYieldEffectGen.apply")(function* (sourceFile) {
|
|
2564
2866
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -2577,7 +2879,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
2577
2879
|
if (ts.isYieldExpression(node) && node.expression && node.asteriskToken === void 0) {
|
|
2578
2880
|
const functionStarNode = ts.findAncestor(
|
|
2579
2881
|
node,
|
|
2580
|
-
(_) =>
|
|
2882
|
+
(_) => ts.isFunctionExpression(_) || ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_)
|
|
2581
2883
|
);
|
|
2582
2884
|
if (functionStarNode && functionStarNode.parent) {
|
|
2583
2885
|
const effectGenNode = functionStarNode.parent;
|
|
@@ -2631,51 +2933,9 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
2631
2933
|
})
|
|
2632
2934
|
});
|
|
2633
2935
|
|
|
2634
|
-
// src/diagnostics/multipleEffectVersions.ts
|
|
2635
|
-
var effectVersionsCache = /* @__PURE__ */ new Map();
|
|
2636
|
-
var programResolvedCacheSize = /* @__PURE__ */ new Map();
|
|
2637
|
-
var multipleEffectVersions = createDiagnostic({
|
|
2638
|
-
name: "effect/multipleEffectVersions",
|
|
2639
|
-
code: 6,
|
|
2640
|
-
apply: fn("multipleEffectVersions.apply")(function* (sourceFile) {
|
|
2641
|
-
const ts = yield* service(TypeScriptApi);
|
|
2642
|
-
const program = yield* service(TypeScriptProgram);
|
|
2643
|
-
const options = yield* service(PluginOptions);
|
|
2644
|
-
const effectDiagnostics = [];
|
|
2645
|
-
if (!options.multipleEffectCheck) return [];
|
|
2646
|
-
if (sourceFile.statements.length < 1) return [];
|
|
2647
|
-
const effectVersions = effectVersionsCache.get(sourceFile.fileName) || {};
|
|
2648
|
-
const newResolvedModuleSize = "resolvedModules" in program && typeof program.resolvedModules === "object" && "size" in program.resolvedModules ? program.resolvedModules.size : 0;
|
|
2649
|
-
const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || 0;
|
|
2650
|
-
if (newResolvedModuleSize !== oldResolvedSize) {
|
|
2651
|
-
if ("forEachResolvedModule" in program && typeof program.forEachResolvedModule === "function") {
|
|
2652
|
-
program.forEachResolvedModule((_) => {
|
|
2653
|
-
if (_ && _.resolvedModule && _.resolvedModule.packageId && _.resolvedModule.packageId.name === "effect" && !(_.resolvedModule.packageId.version in effectVersions)) {
|
|
2654
|
-
effectVersions[_.resolvedModule.packageId.version] = {
|
|
2655
|
-
resolvedFileName: _.resolvedModule.resolvedFileName
|
|
2656
|
-
};
|
|
2657
|
-
}
|
|
2658
|
-
});
|
|
2659
|
-
}
|
|
2660
|
-
effectVersionsCache.set(sourceFile.fileName, effectVersions);
|
|
2661
|
-
programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize);
|
|
2662
|
-
}
|
|
2663
|
-
if (Object.keys(effectVersions).length > 1) {
|
|
2664
|
-
const versions = Object.keys(effectVersions).map((version) => `version ${version}`);
|
|
2665
|
-
effectDiagnostics.push({
|
|
2666
|
-
node: sourceFile.statements[0],
|
|
2667
|
-
category: ts.DiagnosticCategory.Warning,
|
|
2668
|
-
messageText: `Seems like in this project there are multiple effect versions loaded (${versions.join(", ")}). This may cause unexpected type errors and runtime behaviours. If you are ok with that, you can disable this warning by adding "multipleEffectCheck": false to the Effect LSP options inside your tsconfig.json`,
|
|
2669
|
-
fixes: []
|
|
2670
|
-
});
|
|
2671
|
-
}
|
|
2672
|
-
return effectDiagnostics;
|
|
2673
|
-
})
|
|
2674
|
-
});
|
|
2675
|
-
|
|
2676
2936
|
// src/diagnostics/unnecessaryEffectGen.ts
|
|
2677
|
-
var
|
|
2678
|
-
name: "
|
|
2937
|
+
var unnecessaryEffectGen2 = createDiagnostic({
|
|
2938
|
+
name: "unnecessaryEffectGen",
|
|
2679
2939
|
code: 5,
|
|
2680
2940
|
apply: fn("unnecessaryEffectGen.apply")(function* (sourceFile) {
|
|
2681
2941
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -2690,13 +2950,9 @@ var unnecessaryEffectGen = createDiagnostic({
|
|
|
2690
2950
|
while (nodeToVisit.length > 0) {
|
|
2691
2951
|
const node = nodeToVisit.shift();
|
|
2692
2952
|
ts.forEachChild(node, appendNodeToVisit);
|
|
2693
|
-
const maybeNode = yield*
|
|
2694
|
-
effectGen(node),
|
|
2695
|
-
flatMap3(({ body }) => returnYieldEffectBlock(body)),
|
|
2696
|
-
option
|
|
2697
|
-
);
|
|
2953
|
+
const maybeNode = yield* option(unnecessaryEffectGen(node));
|
|
2698
2954
|
if (isSome2(maybeNode)) {
|
|
2699
|
-
unnecessaryGenerators.set(node, maybeNode.value);
|
|
2955
|
+
unnecessaryGenerators.set(node, maybeNode.value.replacementNode);
|
|
2700
2956
|
}
|
|
2701
2957
|
}
|
|
2702
2958
|
unnecessaryGenerators.forEach(
|
|
@@ -2711,7 +2967,7 @@ var unnecessaryEffectGen = createDiagnostic({
|
|
|
2711
2967
|
const textChanges = yield* service(
|
|
2712
2968
|
ChangeTracker
|
|
2713
2969
|
);
|
|
2714
|
-
textChanges.replaceNode(sourceFile, effectGenCall, yieldedResult);
|
|
2970
|
+
textChanges.replaceNode(sourceFile, effectGenCall, yield* yieldedResult);
|
|
2715
2971
|
})
|
|
2716
2972
|
}]
|
|
2717
2973
|
})
|
|
@@ -2722,31 +2978,31 @@ var unnecessaryEffectGen = createDiagnostic({
|
|
|
2722
2978
|
|
|
2723
2979
|
// src/diagnostics.ts
|
|
2724
2980
|
var diagnostics = [
|
|
2725
|
-
|
|
2981
|
+
duplicatePackage,
|
|
2726
2982
|
missingEffectContext,
|
|
2727
2983
|
missingEffectError,
|
|
2728
2984
|
floatingEffect,
|
|
2729
2985
|
missingStarInYieldEffectGen,
|
|
2730
|
-
|
|
2986
|
+
unnecessaryEffectGen2
|
|
2731
2987
|
];
|
|
2732
2988
|
|
|
2733
|
-
// src/quickinfo.ts
|
|
2734
|
-
var SymbolDisplayPartEq = make(
|
|
2735
|
-
(fa, fb) => fa.kind === fb.kind && fa.text === fb.text
|
|
2736
|
-
);
|
|
2989
|
+
// src/quickinfo/dedupeJsDocs.ts
|
|
2990
|
+
var SymbolDisplayPartEq = make((fa, fb) => fa.kind === fb.kind && fa.text === fb.text);
|
|
2737
2991
|
var JSDocTagInfoEq = make(
|
|
2738
2992
|
(fa, fb) => fa.name === fb.name && typeof fa.text === typeof fb.text && (typeof fa.text !== "undefined" ? array(SymbolDisplayPartEq)(fa.text, fb.text) : true)
|
|
2739
2993
|
);
|
|
2740
|
-
function
|
|
2741
|
-
if (!
|
|
2742
|
-
if (
|
|
2743
|
-
return {
|
|
2744
|
-
...
|
|
2745
|
-
tags: dedupeWith(
|
|
2746
|
-
};
|
|
2994
|
+
function dedupeJsDocs(quickInfo2) {
|
|
2995
|
+
if (!quickInfo2) return succeed(quickInfo2);
|
|
2996
|
+
if (quickInfo2.tags) {
|
|
2997
|
+
return succeed({
|
|
2998
|
+
...quickInfo2,
|
|
2999
|
+
tags: dedupeWith(quickInfo2.tags, JSDocTagInfoEq)
|
|
3000
|
+
});
|
|
2747
3001
|
}
|
|
2748
|
-
return
|
|
3002
|
+
return succeed(quickInfo2);
|
|
2749
3003
|
}
|
|
3004
|
+
|
|
3005
|
+
// src/quickinfo/effectTypeArgs.ts
|
|
2750
3006
|
function formatTypeForQuickInfo(channelType, channelName) {
|
|
2751
3007
|
return gen2(function* () {
|
|
2752
3008
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -2759,7 +3015,7 @@ function formatTypeForQuickInfo(channelType, channelName) {
|
|
|
2759
3015
|
return `type ${channelName} = ${stringRepresentation}`;
|
|
2760
3016
|
});
|
|
2761
3017
|
}
|
|
2762
|
-
function
|
|
3018
|
+
function effectTypeArgs(sourceFile, position, quickInfo2) {
|
|
2763
3019
|
return pipe(
|
|
2764
3020
|
gen2(function* () {
|
|
2765
3021
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -2768,11 +3024,11 @@ function prependEffectTypeArguments(sourceFile, position, quickInfo) {
|
|
|
2768
3024
|
yield* getAncestorNodesInRange(sourceFile, toTextRange(position)),
|
|
2769
3025
|
head
|
|
2770
3026
|
);
|
|
2771
|
-
if (isNone2(maybeNode)) return
|
|
3027
|
+
if (isNone2(maybeNode)) return quickInfo2;
|
|
2772
3028
|
const node = maybeNode.value;
|
|
2773
|
-
const hasTruncationHappened =
|
|
2774
|
-
const nodeForType = !
|
|
2775
|
-
if (!nodeForType) return
|
|
3029
|
+
const hasTruncationHappened = quickInfo2 && ts.displayPartsToString(quickInfo2.displayParts).indexOf("...") > -1;
|
|
3030
|
+
const nodeForType = !quickInfo2 && ts.isYieldExpression(node) && node.asteriskToken && node.expression ? node.expression : hasTruncationHappened ? node : void 0;
|
|
3031
|
+
if (!nodeForType) return quickInfo2;
|
|
2776
3032
|
const effectType2 = yield* effectType(
|
|
2777
3033
|
typeChecker.getTypeAtLocation(nodeForType),
|
|
2778
3034
|
nodeForType
|
|
@@ -2781,7 +3037,7 @@ function prependEffectTypeArguments(sourceFile, position, quickInfo) {
|
|
|
2781
3037
|
kind: "text",
|
|
2782
3038
|
text: "```ts\n/* Effect Type Parameters */\n" + (yield* formatTypeForQuickInfo(effectType2.A, "Success")) + "\n" + (yield* formatTypeForQuickInfo(effectType2.E, "Failure")) + "\n" + (yield* formatTypeForQuickInfo(effectType2.R, "Requirements")) + "\n```\n"
|
|
2783
3039
|
}];
|
|
2784
|
-
if (!
|
|
3040
|
+
if (!quickInfo2) {
|
|
2785
3041
|
const start = node.getStart();
|
|
2786
3042
|
const end = node.getEnd();
|
|
2787
3043
|
return {
|
|
@@ -2791,24 +3047,401 @@ function prependEffectTypeArguments(sourceFile, position, quickInfo) {
|
|
|
2791
3047
|
documentation: effectTypeArgsDocumentation
|
|
2792
3048
|
};
|
|
2793
3049
|
}
|
|
2794
|
-
if (
|
|
3050
|
+
if (quickInfo2.documentation) {
|
|
2795
3051
|
return {
|
|
2796
|
-
...
|
|
2797
|
-
documentation: effectTypeArgsDocumentation.concat(
|
|
3052
|
+
...quickInfo2,
|
|
3053
|
+
documentation: effectTypeArgsDocumentation.concat(quickInfo2.documentation)
|
|
2798
3054
|
};
|
|
2799
3055
|
}
|
|
2800
3056
|
return {
|
|
2801
|
-
...
|
|
3057
|
+
...quickInfo2,
|
|
2802
3058
|
documentation: effectTypeArgsDocumentation
|
|
2803
3059
|
};
|
|
2804
3060
|
}),
|
|
2805
|
-
orElse3(() => succeed(
|
|
3061
|
+
orElse3(() => succeed(quickInfo2))
|
|
3062
|
+
);
|
|
3063
|
+
}
|
|
3064
|
+
|
|
3065
|
+
// src/quickinfo/layerInfo.ts
|
|
3066
|
+
var UnableToProduceLayerGraphError = class {
|
|
3067
|
+
constructor(message, node) {
|
|
3068
|
+
this.message = message;
|
|
3069
|
+
this.node = node;
|
|
3070
|
+
}
|
|
3071
|
+
_tag = "@effect/language-service/UnableToProduceLayerGraphError";
|
|
3072
|
+
};
|
|
3073
|
+
var GraphNodeLeaf = class {
|
|
3074
|
+
constructor(id, node, rout, rin) {
|
|
3075
|
+
this.id = id;
|
|
3076
|
+
this.node = node;
|
|
3077
|
+
this.rout = rout;
|
|
3078
|
+
this.rin = rin;
|
|
3079
|
+
}
|
|
3080
|
+
_tag = "GraphNodeLeaf";
|
|
3081
|
+
};
|
|
3082
|
+
var GraphNodeCompoundTransform = class {
|
|
3083
|
+
constructor(id, node, args, rout, rin) {
|
|
3084
|
+
this.id = id;
|
|
3085
|
+
this.node = node;
|
|
3086
|
+
this.args = args;
|
|
3087
|
+
this.rout = rout;
|
|
3088
|
+
this.rin = rin;
|
|
3089
|
+
}
|
|
3090
|
+
_tag = "GraphNodeCompoundTransform";
|
|
3091
|
+
};
|
|
3092
|
+
function processLayerGraphNode(ctx, node, pipedInGraphNode) {
|
|
3093
|
+
return gen2(function* () {
|
|
3094
|
+
const ts = yield* service(TypeScriptApi);
|
|
3095
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3096
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "pipe") {
|
|
3097
|
+
let graphNode = yield* processLayerGraphNode(ctx, node.expression.expression, void 0);
|
|
3098
|
+
for (const entry of node.arguments) {
|
|
3099
|
+
graphNode = yield* processLayerGraphNode(ctx, entry, graphNode);
|
|
3100
|
+
}
|
|
3101
|
+
return graphNode;
|
|
3102
|
+
}
|
|
3103
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "pipe" && node.arguments.length > 0) {
|
|
3104
|
+
let graphNode = yield* processLayerGraphNode(ctx, node.arguments[0], void 0);
|
|
3105
|
+
for (let i = 1; i < node.arguments.length; i++) {
|
|
3106
|
+
graphNode = yield* processLayerGraphNode(ctx, node.arguments[i], graphNode);
|
|
3107
|
+
}
|
|
3108
|
+
return graphNode;
|
|
3109
|
+
}
|
|
3110
|
+
if (ts.isCallExpression(node)) {
|
|
3111
|
+
const type = typeChecker.getTypeAtLocation(node);
|
|
3112
|
+
const maybeLayer = yield* option(layerType(type, node));
|
|
3113
|
+
if (isSome2(maybeLayer)) {
|
|
3114
|
+
const argNodes = yield* option(
|
|
3115
|
+
all2(...node.arguments.map((_) => processLayerGraphNode(ctx, _, void 0)))
|
|
3116
|
+
);
|
|
3117
|
+
if (isSome2(argNodes) && argNodes.value.length === node.arguments.length) {
|
|
3118
|
+
const { allIndexes: outTypes } = yield* appendToUniqueTypesMap(
|
|
3119
|
+
ctx.services,
|
|
3120
|
+
maybeLayer.value.ROut,
|
|
3121
|
+
true
|
|
3122
|
+
);
|
|
3123
|
+
const { allIndexes: inTypes } = yield* appendToUniqueTypesMap(
|
|
3124
|
+
ctx.services,
|
|
3125
|
+
maybeLayer.value.RIn,
|
|
3126
|
+
true
|
|
3127
|
+
);
|
|
3128
|
+
return new GraphNodeCompoundTransform(
|
|
3129
|
+
ctx.nextId(),
|
|
3130
|
+
node,
|
|
3131
|
+
argNodes.value,
|
|
3132
|
+
outTypes,
|
|
3133
|
+
inTypes
|
|
3134
|
+
);
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
if (pipedInGraphNode && ts.isExpression(node)) {
|
|
3139
|
+
const type = typeChecker.getContextualType(node);
|
|
3140
|
+
if (type) {
|
|
3141
|
+
const callSignatures = type.getCallSignatures();
|
|
3142
|
+
if (callSignatures.length === 1) {
|
|
3143
|
+
const [signature] = callSignatures;
|
|
3144
|
+
const returnType = signature.getReturnType();
|
|
3145
|
+
const maybeLayer = yield* option(layerType(returnType, node));
|
|
3146
|
+
if (isSome2(maybeLayer)) {
|
|
3147
|
+
const { allIndexes: outTypes } = yield* appendToUniqueTypesMap(
|
|
3148
|
+
ctx.services,
|
|
3149
|
+
maybeLayer.value.ROut,
|
|
3150
|
+
true
|
|
3151
|
+
);
|
|
3152
|
+
const { allIndexes: inTypes } = yield* appendToUniqueTypesMap(
|
|
3153
|
+
ctx.services,
|
|
3154
|
+
maybeLayer.value.RIn,
|
|
3155
|
+
true
|
|
3156
|
+
);
|
|
3157
|
+
if (ts.isCallExpression(node)) {
|
|
3158
|
+
const argNodes = yield* option(
|
|
3159
|
+
all2(...node.arguments.map((_) => processLayerGraphNode(ctx, _, void 0)))
|
|
3160
|
+
);
|
|
3161
|
+
if (isSome2(argNodes) && argNodes.value.length === node.arguments.length) {
|
|
3162
|
+
return new GraphNodeCompoundTransform(
|
|
3163
|
+
ctx.nextId(),
|
|
3164
|
+
node,
|
|
3165
|
+
[pipedInGraphNode, ...argNodes.value],
|
|
3166
|
+
outTypes,
|
|
3167
|
+
inTypes
|
|
3168
|
+
);
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
const argNode = yield* option(processLayerGraphNode(ctx, node, void 0));
|
|
3172
|
+
if (isSome2(argNode)) {
|
|
3173
|
+
return new GraphNodeCompoundTransform(
|
|
3174
|
+
ctx.nextId(),
|
|
3175
|
+
node,
|
|
3176
|
+
[pipedInGraphNode, argNode.value],
|
|
3177
|
+
outTypes,
|
|
3178
|
+
inTypes
|
|
3179
|
+
);
|
|
3180
|
+
} else {
|
|
3181
|
+
return new GraphNodeCompoundTransform(
|
|
3182
|
+
ctx.nextId(),
|
|
3183
|
+
node,
|
|
3184
|
+
[pipedInGraphNode],
|
|
3185
|
+
outTypes,
|
|
3186
|
+
inTypes
|
|
3187
|
+
);
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
if (ts.isExpression(node)) {
|
|
3194
|
+
const type = typeChecker.getTypeAtLocation(node);
|
|
3195
|
+
const maybeLayer = yield* option(layerType(type, node));
|
|
3196
|
+
if (isSome2(maybeLayer)) {
|
|
3197
|
+
const { allIndexes: outTypes } = yield* appendToUniqueTypesMap(
|
|
3198
|
+
ctx.services,
|
|
3199
|
+
maybeLayer.value.ROut,
|
|
3200
|
+
true
|
|
3201
|
+
);
|
|
3202
|
+
const { allIndexes: inTypes } = yield* appendToUniqueTypesMap(
|
|
3203
|
+
ctx.services,
|
|
3204
|
+
maybeLayer.value.RIn,
|
|
3205
|
+
true
|
|
3206
|
+
);
|
|
3207
|
+
return new GraphNodeLeaf(ctx.nextId(), node, outTypes, inTypes);
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
return yield* fail(new UnableToProduceLayerGraphError(node.getText()));
|
|
3211
|
+
});
|
|
3212
|
+
}
|
|
3213
|
+
function findInnermostGraphEdge(graph, kind, key) {
|
|
3214
|
+
switch (graph._tag) {
|
|
3215
|
+
case "GraphNodeLeaf":
|
|
3216
|
+
return graph[kind].indexOf(key) > -1 ? [graph] : [];
|
|
3217
|
+
case "GraphNodeCompoundTransform": {
|
|
3218
|
+
if (graph[kind].indexOf(key) > -1) {
|
|
3219
|
+
let result = [];
|
|
3220
|
+
for (const child of graph.args) {
|
|
3221
|
+
result = result.concat(findInnermostGraphEdge(child, kind, key));
|
|
3222
|
+
}
|
|
3223
|
+
if (result.length > 0) return result;
|
|
3224
|
+
return [graph];
|
|
3225
|
+
}
|
|
3226
|
+
return [];
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
function escapeMermaid(text) {
|
|
3231
|
+
return text.replace(/"/mg, "#quot;").replace(/\n/mg, " ");
|
|
3232
|
+
}
|
|
3233
|
+
function processNodeMermaid(graph, ctx, ctxL) {
|
|
3234
|
+
return gen2(function* () {
|
|
3235
|
+
const ts = yield* service(TypeScriptApi);
|
|
3236
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3237
|
+
let subgraphDefs = [];
|
|
3238
|
+
if (!ctx.seenIds.has(graph.id)) {
|
|
3239
|
+
const subgraphsIn = [];
|
|
3240
|
+
for (const serviceId of graph.rin) {
|
|
3241
|
+
const type = ctxL.services.get(serviceId);
|
|
3242
|
+
const typeString = typeChecker.typeToString(type, void 0, ts.TypeFormatFlags.NoTruncation);
|
|
3243
|
+
subgraphsIn.push("subgraph " + graph.id + "_rin_" + serviceId + ' ["`' + escapeMermaid(typeString) + '`"]');
|
|
3244
|
+
subgraphsIn.push("end");
|
|
3245
|
+
}
|
|
3246
|
+
const subgraphsOut = [];
|
|
3247
|
+
for (const serviceId of graph.rout) {
|
|
3248
|
+
const type = ctxL.services.get(serviceId);
|
|
3249
|
+
const typeString = typeChecker.typeToString(type, void 0, ts.TypeFormatFlags.NoTruncation);
|
|
3250
|
+
subgraphsOut.push("subgraph " + graph.id + "_rout_" + serviceId + ' ["`' + escapeMermaid(typeString) + '`"]');
|
|
3251
|
+
subgraphsOut.push("end");
|
|
3252
|
+
}
|
|
3253
|
+
const sourceFile = graph.node.getSourceFile();
|
|
3254
|
+
const nodePosition = graph.node.getStart(sourceFile, false);
|
|
3255
|
+
const { character, line } = ts.getLineAndCharacterOfPosition(sourceFile, nodePosition);
|
|
3256
|
+
if (subgraphsIn.length > 0) {
|
|
3257
|
+
subgraphDefs = [
|
|
3258
|
+
...subgraphDefs,
|
|
3259
|
+
"subgraph " + graph.id + "_rin [Requires]",
|
|
3260
|
+
...subgraphsIn,
|
|
3261
|
+
"end",
|
|
3262
|
+
"style " + graph.id + "_rin stroke:none"
|
|
3263
|
+
];
|
|
3264
|
+
}
|
|
3265
|
+
if (subgraphsOut.length > 0) {
|
|
3266
|
+
subgraphDefs = [
|
|
3267
|
+
...subgraphDefs,
|
|
3268
|
+
"subgraph " + graph.id + "_rout [Provides]",
|
|
3269
|
+
...subgraphsOut,
|
|
3270
|
+
"end",
|
|
3271
|
+
"style " + graph.id + "_rout stroke:none"
|
|
3272
|
+
];
|
|
3273
|
+
}
|
|
3274
|
+
subgraphDefs = [
|
|
3275
|
+
"subgraph " + graph.id + ' ["`' + escapeMermaid(graph.node.getText()) + " _at ln " + (line + 1) + " col " + character + '_`"]',
|
|
3276
|
+
...subgraphDefs,
|
|
3277
|
+
"end",
|
|
3278
|
+
"style " + graph.id + " fill:transparent"
|
|
3279
|
+
];
|
|
3280
|
+
ctx.seenIds.add(graph.id);
|
|
3281
|
+
}
|
|
3282
|
+
switch (graph._tag) {
|
|
3283
|
+
case "GraphNodeLeaf": {
|
|
3284
|
+
return subgraphDefs;
|
|
3285
|
+
}
|
|
3286
|
+
case "GraphNodeCompoundTransform": {
|
|
3287
|
+
const childs = flatten(yield* all2(...graph.args.map((_) => processNodeMermaid(_, ctx, ctxL))));
|
|
3288
|
+
let currentEdges = [];
|
|
3289
|
+
const connectedNodes = /* @__PURE__ */ new Set();
|
|
3290
|
+
for (const requiredServiceKey of graph.rin) {
|
|
3291
|
+
for (const childNode of graph.args.filter((childNode2) => childNode2.rin.indexOf(requiredServiceKey) > -1)) {
|
|
3292
|
+
currentEdges = [
|
|
3293
|
+
...currentEdges,
|
|
3294
|
+
graph.id + "_rin_" + requiredServiceKey + " -.-> " + childNode.id + "_rin_" + requiredServiceKey
|
|
3295
|
+
];
|
|
3296
|
+
connectedNodes.add(childNode.id);
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
for (const providedServiceKey of graph.rout) {
|
|
3300
|
+
for (const childNode of graph.args.filter((childNode2) => childNode2.rout.indexOf(providedServiceKey) > -1)) {
|
|
3301
|
+
currentEdges = [
|
|
3302
|
+
...currentEdges,
|
|
3303
|
+
graph.id + "_rout_" + providedServiceKey + " -.-> " + childNode.id + "_rout_" + providedServiceKey
|
|
3304
|
+
];
|
|
3305
|
+
connectedNodes.add(childNode.id);
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
for (const childNode of graph.args) {
|
|
3309
|
+
if (!connectedNodes.has(childNode.id)) {
|
|
3310
|
+
currentEdges = [...currentEdges, graph.id + " -.-x " + childNode.id];
|
|
3311
|
+
}
|
|
3312
|
+
}
|
|
3313
|
+
return [...subgraphDefs, ...childs, ...currentEdges];
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3316
|
+
});
|
|
3317
|
+
}
|
|
3318
|
+
function generateMarmaidUri(graph, ctxL) {
|
|
3319
|
+
return gen2(function* () {
|
|
3320
|
+
const ctx = {
|
|
3321
|
+
seenIds: /* @__PURE__ */ new Set()
|
|
3322
|
+
};
|
|
3323
|
+
const lines = yield* processNodeMermaid(graph, ctx, ctxL);
|
|
3324
|
+
const code = "flowchart TB\n" + lines.join("\n");
|
|
3325
|
+
const state = btoa(JSON.stringify({ code }));
|
|
3326
|
+
return "https://www.mermaidchart.com/play#" + state;
|
|
3327
|
+
});
|
|
3328
|
+
}
|
|
3329
|
+
function layerInfo(sourceFile, position, quickInfo2) {
|
|
3330
|
+
return pipe(
|
|
3331
|
+
gen2(function* () {
|
|
3332
|
+
const ts = yield* service(TypeScriptApi);
|
|
3333
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3334
|
+
const range = toTextRange(position);
|
|
3335
|
+
const maybeNode = pipe(
|
|
3336
|
+
yield* getAncestorNodesInRange(sourceFile, range),
|
|
3337
|
+
filter((_) => ts.isVariableDeclaration(_) || ts.isPropertyDeclaration(_)),
|
|
3338
|
+
filter((_) => isNodeInRange(range)(_.name)),
|
|
3339
|
+
head
|
|
3340
|
+
);
|
|
3341
|
+
if (isNone2(maybeNode)) return quickInfo2;
|
|
3342
|
+
const node = maybeNode.value;
|
|
3343
|
+
const layerNode = node.initializer ? node.initializer : node;
|
|
3344
|
+
const layerType2 = typeChecker.getTypeAtLocation(layerNode);
|
|
3345
|
+
const maybeLayer = yield* option(layerType(layerType2, layerNode));
|
|
3346
|
+
if (isNone2(maybeLayer)) return quickInfo2;
|
|
3347
|
+
let lastId = 0;
|
|
3348
|
+
const graphCtx = {
|
|
3349
|
+
services: /* @__PURE__ */ new Map(),
|
|
3350
|
+
serviceTypeToString: /* @__PURE__ */ new Map(),
|
|
3351
|
+
nextId: () => "id" + lastId++
|
|
3352
|
+
};
|
|
3353
|
+
const layerInfoDisplayParts = yield* pipe(
|
|
3354
|
+
processLayerGraphNode(graphCtx, layerNode, void 0),
|
|
3355
|
+
flatMap3(
|
|
3356
|
+
(rootNode) => gen2(function* () {
|
|
3357
|
+
yield* succeed(void 0);
|
|
3358
|
+
const lines = [];
|
|
3359
|
+
const appendInfo = (providesNode, type, kindText) => {
|
|
3360
|
+
const typeString = typeChecker.typeToString(
|
|
3361
|
+
type,
|
|
3362
|
+
void 0,
|
|
3363
|
+
ts.TypeFormatFlags.NoTruncation
|
|
3364
|
+
);
|
|
3365
|
+
const positions = providesNode.map((_) => {
|
|
3366
|
+
const nodePosition = _.node.getStart(sourceFile, false);
|
|
3367
|
+
const { character, line } = ts.getLineAndCharacterOfPosition(sourceFile, nodePosition);
|
|
3368
|
+
const nodeText = _.node.getText().trim().substr(0, 100);
|
|
3369
|
+
return "ln " + (line + 1) + " col " + character + " by `" + nodeText + "`";
|
|
3370
|
+
});
|
|
3371
|
+
lines.push("- " + typeString + " " + kindText + " at " + positions.join(", "));
|
|
3372
|
+
};
|
|
3373
|
+
for (const providesKey of rootNode.rout) {
|
|
3374
|
+
const providesNode = findInnermostGraphEdge(rootNode, "rout", providesKey);
|
|
3375
|
+
appendInfo(providesNode, graphCtx.services.get(providesKey), "provided");
|
|
3376
|
+
}
|
|
3377
|
+
lines.push("");
|
|
3378
|
+
for (const requiresKey of rootNode.rin) {
|
|
3379
|
+
const requiresNode = findInnermostGraphEdge(rootNode, "rin", requiresKey);
|
|
3380
|
+
appendInfo(requiresNode, graphCtx.services.get(requiresKey), "required");
|
|
3381
|
+
}
|
|
3382
|
+
const mermaidUri = yield* option(generateMarmaidUri(rootNode, graphCtx));
|
|
3383
|
+
const linkParts = [];
|
|
3384
|
+
if (isSome2(mermaidUri)) {
|
|
3385
|
+
linkParts.push({ kind: "space", text: "\n" });
|
|
3386
|
+
linkParts.push({ kind: "link", text: "{@link " });
|
|
3387
|
+
linkParts.push({ kind: "linkText", text: mermaidUri.value + " Show full Layer graph" });
|
|
3388
|
+
linkParts.push({ kind: "link", text: "}" });
|
|
3389
|
+
linkParts.push({ kind: "space", text: "\n" });
|
|
3390
|
+
}
|
|
3391
|
+
return [
|
|
3392
|
+
{
|
|
3393
|
+
kind: "text",
|
|
3394
|
+
text: "```\n/**\n" + lines.map((l) => " * " + l).join("\n") + "\n */\n```\n"
|
|
3395
|
+
},
|
|
3396
|
+
...linkParts
|
|
3397
|
+
];
|
|
3398
|
+
})
|
|
3399
|
+
),
|
|
3400
|
+
orElse3(
|
|
3401
|
+
(e) => succeed([{
|
|
3402
|
+
kind: "text",
|
|
3403
|
+
text: "```\n/** layer graph not created: " + e.message + " */\n```\n"
|
|
3404
|
+
}])
|
|
3405
|
+
)
|
|
3406
|
+
);
|
|
3407
|
+
if (!quickInfo2) {
|
|
3408
|
+
const start = node.getStart();
|
|
3409
|
+
const end = node.getEnd();
|
|
3410
|
+
return {
|
|
3411
|
+
kind: ts.ScriptElementKind.callSignatureElement,
|
|
3412
|
+
kindModifiers: "",
|
|
3413
|
+
textSpan: { start, length: end - start },
|
|
3414
|
+
documentation: layerInfoDisplayParts
|
|
3415
|
+
};
|
|
3416
|
+
}
|
|
3417
|
+
if (quickInfo2.documentation) {
|
|
3418
|
+
return {
|
|
3419
|
+
...quickInfo2,
|
|
3420
|
+
documentation: quickInfo2.documentation.concat([{ kind: "space", text: "\n" }]).concat(layerInfoDisplayParts)
|
|
3421
|
+
};
|
|
3422
|
+
}
|
|
3423
|
+
return {
|
|
3424
|
+
...quickInfo2,
|
|
3425
|
+
documentation: layerInfoDisplayParts
|
|
3426
|
+
};
|
|
3427
|
+
}),
|
|
3428
|
+
orElse3(() => succeed(quickInfo2))
|
|
2806
3429
|
);
|
|
2807
3430
|
}
|
|
2808
3431
|
|
|
3432
|
+
// src/quickinfo.ts
|
|
3433
|
+
function quickInfo(sourceFile, position, quickInfo2) {
|
|
3434
|
+
return gen2(function* () {
|
|
3435
|
+
const deduped = yield* dedupeJsDocs(quickInfo2);
|
|
3436
|
+
const withEffectTypeArgs = yield* effectTypeArgs(sourceFile, position, deduped);
|
|
3437
|
+
const withLayerInfo = yield* layerInfo(sourceFile, position, withEffectTypeArgs);
|
|
3438
|
+
return withLayerInfo;
|
|
3439
|
+
});
|
|
3440
|
+
}
|
|
3441
|
+
|
|
2809
3442
|
// src/refactors/asyncAwaitToGen.ts
|
|
2810
3443
|
var asyncAwaitToGen = createRefactor({
|
|
2811
|
-
name: "
|
|
3444
|
+
name: "asyncAwaitToGen",
|
|
2812
3445
|
description: "Convert to Effect.gen",
|
|
2813
3446
|
apply: fn("asyncAwaitToGen.apply")(function* (sourceFile, textRange) {
|
|
2814
3447
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -2819,9 +3452,7 @@ var asyncAwaitToGen = createRefactor({
|
|
|
2819
3452
|
(node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
|
|
2820
3453
|
),
|
|
2821
3454
|
filter((node2) => !!node2.body),
|
|
2822
|
-
filter(
|
|
2823
|
-
(node2) => !!(ts.getCombinedModifierFlags(node2) & ts.ModifierFlags.Async)
|
|
2824
|
-
),
|
|
3455
|
+
filter((node2) => !!(ts.getCombinedModifierFlags(node2) & ts.ModifierFlags.Async)),
|
|
2825
3456
|
head
|
|
2826
3457
|
);
|
|
2827
3458
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -2880,7 +3511,7 @@ var asyncAwaitToGen = createRefactor({
|
|
|
2880
3511
|
|
|
2881
3512
|
// src/refactors/asyncAwaitToGenTryPromise.ts
|
|
2882
3513
|
var asyncAwaitToGenTryPromise = createRefactor({
|
|
2883
|
-
name: "
|
|
3514
|
+
name: "asyncAwaitToGenTryPromise",
|
|
2884
3515
|
description: "Convert to Effect.gen with failures",
|
|
2885
3516
|
apply: fn("asyncAwaitToGenTryPromise.apply")(function* (sourceFile, textRange) {
|
|
2886
3517
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -2891,9 +3522,7 @@ var asyncAwaitToGenTryPromise = createRefactor({
|
|
|
2891
3522
|
(node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
|
|
2892
3523
|
),
|
|
2893
3524
|
filter((node2) => !!node2.body),
|
|
2894
|
-
filter(
|
|
2895
|
-
(node2) => !!(ts.getCombinedModifierFlags(node2) & ts.ModifierFlags.Async)
|
|
2896
|
-
),
|
|
3525
|
+
filter((node2) => !!(ts.getCombinedModifierFlags(node2) & ts.ModifierFlags.Async)),
|
|
2897
3526
|
head
|
|
2898
3527
|
);
|
|
2899
3528
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
@@ -2982,7 +3611,7 @@ var asyncAwaitToGenTryPromise = createRefactor({
|
|
|
2982
3611
|
|
|
2983
3612
|
// src/refactors/effectGenToFn.ts
|
|
2984
3613
|
var effectGenToFn = createRefactor({
|
|
2985
|
-
name: "
|
|
3614
|
+
name: "effectGenToFn",
|
|
2986
3615
|
description: "Convert to Effect.fn",
|
|
2987
3616
|
apply: fn("effectGenToFn.apply")(function* (sourceFile, textRange) {
|
|
2988
3617
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -3072,7 +3701,7 @@ var effectGenToFn = createRefactor({
|
|
|
3072
3701
|
|
|
3073
3702
|
// src/refactors/functionToArrow.ts
|
|
3074
3703
|
var functionToArrow = createRefactor({
|
|
3075
|
-
name: "
|
|
3704
|
+
name: "functionToArrow",
|
|
3076
3705
|
description: "Convert to arrow",
|
|
3077
3706
|
apply: fn("functionToArrow.apply")(function* (sourceFile, textRange) {
|
|
3078
3707
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -3240,7 +3869,7 @@ var _createOpaqueTypes = fn("_createOpaqueTypes")(function* (effectSchemaName, i
|
|
|
3240
3869
|
return { contextType, encodedType, opaqueType };
|
|
3241
3870
|
});
|
|
3242
3871
|
var makeSchemaOpaque = createRefactor({
|
|
3243
|
-
name: "
|
|
3872
|
+
name: "makeSchemaOpaque",
|
|
3244
3873
|
description: "Make Schema opaque",
|
|
3245
3874
|
apply: fn("makeSchemaOpaque.apply")(function* (sourceFile, textRange) {
|
|
3246
3875
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -3318,7 +3947,7 @@ var makeSchemaOpaque = createRefactor({
|
|
|
3318
3947
|
|
|
3319
3948
|
// src/refactors/makeSchemaOpaqueWithNs.ts
|
|
3320
3949
|
var makeSchemaOpaqueWithNs = createRefactor({
|
|
3321
|
-
name: "
|
|
3950
|
+
name: "makeSchemaOpaqueWithNs",
|
|
3322
3951
|
description: "Make Schema opaque with namespace",
|
|
3323
3952
|
apply: fn("makeSchemaOpaqueWithNs.apply")(function* (sourceFile, textRange) {
|
|
3324
3953
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -3412,7 +4041,7 @@ var makeSchemaOpaqueWithNs = createRefactor({
|
|
|
3412
4041
|
|
|
3413
4042
|
// src/refactors/pipeableToDatafirst.ts
|
|
3414
4043
|
var pipeableToDatafirst = createRefactor({
|
|
3415
|
-
name: "
|
|
4044
|
+
name: "pipeableToDatafirst",
|
|
3416
4045
|
description: "Rewrite to datafirst",
|
|
3417
4046
|
apply: fn("pipeableToDatafirst.apply")(function* (sourceFile, textRange) {
|
|
3418
4047
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -3495,23 +4124,19 @@ var pipeableToDatafirst = createRefactor({
|
|
|
3495
4124
|
|
|
3496
4125
|
// src/refactors/removeUnnecessaryEffectGen.ts
|
|
3497
4126
|
var removeUnnecessaryEffectGen = createRefactor({
|
|
3498
|
-
name: "
|
|
4127
|
+
name: "removeUnnecessaryEffectGen",
|
|
3499
4128
|
description: "Remove unnecessary Effect.gen",
|
|
3500
4129
|
apply: fn("removeUnnecessaryEffectGen.apply")(function* (sourceFile, textRange) {
|
|
3501
4130
|
for (const nodeToReplace of yield* getAncestorNodesInRange(sourceFile, textRange)) {
|
|
3502
|
-
const maybeNode = yield*
|
|
3503
|
-
effectGen(nodeToReplace),
|
|
3504
|
-
flatMap3(({ body }) => returnYieldEffectBlock(body)),
|
|
3505
|
-
option
|
|
3506
|
-
);
|
|
4131
|
+
const maybeNode = yield* option(unnecessaryEffectGen(nodeToReplace));
|
|
3507
4132
|
if (isNone2(maybeNode)) continue;
|
|
3508
|
-
const
|
|
4133
|
+
const replacementNode = maybeNode.value.replacementNode;
|
|
3509
4134
|
return {
|
|
3510
4135
|
kind: "refactor.rewrite.effect.removeUnnecessaryEffectGen",
|
|
3511
4136
|
description: "Remove unnecessary Effect.gen",
|
|
3512
4137
|
apply: gen2(function* () {
|
|
3513
4138
|
const changeTracker = yield* service(ChangeTracker);
|
|
3514
|
-
changeTracker.replaceNode(sourceFile, nodeToReplace,
|
|
4139
|
+
changeTracker.replaceNode(sourceFile, nodeToReplace, yield* replacementNode);
|
|
3515
4140
|
})
|
|
3516
4141
|
};
|
|
3517
4142
|
}
|
|
@@ -3521,7 +4146,7 @@ var removeUnnecessaryEffectGen = createRefactor({
|
|
|
3521
4146
|
|
|
3522
4147
|
// src/refactors/toggleLazyConst.ts
|
|
3523
4148
|
var toggleLazyConst = createRefactor({
|
|
3524
|
-
name: "
|
|
4149
|
+
name: "toggleLazyConst",
|
|
3525
4150
|
description: "Toggle lazy const",
|
|
3526
4151
|
apply: fn("toggleLazyConst.apply")(function* (sourceFile, textRange) {
|
|
3527
4152
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -3561,7 +4186,7 @@ var toggleLazyConst = createRefactor({
|
|
|
3561
4186
|
|
|
3562
4187
|
// src/refactors/toggleReturnTypeAnnotation.ts
|
|
3563
4188
|
var toggleReturnTypeAnnotation = createRefactor({
|
|
3564
|
-
name: "
|
|
4189
|
+
name: "toggleReturnTypeAnnotation",
|
|
3565
4190
|
description: "Toggle return type annotation",
|
|
3566
4191
|
apply: fn("toggleReturnTypeAnnotation.apply")(function* (sourceFile, textRange) {
|
|
3567
4192
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -3611,16 +4236,14 @@ var toggleReturnTypeAnnotation = createRefactor({
|
|
|
3611
4236
|
|
|
3612
4237
|
// src/refactors/toggleTypeAnnotation.ts
|
|
3613
4238
|
var toggleTypeAnnotation = createRefactor({
|
|
3614
|
-
name: "
|
|
4239
|
+
name: "toggleTypeAnnotation",
|
|
3615
4240
|
description: "Toggle type annotation",
|
|
3616
4241
|
apply: fn("toggleTypeAnnotation.apply")(function* (sourceFile, textRange) {
|
|
3617
4242
|
const ts = yield* service(TypeScriptApi);
|
|
3618
4243
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3619
4244
|
const maybeNode = pipe(
|
|
3620
4245
|
yield* getAncestorNodesInRange(sourceFile, textRange),
|
|
3621
|
-
filter(
|
|
3622
|
-
(node2) => ts.isVariableDeclaration(node2) || ts.isPropertyDeclaration(node2)
|
|
3623
|
-
),
|
|
4246
|
+
filter((node2) => ts.isVariableDeclaration(node2) || ts.isPropertyDeclaration(node2)),
|
|
3624
4247
|
filter((node2) => isNodeInRange(textRange)(node2.name)),
|
|
3625
4248
|
filter((node2) => !!node2.initializer),
|
|
3626
4249
|
head
|
|
@@ -4130,7 +4753,7 @@ var applyAtNode = fn("SchemaGen.applyAtNode")(
|
|
|
4130
4753
|
|
|
4131
4754
|
// src/refactors/typeToEffectSchema.ts
|
|
4132
4755
|
var typeToEffectSchema = createRefactor({
|
|
4133
|
-
name: "
|
|
4756
|
+
name: "typeToEffectSchema",
|
|
4134
4757
|
description: "Refactor to Schema",
|
|
4135
4758
|
apply: fn("typeToEffectSchema.apply")(function* (sourceFile, textRange) {
|
|
4136
4759
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -4152,7 +4775,7 @@ var typeToEffectSchema = createRefactor({
|
|
|
4152
4775
|
|
|
4153
4776
|
// src/refactors/typeToEffectSchemaClass.ts
|
|
4154
4777
|
var typeToEffectSchemaClass = createRefactor({
|
|
4155
|
-
name: "
|
|
4778
|
+
name: "typeToEffectSchemaClass",
|
|
4156
4779
|
description: "Refactor to Schema.Class",
|
|
4157
4780
|
apply: fn("typeToEffectSchemaClass.apply")(function* (sourceFile, textRange) {
|
|
4158
4781
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -4174,7 +4797,7 @@ var typeToEffectSchemaClass = createRefactor({
|
|
|
4174
4797
|
|
|
4175
4798
|
// src/refactors/wrapWithEffectGen.ts
|
|
4176
4799
|
var wrapWithEffectGen = createRefactor({
|
|
4177
|
-
name: "
|
|
4800
|
+
name: "wrapWithEffectGen",
|
|
4178
4801
|
description: "Wrap with Effect.gen",
|
|
4179
4802
|
apply: fn("wrapWithEffectGen.apply")(function* (sourceFile, textRange) {
|
|
4180
4803
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -4239,7 +4862,7 @@ var getEffectModuleIdentifierName = fn("getEffectModuleIdentifierName")(
|
|
|
4239
4862
|
|
|
4240
4863
|
// src/refactors/wrapWithPipe.ts
|
|
4241
4864
|
var wrapWithPipe = createRefactor({
|
|
4242
|
-
name: "
|
|
4865
|
+
name: "wrapWithPipe",
|
|
4243
4866
|
description: "Wrap with pipe",
|
|
4244
4867
|
apply: fn("wrapWithPipe.apply")(function* (sourceFile, textRange) {
|
|
4245
4868
|
if (textRange.end - textRange.pos === 0) {
|
|
@@ -4277,10 +4900,12 @@ var refactors = [
|
|
|
4277
4900
|
];
|
|
4278
4901
|
|
|
4279
4902
|
// src/index.ts
|
|
4903
|
+
var LSP_INJECTED_URI = "@effect/language-service/injected";
|
|
4280
4904
|
var init = (modules) => {
|
|
4281
4905
|
function create(info) {
|
|
4282
4906
|
const languageService = info.languageService;
|
|
4283
|
-
|
|
4907
|
+
if (languageService[LSP_INJECTED_URI]) return languageService;
|
|
4908
|
+
const languageServicePluginOptions = parse(info.config);
|
|
4284
4909
|
const diagnosticsErrorCodes = diagnostics.map((diagnostic) => diagnostic.code);
|
|
4285
4910
|
try {
|
|
4286
4911
|
;
|
|
@@ -4291,28 +4916,38 @@ var init = (modules) => {
|
|
|
4291
4916
|
} catch (_) {
|
|
4292
4917
|
}
|
|
4293
4918
|
const proxy = /* @__PURE__ */ Object.create(null);
|
|
4919
|
+
proxy[LSP_INJECTED_URI] = true;
|
|
4294
4920
|
for (const k of Object.keys(languageService)) {
|
|
4295
4921
|
proxy[k] = (...args) => languageService[k].apply(languageService, args);
|
|
4296
4922
|
}
|
|
4923
|
+
function runNano(program) {
|
|
4924
|
+
return (fa) => pipe(
|
|
4925
|
+
fa,
|
|
4926
|
+
provideService(TypeScriptProgram, program),
|
|
4927
|
+
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
4928
|
+
provideService(
|
|
4929
|
+
TypeCheckerApiCache,
|
|
4930
|
+
makeTypeCheckerApiCache()
|
|
4931
|
+
),
|
|
4932
|
+
provideService(TypeScriptApi, modules.typescript),
|
|
4933
|
+
provideService(
|
|
4934
|
+
LanguageServicePluginOptions,
|
|
4935
|
+
languageServicePluginOptions
|
|
4936
|
+
),
|
|
4937
|
+
run
|
|
4938
|
+
);
|
|
4939
|
+
}
|
|
4297
4940
|
const effectCodeFixesForFile = /* @__PURE__ */ new Map();
|
|
4298
4941
|
proxy.getSemanticDiagnostics = (fileName, ...args) => {
|
|
4299
4942
|
const applicableDiagnostics = languageService.getSemanticDiagnostics(fileName, ...args);
|
|
4300
4943
|
const program = languageService.getProgram();
|
|
4301
|
-
if (
|
|
4944
|
+
if (languageServicePluginOptions.diagnostics && program) {
|
|
4302
4945
|
effectCodeFixesForFile.delete(fileName);
|
|
4303
4946
|
const sourceFile = program.getSourceFile(fileName);
|
|
4304
4947
|
if (sourceFile) {
|
|
4305
4948
|
return pipe(
|
|
4306
4949
|
getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),
|
|
4307
|
-
|
|
4308
|
-
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
4309
|
-
provideService(
|
|
4310
|
-
TypeCheckerApiCache,
|
|
4311
|
-
makeTypeCheckerApiCache()
|
|
4312
|
-
),
|
|
4313
|
-
provideService(TypeScriptApi, modules.typescript),
|
|
4314
|
-
provideService(PluginOptions, pluginOptions),
|
|
4315
|
-
run,
|
|
4950
|
+
runNano(program),
|
|
4316
4951
|
Either_exports.map(({ codeFixes, diagnostics: diagnostics2 }) => {
|
|
4317
4952
|
effectCodeFixesForFile.set(fileName, codeFixes);
|
|
4318
4953
|
return diagnostics2.concat(applicableDiagnostics);
|
|
@@ -4381,14 +5016,7 @@ var init = (modules) => {
|
|
|
4381
5016
|
if (sourceFile) {
|
|
4382
5017
|
return pipe(
|
|
4383
5018
|
getApplicableRefactors(refactors, sourceFile, positionOrRange),
|
|
4384
|
-
|
|
4385
|
-
provideService(
|
|
4386
|
-
TypeCheckerApiCache,
|
|
4387
|
-
makeTypeCheckerApiCache()
|
|
4388
|
-
),
|
|
4389
|
-
provideService(TypeScriptApi, modules.typescript),
|
|
4390
|
-
provideService(PluginOptions, pluginOptions),
|
|
4391
|
-
run,
|
|
5019
|
+
runNano(program),
|
|
4392
5020
|
Either_exports.map((effectRefactors) => applicableRefactors.concat(effectRefactors)),
|
|
4393
5021
|
Either_exports.getOrElse(() => applicableRefactors)
|
|
4394
5022
|
);
|
|
@@ -4427,14 +5055,7 @@ var init = (modules) => {
|
|
|
4427
5055
|
);
|
|
4428
5056
|
return { edits };
|
|
4429
5057
|
}),
|
|
4430
|
-
|
|
4431
|
-
provideService(
|
|
4432
|
-
TypeCheckerApiCache,
|
|
4433
|
-
makeTypeCheckerApiCache()
|
|
4434
|
-
),
|
|
4435
|
-
provideService(TypeScriptApi, modules.typescript),
|
|
4436
|
-
provideService(PluginOptions, pluginOptions),
|
|
4437
|
-
run
|
|
5058
|
+
runNano(program)
|
|
4438
5059
|
);
|
|
4439
5060
|
if (Either_exports.isRight(result)) return result.right;
|
|
4440
5061
|
}
|
|
@@ -4450,31 +5071,25 @@ var init = (modules) => {
|
|
|
4450
5071
|
);
|
|
4451
5072
|
};
|
|
4452
5073
|
proxy.getQuickInfoAtPosition = (fileName, position, ...args) => {
|
|
4453
|
-
const
|
|
4454
|
-
if (
|
|
4455
|
-
const dedupedTagsQuickInfo = dedupeJsDocTags(quickInfo);
|
|
5074
|
+
const applicableQuickInfo = languageService.getQuickInfoAtPosition(fileName, position, ...args);
|
|
5075
|
+
if (languageServicePluginOptions.quickinfo) {
|
|
4456
5076
|
const program = languageService.getProgram();
|
|
4457
5077
|
if (program) {
|
|
4458
5078
|
const sourceFile = program.getSourceFile(fileName);
|
|
4459
5079
|
if (sourceFile) {
|
|
4460
5080
|
return pipe(
|
|
4461
|
-
|
|
5081
|
+
quickInfo(
|
|
4462
5082
|
sourceFile,
|
|
4463
5083
|
position,
|
|
4464
|
-
|
|
5084
|
+
applicableQuickInfo
|
|
4465
5085
|
),
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
provideService(TypeScriptApi, modules.typescript),
|
|
4469
|
-
provideService(PluginOptions, pluginOptions),
|
|
4470
|
-
run,
|
|
4471
|
-
Either_exports.getOrElse(() => dedupedTagsQuickInfo)
|
|
5086
|
+
runNano(program),
|
|
5087
|
+
Either_exports.getOrElse(() => applicableQuickInfo)
|
|
4472
5088
|
);
|
|
4473
5089
|
}
|
|
4474
5090
|
}
|
|
4475
|
-
return dedupedTagsQuickInfo;
|
|
4476
5091
|
}
|
|
4477
|
-
return
|
|
5092
|
+
return applicableQuickInfo;
|
|
4478
5093
|
};
|
|
4479
5094
|
proxy.getCompletionsAtPosition = (fileName, position, options, formattingSettings, ...args) => {
|
|
4480
5095
|
const applicableCompletions = languageService.getCompletionsAtPosition(
|
|
@@ -4484,7 +5099,7 @@ var init = (modules) => {
|
|
|
4484
5099
|
formattingSettings,
|
|
4485
5100
|
...args
|
|
4486
5101
|
);
|
|
4487
|
-
if (
|
|
5102
|
+
if (languageServicePluginOptions.completions) {
|
|
4488
5103
|
const program = languageService.getProgram();
|
|
4489
5104
|
if (program) {
|
|
4490
5105
|
const sourceFile = program.getSourceFile(fileName);
|
|
@@ -4497,15 +5112,7 @@ var init = (modules) => {
|
|
|
4497
5112
|
options,
|
|
4498
5113
|
formattingSettings
|
|
4499
5114
|
),
|
|
4500
|
-
|
|
4501
|
-
provideService(TypeCheckerApi, program.getTypeChecker()),
|
|
4502
|
-
provideService(
|
|
4503
|
-
TypeCheckerApiCache,
|
|
4504
|
-
makeTypeCheckerApiCache()
|
|
4505
|
-
),
|
|
4506
|
-
provideService(TypeScriptApi, modules.typescript),
|
|
4507
|
-
provideService(PluginOptions, pluginOptions),
|
|
4508
|
-
run,
|
|
5115
|
+
runNano(program),
|
|
4509
5116
|
Either_exports.map(
|
|
4510
5117
|
(effectCompletions) => applicableCompletions ? {
|
|
4511
5118
|
...applicableCompletions,
|