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

Task Provider Sample shows no tasks #1019

Closed
kenkit opened this issue May 9, 2024 · 2 comments
Closed

Task Provider Sample shows no tasks #1019

kenkit opened this issue May 9, 2024 · 2 comments

Comments

@kenkit
Copy link

kenkit commented May 9, 2024

Extension sample

task-provider-sample

VS Code version

1.89

What went wrong?

I have tried using the task provider sample but I have not managed to get it to list any tasks.
I even tried a sample I found here which uses the same api but it also doesn't show anything. Upon debugging I can see that the methods for retrieving tasks are called and they do return tasks.
This is the other example I tried from SO

@kenkit
Copy link
Author

kenkit commented May 9, 2024

Fixed with this code still don't understand where my mistake was.
Could it be the constructor ??

/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';


export class TaskProvider implements vscode.TaskProvider {
	static esp_tool_task_type = 'esp_tool_tasks';
	private tasks: vscode.Task[] | undefined;

	// We use a CustomExecution task when state needs to be shared across runs of the task or when 
	// the task requires use of some VS Code API to run.
	// If you don't need to share state between runs and if you don't need to execute VS Code API in your task, 
	// then a simple ShellExecution or ProcessExecution should be enough.
	// Since our build has this shared state, the CustomExecution is used below.

	constructor(private workspaceRoot: string) { }

	public async provideTasks(): Promise<vscode.Task[]> {
		return this.getTasks();
	}

	public resolveTask(_task: vscode.Task): vscode.Task | undefined {
			return this.getTask(_task.definition);
	}

	private getTasks(): vscode.Task[] {
		if (this.tasks !== undefined) {
			return this.tasks;
		}

		this.tasks = [];
		this.tasks.push(this.getTask({type:TaskProvider.esp_tool_task_type}));
		return this.tasks;
	}

	private getTask(definition: any): vscode.Task {
		if (definition === undefined) {
			definition = {type: TaskProvider.esp_tool_task_type};
		}
		const execution = new vscode.ShellExecution("echo \"Hello World\"");
		const problemMatchers = ["$myProblemMatcher"];
		return (new vscode.Task(definition, vscode.TaskScope.Workspace,
				"Build", "myExtension", execution, problemMatchers));
	}
}

@kenkit kenkit closed this as completed May 9, 2024
@chipbite
Copy link

chipbite commented Jul 10, 2024

Hey @kenkit could you share a working project with the sample?

I tried to get it working today but was unable to. Things "work" (compiles, runs, activates, etc), except it always says No [...] tasks found.

I also looked at the task provider hello world sample on SO you linked to and found more questions of the same nature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants