mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-05 16:54:54 -05:00
Offer missing abstract codefix once
* per class that is missing potentially many abstract members.
This commit is contained in:
@@ -2153,12 +2153,29 @@ namespace FourSlash {
|
||||
const diagnostics: ts.Diagnostic[] = this.getDiagnostics(fileName);
|
||||
|
||||
let actions: ts.CodeAction[] = undefined;
|
||||
|
||||
const checkedDiagnostics = ts.createMap<boolean>();
|
||||
|
||||
for (const diagnostic of diagnostics) {
|
||||
|
||||
if (errorCode && errorCode !== diagnostic.code) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const summary = JSON.stringify({
|
||||
start: diagnostic.start,
|
||||
length: diagnostic.length,
|
||||
code: diagnostic.code
|
||||
});
|
||||
|
||||
if (checkedDiagnostics.has(summary)) {
|
||||
// Don't want to ask for code fixes in an identical position for the same error code twice.
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
checkedDiagnostics.set(summary, true);
|
||||
}
|
||||
|
||||
const newActions = this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.length, [diagnostic.code]);
|
||||
if (newActions && newActions.length) {
|
||||
actions = actions ? actions.concat(newActions) : newActions;
|
||||
|
||||
@@ -1688,7 +1688,13 @@ namespace ts {
|
||||
|
||||
let allFixes: CodeAction[] = [];
|
||||
|
||||
forEach(errorCodes, error => {
|
||||
// De-duplicate error codes.
|
||||
const errorCodeSet: number[] = [];
|
||||
for (const code of errorCodes) {
|
||||
errorCodeSet[code] = code;
|
||||
}
|
||||
|
||||
forEach(errorCodeSet, error => {
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
|
||||
const context = {
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
|
||||
//// abstract class A {
|
||||
//// abstract x: number;
|
||||
//// abstract foo(): number;
|
||||
//// }
|
||||
////
|
||||
//// class C extends A {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: number;
|
||||
x: number;
|
||||
foo(): number {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
|
||||
Reference in New Issue
Block a user