diff --git a/extensions/typescript-language-features/src/features/organizeImports.ts b/extensions/typescript-language-features/src/features/organizeImports.ts index 2fe5f9e71d2ef5cdedfe42e1e77190599fca683f..7aa0f124d3f3aab27254669b8b563334cec56dc0 100644 --- a/extensions/typescript-language-features/src/features/organizeImports.ts +++ b/extensions/typescript-language-features/src/features/organizeImports.ts @@ -8,7 +8,6 @@ import * as nls from 'vscode-nls'; import * as Proto from '../protocol'; import { ITypeScriptServiceClient } from '../typescriptService'; import { Command, CommandManager } from '../utils/commandManager'; -import { isSupportedLanguageMode } from '../utils/languageModeIds'; import * as typeconverts from '../utils/typeConverters'; const localize = nls.loadMessageBundle(); @@ -23,21 +22,11 @@ class OrganizeImportsCommand implements Command { private readonly client: ITypeScriptServiceClient ) { } - public async execute(): Promise { + public async execute(file: string): Promise { if (!this.client.apiVersion.has280Features()) { return false; } - const editor = vscode.window.activeTextEditor; - if (!editor || !isSupportedLanguageMode(editor.document)) { - return false; - } - - const file = this.client.normalizePath(editor.document.uri); - if (!file) { - return false; - } - const args: Proto.OrganizeImportsRequestArgs = { scope: { type: 'file', @@ -69,7 +58,7 @@ export class OrganizeImportsCodeActionProvider implements vscode.CodeActionProvi }; public provideCodeActions( - _document: vscode.TextDocument, + document: vscode.TextDocument, _range: vscode.Range, _context: vscode.CodeActionContext, _token: vscode.CancellationToken @@ -78,10 +67,15 @@ export class OrganizeImportsCodeActionProvider implements vscode.CodeActionProvi return []; } + const file = this.client.normalizePath(document.uri); + if (!file) { + return []; + } + const action = new vscode.CodeAction( localize('oraganizeImportsAction.title', "Organize Imports"), vscode.CodeActionKind.SourceOrganizeImports); - action.command = { title: '', command: OrganizeImportsCommand.Id }; + action.command = { title: '', command: OrganizeImportsCommand.Id, arguments: [file] }; return [action]; } } \ No newline at end of file diff --git a/src/vs/editor/contrib/codeAction/codeActionCommands.ts b/src/vs/editor/contrib/codeAction/codeActionCommands.ts index 5d93bfa6592f97faed277093ed460ceaf2479795..bff1f08ce9d55fc46ded60698b41907096d0f3ae 100644 --- a/src/vs/editor/contrib/codeAction/codeActionCommands.ts +++ b/src/vs/editor/contrib/codeAction/codeActionCommands.ts @@ -135,7 +135,7 @@ export async function applyCodeAction( action: CodeAction, bulkEditService: IBulkEditService, commandService: ICommandService, - editor: ICodeEditor, + editor?: ICodeEditor, ) { if (action.edit) { await bulkEditService.apply(action.edit, { editor }); diff --git a/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts b/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts index 1ee118c579d83494904d207555075f4a29125f16..eb74c54ffb17ab150dfcb71b794babbe0c76266f 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts @@ -271,7 +271,6 @@ class CodeActionOnParticipant implements ISaveParticipant { constructor( @IBulkEditService private readonly _bulkEditService: IBulkEditService, @ICommandService private readonly _commandService: ICommandService, - @ICodeEditorService private readonly _codeEditorService: ICodeEditorService, @IConfigurationService private readonly _configurationService: IConfigurationService ) { } @@ -281,10 +280,6 @@ class CodeActionOnParticipant implements ISaveParticipant { } const model = editorModel.textEditorModel; - const editor = findEditor(model, this._codeEditorService); - if (!editor) { - return undefined; - } const settingsOverrides = { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.getResource() }; const setting = this._configurationService.getValue('editor.codeActionsOnSave', settingsOverrides); @@ -302,12 +297,12 @@ class CodeActionOnParticipant implements ISaveParticipant { 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 => this.applyCodeActions(actionsToRun, editor)); + }).then(actionsToRun => this.applyCodeActions(actionsToRun)); } - private async applyCodeActions(actionsToRun: CodeAction[], editor: ICodeEditor) { + private async applyCodeActions(actionsToRun: CodeAction[]) { for (const action of actionsToRun) { - await applyCodeAction(action, this._bulkEditService, this._commandService, editor); + await applyCodeAction(action, this._bulkEditService, this._commandService); } }