mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 17:19:01 +01:00
De-duplicate "fix all" quick fixes across requests for multiple diagnostics in selection range
For https://github.com/Microsoft/typescript-tslint-plugin/issues/49
This commit is contained in:
@@ -128,8 +128,8 @@ class DiagnosticsSet {
|
||||
}
|
||||
|
||||
class CodeActionSet {
|
||||
private _actions = new Set<vscode.CodeAction>();
|
||||
private _fixAllActions = new Map<{}, vscode.CodeAction>();
|
||||
private readonly _actions = new Set<vscode.CodeAction>();
|
||||
private readonly _fixAllActions = new Map<{}, vscode.CodeAction>();
|
||||
|
||||
public get values(): Iterable<vscode.CodeAction> {
|
||||
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<Iterable<vscode.CodeAction>> {
|
||||
results: CodeActionSet,
|
||||
token: vscode.CancellationToken,
|
||||
): Promise<CodeActionSet> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user