Skip to content

Commit b19cfc0

Browse files
authored
Make getSupportedCodeFixes plugin test such that we dont need to update its baseline for every new error (#53070)
1 parent 40cd0de commit b19cfc0

File tree

4 files changed

+8
-1227
lines changed

4 files changed

+8
-1227
lines changed

src/services/codeFixProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function createCodeFixActionWorker(fixName: string, description: string, changes
4949
/** @internal */
5050
export function registerCodeFix(reg: CodeFixRegistration) {
5151
for (const error of reg.errorCodes) {
52+
errorCodeToFixesArray = undefined;
5253
errorCodeToFixes.add(String(error), reg);
5354
}
5455
if (reg.fixIds) {
@@ -59,9 +60,10 @@ export function registerCodeFix(reg: CodeFixRegistration) {
5960
}
6061
}
6162

63+
let errorCodeToFixesArray: readonly string[] | undefined;
6264
/** @internal */
6365
export function getSupportedErrorCodes(): readonly string[] {
64-
return arrayFrom(errorCodeToFixes.keys());
66+
return errorCodeToFixesArray ??= arrayFrom(errorCodeToFixes.keys());
6567
}
6668

6769
function removeFixIdIfFixAllUnavailable(registration: CodeFixRegistration, diagnostics: Diagnostic[]) {

src/testRunner/unittests/tsserver/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ export class TestSession extends ts.server.Session {
560560
}
561561
const response = super.executeCommand(request);
562562
if (this.logger.hasLevel(ts.server.LogLevel.verbose)) {
563-
this.logger.info(`response:${ts.server.indent(JSON.stringify(response, undefined, 2))}`);
563+
this.logger.info(`response:${ts.server.indent(JSON.stringify(response.response === ts.getSupportedCodeFixes() ? { ...response, response: "ts.getSupportedCodeFixes()" } : response, undefined, 2))}`);
564564
this.testhost.baselineHost("After request");
565565
}
566566
return response;

src/testRunner/unittests/tsserver/plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe("unittests:: tsserver:: plugins overriding getSupportedCodeFixes", () =
195195
return ["b"];
196196
default:
197197
// Make this stable list of single item so we dont have to update the baseline for every additional error
198-
return [info.languageService.getSupportedCodeFixes(fileName)[0]];
198+
return info.languageService.getSupportedCodeFixes(fileName);
199199
}
200200
};
201201
return proxy;

0 commit comments

Comments
 (0)