diff --git a/extensions/typescript-language-features/src/features/quickFix.ts b/extensions/typescript-language-features/src/features/quickFix.ts index 16b2069c23295768c10c380ede0657db70d9749e..ec98820c7f59c694ffbc02b5b5a51d231e7ac7a6 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; }