Skip to content

Commit f8fd63c

Browse files
committed
Add a new command to help users migrate launch.json configurations
Ruby LSP now provides better logging and error messages when the debugger failed to start. And we plan to keep improving the debugging experience in the future. If users are currently using vscode-rdbg and want to try Ruby LSP, we can help them migrate their launch.json configurations to the format used by Ruby LSP.
1 parent 7ae917e commit f8fd63c

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

vscode/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@
153153
"command": "rubyLsp.collectRubyLspInfo",
154154
"title": "Collect Ruby LSP Information for Issue Reporting",
155155
"category": "Ruby LSP"
156+
},
157+
{
158+
"command": "rubyLsp.migrateLaunchConfiguration",
159+
"title": "Migrate launch.json configurations from rdbg to ruby_lsp",
160+
"category": "Ruby LSP"
156161
}
157162
],
158163
"configuration": {

vscode/src/common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export enum Command {
2929
NewMinitestFile = "rubyLsp.newMinitestFile",
3030
CollectRubyLspInfo = "rubyLsp.collectRubyLspInfo",
3131
StartServerInDebugMode = "rubyLsp.startServerInDebugMode",
32+
MigrateLaunchConfiguration = "rubyLsp.migrateLaunchConfiguration",
3233
}
3334

3435
export interface RubyInterface {

vscode/src/rubyLsp.ts

+62
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,68 @@ export class RubyLsp {
597597
},
598598
),
599599
);
600+
vscode.commands.registerCommand(
601+
Command.MigrateLaunchConfiguration,
602+
async () => {
603+
const workspace = await this.showWorkspacePick();
604+
605+
if (!workspace) {
606+
return;
607+
}
608+
609+
const launchConfig =
610+
(vscode.workspace
611+
.getConfiguration("launch")
612+
?.get("configurations") as any[]) || [];
613+
614+
const updatedLaunchConfig = launchConfig.map((config: any) => {
615+
if (config.type === "rdbg") {
616+
if (config.request === "launch") {
617+
const newConfig = { ...config };
618+
newConfig.type = "ruby_lsp";
619+
620+
if (newConfig.askParameters !== true) {
621+
delete newConfig.rdbgPath;
622+
delete newConfig.cwd;
623+
delete newConfig.useBundler;
624+
625+
const command = (newConfig.command || "").replace(
626+
"${workspaceRoot}/",
627+
"",
628+
);
629+
const script = newConfig.script || "";
630+
const args = (newConfig.args || []).join(" ");
631+
newConfig.program = `${command} ${script} ${args}`.trim();
632+
633+
delete newConfig.command;
634+
delete newConfig.script;
635+
delete newConfig.args;
636+
delete newConfig.askParameters;
637+
}
638+
639+
return newConfig;
640+
} else if (config.request === "attach") {
641+
const newConfig = { ...config };
642+
newConfig.type = "ruby_lsp";
643+
// rdbg's `debugPort` could be socket path, or port number, or host:port
644+
// we don't do complex parsing here, just assume it's socket path
645+
newConfig.debugSocketPath = config.debugPort;
646+
647+
return newConfig;
648+
}
649+
}
650+
return config;
651+
});
652+
653+
await vscode.workspace
654+
.getConfiguration("launch")
655+
.update(
656+
"configurations",
657+
updatedLaunchConfig,
658+
vscode.ConfigurationTarget.Workspace,
659+
);
660+
},
661+
);
600662
}
601663

602664
// Get the current active workspace based on which file is opened in the editor

0 commit comments

Comments
 (0)