@effect/language-service 0.45.1 → 0.47.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
@@ -1175,6 +1175,9 @@ var all = fn("all")(
1175
1175
 
1176
1176
  // src/core/LanguageServicePluginOptions.ts
1177
1177
  var LanguageServicePluginOptions = Tag("PluginOptions");
1178
+ function isValidSeverityLevel(value) {
1179
+ return value === "off" || value === "error" || value === "warning" || value === "message" || value === "suggestion";
1180
+ }
1178
1181
  function parseDiagnosticSeverity(config) {
1179
1182
  if (!isRecord(config)) return {};
1180
1183
  return Object.fromEntries(
@@ -1182,9 +1185,7 @@ function parseDiagnosticSeverity(config) {
1182
1185
  Object.entries(config),
1183
1186
  filter(([key, value]) => isString(key) && isString(value)),
1184
1187
  map4(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),
1185
- filter(
1186
- ([_, value]) => value === "off" || value === "error" || value === "warning" || value === "message" || value === "suggestion"
1187
- )
1188
+ filter(([_, value]) => isValidSeverityLevel(value))
1188
1189
  )
1189
1190
  );
1190
1191
  }
@@ -1193,6 +1194,7 @@ var defaults = {
1193
1194
  diagnostics: true,
1194
1195
  diagnosticSeverity: {},
1195
1196
  diagnosticsName: true,
1197
+ missingDiagnosticNextLine: "warning",
1196
1198
  quickinfo: true,
1197
1199
  quickinfoEffectParameters: "whentruncated",
1198
1200
  quickinfoMaximumLength: -1,
@@ -1235,6 +1237,7 @@ function parse(config) {
1235
1237
  diagnostics: isObject(config) && hasProperty(config, "diagnostics") && isBoolean(config.diagnostics) ? config.diagnostics : defaults.diagnostics,
1236
1238
  diagnosticSeverity: isObject(config) && hasProperty(config, "diagnosticSeverity") && isRecord(config.diagnosticSeverity) ? parseDiagnosticSeverity(config.diagnosticSeverity) : defaults.diagnosticSeverity,
1237
1239
  diagnosticsName: isObject(config) && hasProperty(config, "diagnosticsName") && isBoolean(config.diagnosticsName) ? config.diagnosticsName : defaults.diagnosticsName,
1240
+ missingDiagnosticNextLine: isObject(config) && hasProperty(config, "missingDiagnosticNextLine") && isString(config.missingDiagnosticNextLine) && isValidSeverityLevel(config.missingDiagnosticNextLine) ? config.missingDiagnosticNextLine : defaults.missingDiagnosticNextLine,
1238
1241
  quickinfo: isObject(config) && hasProperty(config, "quickinfo") && isBoolean(config.quickinfo) ? config.quickinfo : defaults.quickinfo,
1239
1242
  quickinfoEffectParameters: isObject(config) && hasProperty(config, "quickinfoEffectParameters") && isString(config.quickinfoEffectParameters) && ["always", "never", "whentruncated"].includes(config.quickinfoEffectParameters.toLowerCase()) ? config.quickinfoEffectParameters.toLowerCase() : defaults.quickinfoEffectParameters,
1240
1243
  quickinfoMaximumLength: isObject(config) && hasProperty(config, "quickinfoMaximumLength") && isNumber(config.quickinfoMaximumLength) ? config.quickinfoMaximumLength : defaults.quickinfoMaximumLength,
@@ -1996,7 +1999,8 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1996
1999
  lineOverrides[ruleName].unshift({
1997
2000
  pos: foundNode.node.pos,
1998
2001
  end: foundNode.node.end,
1999
- level: ruleLevel
2002
+ level: ruleLevel,
2003
+ commentRange: foundNode.commentRange
2000
2004
  });
2001
2005
  }
2002
2006
  } else {
@@ -2069,6 +2073,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
2069
2073
  fixes: entry.fixes.concat(node ? [fixByDisableNextLine(node)] : []).concat([fixByDisableEntireFile])
2070
2074
  });
2071
2075
  });
2076
+ const unusedLineOverrides = new Set(lineOverrides[ruleNameLowered] || []);
2072
2077
  for (const emitted of applicableDiagnostics.slice(0)) {
2073
2078
  let newLevel = defaultLevel;
2074
2079
  const lineOverride = (lineOverrides[ruleNameLowered] || []).find(
@@ -2076,6 +2081,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
2076
2081
  );
2077
2082
  if (lineOverride) {
2078
2083
  newLevel = lineOverride.level;
2084
+ unusedLineOverrides.delete(lineOverride);
2079
2085
  } else {
2080
2086
  const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find((_) => _.pos < emitted.range.pos);
2081
2087
  if (sectionOverride) newLevel = sectionOverride.level;
@@ -2099,6 +2105,19 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
2099
2105
  });
2100
2106
  }
2101
2107
  }
2108
+ if (pluginOptions.missingDiagnosticNextLine !== "off" && unusedLineOverrides.size > 0) {
2109
+ for (const unusedLineOverride of unusedLineOverrides) {
2110
+ diagnostics2.push({
2111
+ file: sourceFile,
2112
+ start: unusedLineOverride.commentRange.pos,
2113
+ length: unusedLineOverride.commentRange.end - unusedLineOverride.commentRange.pos,
2114
+ messageText: `@effect-diagnostics-next-line ${rule.name}:${unusedLineOverride.level} has no effect, make sure you are suppressing the right rule.`,
2115
+ category: levelToDiagnosticCategory[pluginOptions.missingDiagnosticNextLine],
2116
+ code: -1,
2117
+ source: "effect"
2118
+ });
2119
+ }
2120
+ }
2102
2121
  return { diagnostics: diagnostics2, codeFixes };
