@effect/language-service 0.58.1 → 0.58.3

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
@@ -1845,6 +1845,9 @@ function makeTypeScriptUtils(ts) {
1845
1845
  }
1846
1846
  return node;
1847
1847
  }
1848
+ function isDeclarationKind(kind) {
1849
+ return kind === ts.SyntaxKind.ArrowFunction || kind === ts.SyntaxKind.BindingElement || kind === ts.SyntaxKind.ClassDeclaration || kind === ts.SyntaxKind.ClassExpression || kind === ts.SyntaxKind.ClassStaticBlockDeclaration || kind === ts.SyntaxKind.Constructor || kind === ts.SyntaxKind.EnumDeclaration || kind === ts.SyntaxKind.EnumMember || kind === ts.SyntaxKind.ExportSpecifier || kind === ts.SyntaxKind.FunctionDeclaration || kind === ts.SyntaxKind.FunctionExpression || kind === ts.SyntaxKind.GetAccessor || kind === ts.SyntaxKind.ImportClause || kind === ts.SyntaxKind.ImportEqualsDeclaration || kind === ts.SyntaxKind.ImportSpecifier || kind === ts.SyntaxKind.InterfaceDeclaration || kind === ts.SyntaxKind.JsxAttribute || kind === ts.SyntaxKind.MethodDeclaration || kind === ts.SyntaxKind.MethodSignature || kind === ts.SyntaxKind.ModuleDeclaration || kind === ts.SyntaxKind.NamespaceExportDeclaration || kind === ts.SyntaxKind.NamespaceImport || kind === ts.SyntaxKind.NamespaceExport || kind === ts.SyntaxKind.Parameter || kind === ts.SyntaxKind.PropertyAssignment || kind === ts.SyntaxKind.PropertyDeclaration || kind === ts.SyntaxKind.PropertySignature || kind === ts.SyntaxKind.SetAccessor || kind === ts.SyntaxKind.ShorthandPropertyAssignment || kind === ts.SyntaxKind.TypeAliasDeclaration || kind === ts.SyntaxKind.TypeParameter || kind === ts.SyntaxKind.VariableDeclaration || kind === ts.SyntaxKind.JSDocTypedefTag || kind === ts.SyntaxKind.JSDocCallbackTag || kind === ts.SyntaxKind.JSDocPropertyTag || kind === ts.SyntaxKind.NamedTupleMember;
1850
+ }
1848
1851
  return {
1849
1852
  findNodeAtPositionIncludingTrivia,
1850
1853
  parsePackageContentNameAndVersionFromScope,
@@ -1867,7 +1870,8 @@ function makeTypeScriptUtils(ts) {
1867
1870
  parseAccessedExpressionForCompletion,
1868
1871
  getSourceFileOfNode,
1869
1872
  isOuterExpression,
1870
- skipOuterExpressions
1873
+ skipOuterExpressions,
1874
+ isDeclarationKind
1871
1875
  };
1872
1876
  }
1873
1877
 
