Adopt task multi folder API

This commit is contained in:
Dirk Baeumer
2017-09-15 11:03:57 +02:00
parent 9c6880cb32
commit cc5cc9a2d6
10 changed files with 159 additions and 149 deletions

View File

@@ -97,7 +97,7 @@ export function createApiFactory(
const extHostQuickOpen = threadService.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(threadService));
const extHostTerminalService = threadService.set(ExtHostContext.ExtHostTerminalService, new ExtHostTerminalService(threadService));
const extHostSCM = threadService.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(threadService, extHostCommands));
const extHostTask = threadService.set(ExtHostContext.ExtHostTask, new ExtHostTask(threadService));
const extHostTask = threadService.set(ExtHostContext.ExtHostTask, new ExtHostTask(threadService, extHostWorkspace));
const extHostCredentials = threadService.set(ExtHostContext.ExtHostCredentials, new ExtHostCredentials(threadService));
const extHostWindow = threadService.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(threadService));
threadService.set(ExtHostContext.ExtHostExtensionService, extensionService);
@@ -599,6 +599,7 @@ export function createApiFactory(
TaskGroup: extHostTypes.TaskGroup,
ProcessExecution: extHostTypes.ProcessExecution,
ShellExecution: extHostTypes.ShellExecution,
TaskScope: extHostTypes.TaskScope,
Task: extHostTypes.Task,
ConfigurationTarget: extHostTypes.ConfigurationTarget
};

View File

@@ -16,6 +16,7 @@ import * as TaskSystem from 'vs/workbench/parts/tasks/common/tasks';
import { MainContext, MainThreadTaskShape, ExtHostTaskShape, IMainContext } from 'vs/workbench/api/node/extHost.protocol';
import * as types from 'vs/workbench/api/node/extHostTypes';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import * as vscode from 'vscode';
interface StringMap<V> {
@@ -296,13 +297,13 @@ namespace ShellConfiguration {
namespace Tasks {
export function from(tasks: vscode.Task[], extension: IExtensionDescription): TaskSystem.Task[] {
export function from(tasks: vscode.Task[], rootFolder: vscode.WorkspaceFolder, extension: IExtensionDescription): TaskSystem.Task[] {
if (tasks === void 0 || tasks === null) {
return [];
}
let result: TaskSystem.Task[] = [];
for (let task of tasks) {
let converted = fromSingle(task, extension);
let converted = fromSingle(task, rootFolder, extension);
if (converted) {
result.push(converted);
}
@@ -310,7 +311,7 @@ namespace Tasks {
return result;
}
function fromSingle(task: vscode.Task, extension: IExtensionDescription): TaskSystem.ContributedTask {
function fromSingle(task: vscode.Task, rootFolder: vscode.WorkspaceFolder, extension: IExtensionDescription): TaskSystem.ContributedTask {
if (typeof task.name !== 'string') {
return undefined;
}
@@ -327,11 +328,27 @@ namespace Tasks {
return undefined;
}
command.presentation = PresentationOptions.from(task.presentationOptions);
let taskScope: types.TaskScope.Global | types.TaskScope.Workspace | vscode.WorkspaceFolder | undefined = task.scope;
let workspaceFolder: vscode.WorkspaceFolder | undefined;
let scope: TaskSystem.TaskScope;
// For backwards compatibility
if (taskScope === void 0) {
scope = TaskSystem.TaskScope.Folder;
workspaceFolder = rootFolder;
} else if (taskScope === types.TaskScope.Global) {
scope = TaskSystem.TaskScope.Global;
} else if (taskScope === types.TaskScope.Workspace) {
scope = TaskSystem.TaskScope.Workspace;
} else {
workspaceFolder = taskScope;
}
let source: TaskSystem.ExtensionTaskSource = {
kind: TaskSystem.TaskSourceKind.Extension,
label: typeof task.source === 'string' ? task.source : extension.name,
extension: extension.id,
workspaceFolder: task.workspaceFolder ? { uri: task.workspaceFolder.uri as URI } : undefined
scope: scope,
workspaceFolder: workspaceFolder ? { uri: workspaceFolder.uri as URI } : undefined
};
let label = nls.localize('task.label', '{0}: {1}', source.label, task.name);
let key = (task as types.Task).definitionKey;
@@ -400,11 +417,13 @@ interface HandlerData {
export class ExtHostTask implements ExtHostTaskShape {
private _proxy: MainThreadTaskShape;
private _extHostWorkspace: ExtHostWorkspace;
private _handleCounter: number;
private _handlers: Map<number, HandlerData>;
constructor(mainContext: IMainContext) {
constructor(mainContext: IMainContext, extHostWorkspace: ExtHostWorkspace) {
this._proxy = mainContext.get(MainContext.MainThreadTask);
this._extHostWorkspace = extHostWorkspace;
this._handleCounter = 0;
this._handlers = new Map<number, HandlerData>();
};
@@ -428,8 +447,9 @@ export class ExtHostTask implements ExtHostTaskShape {
return TPromise.wrapError<TaskSystem.TaskSet>(new Error('no handler found'));
}
return asWinJsPromise(token => handler.provider.provideTasks(token)).then(value => {
let workspaceFolders = this._extHostWorkspace.getWorkspaceFolders();
return {
tasks: Tasks.from(value, handler.extension),
tasks: Tasks.from(value, workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0] : undefined, handler.extension),
extension: handler.extension
};
});

View File

@@ -1214,11 +1214,16 @@ export class ShellExecution implements vscode.ShellExecution {
}
}
export enum TaskScope {
Global = 1,
Workspace = 2
}
export class Task implements vscode.Task {
private _definition: vscode.TaskDefinition;
private _definitionKey: string;
private _workspaceFolder: vscode.WorkspaceFolder;
private _scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder;
private _name: string;
private _execution: ProcessExecution | ShellExecution;
private _problemMatchers: string[];
@@ -1229,8 +1234,8 @@ export class Task implements vscode.Task {
private _presentationOptions: vscode.TaskPresentationOptions;
constructor(definition: vscode.TaskDefinition, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
constructor(definition: vscode.TaskDefinition, workspaceFolder: vscode.WorkspaceFolder, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
constructor(definition: vscode.TaskDefinition, arg2: string | vscode.WorkspaceFolder, arg3: any, arg4?: any, arg5?: any, arg6?: any) {
constructor(definition: vscode.TaskDefinition, scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
constructor(definition: vscode.TaskDefinition, arg2: string | (vscode.TaskScope.Global | vscode.TaskScope.Workspace) | vscode.WorkspaceFolder, arg3: any, arg4?: any, arg5?: any, arg6?: any) {
this.definition = definition;
let problemMatchers: string | string[];
if (typeof arg2 === 'string') {
@@ -1238,8 +1243,14 @@ export class Task implements vscode.Task {
this.source = arg3;
this.execution = arg4;
problemMatchers = arg5;
} else if (arg2 === TaskScope.Global || arg2 === TaskScope.Workspace) {
this.target = arg2;
this.name = arg3;
this.source = arg4;
this.execution = arg5;
problemMatchers = arg6;
} else {
this.workspaceFolder = arg2;
this.target = arg2;
this.name = arg3;
this.source = arg4;
this.execution = arg5;
@@ -1279,12 +1290,12 @@ export class Task implements vscode.Task {
return this._definitionKey;
}
get workspaceFolder(): vscode.WorkspaceFolder {
return this._workspaceFolder;
get scope(): vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder {
return this._scope;
}
set workspaceFolder(value: vscode.WorkspaceFolder) {
this._workspaceFolder = value;
set target(value: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder) {
this._scope = value;
}
get name(): string {