Skip to content

Commit

Permalink
Enable string type for numbers in launch attributes (microsoft#134)
Browse files Browse the repository at this point in the history
* Update package and values

* Update package.json

Co-authored-by: Tyler James Leonhardt <[email protected]>

---------

Co-authored-by: Tyler James Leonhardt <[email protected]>
  • Loading branch information
paulacamargo25 and TylerLeonhardt authored Nov 20, 2023
1 parent 0a765b5 commit 6d573f4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
},
"port": {
"description": "Port to connect to.",
"type": "number"
"type": ["number", "string"]
}
},
"required": [
Expand Down Expand Up @@ -147,7 +147,7 @@
},
"port": {
"description": "Port to listen on.",
"type": "number"
"type": ["number", "string"]
}
},
"required": [
Expand Down
7 changes: 5 additions & 2 deletions src/extension/debugger/adapter/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"');
}
Expand Down
4 changes: 2 additions & 2 deletions src/extension/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type PathMapping = {

type Connection = {
host?: string;
port?: number;
port?: number | string;
};

export interface IAutomaticCodeReload {
Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/test/unittest/adapter/factory.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 6d573f4

Please sign in to comment.