Skip to content

Commit 2135598

Browse files
author
Arthur Ozga
committed
Offer missing abstract codefix once
* per class that is missing potentially many abstract members.
1 parent 7cd0e1a commit 2135598

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/harness/fourslash.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,12 +2153,29 @@ namespace FourSlash {
21532153
const diagnostics: ts.Diagnostic[] = this.getDiagnostics(fileName);
21542154

21552155
let actions: ts.CodeAction[] = undefined;
2156+
2157+
const checkedDiagnostics = ts.createMap<boolean>();
2158+
21562159
for (const diagnostic of diagnostics) {
21572160

21582161
if (errorCode && errorCode !== diagnostic.code) {
21592162
continue;
21602163
}
21612164

2165+
const summary = JSON.stringify({
2166+
start: diagnostic.start,
2167+
length: diagnostic.length,
2168+
code: diagnostic.code
2169+
});
2170+
2171+
if (checkedDiagnostics.has(summary)) {
2172+
// Don't want to ask for code fixes in an identical position for the same error code twice.
2173+
continue;
2174+
}
2175+
else {
2176+
checkedDiagnostics.set(summary, true);
2177+
}
2178+
21622179
const newActions = this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.length, [diagnostic.code]);
21632180
if (newActions && newActions.length) {
21642181
actions = actions ? actions.concat(newActions) : newActions;

src/services/services.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,13 @@ namespace ts {
16881688

16891689
let allFixes: CodeAction[] = [];
16901690

1691-
forEach(errorCodes, error => {
1691+
// De-duplicate error codes.
1692+
const errorCodeSet: number[] = [];
1693+
for (const code of errorCodes) {
1694+
errorCodeSet[code] = code;
1695+
}
1696+
1697+
forEach(errorCodeSet, error => {
16921698
cancellationToken.throwIfCancellationRequested();
16931699

16941700
const context = {

tests/cases/fourslash/codeFixClassExtendAbstractProperty.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
//// abstract class A {
44
//// abstract x: number;
5+
//// abstract foo(): number;
56
//// }
67
////
78
//// class C extends A {[|
89
//// |]}
910

1011
verify.rangeAfterCodeFix(`
11-
x: number;
12+
x: number;
13+
foo(): number {
14+
throw new Error('Method not implemented.');
15+
}
1216
`);

0 commit comments

Comments
 (0)