Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to re-use a VS Code task window, without closing it

My goal is to re-use a task window in VS Code. However, when I enter ctrl + c, the task stops, but then writes: "Terminal will be reused by tasks, press any key to close it.".

I don't want to close the window. It's frustrating because it forces me to open a new window and navigate to the correct directory.

I recorded a gif of the problem (It's the window on the right):

enter image description here

My task config look like this:

{
    "label": "some label",
    "type": "npm",
    "script": "build",
    "path": "some-path/",
    "problemMatcher": [],
    "runOptions": { "runOn": "folderOpen" },
    "group": "build",
    "presentation": {
        "echo": true,
        "reveal": "silent",
        "focus": false,
        "panel": "shared",
        "showReuseMessage": false,
        "clear": false,
        "group": "build"
    }
}

I tried various combination of the presentation properties, but to no help.

Related feature request on VS code is here.

like image 550
DauleDK Avatar asked Nov 07 '22 11:11

DauleDK


1 Answers

I don't think this is possible and it may be by design.

If you look at the schema of tasks.json, you see:

/**
 * The description of a task.
 */
interface TaskDescription {
  /**
   * The task's name
   */
  label: string;

  /**
   * The type of a custom task. Tasks of type "shell" are executed
   * inside a shell (e.g. bash, cmd, powershell, ...)
   */
  type: 'shell' | 'process';

  //...
}

The type of a custom task. Tasks of type "shell" are executed inside a shell

So to me this implies that if you have a countdown task of type "shell" running this command seq 10 1, behind the scene it would do:

devbox:~ dev$ bash -c "seq 10 1"
10
9
8
7
6
5
4
3
2
1
devbox:~ dev$

As you can see it immediately exits and I'm not sure you can do anything about it. (I may be wrong though)

Even if you set a task of type "process" (command being the path to an executable), it doesn't allow you to reuse the terminal.

Having said that you can force it but VS Code wouldn't be too happy about it: (notice the && sh at the end of the command)

{
  "version": "2.0.0",
  "tasks": [
    {

      "label": "10 9 8 ...",
      "type": "shell",
      "command": "seq 10 1 && sh",
      "presentation": {
        "echo": true,
        "focus": true,
        "reveal": "always",
        "panel": "shared",
      },
      "problemMatcher": [],
    }
  ]
}

When you run the task, you do get another shell immediately:

enter image description here

However if you re-run the same task, then VS Code gets grumpy:

enter image description here

The fact that I couldn't see an option in .vscode/settings.json to support your use case makes me think that it really is a by design choice:

enter image description here

like image 194
customcommander Avatar answered Nov 22 '22 16:11

customcommander