Skip to content

Commit b33b05e

Browse files
Edgar Cumbrerasalexr00
andauthored
Feat: microsoft#94285 Options on saving before running tasks (microsoft#94466)
fixes microsoft#94285 Co-authored-by: Alex Ross <alros@microsoft.com>
1 parent ab42ffc commit b33b05e

3 files changed

Lines changed: 62 additions & 6 deletions

File tree

src/vs/platform/notification/common/notification.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,10 @@ export interface INotificationService {
320320
* Shows a prompt in the notification area with the provided choices. The prompt
321321
* is non-modal. If you want to show a modal dialog instead, use `IDialogService`.
322322
*
323-
* @param onCancel will be called if the user closed the notification without picking
324-
* any of the provided choices.
323+
* @param severity the severity of the notification. Either `Info`, `Warning` or `Error`.
324+
* @param message the message to show as status.
325+
* @param choices options to be choosen from.
326+
* @param options provides some optional configuration options.
325327
*
326328
* @returns a handle on the notification to e.g. hide it or update message, buttons, etc.
327329
*/

src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,12 +1402,52 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
14021402
}
14031403

14041404
private executeTask(task: Task, resolver: ITaskResolver): Promise<ITaskSummary> {
1405-
return ProblemMatcherRegistry.onReady().then(() => {
1406-
return this.editorService.saveAll().then(() => { // make sure all dirty editors are saved
1405+
enum SaveBeforeRunConfigOptions {
1406+
Always = 'always',
1407+
Never = 'never',
1408+
Prompt = 'prompt'
1409+
}
1410+
1411+
const saveBeforeRunTaskConfig: SaveBeforeRunConfigOptions = this.configurationService.getValue('task.saveBeforeRun');
1412+
1413+
const execTask = async (task: Task, resolver: ITaskResolver): Promise<ITaskSummary> => {
1414+
return ProblemMatcherRegistry.onReady().then(() => {
14071415
let executeResult = this.getTaskSystem().run(task, resolver);
14081416
return this.handleExecuteResult(executeResult);
14091417
});
1410-
});
1418+
};
1419+
1420+
const saveAllEditorsAndExecTask = async (task: Task, resolver: ITaskResolver): Promise<ITaskSummary> => {
1421+
return this.editorService.saveAll().then(() => {
1422+
return execTask(task, resolver);
1423+
});
1424+
};
1425+
1426+
const promptAsk = async (task: Task, resolver: ITaskResolver): Promise<ITaskSummary> => {
1427+
const dialogOptions = await this.dialogService.show(
1428+
Severity.Info,
1429+
nls.localize('TaskSystem.saveBeforeRun.prompt.title', 'Save all editors?'),
1430+
[nls.localize('saveBeforeRun.save', 'Save'), nls.localize('saveBeforeRun.dontSave', 'Don\'t save')],
1431+
{
1432+
detail: nls.localize('detail', "Do you want to save all editors before running the task?"),
1433+
cancelId: 1
1434+
}
1435+
);
1436+
1437+
if (dialogOptions.choice === 0) {
1438+
return saveAllEditorsAndExecTask(task, resolver);
1439+
} else {
1440+
return execTask(task, resolver);
1441+
}
1442+
};
1443+
1444+
if (saveBeforeRunTaskConfig === SaveBeforeRunConfigOptions.Never) {
1445+
return execTask(task, resolver);
1446+
} else if (saveBeforeRunTaskConfig === SaveBeforeRunConfigOptions.Prompt) {
1447+
return promptAsk(task, resolver);
1448+
} else {
1449+
return saveAllEditorsAndExecTask(task, resolver);
1450+
}
14111451
}
14121452

14131453
private async handleExecuteResult(executeResult: ITaskExecuteResult): Promise<ITaskSummary> {

src/vs/workbench/contrib/tasks/browser/task.contribution.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,20 @@ configurationRegistry.registerConfiguration({
376376
type: 'boolean',
377377
description: nls.localize('task.quickOpen.skip', "Controls whether the task quick pick is skipped when there is only one task to pick from."),
378378
default: false
379-
}
379+
},
380+
'task.saveBeforeRun': {
381+
markdownDescription: nls.localize(
382+
'task.saveBeforeRun',
383+
'Configures whether all editor will be saved before running a task.'
384+
),
385+
type: 'string',
386+
enum: ['always', 'never', 'prompt'],
387+
enumDescriptions: [
388+
nls.localize('task.saveBeforeRun.always', 'Always saves all editors before running.'),
389+
nls.localize('task.saveBeforeRun.never', 'Never saves editors before running.'),
390+
nls.localize('task.SaveBeforeRun.prompt', 'Prompts whether to save editors before running.'),
391+
],
392+
default: 'always',
393+
},
380394
}
381395
});

0 commit comments

Comments
 (0)