Skip to content

Commit d43b55f

Browse files
committed
feat: run task and refresh actions
1 parent 71dd257 commit d43b55f

File tree

5 files changed

+59
-26
lines changed

5 files changed

+59
-26
lines changed

package.json

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@
1313
"main": "./out/extension.js",
1414
"contributes": {
1515
"commands": [
16+
{
17+
"command": "vscode-task.refresh",
18+
"title": "Refresh Tasks",
19+
"category": "Task",
20+
"icon": "$(refresh)"
21+
},
1622
{
1723
"command": "vscode-task.runTask",
1824
"title": "Run Task",
19-
"category": "Task"
25+
"category": "Task",
26+
"icon": "$(play)"
2027
},
2128
{
22-
"command": "vscode-task.refreshTasks",
23-
"title": "Refresh Tasks",
24-
"category": "Task"
29+
"command": "vscode-task.runTaskPicker",
30+
"title": "Run Task",
31+
"category": "Task",
32+
"icon": "$(play)"
2533
}
2634
],
2735
"viewsContainers": {
@@ -41,6 +49,28 @@
4149
}
4250
]
4351
},
52+
"menus": {
53+
"commandPalette": [
54+
{
55+
"command": "vscode-task.runTask",
56+
"when": "false"
57+
}
58+
],
59+
"view/title": [
60+
{
61+
"command": "vscode-task.refresh",
62+
"when": "view == vscode-task.tasks",
63+
"group": "navigation"
64+
}
65+
],
66+
"view/item/context": [
67+
{
68+
"command": "vscode-task.runTask",
69+
"when": "view == vscode-task.tasks && viewItem == taskTreeItem",
70+
"group": "inline"
71+
}
72+
]
73+
},
4474
"colors": [
4575
{
4676
"id": "vscodetask.namespace",

src/commands/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/commands/runTask.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/providers/tasks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function trimNamespacePrefix(str: string, prefix?: string) {
6666
return str;
6767
}
6868

69-
class TaskTreeItem extends vscode.TreeItem {
69+
export class TaskTreeItem extends vscode.TreeItem {
7070
constructor(
7171
readonly label: string,
7272
readonly namespace: string,
@@ -82,5 +82,6 @@ class TaskTreeItem extends vscode.TreeItem {
8282
} else {
8383
this.iconPath = new vscode.ThemeIcon('debug-breakpoint-data-unverified', new vscode.ThemeColor('vscodetask.outOfDate'));
8484
}
85+
this.contextValue = `${this.task ? 'task' : 'namespace'}TreeItem`;
8586
}
8687
}

src/task.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as vscode from 'vscode';
2-
import * as commands from './commands';
32
import * as elements from './elements';
43
import * as services from './services';
54
import * as models from './models';
5+
import { TaskTreeItem } from './providers/tasks';
66

77
export class TaskExtension {
88
private _taskfile?: models.Taskfile;
@@ -23,10 +23,29 @@ export class TaskExtension {
2323
}
2424

2525
public registerCommands(context: vscode.ExtensionContext): void {
26-
context.subscriptions.push(vscode.commands.registerCommand('vscode-task.runTask', () => {
27-
commands.runTask(this._taskfile);
26+
27+
// Run task
28+
context.subscriptions.push(vscode.commands.registerCommand('vscode-task.runTask', (treeItem?: TaskTreeItem) => {
29+
if (treeItem?.task) {
30+
services.taskfile.runTask(treeItem.task.name);
31+
}
2832
}));
29-
context.subscriptions.push(vscode.commands.registerCommand('vscode-task.refreshTasks', () => {
33+
34+
// Run task picker
35+
context.subscriptions.push(vscode.commands.registerCommand('vscode-task.runTaskPicker', () => {
36+
if (!this._taskfile || this._taskfile.tasks.length === 0) {
37+
vscode.window.showInformationMessage('No tasks found');
38+
return;
39+
}
40+
vscode.window.showQuickPick(this._taskfile.tasks.map(t => t.name)).then((taskName) => {
41+
if (taskName) {
42+
services.taskfile.runTask(taskName);
43+
}
44+
});
45+
}));
46+
47+
// Refresh tasks
48+
context.subscriptions.push(vscode.commands.registerCommand('vscode-task.refresh', () => {
3049
this.update().then(() => {
3150
this.refresh();
3251
}).catch((err: string) => {

0 commit comments

Comments
 (0)