Skip to content

Auto attach debugger to Node processes started from integrated terminal #42521

Closed

Description

Scenario
I as a Node developer use the integrated terminal to launch my Node.js app as I'm used to. My app starts, and now I want to debug. I could make a debug configuration to launch my Node app via VS Code, but that would be a new workflow for me. Instead I want VS code to be able to attach to my started Node process from the terminal.

Proposal
We should explore auto attaching to our Node debugger to the first Node process started from the integrated terminal.

Flow:

  1. User starts process from integrated terminal. Ex npm start
  2. User press F5
  3. We auto detect the Node process started from the integrated terminal
  4. Attach to that specific pID via our existing attach/pickProcess configuration.

This could either happen automatically as a part of our magic out of box experience, or through a new property in the debug configuration.

        {
            "type": "node",
            "request": "attach",
            "name": "Launch Program",
            "attachToIntegratedTerminal: true
        }

Rationale

  • Encourage more users to use the integrated terminal.
  • Leverage the benefits that we know which Node processes that were started from VS Code.
  • Provide a end-to-end scenario without forcing developers to change their workflow by having them adapting launching from VS Code.

Activity

  1. added
    debug
    feature-request
    on Feb 2, 2018
  2. auchenberg commented on Feb 2, 2018

    @auchenberg
    ContributorAuthor

    Suggestion from roblourens: "What if in the existing process picker, we find processes that were started from the integrated terminal, and sort them to the top/highlight them?"

  3. weinand commented on Feb 12, 2018

    @weinand
    Contributor

    Kenneth Auchenberg (@auchenberg) I've started a "Playground" extension for experimenting with this feature.

    Since there is no API for accessing existing terminals, the extension just tries to automatically attach to all node runtimes that are in debug mode.

    Ideas for more features:

    • auto attach to node runtimes that are not in debug mode (via SIGUSR1),
    • add a QuickPick for selecting potential candidates.
  4. Tyriar commented on Feb 12, 2018

    @Tyriar
    Contributor

    Here's the feature request to expose all the terminals to the API #13267, it's mainly just been waiting for compelling use cases. I've wanted to track the terminal process trees for a while as well to give a better experience for confirmOnExit, Windows already does this to track the active process title in the dropdown.

  5. auchenberg commented on Feb 12, 2018

    @auchenberg
    ContributorAuthor

    I like that experience Andre Weinand (@weinand), as the developer intentionally have chosen to enable ``--inspect`.

    We could have the out of box experience like:

    1. Auto detect and attach to Node processes started with debugging (like your extension)
    2. Bump Node Child processes to the top in the QuickPick list when using an attach pickProcess config

    I still can't decide whether pressing F5 for Node apps where we know a Node child process has been launched from the terminal should change behavior from today, as you can argue both ways.

    That said I can easily imagine a workflow where I from my terminal type npm start, followed by a F5 where I then see the QuickPick list. I select my node process, and we send a SIGUSR1 to it, and attach the debugger. That way we don't have an intrusive experience, but we are more intelligent when you press F5 to enable debugging.

    Today the experience somewhat falls apart if you already have started from the terminal, as we would try to launch the Node process again, and it would most likely fail as the port already is used.

    This would be a change in the default F5 logic with no launch.json:

    • If Node child process detected -> Attach with pickProcess config
    • If no child process detected -> Attempt to launch like today.

    What do you think?

  6. weinand commented on Feb 26, 2018

    @weinand
    Contributor

    Daniel Imms (@Tyriar) tracking process trees for VS Code or the integrated terminal works as long as child process are created under a well known VS Code or integrated terminal process. But when running "tmux" in the integrated terminal, spawned process becomes children of a remote tmux server. So they are no longer part of the VS Code tree. Do you have any ideas how to track those processes?

  7. weinand commented on Feb 26, 2018

    @weinand
    Contributor

    The February exploration has been finished. For the next milestone it is planned:

    • to add some of the logic to the node-debug process Picker
    • to make the prototype a special mode of node-debug that can be turned on or off.
  8. 12 remaining items

  9. Tyriar commented on Mar 22, 2018

    @Tyriar
    Contributor

    Rachel Macfarlane (@RMacfarlane) is making good progress on improvements to windows-process-tree and it should soon support everything needed by auto attach (arg list, process as a list not tree) microsoft/vscode-windows-process-tree#12.

  10. weinand commented on Mar 22, 2018

    @weinand
    Contributor

    Daniel Imms (@Tyriar) great! I'll jump on it as soon as possible...

  11. weinand commented on Mar 26, 2018

    @weinand
    Contributor

    In the March release the feature is not yet on by default (and consequently there is no prompt notification) due to the performance concern on Windows. I'll keep the status bar item in the interim.

    I've tried to avoid the performance issues by only starting another wmic if the previous has finished. The frequency of running wmic is determined based on the duration of the previous wmic. The idea is that wmic does not dominate the overall cpu load. In addition I only run the wmic for retrieving the "cpu load" every 4th time.

    However, I will not improve the discoverability of the auto-attach feature in this milestone because there is still potential for performance issues on Windows. I'm waiting for Tyrar and Rachel Macfarlane (@RMacfarlane) for an improved version of the vscode-windows-process-tree module.

  12. Tyriar commented on Mar 26, 2018

    @Tyriar
    Contributor

    Andre Weinand (@weinand) we published the module this morning and Rachel Macfarlane (@RMacfarlane) pulled it into vscode master. So it's good to go. Note that we haven't actually tested the new APIs yet inside VS Code, only hooked up the old one which seems to work fine.

  13. DonJayamanne commented on Mar 27, 2018

    @DonJayamanne
    Contributor

    Daniel Imms (@Tyriar) Will this be available for use by other extension authors via some vscode api. I know it's an npm package, but the fact that it's got native dependencies make it difficult to package with extensions.
    I'm planning on adding similar (auto attach) functionality to the Python extension, but without any dependency on wmi.

  14. Tyriar commented on Mar 27, 2018

    @Tyriar
    Contributor

    Don Jayamanne (@DonJayamanne) I think extensions can just import VS Code's node modules, we don't explicitly make that public API so it could break across versions though.

  15. DonJayamanne commented on Mar 27, 2018

    @DonJayamanne
    Contributor

    Daniel Imms (@Tyriar)

    we don't explicitly make that public API so it could break across versions though.

    Yes I suspected that, hence the question about it being exposed via VS Code API. A shame we cannot implement this in the Python extension due to the above limitation.
    Though Node debugger will never have the same issue as its a first class citizen in VSC.

    To be honest this seems a little unfair.

  16. Tyriar commented on Mar 27, 2018

    @Tyriar
    Contributor

    Don Jayamanne (@DonJayamanne) I pinged the team on Slack about this.

    I was actually thinking about whether an API on Terminal would make sense for this to be able to request the process tree. Is that's what you're after; just the child processes on the terminal?

  17. DonJayamanne commented on Mar 27, 2018

    @DonJayamanne
    Contributor

    Is that's what you're after; just the child processes on the terminal?

    Yes, that would be great.

  18. Tyriar commented on Mar 27, 2018

    @Tyriar
    Contributor
  19. weinand commented on Mar 27, 2018

    @weinand
    Contributor

    Don Jayamanne (@DonJayamanne) sorry but your statement:

    Though Node debugger will never have the same issue as its a first class citizen in VSC.

    is not true.

    Node debugging is developed as an independent extension and the fact that it is shipping with VS Code does not mean that we are not playing by the rules.

    So we are not "reaching into" VS Code for accessing node modules.

    Daniel Imms (@Tyriar) for the March release we (Node Debugging) will not switch to use the vscode-windows-process-tree module because there was no time to adopt it.

  20. DonJayamanne commented on Mar 28, 2018

    @DonJayamanne
    Contributor

    Andre Weinand (@weinand)

    does not mean that we are not playing by the rules.

    I didn't mean anything if that sorts.
    Let me explain this better, the fact that it is bundled with vscode will always make it easier to use native dependencies than external extensions. Everytime a new version of vscode is released nodejs debugger is bundled.
    Extension authors will have to worry about compatibility of older versions of extensions with newer versions of vscode (and vice versa, when using native deps). That's where nodejs debugger benefits from being bundled with vscode. Such extensions will almost never face these (version compatibility) issues.

    Daniel Imms (@Tyriar) thanks for considering to make this a public API.

  21. locked and limited conversation to collaborators on May 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

debugfeature-requeston-testplan

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions