diff --git a/src/fileSystemConfig.ts b/src/fileSystemConfig.ts index 06918ce..d02bdb4 100644 --- a/src/fileSystemConfig.ts +++ b/src/fileSystemConfig.ts @@ -102,6 +102,10 @@ export interface FileSystemConfig extends ConnectConfig { _location?: ConfigLocation; /** Internal property keeping track of where this config comes from (including merges) */ _locations: ConfigLocation[]; + /** Debug port to attach */ + debugPort?: number; + /** Task to run before debug session starts. SSH command: e.g. `/opt/vistec/python/bin/python -m ptvsd --host ${config.host} --port ${config.debugPort} --wait ${file}` */ + debugPreLaunch?: string; } export function invalidConfigName(name: string) { diff --git a/src/manager.ts b/src/manager.ts index e75769e..08d02fc 100644 --- a/src/manager.ts +++ b/src/manager.ts @@ -112,6 +112,89 @@ export class Manager implements vscode.TreeDataProvider { + if (config && config.debugPreLaunch) { + const file = session.configuration['program']; + const command = eval('`' + config.debugPreLaunch + '`'); // resolve ${file} and config. + + new Promise((resolve, reject) => { + Logging.info(`Start preLaunch Task for remote debugging: ${command}`); + client.exec(command, (err, stream) => { + if (err) return reject(err); + stream.stderr.on('data', (d) => { + Logging.error(`Stderr from remote debugging: ${d}`); + }) + stream.on('data', (d) => { + Logging.debug(`Stdout from remote debugging: ${d}`); + }) + stream.on('error', reject); + stream.on('close', (exitCode, signal) => { + if (exitCode || signal) { + return reject(new Error("error listing directory")); + } + resolve(); + }); + }); + }); + }}}; + }} + }); + + vscode.debug.registerDebugAdapterTrackerFactory('*', { + createDebugAdapterTracker(session: vscode.DebugSession) { + if (session.configuration['dapTrace']) { + return { + onWillStartSession: () => console.log(`start: ${session.id}`), + onWillReceiveMessage: m => console.log(`===> ${JSON.stringify(m, undefined, 2)}`), + onDidSendMessage: m => console.log(`<=== ${JSON.stringify(m, undefined, 2)}`), + onWillStopSession: () => console.log(`stop: ${session.id}`), + onError: err => console.log(`error: ${err}`), + onExit: (code, signal) => console.log(`exit: ${code}`) + }; + } + } + }); + const sftp = await getSFTP(client, config); const fs = new SSHFileSystem(name, sftp, root, config!); Logging.info(`Created SSHFileSystem for ${name}, reading root directory...`); diff --git a/webview/src/ConfigEditor/fields.tsx b/webview/src/ConfigEditor/fields.tsx index fc83aec..7987a67 100644 --- a/webview/src/ConfigEditor/fields.tsx +++ b/webview/src/ConfigEditor/fields.tsx @@ -109,8 +109,21 @@ export function passphrase(config: FileSystemConfig, onChange: FSCChanged<'passp return } +export function debugPort(config: FileSystemConfig, onChange: FSCChanged<'debugPort'>): React.ReactElement { + const callback = (value?: number) => onChange('debugPort', value); + const description = 'Debug port to attach'; + return +} + +export function debugPreLaunch(config: FileSystemConfig, onChange: FSCChanged<'debugPreLaunch'>): React.ReactElement { + const callback = (value?: string) => onChange('debugPreLaunch', value); + const description = 'Task to run before debug session starts. SSH command: e.g. `/opt/vistec/python/bin/python -m ptvsd --host ${config.host} --port ${config.debugPort} --wait ${file}`'; + return +} + export type FieldFactory = (config: FileSystemConfig, onChange: FSCChanged, onChangeMultiple: FSCChangedMultiple) => React.ReactElement | null; export const FIELDS: FieldFactory[] = [ name, merge, label, group, putty, host, port, root, agent, username, password, privateKeyPath, passphrase, - PROXY_FIELD]; + PROXY_FIELD, + debugPort, debugPreLaunch]; diff --git a/webview/src/types/fileSystemConfig.ts b/webview/src/types/fileSystemConfig.ts index 4ec8378..869a381 100644 --- a/webview/src/types/fileSystemConfig.ts +++ b/webview/src/types/fileSystemConfig.ts @@ -102,6 +102,10 @@ export interface FileSystemConfig extends ConnectConfig { _location?: ConfigLocation; /** Internal property keeping track of where this config comes from (including merges) */ _locations: ConfigLocation[]; + /** Debug port to attach */ + debugPort?: number; + /** Task to run before debug session starts. SSH command: e.g. `/opt/vistec/python/bin/python -m ptvsd --host ${config.host} --port ${config.debugPort} --wait ${file}` */ + debugPreLaunch?: string; } export function invalidConfigName(name: string) {