Skip to content

Commit

Permalink
feat: support "debug url" in terminals created through the `node-term…
Browse files Browse the repository at this point in the history
…inal` launch type (#2050)

Fixes #2049
  • Loading branch information
connor4312 authored Aug 2, 2024
1 parent 14b4300 commit ca1c645
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: hover evaluation incorrectly showing undefined ([vscode#221503](https://github.com/microsoft/vscode/issues/221503))

## v1.92 (July 2024)
Expand Down
18 changes: 18 additions & 0 deletions src/common/terminalLinkProvider.ts
Original file line number Diff line number Diff line change
@@ -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<T extends vscode.TerminalLink = vscode.TerminalLink>
extends vscode.TerminalLinkProvider<T> {
/**
* Turns on link handling in the given terminal.
*/
enableHandlingInTerminal(terminal: vscode.Terminal): void;
}

export const ITerminalLinkProvider = Symbol('ITerminalLinkProvider');
8 changes: 1 addition & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/targets/node/terminalNodeLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -77,6 +78,9 @@ export class TerminalNodeLauncher extends NodeLauncherBase<ITerminalLaunchConfig
@inject(FS) private readonly fs: FsPromises,
@inject(ISourcePathResolverFactory) pathResolverFactory: ISourcePathResolverFactory,
@inject(IPortLeaseTracker) portLeaseTracker: IPortLeaseTracker,
@optional()
@inject(ITerminalLinkProvider)
private readonly terminalLinkProvider: ITerminalLinkProvider | undefined,
) {
super(pathProvider, logger, portLeaseTracker, pathResolverFactory);
}
Expand Down Expand Up @@ -137,6 +141,7 @@ export class TerminalNodeLauncher extends NodeLauncherBase<ITerminalLaunchConfig
env: hideDebugInfoFromConsole(binary, env).defined(),
isTransient: true,
});
this.terminalLinkProvider?.enableHandlingInTerminal(terminal);
this.terminalCreatedEmitter.fire(terminal);

terminal.show();
Expand Down
7 changes: 3 additions & 4 deletions src/ui/debugTerminalUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '../common/contributionUtils';
import { EventEmitter } from '../common/events';
import { ProxyLogger } from '../common/logging/proxyLogger';
import { ITerminalLinkProvider } from '../common/terminalLinkProvider';
import {
applyDefaults,
ITerminalLaunchConfiguration,
Expand All @@ -32,7 +33,6 @@ import { NodeOnlyPathResolverFactory } from '../targets/sourcePathResolverFactor
import { MutableTargetOrigin } from '../targets/targetOrigin';
import { ITarget } from '../targets/targets';
import { DapTelemetryReporter } from '../telemetry/dapTelemetryReporter';
import { TerminalLinkHandler } from './terminalLinkHandler';

export const launchVirtualTerminalParent = (
delegate: DelegateLauncherFactory,
Expand Down Expand Up @@ -203,7 +203,6 @@ class ProfileTerminalLauncher extends TerminalNodeLauncher {
export function registerDebugTerminalUI(
context: vscode.ExtensionContext,
delegateFactory: DelegateLauncherFactory,
linkHandler: TerminalLinkHandler,
services: Container,
) {
const terminals = new Map<
Expand All @@ -218,6 +217,7 @@ export function registerDebugTerminalUI(
services.get(FS),
services.get(NodeOnlyPathResolverFactory),
services.get(IPortLeaseTracker),
services.get(ITerminalLinkProvider),
);

/**
Expand Down Expand Up @@ -263,7 +263,6 @@ export function registerDebugTerminalUI(

launcher.onTerminalCreated(terminal => {
terminals.set(terminal, { launcher, folder: workspaceFolder, cwd: defaultConfig?.cwd });
linkHandler.enableHandlingInTerminal(terminal);
});

try {
Expand Down Expand Up @@ -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)));
Expand All @@ -314,6 +314,5 @@ export function registerDebugTerminalUI(
}),
),
}),
vscode.window.registerTerminalLinkProvider?.(linkHandler),
);
}
7 changes: 4 additions & 3 deletions src/ui/terminalLinkHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -29,9 +30,7 @@ const enum Protocol {
}

@injectable()
export class TerminalLinkHandler
implements vscode.TerminalLinkProvider<ITerminalLink>, IDisposable
{
export class TerminalLinkHandler implements ITerminalLinkProvider<ITerminalLink>, IDisposable {
private readonly enabledTerminals = new WeakSet<vscode.Terminal>();
private readonly disposable = new DisposableList();
private notifiedCantOpenOnWeb = false;
Expand All @@ -44,6 +43,8 @@ export class TerminalLinkHandler
this.baseConfiguration = this.readConfig();
}
}),

vscode.window.registerTerminalLinkProvider(this),
);
}

Expand Down
7 changes: 6 additions & 1 deletion src/ui/ui-ioc.extensionOnly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ca1c645

Please sign in to comment.