mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
Task query and execution polish
This commit is contained in:
@@ -17,7 +17,7 @@ import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspac
|
||||
|
||||
import {
|
||||
ContributedTask, ExtensionTaskSourceTransfer, TaskIdentifier, TaskExecution, Task, TaskEvent, TaskEventKind,
|
||||
PresentationOptions, CommandOptions, CommandConfiguration, RuntimeType, CustomTask, TaskScope, TaskSource, TaskSourceKind, ExtensionTaskSource
|
||||
PresentationOptions, CommandOptions, CommandConfiguration, RuntimeType, CustomTask, TaskScope, TaskSource, TaskSourceKind, ExtensionTaskSource, RevealKind, PanelKind
|
||||
} from 'vs/workbench/parts/tasks/common/tasks';
|
||||
import { ITaskService } from 'vs/workbench/parts/tasks/common/taskService';
|
||||
|
||||
@@ -35,11 +35,13 @@ namespace TaskExecutionDTO {
|
||||
export function from(value: TaskExecution): TaskExecutionDTO {
|
||||
return {
|
||||
id: value.id,
|
||||
task: TaskDTO.from(value.task)
|
||||
};
|
||||
}
|
||||
export function to(value: TaskExecutionDTO, workspace: IWorkspaceContextService): TaskExecution {
|
||||
return {
|
||||
id: value.id,
|
||||
task: TaskDTO.to(value.task, workspace)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -303,6 +305,8 @@ namespace TaskDTO {
|
||||
return undefined;
|
||||
}
|
||||
command.presentation = TaskPresentationOptionsDTO.to(task.presentationOptions);
|
||||
command.presentation = Objects.assign(command.presentation || {}, { echo: true, reveal: RevealKind.Always, focus: false, panel: PanelKind.Shared });
|
||||
|
||||
let source = TaskSourceDTO.to(task.source, workspace);
|
||||
|
||||
let label = nls.localize('task.label', '{0}: {1}', source.label, task.name);
|
||||
@@ -403,7 +407,8 @@ export class MainThreadTask implements MainThreadTaskShape {
|
||||
this._taskService.getTask(workspaceFolder, value.id, true).then((task: Task) => {
|
||||
this._taskService.run(task);
|
||||
let result: TaskExecutionDTO = {
|
||||
id: value.id
|
||||
id: value.id,
|
||||
task: TaskDTO.from(task)
|
||||
};
|
||||
resolve(result);
|
||||
}, (error) => {
|
||||
@@ -413,19 +418,19 @@ export class MainThreadTask implements MainThreadTaskShape {
|
||||
let task = TaskDTO.to(value, this._workspaceContextServer);
|
||||
this._taskService.run(task);
|
||||
let result: TaskExecutionDTO = {
|
||||
id: task._id
|
||||
id: task._id,
|
||||
task: TaskDTO.from(task)
|
||||
};
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public $terminateTask(value: TaskExecutionDTO): TPromise<void> {
|
||||
let execution: TaskExecution = TaskExecutionDTO.to(value, this._workspaceContextServer);
|
||||
public $terminateTask(id: string): TPromise<void> {
|
||||
return new TPromise<void>((resolve, reject) => {
|
||||
this._taskService.getActiveTasks().then((tasks) => {
|
||||
for (let task of tasks) {
|
||||
if (execution.id === task._id) {
|
||||
if (id === task._id) {
|
||||
this._taskService.terminate(task).then((value) => {
|
||||
resolve(undefined);
|
||||
}, (error) => {
|
||||
|
||||
@@ -517,18 +517,21 @@ export function createApiFactory(
|
||||
registerTaskProvider: (type: string, provider: vscode.TaskProvider) => {
|
||||
return extHostTask.registerTaskProvider(extension, provider);
|
||||
},
|
||||
fetchTasks: proposedApiFunction(extension, (): Thenable<vscode.Task[]> => {
|
||||
// fetchTasks: proposedApiFunction(extension, (): Thenable<vscode.Task[]> => {
|
||||
// return extHostTask.executeTaskProvider();
|
||||
// }),
|
||||
// executeTask: proposedApiFunction(extension, (task: vscode.Task): Thenable<vscode.TaskExecution> => {
|
||||
// return extHostTask.executeTask(extension, task);
|
||||
// }),
|
||||
fetchTasks: (): Thenable<vscode.Task[]> => {
|
||||
return extHostTask.executeTaskProvider();
|
||||
}),
|
||||
executeTask: proposedApiFunction(extension, (task: vscode.Task): Thenable<vscode.TaskExecution> => {
|
||||
},
|
||||
executeTask: (task: vscode.Task): Thenable<vscode.TaskExecution> => {
|
||||
return extHostTask.executeTask(extension, task);
|
||||
}),
|
||||
},
|
||||
onDidStartTask: (listeners, thisArgs?, disposables?) => {
|
||||
return extHostTask.onDidStartTask(listeners, thisArgs, disposables);
|
||||
},
|
||||
terminateTask: proposedApiFunction(extension, (task: vscode.TaskExecution): void => {
|
||||
extHostTask.terminateTask(task);
|
||||
}),
|
||||
onDidEndTask: (listeners, thisArgs?, disposables?) => {
|
||||
return extHostTask.onDidEndTask(listeners, thisArgs, disposables);
|
||||
},
|
||||
|
||||
@@ -391,7 +391,7 @@ export interface MainThreadTaskShape extends IDisposable {
|
||||
$registerTaskProvider(handle: number): TPromise<void>;
|
||||
$executeTaskProvider(): TPromise<TaskDTO[]>;
|
||||
$executeTask(task: TaskHandleDTO | TaskDTO): TPromise<TaskExecutionDTO>;
|
||||
$terminateTask(task: TaskExecutionDTO): TPromise<void>;
|
||||
$terminateTask(id: string): TPromise<void>;
|
||||
$unregisterTaskProvider(handle: number): TPromise<void>;
|
||||
}
|
||||
|
||||
|
||||
@@ -613,6 +613,7 @@ namespace TaskDTO {
|
||||
if (!execution || !definition || !scope) {
|
||||
return undefined;
|
||||
}
|
||||
let group = (value.group as types.TaskGroup) ? (value.group as types.TaskGroup).id : undefined;
|
||||
let result: TaskDTO = {
|
||||
_id: (value as types.Task)._id,
|
||||
definition,
|
||||
@@ -624,7 +625,7 @@ namespace TaskDTO {
|
||||
},
|
||||
execution,
|
||||
isBackground: value.isBackground,
|
||||
group: (value.group as types.TaskGroup).id,
|
||||
group: group,
|
||||
presentationOptions: TaskPresentationOptionsDTO.from(value.presentationOptions),
|
||||
problemMatchers: value.problemMatchers,
|
||||
hasDefinedMatchers: (value as types.Task).hasDefinedMatchers
|
||||
@@ -675,17 +676,26 @@ namespace TaskDTO {
|
||||
}
|
||||
|
||||
class TaskExecutionImpl implements vscode.TaskExecution {
|
||||
constructor(readonly _id: string) {
|
||||
constructor(readonly _id: string, private readonly _task: vscode.Task, private readonly _tasks: ExtHostTask) {
|
||||
}
|
||||
|
||||
get task(): vscode.Task {
|
||||
return this._task;
|
||||
}
|
||||
|
||||
public terminate(): void {
|
||||
this._tasks.terminateTask(this);
|
||||
}
|
||||
}
|
||||
|
||||
namespace TaskExecutionDTO {
|
||||
export function to(value: TaskExecutionDTO): vscode.TaskExecution {
|
||||
return new TaskExecutionImpl(value.id);
|
||||
export function to(value: TaskExecutionDTO, tasks: ExtHostTask): vscode.TaskExecution {
|
||||
return new TaskExecutionImpl(value.id, TaskDTO.to(value.task, tasks.extHostWorkspace), tasks);
|
||||
}
|
||||
export function from(value: vscode.TaskExecution): TaskExecutionDTO {
|
||||
return {
|
||||
id: (value as TaskExecutionImpl)._id
|
||||
id: (value as TaskExecutionImpl)._id,
|
||||
task: undefined
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -712,6 +722,10 @@ export class ExtHostTask implements ExtHostTaskShape {
|
||||
this._handlers = new Map<number, HandlerData>();
|
||||
}
|
||||
|
||||
public get extHostWorkspace(): ExtHostWorkspace {
|
||||
return this._extHostWorkspace;
|
||||
}
|
||||
|
||||
public registerTaskProvider(extension: IExtensionDescription, provider: vscode.TaskProvider): vscode.Disposable {
|
||||
if (!provider) {
|
||||
return new types.Disposable(() => { });
|
||||
@@ -742,15 +756,19 @@ export class ExtHostTask implements ExtHostTaskShape {
|
||||
let tTask = (task as types.Task);
|
||||
// We have a preserved ID. So the task didn't change.
|
||||
if (tTask._id !== void 0) {
|
||||
return this._proxy.$executeTask(TaskHandleDTO.from(tTask)).then(value => TaskExecutionDTO.to(value));
|
||||
return this._proxy.$executeTask(TaskHandleDTO.from(tTask)).then(value => new TaskExecutionImpl(value.id, task, this));
|
||||
} else {
|
||||
return this._proxy.$executeTask(TaskDTO.from(task, extension)).then(value => TaskExecutionDTO.to(value));
|
||||
let dto = TaskDTO.from(task, extension);
|
||||
if (dto === void 0) {
|
||||
return Promise.reject(new Error('Task is not valid'));
|
||||
}
|
||||
return this._proxy.$executeTask(dto).then(value => new TaskExecutionImpl(value.id, task, this));
|
||||
}
|
||||
}
|
||||
|
||||
public $taskStarted(execution: TaskExecutionDTO): void {
|
||||
this._onDidExecuteTask.fire({
|
||||
execution: TaskExecutionDTO.to(execution)
|
||||
execution: TaskExecutionDTO.to(execution, this)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -762,12 +780,12 @@ export class ExtHostTask implements ExtHostTaskShape {
|
||||
if (!(execution instanceof TaskExecutionImpl)) {
|
||||
throw new Error('No valid task execution provided');
|
||||
}
|
||||
return this._proxy.$terminateTask(TaskExecutionDTO.from(execution));
|
||||
return this._proxy.$terminateTask((execution as TaskExecutionImpl)._id);
|
||||
}
|
||||
|
||||
public $taskEnded(execution: TaskExecutionDTO): void {
|
||||
this._onDidTerminateTask.fire({
|
||||
execution: TaskExecutionDTO.to(execution)
|
||||
execution: TaskExecutionDTO.to(execution, this)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1343,6 +1343,20 @@ export class ProcessExecution implements vscode.ProcessExecution {
|
||||
set options(value: vscode.ProcessExecutionOptions) {
|
||||
this._options = value;
|
||||
}
|
||||
|
||||
public computeId(): string {
|
||||
const hash = crypto.createHash('md5');
|
||||
hash.update('process');
|
||||
if (this._process !== void 0) {
|
||||
hash.update(this._process);
|
||||
}
|
||||
if (this._args && this._args.length > 0) {
|
||||
for (let arg of this._args) {
|
||||
hash.update(arg);
|
||||
}
|
||||
}
|
||||
return hash.digest('hex');
|
||||
}
|
||||
}
|
||||
|
||||
export class ShellExecution implements vscode.ShellExecution {
|
||||
@@ -1411,6 +1425,23 @@ export class ShellExecution implements vscode.ShellExecution {
|
||||
set options(value: vscode.ShellExecutionOptions) {
|
||||
this._options = value;
|
||||
}
|
||||
|
||||
public computeId(): string {
|
||||
const hash = crypto.createHash('md5');
|
||||
hash.update('shell');
|
||||
if (this._commandLine !== void 0) {
|
||||
hash.update(this._commandLine);
|
||||
}
|
||||
if (this._command !== void 0) {
|
||||
hash.update(typeof this._command === 'string' ? this._command : this._command.value);
|
||||
}
|
||||
if (this._args && this._args.length > 0) {
|
||||
for (let arg of this._args) {
|
||||
hash.update(typeof arg === 'string' ? arg : arg.value);
|
||||
}
|
||||
}
|
||||
return hash.digest('hex');
|
||||
}
|
||||
}
|
||||
|
||||
export enum ShellQuoting {
|
||||
@@ -1485,7 +1516,24 @@ export class Task implements vscode.Task {
|
||||
}
|
||||
|
||||
private clear(): void {
|
||||
if (this.__id === void 0) {
|
||||
return;
|
||||
}
|
||||
this.__id = undefined;
|
||||
this._scope = undefined;
|
||||
this._definitionKey = undefined;
|
||||
this._definition = undefined;
|
||||
if (this._execution instanceof ProcessExecution) {
|
||||
this._definition = {
|
||||
type: 'process',
|
||||
id: this._execution.computeId()
|
||||
};
|
||||
} else if (this._execution instanceof ShellExecution) {
|
||||
this._definition = {
|
||||
type: 'shell',
|
||||
id: this._execution.computeId()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
get definition(): vscode.TaskDefinition {
|
||||
|
||||
@@ -11,10 +11,6 @@ export interface TaskDefinitionDTO {
|
||||
[name: string]: any;
|
||||
}
|
||||
|
||||
export interface TaskExecutionDTO {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface TaskPresentationOptionsDTO {
|
||||
reveal?: number;
|
||||
echo?: boolean;
|
||||
@@ -85,4 +81,9 @@ export interface TaskDTO {
|
||||
presentationOptions: TaskPresentationOptionsDTO;
|
||||
problemMatchers: string[];
|
||||
hasDefinedMatchers: boolean;
|
||||
}
|
||||
|
||||
export interface TaskExecutionDTO {
|
||||
id: string;
|
||||
task: TaskDTO;
|
||||
}
|
||||
Reference in New Issue
Block a user