Skip to content

Commit

Permalink
✨ Add task runner support (#70)
Browse files Browse the repository at this point in the history
* feat: first pass

* refactor: use task provider class

* refactor: follow task example

* chore: update docs
  • Loading branch information
nefrob authored Jan 2, 2025
1 parent 25579e2 commit cc0eaf2
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Added

- Task runner support

## [0.7.0] - 2025-01-02

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Commands:

- Format on save
- Run recipe
- Task running


Demo:
Expand Down
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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 = () => {
Expand Down
47 changes: 47 additions & 0 deletions src/tasks.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit cc0eaf2

Please sign in to comment.