Skip to content

Commit 6d573f4

Browse files
Enable string type for numbers in launch attributes (#134)
* Update package and values * Update package.json Co-authored-by: Tyler James Leonhardt <[email protected]> --------- Co-authored-by: Tyler James Leonhardt <[email protected]>
1 parent 0a765b5 commit 6d573f4

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
},
107107
"port": {
108108
"description": "Port to connect to.",
109-
"type": "number"
109+
"type": ["number", "string"]
110110
}
111111
},
112112
"required": [
@@ -147,7 +147,7 @@
147147
},
148148
"port": {
149149
"description": "Port to listen on.",
150-
"type": "number"
150+
"type": ["number", "string"]
151151
}
152152
},
153153
"required": [

src/extension/debugger/adapter/factory.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
5858
configuration.connect.port
5959
}`,
6060
);
61-
return new DebugAdapterServer(configuration.connect.port, configuration.connect.host ?? '127.0.0.1');
61+
return new DebugAdapterServer(
62+
Number(configuration.connect.port),
63+
configuration.connect.host ?? '127.0.0.1',
64+
);
6265
} else if (configuration.port !== undefined) {
6366
traceLog(`Connecting to DAP Server at: ${configuration.host ?? '127.0.0.1'}:${configuration.port}`);
64-
return new DebugAdapterServer(configuration.port, configuration.host ?? '127.0.0.1');
67+
return new DebugAdapterServer(Number(configuration.port), configuration.host ?? '127.0.0.1');
6568
} else if (configuration.listen === undefined && configuration.processId === undefined) {
6669
throw new Error('"request":"attach" requires either "connect", "listen", or "processId"');
6770
}

src/extension/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export type PathMapping = {
4545

4646
type Connection = {
4747
host?: string;
48-
port?: number;
48+
port?: number | string;
4949
};
5050

5151
export interface IAutomaticCodeReload {
@@ -64,7 +64,7 @@ interface ICommonDebugArguments {
6464
justMyCode?: boolean;
6565
logToFile?: boolean;
6666
debugOptions?: DebugOptions[];
67-
port?: number;
67+
port?: number | string;
6868
host?: string;
6969
// Show return values of functions while stepping.
7070
showReturnValue?: boolean;

src/test/unittest/adapter/factory.unit.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ suite('Debugging - Adapter Factory', () => {
182182
assert.deepStrictEqual(descriptor, debugServer);
183183
});
184184

185+
test('Return Debug Adapter server if request is "attach", and connect is specified with port as string', async () => {
186+
const session = createSession({ request: 'attach', connect: { port: '5678', host: 'localhost' } });
187+
const debugServer = new DebugAdapterServer(5678, session.configuration.connect.host);
188+
const descriptor = await factory.createDebugAdapterDescriptor(session, nodeExecutable);
189+
190+
// Interpreter not needed for connect
191+
sinon.assert.neverCalledWith(getInterpretersStub);
192+
assert.deepStrictEqual(descriptor, debugServer);
193+
});
194+
185195
test('Return Debug Adapter executable if request is "attach", and listen is specified', async () => {
186196
const session = createSession({ request: 'attach', listen: { port: 5678, host: 'localhost' } });
187197
const debugExecutable = new DebugAdapterExecutable(pythonPath, [debugAdapterPath]);

0 commit comments

Comments
 (0)