-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for TaskProvider.resolveTask #71027
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d057c7
Adding support for TaskProvider.resolveTask.
joelday e65f3e6
Merge. Resolve conflict with mainThreadTask.ts
joelday ce1a668
Reorganize task grouping and resolution async code for readability.
icfjoeld 5ceabc6
Merge branch 'master' into task-provider-resolve-task
icfjoeld b12ab13
Merge master
alexr00 fe7baeb
Made small changes and implmented resolveTask for gulp
alexr00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,6 +347,7 @@ namespace TaskExecutionDTO { | |
} | ||
|
||
interface HandlerData { | ||
type: string; | ||
provider: vscode.TaskProvider; | ||
extension: IExtensionDescription; | ||
} | ||
|
@@ -491,13 +492,13 @@ export class ExtHostTask implements ExtHostTaskShape { | |
this._activeCustomExecutions = new Map<string, CustomExecutionData>(); | ||
} | ||
|
||
public registerTaskProvider(extension: IExtensionDescription, provider: vscode.TaskProvider): vscode.Disposable { | ||
public registerTaskProvider(extension: IExtensionDescription, type: string, provider: vscode.TaskProvider): vscode.Disposable { | ||
if (!provider) { | ||
return new types.Disposable(() => { }); | ||
} | ||
const handle = this.nextHandle(); | ||
this._handlers.set(handle, { provider, extension }); | ||
this._proxy.$registerTaskProvider(handle); | ||
this._handlers.set(handle, { type, provider, extension }); | ||
this._proxy.$registerTaskProvider(handle, type); | ||
return new types.Disposable(() => { | ||
this._handlers.delete(handle); | ||
this._proxy.$unregisterTaskProvider(handle); | ||
|
@@ -651,15 +652,10 @@ export class ExtHostTask implements ExtHostTaskShape { | |
taskDTOs.push(taskDTO); | ||
|
||
if (CustomExecutionDTO.is(taskDTO.execution)) { | ||
taskIdPromises.push(new Promise((resolve) => { | ||
// The ID is calculated on the main thread task side, so, let's call into it here. | ||
// We need the task id's pre-computed for custom task executions because when OnDidStartTask | ||
// is invoked, we have to be able to map it back to our data. | ||
this._proxy.$createTaskId(taskDTO).then((taskId) => { | ||
this._providedCustomExecutions.set(taskId, new CustomExecutionData(<vscode.CustomExecution>(<vscode.Task2>task).execution2, this._terminalService)); | ||
resolve(); | ||
}); | ||
})); | ||
// The ID is calculated on the main thread task side, so, let's call into it here. | ||
// We need the task id's pre-computed for custom task executions because when OnDidStartTask | ||
// is invoked, we have to be able to map it back to our data. | ||
taskIdPromises.push(this.addCustomExecution(taskDTO, <vscode.Task2>task)); | ||
} | ||
} | ||
} | ||
|
@@ -679,6 +675,38 @@ export class ExtHostTask implements ExtHostTaskShape { | |
}); | ||
} | ||
|
||
public async $resolveTask(handle: number, taskDTO: TaskDTO): Promise<TaskDTO | undefined> { | ||
const handler = this._handlers.get(handle); | ||
if (!handler) { | ||
return Promise.reject(new Error('no handler found')); | ||
} | ||
|
||
if (taskDTO.definition.type !== handler.type) { | ||
throw new Error(`Unexpected: Task of type [${taskDTO.definition.type}] cannot be resolved by provider of type [${handler.type}].`); | ||
} | ||
|
||
const task = await TaskDTO.to(taskDTO, this._workspaceProvider); | ||
if (!task) { | ||
throw new Error('Unexpected: Task cannot be resolved.'); | ||
} | ||
|
||
const resolvedTask = await handler.provider.resolveTask(task, CancellationToken.None); | ||
if (!resolvedTask) { | ||
return; | ||
} | ||
|
||
const resolvedTaskDTO: TaskDTO | undefined = TaskDTO.from(resolvedTask, handler.extension); | ||
if (!resolvedTaskDTO) { | ||
throw new Error('Unexpected: Task cannot be resolved.'); | ||
} | ||
|
||
if (CustomExecutionDTO.is(resolvedTaskDTO.execution)) { | ||
await this.addCustomExecution(taskDTO, <vscode.Task2>task); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we allow the provider to change the DTO properties, then we have a different task since those properties are the fingerprint of the task. |
||
} | ||
|
||
return resolvedTaskDTO; | ||
} | ||
|
||
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 uri: URI = URI.revive(uriComponents); | ||
|
@@ -724,6 +752,11 @@ export class ExtHostTask implements ExtHostTaskShape { | |
return this._handleCounter++; | ||
} | ||
|
||
private async addCustomExecution(taskDTO: TaskDTO, task: vscode.Task2): Promise<void> { | ||
const taskId = await this._proxy.$createTaskId(taskDTO); | ||
this._providedCustomExecutions.set(taskId, new CustomExecutionData(<vscode.CustomExecution>(<vscode.Task2>task).execution2, this._terminalService)); | ||
} | ||
|
||
private async getTaskExecution(execution: TaskExecutionDTO | string, task?: vscode.Task): Promise<TaskExecutionImpl> { | ||
if (typeof execution === 'string') { | ||
const taskExecution = this._taskExecutions.get(execution); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can see, not having a name is fine. The important thing is that the task has a definition so that the task provider knows what to do with it.