@effect/language-service 0.41.0 → 0.42.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.
@@ -1174,6 +1174,7 @@ var defaults = {
1174
1174
  diagnosticSeverity: {},
1175
1175
  quickinfo: true,
1176
1176
  quickinfoEffectParameters: "whentruncated",
1177
+ quickinfoMaximumLength: -1,
1177
1178
  completions: true,
1178
1179
  goto: true,
1179
1180
  inlays: true,
@@ -1192,6 +1193,7 @@ function parse(config) {
1192
1193
  diagnosticSeverity: isObject(config) && hasProperty(config, "diagnosticSeverity") && isRecord(config.diagnosticSeverity) ? parseDiagnosticSeverity(config.diagnosticSeverity) : defaults.diagnosticSeverity,
1193
1194
  quickinfo: isObject(config) && hasProperty(config, "quickinfo") && isBoolean(config.quickinfo) ? config.quickinfo : defaults.quickinfo,
1194
1195
  quickinfoEffectParameters: isObject(config) && hasProperty(config, "quickinfoEffectParameters") && isString(config.quickinfoEffectParameters) && ["always", "never", "whentruncated"].includes(config.quickinfoEffectParameters.toLowerCase()) ? config.quickinfoEffectParameters.toLowerCase() : defaults.quickinfoEffectParameters,
1196
+ quickinfoMaximumLength: isObject(config) && hasProperty(config, "quickinfoMaximumLength") && isNumber(config.quickinfoMaximumLength) ? config.quickinfoMaximumLength : defaults.quickinfoMaximumLength,
1195
1197
  completions: isObject(config) && hasProperty(config, "completions") && isBoolean(config.completions) ? config.completions : defaults.completions,
1196
1198
  goto: isObject(config) && hasProperty(config, "goto") && isBoolean(config.goto) ? config.goto : defaults.goto,
1197
1199
  inlays: isObject(config) && hasProperty(config, "inlays") && isBoolean(config.inlays) ? config.inlays : defaults.inlays,
@@ -1209,6 +1211,56 @@ function parse(config) {
1209
1211
  var TypeScriptApi = Tag("TypeScriptApi");
1210
1212
  var TypeScriptProgram = Tag("TypeScriptProgram");
1211
1213
  var ChangeTracker = Tag("ChangeTracker");
1214
+ function getPackageJsonInfoCache(program) {
1215
+ try {
1216
+ if (hasProperty(program, "getModuleResolutionCache") && isFunction2(program.getModuleResolutionCache)) {
1217
+ const moduleResolutionCache = program.getModuleResolutionCache();
1218
+ if (hasProperty(moduleResolutionCache, "getPackageJsonInfoCache") && isFunction2(moduleResolutionCache.getPackageJsonInfoCache)) {
1219
+ return moduleResolutionCache.getPackageJsonInfoCache();
1220
+ }
1221
+ }
1222
+ } catch (_) {
1223
+ return void 0;
1224
+ }
1225
+ return void 0;
1226
+ }
1227
+ function getDirectoryPath(ts, path) {
1228
+ try {
1229
+ if (hasProperty(ts, "getDirectoryPath") && isFunction2(ts.getDirectoryPath)) {
1230
+ return ts.getDirectoryPath(path);
1231
+ }
1232
+ return path;
1233
+ } catch (_) {
1234
+ return path;
1235
+ }
1236
+ }
1237
+ function makeGetModuleSpecifier(ts) {
1238
+ if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
1239
+ const _internal = ts.moduleSpecifiers.getModuleSpecifier;
1240
+ return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options) => {
1241
+ return _internal(
1242
+ compilerOptions,
1243
+ importingSourceFile,
1244
+ importingSourceFileName,
1245
+ toFileName,
1246
+ host,
1247
+ options
1248
+ );
1249
+ };
1250
+ }
1251
+ function makeGetTemporaryModuleResolutionState(ts) {
1252
+ if (hasProperty(ts, "getTemporaryModuleResolutionState") && isFunction2(ts.getTemporaryModuleResolutionState)) {
1253
+ const _internal = ts.getTemporaryModuleResolutionState;
1254
+ return (cache, program, compilerOptions) => _internal(cache, program, compilerOptions);
1255
+ }
1256
+ return void 0;
1257
+ }
1258
+ function makeGetPackageScopeForPath(ts) {
1259
+ if (hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath)) {
1260
+ const _internal = ts.getPackageScopeForPath;
1261
+ return (path, state) => _internal(path, state);
1262
+ }
1263
+ }
1212
1264
 
1213
1265
  // src/core/TypeScriptUtils.ts
1214
1266
  var TypeScriptUtils = Tag("TypeScriptUtils");
@@ -1217,6 +1269,8 @@ var nanoLayer = (fa) => pipe(
1217
1269
  flatMap2((ts) => pipe(fa, provideService(TypeScriptUtils, makeTypeScriptUtils(ts))))
1218
1270
  );
1219
1271
  function makeTypeScriptUtils(ts) {
1272
+ const getTemporaryModuleResolutionState = makeGetTemporaryModuleResolutionState(ts);
1273
+ const getPackageScopeForPath = makeGetPackageScopeForPath(ts);
1220
1274
  function parsePackageContentNameAndVersionFromScope(v) {
1221
1275
  if (!isObject(v)) return;
1222
1276
  if (!hasProperty(v, "packageJsonScope")) return;
@@ -1251,20 +1305,26 @@ function makeTypeScriptUtils(ts) {
1251
1305
  exportsKeys
1252
1306
  };
1253
1307
  }
1254
- function resolveModulePattern(program, sourceFile, pattern) {
1255
- if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
1308
+ function resolveModuleWithPackageInfoFromSourceFile(program, sourceFile) {
1256
1309
  let packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
1257
- if (!packageJsonScope && hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath) && hasProperty(ts, "getTemporaryModuleResolutionState") && isFunction2(ts.getTemporaryModuleResolutionState) && hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath)) {
1258
- const temporaryModuleResolutionState = ts.getTemporaryModuleResolutionState(
1259
- void 0,
1310
+ if (!packageJsonScope && getPackageScopeForPath && getTemporaryModuleResolutionState) {
1311
+ const packageJsonInfoCache = getPackageJsonInfoCache(program);
1312
+ const temporaryModuleResolutionState = getTemporaryModuleResolutionState(
1313
+ packageJsonInfoCache,
1260
1314
  program,
1261
1315
  program.getCompilerOptions()
1262
1316
  );
1317
+ const directoryPath = getDirectoryPath(ts, sourceFile.fileName);
1263
1318
  packageJsonScope = parsePackageContentNameAndVersionFromScope({
1264
1319
  ...sourceFile,
1265
- packageJsonScope: ts.getPackageScopeForPath(sourceFile.fileName, temporaryModuleResolutionState)
1320
+ packageJsonScope: getPackageScopeForPath(directoryPath, temporaryModuleResolutionState)
1266
1321
  });
1267
1322
  }
1323
+ return packageJsonScope;
1324
+ }
1325
+ function resolveModulePattern(program, sourceFile, pattern) {
1326
+ if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
1327
+ const packageJsonScope = resolveModuleWithPackageInfoFromSourceFile(program, sourceFile);
1268
1328
  const referencedPackages = [];
1269
1329
  for (const statement of sourceFile.statements) {
1270
1330
  if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
@@ -1282,20 +1342,6 @@ function makeTypeScriptUtils(ts) {
1282
1342
  )
1283
1343
  );
1284
1344
  }
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
1345
  function findNodeWithLeadingCommentAtPosition(sourceFile, position) {
1300
1346
  const sourceText = sourceFile.text;
1301
1347
  let result;
@@ -1684,6 +1730,7 @@ function makeTypeScriptUtils(ts) {
1684
1730
  findNodeAtPositionIncludingTrivia,
1685
1731
  parsePackageContentNameAndVersionFromScope,
1686
1732
  resolveModulePattern,
1733
+ resolveModuleWithPackageInfoFromSourceFile,
1687
1734
  findNodeWithLeadingCommentAtPosition,
1688
1735
  getCommentAtPosition,
1689
1736
  getAncestorNodesInRange,
@@ -1698,7 +1745,6 @@ function makeTypeScriptUtils(ts) {
1698
1745
  parseDataForExtendsClassCompletion,
1699
1746
  createEffectGenCallExpressionWithBlock,
1700
1747
  createReturnYieldStarStatement,
1701
- makeGetModuleSpecifier,
1702
1748
  parseAccessedExpressionForCompletion,
1703
1749
  getSourceFileOfNode
1704
1750
  };
@@ -3656,14 +3702,14 @@ var importFromBarrel = createDiagnostic({
3656
3702
  const tsUtils = yield* service(TypeScriptUtils);
3657
3703
  const typeChecker = yield* service(TypeCheckerApi);
3658
3704
  const program = yield* service(TypeScriptProgram);
3705
+ const getModuleSpecifier = makeGetModuleSpecifier(ts);
3706
+ const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
3659
3707
  const packageNamesToCheck = flatten(
3660
3708
  languageServicePluginOptions.namespaceImportPackages.map(
3661
3709
  (packageName) => tsUtils.resolveModulePattern(program, sourceFile, packageName)
3662
3710
  )
3663
3711
  );
3664
3712
  const isImportedFromBarrelExport = (element) => {
3665
- const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
3666
- const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
3667
3713
  if (!(getModuleSpecifier && resolveExternalModuleName)) return;
3668
3714
  const importDeclaration = ts.findAncestor(element, (node) => ts.isImportDeclaration(node));
3669
3715
  if (!importDeclaration) return;