diff --git a/extensions/typescript-language-features/src/features/autoFix.ts b/extensions/typescript-language-features/src/features/autoFix.ts index c0d8b581774..7dfd96d3d23 100644 --- a/extensions/typescript-language-features/src/features/autoFix.ts +++ b/extensions/typescript-language-features/src/features/autoFix.ts @@ -38,7 +38,7 @@ class TypeScriptAutoFixProvider implements vscode.CodeActionProvider { context: vscode.CodeActionContext, token: vscode.CancellationToken ): Promise { - if (!context.only || !context.only.contains(vscode.CodeActionKind.Source)) { + if (!context.only || !(context.only.contains(vscode.CodeActionKind.SourceAutoFix) || vscode.CodeActionKind.SourceAutoFix.contains(context.only))) { return undefined; } diff --git a/extensions/typescript-language-features/src/features/organizeImports.ts b/extensions/typescript-language-features/src/features/organizeImports.ts index 7a4cdf7bc46..55458284c20 100644 --- a/extensions/typescript-language-features/src/features/organizeImports.ts +++ b/extensions/typescript-language-features/src/features/organizeImports.ts @@ -82,14 +82,14 @@ export class OrganizeImportsCodeActionProvider implements vscode.CodeActionProvi return []; } - if (!context.only || !context.only.contains(vscode.CodeActionKind.SourceOrganizeImports)) { + if (!context.only || !(context.only.contains(vscode.CodeActionKind.SourceOrganizeImports) || vscode.CodeActionKind.SourceOrganizeImports.contains(context.only))) { return []; } this.fileConfigManager.ensureConfigurationForDocument(document, token); const action = new vscode.CodeAction( - localize('oraganizeImportsAction.title', "Organize Imports"), + localize('organizeImportsAction.title', "Organize Imports"), vscode.CodeActionKind.SourceOrganizeImports); action.command = { title: '', command: OrganizeImportsCommand.Id, arguments: [file] }; return [action]; diff --git a/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts b/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts index 15ee58b4855..3e233c987cf 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts @@ -318,13 +318,22 @@ class CodeActionOnParticipant implements ISaveParticipant { const timeout = this._configurationService.getValue('editor.codeActionsOnSaveTimeout', settingsOverrides); - return new Promise((resolve, reject) => { - setTimeout(() => reject(localize('codeActionsOnSave.didTimeout', "Aborted codeActionsOnSave after {0}ms", timeout)), timeout); - this.getActionsToRun(model, codeActionsOnSave).then(resolve); - }).then(actionsToRun => { - // Failure to apply a code action should not block other on save actions - return this.applyCodeActions(actionsToRun).catch(() => undefined); - }); + return Promise.race([ + new Promise((_resolve, reject) => + setTimeout(() => reject(localize('codeActionsOnSave.didTimeout', "Aborted codeActionsOnSave after {0}ms", timeout)), timeout)), + this.applyOnSaveActions(model, codeActionsOnSave) + ]).then(() => undefined); + } + + private async applyOnSaveActions(model: ITextModel, codeActionsOnSave: CodeActionKind[]): Promise { + for (const codeActionKind of codeActionsOnSave) { + const actionsToRun = await this.getActionsToRun(model, codeActionKind); + try { + await this.applyCodeActions(actionsToRun); + } catch { + // Failure to apply a code action should not block other on save actions + } + } } private async applyCodeActions(actionsToRun: CodeAction[]) { @@ -333,13 +342,11 @@ class CodeActionOnParticipant implements ISaveParticipant { } } - private async getActionsToRun(model: ITextModel, codeActionsOnSave: CodeActionKind[]) { - const actions = await getCodeActions(model, model.getFullModelRange(), { + private getActionsToRun(model: ITextModel, codeActionKind: CodeActionKind) { + return getCodeActions(model, model.getFullModelRange(), { type: 'auto', - filter: { kind: CodeActionKind.Source, includeSourceActions: true }, + filter: { kind: codeActionKind, includeSourceActions: true }, }); - const actionsToRun = actions.filter(returnedAction => returnedAction.kind && codeActionsOnSave.some(onSaveKind => onSaveKind.contains(returnedAction.kind))); - return actionsToRun; } }