未验证 提交 b33b05ec 编写于 作者: E Edgar Cumbreras 提交者: GitHub

Feat: #94285 Options on saving before running tasks (#94466)

fixes #94285
Co-authored-by: NAlex Ross <alros@microsoft.com>
上级 ab42ffc4
......@@ -320,8 +320,10 @@ export interface INotificationService {
* Shows a prompt in the notification area with the provided choices. The prompt
* is non-modal. If you want to show a modal dialog instead, use `IDialogService`.
*
* @param onCancel will be called if the user closed the notification without picking
* any of the provided choices.
* @param severity the severity of the notification. Either `Info`, `Warning` or `Error`.
* @param message the message to show as status.
* @param choices options to be choosen from.
* @param options provides some optional configuration options.
*
* @returns a handle on the notification to e.g. hide it or update message, buttons, etc.
*/
......
......@@ -1402,12 +1402,52 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
}
private executeTask(task: Task, resolver: ITaskResolver): Promise<ITaskSummary> {
enum SaveBeforeRunConfigOptions {
Always = 'always',
Never = 'never',
Prompt = 'prompt'
}
const saveBeforeRunTaskConfig: SaveBeforeRunConfigOptions = this.configurationService.getValue('task.saveBeforeRun');
const execTask = async (task: Task, resolver: ITaskResolver): Promise<ITaskSummary> => {
return ProblemMatcherRegistry.onReady().then(() => {
return this.editorService.saveAll().then(() => { // make sure all dirty editors are saved
let executeResult = this.getTaskSystem().run(task, resolver);
return this.handleExecuteResult(executeResult);
});
};
const saveAllEditorsAndExecTask = async (task: Task, resolver: ITaskResolver): Promise<ITaskSummary> => {
return this.editorService.saveAll().then(() => {
return execTask(task, resolver);
});
};
const promptAsk = async (task: Task, resolver: ITaskResolver): Promise<ITaskSummary> => {
const dialogOptions = await this.dialogService.show(
Severity.Info,
nls.localize('TaskSystem.saveBeforeRun.prompt.title', 'Save all editors?'),
[nls.localize('saveBeforeRun.save', 'Save'), nls.localize('saveBeforeRun.dontSave', 'Don\'t save')],
{
detail: nls.localize('detail', "Do you want to save all editors before running the task?"),
cancelId: 1
}
);
if (dialogOptions.choice === 0) {
return saveAllEditorsAndExecTask(task, resolver);
} else {
return execTask(task, resolver);
}
};
if (saveBeforeRunTaskConfig === SaveBeforeRunConfigOptions.Never) {
return execTask(task, resolver);
} else if (saveBeforeRunTaskConfig === SaveBeforeRunConfigOptions.Prompt) {
return promptAsk(task, resolver);
} else {
return saveAllEditorsAndExecTask(task, resolver);
}
}
private async handleExecuteResult(executeResult: ITaskExecuteResult): Promise<ITaskSummary> {
......
......@@ -376,6 +376,20 @@ configurationRegistry.registerConfiguration({
type: 'boolean',
description: nls.localize('task.quickOpen.skip', "Controls whether the task quick pick is skipped when there is only one task to pick from."),
default: false
}
},
'task.saveBeforeRun': {
markdownDescription: nls.localize(
'task.saveBeforeRun',
'Configures whether all editor will be saved before running a task.'
),
type: 'string',
enum: ['always', 'never', 'prompt'],
enumDescriptions: [
nls.localize('task.saveBeforeRun.always', 'Always saves all editors before running.'),
nls.localize('task.saveBeforeRun.never', 'Never saves editors before running.'),
nls.localize('task.SaveBeforeRun.prompt', 'Prompts whether to save editors before running.'),
],
default: 'always',
},
}
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册