Skip to content
Open
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
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
}
}
]
}
}
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,25 @@
}
}
}
}
},
"taskDefinitions": [
{
"type": "go-task",
"required": [
"name"
],
"properties": {
"task": {
"type": "string",
"description": "The Taskfile task to customize"
},
"location": {
"type": "string",
"description": "The Taskfile file that provides the task. Can be omitted."
}
}
}
]
},
"scripts": {
"preinstall": "npx only-allow pnpm",
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { TaskExtension } from './task.js';

export function activate(context: vscode.ExtensionContext) {
log.info("Extension activated");

// Create a new instance of Tagger
let taskExtension: TaskExtension = new TaskExtension();

// Registration
taskExtension.registerCommands(context);
taskExtension.registerListeners(context);

taskExtension.registerTaskProvider(context);
// Refresh the tasks list
taskExtension.refresh();
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/taskfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TaskfileService {
return this._instance ?? (this._instance = new this());
}

private command(command?: string, cliArgs?: string): string {
public command(command?: string, cliArgs?: string): string {
if (command === undefined) {
return settings.path;
}
Expand Down
46 changes: 45 additions & 1 deletion src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,28 @@ import { taskfileSvc } from './services/taskfile.js';
import { log } from './utils/log.js';
import { configKey, oldConfigKey, settings, UpdateOn } from './utils/settings.js';

export class TaskExtension {
function resolveTaskForNamespace(ns: Namespace) : vscode.Task[] {
const result: vscode.Task[] = [];
if (ns.tasks.length > 0) {
ns.tasks.forEach(task => {
const definition = {"type":TaskExtension.TaskExtensionTaskType, "name":task.name, "location":task.location}
const execution = new vscode.ShellExecution(`${taskfileSvc.command()} ${task.name}`)
const vTask = new vscode.Task(definition, vscode.TaskScope.Workspace, task.name, TaskExtension.TaskExtensionTaskType, execution);
result.push(vTask);
});
}
if (ns.namespaces === undefined) {
return result
}
const nss = new Map<string, Namespace>(Object.entries(ns.namespaces))
nss.forEach((obj) => {
result.push(...resolveTaskForNamespace(obj))
});
return result
}

export class TaskExtension implements vscode.TaskProvider<vscode.Task> {
public static TaskExtensionTaskType = 'go-task';
private _taskfiles: Namespace[] = [];
private _activityBar: ActivityBar;
private _watcher: vscode.FileSystemWatcher;
Expand All @@ -22,6 +43,17 @@ export class TaskExtension {
this._status = settings.tree.status;
vscode.commands.executeCommand('setContext', 'vscode-task:treeNesting', this._nesting);
}


public async provideTasks(token: vscode.CancellationToken): Promise<vscode.Task[]> {
await this.refresh();
return this.getVscodeTask();
}
public resolveTask(_task: vscode.Task, token: vscode.CancellationToken): vscode.ProviderResult<vscode.Task> {
const definition = {"type":TaskExtension.TaskExtensionTaskType, "name":_task.name}
const execution = new vscode.ShellExecution(`${taskfileSvc.command()} ${definition.name}`)
return new vscode.Task(definition, _task.scope ?? vscode.TaskScope.Workspace, definition.name, 'go-task', execution);
}

public async update(checkForUpdates?: boolean): Promise<void> {
// Do version checks
Expand Down Expand Up @@ -257,13 +289,25 @@ export class TaskExtension {
vscode.workspace.onDidChangeConfiguration(event => { this._onDidChangeConfiguration(event); });
}

public registerTaskProvider(context: vscode.ExtensionContext): void {
vscode.tasks.registerTaskProvider(TaskExtension.TaskExtensionTaskType, this);
}
private async getVscodeTask(): Promise<vscode.Task[]> {
const result: vscode.Task[] = [];
this._taskfiles.forEach(taskfile => {
result.push(...resolveTaskForNamespace(taskfile))
});
return result;
}

private _loadTasksFromTaskfile() {
let items: vscode.QuickPickItem[] = [];
this._taskfiles.forEach(taskfile => {
if (taskfile.tasks.length > 0) {
items = items.concat(new QuickPickTaskSeparator(taskfile));
taskfile.tasks.forEach(task => {
items = items.concat(new QuickPickTaskItem(taskfile, task));

});
}
});
Expand Down