From 7b8ff80b435cbe41a6be0b63a0c5aa1c3e6a5d0c Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 15 Aug 2024 22:02:34 +0100 Subject: [PATCH] Add a new command to help users migrate launch.json configurations --- 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 95b10010b..dfd383aff 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -140,6 +140,11 @@ "title": "Ruby file operations", "category": "Ruby LSP", "icon": "$(ruby)" + }, + { + "command": "rubyLsp.migrateLaunchConfiguration", + "title": "Migrate vscode-rdbg's launch.json configurations to ruby_lsp style", + "category": "Ruby LSP" } ], "configuration": { diff --git a/vscode/src/common.ts b/vscode/src/common.ts index 9a868a135..eba9b445e 100644 --- a/vscode/src/common.ts +++ b/vscode/src/common.ts @@ -26,6 +26,7 @@ export enum Command { RailsGenerate = "rubyLsp.railsGenerate", RailsDestroy = "rubyLsp.railsDestroy", NewMinitestFile = "rubyLsp.newMinitestFile", + MigrateLaunchConfiguration = "rubyLsp.migrateLaunchConfiguration", } export interface RubyInterface { diff --git a/vscode/src/rubyLsp.ts b/vscode/src/rubyLsp.ts index 148fa14a2..1e5f6fcfb 100644 --- a/vscode/src/rubyLsp.ts +++ b/vscode/src/rubyLsp.ts @@ -571,6 +571,68 @@ export class RubyLsp { }), vscode.commands.registerCommand(Command.NewMinitestFile, newMinitestFile), ); + 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