@effect/language-service 0.10.0 → 0.10.1

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.
Files changed (3) hide show
  1. package/index.js +80 -93
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -3112,11 +3112,12 @@ function createCompletion(definition) {
3112
3112
  var PluginOptions = Tag("PluginOptions");
3113
3113
  var SourceFileNotFoundError = class extends TaggedError("SourceFileNotFoundError") {
3114
3114
  };
3115
- var getSemanticDiagnostics = fn("LSP.getSemanticDiagnostics")(function* (diagnostics2, sourceFile) {
3115
+ var getSemanticDiagnosticsWithCodeFixes = fn("LSP.getSemanticDiagnostics")(function* (rules, sourceFile) {
3116
3116
  const effectDiagnostics = [];
3117
+ const effectCodeFixes = [];
3117
3118
  const executor = yield* createDiagnosticExecutor(sourceFile);
3118
- for (const diagnostic of diagnostics2) {
3119
- const result = yield* option(executor.execute(diagnostic));
3119
+ for (const rule of rules) {
3120
+ const result = yield* option(executor.execute(rule));
3120
3121
  if (isSome2(result)) {
3121
3122
  effectDiagnostics.push(
3122
3123
  ...pipe(
@@ -3127,35 +3128,34 @@ var getSemanticDiagnostics = fn("LSP.getSemanticDiagnostics")(function* (diagnos
3127
3128
  length: _.node.getEnd() - _.node.getStart(sourceFile),
3128
3129
  messageText: _.messageText,
3129
3130
  category: _.category,
3130
- code: diagnostic.code,
3131
+ code: rule.code,
3131
3132
  source: "effect"
3132
3133
  }))
3133
3134
  )
3134
3135
  );
3135
- }
3136
- }
3137
- return effectDiagnostics;
3138
- });
3139
- var getCodeFixesAtPosition = fn("LSP.getCodeFixesAtPosition")(function* (diagnostics2, sourceFile, start, end, errorCodes) {
3140
- const runnableDiagnostics = diagnostics2.filter((_) => errorCodes.indexOf(_.code) > -1);
3141
- const applicableFixes = [];
3142
- const executor = yield* createDiagnosticExecutor(sourceFile);
3143
- for (const diagnostic of runnableDiagnostics) {
3144
- const result = yield* option(executor.execute(diagnostic));
3145
- if (isSome2(result)) {
3146
- applicableFixes.push(
3136
+ effectCodeFixes.push(
3147
3137
  ...pipe(
3148
3138
  result.value,
3149
- filter(
3150
- (_) => _.node.getStart(sourceFile) === start && _.node.getEnd() === end
3139
+ map2(
3140
+ (_) => map2(
3141
+ _.fixes,
3142
+ (fix) => ({
3143
+ ...fix,
3144
+ code: rule.code,
3145
+ start: _.node.getStart(sourceFile),
3146
+ end: _.node.getEnd()
3147
+ })
3148
+ )
3151
3149
  ),
3152
- map2((_) => _.fixes),
3153
3150
  flatten
3154
3151
  )
3155
3152
  );
3156
3153
  }
3157
3154
  }
3158
- return applicableFixes;
3155
+ return {
3156
+ diagnostics: effectDiagnostics,
3157
+ codeFixes: effectCodeFixes
3158
+ };
3159
3159
  });
3160
3160
  var getApplicableRefactors = fn("LSP.getApplicableRefactors")(function* (refactors2, sourceFile, positionOrRange) {
3161
3161
  const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
@@ -4813,10 +4813,6 @@ var init = (modules) => {
4813
4813
  quickinfo: info.config && "quickinfo" in info.config && typeof info.config.quickinfo === "boolean" ? info.config.quickinfo : true,
4814
4814
  completions: info.config && "completions" in info.config && typeof info.config.completions === "boolean" ? info.config.completions : true
4815
4815
  };
4816
- const proxy = /* @__PURE__ */ Object.create(null);
4817
- for (const k of Object.keys(languageService)) {
4818
- proxy[k] = (...args) => languageService[k].apply(languageService, args);
4819
- }
4820
4816
  const diagnosticsErrorCodes = diagnostics.map((diagnostic) => diagnostic.code);
4821
4817
  try {
4822
4818
  ;
@@ -4826,81 +4822,20 @@ var init = (modules) => {
4826
4822
  });
4827
4823
  } catch (_) {
4828
4824
  }
4829
- proxy.getSupportedCodeFixes = (...args) => languageService.getSupportedCodeFixes(...args).concat(
4830
- diagnosticsErrorCodes.map((_) => "" + _)
4831
- );
4832
- proxy.getCodeFixesAtPosition = (fileName, start, end, errorCodes, formatOptions, preferences, ...args) => {
4833
- const applicableCodeFixes = languageService.getCodeFixesAtPosition(
4834
- fileName,
4835
- start,
4836
- end,
4837
- errorCodes,
4838
- formatOptions,
4839
- preferences,
4840
- ...args
4841
- );
4842
- const program = languageService.getProgram();
4843
- if (program) {
4844
- const sourceFile = program.getSourceFile(fileName);
4845
- if (sourceFile) {
4846
- return pipe(
4847
- gen2(function* () {
4848
- const effectCodeFixes = [];
4849
- const applicableFixes = yield* getCodeFixesAtPosition(
4850
- diagnostics,
4851
- sourceFile,
4852
- start,
4853
- end,
4854
- errorCodes
4855
- );
4856
- const formatContext = modules.typescript.formatting.getFormatContext(
4857
- formatOptions,
4858
- info.languageServiceHost
4859
- );
4860
- for (const applicableFix of applicableFixes) {
4861
- const changes = modules.typescript.textChanges.ChangeTracker.with(
4862
- {
4863
- formatContext,
4864
- host: info.languageServiceHost,
4865
- preferences: preferences || {}
4866
- },
4867
- (changeTracker) => pipe(
4868
- applicableFix.apply,
4869
- provideService(ChangeTracker, changeTracker),
4870
- run
4871
- )
4872
- );
4873
- effectCodeFixes.push({
4874
- fixName: applicableFix.fixName,
4875
- description: applicableFix.description,
4876
- changes
4877
- });
4878
- }
4879
- return effectCodeFixes;
4880
- }),
4881
- provideService(TypeCheckerApi, program.getTypeChecker()),
4882
- provideService(
4883
- TypeCheckerApiCache,
4884
- makeTypeCheckerApiCache()
4885
- ),
4886
- provideService(TypeScriptApi, modules.typescript),
4887
- provideService(PluginOptions, pluginOptions),
4888
- run,
4889
- Either_exports.map((effectCodeFixes) => applicableCodeFixes.concat(effectCodeFixes)),
4890
- Either_exports.getOrElse(() => applicableCodeFixes)
4891
- );
4892
- }
4893
- }
4894
- return applicableCodeFixes;
4895
- };
4825
+ const proxy = /* @__PURE__ */ Object.create(null);
4826
+ for (const k of Object.keys(languageService)) {
4827
+ proxy[k] = (...args) => languageService[k].apply(languageService, args);
4828
+ }
4829
+ const effectCodeFixesForFile = /* @__PURE__ */ new Map();
4896
4830
  proxy.getSemanticDiagnostics = (fileName, ...args) => {
4897
4831
  const applicableDiagnostics = languageService.getSemanticDiagnostics(fileName, ...args);
4898
4832
  const program = languageService.getProgram();
4899
4833
  if (pluginOptions.diagnostics && program) {
4834
+ effectCodeFixesForFile.delete(fileName);
4900
4835
  const sourceFile = program.getSourceFile(fileName);
4901
4836
  if (sourceFile) {
4902
4837
  return pipe(
4903
- getSemanticDiagnostics(diagnostics, sourceFile),
4838
+ getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),
4904
4839
  provideService(TypeCheckerApi, program.getTypeChecker()),
4905
4840
  provideService(
4906
4841
  TypeCheckerApiCache,
@@ -4909,13 +4844,65 @@ var init = (modules) => {
4909
4844
  provideService(TypeScriptApi, modules.typescript),
4910
4845
  provideService(PluginOptions, pluginOptions),
4911
4846
  run,
4912
- Either_exports.map((effectDiagnostics) => effectDiagnostics.concat(applicableDiagnostics)),
4847
+ Either_exports.map(({ codeFixes, diagnostics: diagnostics2 }) => {
4848
+ effectCodeFixesForFile.set(fileName, codeFixes);
4849
+ return diagnostics2.concat(applicableDiagnostics);
4850
+ }),
4913
4851
  Either_exports.getOrElse(() => applicableDiagnostics)
4914
4852
  );
4915
4853
  }
4916
4854
  }
4917
4855
  return applicableDiagnostics;
4918
4856
  };
4857
+ proxy.getSupportedCodeFixes = (...args) => languageService.getSupportedCodeFixes(...args).concat(
4858
+ diagnosticsErrorCodes.map((_) => "" + _)
4859
+ );
4860
+ proxy.getCodeFixesAtPosition = (fileName, start, end, errorCodes, formatOptions, preferences, ...args) => {
4861
+ const applicableCodeFixes = languageService.getCodeFixesAtPosition(
4862
+ fileName,
4863
+ start,
4864
+ end,
4865
+ errorCodes,
4866
+ formatOptions,
4867
+ preferences,
4868
+ ...args
4869
+ );
4870
+ return pipe(
4871
+ sync(() => {
4872
+ const effectCodeFixes = [];
4873
+ const applicableFixes = (effectCodeFixesForFile.get(fileName) || []).filter(
4874
+ (_) => _.start === start && _.end === end && errorCodes.indexOf(_.code) > -1
4875
+ );
4876
+ const formatContext = modules.typescript.formatting.getFormatContext(
4877
+ formatOptions,
4878
+ info.languageServiceHost
4879
+ );
4880
+ for (const applicableFix of applicableFixes) {
4881
+ const changes = modules.typescript.textChanges.ChangeTracker.with(
4882
+ {
4883
+ formatContext,
4884
+ host: info.languageServiceHost,
4885
+ preferences: preferences || {}
4886
+ },
4887
+ (changeTracker) => pipe(
4888
+ applicableFix.apply,
4889
+ provideService(ChangeTracker, changeTracker),
4890
+ run
4891
+ )
4892
+ );
4893
+ effectCodeFixes.push({
4894
+ fixName: applicableFix.fixName,
4895
+ description: applicableFix.description,
4896
+ changes
4897
+ });
4898
+ }
4899
+ return effectCodeFixes;
4900
+ }),
4901
+ run,
4902
+ Either_exports.map((effectCodeFixes) => applicableCodeFixes.concat(effectCodeFixes)),
4903
+ Either_exports.getOrElse(() => applicableCodeFixes)
4904
+ );
4905
+ };
4919
4906
  proxy.getApplicableRefactors = (...args) => {
4920
4907
  const applicableRefactors = languageService.getApplicableRefactors(...args);
4921
4908
  const [fileName, positionOrRange] = args;