Skip to content

Commit c7c6378

Browse files
committed
feat: run last task command
1 parent 6dbff8d commit c7c6378

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed

CHANGELOG.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Changelog
22

3-
## v0.1.0-prerelease [Unreleased]
3+
## v0.1.0 [Unreleased]
44

5-
- View tasks in the activity bar
6-
- Run tasks from the activity bar and command palette
7-
- Go to definition
8-
- Multi-root workspace support
9-
- Ability to initialize a Taskfile in the current workspace
10-
- If no Taskfile is detected a button will appear in the activity bar
11-
- Refresh on save
12-
- Configurable via `task.updateOn` setting (values: `save` (default) or `manual`)
13-
- Activity bar icon provided by @drite93
5+
- View tasks in the sidebar.
6+
- Run tasks from the sidebar and command palette.
7+
- Go to definition from the sidebar and command palette.
8+
- Run last task command.
9+
- Multi-root workspace support.
10+
- Ability to initialize a Taskfile in the current workspace.
11+
- If no Taskfile is detected a button will appear in the sidebar.
12+
- Refresh on save.
13+
- Configurable via `task.updateOn` setting (values: `save` (default) or `manual`).
14+
- Sidebar icon provided by @drite93.

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ This extension integrates your Taskfile into Visual Studio Code.
44

55
## Features
66

7-
- View tasks in the activity bar
8-
- Run tasks from the activity bar and command palette
9-
- Go to definition
10-
- Multi-root workspace support
11-
- Ability to initialize a Taskfile in the current workspace
12-
- If no Taskfile is detected a button will appear in the activity bar
7+
- View tasks in the sidebar.
8+
- Run tasks from the sidebar and command palette.
9+
- Go to definition from the sidebar and command palette.
10+
- Run last task command.
11+
- Multi-root workspace support.
12+
- Ability to initialize a Taskfile in the current workspace.
13+
- If no Taskfile is detected a button will appear in the sidebar.
1314

1415
## Roadmap
1516

16-
- Run last task command
17-
- Loading icon when a task is running in tree view
1817
- Switch between nested/flat task view
1918
- Refresh up-to-date status when a task's sources change
2019
- Status polling to update up-to-date status
2120
- Support global tasks
22-
- Install Task via command palette
21+
- Ability to install Task via command palette
2322
- Prompt if a Taskfile is detected and Task is not installed
23+
- Prompt if version of Task is out of date

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@
6060
"category": "Task",
6161
"icon": "$(play)"
6262
},
63+
{
64+
"command": "vscode-task.runLastTask",
65+
"title": "Run Last Task",
66+
"category": "Task",
67+
"icon": "$(redo)"
68+
},
6369
{
6470
"command": "vscode-task.goToDefinition",
6571
"title": "Go to Definition",

src/services/taskfile.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class TaskfileService {
88
private static _instance: TaskfileService;
99
private static outputChannel: vscode.OutputChannel;
1010
private static readonly taskCommand = 'task';
11+
private lastTaskName: string | undefined;
12+
private lastTaskDir: string | undefined;
1113

1214
private constructor() {
1315
TaskfileService.outputChannel = vscode.window.createOutputChannel('Task');
@@ -54,6 +56,14 @@ class TaskfileService {
5456
});
5557
}
5658

59+
public async runLastTask(): Promise<void> {
60+
if (this.lastTaskName === undefined) {
61+
vscode.window.showErrorMessage(`No task has been run yet.`);
62+
return;
63+
}
64+
await this.runTask(this.lastTaskName, this.lastTaskDir);
65+
}
66+
5767
public async runTask(taskName: string, dir?: string): Promise<void> {
5868
return await new Promise((resolve) => {
5969
// Spawn a child process
@@ -78,6 +88,8 @@ class TaskfileService {
7888
// When the task finishes, print the exit code and resolve the promise
7989
child.on('close', code => {
8090
TaskfileService.outputChannel.append(`task: completed with code ${code}\n`);
91+
this.lastTaskName = taskName;
92+
this.lastTaskDir = dir;
8193
return resolve();
8294
});
8395
});

src/task.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ export class TaskExtension {
9494
});
9595
}));
9696

97+
// Run last task
98+
context.subscriptions.push(vscode.commands.registerCommand('vscode-task.runLastTask', () => {
99+
services.taskfile.runLastTask();
100+
}));
101+
97102
// Go to definition
98103
context.subscriptions.push(vscode.commands.registerCommand('vscode-task.goToDefinition', (task: elements.TaskTreeItem | models.Task, preview: boolean = false) => {
99104
if (task instanceof elements.TaskTreeItem) {

0 commit comments

Comments
 (0)