Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add task runner support #70

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
Loading