@effect/language-service 0.16.7 → 0.17.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 +1 -0
- package/index.js +98 -47
- package/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,6 +45,7 @@ And you're done! You'll now be able to use a set of refactor and diagnostics tha
|
|
|
45
45
|
### Completions
|
|
46
46
|
|
|
47
47
|
- Autocomplete 'Self' in Effect.Service, Context.Tag, Schema.TaggedClass, Schema.TaggedRequest and family
|
|
48
|
+
- Autocomplete Effect.gen with `function*(){}`
|
|
48
49
|
|
|
49
50
|
### Refactors
|
|
50
51
|
|
package/index.js
CHANGED
|
@@ -1372,50 +1372,62 @@ var tryPreserveDeclarationSemantics = fn("AST.tryPreserveDeclarationSemantics")(
|
|
|
1372
1372
|
return node;
|
|
1373
1373
|
}
|
|
1374
1374
|
);
|
|
1375
|
+
var parseAccessedExpressionForCompletion = fn(
|
|
1376
|
+
"AST.parseAccessedExpressionForCompletion"
|
|
1377
|
+
)(
|
|
1378
|
+
function* (sourceFile, position) {
|
|
1379
|
+
const ts = yield* service(TypeScriptApi);
|
|
1380
|
+
const precedingToken = ts.findPrecedingToken(position, sourceFile, void 0, true);
|
|
1381
|
+
if (!precedingToken) return yield* fail(new NodeNotFoundError());
|
|
1382
|
+
let accessedObject = precedingToken;
|
|
1383
|
+
let replacementSpan = ts.createTextSpan(position, 0);
|
|
1384
|
+
let outerNode = precedingToken;
|
|
1385
|
+
if (ts.isIdentifier(precedingToken) && precedingToken.parent && ts.isPropertyAccessExpression(precedingToken.parent)) {
|
|
1386
|
+
replacementSpan = ts.createTextSpan(
|
|
1387
|
+
precedingToken.parent.getStart(sourceFile),
|
|
1388
|
+
precedingToken.end - precedingToken.parent.getStart(sourceFile)
|
|
1389
|
+
);
|
|
1390
|
+
accessedObject = precedingToken.parent.expression;
|
|
1391
|
+
outerNode = precedingToken.parent;
|
|
1392
|
+
} else if (ts.isToken(precedingToken) && precedingToken.kind === ts.SyntaxKind.DotToken && ts.isPropertyAccessExpression(precedingToken.parent)) {
|
|
1393
|
+
replacementSpan = ts.createTextSpan(
|
|
1394
|
+
precedingToken.parent.getStart(sourceFile),
|
|
1395
|
+
precedingToken.end - precedingToken.parent.getStart(sourceFile)
|
|
1396
|
+
);
|
|
1397
|
+
accessedObject = precedingToken.parent.expression;
|
|
1398
|
+
outerNode = precedingToken.parent;
|
|
1399
|
+
} else if (ts.isIdentifier(precedingToken) && precedingToken.parent) {
|
|
1400
|
+
replacementSpan = ts.createTextSpan(
|
|
1401
|
+
precedingToken.getStart(sourceFile),
|
|
1402
|
+
precedingToken.end - precedingToken.getStart(sourceFile)
|
|
1403
|
+
);
|
|
1404
|
+
accessedObject = precedingToken;
|
|
1405
|
+
outerNode = precedingToken;
|
|
1406
|
+
} else {
|
|
1407
|
+
return yield* fail(new NodeNotFoundError());
|
|
1408
|
+
}
|
|
1409
|
+
return { accessedObject, outerNode, replacementSpan };
|
|
1410
|
+
}
|
|
1411
|
+
);
|
|
1375
1412
|
var parseDataForExtendsClassCompletion = fn(
|
|
1376
1413
|
"AST.parseDataForExtendsClassCompletion"
|
|
1377
1414
|
)(function* (sourceFile, position) {
|
|
1378
1415
|
const ts = yield* service(TypeScriptApi);
|
|
1379
|
-
const
|
|
1380
|
-
if (!
|
|
1381
|
-
let accessedObject = precedingToken;
|
|
1382
|
-
let replacementSpan = ts.createTextSpan(position, 0);
|
|
1383
|
-
let outerNode = precedingToken;
|
|
1384
|
-
if (ts.isIdentifier(precedingToken) && precedingToken.parent && ts.isPropertyAccessExpression(precedingToken.parent)) {
|
|
1385
|
-
replacementSpan = ts.createTextSpan(
|
|
1386
|
-
precedingToken.parent.getStart(sourceFile),
|
|
1387
|
-
precedingToken.end - precedingToken.parent.getStart(sourceFile)
|
|
1388
|
-
);
|
|
1389
|
-
accessedObject = precedingToken.parent.expression;
|
|
1390
|
-
outerNode = precedingToken.parent;
|
|
1391
|
-
} else if (ts.isToken(precedingToken) && precedingToken.kind === ts.SyntaxKind.DotToken && ts.isPropertyAccessExpression(precedingToken.parent)) {
|
|
1392
|
-
replacementSpan = ts.createTextSpan(
|
|
1393
|
-
precedingToken.parent.getStart(sourceFile),
|
|
1394
|
-
precedingToken.end - precedingToken.parent.getStart(sourceFile)
|
|
1395
|
-
);
|
|
1396
|
-
accessedObject = precedingToken.parent.expression;
|
|
1397
|
-
outerNode = precedingToken.parent;
|
|
1398
|
-
} else if (ts.isIdentifier(precedingToken) && precedingToken.parent) {
|
|
1399
|
-
replacementSpan = ts.createTextSpan(
|
|
1400
|
-
precedingToken.getStart(sourceFile),
|
|
1401
|
-
precedingToken.end - precedingToken.getStart(sourceFile)
|
|
1402
|
-
);
|
|
1403
|
-
accessedObject = precedingToken;
|
|
1404
|
-
outerNode = precedingToken;
|
|
1405
|
-
} else {
|
|
1406
|
-
return none2();
|
|
1407
|
-
}
|
|
1408
|
-
if (!ts.isIdentifier(accessedObject)) return none2();
|
|
1416
|
+
const { accessedObject, outerNode, replacementSpan } = yield* parseAccessedExpressionForCompletion(sourceFile, position);
|
|
1417
|
+
if (!ts.isIdentifier(accessedObject)) return yield* fail(new NodeNotFoundError());
|
|
1409
1418
|
let classDeclaration = outerNode.parent;
|
|
1410
1419
|
while (ts.isExpressionWithTypeArguments(classDeclaration) || ts.isHeritageClause(classDeclaration)) {
|
|
1411
1420
|
if (!classDeclaration.parent) break;
|
|
1412
1421
|
classDeclaration = classDeclaration.parent;
|
|
1413
1422
|
}
|
|
1414
|
-
if (!ts.isClassDeclaration(classDeclaration)) return
|
|
1415
|
-
if (!classDeclaration.name) return
|
|
1416
|
-
return
|
|
1417
|
-
|
|
1418
|
-
|
|
1423
|
+
if (!ts.isClassDeclaration(classDeclaration)) return yield* fail(new NodeNotFoundError());
|
|
1424
|
+
if (!classDeclaration.name) return yield* fail(new NodeNotFoundError());
|
|
1425
|
+
return {
|
|
1426
|
+
accessedObject,
|
|
1427
|
+
classDeclaration,
|
|
1428
|
+
className: classDeclaration.name,
|
|
1429
|
+
replacementSpan
|
|
1430
|
+
};
|
|
1419
1431
|
});
|
|
1420
1432
|
var createEffectGenCallExpression = fn("AST.createEffectGenCallExpression")(function* (effectModuleIdentifierName, node) {
|
|
1421
1433
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -1647,7 +1659,9 @@ var contextSelfInClasses = createCompletion({
|
|
|
1647
1659
|
name: "effect/contextSelfInClasses",
|
|
1648
1660
|
apply: fn("contextSelfInClasses")(function* (sourceFile, position) {
|
|
1649
1661
|
const ts = yield* service(TypeScriptApi);
|
|
1650
|
-
const maybeInfos = yield*
|
|
1662
|
+
const maybeInfos = yield* option(
|
|
1663
|
+
parseDataForExtendsClassCompletion(sourceFile, position)
|
|
1664
|
+
);
|
|
1651
1665
|
if (isNone2(maybeInfos)) return [];
|
|
1652
1666
|
const { accessedObject, className, replacementSpan } = maybeInfos.value;
|
|
1653
1667
|
const contextName = yield* option(
|
|
@@ -1678,7 +1692,9 @@ var effectDataClasses = createCompletion({
|
|
|
1678
1692
|
name: "effect/effectDataClasses",
|
|
1679
1693
|
apply: fn("effectDataClasses")(function* (sourceFile, position) {
|
|
1680
1694
|
const ts = yield* service(TypeScriptApi);
|
|
1681
|
-
const maybeInfos = yield*
|
|
1695
|
+
const maybeInfos = yield* option(
|
|
1696
|
+
parseDataForExtendsClassCompletion(sourceFile, position)
|
|
1697
|
+
);
|
|
1682
1698
|
if (isNone2(maybeInfos)) return [];
|
|
1683
1699
|
const { accessedObject, className, replacementSpan } = maybeInfos.value;
|
|
1684
1700
|
const dataName = yield* option(
|
|
@@ -1715,7 +1731,9 @@ var effectSchemaSelfInClasses = createCompletion({
|
|
|
1715
1731
|
name: "effect/effectSchemaSelfInClasses",
|
|
1716
1732
|
apply: fn("effectSchemaSelfInClasses")(function* (sourceFile, position) {
|
|
1717
1733
|
const ts = yield* service(TypeScriptApi);
|
|
1718
|
-
const maybeInfos = yield*
|
|
1734
|
+
const maybeInfos = yield* option(
|
|
1735
|
+
parseDataForExtendsClassCompletion(sourceFile, position)
|
|
1736
|
+
);
|
|
1719
1737
|
if (isNone2(maybeInfos)) return [];
|
|
1720
1738
|
const { accessedObject, className, replacementSpan } = maybeInfos.value;
|
|
1721
1739
|
const effectSchemaName = yield* option(
|
|
@@ -1764,7 +1782,9 @@ var effectSelfInClasses = createCompletion({
|
|
|
1764
1782
|
name: "effect/effectSelfInClasses",
|
|
1765
1783
|
apply: fn("effectSelfInClasses")(function* (sourceFile, position) {
|
|
1766
1784
|
const ts = yield* service(TypeScriptApi);
|
|
1767
|
-
const maybeInfos = yield*
|
|
1785
|
+
const maybeInfos = yield* option(
|
|
1786
|
+
parseDataForExtendsClassCompletion(sourceFile, position)
|
|
1787
|
+
);
|
|
1768
1788
|
if (isNone2(maybeInfos)) return [];
|
|
1769
1789
|
const { accessedObject, className, replacementSpan } = maybeInfos.value;
|
|
1770
1790
|
const effectName = yield* option(
|
|
@@ -1790,14 +1810,6 @@ var effectSelfInClasses = createCompletion({
|
|
|
1790
1810
|
})
|
|
1791
1811
|
});
|
|
1792
1812
|
|
|
1793
|
-
// src/completions.ts
|
|
1794
|
-
var completions = [
|
|
1795
|
-
effectSchemaSelfInClasses,
|
|
1796
|
-
effectSelfInClasses,
|
|
1797
|
-
contextSelfInClasses,
|
|
1798
|
-
effectDataClasses
|
|
1799
|
-
];
|
|
1800
|
-
|
|
1801
1813
|
// src/core/TypeCheckerApi.ts
|
|
1802
1814
|
var TypeCheckerApi = Tag("TypeChecker");
|
|
1803
1815
|
var TypeCheckerApiCache = Tag("TypeCheckerApiCache");
|
|
@@ -2004,6 +2016,45 @@ var expectedAndRealType = fn("TypeCheckerApi.expectedAndRealType")(function* (so
|
|
|
2004
2016
|
return result;
|
|
2005
2017
|
});
|
|
2006
2018
|
|
|
2019
|
+
// src/completions/genFunctionStar.ts
|
|
2020
|
+
var genFunctionStar = createCompletion({
|
|
2021
|
+
name: "effect/genFunctionStar",
|
|
2022
|
+
apply: fn("genFunctionStar")(function* (sourceFile, position) {
|
|
2023
|
+
const ts = yield* service(TypeScriptApi);
|
|
2024
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
2025
|
+
const maybeInfos = yield* option(
|
|
2026
|
+
parseAccessedExpressionForCompletion(sourceFile, position)
|
|
2027
|
+
);
|
|
2028
|
+
if (isNone2(maybeInfos)) return [];
|
|
2029
|
+
const { accessedObject } = maybeInfos.value;
|
|
2030
|
+
const type = typeChecker.getTypeAtLocation(accessedObject);
|
|
2031
|
+
const genMemberSymbol = type.getProperty("gen");
|
|
2032
|
+
if (!genMemberSymbol) return [];
|
|
2033
|
+
const genType = typeChecker.getTypeOfSymbolAtLocation(genMemberSymbol, accessedObject);
|
|
2034
|
+
if (genType.getCallSignatures().length === 0) return [];
|
|
2035
|
+
const span = ts.createTextSpan(
|
|
2036
|
+
accessedObject.end + 1,
|
|
2037
|
+
Math.max(0, position - accessedObject.end - 1)
|
|
2038
|
+
);
|
|
2039
|
+
return [{
|
|
2040
|
+
name: `gen(function*(){})`,
|
|
2041
|
+
kind: ts.ScriptElementKind.constElement,
|
|
2042
|
+
insertText: `gen(function*(){${"${0}"}})`,
|
|
2043
|
+
replacementSpan: span,
|
|
2044
|
+
isSnippet: true
|
|
2045
|
+
}];
|
|
2046
|
+
})
|
|
2047
|
+
});
|
|
2048
|
+
|
|
2049
|
+
// src/completions.ts
|
|
2050
|
+
var completions = [
|
|
2051
|
+
effectSchemaSelfInClasses,
|
|
2052
|
+
effectSelfInClasses,
|
|
2053
|
+
contextSelfInClasses,
|
|
2054
|
+
genFunctionStar,
|
|
2055
|
+
effectDataClasses
|
|
2056
|
+
];
|
|
2057
|
+
|
|
2007
2058
|
// src/utils/TypeParser.ts
|
|
2008
2059
|
var TypeParserIssue = class {
|
|
2009
2060
|
constructor(type, node, message) {
|