From f4b6baa043dd6ad966a6fd8c6cc0ac57c3dd00c6 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 5 Dec 2024 20:54:37 +0000 Subject: [PATCH 1/3] 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. --- vscode/package.json | 5 ++++ vscode/src/common.ts | 1 + vscode/src/rubyLsp.ts | 62 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/vscode/package.json b/vscode/package.json index ebeb9a68d..90c5d8e2f 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -153,6 +153,11 @@ "command": "rubyLsp.collectRubyLspInfo", "title": "Collect Ruby LSP information for issue reporting", "category": "Ruby LSP" + }, + { + "command": "rubyLsp.migrateLaunchConfiguration", + "title": "Migrate launch.json configurations from rdbg to ruby_lsp", + "category": "Ruby LSP" } ], "configuration": { diff --git a/vscode/src/common.ts b/vscode/src/common.ts index 061acae19..7652eccb3 100644 --- a/vscode/src/common.ts +++ b/vscode/src/common.ts @@ -29,6 +29,7 @@ export enum Command { NewMinitestFile = "rubyLsp.newMinitestFile", CollectRubyLspInfo = "rubyLsp.collectRubyLspInfo", StartServerInDebugMode = "rubyLsp.startServerInDebugMode", + MigrateLaunchConfiguration = "rubyLsp.migrateLaunchConfiguration", } export interface RubyInterface { diff --git a/vscode/src/rubyLsp.ts b/vscode/src/rubyLsp.ts index 6bc84d00e..f49d9a517 100644 --- a/vscode/src/rubyLsp.ts +++ b/vscode/src/rubyLsp.ts @@ -597,6 +597,68 @@ export class RubyLsp { }, ), ); + vscode.commands.registerCommand( + Command.MigrateLaunchConfiguration, + async () => { + const workspace = await this.showWorkspacePick(); + + if (!workspace) { + return; + } + + const launchConfig = + (vscode.workspace + .getConfiguration("launch") + ?.get("configurations") as any[]) || []; + + const updatedLaunchConfig = launchConfig.map((config: any) => { + if (config.type === "rdbg") { + if (config.request === "launch") { + const newConfig = { ...config }; + newConfig.type = "ruby_lsp"; + + if (newConfig.askParameters !== true) { + delete newConfig.rdbgPath; + delete newConfig.cwd; + delete newConfig.useBundler; + + const command = (newConfig.command || "").replace( + "${workspaceRoot}/", + "", + ); + const script = newConfig.script || ""; + const args = (newConfig.args || []).join(" "); + newConfig.program = `${command} ${script} ${args}`.trim(); + + delete newConfig.command; + delete newConfig.script; + delete newConfig.args; + delete newConfig.askParameters; + } + + return newConfig; + } else if (config.request === "attach") { + const newConfig = { ...config }; + newConfig.type = "ruby_lsp"; + // rdbg's `debugPort` could be socket path, or port number, or host:port + // we don't do complex parsing here, just assume it's socket path + newConfig.debugSocketPath = config.debugPort; + + return newConfig; + } + } + return config; + }); + + await vscode.workspace + .getConfiguration("launch") + .update( + "configurations", + updatedLaunchConfig, + vscode.ConfigurationTarget.Workspace, + ); + }, + ); } // Get the current active workspace based on which file is opened in the editor From a407d77bfe627a973db652aa5d5be77519173ddf Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 5 Dec 2024 21:05:50 +0000 Subject: [PATCH 2/3] Fix debugger client's logging message trimming --- vscode/src/debugger.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/vscode/src/debugger.ts b/vscode/src/debugger.ts index 7ddbf51ca..737f4c34f 100644 --- a/vscode/src/debugger.ts +++ b/vscode/src/debugger.ts @@ -347,10 +347,12 @@ export class Debugger } private logDebuggerMessage(message: string) { - const trimmedMessage = message.trimEnd(); - if (trimmedMessage.length > 0) { - LOG_CHANNEL.info(`[debugger]: ${trimmedMessage}`); - this.console.append(trimmedMessage); - } + // In the Output panel, each log automatically gets a new line + // And trailing newlines will create one additional line in the panel, so we trimEnd() here to avoid that + LOG_CHANNEL.info(`[debugger]: ${message.trimEnd()}`); + + // In the Debug Console, output doesn't get a new line automatically, so we don't trimEnd() here as well as print + // the newlines too + this.console.append(message); } } From 5ab67962997b51f4face2b67d3c8f167e9f1e5de Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Wed, 18 Dec 2024 21:36:02 +0000 Subject: [PATCH 3/3] Address feedback --- vscode/src/debugger.ts | 8 ++++---- vscode/src/rubyLsp.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vscode/src/debugger.ts b/vscode/src/debugger.ts index 737f4c34f..88b115174 100644 --- a/vscode/src/debugger.ts +++ b/vscode/src/debugger.ts @@ -347,12 +347,12 @@ export class Debugger } private logDebuggerMessage(message: string) { - // In the Output panel, each log automatically gets a new line - // And trailing newlines will create one additional line in the panel, so we trimEnd() here to avoid that + // Log to Output panel: Messages here automatically get newlines appended. + // Trim trailing newlines to prevent unwanted blank lines in the output LOG_CHANNEL.info(`[debugger]: ${message.trimEnd()}`); - // In the Debug Console, output doesn't get a new line automatically, so we don't trimEnd() here as well as print - // the newlines too + // Log to Debug Console: Unlike Output panel, this needs explicit newlines + // so we preserve the original message format including any newlines this.console.append(message); } } diff --git a/vscode/src/rubyLsp.ts b/vscode/src/rubyLsp.ts index f49d9a517..3d66b587d 100644 --- a/vscode/src/rubyLsp.ts +++ b/vscode/src/rubyLsp.ts @@ -640,7 +640,7 @@ export class RubyLsp { } else if (config.request === "attach") { const newConfig = { ...config }; newConfig.type = "ruby_lsp"; - // rdbg's `debugPort` could be socket path, or port number, or host:port + // rdbg's `debugPort` could be a socket path, or port number, or host:port // we don't do complex parsing here, just assume it's socket path newConfig.debugSocketPath = config.debugPort;