From f2edffb3d53b59dfb93fae3cb2472debc88b221f Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Mon, 19 Dec 2022 14:26:23 +0100 Subject: [PATCH] Add a setting for disabling port forwarding on click (#168311) Fixes https://github.com/microsoft/vscode-remote-release/issues/6972 Co-authored-by: Daniel Imms <2193314+Tyriar@users.noreply.github.com> --- src/vs/workbench/contrib/debug/browser/linkDetector.ts | 6 ++++-- .../workbench/contrib/remote/common/remote.contribution.ts | 5 +++++ .../contrib/terminal/browser/links/terminalLinkOpeners.ts | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/debug/browser/linkDetector.ts b/src/vs/workbench/contrib/debug/browser/linkDetector.ts index 4615c12f47a..abfca65cb23 100644 --- a/src/vs/workbench/contrib/debug/browser/linkDetector.ts +++ b/src/vs/workbench/contrib/debug/browser/linkDetector.ts @@ -17,6 +17,7 @@ import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { KeyCode } from 'vs/base/common/keyCodes'; import { localize } from 'vs/nls'; import { ITunnelService } from 'vs/platform/tunnel/common/tunnel'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; const CONTROL_CODES = '\\u0000-\\u0020\\u007f-\\u009f'; const WEB_LINK_REGEX = new RegExp('(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\\/\\/|data:|www\\.)[^\\s' + CONTROL_CODES + '"]{2,}[^\\s' + CONTROL_CODES + '"\')}\\],:;.!?]', 'ug'); @@ -45,7 +46,8 @@ export class LinkDetector { @IOpenerService private readonly openerService: IOpenerService, @IPathService private readonly pathService: IPathService, @ITunnelService private readonly tunnelService: ITunnelService, - @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService + @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService, + @IConfigurationService private readonly configurationService: IConfigurationService ) { // noop } @@ -140,7 +142,7 @@ export class LinkDetector { return; } - this.openerService.open(url, { allowTunneling: !!this.environmentService.remoteAuthority }); + this.openerService.open(url, { allowTunneling: (!!this.environmentService.remoteAuthority && this.configurationService.getValue('remote.forwardOnOpen')) }); }); return link; diff --git a/src/vs/workbench/contrib/remote/common/remote.contribution.ts b/src/vs/workbench/contrib/remote/common/remote.contribution.ts index d95a33548dc..88d2a14aff5 100644 --- a/src/vs/workbench/contrib/remote/common/remote.contribution.ts +++ b/src/vs/workbench/contrib/remote/common/remote.contribution.ts @@ -363,6 +363,11 @@ Registry.as(ConfigurationExtensions.Configuration) ], default: 'process' }, + 'remote.forwardOnOpen': { + type: 'boolean', + description: localize('remote.forwardOnClick', "Controls whether local URLs with a port will be forwarded when opened from the terminal and the debug console."), + default: true + }, // Consider making changes to extensions\configuration-editing\schemas\devContainer.schema.src.json // and extensions\configuration-editing\schemas\attachContainer.schema.json // to keep in sync with devcontainer.json schema. diff --git a/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts b/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts index 8d9095e161f..b9f87b84940 100644 --- a/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts +++ b/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts @@ -21,6 +21,7 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/ import { IHostService } from 'vs/workbench/services/host/browser/host'; import { QueryBuilder } from 'vs/workbench/services/search/common/queryBuilder'; import { ISearchService } from 'vs/workbench/services/search/common/search'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { getLinkSuffix } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkParsing'; export class TerminalLocalFileLinkOpener implements ITerminalLinkOpener { @@ -238,7 +239,8 @@ interface IResourceMatch { export class TerminalUrlLinkOpener implements ITerminalLinkOpener { constructor( private readonly _isRemote: boolean, - @IOpenerService private readonly _openerService: IOpenerService + @IOpenerService private readonly _openerService: IOpenerService, + @IConfigurationService private readonly _configurationService: IConfigurationService ) { } @@ -249,7 +251,7 @@ export class TerminalUrlLinkOpener implements ITerminalLinkOpener { // It's important to use the raw string value here to avoid converting pre-encoded values // from the URL like `%2B` -> `+`. this._openerService.open(link.text, { - allowTunneling: this._isRemote, + allowTunneling: this._isRemote && this._configurationService.getValue('remote.forwardOnOpen'), allowContributedOpeners: true, openExternal: true });