@@ -4168,18 +4172,12 @@ var annotate = createCodegen({
4168
4172
  for (const variableDeclaration of variableDeclarations) {
4169
4173
  if (!variableDeclaration.initializer) continue;
4170
4174
  const initializerType = typeChecker.getTypeAtLocation(variableDeclaration.initializer);
4175
+ const enclosingNode = ts.findAncestor(variableDeclaration, (_) => tsUtils.isDeclarationKind(_.kind)) || sourceFile;
4171
4176
  const initializerTypeNode = fromNullable(typeCheckerUtils.typeToSimplifiedTypeNode(
4172
4177
  initializerType,
4173
- node,
4178
+ enclosingNode,
4174
4179
  ts.NodeBuilderFlags.NoTruncation
4175
4180
  )).pipe(
4176
- orElse(
4177
- () => fromNullable(typeCheckerUtils.typeToSimplifiedTypeNode(
4178
- initializerType,
4179
- void 0,
4180
- ts.NodeBuilderFlags.NoTruncation
4181
- ))
4182
- ),
4183
4181
  getOrUndefined
4184
4182
  );
4185
4183
  if (!initializerTypeNode) continue;
@@ -4318,9 +4316,11 @@ var anyUnknownInErrorContext = createDiagnostic({
4318
4316
  }
4319
4317
  if (ts.isParameter(node) || ts.isPropertyDeclaration(node) || ts.isVariableDeclaration(node)) {
4320
4318
  if (node.type) {
4319
+ const typeNode = node.type;
4321
4320
  const type2 = typeChecker.getTypeAtLocation(node.type);
4322
4321
  const expectedEffect = yield* pipe(
4323
4322
  typeParser.strictEffectType(type2, node.type),
4323
+ orElse2(() => typeParser.layerType(type2, typeNode)),
4324
4324
  orElse2(() => void_)
4325
4325
  );
4326
4326
  if (expectedEffect) continue;
@@ -4342,8 +4342,9 @@ var anyUnknownInErrorContext = createDiagnostic({
4342
4342
  if (!type) continue;
4343
4343
  yield* pipe(
4344
4344
  typeParser.strictEffectType(type, node),
4345
- map5((effect) => {
4346
- const { E, R } = effect;
4345
+ orElse2(() => pipe(typeParser.layerType(type, node), map5(({ E, RIn }) => ({ E, R: RIn })))),
4346
+ map5((effectOrLayer) => {
4347
+ const { E, R } = effectOrLayer;
4347
4348
  const hasAnyUnknownR = isAnyOrUnknown(R);
4348
4349
  const hasAnyUnknownE = isAnyOrUnknown(E);
4349
4350
  if (hasAnyUnknownR || hasAnyUnknownE) {
@@ -4366,7 +4367,7 @@ var anyUnknownInErrorContext = createDiagnostic({
4366
4367
  matchingNodes.splice(i, 1);
4367
4368
  }
4368
4369
  }
4369
- const suggestions = [`This Effect has ${channels.join(" and ")} which is not recommended.`];
4370
+ const suggestions = [`This has ${channels.join(" and ")} which is not recommended.`];
4370
4371
  if (hasAnyUnknownR) {
4371
4372
  suggestions.push(`Only service identifiers should appear in the requirements channel.`);
4372
4373
  }
@@ -16478,9 +16479,10 @@ var toggleReturnTypeAnnotation = createRefactor({
16478
16479
  }
16479
16480
  const returnType = typeCheckerUtils.getInferredReturnType(node);
16480
16481
  if (!returnType) return yield* fail(new RefactorNotApplicableError());
16482
+ const enclosingNode = ts.findAncestor(node, (_) => tsUtils.isDeclarationKind(_.kind)) || sourceFile;
16481
16483
  const returnTypeNode = typeCheckerUtils.typeToSimplifiedTypeNode(
16482
16484
  returnType,
16483
- node,
16485
+ enclosingNode,
16484
16486
  ts.NodeBuilderFlags.NoTruncation
16485
16487
  );
16486
16488
  if (!returnTypeNode) return yield* fail(new RefactorNotApplicableError());
@@ -16525,18 +16527,12 @@ var toggleTypeAnnotation = createRefactor({
16525
16527
  }
16526
16528
  const initializer = node.initializer;
16527
16529
  const initializerType = typeChecker.getTypeAtLocation(initializer);
16530
+ const enclosingNode = ts.findAncestor(node, (_) => tsUtils.isDeclarationKind(_.kind)) || sourceFile;
16528
16531
  const initializerTypeNode = fromNullable(typeCheckerUtils.typeToSimplifiedTypeNode(
16529
16532
  initializerType,
16530
- node,
16533
+ enclosingNode,
16531
16534
  ts.NodeBuilderFlags.NoTruncation
16532
16535
  )).pipe(
16533
- orElse(
16534
- () => fromNullable(typeCheckerUtils.typeToSimplifiedTypeNode(
16535
- initializerType,
16536
- void 0,
16537
- ts.NodeBuilderFlags.NoTruncation
16538
- ))
16539
- ),
16540
16536
  getOrUndefined
16541
16537
  );
16542
16538
  if (initializerTypeNode) {