From 9d3c784f454e8e8f05e0a0e42fd30b67e7e67205 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Fri, 2 Aug 2024 11:45:42 -0700 Subject: [PATCH] feat: support "debug url" in terminals created through the `node-terminal` launch type Fixes #2049 --- CHANGELOG.md | 1 + src/common/terminalLinkProvider.ts | 18 ++++++++++++++++++ src/extension.ts | 8 +------- src/targets/node/terminalNodeLauncher.ts | 7 ++++++- src/ui/debugTerminalUI.ts | 7 +++---- src/ui/terminalLinkHandler.ts | 7 ++++--- src/ui/ui-ioc.extensionOnly.ts | 7 ++++++- 7 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 src/common/terminalLinkProvider.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 12f5a2079..753886225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes he ## Nightly (only) +- feat: support "debug url" in terminals created through the `node-terminal` launch type ([#2049](https://github.com/microsoft/vscode-js-debug/issues/2049)) - fix: automatically guess outFiles in extension development ([#2032](https://github.com/microsoft/vscode-js-debug/issues/2032)) - fix: breakpoints at unmapped locations setting in wrong locations ([vscode#219031](https://github.com/microsoft/vscode/issues/219031)) - fix: debug targets orphaned when a detached child starts after a parent exits ([vscode#219673](https://github.com/microsoft/vscode/issues/219673)) diff --git a/src/common/terminalLinkProvider.ts b/src/common/terminalLinkProvider.ts new file mode 100644 index 000000000..06bd52309 --- /dev/null +++ b/src/common/terminalLinkProvider.ts @@ -0,0 +1,18 @@ +/*--------------------------------------------------------- + * Copyright (C) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------*/ + +import type * as vscode from 'vscode'; + +/** + * Terminal link provider available when running in the vscode UI. + */ +export interface ITerminalLinkProvider + extends vscode.TerminalLinkProvider { + /** + * Turns on link handling in the given terminal. + */ + enableHandlingInTerminal(terminal: vscode.Terminal): void; +} + +export const ITerminalLinkProvider = Symbol('ITerminalLinkProvider'); diff --git a/src/extension.ts b/src/extension.ts index 5c41e4672..8d9d028b0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -27,7 +27,6 @@ import { attachProcess, pickProcess } from './ui/processPicker'; import { registerProfilingCommand } from './ui/profiling'; import { registerRequestCDPProxy } from './ui/requestCDPProxy'; import { registerRevealPage } from './ui/revealPage'; -import { TerminalLinkHandler } from './ui/terminalLinkHandler'; import { toggleSkippingFile } from './ui/toggleSkippingFile'; import { VSCodeSessionManager } from './ui/vsCodeSessionManager'; @@ -93,12 +92,7 @@ export function activate(context: vscode.ExtensionContext) { registerCompanionBrowserLaunch(context); registerCustomBreakpointsUI(context, debugSessionTracker); - registerDebugTerminalUI( - context, - services.get(DelegateLauncherFactory), - services.get(TerminalLinkHandler), - services, - ); + registerDebugTerminalUI(context, services.get(DelegateLauncherFactory), services); registerProfilingCommand(context, services); registerAutoAttach(context, services.get(DelegateLauncherFactory), services); registerRevealPage(context, debugSessionTracker); diff --git a/src/targets/node/terminalNodeLauncher.ts b/src/targets/node/terminalNodeLauncher.ts index 23d193a81..73fd3e4f6 100644 --- a/src/targets/node/terminalNodeLauncher.ts +++ b/src/targets/node/terminalNodeLauncher.ts @@ -3,7 +3,7 @@ *--------------------------------------------------------*/ import { randomBytes } from 'crypto'; -import { inject, injectable } from 'inversify'; +import { inject, injectable, optional } from 'inversify'; import { tmpdir } from 'os'; import * as path from 'path'; import * as vscode from 'vscode'; @@ -12,6 +12,7 @@ import { DebugType } from '../../common/contributionUtils'; import { EventEmitter } from '../../common/events'; import { ILogger } from '../../common/logging'; import { delay } from '../../common/promiseUtil'; +import { ITerminalLinkProvider } from '../../common/terminalLinkProvider'; import { AnyLaunchConfiguration, ITerminalLaunchConfiguration } from '../../configuration'; import { ErrorCodes } from '../../dap/errors'; import { ProtocolError } from '../../dap/protocolError'; @@ -77,6 +78,9 @@ export class TerminalNodeLauncher extends NodeLauncherBase { terminals.set(terminal, { launcher, folder: workspaceFolder, cwd: defaultConfig?.cwd }); - linkHandler.enableHandlingInTerminal(terminal); }); try { @@ -306,6 +305,7 @@ export function registerDebugTerminalUI( services.get(FS), services.get(NodeOnlyPathResolverFactory), services.get(IPortLeaseTracker), + services.get(ITerminalLinkProvider), ); launcher.onOptionsReady(options => resolve(new vscode.TerminalProfile(options))); @@ -314,6 +314,5 @@ export function registerDebugTerminalUI( }), ), }), - vscode.window.registerTerminalLinkProvider?.(linkHandler), ); } diff --git a/src/ui/terminalLinkHandler.ts b/src/ui/terminalLinkHandler.ts index 335686698..776a39bb7 100644 --- a/src/ui/terminalLinkHandler.ts +++ b/src/ui/terminalLinkHandler.ts @@ -16,6 +16,7 @@ import { import { DefaultBrowser, IDefaultBrowserProvider } from '../common/defaultBrowserProvider'; import { DisposableList, IDisposable } from '../common/disposable'; import { once } from '../common/objUtils'; +import { ITerminalLinkProvider } from '../common/terminalLinkProvider'; import { isLoopbackIp, isMetaAddress } from '../common/urlUtils'; interface ITerminalLink extends vscode.TerminalLink { @@ -29,9 +30,7 @@ const enum Protocol { } @injectable() -export class TerminalLinkHandler - implements vscode.TerminalLinkProvider, IDisposable -{ +export class TerminalLinkHandler implements ITerminalLinkProvider, IDisposable { private readonly enabledTerminals = new WeakSet(); private readonly disposable = new DisposableList(); private notifiedCantOpenOnWeb = false; @@ -44,6 +43,8 @@ export class TerminalLinkHandler this.baseConfiguration = this.readConfig(); } }), + + vscode.window.registerTerminalLinkProvider(this), ); } diff --git a/src/ui/ui-ioc.extensionOnly.ts b/src/ui/ui-ioc.extensionOnly.ts index 634bf0ec0..af0a06698 100644 --- a/src/ui/ui-ioc.extensionOnly.ts +++ b/src/ui/ui-ioc.extensionOnly.ts @@ -5,6 +5,7 @@ import { Container } from 'inversify'; import { IDwarfModuleProvider } from '../adapter/dwarf/dwarfModuleProvider'; import { IRequestOptionsProvider } from '../adapter/resourceProvider/requestOptionsProvider'; +import { ITerminalLinkProvider } from '../common/terminalLinkProvider'; import { IExtensionContribution, trackDispose, VSCodeApi } from '../ioc-extras'; import { TerminalNodeLauncher } from '../targets/node/terminalNodeLauncher'; import { ILauncher } from '../targets/targets'; @@ -68,9 +69,13 @@ export const registerUiComponents = (container: Container) => { container.bind(ILinkedBreakpointLocation).to(LinkedBreakpointLocationUI).inSingletonScope(); container.bind(DebugSessionTracker).toSelf().inSingletonScope().onActivation(trackDispose); container.bind(UiProfileManager).toSelf().inSingletonScope().onActivation(trackDispose); - container.bind(TerminalLinkHandler).toSelf().inSingletonScope(); container.bind(DisableSourceMapUI).toSelf().inSingletonScope(); container.bind(IDwarfModuleProvider).to(DwarfModuleProvider).inSingletonScope(); + container + .bind(ITerminalLinkProvider) + .to(TerminalLinkHandler) + .inSingletonScope() + .onActivation(trackDispose); container .bind(ITerminationConditionFactory)