Skip to content

Commit 6c2c2f8

Browse files
author
Arthur Ozga
committed
use deduplicate
1 parent 2135598 commit 6c2c2f8

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

src/harness/fourslash.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,32 +2150,23 @@ namespace FourSlash {
21502150
* @param fileName Path to file where error should be retrieved from.
21512151
*/
21522152
private getCodeFixActions(fileName: string, errorCode?: number): ts.CodeAction[] {
2153-
const diagnostics: ts.Diagnostic[] = this.getDiagnostics(fileName);
2153+
const diagnosticsForCodeFix = this.getDiagnostics(fileName).map(diagnostic => {
2154+
return {
2155+
start: diagnostic.start,
2156+
length: diagnostic.length,
2157+
code: diagnostic.code
2158+
}
2159+
});
2160+
const dedupedDiagnositcs = ts.deduplicate(diagnosticsForCodeFix, ts.equalOwnProperties);
21542161

21552162
let actions: ts.CodeAction[] = undefined;
21562163

2157-
const checkedDiagnostics = ts.createMap<boolean>();
2158-
2159-
for (const diagnostic of diagnostics) {
2164+
for (const diagnostic of dedupedDiagnositcs) {
21602165

21612166
if (errorCode && errorCode !== diagnostic.code) {
21622167
continue;
21632168
}
21642169

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-
21792170
const newActions = this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.length, [diagnostic.code]);
21802171
if (newActions && newActions.length) {
21812172
actions = actions ? actions.concat(newActions) : newActions;

src/services/services.ts

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

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

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 => {
1691+
forEach(deduplicate(errorCodes), error => {
16981692
cancellationToken.throwIfCancellationRequested();
16991693

17001694
const context = {

0 commit comments

Comments
 (0)