-
Notifications
You must be signed in to change notification settings - Fork 28.8k
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
Allow users to customize tasks provided from TaskProvider #58836
Comments
This is currently not possible. The closest duplicate is #43782. One option would be to put the port into the settings since a task can reference settings values. But then you need to remove the port from the TaskDefinition. |
@dbaeumer Is there any way to work around this? |
The problem here is if the property you want to let the user configure is a defining property of the task (e.g. it goes into the tasks key). In this case the tasks are different and there is no way to match these tasks. However since the issue got opened VS Code has introduced the concept of a Just to clarify: the resolveTask hook (as explained earlier) is not to change properties of a task. It is imagined to be a performance optimization so that a task provider can provide task stubs (including all arguments that make the key) and add the rest later. Can you provide an example of what exactly you want to achieve? |
Oh I haven't seen any |
Actually what you want is to have a separate Process or Shell task based on task's properties. One idea would be to support access task properties as variables as we allow settings and environemt. Something like |
I think my biggest confusion here is that I assumed
Couldn't you do the same thing for tasks? |
The However I see the confusion. @EricJizbaMSFT to make things consistent we should think about a |
I think some sort of additional task property could be useful, but I'm not sure where the user should set it. It isn't something you would want to commit in a repository, so I don't think it makes sense to have in tasks.json. |
Fair enough, but debugConfig and tasks feel much more related and so I think it's more important for those two to have consistency. In both cases, you're providing a json configuration to a file in the
That still confuses me. After all,
I'm not entirely following this. Can you give a more detailed example?
As discussed in my original comment, we provide a task to run the Azure Functions host on your local machine for a functions project. We've had users report that they have multiple projects in one repo and they want to run both at the same time. They immediately run into problems because of conflicting ports. It would be great if they could customize one of their tasks to have a non-default port and I think it makes sense for them to commit that change. @dbaeumer suggested putting the port in a settings file which is a decent workaround, but it still feels more natural if the user can customize a task right in their tasks.json. |
The idea of Regarding the property. What I imagine is for a task like this:
The provided process would have a shell or process command with something like this in its command I do agree to @alexr00 comment that this might not be a good user story when this is checked into the repository. |
Can you guys give example scenarios and reasoning why you wouldn't want to commit this kind of thing to a repository? The only scenario I've brought up so far is running multiple function projects in the same repo and you have to specify different ports otherwise you can't run both at the same time. This seems like something you would definitely want check in to your repo so that everyone who clones it can run both without any extra configuration needed. |
Something like ${task:port}, ${task:sourceFile} or what have you, is exactly what I want. |
@EricJizbaMSFT my concern is that if the provided value is something that users want to change, then different contributors to a project might want to have different values. I do think that having these properties on tasks is a good idea and the best options I've heard for passing properties to provided tasks. |
Where can I find into about "tasks": [
{
"type": "dart",
"command": "dartdoc",
"args": [
"--favicon" // This is added by the user
],
"problemMatcher": [],
"label": "dart: dartdoc"
}
] VS Code shows a cog next to my contributed tasks that copy them to tasks.json, which I assumed was for customisation - but if I do customise them, they fail to run. Is there another way to do this? What's the cog for on the contributed tasks if not to customise the task? |
Documentation of custom execution tasks: https://code.visualstudio.com/api/extension-guides/task-provider#customexecution and https://code.visualstudio.com/api/references/vscode-api#CustomExecution The cog icon is for customizing the problem matcher, run options, presentation, and other properties that exist on all tasks. Some tasks types might be able to handle you changing their "definition" properties (i.e. properties that are specific to that task In your case the |
Ah, I see. I don't think that helps me here. I'm using
I'm the author of the Dart extension - I'm trying to understand how to make the extension support Thanks! |
As the extension author you can implement Looks like the documentation doesn't outline this well. I'll update it. |
@alexr00 I do have a Are there any samples that already support this that I could use as a reference? |
The built in NPM task provider does this: vscode/extensions/npm/src/tasks.ts Lines 43 to 60 in 0de8d51
You do need to |
aha, that was it - thanks! |
@alexr00 I think this solves my original issue (although it has been a while so I don't 100% remember 😝). Unless you have some unfinished work you planned to do for this, I think it's good to close |
@alexr00 has anything changed around this in the latest version? This doesn't seem to be working for me now. I've created a {
"version": "2.0.0",
"tasks": [
{
"type": "dart",
"command": "dartdoc",
"args": [
"foo"
],
"problemMatcher": [],
"label": "dart: dartdoc foo"
}
]
} There is no contributed task for this (there is one for public async resolveTask(task: DartTask, token?: vs.CancellationToken): Promise<vs.Task> {
console.log(`Resolving task for ${task.definition.command} ${task.definition.args?.join(" ")}`);
const scope: any = task.scope;
const cwd = "uri" in scope ? fsPath((scope as vs.WorkspaceFolder).uri) : undefined;
const newDefinition = { ...task.definition };
const options = this.getOptions(newDefinition);
// We *must* return a new Task here, otherwise the task cannot be customised
// in task.json.
// https://github.com/microsoft/vscode/issues/58836#issuecomment-696620105
const newTask: DartTask = new vs.Task(
newDefinition,
task.scope || vs.TaskScope.Workspace,
task.name,
task.source,
await this.createTaskExecution(this.sdks, newDefinition, cwd),
undefined,
);
newTask.problemMatchers = (newTask.problemMatchers && newTask.problemMatchers.length ? newTask.problemMatchers : options?.problemMatchers) ?? [];
newTask.group = task.group ?? options?.group;
newTask.isBackground = task.isBackground || (options?.isBackground ?? false);
return newTask;
} However when I run the Run Task command and then select the Dart section, it immediately reports:
Is there anything else special about the return value from |
@DanTup I'm not able to repro the behavior you're seeing. I installed the Dart extension from Dart Code and copied your task. Any other steps to repro? |
@alexr00 the release version doesn't have the latest code, so you'd be better cloning from https://github.com/Dart-Code/Dart-Code. You should only need to |
@DanTup any errors in the developer tools? You must use the exact same object for the task definition, and there should be an error for that in the dev tools since it looks like you're creating a new definition. |
@alexr00 there was an error in the console (and it pops up as a notification), though it seems incorrect/misleading: You were right though - it was because I was creating new objects for the definition. It may be useful to detect this and report a clearer error. Thanks for the help! |
I'm attempting to move over to
TaskProvider
for our extension rather than custom shell tasks. Per these docs, the TaskDefinition provided through TaskProvider is used "To uniquely identify a task in the system", but I don't just want to "identify" the task, I want to let users customize it as well.For example, we want to provide a task that starts the Azure Functions host before a user debugs. The launch.json would look like this:
And I would provide the "func: host start" task like this:
However, as soon as I try to change the port, I get an error like this:
cc @dbaeumer continuing the conversation from here: #57707. You mentioned this issue #4758, but that seems focused on prompting users. We don't want to prompt users at all - we just want to give them the ability to customize if necessary.
The text was updated successfully, but these errors were encountered: