diff --git a/src/vs/workbench/contrib/remote/common/remote.contribution.ts b/src/vs/workbench/contrib/remote/common/remote.contribution.ts index 3e9e9616524..707332a5ec5 100644 --- a/src/vs/workbench/contrib/remote/common/remote.contribution.ts +++ b/src/vs/workbench/contrib/remote/common/remote.contribution.ts @@ -184,10 +184,43 @@ Registry.as(ConfigurationExtensions.Configuration) } } }, - markdownDescription: localize('remote.portsAttributes', "Set default properties that are applied when a specific port number is forwarded. For example:\n\n```\n\"3000\": {\n \"label\": \"Labeled Port\"\n},\n\"40000-55000\": {\n \"onAutoForward\": \"ignore\"\n},\n\".+\\\\/server.js\": {\n \"onAutoForward\": \"openPreview\"\n}\n```"), - defaultSnippets: [{ body: { '${1:3000}': { label: '${2:My Port}', onAutoForward: 'openPreview' }, 'others': { onAutoForward: 'notify' } } }], + markdownDescription: localize('remote.portsAttributes', "Set properties that are applied when a specific port number is forwarded. For example:\n\n```\n\"3000\": {\n \"label\": \"Labeled Port\"\n},\n\"40000-55000\": {\n \"onAutoForward\": \"ignore\"\n},\n\".+\\\\/server.js\": {\n \"onAutoForward\": \"openPreview\"\n}\n```"), + defaultSnippets: [{ body: { '${1:3000}': { label: '${2:My Port}', onAutoForward: 'openPreview' } } }], errorMessage: localize('remote.portsAttributes.patternError', "Must be a port number, range of port numbers, or regular expression."), additionalProperties: false + }, + 'remote.portsAttributes.defaults': { + type: 'object', + properties: { + 'onAutoForward': { + type: 'string', + enum: ['notify', 'openBrowser', 'openPreview', 'silent', 'ignore'], + enumDescriptions: [ + localize('remote.portsAttributes.notify', "Shows a notification when a port is automatically forwarded."), + localize('remote.portsAttributes.openBrowser', "Opens the browser when the port is automatically forwarded. Depending on your settings, this could open an embedded browser."), + localize('remote.portsAttributes.openPreview', "Opens a preview in the same window when the port is automatically forwarded."), + localize('remote.portsAttributes.silent', "Shows no notification and takes no action when this port is automatically forwarded."), + localize('remote.portsAttributes.ignore', "This port will not be automatically forwarded.") + ], + description: localize('remote.portsAttributes.onForward', "Defines the action that occurs when the port is discovered for automatic forwarding"), + default: 'notify' + }, + 'elevateIfNeeded': { + type: 'boolean', + description: localize('remote.portsAttributes.elevateIfNeeded', "Automatically prompt for elevation (if needed) when this port is forwarded. Elevate is required if the local port is a privileged port."), + default: false + }, + 'label': { + type: 'string', + description: localize('remote.portsAttributes.label', "Label that will be shown in the UI for this port."), + default: localize('remote.portsAttributes.labelDefault', "Labeled Port") + } + }, + default: { + 'onAutoForward': 'notify' + }, + markdownDescription: localize('remote.portsAttributes.defaults', "Set default properties that are applied to all ports that don't get properties from the setting `remote.portsAttributes`. For example:\n\n```\n{\n \"onAutoForward\": \"notify\"\n}\n```"), + additionalProperties: false } } }); diff --git a/src/vs/workbench/services/remote/common/remoteExplorerService.ts b/src/vs/workbench/services/remote/common/remoteExplorerService.ts index 39cd8dcbd77..2b860229ca8 100644 --- a/src/vs/workbench/services/remote/common/remoteExplorerService.ts +++ b/src/vs/workbench/services/remote/common/remoteExplorerService.ts @@ -154,10 +154,10 @@ interface PortAttributes extends Attributes { export class PortsAttributes extends Disposable { private static SETTING = 'remote.portsAttributes'; + private static DEFAULTS = 'remote.portsAttributes.defaults'; private static RANGE = /^(\d+)\-(\d+)$/; - private static OTHERS = 'others'; private portsAttributes: PortAttributes[] = []; - private otherPortAttributes: Attributes | undefined; + private defaultPortAttributes: Attributes | undefined; private _onDidChangeAttributes = new Emitter(); public readonly onDidChangeAttributes = this._onDidChangeAttributes.event; @@ -241,12 +241,6 @@ export class PortsAttributes extends Disposable { let key: number | { start: number, end: number } | RegExp | undefined = undefined; if (Number(attributesKey)) { key = Number(attributesKey); - } else if (attributesKey === PortsAttributes.OTHERS) { - this.otherPortAttributes = { - elevateIfNeeded: setting.elevateIfPrivileged, - onAutoForward: setting.onAutoForward, - label: setting.label - }; } else if (isString(attributesKey)) { if (PortsAttributes.RANGE.test(attributesKey)) { const match = (attributesKey).match(PortsAttributes.RANGE); @@ -269,6 +263,15 @@ export class PortsAttributes extends Disposable { }); } + const defaults = this.configurationService.getValue(PortsAttributes.DEFAULTS); + if (defaults) { + this.defaultPortAttributes = { + elevateIfNeeded: defaults.elevateIfNeeded, + label: defaults.label, + onAutoForward: defaults.onAutoForward + }; + } + return this.sortAttributes(attributes); } @@ -289,7 +292,7 @@ export class PortsAttributes extends Disposable { } private getOtherAttributes() { - return this.otherPortAttributes; + return this.defaultPortAttributes; } static providedActionToAction(providedAction: ProvidedOnAutoForward | undefined) {