@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.
package/index.js CHANGED
@@ -1064,6 +1064,68 @@ var all = fn("all")(
1064
1064
  var TypeScriptApi = Tag("TypeScriptApi");
1065
1065
  var TypeScriptProgram = Tag("TypeScriptProgram");
1066
1066
  var ChangeTracker = Tag("ChangeTracker");
1067
+ function getPackageJsonInfoCache(program) {
1068
+ try {
1069
+ if (hasProperty(program, "getModuleResolutionCache") && isFunction2(program.getModuleResolutionCache)) {
1070
+ const moduleResolutionCache = program.getModuleResolutionCache();
1071
+ if (hasProperty(moduleResolutionCache, "getPackageJsonInfoCache") && isFunction2(moduleResolutionCache.getPackageJsonInfoCache)) {
1072
+ return moduleResolutionCache.getPackageJsonInfoCache();
1073
+ }
1074
+ }
1075
+ } catch (_) {
1076
+ return void 0;
1077
+ }
1078
+ return void 0;
1079
+ }
1080
+ function getDirectoryPath(ts, path) {
1081
+ try {
1082
+ if (hasProperty(ts, "getDirectoryPath") && isFunction2(ts.getDirectoryPath)) {
1083
+ return ts.getDirectoryPath(path);
1084
+ }
1085
+ return path;
1086
+ } catch (_) {
1087
+ return path;
1088
+ }
1089
+ }
1090
+ function makeGetModuleSpecifier(ts) {
1091
+ if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
1092
+ const _internal = ts.moduleSpecifiers.getModuleSpecifier;
1093
+ return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options) => {
1094
+ return _internal(
1095
+ compilerOptions,
1096
+ importingSourceFile,
1097
+ importingSourceFileName,
1098
+ toFileName,
1099
+ host,
1100
+ options
1101
+ );
1102
+ };
1103
+ }
1104
+ function makeGetTemporaryModuleResolutionState(ts) {
1105
+ if (hasProperty(ts, "getTemporaryModuleResolutionState") && isFunction2(ts.getTemporaryModuleResolutionState)) {
1106
+ const _internal = ts.getTemporaryModuleResolutionState;
1107
+ return (cache, program, compilerOptions) => _internal(cache, program, compilerOptions);
1108
+ }
1109
+ return void 0;
1110
+ }
1111
+ function makeGetPackageScopeForPath(ts) {
1112
+ if (hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath)) {
1113
+ const _internal = ts.getPackageScopeForPath;
1114
+ return (path, state) => _internal(path, state);
1115
+ }
1116
+ }
1117
+ function makeResolvePackageNameToPackageJson(ts) {
1118
+ if (hasProperty(ts, "resolvePackageNameToPackageJson") && isFunction2(ts.resolvePackageNameToPackageJson)) {
1119
+ const _internal = ts.resolvePackageNameToPackageJson;
1120
+ return (packageName, fromFileName, compilerOptions, host) => _internal(packageName, fromFileName, compilerOptions, host);
1121
+ }
1122
+ }
1123
+ function makeGetEntrypointsFromPackageJsonInfo(ts) {
1124
+ if (hasProperty(ts, "getEntrypointsFromPackageJsonInfo") && isFunction2(ts.getEntrypointsFromPackageJsonInfo)) {
1125
+ const _internal = ts.getEntrypointsFromPackageJsonInfo;
1126
+ return (packageJsonInfo, compilerOptions, host) => _internal(packageJsonInfo, compilerOptions, host);
1127
+ }
1128
+ }
1067
1129
 
1068
1130
  // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/array.js
1069
1131
  var isNonEmptyArray = (self) => self.length > 0;
@@ -1185,6 +1247,8 @@ var nanoLayer = (fa) => pipe(
1185
1247
  flatMap((ts) => pipe(fa, provideService(TypeScriptUtils, makeTypeScriptUtils(ts))))
1186
1248
  );