2103
2122
  });
2104
2123
  return { execute };
@@ -4545,6 +4564,7 @@ var leakingRequirements = createDiagnostic({
4545
4564
  const typeChecker = yield* service(TypeCheckerApi);
4546
4565
  const typeCheckerUtils = yield* service(TypeCheckerUtils);
4547
4566
  const typeParser = yield* service(TypeParser);
4567
+ const tsUtils = yield* service(TypeScriptUtils);
4548
4568
  const parseLeakedRequirements = cachedBy(
4549
4569
  fn("leakingServices.checkServiceLeaking")(
4550
4570
  function* (service2, atLocation) {
@@ -4602,7 +4622,21 @@ var leakingRequirements = createDiagnostic({
4602
4622
  }
4603
4623
  }
4604
4624
  if (sharedRequirementsKeys && sharedRequirementsKeys.length > 0 && effectMembers >= 2) {
4605
- return sharedRequirementsKeys.map((key) => memory.get(key));
4625
+ return sharedRequirementsKeys.map((key) => memory.get(key)).filter(
4626
+ (type) => {
4627
+ let symbol3 = type.symbol;
4628
+ if (symbol3 && symbol3.flags & ts.SymbolFlags.Alias) {
4629
+ symbol3 = typeChecker.getAliasedSymbol(symbol3);
4630
+ }
4631
+ return !(symbol3.declarations || []).some((declaration) => {
4632
+ const declarationSource = tsUtils.getSourceFileOfNode(declaration);
4633
+ if (!declarationSource) return false;
4634
+ return declarationSource.text.substring(declaration.pos, declaration.end).toLowerCase().indexOf(
4635
+ "@effect-leakable-service"
4636
+ ) > -1;
4637
+ });
4638
+ }
4639
+ );
4606
4640
  }
4607
4641
  return [];
4608
4642
  }
@@ -4615,7 +4649,7 @@ var leakingRequirements = createDiagnostic({
4615
4649
  report({
4616
4650
  location: node,
4617
4651
  messageText: `This Service is leaking the ${requirements.map((_) => typeChecker.typeToString(_)).join(" | ")} requirement.
4618
- If these requirements cannot be cached and are expected to be provided per method invocation (e.g. HttpServerRequest), you can safely disable this diagnostic for this line through quickfixes.
4652
+ If these requirements cannot be cached and are expected to be provided per method invocation (e.g. HttpServerRequest), you can either safely disable this diagnostic for this line through quickfixes or mark the service declaration with a JSDoc @effect-leakable-service.
4619
4653
  More info at https://effect.website/docs/requirements-management/layers/#avoiding-requirement-leakage`,
4620
4654
  fixes: []
4621
4655
  });
@@ -12331,7 +12365,7 @@ var layerMagic = createRefactor({
12331
12365
  return pipe(
12332
12366
  extractLayers(atLocation, false),
12333
12367
  flatMap2(
12334
- (extractedLayer) => extractedLayer.length < 1 ? TypeParserIssue.issue : succeed(extractedLayer)
12368
+ (extractedLayer) => extractedLayer.length <= 1 ? TypeParserIssue.issue : succeed(extractedLayer)
12335
12369
  ),
12336
12370
  map5((extractedLayers) => ({
12337
12371
  kind: "refactor.rewrite.effect.layerMagicPrepare",
@@ -12417,7 +12451,7 @@ var layerMagic = createRefactor({
12417
12451
  extractArrayLiteral(_targetLayer.castedStructure),
12418
12452
  orElse2(() => extractLayers(_targetLayer.castedStructure, false)),
12419
12453
  flatMap2(
12420
- (extractedLayer) => extractedLayer.length < 1 ? TypeParserIssue.issue : succeed(extractedLayer)
12454
+ (extractedLayer) => extractedLayer.length <= 1 ? TypeParserIssue.issue : succeed(extractedLayer)
12421
12455
  ),
12422
12456
  map5((extractedLayers) => ({
12423
12457
  kind: "refactor.rewrite.effect.layerMagicBuild",
@@ -12455,7 +12489,8 @@ var layerMagic = createRefactor({
12455
12489
  const missingOutput = new Set(outputIndexes);
12456
12490
  const missingInternal = /* @__PURE__ */ new Set();
12457
12491
  const outputEntry = [];
12458
- for (const graphNode of sortedNodes) {
12492
+ for (let i = 0; i < sortedNodes.length; i++) {
12493
+ const graphNode = sortedNodes[i];
12459
12494
  const mergeOutput = graphNode.provides.filter((_) => missingOutput.has(_));
12460
12495
  const provideInternal = graphNode.provides.filter((_) => missingInternal.has(_));
12461
12496
  graphNode.requires.forEach((_) => missingInternal.add(_));
@@ -12483,7 +12518,15 @@ var layerMagic = createRefactor({
12483
12518
  )
12484
12519
  )
12485
12520
  );
12486
- changeTracker.replaceNode(sourceFile, atLocation, newDeclaration, {
12521
+ const newDeclarationWithComment = missingOutput.size > 0 ? ts.addSyntheticTrailingComment(
12522
+ newDeclaration,
12523
+ ts.SyntaxKind.MultiLineCommentTrivia,
12524
+ " Unable to find " + fromIterable(missingOutput).map((key) => memory.get(key)).map(
12525
+ (_) => typeChecker.typeToString(_, void 0, ts.TypeFormatFlags.NoTruncation)
12526
+ ).join(", ") + " in the provided layers. ",
12527
+ false
12528
+ ) : newDeclaration;
12529
+ changeTracker.replaceNode(sourceFile, atLocation, newDeclarationWithComment, {
12487
12530
  leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll,
12488
12531
  trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Exclude
12489
12532
  });