Skip to content

Commit c9881df

Browse files
committed
chore: remove support for versions < 3.23
1 parent b80e840 commit c9881df

File tree

3 files changed

+34
-46
lines changed

3 files changed

+34
-46
lines changed

src/providers/taskTreeDataProvider.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ export class TaskTreeDataProvider implements vscode.TreeDataProvider<elements.Tr
4242
return Promise.resolve([]);
4343
}
4444

45-
// Check if the workspace folder is the same as the taskfile location.
46-
// If there is no location available (Task v3.22 or older), compare against the workspace instead.
47-
// This has the downside the tasks from Taskfiles outside of the workspace folder might be shown.
48-
if (vscode.workspace.workspaceFolders[0].uri.fsPath !== (this._taskfiles[0].location ? path.dirname(this._taskfiles[0].location) : this._taskfiles[0].workspace)) {
49-
return Promise.resolve([]);
50-
}
51-
5245
var tasks: models.Task[] | undefined;
5346
var parentNamespace = "";
5447
var workspace = "";
@@ -128,20 +121,14 @@ export class TaskTreeDataProvider implements vscode.TreeDataProvider<elements.Tr
128121
getWorkspaces(): elements.WorkspaceTreeItem[] {
129122
let workspaceTreeItems: elements.WorkspaceTreeItem[] = [];
130123
this._taskfiles?.forEach(taskfile => {
131-
vscode.workspace.workspaceFolders?.forEach(workspace => {
132-
// Check if the workspace folder is the same as the taskfile location.
133-
// If there is no location available (Task v3.22 or older), compare against the workspace instead.
134-
// This has the downside the tasks from Taskfiles outside of the workspace folder might be shown.
135-
if (workspace.uri.fsPath === (taskfile.location ? path.dirname(taskfile.location) : taskfile.workspace)) {
136-
let workspaceTreeItem = new elements.WorkspaceTreeItem(
137-
workspace.name,
138-
workspace.uri.fsPath,
139-
taskfile.tasks,
140-
vscode.TreeItemCollapsibleState.Expanded
141-
);
142-
workspaceTreeItems = workspaceTreeItems.concat(workspaceTreeItem);
143-
}
144-
});
124+
let dir = path.dirname(taskfile.location);
125+
let workspaceTreeItem = new elements.WorkspaceTreeItem(
126+
path.basename(dir),
127+
dir,
128+
taskfile.tasks,
129+
vscode.TreeItemCollapsibleState.Expanded
130+
);
131+
workspaceTreeItems = workspaceTreeItems.concat(workspaceTreeItem);
145132
});
146133
return workspaceTreeItems;
147134
}

src/services/taskfile.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ const octokit = new Octokit();
1212
type ReleaseRequest = Endpoints["GET /repos/{owner}/{repo}/releases/latest"]["parameters"];
1313
type ReleaseResponse = Endpoints["GET /repos/{owner}/{repo}/releases/latest"]["response"];
1414

15-
const minimumRequiredVersion = '3.19.1';
16-
const minimumRecommendedVersion = '3.23.0';
15+
const minimumRequiredVersion = '3.23.0';
1716

1817
class TaskfileService {
1918
private static _instance: TaskfileService;
@@ -61,12 +60,6 @@ class TaskfileService {
6160
return resolve("outOfDate");
6261
}
6362

64-
// If the current version is older than the minimum recommended version, show a warning
65-
if (version && version.compare(minimumRecommendedVersion) < 0) {
66-
vscode.window.showWarningMessage(`Task v${minimumRecommendedVersion} is recommended to run this extension. Your current version is v${version} which doesn't support some features.`, "Update").then(this.buttonCallback);
67-
return resolve("ready");
68-
}
69-
7063
// If a newer version is available, show a message
7164
// TODO: what happens if the user is offline?
7265
if (settings.checkForUpdates) {
@@ -143,10 +136,13 @@ class TaskfileService {
143136
}
144137

145138
public async read(dir: string): Promise<models.Taskfile> {
146-
return await new Promise((resolve) => {
139+
return await new Promise((resolve, reject) => {
147140
let command = this.command('--list-all --json');
148141
cp.exec(command, { cwd: dir }, (_, stdout: string) => {
149142
var taskfile: models.Taskfile = JSON.parse(stdout);
143+
if (path.dirname(taskfile.location) !== dir) {
144+
return reject();
145+
}
150146
taskfile.workspace = dir;
151147
return resolve(taskfile);
152148
});
@@ -193,11 +189,6 @@ class TaskfileService {
193189
}
194190

195191
public async goToDefinition(task: models.Task, preview: boolean = false): Promise<void> {
196-
if (task.location === undefined) {
197-
vscode.window.showErrorMessage(`Go to definition requires Task v3.23.0 or higher.`, "Update").then(this.buttonCallback);
198-
return;
199-
}
200-
201192
let position = new vscode.Position(task.location.line - 1, task.location.column - 1);
202193
let range = new vscode.Range(position, position);
203194

src/task.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,29 @@ export class TaskExtension {
1717

1818
public async update(): Promise<void> {
1919
// Do version checks
20-
await services.taskfile.checkInstallation().then((status): Promise<models.Taskfile[]> => {
20+
await services.taskfile.checkInstallation().then((status): Promise<PromiseSettledResult<models.Taskfile>[]> => {
21+
22+
// Set the status
2123
vscode.commands.executeCommand('setContext', 'vscode-task:status', status);
22-
if (status === "ready") {
23-
// Read taskfiles
24-
let p: Promise<models.Taskfile>[] = [];
25-
vscode.workspace.workspaceFolders?.forEach((folder) => {
26-
p.push(services.taskfile.read(folder.uri.fsPath));
27-
});
28-
return Promise.all(p);
24+
25+
// If the status is not "ready", reject the promise
26+
if (status !== "ready") {
27+
return Promise.reject();
28+
}
29+
30+
// Read taskfiles
31+
let p: Promise<models.Taskfile>[] = [];
32+
vscode.workspace.workspaceFolders?.forEach((folder) => {
33+
p.push(services.taskfile.read(folder.uri.fsPath));
34+
});
35+
return Promise.allSettled(p);
36+
37+
// If there are no valid taskfiles, set the status to "noTaskfile"
38+
}).then(results => {
39+
this._taskfiles = results.filter(result => result.status === "fulfilled").map(result => <PromiseFulfilledResult<any>>result).map(result => result.value);
40+
if (this._taskfiles.length === 0) {
41+
vscode.commands.executeCommand('setContext', 'vscode-task:status', "noTaskfile");
2942
}
30-
return Promise.resolve([]);
31-
}).then((taskfiles: models.Taskfile[]) => {
32-
this._taskfiles = taskfiles;
3343
});
3444
}
3545

0 commit comments

Comments
 (0)