microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.36k stars 29.31k forks source link

Add a task instancePolicy to task runOptions. #90125

Open alexr00 opened 4 years ago

alexr00 commented 4 years ago

When a task has reached the max number of instances it can have (default is 1, can be changed with instanceLimit) the instancePolicy determines what happens when another instance is started.

History: https://github.com/microsoft/vscode/issues/32264 PR for insanceLimit which is relevant to anyone interested in implementing instancePolicy: https://github.com/microsoft/vscode/pull/89872

alpalla commented 4 years ago

I can keep working on this. Just to reiterate (basing myself off this comment), should instancePolicy provide the following options?

  1. terminate the last instance
  2. terminate the first instance
  3. ask which instance to terminate
  4. do nothing and possibly indicate that the instance limit has been reached

I imagine the first 3 options would also have a restart counterpart.

alexr00 commented 4 years ago
  1. terminate the last instance

Yes, let's call it terminateNewest

  1. terminate the first instance

terminateOldest

  1. ask which instance to terminate

prompt? I'm not 100% on this name yet. But this should be the default and use the existing behavior with the notification.

  1. do nothing and possibly indicate that the instance limit has been reached

I'm not sure which would be more useful here: show no indication that the instance limit has been hit or notify. Maybe we need two options: warn and silent

I don't think we need any restart options since you are effectively restarting by terminating one of the existing instances.

alpalla commented 4 years ago

@alexr00 I'm a little confused about the prompt option. This option asks the user which of the N active instances to terminate, correct? How would this option use the existing behavior with the notification?

So far my understanding for how to handle prompt would be to open the QuickPick and show all instances of the task, then when an instance is selected it would be terminated.

alexr00 commented 4 years ago

For prompt, yes it would be ideal to show the quick pick instead of the notification.

fatfatson commented 4 years ago

waiting for improve

darylknowles commented 4 years ago

In the most recent release I am now getting prompted to restart or terminate when I try to run scripts from the NPM Task explorer from two different open working folders (and package.json files) that happen to share the same name. For example, running "start" from workspace folder 1 then trying to also run "start" from workspace folder 2 causes the prompt. I suspect we're not using the full paths to detect # of instances already running.

aroman commented 3 years ago

any update on this? i think there's a clear and common usecase here for running a server -- you want to terminate the previous process and restart so the port is free

bpasero commented 3 years ago

My primary scenario is triggering the default build task in VSCode (Cmd+Shift+B) a lot of times per day but currently I have to terminate the 2 running tasks from the terminal because they even run detached from the app to survive window reloads.

If there was a way to kill these 2 running tasks before starting the new ones that would be very cool 👍

ludekvodicka commented 2 years ago

Is this feature already implemented? Or is there any way how to force running task restart automatically when the instance is already running?

jej commented 2 years ago

Am I missing an option or a tweak to get rid of this pop-up?...

capture_ecran_20220124-000525

gilescope commented 1 year ago

Every time I click run. Surely there's a setting to just terminate the previous one when I want to run a new one without it asking every time. Every time. Like always. I mean I press run a lot. And it asks every time. Maybe we need some AI ML model to train and realize that I press the kill the existing process button after I press the run button every time. Did I mention it prompts every time I click run? Every time... man if I had a penny for every time it prompted me I'd be a rich man... every time. every time.

starball5 commented 1 year ago

Related on Stack Overflow: In VS Code, when kicking off a task which is already running, how can the task be automatically restarted?. I'll update my answer there once this is released. Thanks, and keep up the great work!

matklad commented 1 year ago

Work-around: defile multicommand to kill all running tasks:

  { "key": "ctrl+whatever", "command": "extension.multiCommand.execute",
    "args": { "sequence": [ { "command": "workbench.action.tasks.terminate", "args": "terminateAll" }, "workbench.action.tasks.build" ] } },
starball5 commented 1 year ago

@matklad nice! Note that in VS Code 1.77, you can use the builtin runCommand command instead of the multicommand extension (see also this). I've updated my answer to the Stack Overflow question to show an example based on your workaround but with my own changes.

mattlacey commented 5 months ago

No movement a year later? Would love to see this where I'm automatically launching an emulator after a successful build.

lypanov commented 1 month ago

Is there keyboard interaction via eg accessibility to access the two buttons? For me the lack of obvious keyboard interactions to initiate the terminate/restart is the real issue. I'd expect the dialog to take focus and the arrow keys to work. Instead I need to worsen my RSI.

Update:

Found a work around shortly after writing this: https://superuser.com/a/1706615

TL;DR: Add the snippet:

{
        "key": "ctrl+shift+=",
        "command": "notifications.focusToasts"
},

to your keybindings.json. Then ctrl-shift-b, ctrl-shift-=, tab, tab, enter. Far from intuitive and quite laborious, but terminateAll isn't an option for me.

BrianLeishman commented 1 month ago

For me, (using hugo), the restart button doesn't even work, since it seems the port isn't free yet by the time vscode tries to start the next instance.

I always get the message "bind: address already in use". Then I have to start it again.

bilogic commented 1 day ago

Will this happen soon? Billions of clicks have been spent deciding to Terminate or Restart