Skip to content

Commit dbd181f

Browse files
Redefine the task definition.
Add tasks for buildifier and unused deps.
1 parent d7ea3ce commit dbd181f

File tree

2 files changed

+66
-13
lines changed

2 files changed

+66
-13
lines changed

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,21 @@
4545
},
4646
"taskDefinitions": [
4747
{
48-
"type": "bazel"
48+
"type": "bazel",
49+
"required": [
50+
"name",
51+
"task"
52+
],
53+
"properties": {
54+
"name": {
55+
"type": "string",
56+
"description": "The task name"
57+
},
58+
"task": {
59+
"type": "string",
60+
"description": "The task command"
61+
}
62+
}
4963
}
5064
]
5165
},

src/bazelTaskProvider.ts

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import * as vscode from 'vscode';
33

44
export class BazelTaskProvider implements vscode.TaskProvider {
55

6-
static BazelType = 'bazel';
7-
private bazelPromise: Thenable<vscode.Task[]> | undefined = undefined;
6+
static BazelType = 'bazel';
7+
private bazelPromise: Thenable<vscode.Task[]> | undefined = undefined;
88

9-
public provideTasks(): Thenable<vscode.Task[]> | undefined {
9+
public provideTasks(): Thenable<vscode.Task[]> | undefined {
1010
if (!this.bazelPromise) {
1111
this.bazelPromise = getBazelTasks();
1212
}
@@ -18,7 +18,7 @@ export class BazelTaskProvider implements vscode.TaskProvider {
1818
if (task) {
1919
// resolveTask requires that the same definition object be used.
2020
const definition: BazelTaskDefinition = <any>_task.definition;
21-
return new vscode.Task(definition, _task.scope ?? vscode.TaskScope.Workspace, definition.task, 'bazel', new vscode.ShellExecution(`bazel ${definition.task}`));
21+
return new vscode.Task(definition, _task.scope ?? vscode.TaskScope.Workspace, definition.name, definition.type, new vscode.ShellExecution(`${definition.task}`));
2222
}
2323
return undefined;
2424
}
@@ -30,15 +30,54 @@ interface BazelTaskDefinition extends vscode.TaskDefinition {
3030
}
3131

3232
async function getBazelTasks(): Promise<vscode.Task[]> {
33-
const result: vscode.Task[] = [];
3433

35-
const kind: BazelTaskDefinition = {
36-
type: 'bazel',
37-
};
34+
const tasksDefenitions: BazelTaskDefinition[] = [];
3835

39-
result.push(new vscode.Task(kind, vscode.TaskScope.Workspace, 'Build', 'bazel', new vscode.ShellExecution(`bazel build //...`)));
40-
result.push(new vscode.Task(kind, vscode.TaskScope.Workspace, 'Test', 'bazel', new vscode.ShellExecution(`bazel test //...`)));
41-
result.push(new vscode.Task(kind, vscode.TaskScope.Workspace, 'Dependencies', 'bazel', new vscode.ShellExecution(`bazel query --notool_deps --noimplicit_deps \"deps(//...)\" --output graph`)));
36+
tasksDefenitions.push(
37+
{
38+
type: 'bazel',
39+
name: 'Build',
40+
task: 'bazel build //...'
41+
}
42+
);
43+
44+
tasksDefenitions.push(
45+
{
46+
type: 'bazel',
47+
name: 'Test',
48+
task: 'bazel test //...'
49+
}
50+
);
51+
52+
tasksDefenitions.push(
53+
{
54+
type: 'bazel',
55+
name: 'Dependencies',
56+
task: 'bazel query --notool_deps --noimplicit_deps \"deps(//...)\" --output graph'
57+
}
58+
);
59+
60+
tasksDefenitions.push(
61+
{
62+
type: 'bazel',
63+
name: 'Formatting',
64+
task: 'buildifier -r . && echo \"Formatted\"'
65+
}
66+
);
67+
68+
tasksDefenitions.push(
69+
{
70+
type: 'bazel',
71+
name: 'Unused deps',
72+
task: 'unused_deps //...'
73+
}
74+
);
75+
76+
const result: vscode.Task[] = [];
77+
78+
tasksDefenitions.forEach(function (value) {
79+
result.push(new vscode.Task(value, vscode.TaskScope.Workspace, `${value.name}`, `${value.type}`, new vscode.ShellExecution(`${value.task}`)));
80+
});
4281

43-
return result;
82+
return result;
4483
}

0 commit comments

Comments
 (0)