From 6d573f44e861198b39628d0da649e7e03d00c2af Mon Sep 17 00:00:00 2001 From: paulacamargo25 Date: Mon, 20 Nov 2023 07:01:45 -0800 Subject: [PATCH] Enable string type for numbers in launch attributes (#134) * Update package and values * Update package.json Co-authored-by: Tyler James Leonhardt --------- Co-authored-by: Tyler James Leonhardt --- package.json | 4 ++-- src/extension/debugger/adapter/factory.ts | 7 +++++-- src/extension/types.ts | 4 ++-- src/test/unittest/adapter/factory.unit.test.ts | 10 ++++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b560a28e..776be890 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ }, "port": { "description": "Port to connect to.", - "type": "number" + "type": ["number", "string"] } }, "required": [ @@ -147,7 +147,7 @@ }, "port": { "description": "Port to listen on.", - "type": "number" + "type": ["number", "string"] } }, "required": [ diff --git a/src/extension/debugger/adapter/factory.ts b/src/extension/debugger/adapter/factory.ts index af5b58cc..d2d5b8e2 100644 --- a/src/extension/debugger/adapter/factory.ts +++ b/src/extension/debugger/adapter/factory.ts @@ -58,10 +58,13 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac configuration.connect.port }`, ); - return new DebugAdapterServer(configuration.connect.port, configuration.connect.host ?? '127.0.0.1'); + return new DebugAdapterServer( + Number(configuration.connect.port), + configuration.connect.host ?? '127.0.0.1', + ); } else if (configuration.port !== undefined) { traceLog(`Connecting to DAP Server at: ${configuration.host ?? '127.0.0.1'}:${configuration.port}`); - return new DebugAdapterServer(configuration.port, configuration.host ?? '127.0.0.1'); + return new DebugAdapterServer(Number(configuration.port), configuration.host ?? '127.0.0.1'); } else if (configuration.listen === undefined && configuration.processId === undefined) { throw new Error('"request":"attach" requires either "connect", "listen", or "processId"'); } diff --git a/src/extension/types.ts b/src/extension/types.ts index 0646e5ff..d7a89edb 100644 --- a/src/extension/types.ts +++ b/src/extension/types.ts @@ -45,7 +45,7 @@ export type PathMapping = { type Connection = { host?: string; - port?: number; + port?: number | string; }; export interface IAutomaticCodeReload { @@ -64,7 +64,7 @@ interface ICommonDebugArguments { justMyCode?: boolean; logToFile?: boolean; debugOptions?: DebugOptions[]; - port?: number; + port?: number | string; host?: string; // Show return values of functions while stepping. showReturnValue?: boolean; diff --git a/src/test/unittest/adapter/factory.unit.test.ts b/src/test/unittest/adapter/factory.unit.test.ts index 5cd492c3..ada6cef1 100644 --- a/src/test/unittest/adapter/factory.unit.test.ts +++ b/src/test/unittest/adapter/factory.unit.test.ts @@ -182,6 +182,16 @@ suite('Debugging - Adapter Factory', () => { assert.deepStrictEqual(descriptor, debugServer); }); + test('Return Debug Adapter server if request is "attach", and connect is specified with port as string', async () => { + const session = createSession({ request: 'attach', connect: { port: '5678', host: 'localhost' } }); + const debugServer = new DebugAdapterServer(5678, session.configuration.connect.host); + const descriptor = await factory.createDebugAdapterDescriptor(session, nodeExecutable); + + // Interpreter not needed for connect + sinon.assert.neverCalledWith(getInterpretersStub); + assert.deepStrictEqual(descriptor, debugServer); + }); + test('Return Debug Adapter executable if request is "attach", and listen is specified', async () => { const session = createSession({ request: 'attach', listen: { port: 5678, host: 'localhost' } }); const debugExecutable = new DebugAdapterExecutable(pythonPath, [debugAdapterPath]);