未验证 提交 067f46af 编写于 作者: A Alex Ross 提交者: GitHub

Support for automatic tasks (#63695)

Fixes #17147
上级 8bcb65bb
......@@ -11,7 +11,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
import { IDisposable } from 'vs/base/common/lifecycle';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { Task, ContributedTask, CustomTask, TaskSet, TaskSorter, TaskEvent, TaskIdentifier } from 'vs/workbench/parts/tasks/common/tasks';
import { Task, ContributedTask, CustomTask, TaskSet, TaskSorter, TaskEvent, TaskIdentifier, ConfiguringTask } from 'vs/workbench/parts/tasks/common/tasks';
import { ITaskSummary, TaskTerminateResponse, TaskSystemInfo } from 'vs/workbench/parts/tasks/common/taskSystem';
import { IStringDictionary } from 'vs/base/common/collections';
......@@ -38,6 +38,18 @@ export interface TaskFilter {
type?: string;
}
interface WorkspaceTaskResult {
set: TaskSet;
configurations: {
byIdentifier: IStringDictionary<ConfiguringTask>;
};
hasErrors: boolean;
}
export interface WorkspaceFolderTaskResult extends WorkspaceTaskResult {
workspaceFolder: IWorkspaceFolder;
}
export interface ITaskService {
_serviceBrand: any;
onDidStateChange: Event<TaskEvent>;
......@@ -54,6 +66,7 @@ export interface ITaskService {
terminate(task: Task): TPromise<TaskTerminateResponse>;
terminateAll(): TPromise<TaskTerminateResponse[]>;
tasks(filter?: TaskFilter): TPromise<Task[]>;
getWorkspaceTasks(): TPromise<Map<string, WorkspaceFolderTaskResult>>;
/**
* @param alias The task's name, label or defined identifier.
*/
......
......@@ -176,21 +176,6 @@ export namespace PanelKind {
}
}
export namespace RerunBehavior {
export function fromString(value: string | undefined): RerunBehavior {
if (!value) {
return RerunBehavior.reevaluate;
}
switch (value.toLowerCase()) {
case 'useevaluated':
return RerunBehavior.useEvaluated;
case 'reevaulate':
default:
return RerunBehavior.reevaluate;
}
}
}
export interface PresentationOptions {
/**
* Controls whether the task output is reveal in the user interface.
......@@ -441,8 +426,14 @@ export enum RerunBehavior {
useEvaluated = 2,
}
export enum RunOnOptions {
default = 1,
folderOpen = 2
}
export interface RunOptions {
rerunBehavior?: RerunBehavior;
runOn?: RunOnOptions;
}
export interface CommonTask {
......
......@@ -281,16 +281,20 @@ const identifier: IJSONSchema = {
deprecationMessage: nls.localize('JsonSchema.tasks.identifier.deprecated', 'User defined identifiers are deprecated. For custom task use the name as a reference and for tasks provided by extensions use their defined task identifier.')
};
const rerunBehavior: IJSONSchema = {
type: 'string',
enum: ['reevauate', 'useEvaluated'],
description: nls.localize('JsonSchema.tasks.rerunBehavior', 'The task\'s behavior on rerun')
};
const runOptions: IJSONSchema = {
type: 'object',
properties: {
rerunBehavior: Objects.deepClone(rerunBehavior),
rerunBehavior: {
type: 'string',
enum: ['reevauate', 'useEvaluated'],
description: nls.localize('JsonSchema.tasks.rerunBehavior', 'The task\'s behavior on rerun')
},
runOn: {
type: 'string',
enum: ['default', 'folderOpen'],
description: nls.localize('JsonSchema.tasks.runOn', 'Configures when the task should be run. If set to folderOpen, then the task will be run automatically when the folder is opened.'),
default: 'default'
},
},
description: nls.localize('JsonSchema.tasks.runOptions', 'The task\'s run related options')
};
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Disposable } from 'vs/base/common/lifecycle';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { ITaskService } from 'vs/workbench/parts/tasks/common/taskService';
import { forEach } from 'vs/base/common/collections';
import { RunOnOptions } from 'vs/workbench/parts/tasks/common/tasks';
export class RunAutomaticTasks extends Disposable implements IWorkbenchContribution {
constructor(
@ITaskService taskService: ITaskService) {
super();
taskService.getWorkspaceTasks().then(workspaceTaskResult => {
if (workspaceTaskResult) {
workspaceTaskResult.forEach(resultElement => {
resultElement.set.tasks.forEach(task => {
if (task.runOptions.runOn === RunOnOptions.folderOpen) {
taskService.run(task);
}
});
if (resultElement.configurations) {
forEach(resultElement.configurations.byIdentifier, (configedTask) => {
if (configedTask.value.runOptions.runOn === RunOnOptions.folderOpen) {
taskService.getTask(resultElement.workspaceFolder, configedTask.value._id, true).then(task => {
if (task) {
taskService.run(task);
}
});
}
});
}
});
}
});
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@ import { LinkedMap, Touch } from 'vs/base/common/map';
import { OcticonLabel } from 'vs/base/browser/ui/octiconLabel/octiconLabel';
import { Registry } from 'vs/platform/registry/common/platform';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IMarkerService, MarkerStatistics } from 'vs/platform/markers/common/markers';
......@@ -76,7 +76,7 @@ import {
TaskEventKind, TaskSet, TaskGroup, GroupType, ExecutionEngine, JsonSchemaVersion, TaskSourceKind,
TaskSorter, TaskIdentifier, KeyedTaskIdentifier, TASK_RUNNING_STATE, RerunBehavior
} from 'vs/workbench/parts/tasks/common/tasks';
import { ITaskService, ITaskProvider, ProblemMatcherRunOptions, CustomizationProperties, TaskFilter } from 'vs/workbench/parts/tasks/common/taskService';
import { ITaskService, ITaskProvider, ProblemMatcherRunOptions, CustomizationProperties, TaskFilter, WorkspaceFolderTaskResult } from 'vs/workbench/parts/tasks/common/taskService';
import { getTemplates as getTaskTemplates } from 'vs/workbench/parts/tasks/common/taskTemplates';
import { KeyedTaskIdentifier as NKeyedTaskIdentifier, TaskDefinition } from 'vs/workbench/parts/tasks/node/tasks';
......@@ -93,9 +93,14 @@ import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/
import { TaskDefinitionRegistry } from 'vs/workbench/parts/tasks/common/taskDefinitionRegistry';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { RunAutomaticTasks } from 'vs/workbench/parts/tasks/electron-browser/runAutomaticTasks';
let tasksCategory = nls.localize('tasksCategory', "Tasks");
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(RunAutomaticTasks, LifecyclePhase.Eventually);
namespace ConfigureTaskAction {
export const ID = 'workbench.action.tasks.configureTaskRunner';
export const TEXT = nls.localize('ConfigureTaskRunnerAction.label', "Configure Task");
......@@ -370,18 +375,6 @@ class ProblemReporter implements TaskConfig.IProblemReporter {
}
}
interface WorkspaceTaskResult {
set: TaskSet;
configurations: {
byIdentifier: IStringDictionary<ConfiguringTask>;
};
hasErrors: boolean;
}
interface WorkspaceFolderTaskResult extends WorkspaceTaskResult {
workspaceFolder: IWorkspaceFolder;
}
interface WorkspaceFolderConfigurationResult {
workspaceFolder: IWorkspaceFolder;
config: TaskConfig.ExternalTaskRunnerConfiguration;
......@@ -1493,7 +1486,7 @@ class TaskService extends Disposable implements ITaskService {
return result;
}
private getWorkspaceTasks(): TPromise<Map<string, WorkspaceFolderTaskResult>> {
public getWorkspaceTasks(): TPromise<Map<string, WorkspaceFolderTaskResult>> {
if (this._workspaceTasksPromise) {
return this._workspaceTasksPromise;
}
......
......@@ -121,6 +121,7 @@ export interface PresentationOptionsConfig {
export interface RunOptionsConfig {
rerunBehavior?: string;
runOn?: string;
}
export interface TaskIdentifier {
......@@ -633,6 +634,45 @@ function _freeze<T>(this: void, target: T, properties: MetaData<T, any>[]): Read
return target;
}
export namespace RerunBehavior {
export function fromString(value: string | undefined): Tasks.RerunBehavior {
if (!value) {
return Tasks.RerunBehavior.reevaluate;
}
switch (value.toLowerCase()) {
case 'useevaluated':
return Tasks.RerunBehavior.useEvaluated;
case 'reevaulate':
default:
return Tasks.RerunBehavior.reevaluate;
}
}
}
export namespace RunOnOptions {
export function fromString(value: string | undefined): Tasks.RunOnOptions {
if (!value) {
return Tasks.RunOnOptions.default;
}
switch (value.toLowerCase()) {
case 'folderopen':
return Tasks.RunOnOptions.folderOpen;
case 'default':
default:
return Tasks.RunOnOptions.default;
}
}
}
export namespace RunOptions {
export function fromConfiguration(value: RunOptionsConfig | undefined): Tasks.RunOptions {
return {
rerunBehavior: value ? RerunBehavior.fromString(value.rerunBehavior) : Tasks.RerunBehavior.reevaluate,
runOn: value ? RunOnOptions.fromString(value.runOn) : Tasks.RunOnOptions.default
};
}
}
interface ParseContext {
workspaceFolder: IWorkspaceFolder;
problemReporter: IProblemReporter;
......@@ -1295,7 +1335,7 @@ namespace ConfiguringTask {
_id: `${typeDeclaration.extensionId}.${taskIdentifier._key}`,
_source: Objects.assign({}, source, { config: configElement }),
_label: undefined,
runOptions: { rerunBehavior: external.runOptions ? Tasks.RerunBehavior.fromString(external.runOptions.rerunBehavior) : Tasks.RerunBehavior.reevaluate },
runOptions: RunOptions.fromConfiguration(external.runOptions)
};
let configuration = ConfigurationProperties.from(external, context, true);
if (configuration) {
......@@ -1355,7 +1395,7 @@ namespace CustomTask {
identifier: taskName,
hasDefinedMatchers: false,
command: undefined,
runOptions: { rerunBehavior: external.runOptions ? Tasks.RerunBehavior.fromString(external.runOptions.rerunBehavior) : Tasks.RerunBehavior.reevaluate }
runOptions: RunOptions.fromConfiguration(external.runOptions)
};
let configuration = ConfigurationProperties.from(external, context, false);
if (configuration) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册