Skip to content

Commit b005fbc

Browse files
authored
Add a new command to help users migrate launch.json configurations (#2450)
* 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. * Fix debugger client's logging message trimming * Address feedback
1 parent 53cbea6 commit b005fbc

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
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/debugger.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,12 @@ export class Debugger
347347
}
348348

349349
private logDebuggerMessage(message: string) {
350-
const trimmedMessage = message.trimEnd();
351-
if (trimmedMessage.length > 0) {
352-
LOG_CHANNEL.info(`[debugger]: ${trimmedMessage}`);
353-
this.console.append(trimmedMessage);
354-
}
350+
// Log to Output panel: Messages here automatically get newlines appended.
351+
// Trim trailing newlines to prevent unwanted blank lines in the output
352+
LOG_CHANNEL.info(`[debugger]: ${message.trimEnd()}`);
353+
354+
// Log to Debug Console: Unlike Output panel, this needs explicit newlines
355+
// so we preserve the original message format including any newlines
356+
this.console.append(message);
355357
}
356358
}

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 a 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)