Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 31cd1f2

Browse files
authored
Ensure local host only if connection not available (#10600) (#10644)
* Ensure local host only if connection not available * Add news item
1 parent f7cf79b commit 31cd1f2

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

news/2 Fixes/10597.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure default `host` is not set, if `connect` or `listen` settings are available.

src/client/debugger/extension/configuration/resolvers/attach.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export class AttachConfigurationResolver extends BaseConfigurationResolver<Attac
5555
if (!Array.isArray(debugConfiguration.debugOptions)) {
5656
debugConfiguration.debugOptions = [];
5757
}
58-
if (!debugConfiguration.host) {
58+
if (!(debugConfiguration.connect || debugConfiguration.listen) && !debugConfiguration.host) {
59+
// Connect and listen cannot be mixed with host property.
5960
debugConfiguration.host = 'localhost';
6061
}
6162
if (debugConfiguration.justMyCode === undefined) {
@@ -116,7 +117,7 @@ export class AttachConfigurationResolver extends BaseConfigurationResolver<Attac
116117

117118
private resolvePathMappings(
118119
pathMappings: PathMapping[],
119-
host: string,
120+
host?: string,
120121
localRoot?: string,
121122
remoteRoot?: string,
122123
workspaceFolder?: Uri

src/client/debugger/types.ts

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export type PathMapping = {
2626
localRoot: string;
2727
remoteRoot: string;
2828
};
29+
export type Connection = {
30+
host: string;
31+
port: number;
32+
};
33+
2934
interface ICommonDebugArguments {
3035
redirectOutput?: boolean;
3136
django?: boolean;
@@ -54,6 +59,8 @@ export interface IKnownAttachDebugArguments extends ICommonDebugArguments {
5459
subProcessId?: number;
5560

5661
processId?: number | string;
62+
connect?: Connection;
63+
listen?: Connection;
5764
}
5865

5966
export interface IKnownLaunchRequestArguments extends ICommonDebugArguments {

src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,32 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
181181
.deep.equal(debugOptionsAvailable);
182182
expect(debugConfig).to.have.property('host', 'localhost');
183183
});
184+
test('Default host should not be added if connect is available.', async () => {
185+
const pythonFile = 'xyz.py';
186+
187+
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
188+
setupWorkspaces([]);
189+
190+
const debugConfig = await debugProvider.resolveDebugConfiguration!(undefined, {
191+
request: 'attach',
192+
connect: { host: 'localhost', port: 5678 }
193+
} as AttachRequestArguments);
194+
195+
expect(debugConfig).to.not.have.property('host', 'localhost');
196+
});
197+
test('Default host should not be added if listen is available.', async () => {
198+
const pythonFile = 'xyz.py';
199+
200+
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
201+
setupWorkspaces([]);
202+
203+
const debugConfig = await debugProvider.resolveDebugConfiguration!(undefined, {
204+
request: 'attach',
205+
listen: { host: 'localhost', port: 5678 }
206+
} as AttachRequestArguments);
207+
208+
expect(debugConfig).to.not.have.property('host', 'localhost');
209+
});
184210
test("Ensure 'localRoot' is left unaltered", async () => {
185211
const activeFile = 'xyz.py';
186212
const workspaceFolder = createMoqWorkspaceFolder(__dirname);

0 commit comments

Comments
 (0)