microsoft / vscode

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

Task that runs on folderOpen also always opens new terminal #142796

Open thesoftwarephilosopher opened 2 years ago

thesoftwarephilosopher commented 2 years ago

Issue Type: Bug

If I add this to .vscode/tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "npm",
            "script": "watch",
            "group": "build",
            "problemMatcher": [],
            "label": "npm: watch",
            "detail": "tsc --watch",
            "runOptions": {
                "runOn": "folderOpen"
            }
        }
    ]
}

And I open a new window:

  1. The task starts (great)
  2. A new terminal also always opens (not great)

VS Code version: Code 1.64.2 (f80445acd5a3dadef24aa209168452a3d97cc326, 2022-02-09T22:02:28.252Z) OS version: Windows_NT x64 10.0.22000 Restricted Mode: No

gjsjohnmurray commented 2 years ago

Did you look at https://code.visualstudio.com/docs/editor/tasks#_output-behavior information?

alexr00 commented 2 years ago

A new terminal also always opens (not great)

Do you mean the terminal that the task runs in?

thesoftwarephilosopher commented 2 years ago

A new terminal also always opens (not great)

Do you mean the terminal that the task runs in?

image

Two terminals open: bash and task. Task should be there. Bash should not. This only happens when I have the automatic task runner thing on for folderOpen.

thesoftwarephilosopher commented 2 years ago

But in another project, the extra bash did not open.

And on further reflection, once I open bash in a VS Code terminal, even after I close it, subsequent openings of that same VS Code workspace/window will open bash without asking me, as soon as I open the window. This is already frustrating and has been happening for months.

So I think the bug of this issue is probably related to that.

alexr00 commented 2 years ago

This looks like terminal persistence. @Tyriar FYI.

@sdegutis VS Code has a feature that restores your terminal session. If you close your bash terminal in a workspace, does it still come back when you next open that workspace?

You can entirely disable the terminal persistence feature with the setting terminal.integrated.enablePersistentSessions: false.

thesoftwarephilosopher commented 2 years ago

@sdegutis VS Code has a feature that restores your terminal session. If you close your bash terminal in a workspace, does it still come back when you next open that workspace?

Yes. That's the problem.

You can entirely disable the terminal persistence feature with the setting terminal.integrated.enablePersistentSessions: false.

But I like it. Just not its bugs.

meganrogge commented 2 years ago

Reproes with or without terminal persistence enabled, believe it's related to showPanel

meganrogge commented 2 years ago

very strange - I can repro in an Insider's window, but not in OSS using the same repo and tasks.json Screen Shot 2022-06-16 at 12 22 39 PM Screen Shot 2022-06-16 at 12 22 55 PM

meganrogge commented 2 years ago

In insider's, where the bug can be reproduced, I see that 2 tasks are found when there should only be one. It looks like the Screen Shot 2022-06-16 at 12 24 48 PM Screen Shot 2022-06-16 at 12 25 31 PM

and the command is getting passed into shellLaunchConfig as the executable

meganrogge commented 2 years ago

Screen Shot 2022-06-16 at 12 29 12 PM Screen Shot 2022-06-16 at 12 29 54 PM

meganrogge commented 2 years ago

wish I could debug this in OSS - the source maps are taking a long time to load and then the window becomes unresponsive. any idea why this might not repro there? @alexr00

alexr00 commented 2 years ago

@meganrogge I can't reproduce the 2 automatic tasks found. I also can't reproduce the issue if I disable terminal persistence. I can repro with OSS.

The two things that immediately come to mind for why something might not repro in OSS are minification and timing. Since I'm running all this on a fast desktop, and we have different situations under which this repros, I would guess timing.

Ghost-Core commented 1 year ago

update tasks.json file to this: { "version": "2.0.0", "tasks": [ { "type": "npm", "script": "watch", "group": "build", "problemMatcher": [], "label": "npm: watch", "detail": "tsc --watch", "runOptions": { "runOn": "folderOpen", "instanceLimit": 1 }, "presentation": { "reveal": "silent", "echo": false }, "options": { "env": { "DISABLE_TERMINAL_PERSISTENCE": "1" } } } ] } It disables terminal persistence for a task.

meganrogge commented 1 year ago

@markw65 has been looking into some issues related to this, one of his PRs might fix this. I'll be testing them next week

markw65 commented 1 year ago

@markw65 has been looking into some issues related to this, one of his PRs might fix this

I don't think that's likely, I'm afraid.

I see that 2 tasks are found when there should only be one

I think thats just a misleading message.

It's printing RunAutomaticTasks: Found ${workspaceTasks.size} automatic tasks, where workspaceTasks is a map from workspace folder uris to the set of tasks found there:

Screenshot 2023-04-26 at 4 07 55 PM

In my case, there are two entries. One is the actual workspace folder, with one task, and the other is "settings", with no tasks. It seems that "settings" are tasks inferred from the User's settings.json - and in my case, there are none. I'm not sure when there would be such tasks...

If I then step into the next function, it correctly extracts and launches the single task.

But I think all this is a side issue; the unwanted terminal has already been created by the time it starts running the automatic tasks. And I think that happens when the bottom panel is shown.

In fact, without any tasks, auto-run or otherwise, I can sort of repro this issue.

Start with the terminal panel open. Kill all the terminals. The entire bottom panel disappears. Now re-open it, eg via Cmd-Shift-M to show the problems panel, and then switch to the terminal panel. You'll see that a shell starts running. In other words, showing the terminal panel will start a shell if there are no other terminals.

So I think the problem is simply that vscode remembers that the terminal panel was selected.

So the fix might be as simple as not restoring the active panel until after the auto-run tasks have run.

markw65 commented 1 year ago

I think thats just a misleading message.

In fact its a very misleading message... the "set" field in each entry in the workspaceTasks map actually includes all tasks, not just the auto-run tasks; so you can't fix the message by simply adding up the sizes of the sets across all the entries in the map. The next step does correctly filter them out though, so its only the trace message which is broken...

markw65 commented 1 year ago

Actually, at the time you wrote about seeing two tasks, the code really was reporting the number of auto-run tasks found; it was (inadvertently by the looks of things) changed to report the number of places that it looked for tasks in 1715e06. So perhaps the two tasks thing is a separate issue, and still there...

meganrogge commented 10 months ago

This no longer happens

aeschli commented 10 months ago

I can still reproduce the problem:

thesoftwarephilosopher commented 1 month ago

Any update? I'm still getting new bash terminals started basically always, ones that I didn't open or want opened, and I can't prevent it. I have to close them every single time I open any project window.