mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-17 19:11:26 -06:00
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
/* @internal */
|
|
namespace ts {
|
|
export interface CodeFix {
|
|
errorCodes: number[];
|
|
getCodeActions(context: CodeFixContext): CodeAction[] | undefined;
|
|
}
|
|
|
|
export interface CodeFixContext {
|
|
errorCode: number;
|
|
sourceFile: SourceFile;
|
|
span: TextSpan;
|
|
program: Program;
|
|
newLineCharacter: string;
|
|
}
|
|
|
|
export namespace codefix {
|
|
const codeFixes = createMap<CodeFix[]>();
|
|
|
|
export function registerCodeFix(action: CodeFix) {
|
|
forEach(action.errorCodes, error => {
|
|
let fixes = codeFixes[error];
|
|
if (!fixes) {
|
|
fixes = [];
|
|
codeFixes[error] = fixes;
|
|
}
|
|
fixes.push(action);
|
|
});
|
|
}
|
|
|
|
export function getSupportedErrorCodes() {
|
|
return Object.keys(codeFixes);
|
|
}
|
|
|
|
export function getFixes(context: CodeFixContext): CodeAction[] {
|
|
const fixes = codeFixes[context.errorCode];
|
|
let allActions: CodeAction[] = [];
|
|
|
|
forEach(fixes, f => {
|
|
const actions = f.getCodeActions(context);
|
|
if (actions && actions.length > 0) {
|
|
allActions = allActions.concat(actions);
|
|
}
|
|
});
|
|
|
|
return allActions;
|
|
}
|
|
}
|
|
}
|