You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Auto attach debugger to Node processes started from integrated terminal #42521
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:
User starts process from integrated terminal. Ex npm start
User press F5
We auto detect the Node process started from the integrated terminal
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.
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?"
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.
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:
Auto detect and attach to Node processes started with debugging (like your extension)
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.
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?
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.
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.
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.
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.
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.
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?
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.
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.
Activity
auchenberg commentedon Feb 2, 2018
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?"
weinand commentedon Feb 12, 2018
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:
Tyriar commentedon Feb 12, 2018
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.auchenberg commentedon Feb 12, 2018
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:
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:
What do you think?
weinand commentedon Feb 26, 2018
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?
weinand commentedon Feb 26, 2018
The February exploration has been finished. For the next milestone it is planned:
12 remaining items
Tyriar commentedon Mar 22, 2018
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.
weinand commentedon Mar 22, 2018
Daniel Imms (@Tyriar) great! I'll jump on it as soon as possible...
weinand commentedon Mar 26, 2018
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
wmicif the previous has finished. The frequency of runningwmicis determined based on the duration of the previouswmic. The idea is thatwmicdoes 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-treemodule.Tyriar commentedon Mar 26, 2018
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.
Tyriar commentedon Mar 26, 2018
Andre Weinand (@weinand) you will want to use
getProcessListand pass in theProcessDataFlag.CommandLineflag:https://github.com/Microsoft/vscode-windows-process-tree/blob/master/typings/windows-process-tree.d.ts#L55
DonJayamanne commentedon Mar 27, 2018
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.
Tyriar commentedon Mar 27, 2018
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.
DonJayamanne commentedon Mar 27, 2018
Daniel Imms (@Tyriar)
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.
Tyriar commentedon Mar 27, 2018
Don Jayamanne (@DonJayamanne) I pinged the team on Slack about this.
I was actually thinking about whether an API on
Terminalwould 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?DonJayamanne commentedon Mar 27, 2018
Yes, that would be great.
Tyriar commentedon Mar 27, 2018
Don Jayamanne (@DonJayamanne) created #46737 to track
weinand commentedon Mar 27, 2018
Don Jayamanne (@DonJayamanne) sorry but your statement:
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-treemodule because there was no time to adopt it.DonJayamanne commentedon Mar 28, 2018
Andre Weinand (@weinand)
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.