@effect/language-service 0.49.0 → 0.50.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
@@ -1242,7 +1242,8 @@ var defaults = {
1242
1242
  pattern: "default",
1243
1243
  skipLeadingPath: ["src/"]
1244
1244
  }],
1245
- extendedKeyDetection: false
1245
+ extendedKeyDetection: false,
1246
+ pipeableMinArgCount: 1
1246
1247
  };
1247
1248
  function parseKeyPatterns(patterns) {
1248
1249
  const result = [];
@@ -1277,7 +1278,8 @@ function parse(config) {
1277
1278
  renames: isObject(config) && hasProperty(config, "renames") && isBoolean(config.renames) ? config.renames : defaults.renames,
1278
1279
  noExternal: isObject(config) && hasProperty(config, "noExternal") && isBoolean(config.noExternal) ? config.noExternal : defaults.noExternal,
1279
1280
  keyPatterns: isObject(config) && hasProperty(config, "keyPatterns") && isArray(config.keyPatterns) ? parseKeyPatterns(config.keyPatterns) : defaults.keyPatterns,
1280
- extendedKeyDetection: isObject(config) && hasProperty(config, "extendedKeyDetection") && isBoolean(config.extendedKeyDetection) ? config.extendedKeyDetection : defaults.extendedKeyDetection
1281
+ extendedKeyDetection: isObject(config) && hasProperty(config, "extendedKeyDetection") && isBoolean(config.extendedKeyDetection) ? config.extendedKeyDetection : defaults.extendedKeyDetection,
1282
+ pipeableMinArgCount: isObject(config) && hasProperty(config, "pipeableMinArgCount") && isNumber(config.pipeableMinArgCount) ? config.pipeableMinArgCount : defaults.pipeableMinArgCount
1281
1283
  };
1282
1284
  }
1283
1285
 
@@ -7027,6 +7029,69 @@ More info at https://effect.website/docs/requirements-management/layers/#avoidin
7027
7029
  })
7028
7030
  });
7029
7031
 
7032
+ // src/diagnostics/missedPipeableOpportunity.ts
7033
+ var missedPipeableOpportunity = createDiagnostic({
7034
+ name: "missedPipeableOpportunity",
7035
+ code: 26,
7036
+ severity: "off",
7037
+ apply: fn("missedPipeableOpportunity.apply")(function* (sourceFile, report) {
7038
+ const ts = yield* service(TypeScriptApi);
7039
+ const typeChecker = yield* service(TypeCheckerApi);
7040
+ const typeParser = yield* service(TypeParser);
7041
+ const options = yield* service(LanguageServicePluginOptions);
7042
+ const nodeToVisit = [sourceFile];
7043
+ const prependNodeToVisit = (node) => {
7044
+ nodeToVisit.unshift(node);
7045
+ return void 0;
7046
+ };
7047
+ const callChainNodes = /* @__PURE__ */ new WeakMap();
7048
+ while (nodeToVisit.length > 0) {
7049
+ const node = nodeToVisit.shift();
7050
+ if (ts.isCallExpression(node) && node.arguments.length === 1 && node.parent) {
7051
+ const parentChain = callChainNodes.get(node.parent) || [];
7052
+ callChainNodes.set(node, parentChain.concat(node));
7053
+ } else if (node.parent && callChainNodes.has(node.parent) && ts.isExpression(node)) {
7054
+ const parentChain = callChainNodes.get(node.parent) || [];
7055
+ const originalParentChain = parentChain.slice();
7056
+ parentChain.push(node);
7057
+ while (parentChain.length > options.pipeableMinArgCount) {
7058
+ const subject = parentChain.pop();
7059
+ const resultType = typeChecker.getTypeAtLocation(subject);
7060
+ const pipeableType = yield* pipe(typeParser.pipeableType(resultType, subject), orElse2(() => void_));
7061
+ if (pipeableType) {
7062
+ report({
7063
+ location: parentChain[0],
7064
+ messageText: `Nested function calls can be converted to pipeable style for better readability.`,
7065
+ fixes: [{
7066
+ fixName: "missedPipeableOpportunity_fix",
7067
+ description: "Convert to pipe style",
7068
+ apply: gen(function* () {
7069
+ const changeTracker = yield* service(ChangeTracker);
7070
+ changeTracker.replaceNode(
7071
+ sourceFile,
7072
+ parentChain[0],
7073
+ ts.factory.createCallExpression(
7074
+ ts.factory.createPropertyAccessExpression(
7075
+ subject,
7076
+ "pipe"
7077
+ ),
7078
+ void 0,
7079
+ parentChain.filter(ts.isCallExpression).map((call) => call.expression)
7080
+ )
7081
+ );
7082
+ })
7083
+ }]
7084
+ });
7085
+ originalParentChain.forEach((node2) => callChainNodes.delete(node2));
7086
+ break;
7087
+ }
7088
+ }
7089
+ }
7090
+ ts.forEachChild(node, prependNodeToVisit);
7091
+ }
7092
+ })
7093
+ });
7094
+
7030
7095
  // src/diagnostics/missingEffectContext.ts
7031
7096
  var missingEffectContext = createDiagnostic({
7032
7097
  name: "missingEffectContext",
@@ -8301,7 +8366,8 @@ var diagnostics = [
8301
8366
  overriddenSchemaConstructor,
8302
8367
  unsupportedServiceAccessors,
8303
8368
  nonObjectEffectServiceType,
8304
- deterministicKeys
8369
+ deterministicKeys,
8370
+ missedPipeableOpportunity
8305
8371
  ];
8306
8372
 
8307
8373
  // src/completions/effectDiagnosticsComment.ts