Skip to content

Debug extension host without requiring a restart - #326534

Open
Haras (ArasHuseyin) wants to merge 2 commits into
microsoft:mainfrom
ArasHuseyin:fix/85422-debug-ext-host-without-restart
Open

Debug extension host without requiring a restart#326534
Haras (ArasHuseyin) wants to merge 2 commits into
microsoft:mainfrom
ArasHuseyin:fix/85422-debug-ext-host-without-restart

Conversation

@ArasHuseyin

Copy link
Copy Markdown

Fixes #85422

Problem

Clicking Debug Extension Host In New Window (and Debug Extension Host and Renderer In New Window) always prompts for a restart, even when the extension host is already running. This defeats the main use case of the feature — attaching a debugger to a running extension host to investigate an issue that is happening right now.

Cause

Both actions go through the shared getExtensionHostPort helper, which called:

extensionService.getInspectPorts(ExtensionHostKind.LocalProcess, /* tryEnableInspector */ false)

With tryEnableInspector = false, the extension host manager never calls enableInspectPort(), so when the host was not started with --inspect-extensions there are no inspect ports and the code falls through to the restart prompt.

The profiling path (ExtensionHostProfileService.startProfiling) and the dev-tools path (DebugExtensionHostInDevToolsAction) already pass true, which enables the inspector on the running extension host via node's process._debugProcess(pid) (UtilityProcess.enableInspectPort) — no restart required. This matches the approach suggested by Andre Weinand (@weinand) and Johannes Rieken (@jrieken) in the issue, and explains Connor Peet (@connor4312)'s observation that profiling works without a restart while debugging does not.

Fix

Pass tryEnableInspector = true in the shared helper so the debug actions first try to enable the inspector on the running host, exactly like profiling. The restart prompt is kept as a fallback for the case where the inspector cannot be enabled on the fly (e.g. _debugProcess unavailable or the host is not running).

Notes

  • No behavior change when the host was already started with --inspect-extensions: enableInspectPort() short-circuits when an inspect listener already exists.
  • No new state and no new UI; the change is limited to the shared helper used by the two debug actions.

The shared getExtensionHostPort helper called getInspectPorts with tryEnableInspector=false, so the Debug Extension Host actions always prompted for a restart. The profiling and dev-tools paths already pass true, which enables the inspector on the running extension host via process._debugProcess(pid). Align the debug action with them; the restart prompt remains as a fallback when the inspector cannot be enabled on the fly.

Fixes microsoft#85422
Copilot AI review requested due to automatic review settings July 19, 2026 19:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables debugging an already-running local extension host without restarting VS Code.

Changes:

  • Attempts to enable the inspector dynamically.
  • Retains the restart prompt as a fallback.

Comment on lines +40 to +43
// Try to enable the inspector on the already running extension host (same as profiling and the
// dev tools action do). This avoids forcing a restart just to debug extensions; the restart
// prompt below is only used as a fallback when the inspector cannot be enabled on the fly.
const inspectPorts = await extensionService.getInspectPorts(ExtensionHostKind.LocalProcess, true);
@ArasHuseyin

Haras (ArasHuseyin) commented Jul 19, 2026

Copy link
Copy Markdown
Author

reduced the inline comment to a single line as suggested (3483d82). It now only notes the non-obvious intent (enabling the inspector on the running host to avoid a restart, matching the profiling path).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change Start Debugging Extension Host on Running Extensions to not require a restart

3 participants