Skip to content

Commit 3bf7fd9

Browse files
authored
Task sorting in tree view (#20)
* feat: task sorting * feat: version check for sorting functionality
1 parent cbb110b commit 3bf7fd9

File tree

5 files changed

+47
-17
lines changed

5 files changed

+47
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Added the ability to sort tasks in the tree view.
6+
- Configurable via `task.tree.sort` setting (values: `"default"` (default), `"alphanumeric"` or `"none"`).
7+
38
## v0.1.1 - 2021-03-27
49

510
- Fixed some installations (e.g. Brew) not detecting the Task version correctly (#13, #14 by @pd93).
@@ -17,7 +22,7 @@
1722
- Refresh on save.
1823
- Configurable via `task.updateOn` setting (values: `"save"` (default) or `"manual"`).
1924
- Toggle tree nesting on/off
20-
- Configurable via `task.nesting` setting (values: `true` (default) or `false`).
25+
- Configurable via `task.tree.nesting` setting (values: `true` (default) or `false`).
2126
- Change the path to the Task binary.
2227
- Can also be set to the name of a binary in your `$PATH`.
2328
- Configurable via `task.path` setting (defaults to `"task"`).

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232

3333
## Configuration
3434

35-
| Setting | Type | Allowed Values | Default | Description |
36-
| ----------------- | --------- | -------------------- | -------- | ----------------------------------------------------------------------- |
37-
| `updateOn` | `string` | `"manual"`, `"save"` | `"save"` | When the list of tasks should be updated. |
38-
| `path` | `string` | | `"task"` | Path to the Task binary. Can also the name of a binary in your `$PATH`. |
39-
| `checkForUpdates` | `boolean` | | `true` | Check if there is a newer version of Task on startup. |
40-
| `tree.nesting` | `boolean` | | `true` | Whether to nest tasks by their namespace in the tree view. |
35+
| Setting | Type | Allowed Values | Default | Description |
36+
| ----------------- | --------- | --------------------------------- | ----------- | ----------------------------------------------------------------------- |
37+
| `updateOn` | `string` | `"manual"`, `"save"` | `"save"` | When the list of tasks should be updated. |
38+
| `path` | `string` | | `"task"` | Path to the Task binary. Can also the name of a binary in your `$PATH`. |
39+
| `checkForUpdates` | `boolean` | | `true` | Check if there is a newer version of Task on startup. |
40+
| `tree.nesting` | `boolean` | | `true` | Whether to nest tasks by their namespace in the tree view. |
41+
| `tree.sort` | `sort` | `default`, `alphanumeric`, `none` | `"default"` | The order in which to display tasks in the tree view. |

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,16 @@
260260
"type": "boolean",
261261
"default": true,
262262
"description": "Whether to nest tasks by their namespace in the tree view."
263+
},
264+
"sort": {
265+
"type": "string",
266+
"enum": [
267+
"default",
268+
"alphanumeric",
269+
"none"
270+
],
271+
"default": "default",
272+
"description": "The order in which to display tasks in the tree view."
263273
}
264274
}
265275
}

