-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
add fetchTasks() and executeTask() to tasks API #6058
Conversation
return taskExecution; | ||
} | ||
} | ||
return Promise.reject(new Error(reason)); |
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.
resolved Roman's feedback #5357 (comment)
CHANGELOG.md
Outdated
@@ -10,6 +10,7 @@ | |||
- [task] displayed the customized tasks as "configured tasks" in the task quick open [#5777](https://github.com/theia-ide/theia/pull/5777) | |||
- [task] allowed users to override any task properties other than the ones used in the task definition [#5777](https://github.com/theia-ide/theia/pull/5777) | |||
- [task] notified clients of TaskDefinitionRegistry on change [#5915](https://github.com/theia-ide/theia/pull/5915) | |||
- [task] added `tasks.fetchTasks()` and `tasks.executeTask()` to plugins API [#???](https://github.com/theia-ide/theia/pull/???) |
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.
I believe you can add the number now :) #6058
packages/plugin/src/theia.d.ts
Outdated
version?: string; | ||
|
||
/** | ||
* The task type to return; |
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.
Can we adjust the formatting?
packages/plugin/src/theia.d.ts
Outdated
version?: string; | ||
|
||
/** | ||
* The task type to return; |
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.
The task type to return.
instead of The task type to return;
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.
i changed it to the type of tasks to return.
3223cfc
to
3cb394c
Compare
3cb394c
to
d1cb3d9
Compare
@elaihau @akosyakov |
@RomanNikitenko thank you for the heads up ! Have fun :) @vince-fugnitto maybe i can walk you through the code and explain how to test it this Friday (Sep 6) ? |
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.
I looked though the code, looks ok to me.
Will test this PR a bit later.
} | ||
|
||
const filtered: TaskConfiguration[] = []; | ||
found.forEach((taskConfig, ind) => { |
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.
Please use taskIndex
, index
or i
.
if (executionDto) { | ||
const taskExecution = this.getTaskExecution(executionDto); | ||
return taskExecution; | ||
} |
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.
Up to you, but I'd prefer not to introduce another variable for error message.
This way we'll avoid usually unneded variable, (small plus to performance and memory usage) and it will be easier to read:
const x = getX(...);
if (x) {
const y = getY(...);
if (y) {
...
return;
}
throw new Error('Y not found');
}
throw new Error ('X not found')
(And it is clear after which if
it failed and exited).
packages/plugin/src/theia.d.ts
Outdated
* | ||
* @param filter a filter to filter the return tasks. | ||
*/ | ||
export function fetchTasks(filter?: TaskFilter): Thenable<Task[]>; |
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.
Please use PromiseLike
insted of Thenable
Yes, that sounds fine with me :) |
I've tested the changes for the following cases:
All described above cases worked for me. Resource used for testing of this PR: Source code of the test pluginimport * as theia from '@theia/plugin';
export function start(context: theia.PluginContext) {
const listTAsksTestCommand = {
id: 'list-tasks-test-command',
label: "Test list tasks of type"
};
context.subscriptions.push(theia.commands.registerCommand(listTAsksTestCommand, (...args: any[]) => {
theia.window.showInformationMessage('On list tasks');
theia.tasks.fetchTasks({ type: 'ctask' }).then((tasks: theia.Task[]) => {
console.log('IN CALLBACK:', tasks);
for (const task of tasks) {
console.log('TASK:', task.name);
}
});
}));
const runTaskTestCommand = {
id: 'run-task-test-command',
label: "Test alter task"
};
context.subscriptions.push(theia.commands.registerCommand(runTaskTestCommand, (...args: any[]) => {
theia.window.showInformationMessage('On run altered task');
theia.tasks.fetchTasks({ type: 'ctask' }).then((tasks: theia.Task[]) => {
console.log('IN RUN TASK:', tasks);
for (const task of tasks) {
if (task.name.startsWith('Echo hello world')) {
if (!task.execution) {
task.execution = {};
}
if (!task.execution.options) {
task.execution.options = {};
}
(task.execution as theia.ShellExecution).commandLine = 'sleep 1 && ls -la';
task.execution.options.cwd = "/tmp";
theia.tasks.executeTask(task);
return;
}
}
});
}));
theia.tasks.registerTaskProvider('ctask', new CTaskProvider());
}
class CTaskProvider {
async provideTasks(): Promise<theia.Task[]> {
const task1 = new theia.Task({ type: 'ctask' }, theia.TaskScope.Global, 'first task', 'the-extension');
const task2 = new theia.Task({ type: 'ctask' }, theia.TaskScope.Workspace, 'second task', 'ctask');
return [task1, task2];
}
async resolveTask(task: theia.Task): Promise<theia.Task> {
return task;
}
}
export function stop() { } tasks.json{
"tasks": [
{
"type": "abcd",
"label": "rnodejs-hello-world:run",
"command": "yarn",
"target": {
"workingDir": "/projects/theia"
},
"previewUrl": "${server.3000/tcp}"
},
{
"type": "ctask",
"label": "Echo hello world",
"command": "echo \"hello world\"",
"target": {
"workingDir": "/projects",
"containerName": "theia-dev"
}
}
]
} |
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.
I've tested changes (see comment above) and it works as expected.
@elaihau please take a look at my previous comments at least about PromiseLike
and Thenable
.
- This pull request adds the support of executing a vscode.Task, and fetching tasks by type and schema version to the plugins API. - resolved #5342 Signed-off-by: Liang Huang <[email protected]>
d1cb3d9
to
2b58503
Compare
Thank you for the review @mmorhun ! I updated the code to address your review comments. |
Signed-off-by: Liang Huang [email protected]
How to test
This pull request can be tested with adding a vscode extension to Theia:
vsce
https://code.visualstudio.com/api/working-with-extensions/publishing-extensionTest Fetch Task and Execute Task
to TheiaFor reviewer's convenience I uploaded the source code of my extension to https://github.com/elaihau/fetchtest
Review checklist