From 21355982fd2c0c72ee507faed0d4b5a2f848245c Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Mon, 13 Feb 2017 16:58:14 -0800 Subject: [PATCH] Offer missing abstract codefix once * per class that is missing potentially many abstract members. --- src/harness/fourslash.ts | 17 +++++++++++++++++ src/services/services.ts | 8 +++++++- .../codeFixClassExtendAbstractProperty.ts | 6 +++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index fc85fb7276c..62770a96e7a 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2153,12 +2153,29 @@ namespace FourSlash { const diagnostics: ts.Diagnostic[] = this.getDiagnostics(fileName); let actions: ts.CodeAction[] = undefined; + + const checkedDiagnostics = ts.createMap(); + 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; diff --git a/src/services/services.ts b/src/services/services.ts index b83995e31ed..35588a1902a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -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 = { diff --git a/tests/cases/fourslash/codeFixClassExtendAbstractProperty.ts b/tests/cases/fourslash/codeFixClassExtendAbstractProperty.ts index 46de88f7511..3160a3b9a08 100644 --- a/tests/cases/fourslash/codeFixClassExtendAbstractProperty.ts +++ b/tests/cases/fourslash/codeFixClassExtendAbstractProperty.ts @@ -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.'); + } `);