Skip to content

Enable string type for numbers in launch attributes #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should there be some error handling when this doesn't cast properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The adapter handle the error if the data is not right

} 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