@effect/language-service 0.40.1 → 0.41.1
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/cli.js +51 -21
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +160 -25
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +184 -28
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +160 -25
- package/transform.js.map +1 -1
|
@@ -1209,6 +1209,56 @@ function parse(config) {
|
|
|
1209
1209
|
var TypeScriptApi = Tag("TypeScriptApi");
|
|
1210
1210
|
var TypeScriptProgram = Tag("TypeScriptProgram");
|
|
1211
1211
|
var ChangeTracker = Tag("ChangeTracker");
|
|
1212
|
+
function getPackageJsonInfoCache(program) {
|
|
1213
|
+
try {
|
|
1214
|
+
if (hasProperty(program, "getModuleResolutionCache") && isFunction2(program.getModuleResolutionCache)) {
|
|
1215
|
+
const moduleResolutionCache = program.getModuleResolutionCache();
|
|
1216
|
+
if (hasProperty(moduleResolutionCache, "getPackageJsonInfoCache") && isFunction2(moduleResolutionCache.getPackageJsonInfoCache)) {
|
|
1217
|
+
return moduleResolutionCache.getPackageJsonInfoCache();
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
} catch (_) {
|
|
1221
|
+
return void 0;
|
|
1222
|
+
}
|
|
1223
|
+
return void 0;
|
|
1224
|
+
}
|
|
1225
|
+
function getDirectoryPath(ts, path) {
|
|
1226
|
+
try {
|
|
1227
|
+
if (hasProperty(ts, "getDirectoryPath") && isFunction2(ts.getDirectoryPath)) {
|
|
1228
|
+
return ts.getDirectoryPath(path);
|
|
1229
|
+
}
|
|
1230
|
+
return path;
|
|
1231
|
+
} catch (_) {
|
|
1232
|
+
return path;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
function makeGetModuleSpecifier(ts) {
|
|
1236
|
+
if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
|
|
1237
|
+
const _internal = ts.moduleSpecifiers.getModuleSpecifier;
|
|
1238
|
+
return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options) => {
|
|
1239
|
+
return _internal(
|
|
1240
|
+
compilerOptions,
|
|
1241
|
+
importingSourceFile,
|
|
1242
|
+
importingSourceFileName,
|
|
1243
|
+
toFileName,
|
|
1244
|
+
host,
|
|
1245
|
+
options
|
|
1246
|
+
);
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
function makeGetTemporaryModuleResolutionState(ts) {
|
|
1250
|
+
if (hasProperty(ts, "getTemporaryModuleResolutionState") && isFunction2(ts.getTemporaryModuleResolutionState)) {
|
|
1251
|
+
const _internal = ts.getTemporaryModuleResolutionState;
|
|
1252
|
+
return (cache, program, compilerOptions) => _internal(cache, program, compilerOptions);
|
|
1253
|
+
}
|
|
1254
|
+
return void 0;
|
|
1255
|
+
}
|
|
1256
|
+
function makeGetPackageScopeForPath(ts) {
|
|
1257
|
+
if (hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath)) {
|
|
1258
|
+
const _internal = ts.getPackageScopeForPath;
|
|
1259
|
+
return (path, state) => _internal(path, state);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1212
1262
|
|
|
1213
1263
|
// src/core/TypeScriptUtils.ts
|
|
1214
1264
|
var TypeScriptUtils = Tag("TypeScriptUtils");
|
|
@@ -1217,6 +1267,8 @@ var nanoLayer = (fa) => pipe(
|
|
|
1217
1267
|
flatMap2((ts) => pipe(fa, provideService(TypeScriptUtils, makeTypeScriptUtils(ts))))
|
|
1218
1268
|
);
|
|
1219
1269
|
function makeTypeScriptUtils(ts) {
|
|
1270
|
+
const getTemporaryModuleResolutionState = makeGetTemporaryModuleResolutionState(ts);
|
|
1271
|
+
const getPackageScopeForPath = makeGetPackageScopeForPath(ts);
|
|
1220
1272
|
function parsePackageContentNameAndVersionFromScope(v) {
|
|
1221
1273
|
if (!isObject(v)) return;
|
|
1222
1274
|
if (!hasProperty(v, "packageJsonScope")) return;
|
|
@@ -1251,20 +1303,26 @@ function makeTypeScriptUtils(ts) {
|
|
|
1251
1303
|
exportsKeys
|
|
1252
1304
|
};
|
|
1253
1305
|
}
|
|
1254
|
-
function
|
|
1255
|
-
if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
|
|
1306
|
+
function resolveModuleWithPackageInfoFromSourceFile(program, sourceFile) {
|
|
1256
1307
|
let packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
|
|
1257
|
-
if (!packageJsonScope &&
|
|
1258
|
-
const
|
|
1259
|
-
|
|
1308
|
+
if (!packageJsonScope && getPackageScopeForPath && getTemporaryModuleResolutionState) {
|
|
1309
|
+
const packageJsonInfoCache = getPackageJsonInfoCache(program);
|
|
1310
|
+
const temporaryModuleResolutionState = getTemporaryModuleResolutionState(
|
|
1311
|
+
packageJsonInfoCache,
|
|
1260
1312
|
program,
|
|
1261
1313
|
program.getCompilerOptions()
|
|
1262
1314
|
);
|
|
1315
|
+
const directoryPath = getDirectoryPath(ts, sourceFile.fileName);
|
|
1263
1316
|
packageJsonScope = parsePackageContentNameAndVersionFromScope({
|
|
1264
1317
|
...sourceFile,
|
|
1265
|
-
packageJsonScope:
|
|
1318
|
+
packageJsonScope: getPackageScopeForPath(directoryPath, temporaryModuleResolutionState)
|
|
1266
1319
|
});
|
|
1267
1320
|
}
|
|
1321
|
+
return packageJsonScope;
|
|
1322
|
+
}
|
|
1323
|
+
function resolveModulePattern(program, sourceFile, pattern) {
|
|
1324
|
+
if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
|
|
1325
|
+
const packageJsonScope = resolveModuleWithPackageInfoFromSourceFile(program, sourceFile);
|
|
1268
1326
|
const referencedPackages = [];
|
|
1269
1327
|
for (const statement of sourceFile.statements) {
|
|
1270
1328
|
if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
@@ -1282,20 +1340,6 @@ function makeTypeScriptUtils(ts) {
|
|
|
1282
1340
|
)
|
|
1283
1341
|
);
|
|
1284
1342
|
}
|
|
1285
|
-
function makeGetModuleSpecifier() {
|
|
1286
|
-
if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
|
|
1287
|
-
const _internal = ts.moduleSpecifiers.getModuleSpecifier;
|
|
1288
|
-
return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options) => {
|
|
1289
|
-
return _internal(
|
|
1290
|
-
compilerOptions,
|
|
1291
|
-
importingSourceFile,
|
|
1292
|
-
importingSourceFileName,
|
|
1293
|
-
toFileName,
|
|
1294
|
-
host,
|
|
1295
|
-
options
|
|
1296
|
-
);
|
|
1297
|
-
};
|
|
1298
|
-
}
|
|
1299
1343
|
function findNodeWithLeadingCommentAtPosition(sourceFile, position) {
|
|
1300
1344
|
const sourceText = sourceFile.text;
|
|
1301
1345
|
let result;
|
|
@@ -1684,6 +1728,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1684
1728
|
findNodeAtPositionIncludingTrivia,
|
|
1685
1729
|
parsePackageContentNameAndVersionFromScope,
|
|
1686
1730
|
resolveModulePattern,
|
|
1731
|
+
resolveModuleWithPackageInfoFromSourceFile,
|
|
1687
1732
|
findNodeWithLeadingCommentAtPosition,
|
|
1688
1733
|
getCommentAtPosition,
|
|
1689
1734
|
getAncestorNodesInRange,
|
|
@@ -1698,7 +1743,6 @@ function makeTypeScriptUtils(ts) {
|
|
|
1698
1743
|
parseDataForExtendsClassCompletion,
|
|
1699
1744
|
createEffectGenCallExpressionWithBlock,
|
|
1700
1745
|
createReturnYieldStarStatement,
|
|
1701
|
-
makeGetModuleSpecifier,
|
|
1702
1746
|
parseAccessedExpressionForCompletion,
|
|
1703
1747
|
getSourceFileOfNode
|
|
1704
1748
|
};
|
|
@@ -3656,14 +3700,14 @@ var importFromBarrel = createDiagnostic({
|
|
|
3656
3700
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
3657
3701
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3658
3702
|
const program = yield* service(TypeScriptProgram);
|
|
3703
|
+
const getModuleSpecifier = makeGetModuleSpecifier(ts);
|
|
3704
|
+
const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
|
|
3659
3705
|
const packageNamesToCheck = flatten(
|
|
3660
3706
|
languageServicePluginOptions.namespaceImportPackages.map(
|
|
3661
3707
|
(packageName) => tsUtils.resolveModulePattern(program, sourceFile, packageName)
|
|
3662
3708
|
)
|
|
3663
3709
|
);
|
|
3664
3710
|
const isImportedFromBarrelExport = (element) => {
|
|
3665
|
-
const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
|
|
3666
|
-
const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
|
|
3667
3711
|
if (!(getModuleSpecifier && resolveExternalModuleName)) return;
|
|
3668
3712
|
const importDeclaration = ts.findAncestor(element, (node) => ts.isImportDeclaration(node));
|
|
3669
3713
|
if (!importDeclaration) return;
|
|
@@ -4098,7 +4142,7 @@ var missingEffectError = createDiagnostic({
|
|
|
4098
4142
|
// src/diagnostics/missingEffectServiceDependency.ts
|
|
4099
4143
|
var missingEffectServiceDependency = createDiagnostic({
|
|
4100
4144
|
name: "missingEffectServiceDependency",
|
|
4101
|
-
code:
|
|
4145
|
+
code: 22,
|
|
4102
4146
|
severity: "off",
|
|
4103
4147
|
apply: fn("missingEffectServiceDependency.apply")(function* (sourceFile, report) {
|
|
4104
4148
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -4420,6 +4464,96 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
4420
4464
|
})
|
|
4421
4465
|
});
|
|
4422
4466
|
|
|
4467
|
+
// src/diagnostics/nonObjectEffectServiceType.ts
|
|
4468
|
+
var nonObjectEffectServiceType = createDiagnostic({
|
|
4469
|
+
name: "nonObjectEffectServiceType",
|
|
4470
|
+
code: 24,
|
|
4471
|
+
severity: "error",
|
|
4472
|
+
apply: fn("nonObjectEffectServiceType.apply")(function* (sourceFile, report) {
|
|
4473
|
+
const ts = yield* service(TypeScriptApi);
|
|
4474
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
4475
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
4476
|
+
const typeParser = yield* service(TypeParser);
|
|
4477
|
+
function isPrimitiveType(type) {
|
|
4478
|
+
return typeCheckerUtils.unrollUnionMembers(type).some(
|
|
4479
|
+
(type2) => !!(type2.flags & ts.TypeFlags.String || type2.flags & ts.TypeFlags.Number || type2.flags & ts.TypeFlags.Boolean || type2.flags & ts.TypeFlags.StringLiteral || type2.flags & ts.TypeFlags.NumberLiteral || type2.flags & ts.TypeFlags.BooleanLiteral || type2.flags & ts.TypeFlags.Undefined || type2.flags & ts.TypeFlags.Null)
|
|
4480
|
+
);
|
|
4481
|
+
}
|
|
4482
|
+
const nodeToVisit = [];
|
|
4483
|
+
const appendNodeToVisit = (node) => {
|
|
4484
|
+
nodeToVisit.push(node);
|
|
4485
|
+
return void 0;
|
|
4486
|
+
};
|
|
4487
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
4488
|
+
while (nodeToVisit.length > 0) {
|
|
4489
|
+
const node = nodeToVisit.shift();
|
|
4490
|
+
if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {
|
|
4491
|
+
const serviceResult = yield* pipe(
|
|
4492
|
+
typeParser.extendsEffectService(node),
|
|
4493
|
+
orElse2(() => void_)
|
|
4494
|
+
);
|
|
4495
|
+
if (serviceResult && serviceResult.options && ts.isObjectLiteralExpression(serviceResult.options)) {
|
|
4496
|
+
const options = serviceResult.options;
|
|
4497
|
+
for (const property of options.properties) {
|
|
4498
|
+
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
|
|
4499
|
+
continue;
|
|
4500
|
+
}
|
|
4501
|
+
const propertyName = ts.idText(property.name);
|
|
4502
|
+
const propertyValue = property.initializer;
|
|
4503
|
+
const errorToReport = {
|
|
4504
|
+
location: property.name,
|
|
4505
|
+
messageText: "Effect.Service requires the service type to be an object {} and not a primitive type. \nConsider wrapping the value in an object, or manually using Context.Tag or Effect.Tag if you want to use a primitive instead.",
|
|
4506
|
+
fixes: []
|
|
4507
|
+
};
|
|
4508
|
+
if (propertyName === "succeed") {
|
|
4509
|
+
const valueType = typeChecker.getTypeAtLocation(propertyValue);
|
|
4510
|
+
if (isPrimitiveType(valueType)) {
|
|
4511
|
+
report(errorToReport);
|
|
4512
|
+
}
|
|
4513
|
+
} else if (propertyName === "sync") {
|
|
4514
|
+
const valueType = typeChecker.getTypeAtLocation(propertyValue);
|
|
4515
|
+
const signatures = typeChecker.getSignaturesOfType(valueType, ts.SignatureKind.Call);
|
|
4516
|
+
for (const signature of signatures) {
|
|
4517
|
+
const returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
4518
|
+
if (isPrimitiveType(returnType)) {
|
|
4519
|
+
report(errorToReport);
|
|
4520
|
+
break;
|
|
4521
|
+
}
|
|
4522
|
+
}
|
|
4523
|
+
} else if (propertyName === "effect" || propertyName === "scoped") {
|
|
4524
|
+
const valueType = typeChecker.getTypeAtLocation(propertyValue);
|
|
4525
|
+
const effectResult = yield* pipe(
|
|
4526
|
+
typeParser.effectType(valueType, propertyValue),
|
|
4527
|
+
orElse2(() => void_)
|
|
4528
|
+
);
|
|
4529
|
+
if (effectResult) {
|
|
4530
|
+
if (isPrimitiveType(effectResult.A)) {
|
|
4531
|
+
report(errorToReport);
|
|
4532
|
+
continue;
|
|
4533
|
+
}
|
|
4534
|
+
} else {
|
|
4535
|
+
const signatures = typeChecker.getSignaturesOfType(valueType, ts.SignatureKind.Call);
|
|
4536
|
+
for (const signature of signatures) {
|
|
4537
|
+
const returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
4538
|
+
const effectReturnResult = yield* pipe(
|
|
4539
|
+
typeParser.effectType(returnType, propertyValue),
|
|
4540
|
+
orElse2(() => void_)
|
|
4541
|
+
);
|
|
4542
|
+
if (effectReturnResult && isPrimitiveType(effectReturnResult.A)) {
|
|
4543
|
+
report(errorToReport);
|
|
4544
|
+
break;
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
}
|
|
4548
|
+
}
|
|
4549
|
+
}
|
|
4550
|
+
}
|
|
4551
|
+
}
|
|
4552
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
4553
|
+
}
|
|
4554
|
+
})
|
|
4555
|
+
});
|
|
4556
|
+
|
|
4423
4557
|
// src/refactors/writeTagClassAccessors.ts
|
|
4424
4558
|
var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, service2, className, atLocation, involvedMembers) {
|
|
4425
4559
|
const ts = yield* service(TypeScriptApi);
|
|
@@ -5334,7 +5468,8 @@ var diagnostics = [
|
|
|
5334
5468
|
multipleEffectProvide,
|
|
5335
5469
|
outdatedEffectCodegen,
|
|
5336
5470
|
overriddenSchemaConstructor,
|
|
5337
|
-
unsupportedServiceAccessors
|
|
5471
|
+
unsupportedServiceAccessors,
|
|
5472
|
+
nonObjectEffectServiceType
|
|
5338
5473
|
];
|
|
5339
5474
|
|
|
5340
5475
|
// src/effect-lsp-patch-utils.ts
|