1187
1249
  function makeTypeScriptUtils(ts) {
1250
+ const getTemporaryModuleResolutionState = makeGetTemporaryModuleResolutionState(ts);
1251
+ const getPackageScopeForPath = makeGetPackageScopeForPath(ts);
1188
1252
  function parsePackageContentNameAndVersionFromScope(v) {
1189
1253
  if (!isObject(v)) return;
1190
1254
  if (!hasProperty(v, "packageJsonScope")) return;
@@ -1219,20 +1283,26 @@ function makeTypeScriptUtils(ts) {
1219
1283
  exportsKeys
1220
1284
  };
1221
1285
  }
1222
- function resolveModulePattern(program, sourceFile, pattern) {
1223
- if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
1286
+ function resolveModuleWithPackageInfoFromSourceFile(program, sourceFile) {
1224
1287
  let packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
1225
- if (!packageJsonScope && hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath) && hasProperty(ts, "getTemporaryModuleResolutionState") && isFunction2(ts.getTemporaryModuleResolutionState) && hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath)) {
1226
- const temporaryModuleResolutionState = ts.getTemporaryModuleResolutionState(
1227
- void 0,
1288
+ if (!packageJsonScope && getPackageScopeForPath && getTemporaryModuleResolutionState) {
1289
+ const packageJsonInfoCache = getPackageJsonInfoCache(program);
1290
+ const temporaryModuleResolutionState = getTemporaryModuleResolutionState(
1291
+ packageJsonInfoCache,
1228
1292
  program,
1229
1293
  program.getCompilerOptions()
1230
1294
  );
1295
+ const directoryPath = getDirectoryPath(ts, sourceFile.fileName);
1231
1296
  packageJsonScope = parsePackageContentNameAndVersionFromScope({
1232
1297
  ...sourceFile,
1233
- packageJsonScope: ts.getPackageScopeForPath(sourceFile.fileName, temporaryModuleResolutionState)
1298
+ packageJsonScope: getPackageScopeForPath(directoryPath, temporaryModuleResolutionState)
1234
1299
  });
1235
1300
  }
1301
+ return packageJsonScope;
1302
+ }
1303
+ function resolveModulePattern(program, sourceFile, pattern) {
1304
+ if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
1305
+ const packageJsonScope = resolveModuleWithPackageInfoFromSourceFile(program, sourceFile);
1236
1306
  const referencedPackages = [];
1237
1307
  for (const statement of sourceFile.statements) {
1238
1308
  if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
@@ -1250,20 +1320,6 @@ function makeTypeScriptUtils(ts) {
1250
1320
  )
1251
1321
  );
1252
1322
  }
1253
- function makeGetModuleSpecifier() {
1254
- if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
1255
- const _internal = ts.moduleSpecifiers.getModuleSpecifier;
1256
- return (compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, options) => {
1257
- return _internal(
1258
- compilerOptions,
1259
- importingSourceFile,
1260
- importingSourceFileName,
1261
- toFileName,
1262
- host,
1263
- options
1264
- );
1265
- };
1266
- }
1267
1323
  function findNodeWithLeadingCommentAtPosition(sourceFile, position) {
1268
1324
  const sourceText = sourceFile.text;
1269
1325
  let result;
@@ -1652,6 +1708,7 @@ function makeTypeScriptUtils(ts) {
1652
1708
  findNodeAtPositionIncludingTrivia,
1653
1709
  parsePackageContentNameAndVersionFromScope,
1654
1710
  resolveModulePattern,
1711
+ resolveModuleWithPackageInfoFromSourceFile,
1655
1712
  findNodeWithLeadingCommentAtPosition,
1656
1713
  getCommentAtPosition,
1657
1714
  getAncestorNodesInRange,
@@ -1666,7 +1723,6 @@ function makeTypeScriptUtils(ts) {
1666
1723
  parseDataForExtendsClassCompletion,
1667
1724
  createEffectGenCallExpressionWithBlock,
1668
1725
  createReturnYieldStarStatement,
1669
- makeGetModuleSpecifier,
1670
1726
  parseAccessedExpressionForCompletion,
1671
1727
  getSourceFileOfNode
1672
1728
  };
@@ -1693,6 +1749,7 @@ var defaults = {
1693
1749
  diagnosticSeverity: {},
1694
1750
  quickinfo: true,
1695
1751
  quickinfoEffectParameters: "whentruncated",
1752
+ quickinfoMaximumLength: -1,
1696
1753
  completions: true,
1697
1754
  goto: true,
1698
1755
  inlays: true,
@@ -1711,6 +1768,7 @@ function parse(config) {
1711
1768
  diagnosticSeverity: isObject(config) && hasProperty(config, "diagnosticSeverity") && isRecord(config.diagnosticSeverity) ? parseDiagnosticSeverity(config.diagnosticSeverity) : defaults.diagnosticSeverity,
1712
1769
  quickinfo: isObject(config) && hasProperty(config, "quickinfo") && isBoolean(config.quickinfo) ? config.quickinfo : defaults.quickinfo,
1713
1770
  quickinfoEffectParameters: isObject(config) && hasProperty(config, "quickinfoEffectParameters") && isString(config.quickinfoEffectParameters) && ["always", "never", "whentruncated"].includes(config.quickinfoEffectParameters.toLowerCase()) ? config.quickinfoEffectParameters.toLowerCase() : defaults.quickinfoEffectParameters,
1771
+ quickinfoMaximumLength: isObject(config) && hasProperty(config, "quickinfoMaximumLength") && isNumber(config.quickinfoMaximumLength) ? config.quickinfoMaximumLength : defaults.quickinfoMaximumLength,
1714
1772
  completions: isObject(config) && hasProperty(config, "completions") && isBoolean(config.completions) ? config.completions : defaults.completions,
1715
1773
  goto: isObject(config) && hasProperty(config, "goto") && isBoolean(config.goto) ? config.goto : defaults.goto,
1716
1774
  inlays: isObject(config) && hasProperty(config, "inlays") && isBoolean(config.inlays) ? config.inlays : defaults.inlays,
@@ -4143,14 +4201,14 @@ var importFromBarrel = createDiagnostic({
4143
4201
  const tsUtils = yield* service(TypeScriptUtils);
4144
4202
  const typeChecker = yield* service(TypeCheckerApi);
4145
4203
  const program = yield* service(TypeScriptProgram);
4204
+ const getModuleSpecifier = makeGetModuleSpecifier(ts);
4205
+ const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
4146
4206
  const packageNamesToCheck = flatten(
4147
4207
  languageServicePluginOptions.namespaceImportPackages.map(
4148
4208
  (packageName) => tsUtils.resolveModulePattern(program, sourceFile, packageName)
4149
4209
  )
4150
4210
  );
4151
4211
  const isImportedFromBarrelExport = (element) => {
4152
- const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
4153
- const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
4154
4212
  if (!(getModuleSpecifier && resolveExternalModuleName)) return;
4155
4213
  const importDeclaration = ts.findAncestor(element, (node) => ts.isImportDeclaration(node));
4156
4214
  if (!importDeclaration) return;
@@ -5720,6 +5778,12 @@ var effectSelfInClasses = createCompletion({
5720
5778
  insertText: `${effectIdentifier}.Service<${name}>()("${name}", {${"${0}"}}){}`,
5721
5779
  replacementSpan,
5722
5780
  isSnippet: true
5781
+ }, {
5782
+ name: `Tag("${name}")`,
5783
+ kind: ts.ScriptElementKind.constElement,
5784
+ insertText: `${effectIdentifier}.Tag("${name}")<${name}, {${"${0}"}}>(){}`,
5785
+ replacementSpan,
5786
+ isSnippet: true
5723
5787
  }];
5724
5788
  })
5725
5789
  });
@@ -5890,7 +5954,9 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
5890
5954
  const program = yield* service(TypeScriptProgram);
5891
5955
  const languageServicePluginOptions = yield* service(LanguageServicePluginOptions);
5892
5956
  const host = program;
5893
- const getModuleSpecifier = tsUtils.makeGetModuleSpecifier();
5957
+ const getModuleSpecifier = makeGetModuleSpecifier(ts);
5958
+ const resolvePackageNameToPackageJson = makeResolvePackageNameToPackageJson(ts);
5959
+ const getEntrypointsFromPackageJsonInfo = makeGetEntrypointsFromPackageJsonInfo(ts);
5894
5960
  function collectSourceFileReexports(sourceFile) {
5895
5961
  const namespaceExports = [];
5896
5962
  const namedExports = [];
@@ -5928,14 +5994,15 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
5928
5994
  }
5929
5995
  function getPackageInfo(fromFileName, packageName) {
5930
5996
  try {
5931
- const packageJsonInfo = ts.resolvePackageNameToPackageJson(
5997
+ if (!resolvePackageNameToPackageJson || !getEntrypointsFromPackageJsonInfo) return;
5998
+ const packageJsonInfo = resolvePackageNameToPackageJson(
5932
5999
  packageName,
5933
6000
  fromFileName,
5934
6001
  program.getCompilerOptions(),
5935
6002
  host
5936
6003
  );
5937
6004
  if (!packageJsonInfo) return;
5938
- const _entrypoints = ts.getEntrypointsFromPackageJsonInfo(
6005
+ const _entrypoints = getEntrypointsFromPackageJsonInfo(
5939
6006
  packageJsonInfo,
5940
6007
  program.getCompilerOptions(),
5941
6008
  host
@@ -6664,11 +6731,22 @@ function effectTypeArgs(sourceFile, position, quickInfo2) {
6664
6731
  const options = yield* service(LanguageServicePluginOptions);
6665
6732
  if (options.quickinfoEffectParameters === "never") return quickInfo2;
6666
6733
  function formatTypeForQuickInfo(channelType, channelName) {
6667
- const stringRepresentation = typeChecker.typeToString(
6668
- channelType,
6669
- void 0,
6670
- ts.TypeFormatFlags.NoTruncation
6671
- );
6734
+ let stringRepresentation = "";
6735
+ if (options.quickinfoMaximumLength > 0) {
6736
+ const typeNode = typeChecker.typeToTypeNode(
6737
+ channelType,
6738
+ void 0,
6739
+ ts.NodeBuilderFlags.None,
6740
+ // @ts-expect-error
6741
+ void 0,
6742
+ void 0,
6743
+ options.quickinfoMaximumLength
6744
+ );
6745
+ const printer = ts.createPrinter({});
6746
+ stringRepresentation = typeNode ? printer.printNode(ts.EmitHint.Unspecified, typeNode, sourceFile) : "";
6747
+ } else {
6748
+ stringRepresentation = typeChecker.typeToString(channelType, void 0, ts.TypeFormatFlags.NoTruncation);
6749
+ }
6672
6750
  return `type ${channelName} = ${stringRepresentation}`;
6673
6751
  }
6674
6752
  function makeSymbolDisplayParts(title, A, E, R) {