-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new port forwarding API (#15243)
* Use new port forwarding API * Fix tests
- Loading branch information
1 parent
924cb5c
commit a4faddd
Showing
7 changed files
with
93 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { | ||
PortAttributes, | ||
type CancellationToken, | ||
type PortAttributesProvider, | ||
PortAutoForwardAction, | ||
type PortAttributesSelector, | ||
workspace | ||
} from 'vscode'; | ||
import { DisposableStore } from '../../platform/common/utils/lifecycle'; | ||
import { traceError } from '../../platform/logging'; | ||
|
||
// Keeps track of all ports used by Kernels and other processes spawned by Kernels and related code | ||
export const UsedPorts = new Set<number>(); | ||
|
||
export function ignorePortForwarding(...ports: number[]) { | ||
const disposableStore = new DisposableStore(); | ||
try { | ||
const provider = new (class implements PortAttributesProvider { | ||
async providePortAttributes( | ||
attributes: { port: number; pid?: number; commandLine?: string }, | ||
_token: CancellationToken | ||
) { | ||
if (ports.includes(attributes.port)) { | ||
return new PortAttributes(PortAutoForwardAction.Ignore); | ||
} | ||
return undefined; | ||
} | ||
})(); | ||
|
||
for (const port of ports) { | ||
const portSelector: PortAttributesSelector = { | ||
portRange: port | ||
}; | ||
disposableStore.add(workspace.registerPortAttributesProvider(portSelector, provider)); | ||
} | ||
} catch (ex) { | ||
// In case proposed API changes. | ||
traceError('Failure in registering port attributes', ex); | ||
} | ||
|
||
return disposableStore; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters