Skip to content

Commit

Permalink
Add a new command to help users migrate launch.json configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Aug 15, 2024
1 parent e18d456 commit 7b8ff80
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export enum Command {
RailsGenerate = "rubyLsp.railsGenerate",
RailsDestroy = "rubyLsp.railsDestroy",
NewMinitestFile = "rubyLsp.newMinitestFile",
MigrateLaunchConfiguration = "rubyLsp.migrateLaunchConfiguration",
}

export interface RubyInterface {
Expand Down
62 changes: 62 additions & 0 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}/",

Check warning on line 600 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Unexpected template string expression

Check warning on line 600 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Unexpected template string expression
"",
);
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
Expand Down

0 comments on commit 7b8ff80

Please sign in to comment.