@effect/language-service 0.41.0 → 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/cli.js +51 -21
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +67 -23
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +91 -26
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +67 -23
- 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;
|