Skip to content

Commit a6b4e6f

Browse files
authored
fix: tree view (#214)
* feat: use --nested flag * feat: increase minimum required version of Task * feat: detect development mode when --version includes build metadata (after "+") * fix: bug where only one additional flag gets set * feat: disable status checking by default - adds a new tree.status setting to reenable - change the default task icon color to task's primary color * refactor: tree item * fix: ensure nesting icon is in correct state on startup * fix: updated minimum required version
1 parent 75b7e46 commit a6b4e6f

File tree

11 files changed

+152
-193
lines changed

11 files changed

+152
-193
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"tasks": [
66
{
77
"type": "npm",
8-
"script": "bundle",
8+
"script": "compile",
99
"problemMatcher": "$tsc-watch",
1010
"isBackground": true,
1111
"presentation": {

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@
4545
| `checkForUpdates` | `boolean` | | `true` | Check if there is a newer version of Task on startup. |
4646
| `doubleClickTimeout` | `number` | | `0` | Time in milliseconds to consider a double-click. 0 disables double-click to run. 500 is a good starting point if you want to enable it. |
4747
| `tree.nesting` | `boolean` | | `true` | Whether to nest tasks by their namespace in the tree view. |
48+
| `tree.status` | `boolean` | | `false` | Whether to show the status of tasks in the tree view (may be slow on large Taskfiles). |
4849
| `tree.sort` | `sort` | `default`, `alphanumeric`, `none` | `"default"` | The order in which to display tasks in the tree view. |

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@
263263
"highContrast": "#ff9b05",
264264
"highContrastLight": "#ff9b05"
265265
}
266+
},
267+
{
268+
"id": "vscodetask.primaryColor",
269+
"description": "Color for primary elements.",
270+
"defaults": {
271+
"dark": "#43aba2",
272+
"light": "#43aba2",
273+
"highContrast": "#43aba2",
274+
"highContrastLight": "#43aba2"
275+
}
266276
}
267277
],
268278
"configuration": {
@@ -314,6 +324,11 @@
314324
"default": true,
315325
"description": "Whether to nest tasks by their namespace in the tree view."
316326
},
327+
"status": {
328+
"type": "boolean",
329+
"default": false,
330+
"description": "Whether to show the status of tasks in the tree view (may be slow on large Taskfiles)."
331+
},
317332
"sort": {
318333
"type": "string",
319334
"enum": [

src/elements/activityBar.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22
import { TaskTreeDataProvider } from '../providers/taskTreeDataProvider.js';
3-
import { Taskfile } from '../models/taskfile.js';
3+
import { Namespace } from '../models/models.js';
44

55
export class ActivityBar {
66
private _provider: TaskTreeDataProvider;
@@ -16,12 +16,7 @@ export class ActivityBar {
1616
});
1717
}
1818

19-
public setTreeNesting(enabled: boolean) {
20-
this._provider.setTreeNesting(enabled);
21-
this._provider.refresh();
22-
}
23-
24-
public refresh(taskfiles?: Taskfile[]) {
25-
this._provider.refresh(taskfiles);
19+
public refresh(taskfiles?: Namespace[], nesting?: boolean): void {
20+
this._provider.refresh(taskfiles, nesting);
2621
}
2722
}

src/elements/quickPickItem.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import * as vscode from 'vscode';
2-
import { Taskfile, Task } from '../models/taskfile.js';
2+
import { Namespace, Task } from '../models/models.js';
33

44
export class QuickPickTaskItem implements vscode.QuickPickItem {
5-
constructor(taskfile: Taskfile, task: Task) {
6-
this.taskfile = taskfile;
5+
constructor(namespace: Namespace, task: Task) {
6+
this.namespace = namespace;
77
this.task = task;
88
this.label = task.name;
99
this.description = task.desc;
1010
this.kind = vscode.QuickPickItemKind.Default;
1111
}
12-
taskfile: Taskfile;
12+
namespace: Namespace;
1313
task: Task;
1414
label: string;
1515
description: string;
1616
kind: vscode.QuickPickItemKind;
1717
}
1818

1919
export class QuickPickTaskSeparator implements vscode.QuickPickItem {
20-
constructor(taskfile: Taskfile) {
21-
this.label = taskfile.location;
20+
constructor(namespace: Namespace) {
21+
this.label = namespace.location;
2222
this.kind = vscode.QuickPickItemKind.Separator;
2323
}
2424
label: string;

src/elements/treeItem.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,47 @@
11
import * as vscode from 'vscode';
2-
import { Task } from '../models/taskfile.js';
2+
import { Namespace, Task } from '../models/models.js';
33

44
export type TreeItem = WorkspaceTreeItem | NamespaceTreeItem | TaskTreeItem;
55

66
export class WorkspaceTreeItem extends vscode.TreeItem {
7+
private static readonly icon = 'folder';
78
constructor(
89
readonly label: string,
910
readonly workspace: string,
10-
readonly tasks: Task[],
11+
readonly namespace: Namespace,
1112
readonly collapsibleState: vscode.TreeItemCollapsibleState,
1213
readonly command?: vscode.Command
1314
) {
1415
super(label, collapsibleState);
1516
this.description = this.workspace;
16-
this.iconPath = new vscode.ThemeIcon('folder', new vscode.ThemeColor('vscodetask.workspaceIcon'));
17+
this.iconPath = new vscode.ThemeIcon(
18+
WorkspaceTreeItem.icon,
19+
new vscode.ThemeColor('vscodetask.workspaceIcon')
20+
);
1721
this.contextValue = `workspaceTreeItem`;
1822
}
1923
}
2024

2125
export class NamespaceTreeItem extends vscode.TreeItem {
26+
private static readonly icon = 'symbol-namespace';
2227
constructor(
2328
readonly label: string,
2429
readonly workspace: string,
25-
readonly namespaceMap: any,
26-
readonly tasks: Task[],
30+
readonly namespace: Namespace,
2731
readonly collapsibleState: vscode.TreeItemCollapsibleState,
2832
readonly command?: vscode.Command
2933
) {
3034
super(label, collapsibleState);
31-
this.iconPath = new vscode.ThemeIcon('symbol-namespace', new vscode.ThemeColor('vscodetask.namespaceIcon'));
35+
this.iconPath = new vscode.ThemeIcon(
36+
NamespaceTreeItem.icon,
37+
new vscode.ThemeColor('vscodetask.namespaceIcon')
38+
);
3239
this.contextValue = `namespaceTreeItem`;
3340
}
3441
}
3542

3643
export class TaskTreeItem extends vscode.TreeItem {
44+
private static readonly icon = 'symbol-function';
3745
constructor(
3846
readonly label: string,
3947
readonly workspace: string,
@@ -43,10 +51,24 @@ export class TaskTreeItem extends vscode.TreeItem {
4351
) {
4452
super(label, collapsibleState);
4553
this.description = this.task?.desc;
46-
if (this.task.up_to_date) {
47-
this.iconPath = new vscode.ThemeIcon('debug-breakpoint-log-unverified', new vscode.ThemeColor('vscodetask.upToDateIcon'));
48-
} else {
49-
this.iconPath = new vscode.ThemeIcon('debug-breakpoint-data-unverified', new vscode.ThemeColor('vscodetask.outOfDateIcon'));
54+
switch (this.task.up_to_date) {
55+
case true:
56+
this.iconPath = new vscode.ThemeIcon(
57+
TaskTreeItem.icon,
58+
new vscode.ThemeColor('vscodetask.upToDateIcon')
59+
);
60+
break;
61+
case false:
62+
this.iconPath = new vscode.ThemeIcon(
63+
TaskTreeItem.icon,
64+
new vscode.ThemeColor('vscodetask.outOfDateIcon')
65+
);
66+
break;
67+
default:
68+
this.iconPath = new vscode.ThemeIcon(
69+
TaskTreeItem.icon,
70+
new vscode.ThemeColor('vscodetask.primaryColor')
71+
);
5072
}
5173
this.contextValue = `taskTreeItem`;
5274
}

src/models/taskfile.ts renamed to src/models/models.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
export type TaskMapping = {
2-
[key: string]: TaskMapping | null;
3-
};
4-
5-
export interface Taskfile {
1+
export interface Namespace {
62
tasks: Task[];
3+
namespaces: Map<string, Namespace>;
74
location: string; // The location of the actual Taskfile
85
// The vscode workspace directory where the command was executed to find this taskfile
96
// This is where tasks in this taskfile will be executed from.
@@ -15,7 +12,7 @@ export interface Task {
1512
desc: string;
1613
summary: string;
1714
// eslint-disable-next-line @typescript-eslint/naming-convention
18-
up_to_date: boolean;
15+
up_to_date: boolean | undefined;
1916
location: Location;
2017
}
2118

0 commit comments

Comments
 (0)