From cc0eaf29625d39782334c7a8acf31689496eba8d Mon Sep 17 00:00:00 2001 From: nefrob <25070989+nefrob@users.noreply.github.com> Date: Thu, 2 Jan 2025 13:18:49 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20task=20runner=20support=20(#7?= =?UTF-8?q?0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: first pass * refactor: use task provider class * refactor: follow task example * chore: update docs --- CHANGELOG.md | 4 ++++ README.md | 1 + package.json | 19 +++++++++++++++++++ src/extension.ts | 5 +++++ src/tasks.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 src/tasks.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index fd4a8cf..5fc40a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- Task runner support + ## [0.7.0] - 2025-01-02 ### Added diff --git a/README.md b/README.md index 4d0c3c7..c62edea 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Commands: - Format on save - Run recipe +- Task running Demo: diff --git a/package.json b/package.json index 17cc42e..5869d2e 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,25 @@ "command": "vscode-just.runRecipe", "title": "Just: Run Recipe" } + ], + "taskDefinitions": [ + { + "type": "vscode-just", + "when": "shellExecutionSupported", + "required": [ + "task" + ], + "properties": { + "task": { + "type": "string", + "description": "The just command." + }, + "args": { + "type": "array", + "description": "Arguments to pass to the task" + } + } + } ] }, "devDependencies": { diff --git a/src/extension.ts b/src/extension.ts index 1a69193..13dc182 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -5,6 +5,7 @@ import { formatWithExecutable } from './format'; import { getLauncher } from './launcher'; import { getLogger } from './logger'; import { runRecipeCommand } from './recipe'; +import { TaskProvider } from './tasks'; export const activate = (context: vscode.ExtensionContext) => { console.debug(`${EXTENSION_NAME} activated`); @@ -27,6 +28,10 @@ export const activate = (context: vscode.ExtensionContext) => { }, ); context.subscriptions.push(runRecipeDisposable); + + context.subscriptions.push( + vscode.tasks.registerTaskProvider(EXTENSION_NAME, new TaskProvider()), + ); }; export const deactivate = () => { diff --git a/src/tasks.ts b/src/tasks.ts new file mode 100644 index 0000000..b1461b6 --- /dev/null +++ b/src/tasks.ts @@ -0,0 +1,47 @@ +import * as vscode from 'vscode'; + +import { EXTENSION_NAME } from './const'; +import { getJustPath } from './utils'; + +export interface TaskDefinition extends vscode.TaskDefinition { + task: string; + args?: string[]; +} + +export class TaskProvider implements vscode.TaskProvider { + public constructor() {} + + public provideTasks() { + return [getDefaultRecipeTask()]; + } + + public resolveTask(_task: vscode.Task) { + if (_task.definition.type !== EXTENSION_NAME) return undefined; + + const definition = _task.definition as TaskDefinition; + + return new vscode.Task( + definition, + _task.scope ?? vscode.TaskScope.Workspace, + definition.label ?? 'Run recipe', + definition.type, + new vscode.ShellExecution(definition.task, definition.args ?? []), + ); + } +} + +export const getDefaultRecipeTask = () => { + const runDefaultRecipeTask = new vscode.Task( + { type: EXTENSION_NAME, task: 'just' }, + vscode.TaskScope.Workspace, + 'Run default recipe', + EXTENSION_NAME, + new vscode.ShellExecution(getJustPath()), + ); + runDefaultRecipeTask.presentationOptions = { + showReuseMessage: false, + close: false, + }; + + return runDefaultRecipeTask; +};