diff --git a/package.json b/package.json index b9532907..c00f979f 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "description": "Python Debugger extension using `debugpy`.", "version": "2023.3.0-dev", "publisher": "ms-python", + "enabledApiProposals": [ + "portsAttributes" + ], "license": "MIT", "homepage": "https://github.com/Microsoft/vscode-python-debugger", "repository": { diff --git a/src/extension/debugger/debugPort/portAttributesProvider.ts b/src/extension/debugger/debugPort/portAttributesProvider.ts new file mode 100644 index 00000000..13fea1b5 --- /dev/null +++ b/src/extension/debugger/debugPort/portAttributesProvider.ts @@ -0,0 +1,14 @@ +/*--------------------------------------------------------- + * Copyright (C) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------*/ + +import { CancellationToken, PortAttributes, PortAttributesProvider, ProviderResult } from 'vscode'; + +export class DebugPortAttributesProvider implements PortAttributesProvider { + public providePortAttributes( + _attributes: { port: number; pid?: number; commandLine?: string }, + _token: CancellationToken, + ): ProviderResult { + return undefined; + } +} diff --git a/src/extension/extensionInit.ts b/src/extension/extensionInit.ts index 5318cd23..35dd76b0 100644 --- a/src/extension/extensionInit.ts +++ b/src/extension/extensionInit.ts @@ -3,7 +3,7 @@ 'use strict'; -import { debug, DebugConfigurationProviderTriggerKind, languages, Uri, window } from 'vscode'; +import { debug, DebugConfigurationProviderTriggerKind, languages, Uri, window, workspace } from 'vscode'; import { executeCommand, getConfiguration, registerCommand, startDebugging } from './common/vscodeapi'; import { DebuggerTypeName } from './constants'; import { DynamicPythonDebugConfigurationService } from './debugger/configuration/dynamicdebugConfigurationService'; @@ -31,6 +31,7 @@ import { JsonLanguages, LaunchJsonCompletionProvider } from './debugger/configur import { LaunchJsonUpdaterServiceHelper } from './debugger/configuration/launch.json/updaterServiceHelper'; import { ignoreErrors } from './common/promiseUtils'; import { pickArgsInput } from './common/utils/localize'; +import { DebugPortAttributesProvider } from './debugger/debugPort/portAttributesProvider'; export async function registerDebugger(context: IExtensionContext): Promise { const childProcessAttachService = new ChildProcessAttachService(); @@ -125,4 +126,12 @@ export async function registerDebugger(context: IExtensionContext): Promise; + } + + /** + * A selector that will be used to filter which {@link PortAttributesProvider} should be called for each port. + */ + export interface PortAttributesSelector { + /** + * Specifying a port range will cause your provider to only be called for ports within the range. + * The start is inclusive and the end is exclusive. + */ + portRange?: [number, number] | number; + + /** + * Specifying a command pattern will cause your provider to only be called for processes whose command line matches the pattern. + */ + commandPattern?: RegExp; + } + + export namespace workspace { + /** + * If your extension listens on ports, consider registering a PortAttributesProvider to provide information + * about the ports. For example, a debug extension may know about debug ports in it's debuggee. By providing + * this information with a PortAttributesProvider the extension can tell the editor that these ports should be + * ignored, since they don't need to be user facing. + * + * The results of the PortAttributesProvider are merged with the user setting `remote.portsAttributes`. If the values conflict, the user setting takes precedence. + * + * @param portSelector It is best practice to specify a port selector to avoid unnecessary calls to your provider. + * If you don't specify a port selector your provider will be called for every port, which will result in slower port forwarding for the user. + * @param provider The {@link PortAttributesProvider PortAttributesProvider}. + */ + export function registerPortAttributesProvider(portSelector: PortAttributesSelector, provider: PortAttributesProvider): Disposable; + } +}