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

VS Code 1.81.1 starts *all* onTaskType extensions when debugging #192043

Closed
larsch opened this issue Sep 2, 2023 · 12 comments · Fixed by #221967 or #223136
Closed

VS Code 1.81.1 starts *all* onTaskType extensions when debugging #192043

larsch opened this issue Sep 2, 2023 · 12 comments · Fixed by #221967 or #223136
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders tasks Task system issues verified Verification succeeded
Milestone

Comments

@larsch
Copy link

larsch commented Sep 2, 2023

This issue is to ressurrect #175821 which was fixed, then closed, then reverted without comment.

The issue remains in 1.81.1. Attempting to run any task loads ALL extensions.

For example, for me it loads PlatformIO, Rust Analyzer, etc. when I'm working on a C project.

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.81.1
  • OS Version: Linux

Steps to Reproduce:

  1. See VS Code 1.76 starts *all* onTaskType extensions when debugging #175821
@Blokyk
Copy link

Blokyk commented Nov 9, 2023

Any update on this? I'm still encountering this bug using 1.84.2, and it's very overwhelming to have every extension startup all at once (with their associated notifications) when you just want to debug your project :/

@ meganrogge since you were the one to revert the fix commit, could you at least explain why? Ok so it seems that the fix commit was reverted in #185812, and then that revert was reverted itself in #185925 because of the current issue; however, something must have broken, because despite the double-revert, the original issue (i.e. the current one) is still happening in 1.84.2

@hyangah
Copy link

hyangah commented Jan 7, 2024

I am a maintainer of the Go extension. We are observing that the Go extension is activated randomly due to this bug.
Is there any workaround extension authors can use until this issue is addresssed?

@blaine
Copy link

blaine commented Apr 28, 2024

This is an extremely annoying bug. I have the rust-analyzer extension installed, and when I'm working on non-rust projects (e.g., a platformio C++ arduino project), rust-analyzer shows a very urgent red error message at the bottom of my screen. From all the related bugs, it sounds like this is a vscode issue, and extension authors are unable to fix it.

@carsonfarmer
Copy link

Seeing this issue as well from within a Swift project. I found this issue via: rust-lang/rust-analyzer#17018

@meganrogge
Copy link
Contributor

meganrogge commented Jul 17, 2024

I see the issue here. I don't think we ever should've adopted implicit activation for tasks - which means that onTaskType:x is added as an activation event for any extension that contributes a task x.

activationEventsGenerator: (contributions: Configuration.ITaskDefinition[], result: { push(item: string): void }) => {
for (const task of contributions) {
if (task.type) {
result.push(`onTaskType:${task.type}`);
}
}
},

Thus, that extension will get activated when the build task command is run for example because in doing that, we call activate task providers, which fires the events for the whole registry.

for (const definition of TaskDefinitionRegistry.all()) {
result.push(`onTaskType:${definition.taskType}`);
}

We fire events for the whole registry for that case because tasks (including a build task) are provided in the extension programmatically and we want the execution of the task after user request to be expeditious vs waiting for on-demand extension activation.

/**
* A task provider allows to add tasks to the task service.
* A task provider is registered via {@link tasks.registerTaskProvider}.
*/
export interface TaskProvider<T extends Task = Task> {
/**
* Provides tasks.
* @param token A cancellation token.
* @returns an array of tasks
*/
provideTasks(token: CancellationToken): ProviderResult<T[]>;
.

Reverting this should fix it:

#173192

meganrogge added a commit that referenced this issue Jul 17, 2024
@meganrogge meganrogge added this to the July 2024 milestone Jul 17, 2024
@vscodenpa vscodenpa added the unreleased Patch has not yet been released in VS Code Insiders label Jul 17, 2024
@vscodenpa vscodenpa added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Jul 18, 2024
@meganrogge
Copy link
Contributor

This would also happen when debugging if the configured task for debugging lacks a type, which may be undefined

// Nice, we found a configured task!
const task = matchedTasks[0];
if (ConfiguringTask.is(task)) {
return this.tryResolveTask(task);

await this._activateTaskProviders(configuringTask.type);

@meganrogge
Copy link
Contributor

I have to revert this fix once again because we need to activate all task providing extensions when debugging as otherwise, a preLaunchTask might not be found. A user can set their preLaunchTask to be anything.

Similarly, build tasks can be set programmatically, using the TaskGroup API property. Thus, when the build task is run, we need to activate all extensions that contribute tasks.

In order to minimize the number of extension activations, we encourage people to set the type property for their preLaunchTask.

@isidorn
Copy link
Contributor

isidorn commented Jul 19, 2024

This is unfortunate. Is there an alternative approach to fix this issue? Or is there some capability for tasks that we would have to add to tackle this?

@meganrogge
Copy link
Contributor

meganrogge commented Jul 19, 2024

One idea for the debugging case would be to add a task type property for preLaunchTask. #223081

@meganrogge
Copy link
Contributor

meganrogge commented Jul 22, 2024

I can repro when I set preLaunchTask to be ${defaultBuildTask}.

Currently, when ${defaultBuildTask} is used as a preLaunchTask we fetch all tasks, activating all providers, then filter to find the default build task. We then run it, which redundantly activates that provider.

The fix is to wait on activation. If we find a default build task, then its provider will be activated when it's run.

If we don't find one, then we'll fall back to the current behavior - activating all providers.

@connor4312
Copy link
Member

connor4312 commented Jul 22, 2024

I think that's good behavior. We might still be able to add some optimization for the case of extension-provided configurations. Maybe in workspace storage we keep a small LRU (say ~5 entries) to associate labels of tasks with the extensions that provide them, to avoid having to activate all extensions all the time if I run some npm: scriptThatIDontHaveATaskFor?

@isidorn
Copy link
Contributor

isidorn commented Jul 23, 2024

Thanks @meganrogge for improving this. I just tried it out and it behaves better for me. Adding verified label
@larsch if you can still reproduce with the latest VS Code Insiders build do let us know. Thanks!

@isidorn isidorn added the verified Verification succeeded label Jul 23, 2024
@vscodenpa vscodenpa added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Jul 24, 2024
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Sep 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders tasks Task system issues verified Verification succeeded
Projects
None yet
10 participants