Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ You can specify the following "attach" configurations.
* Specify pairs of remote root path and local root path like `/remote_dir:/local_dir` if sharing the same source repository with local and remote computers.
* You can specify multiple pairs like `/rem1:/loc1,/rem2:/loc2` by concatenating with `,`.
* default: undefined
* `supportAttachMultiSockets`
* Allow for attaching multiple running sockets at once

Without `debugPort` configuration, the

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
"type": "string",
"description": "Specify pairs of remote root path and local root path like `/remote_dir:/local_dir`. `/remote_dir:$(workspaceFolder)` is useful. You can specify multiple pairs like `/rem1:/loc1,/rem2:/loc2` by concatenating with `,`."
},
"supportAttachMultiSockets": {
"type": "boolean",
"description": "Allow for attaching multiple running sockets at once",
"default": false
},
"env": {
"type": "object",
"description": "Additional environment variables to pass to the rdbg process",
Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface AttachConfiguration extends DebugConfiguration {
debugPort?: string;
cwd?: string;
showProtocolLog?: boolean;
supportAttachMultiSockets?: boolean;

autoAttach?: string;
}
Expand All @@ -32,5 +33,5 @@ export interface LaunchConfiguration extends DebugConfiguration {
rdbgPath?: string;
showProtocolLog?: boolean;

useTerminal?: boolean
useTerminal?: boolean;
}
51 changes: 51 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let lastExecCommand: string | undefined;
let lastProgram: string | undefined;

const terminalName: string = "Ruby Debug Terminal";
const attachSingleSocketEvent: string = "attachSingleSocket";

function workspaceFolder(): string | undefined {
if (vscode.workspace.workspaceFolders) {
Expand Down Expand Up @@ -119,6 +120,24 @@ export function activate(context: vscode.ExtensionContext) {
}
}));

context.subscriptions.push(
vscode.debug.onDidReceiveDebugSessionCustomEvent((e) => {
switch (e.event) {
case attachSingleSocketEvent:
vscode.debug.startDebugging(
e.session.workspaceFolder,
{
type: "rdbg",
name: e.body.name,
request: "attach",
debugPort: e.body.socketPath,
} as AttachConfiguration,
e.session,
);
}
}),
);

const folders = vscode.workspace.workspaceFolders;

if (folders !== undefined && folders.length > 0) {
Expand Down Expand Up @@ -265,6 +284,34 @@ class StopDebugAdapter implements vscode.DebugAdapter {
}
}

class MultiSessionDebugAdapter implements vscode.DebugAdapter {
private sockPaths: Array<string> = [];
private sendMessage = new vscode.EventEmitter<vscode.DebugProtocolMessage>();
readonly onDidSendMessage: vscode.Event<any> = this.sendMessage.event;

constructor(sockPaths: Array<string>) {
this.sockPaths = sockPaths;
}

handleMessage(message: any): void {
if (message.type === "request" && message.command === "initialize") {
for (const [index, socketPath] of this.sockPaths.entries()) {
const name = socketPath.split("/").pop();
this.sendMessage.fire({
type: "event",
seq: index,
event: attachSingleSocketEvent,
body: { name, socketPath },
});
}
}
}

dispose() {
// Nothing to do
}
}

const findRDBGTerminal = (): vscode.Terminal | undefined => {
let terminal: vscode.Terminal | undefined;
const currentTerminals: vscode.Terminal[] = Array.from(outputTerminals.values());
Expand Down Expand Up @@ -479,6 +526,10 @@ class RdbgAdapterDescriptorFactory implements DebugAdapterDescriptorFactory, Ver
sockPath = list[0];
break;
default:
if (config.supportAttachMultiSockets) {
return new DebugAdapterInlineImplementation(new MultiSessionDebugAdapter(list));
}

const simplifiedList = this.simplifySockList(list);
const sock = await vscode.window.showQuickPick(simplifiedList, {
title: "debug ports in " + path.dirname(list[0])
Expand Down