Delay extension host until workspace is completely initialized

This commit is contained in:
Sandeep Somavarapu
2019-01-28 10:54:45 +01:00
parent 1f28c5fc68
commit aba0fcbb58
14 changed files with 204 additions and 139 deletions

View File

@@ -16,7 +16,7 @@ import { IExtensionDescription } from 'vs/workbench/services/extensions/common/e
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 { ExtHostWorkspace, ExtHostWorkspaceProvider } from 'vs/workbench/api/node/extHostWorkspace';
import * as vscode from 'vscode';
import {
TaskDefinitionDTO, TaskExecutionDTO, TaskPresentationOptionsDTO, ProcessExecutionOptionsDTO, ProcessExecutionDTO,
@@ -219,7 +219,7 @@ namespace TaskDTO {
};
return result;
}
export function to(value: TaskDTO, workspace: ExtHostWorkspace): types.Task {
export function to(value: TaskDTO, workspace: ExtHostWorkspaceProvider): types.Task {
if (value === undefined || value === null) {
return undefined;
}
@@ -296,8 +296,8 @@ class TaskExecutionImpl implements vscode.TaskExecution {
}
namespace TaskExecutionDTO {
export function to(value: TaskExecutionDTO, tasks: ExtHostTask): vscode.TaskExecution {
return new TaskExecutionImpl(tasks, value.id, TaskDTO.to(value.task, tasks.extHostWorkspace));
export function to(value: TaskExecutionDTO, tasks: ExtHostTask, workspaceProvider: ExtHostWorkspaceProvider): vscode.TaskExecution {
return new TaskExecutionImpl(tasks, value.id, TaskDTO.to(value.task, workspaceProvider));
}
export function from(value: vscode.TaskExecution): TaskExecutionDTO {
return {
@@ -338,10 +338,6 @@ export class ExtHostTask implements ExtHostTaskShape {
this._taskExecutions = new Map<string, TaskExecutionImpl>();
}
public get extHostWorkspace(): ExtHostWorkspace {
return this._workspaceService;
}
public registerTaskProvider(extension: IExtensionDescription, provider: vscode.TaskProvider): vscode.Disposable {
if (!provider) {
return new types.Disposable(() => { });
@@ -360,10 +356,11 @@ export class ExtHostTask implements ExtHostTaskShape {
}
public fetchTasks(filter?: vscode.TaskFilter): Promise<vscode.Task[]> {
return this._proxy.$fetchTasks(TaskFilterDTO.from(filter)).then((values) => {
return this._proxy.$fetchTasks(TaskFilterDTO.from(filter)).then(async (values) => {
let result: vscode.Task[] = [];
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
for (let value of values) {
let task = TaskDTO.to(value, this._workspaceService);
let task = TaskDTO.to(value, workspaceProvider);
if (task) {
result.push(task);
}
@@ -372,17 +369,18 @@ export class ExtHostTask implements ExtHostTaskShape {
});
}
public executeTask(extension: IExtensionDescription, task: vscode.Task): Promise<vscode.TaskExecution> {
public async executeTask(extension: IExtensionDescription, task: vscode.Task): Promise<vscode.TaskExecution> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
let tTask = (task as types.Task);
// We have a preserved ID. So the task didn't change.
if (tTask._id !== undefined) {
return this._proxy.$executeTask(TaskHandleDTO.from(tTask)).then(value => this.getTaskExecution(value, task));
return this._proxy.$executeTask(TaskHandleDTO.from(tTask)).then(value => this.getTaskExecution(value, workspaceProvider, task));
} else {
let dto = TaskDTO.from(task, extension);
if (dto === undefined) {
return Promise.reject(new Error('Task is not valid'));
}
return this._proxy.$executeTask(dto).then(value => this.getTaskExecution(value, task));
return this._proxy.$executeTask(dto).then(value => this.getTaskExecution(value, workspaceProvider, task));
}
}
@@ -403,9 +401,10 @@ export class ExtHostTask implements ExtHostTaskShape {
return this._onDidExecuteTask.event;
}
public $onDidStartTask(execution: TaskExecutionDTO): void {
public async $onDidStartTask(execution: TaskExecutionDTO): Promise<void> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
this._onDidExecuteTask.fire({
execution: this.getTaskExecution(execution)
execution: this.getTaskExecution(execution, workspaceProvider)
});
}
@@ -413,8 +412,9 @@ export class ExtHostTask implements ExtHostTaskShape {
return this._onDidTerminateTask.event;
}
public $OnDidEndTask(execution: TaskExecutionDTO): void {
const _execution = this.getTaskExecution(execution);
public async $OnDidEndTask(execution: TaskExecutionDTO): Promise<void> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
const _execution = this.getTaskExecution(execution, workspaceProvider);
this._taskExecutions.delete(execution.id);
this._onDidTerminateTask.fire({
execution: _execution
@@ -425,8 +425,9 @@ export class ExtHostTask implements ExtHostTaskShape {
return this._onDidTaskProcessStarted.event;
}
public $onDidStartTaskProcess(value: TaskProcessStartedDTO): void {
const execution = this.getTaskExecution(value.id);
public async $onDidStartTaskProcess(value: TaskProcessStartedDTO): Promise<void> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
const execution = this.getTaskExecution(value.id, workspaceProvider);
if (execution) {
this._onDidTaskProcessStarted.fire({
execution: execution,
@@ -439,8 +440,9 @@ export class ExtHostTask implements ExtHostTaskShape {
return this._onDidTaskProcessEnded.event;
}
public $onDidEndTaskProcess(value: TaskProcessEndedDTO): void {
const execution = this.getTaskExecution(value.id);
public async $onDidEndTaskProcess(value: TaskProcessEndedDTO): Promise<void> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
const execution = this.getTaskExecution(value.id, workspaceProvider);
if (execution) {
this._onDidTaskProcessEnded.fire({
execution: execution,
@@ -473,13 +475,14 @@ export class ExtHostTask implements ExtHostTaskShape {
public async $resolveVariables(uriComponents: UriComponents, toResolve: { process?: { name: string; cwd?: string; path?: string }, variables: string[] }): Promise<{ process?: string, variables: { [key: string]: string; } }> {
const configProvider = await this._configurationService.getConfigProvider();
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
let uri: URI = URI.revive(uriComponents);
let result = {
process: undefined as string,
variables: Object.create(null)
};
let workspaceFolder = this._workspaceService.resolveWorkspaceFolder(uri);
let resolver = new ExtHostVariableResolverService(this._workspaceService, this._editorService, configProvider);
let workspaceFolder = workspaceProvider.resolveWorkspaceFolder(uri);
let resolver = new ExtHostVariableResolverService(workspaceProvider, this._editorService, configProvider);
let ws: IWorkspaceFolder = {
uri: workspaceFolder.uri,
name: workspaceFolder.name,
@@ -512,7 +515,7 @@ export class ExtHostTask implements ExtHostTaskShape {
return this._handleCounter++;
}
private getTaskExecution(execution: TaskExecutionDTO | string, task?: vscode.Task): TaskExecutionImpl {
private getTaskExecution(execution: TaskExecutionDTO | string, workspaceProvider: ExtHostWorkspaceProvider, task?: vscode.Task): TaskExecutionImpl {
if (typeof execution === 'string') {
return this._taskExecutions.get(execution);
}
@@ -521,7 +524,7 @@ export class ExtHostTask implements ExtHostTaskShape {
if (result) {
return result;
}
result = new TaskExecutionImpl(this, execution.id, task ? task : TaskDTO.to(execution.task, this._workspaceService));
result = new TaskExecutionImpl(this, execution.id, task ? task : TaskDTO.to(execution.task, workspaceProvider));
this._taskExecutions.set(execution.id, result);
return result;
}