Simplify registerCodeFIx (#23349)
This commit is contained in:
parent
a04e747569
commit
b363240d05
1 changed files with 5 additions and 27 deletions
|
@ -24,7 +24,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace codefix {
|
export namespace codefix {
|
||||||
const codeFixRegistrations: CodeFixRegistration[][] = [];
|
const errorCodeToFixes = createMultiMap<CodeFixRegistration>();
|
||||||
const fixIdToRegistration = createMap<CodeFixRegistration>();
|
const fixIdToRegistration = createMap<CodeFixRegistration>();
|
||||||
|
|
||||||
type DiagnosticAndArguments = DiagnosticMessage | [DiagnosticMessage, string] | [DiagnosticMessage, string, string];
|
type DiagnosticAndArguments = DiagnosticMessage | [DiagnosticMessage, string] | [DiagnosticMessage, string, string];
|
||||||
|
@ -48,12 +48,7 @@ namespace ts {
|
||||||
|
|
||||||
export function registerCodeFix(reg: CodeFixRegistration) {
|
export function registerCodeFix(reg: CodeFixRegistration) {
|
||||||
for (const error of reg.errorCodes) {
|
for (const error of reg.errorCodes) {
|
||||||
let registrations = codeFixRegistrations[error];
|
errorCodeToFixes.add(String(error), reg);
|
||||||
if (!registrations) {
|
|
||||||
registrations = [];
|
|
||||||
codeFixRegistrations[error] = registrations;
|
|
||||||
}
|
|
||||||
registrations.push(reg);
|
|
||||||
}
|
}
|
||||||
if (reg.fixIds) {
|
if (reg.fixIds) {
|
||||||
for (const fixId of reg.fixIds) {
|
for (const fixId of reg.fixIds) {
|
||||||
|
@ -63,29 +58,12 @@ namespace ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSupportedErrorCodes() {
|
export function getSupportedErrorCodes(): string[] {
|
||||||
return Object.keys(codeFixRegistrations);
|
return arrayFrom(errorCodeToFixes.keys());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFixes(context: CodeFixContext): CodeFixAction[] {
|
export function getFixes(context: CodeFixContext): CodeFixAction[] {
|
||||||
const fixes = codeFixRegistrations[context.errorCode];
|
return flatMap(errorCodeToFixes.get(String(context.errorCode)) || emptyArray, f => f.getCodeActions(context));
|
||||||
const allActions: CodeFixAction[] = [];
|
|
||||||
|
|
||||||
forEach(fixes, f => {
|
|
||||||
const actions = f.getCodeActions(context);
|
|
||||||
if (actions && actions.length > 0) {
|
|
||||||
for (const action of actions) {
|
|
||||||
if (action === undefined) {
|
|
||||||
context.host.log(`Action for error code ${context.errorCode} added an invalid action entry; please log a bug`);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
allActions.push(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return allActions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAllFixes(context: CodeFixAllContext): CombinedCodeActions {
|
export function getAllFixes(context: CodeFixAllContext): CombinedCodeActions {
|
||||||
|
|
Loading…
Reference in a new issue