Skip to content

Commit 7b8ff80

Browse files
committed
Add a new command to help users migrate launch.json configurations
1 parent e18d456 commit 7b8ff80

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
@@ -140,6 +140,11 @@
140140
"title": "Ruby file operations",
141141
"category": "Ruby LSP",
142142
"icon": "$(ruby)"
143+
},
144+
{
145+
"command": "rubyLsp.migrateLaunchConfiguration",
146+
"title": "Migrate vscode-rdbg's launch.json configurations to ruby_lsp style",
147+
"category": "Ruby LSP"
143148
}
144149
],
145150
"configuration": {

vscode/src/common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export enum Command {
2626
RailsGenerate = "rubyLsp.railsGenerate",
2727
RailsDestroy = "rubyLsp.railsDestroy",
2828
NewMinitestFile = "rubyLsp.newMinitestFile",
29+
MigrateLaunchConfiguration = "rubyLsp.migrateLaunchConfiguration",
2930
}
3031

3132
export interface RubyInterface {

vscode/src/rubyLsp.ts

+62
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,68 @@ export class RubyLsp {
571571
}),
572572
vscode.commands.registerCommand(Command.NewMinitestFile, newMinitestFile),
573573
);
574+
vscode.commands.registerCommand(
575+
Command.MigrateLaunchConfiguration,
576+
async () => {
577+
const workspace = await this.showWorkspacePick();
578+
579+
if (!workspace) {
580+
return;
581+
}
582+
583+
const launchConfig =
584+
(vscode.workspace
585+
.getConfiguration("launch")
586+
?.get("configurations") as any[]) || [];
587+
588+
const updatedLaunchConfig = launchConfig.map((config: any) => {
589+
if (config.type === "rdbg") {
590+
if (config.request === "launch") {
591+
const newConfig = { ...config };
592+
newConfig.type = "ruby_lsp";
593+
594+
if (newConfig.askParameters !== true) {
595+
delete newConfig.rdbgPath;
596+
delete newConfig.cwd;
597+
delete newConfig.useBundler;
598+
599+
const command = (newConfig.command || "").replace(
600+
"${workspaceRoot}/",
601+
"",
602+
);
603+
const script = newConfig.script || "";
604+
const args = (newConfig.args || []).join(" ");
605+
newConfig.program = `${command} ${script} ${args}`.trim();
606+
607+
delete newConfig.command;
608+
delete newConfig.script;
609+
delete newConfig.args;
610+
delete newConfig.askParameters;
611+
}
612+
613+
return newConfig;
614+
} else if (config.request === "attach") {
615+
const newConfig = { ...config };
616+
newConfig.type = "ruby_lsp";
617+
// rdbg's `debugPort` could be socket path, or port number, or host:port
618+
// we don't do complex parsing here, just assume it's socket path
619+
newConfig.debugSocketPath = config.debugPort;
620+
621+
return newConfig;
622+
}
623+
}
624+
return config;
625+
});
626+
627+
await vscode.workspace
628+
.getConfiguration("launch")
629+
.update(
630+
"configurations",
631+
updatedLaunchConfig,
632+
vscode.ConfigurationTarget.Workspace,
633+
);
634+
},
635+
);
574636
}
575637

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

0 commit comments

Comments
 (0)