-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hx
45 lines (39 loc) · 1.23 KB
/
Main.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import vscode.*;
import Vscode.*;
using Lambda;
class Main {
final context:ExtensionContext;
var runningTasks:Array<TaskExecution> = [];
function new(context) {
this.context = context;
tasks.onDidStartTask(event -> {
runningTasks.push(event.execution);
});
tasks.onDidEndTask(event -> {
runningTasks = runningTasks.filter(execution -> execution.task.name != event.execution.task.name);
});
commands.registerCommand("terminator.run", function(taskName) {
if (taskName == null || taskName == "") {
window.showErrorMessage('Keybinding is missing a task name regex to match against in `args`.');
return;
}
var taskNameRegex = new EReg(taskName, "");
tasks.fetchTasks().then(fetchedTasks -> {
var task = fetchedTasks.find(task -> taskNameRegex.match(task.name));
if (task == null) {
window.showErrorMessage('Could not find a task whose name matches \'$taskName\'.');
} else {
var runningTask = runningTasks.find(execution -> taskNameRegex.match(execution.task.name));
if (runningTask != null) {
runningTask.terminate();
}
tasks.executeTask(task);
}
});
});
}
@:expose("activate")
static function activate(context:ExtensionContext) {
new Main(context);
}
}