@effect/language-service 0.44.1 → 0.45.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
@@ -1210,14 +1210,19 @@ var defaults = {
1210
1210
  target: "service",
1211
1211
  pattern: "default",
1212
1212
  skipLeadingPath: ["src/"]
1213
- }]
1213
+ }, {
1214
+ target: "custom",
1215
+ pattern: "default",
1216
+ skipLeadingPath: ["src/"]
1217
+ }],
1218
+ extendedKeyDetection: false
1214
1219
  };
1215
1220
  function parseKeyPatterns(patterns) {
1216
1221
  const result = [];
1217
1222
  for (const entry of patterns) {
1218
1223
  if (!isObject(entry)) continue;
1219
1224
  result.push({
1220
- target: hasProperty(entry, "target") && isString(entry.target) && ["service", "error"].includes(entry.target.toLowerCase()) ? entry.target.toLowerCase() : "service",
1225
+ target: hasProperty(entry, "target") && isString(entry.target) && ["service", "error", "custom"].includes(entry.target.toLowerCase()) ? entry.target.toLowerCase() : "service",
1221
1226
  pattern: hasProperty(entry, "pattern") && isString(entry.pattern) && ["package-identifier", "default"].includes(entry.pattern.toLowerCase()) ? entry.pattern.toLowerCase() : "default",
1222
1227
  skipLeadingPath: hasProperty(entry, "skipLeadingPath") && isArray(entry.skipLeadingPath) && entry.skipLeadingPath.every(isString) ? entry.skipLeadingPath : ["src/"]
1223
1228
  });
@@ -1243,7 +1248,8 @@ function parse(config) {
1243
1248
  topLevelNamedReexports: isObject(config) && hasProperty(config, "topLevelNamedReexports") && isString(config.topLevelNamedReexports) && ["ignore", "follow"].includes(config.topLevelNamedReexports.toLowerCase()) ? config.topLevelNamedReexports.toLowerCase() : defaults.topLevelNamedReexports,
1244
1249
  renames: isObject(config) && hasProperty(config, "renames") && isBoolean(config.renames) ? config.renames : defaults.renames,
1245
1250
  noExternal: isObject(config) && hasProperty(config, "noExternal") && isBoolean(config.noExternal) ? config.noExternal : defaults.noExternal,
1246
- keyPatterns: isObject(config) && hasProperty(config, "keyPatterns") && isArray(config.keyPatterns) ? parseKeyPatterns(config.keyPatterns) : defaults.keyPatterns
1251
+ keyPatterns: isObject(config) && hasProperty(config, "keyPatterns") && isArray(config.keyPatterns) ? parseKeyPatterns(config.keyPatterns) : defaults.keyPatterns,
1252
+ extendedKeyDetection: isObject(config) && hasProperty(config, "extendedKeyDetection") && isBoolean(config.extendedKeyDetection) ? config.extendedKeyDetection : defaults.extendedKeyDetection
1247
1253
  };
1248
1254
  }
1249
1255
 
@@ -4052,6 +4058,62 @@ var deterministicKeys = createDiagnostic({
4052
4058
  apply: fn("deterministicKeys.apply")(function* (sourceFile, report) {
4053
4059
  const ts = yield* service(TypeScriptApi);
4054
4060
  const typeParser = yield* service(TypeParser);
4061
+ const typeChecker = yield* service(TypeCheckerApi);
4062
+ const typeScriptUtils = yield* service(TypeScriptUtils);
4063
+ const options = yield* service(LanguageServicePluginOptions);
4064
+ const parseExtendsCustom = cachedBy(
4065
+ fn("parseExtendsCustom")(function* (classDeclaration) {
4066
+ if (!options.extendedKeyDetection) {
4067
+ return yield* typeParserIssue("Extended key detection is disabled", void 0, classDeclaration);
4068
+ }
4069
+ if (!classDeclaration.name) {
4070
+ return yield* typeParserIssue("Class has no name", void 0, classDeclaration);
4071
+ }
4072
+ if (!ts.isIdentifier(classDeclaration.name)) {
4073
+ return yield* typeParserIssue("Class name is not an identifier", void 0, classDeclaration);
4074
+ }
4075
+ const heritageClauses = classDeclaration.heritageClauses;
4076
+ if (!heritageClauses) {
4077
+ return yield* typeParserIssue("Class has no heritage clauses", void 0, classDeclaration);
4078
+ }
4079
+ const nodeToVisit2 = [...classDeclaration.heritageClauses];
4080
+ const appendNodeToVisit2 = (node) => {
4081
+ nodeToVisit2.push(node);
4082
+ return void 0;
4083
+ };
4084
+ while (nodeToVisit2.length > 0) {
4085
+ const node = nodeToVisit2.shift();
4086
+ if (ts.isCallExpression(node)) {
4087
+ for (let i = 0; i < node.arguments.length; i++) {
4088
+ const arg = node.arguments[i];
4089
+ if (!ts.isStringLiteral(arg)) continue;
4090
+ const resolvedSignature = typeChecker.getResolvedSignature(node);
4091
+ if (resolvedSignature) {
4092
+ const parameter = resolvedSignature.parameters[i];
4093
+ if (!parameter) continue;
4094
+ if (parameter.declarations) {
4095
+ for (const declaration of parameter.declarations) {
4096
+ const parameterSourceFile = typeScriptUtils.getSourceFileOfNode(declaration);
4097
+ const paramText = parameterSourceFile.text.substring(declaration.pos, declaration.end);
4098
+ if (paramText.toLowerCase().includes("@effect-identifier")) {
4099
+ return { className: classDeclaration.name, keyStringLiteral: arg, target: "custom" };
4100
+ }
4101
+ }
4102
+ }
4103
+ }
4104
+ }
4105
+ }
4106
+ ts.forEachChild(node, appendNodeToVisit2);
4107
+ }
4108
+ return yield* typeParserIssue(
4109
+ "Class does not extend any custom pattern",
4110
+ void 0,
4111
+ classDeclaration
4112
+ );
4113
+ }),
4114
+ "deterministicKeys.parseExtendsCustom",
4115
+ (classDeclaration) => classDeclaration
4116
+ );
4055
4117
  const nodeToVisit = [];
4056
4118
  const appendNodeToVisit = (node) => {
4057
4119
  nodeToVisit.push(node);
@@ -4075,12 +4137,13 @@ var deterministicKeys = createDiagnostic({
4075
4137
  map5(({ className, keyStringLiteral }) => ({ keyStringLiteral, className, target: "error" }))
4076
4138
  )
4077
4139
  ),
4140
+ orElse2(() => parseExtendsCustom(node)),
4078
4141
  orElse2(() => void_)
4079
4142
  );
4080
4143
  if (result && result.keyStringLiteral) {
4081
- const { className, keyStringLiteral } = result;
4144
+ const { className, keyStringLiteral, target } = result;
4082
4145
  const classNameText = ts.idText(className);
4083
- const expectedKey = yield* createString(sourceFile, classNameText, result.target);
4146
+ const expectedKey = yield* createString(sourceFile, classNameText, target);
4084
4147
  if (!expectedKey) continue;
4085
4148
  const actualIdentifier = keyStringLiteral.text;
4086
4149
  if (actualIdentifier !== expectedKey) {
@@ -5857,6 +5920,31 @@ var effectDiagnosticsComment = createCompletion({
5857
5920
  })
5858
5921
  });
5859
5922
 
5923
+ // src/completions/effectJsdocComment.ts
5924
+ var effectJsdocComment = createCompletion({
5925
+ name: "effectJsdocComment",
5926
+ apply: fn("effectJsdocComment")(function* (sourceFile, position) {
5927
+ const ts = yield* service(TypeScriptApi);
5928
+ const sourceText = sourceFile.text;
5929
+ const match2 = /(\/\/|\/\*(?:\*?))\s*(@)\s*$/id.exec(sourceText.substring(0, position));
5930
+ if (match2 && match2.indices) {
5931
+ const lastIndex = match2.indices[2][0];
5932
+ const replacementSpan = {
5933
+ start: lastIndex,
5934
+ length: Math.max(0, position - lastIndex)
5935
+ };
5936
+ return [{
5937
+ name: `@effect-identifier`,
5938
+ kind: ts.ScriptElementKind.string,
5939
+ insertText: "@effect-identifier",
5940
+ isSnippet: true,
5941
+ replacementSpan
5942
+ }];
5943
+ }
5944
+ return [];
5945
+ })
5946
+ });
5947
+
5860
5948
  // src/completions/effectSchemaSelfInClasses.ts
5861
5949
  var effectSchemaSelfInClasses = createCompletion({
5862
5950
  name: "effectSchemaSelfInClasses",
@@ -6090,6 +6178,7 @@ var completions = [
6090
6178
  effectDataClasses,
6091
6179
  effectDiagnosticsComment,
6092
6180
  effectCodegensComment,
6181
+ effectJsdocComment,
6093
6182
  durationInput,
6094
6183
  schemaBrand
6095
6184
  ];