mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 03:20:56 -06:00
Add removeAbstractModifier Fix
Still need to add localization strings
This commit is contained in:
parent
834245cd8f
commit
c89b97b56a
@ -173,7 +173,8 @@ var servicesSources = [
|
||||
"codeFixes/fixClassIncorrectlyImplementsInterface.ts",
|
||||
"codeFixes/fixClassDoesntImplementInheritedAbstractMember.ts",
|
||||
"codeFixes/fixClassSuperMustPrecedeThisAccess.ts",
|
||||
"codeFixes/fixConstructorForDerivedNeedSuperCall.ts"
|
||||
"codeFixes/fixConstructorForDerivedNeedSuperCall.ts",
|
||||
"codeFixes/fixRemoveAbstractModifierInNonAbstractClass.ts"
|
||||
].map(function (f) {
|
||||
return path.join(servicesDirectory, f);
|
||||
}));
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
/* @internal */
|
||||
namespace ts.codefix {
|
||||
registerCodeFix({
|
||||
errorCodes: [Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class.code],
|
||||
getCodeActions: (context: CodeFixContext) => {
|
||||
const sourceFile = context.sourceFile;
|
||||
const start = context.span.start;
|
||||
const token = getTokenAtPosition(sourceFile, start);
|
||||
|
||||
Debug.assert(token.kind === SyntaxKind.AbstractKeyword);
|
||||
|
||||
const propertyDeclaration = <PropertyDeclaration>token.parent;
|
||||
const classDeclaration = <ClassDeclaration>propertyDeclaration.parent;
|
||||
const classKeywordStart = classDeclaration.getChildren()[0].getStart();
|
||||
|
||||
let codeFix: CodeAction[] = [
|
||||
{
|
||||
description: `Remove abstract modifier from ${propertyDeclaration.name.getText()}.`,
|
||||
changes: [{
|
||||
fileName: sourceFile.fileName,
|
||||
textChanges: [{
|
||||
span: {start: start, length: context.span.length + /*space*/ 1},
|
||||
newText: ""
|
||||
}]
|
||||
}]
|
||||
},
|
||||
{
|
||||
description: `Make class ${classDeclaration.name.getText()} abstract.`,
|
||||
changes: [{
|
||||
fileName: sourceFile.fileName,
|
||||
textChanges: [{
|
||||
span: { start: classKeywordStart, length: 0 },
|
||||
newText: "abstract "
|
||||
}]
|
||||
}]
|
||||
}
|
||||
];
|
||||
|
||||
return codeFix;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -2,4 +2,5 @@
|
||||
/// <reference path="fixClassDoesntImplementInheritedAbstractMember.ts" />
|
||||
/// <reference path="fixClassSuperMustPrecedeThisAccess.ts" />
|
||||
/// <reference path="fixConstructorForDerivedNeedSuperCall.ts" />
|
||||
/// <reference path="fixExtendsInterfaceBecomesImplements.ts" />
|
||||
/// <reference path="fixExtendsInterfaceBecomesImplements.ts" />
|
||||
/// <reference path="fixRemoveAbstractModifierInNonAbstractClass.ts" />
|
||||
Loading…
x
Reference in New Issue
Block a user