From 4f8d546aa7b0f18f7eabdc4eefe627558364f785 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 21 Jan 2019 16:02:17 -0800 Subject: [PATCH] De-duplicate "fix all" quick fixes across requests for multiple diagnostics in selection range For https://github.com/Microsoft/typescript-tslint-plugin/issues/49 --- .../src/features/quickFix.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/extensions/typescript-language-features/src/features/quickFix.ts b/extensions/typescript-language-features/src/features/quickFix.ts index 16b2069c232..ec98820c7f5 100644 --- a/extensions/typescript-language-features/src/features/quickFix.ts +++ b/extensions/typescript-language-features/src/features/quickFix.ts @@ -128,8 +128,8 @@ class DiagnosticsSet { } class CodeActionSet { - private _actions = new Set(); - private _fixAllActions = new Map<{}, vscode.CodeAction>(); + private readonly _actions = new Set(); + private readonly _fixAllActions = new Map<{}, vscode.CodeAction>(); public get values(): Iterable { return this._actions; @@ -142,7 +142,7 @@ class CodeActionSet { public addFixAllAction(fixId: {}, action: vscode.CodeAction) { const existing = this._fixAllActions.get(fixId); if (existing) { - // reinsert action at back + // reinsert action at back of actions list this._actions.delete(existing); } this.addAction(action); @@ -216,33 +216,33 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider { await this.formattingConfigurationManager.ensureConfigurationForDocument(document, token); - const results: vscode.CodeAction[] = []; + const results = new CodeActionSet(); for (const diagnostic of fixableDiagnostics.values) { - results.push(...await this.getFixesForDiagnostic(document, file, diagnostic, token)); + await this.getFixesForDiagnostic(document, file, diagnostic, results, token); } - return results; + return Array.from(results.values); } private async getFixesForDiagnostic( document: vscode.TextDocument, file: string, diagnostic: vscode.Diagnostic, - token: vscode.CancellationToken - ): Promise> { + results: CodeActionSet, + token: vscode.CancellationToken, + ): Promise { const args: Proto.CodeFixRequestArgs = { ...typeConverters.Range.toFileRangeRequestArgs(file, diagnostic.range), errorCodes: [+(diagnostic.code!)] }; const response = await this.client.execute('getCodeFixes', args, token); if (response.type !== 'response' || !response.body) { - return []; + return results; } - const results = new CodeActionSet(); for (const tsCodeFix of response.body) { this.addAllFixesForTsCodeAction(results, document, file, diagnostic, tsCodeFix as Proto.CodeFixAction); } - return results.values; + return results; } private addAllFixesForTsCodeAction( @@ -282,7 +282,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider { diagnostic: vscode.Diagnostic, tsAction: Proto.CodeFixAction, ): CodeActionSet { - if (!tsAction.fixId || this.client.apiVersion.lt(API.v270) || results.hasFixAllAction(results)) { + if (!tsAction.fixId || this.client.apiVersion.lt(API.v270) || results.hasFixAllAction(tsAction.fixId)) { return results; } -- GitLab