From 6c2c2f8f3fb92d55c138262c7c20587d68673f61 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 14 Feb 2017 11:30:19 -0800 Subject: [PATCH] use deduplicate --- src/harness/fourslash.ts | 31 +++++++++++-------------------- src/services/services.ts | 8 +------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 62770a96e7a..458eaeb2c29 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2150,30 +2150,21 @@ namespace FourSlash { * @param fileName Path to file where error should be retrieved from. */ private getCodeFixActions(fileName: string, errorCode?: number): ts.CodeAction[] { - 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({ + const diagnosticsForCodeFix = this.getDiagnostics(fileName).map(diagnostic => { + return { 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 dedupedDiagnositcs = ts.deduplicate(diagnosticsForCodeFix, ts.equalOwnProperties); + + let actions: ts.CodeAction[] = undefined; + + for (const diagnostic of dedupedDiagnositcs) { + + if (errorCode && errorCode !== diagnostic.code) { + continue; } const newActions = this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.length, [diagnostic.code]); diff --git a/src/services/services.ts b/src/services/services.ts index 35588a1902a..2b1d414f4c3 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1688,13 +1688,7 @@ namespace ts { let allFixes: CodeAction[] = []; - // De-duplicate error codes. - const errorCodeSet: number[] = []; - for (const code of errorCodes) { - errorCodeSet[code] = code; - } - - forEach(errorCodeSet, error => { + forEach(deduplicate(errorCodes), error => { cancellationToken.throwIfCancellationRequested(); const context = {