src/services/taskfile.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ type ReleaseRequest = Endpoints["GET /repos/{owner}/{repo}/releases/latest"]["pa
1313
type ReleaseResponse = Endpoints["GET /repos/{owner}/{repo}/releases/latest"]["response"];
1414

1515
const minimumRequiredVersion = '3.23.0';
16+
const minimumRequiredVersionForSorting = '3.24.0';
1617

1718
class TaskfileService {
1819
private static _instance: TaskfileService;
1920
private static outputChannel: vscode.OutputChannel;
2021
private lastTaskName: string | undefined;
2122
private lastTaskDir: string | undefined;
23+
private version: semver.SemVer | undefined;
2224

2325
private constructor() {
2426
TaskfileService.outputChannel = vscode.window.createOutputChannel('Task');
@@ -46,33 +48,34 @@ class TaskfileService {
4648
// If the version is a devel version, ignore all version checks
4749
if (stdout.includes("devel")) {
4850
log.info("Using development version of task");
51+
this.version = new semver.SemVer("999.0.0");
4952
return resolve("ready");
5053
}
5154

5255
// Get the installed version of task (if any)
53-
let version = this.parseVersion(stdout);
56+
this.version = this.parseVersion(stdout);
5457

5558
// If there is an error fetching the version, assume task is not installed
56-
if (stderr !== "" || version === undefined) {
57-
log.error(version ? stderr : "Version is undefined");
59+
if (stderr !== "" || this.version === undefined) {
60+
log.error(this.version ? stderr : "Version is undefined");
5861
vscode.window.showErrorMessage("Task command not found.", "Install").then(this.buttonCallback);
5962
return resolve("notInstalled");
6063
}
6164

6265
// If the current version is older than the minimum required version, show an error
63-
if (version && version.compare(minimumRequiredVersion) < 0) {
64-
log.error(`Task v${minimumRequiredVersion} is required to run this extension. The current version is v${version}`);
65-
vscode.window.showErrorMessage(`Task v${minimumRequiredVersion} is required to run this extension. The current version is v${version}.`, "Update").then(this.buttonCallback);
66+
if (this.version && this.version.compare(minimumRequiredVersion) < 0) {
67+
log.error(`Task v${minimumRequiredVersion} is required to run this extension. The current version is v${this.version}`);
68+
vscode.window.showErrorMessage(`Task v${minimumRequiredVersion} is required to run this extension. The current version is v${this.version}.`, "Update").then(this.buttonCallback);
6669
return resolve("outOfDate");
6770
}
6871

6972
// If a newer version is available, show a message
7073
// TODO: what happens if the user is offline?
7174
if (checkForUpdates) {
7275
this.getLatestVersion().then((latestVersion) => {
73-
if (version && latestVersion && version.compare(latestVersion) < 0) {
74-
log.info(`A new version of Task is available. Current version: v${version}, Latest version: v${latestVersion}`);
75-
vscode.window.showInformationMessage(`A new version of Task is available. Current version: v${version}, Latest version: v${latestVersion}`, "Update").then(this.buttonCallback);
76+
if (this.version && latestVersion && this.version.compare(latestVersion) < 0) {
77+
log.info(`A new version of Task is available. Current version: v${this.version}, Latest version: v${latestVersion}`);
78+
vscode.window.showInformationMessage(`A new version of Task is available. Current version: v${this.version}, Latest version: v${latestVersion}`, "Update").then(this.buttonCallback);
7679
}
7780
return resolve("ready");
7881
}).catch((err) => {
@@ -150,7 +153,16 @@ class TaskfileService {
150153
public async read(dir: string): Promise<models.Taskfile> {
151154
log.info(`Searching for taskfile in: "${dir}"`);
152155
return await new Promise((resolve, reject) => {
153-
let command = this.command('--list-all --json');
156+
let additionalFlags = "";
157+
// Sorting
158+
if (settings.treeSort !== "default") {
159+
if (this.version && this.version.compare(minimumRequiredVersionForSorting) < 0) {
160+
vscode.window.showWarningMessage(`Task version v${minimumRequiredVersionForSorting} is required to change the sort order. Falling back to "default".`, "Update").then(this.buttonCallback);
161+
} else {
162+
additionalFlags = ` --sort ${settings.treeSort}`;
163+
}
164+
}
165+
let command = this.command(`--list-all --json${additionalFlags}`);
154166
cp.exec(command, { cwd: dir }, (err: cp.ExecException | null, stdout: string) => {
155167
if (err) {
156168
log.error(err);

src/utils/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Settings {
77
public path!: string;
88
public checkForUpdates!: boolean;
99
public treeNesting!: boolean;
10+
public treeSort!: string;
1011

1112
constructor() {
1213
this.update();
@@ -28,6 +29,7 @@ class Settings {
2829
this.path = config.get("path") ?? "task";
2930
this.checkForUpdates = config.get("checkForUpdates") ?? true;
3031
this.treeNesting = config.get("tree.nesting") ?? true;
32+
this.treeSort = config.get("tree.sort") ?? "default";
3133
}
3234
}
3335

0 commit comments

Comments
 (0)