aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-vscode/src/features/tasks/tasks.ts
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
commit7458b969c5d9971e89d187b687e1924e78da427e (patch)
treeee3dbf95c728cf407bf49a27826b541e9264a8bd /packages/bun-vscode/src/features/tasks/tasks.ts
parentd4a2c29131ec154f5e4db897d4deedab2002cbc4 (diff)
parente91436e5248d947b50f90b4a7402690be8a41f39 (diff)
downloadbun-7458b969c5d9971e89d187b687e1924e78da427e.tar.gz
bun-7458b969c5d9971e89d187b687e1924e78da427e.tar.zst
bun-7458b969c5d9971e89d187b687e1924e78da427e.zip
Merge branch 'main' into postinstall_3
Diffstat (limited to 'packages/bun-vscode/src/features/tasks/tasks.ts')
-rw-r--r--packages/bun-vscode/src/features/tasks/tasks.ts59
1 files changed, 59 insertions, 0 deletions
diff --git a/packages/bun-vscode/src/features/tasks/tasks.ts b/packages/bun-vscode/src/features/tasks/tasks.ts
new file mode 100644
index 000000000..aabeb3920
--- /dev/null
+++ b/packages/bun-vscode/src/features/tasks/tasks.ts
@@ -0,0 +1,59 @@
+import * as vscode from "vscode";
+import { providePackageJsonTasks } from "./package.json";
+
+interface BunTaskDefinition extends vscode.TaskDefinition {
+ script: string;
+}
+
+export class BunTask extends vscode.Task {
+ declare definition: BunTaskDefinition;
+
+ constructor({
+ script,
+ name,
+ detail,
+ execution,
+ scope = vscode.TaskScope.Workspace,
+ }: {
+ script: string;
+ name: string;
+ detail?: string;
+ scope?: vscode.WorkspaceFolder | vscode.TaskScope.Global | vscode.TaskScope.Workspace;
+ execution?: vscode.ProcessExecution | vscode.ShellExecution | vscode.CustomExecution;
+ }) {
+ super({ type: "bun", script }, scope, name, "bun", execution);
+ this.detail = detail;
+ }
+}
+
+/**
+ * Registers the task provider for the bun extension.
+ */
+export function registerTaskProvider(context: vscode.ExtensionContext) {
+ const taskProvider: vscode.TaskProvider<BunTask> = {
+ provideTasks: async () => await providePackageJsonTasks(),
+ resolveTask: task => resolveTask(task),
+ };
+ context.subscriptions.push(vscode.tasks.registerTaskProvider("bun", taskProvider));
+}
+
+/**
+ * Parses tasks defined in the vscode tasks.json file.
+ * For more information, see https://code.visualstudio.com/api/extension-guides/task-provider
+ */
+export function resolveTask(task: BunTask): BunTask | undefined {
+ // Make sure the task has a script defined
+ const definition: BunTask["definition"] = task.definition;
+ if (!definition.script) return task;
+ const shellCommand = definition.script.startsWith("bun ") ? definition.script : `bun ${definition.script}`;
+
+ const newTask = new vscode.Task(
+ definition,
+ task.scope ?? vscode.TaskScope.Workspace,
+ task.name,
+ "bun",
+ new vscode.ShellExecution(shellCommand),
+ ) as BunTask;
+ newTask.detail = `${shellCommand} - tasks.json`;
+ return newTask;
+}