@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
package/package.json
CHANGED
package/transform.js
CHANGED
|
@@ -1214,6 +1214,56 @@ function parse(config) {
|
|
|
1214
1214
|
var TypeScriptApi = Tag("TypeScriptApi");
|
|
1215
1215
|
var TypeScriptProgram = Tag("TypeScriptProgram");
|
|
1216
1216
|
var ChangeTracker = Tag("ChangeTracker");
|
|
1217
|
+
function getPackageJsonInfoCache(program) {
|
|
1218
|
+
try {
|
|
1219
|
+
if (hasProperty(program, "getModuleResolutionCache") && isFunction2(program.getModuleResolutionCache)) {
|
|
1220
|
+
const moduleResolutionCache = program.getModuleResolutionCache();
|
|
1221
|
+
if (hasProperty(moduleResolutionCache, "getPackageJsonInfoCache") && isFunction2(moduleResolutionCache.getPackageJsonInfoCache)) {
|
|
1222
|
+
return moduleResolutionCache.getPackageJsonInfoCache();
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
} catch (_) {
|
|
1226
|
+
return void 0;
|
|
1227
|
+
}
|
|
1228
|
+
return void 0;
|
|
1229
|
+
}
|
|
1230
|
+
function getDirectoryPath(ts, path) {
|
|
1231
|
+
try {
|
|
1232
|
+
if (hasProperty(ts, "getDirectoryPath") && isFunction2(ts.getDirectoryPath)) {
|
|
1233
|
+
return ts.getDirectoryPath(path);
|
|
1234
|
+
}
|
|
1235
|
+
return path;
|
|
1236
|
+
} catch (_) {
|
|
1237
|
+
return path;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
function makeGetModuleSpecifier(ts) {
|
|
1241
|
+
if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
|
|
1242
|
+
const _internal = ts.moduleSpecifiers.getModuleSpecifier;
|
|
1243
|
+
return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options) => {
|
|
1244
|
+
return _internal(
|
|
1245
|
+
compilerOptions,
|
|
1246
|
+
importingSourceFile,
|
|
1247
|
+
importingSourceFileName,
|
|
1248
|
+
toFileName,
|
|
1249
|
+
host,
|
|
1250
|
+
options
|
|
1251
|
+
);
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
function makeGetTemporaryModuleResolutionState(ts) {
|
|
1255
|
+
if (hasProperty(ts, "getTemporaryModuleResolutionState") && isFunction2(ts.getTemporaryModuleResolutionState)) {
|
|
1256
|
+
const _internal = ts.getTemporaryModuleResolutionState;
|
|
1257
|
+
return (cache, program, compilerOptions) => _internal(cache, program, compilerOptions);
|
|
1258
|
+
}
|
|
1259
|
+
return void 0;
|
|
1260
|
+
}
|
|
1261
|
+
function makeGetPackageScopeForPath(ts) {
|
|
1262
|
+
if (hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath)) {
|
|
1263
|
+
const _internal = ts.getPackageScopeForPath;
|
|
1264
|
+
return (path, state) => _internal(path, state);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1217
1267
|
|
|
1218
1268
|
// src/core/TypeScriptUtils.ts
|
|
1219
1269
|
var TypeScriptUtils = Tag("TypeScriptUtils");
|
|
@@ -1222,6 +1272,8 @@ var nanoLayer = (fa) => pipe(
|
|
|
1222
1272
|
flatMap2((ts) => pipe(fa, provideService(TypeScriptUtils, makeTypeScriptUtils(ts))))
|
|
1223
1273
|
);
|
|
1224
1274
|
function makeTypeScriptUtils(ts) {
|
|
1275
|
+
const getTemporaryModuleResolutionState = makeGetTemporaryModuleResolutionState(ts);
|
|
1276
|
+
const getPackageScopeForPath = makeGetPackageScopeForPath(ts);
|
|
1225
1277
|
function parsePackageContentNameAndVersionFromScope(v) {
|
|
1226
1278
|
if (!isObject(v)) return;
|
|
1227
1279
|
if (!hasProperty(v, "packageJsonScope")) return;
|
|
@@ -1256,20 +1308,26 @@ function makeTypeScriptUtils(ts) {
|
|
|
1256
1308
|
exportsKeys
|
|
1257
1309
|
};
|
|
1258
1310
|
}
|
|
1259
|
-
function
|
|
1260
|
-
if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
|
|
1311
|
+
function resolveModuleWithPackageInfoFromSourceFile(program, sourceFile) {
|
|
1261
1312
|
let packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
|
|
1262
|
-
if (!packageJsonScope &&
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1313
|
+
if (!packageJsonScope && getPackageScopeForPath && getTemporaryModuleResolutionState) {
|
|
1314
|
+
const packageJsonInfoCache = getPackageJsonInfoCache(program);
|
|
1315
|
+
const temporaryModuleResolutionState = getTemporaryModuleResolutionState(
|
|
1316
|
+
packageJsonInfoCache,
|
|
1265
1317
|
program,
|
|
1266
1318
|
program.getCompilerOptions()
|
|
1267
1319
|
);
|
|
1320
|
+
const directoryPath = getDirectoryPath(ts, sourceFile.fileName);
|
|
1268
1321
|
packageJsonScope = parsePackageContentNameAndVersionFromScope({
|
|
1269
1322
|
...sourceFile,
|
|
1270
|
-
packageJsonScope:
|
|
1323
|
+
packageJsonScope: getPackageScopeForPath(directoryPath, temporaryModuleResolutionState)
|
|
1271
1324
|
});
|
|
1272
1325
|
}
|
|
1326
|
+
return packageJsonScope;
|
|
1327
|
+
}
|
|
1328
|
+
function resolveModulePattern(program, sourceFile, pattern) {
|
|
1329
|
+
if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
|
|
1330
|
+
const packageJsonScope = resolveModuleWithPackageInfoFromSourceFile(program, sourceFile);
|
|
1273
1331
|
const referencedPackages = [];
|
|
1274
1332
|
for (const statement of sourceFile.statements) {
|
|
1275
1333
|
if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
@@ -1287,20 +1345,6 @@ function makeTypeScriptUtils(ts) {
|
|
|
1287
1345
|
)
|
|
1288
1346
|
);
|
|
1289
1347
|
}
|
|
1290
|
-
function makeGetModuleSpecifier() {
|
|
1291
|
-
if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
|
|
1292
|
-
const _internal = ts.moduleSpecifiers.getModuleSpecifier;
|
|
1293
|
-
return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options) => {
|
|
1294
|
-
return _internal(
|
|
1295
|
-
compilerOptions,
|
|
1296
|
-
importingSourceFile,
|
|
1297
|
-
importingSourceFileName,
|
|
1298
|
-
toFileName,
|
|
1299
|
-
host,
|
|
1300
|
-
options
|
|
1301
|
-
);
|
|
1302
|
-
};
|
|
1303
|
-
}
|
|
1304
1348
|
function findNodeWithLeadingCommentAtPosition(sourceFile, position) {
|
|
1305
1349
|
const sourceText = sourceFile.text;
|
|
1306
1350
|
let result;
|
|
@@ -1689,6 +1733,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1689
1733
|
findNodeAtPositionIncludingTrivia,
|
|
1690
1734
|
parsePackageContentNameAndVersionFromScope,
|
|
1691
1735
|
resolveModulePattern,
|
|
1736
|
+
resolveModuleWithPackageInfoFromSourceFile,
|
|
1692
1737
|
findNodeWithLeadingCommentAtPosition,
|
|
1693
1738
|
getCommentAtPosition,
|
|
1694
1739
|
getAncestorNodesInRange,
|
|
@@ -1703,7 +1748,6 @@ function makeTypeScriptUtils(ts) {
|
|
|
1703
1748
|
parseDataForExtendsClassCompletion,
|
|
1704
1749
|
createEffectGenCallExpressionWithBlock,
|
|
1705
1750
|
createReturnYieldStarStatement,
|
|
1706
|
-
makeGetModuleSpecifier,
|
|
1707
1751
|
parseAccessedExpressionForCompletion,
|
|
1708
1752
|
getSourceFileOfNode
|
|
1709
1753
|
};
|
|
@@ -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;
|