提交 90da6715 编写于 作者: D Dirk Baeumer

Fixes #3110: Expose ConfigureTaskSystem action

上级 7082af62
......@@ -5,6 +5,7 @@
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { Action } from 'vs/base/common/actions';
import { IEventEmitter } from 'vs/base/common/eventEmitter';
import { TerminateResponse } from 'vs/base/common/processes';
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
......@@ -23,6 +24,7 @@ export namespace TaskServiceEvents {
export interface ITaskService extends IEventEmitter {
serviceId: ServiceIdentifier<any>;
configureAction(): Action;
build(): TPromise<ITaskSummary>;
rebuild(): TPromise<ITaskSummary>;
clean(): TPromise<ITaskSummary>;
......
......@@ -11,12 +11,23 @@ import { IEventEmitter } from 'vs/base/common/eventEmitter';
import { ProblemMatcher } from 'vs/platform/markers/common/problemMatcher';
export enum TaskErrors {
NotConfigured,
RunningTask,
NoBuildTask,
NoTestTask,
ConfigValidationError,
TaskNotFound,
NoValidTaskRunner,
UnknownError
}
export class TaskError {
public severity:Severity;
public message:string;
public code:number;
public severity: Severity;
public message: string;
public code: TaskErrors;
constructor(severity:Severity, message:string, code:number = -1) {
constructor(severity: Severity, message: string, code: TaskErrors) {
this.severity = severity;
this.message = message;
this.code = code;
......
......@@ -60,7 +60,7 @@ import { SystemVariables } from 'vs/workbench/parts/lib/node/systemVariables';
import { ITextFileService, EventType } from 'vs/workbench/parts/files/common/files';
import { IOutputService, IOutputChannelRegistry, Extensions as OutputExt } from 'vs/workbench/parts/output/common/output';
import { ITaskSystem, ITaskSummary, ITaskRunResult, TaskError, TaskConfiguration, TaskDescription, TaskSystemEvents } from 'vs/workbench/parts/tasks/common/taskSystem';
import { ITaskSystem, ITaskSummary, ITaskRunResult, TaskError, TaskErrors, TaskConfiguration, TaskDescription, TaskSystemEvents } from 'vs/workbench/parts/tasks/common/taskSystem';
import { ITaskService, TaskServiceEvents } from 'vs/workbench/parts/tasks/common/taskService';
import { LanguageServiceTaskSystem, LanguageServiceTaskConfiguration } from 'vs/workbench/parts/tasks/common/languageServiceTaskSystem';
......@@ -570,7 +570,7 @@ class TaskService extends EventEmitter implements ITaskService {
return configPromise.then((config) => {
if (!config) {
this._taskSystemPromise = null;
throw new TaskError(Severity.Info, nls.localize('TaskSystem.noConfiguration', 'No task runner configured.'), 1);
throw new TaskError(Severity.Info, nls.localize('TaskSystem.noConfiguration', 'No task runner configured.'), TaskErrors.NotConfigured);
}
let result: ITaskSystem = null;
if (config.buildSystem === 'service') {
......@@ -580,7 +580,7 @@ class TaskService extends EventEmitter implements ITaskService {
}
if (result === null) {
this._taskSystemPromise = null;
throw new TaskError(Severity.Info, nls.localize('TaskSystem.noBuildType', "No valid task runner configured. Supported task runners are 'service' and 'program'."));
throw new TaskError(Severity.Info, nls.localize('TaskSystem.noBuildType', "No valid task runner configured. Supported task runners are 'service' and 'program'."), TaskErrors.NoValidTaskRunner);
}
this.taskSystemListeners.push(result.addListener(TaskSystemEvents.Active, (event) => this.emit(TaskServiceEvents.Active, event)));
this.taskSystemListeners.push(result.addListener(TaskSystemEvents.Inactive, (event) => this.emit(TaskServiceEvents.Inactive, event)));
......@@ -618,6 +618,12 @@ class TaskService extends EventEmitter implements ITaskService {
return ProcessRunnerDetector.supports(config.command);
}
public configureAction(): Action {
return new ConfigureTaskRunnerAction(ConfigureTaskRunnerAction.ID, ConfigureTaskRunnerAction.TEXT,
this.configurationService, this.editorService, this.fileService, this.contextService,
this.outputService, this.messageService);
}
public build(): TPromise<ITaskSummary> {
return this.executeTarget(taskSystem => taskSystem.build());
}
......@@ -634,11 +640,11 @@ class TaskService extends EventEmitter implements ITaskService {
return this.executeTarget(taskSystem => taskSystem.runTest());
}
public run(taskIdentifier:string): TPromise<ITaskSummary> {
public run(taskIdentifier: string): TPromise<ITaskSummary> {
return this.executeTarget(taskSystem => taskSystem.run(taskIdentifier));
}
private executeTarget(fn:(taskSystem:ITaskSystem) => ITaskRunResult): TPromise<ITaskSummary> {
private executeTarget(fn: (taskSystem: ITaskSystem) => ITaskRunResult): TPromise<ITaskSummary> {
return this.textFileService.saveAll().then((value) => {
return this.taskSystemPromise.
then((taskSystem) => {
......@@ -646,7 +652,7 @@ class TaskService extends EventEmitter implements ITaskService {
if (!active) {
return fn(taskSystem);
} else {
throw new TaskError(Severity.Warning, nls.localize('TaskSystem.active', 'There is an active running task right now. Terminate it first before executing another task.'), 2);
throw new TaskError(Severity.Warning, nls.localize('TaskSystem.active', 'There is an active running task right now. Terminate it first before executing another task.'), TaskErrors.RunningTask);
}
});
}).
......@@ -739,9 +745,11 @@ class TaskService extends EventEmitter implements ITaskService {
let showOutput = true;
if (err instanceof TaskError) {
let buildError = <TaskError>err;
if (buildError.code === 1 || buildError.code === 2) {
let needsConfig = buildError.code === TaskErrors.NotConfigured || buildError.code === TaskErrors.NoBuildTask || buildError.code === TaskErrors.NoTestTask;
let needsTerminate = buildError.code === TaskErrors.RunningTask;
if (needsConfig || needsTerminate) {
let closeAction = new CloseMessageAction();
let action = buildError.code === 1
let action = needsConfig
? new ConfigureTaskRunnerAction(ConfigureTaskRunnerAction.ID, ConfigureTaskRunnerAction.TEXT, this.configurationService, this.editorService, this.fileService, this.contextService, this.outputService, this.messageService)
: new TerminateAction(TerminateAction.ID, TerminateAction.TEXT, this, this.telemetryService);
......
......@@ -26,7 +26,7 @@ import { ProblemMatcher } from 'vs/platform/markers/common/problemMatcher';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { StartStopProblemCollector, WatchingProblemCollector, ProblemCollectorEvents } from 'vs/workbench/parts/tasks/common/problemCollectors';
import { ITaskSystem, ITaskSummary, ITaskRunResult, TaskError, TaskRunnerConfiguration, TaskDescription, CommandOptions, ShowOutput, TelemetryEvent, Triggers, TaskSystemEvents, TaskEvent, TaskType } from 'vs/workbench/parts/tasks/common/taskSystem';
import { ITaskSystem, ITaskSummary, ITaskRunResult, TaskError, TaskErrors, TaskRunnerConfiguration, TaskDescription, CommandOptions, ShowOutput, TelemetryEvent, Triggers, TaskSystemEvents, TaskEvent, TaskType } from 'vs/workbench/parts/tasks/common/taskSystem';
import * as FileConfig from './processRunnerConfiguration';
export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
......@@ -83,7 +83,7 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
public build(): ITaskRunResult {
if (!this.defaultBuildTaskIdentifier) {
throw new TaskError(Severity.Info, nls.localize('TaskRunnerSystem.noBuildTask', 'No build task configured.'), 1);
throw new TaskError(Severity.Info, nls.localize('TaskRunnerSystem.noBuildTask', 'No build task configured.'), TaskErrors.NoBuildTask);
}
return this.executeTask(this.defaultBuildTaskIdentifier, Triggers.shortcut);
}
......@@ -98,7 +98,7 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
public runTest(): ITaskRunResult {
if (!this.defaultTestTaskIdentifier) {
throw new TaskError(Severity.Info, nls.localize('TaskRunnerSystem.noTestTask', 'No test task configured.'), 1);
throw new TaskError(Severity.Info, nls.localize('TaskRunnerSystem.noTestTask', 'No test task configured.'), TaskErrors.NoTestTask);
}
return this.executeTask(this.defaultTestTaskIdentifier, Triggers.shortcut);
}
......@@ -147,11 +147,11 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
private executeTask(taskIdentifier: string, trigger: string = Triggers.command): ITaskRunResult {
if (this.validationStatus.isFatal()) {
throw new TaskError(Severity.Error, nls.localize('TaskRunnerSystem.fatalError', 'The provided task configuration has validation errors. See tasks output log for details.'));
throw new TaskError(Severity.Error, nls.localize('TaskRunnerSystem.fatalError', 'The provided task configuration has validation errors. See tasks output log for details.'), TaskErrors.ConfigValidationError);
}
let task = this.configuration.tasks[taskIdentifier];
if (!task) {
throw new TaskError(Severity.Info, nls.localize('TaskRunnerSystem.norebuild', 'No task to execute found.'));
throw new TaskError(Severity.Info, nls.localize('TaskRunnerSystem.norebuild', 'No task to execute found.'), TaskErrors.TaskNotFound);
}
let telemetryEvent: TelemetryEvent = {
trigger: trigger,
......@@ -177,10 +177,10 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
} else if (err instanceof Error) {
let error = <Error>err;
this.outputService.append(this.outputChannel, error.message);
throw new TaskError(Severity.Error, error.message);
throw new TaskError(Severity.Error, error.message, TaskErrors.UnknownError);
} else {
this.outputService.append(this.outputChannel, err.toString());
throw new TaskError(Severity.Error, nls.localize('TaskRunnerSystem.unknownError', 'A unknown error has occurred while executing a task. See task output log for details.'));
throw new TaskError(Severity.Error, nls.localize('TaskRunnerSystem.unknownError', 'A unknown error has occurred while executing a task. See task output log for details.'), TaskErrors.UnknownError);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册