Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new command to help users migrate launch.json configurations #2450

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"title": "Migrate launch.json configurations from rdbg to ruby_lsp",
"title": "Migrate debug launch.json configurations from rdbg to ruby_lsp",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to add debug before it as there's no other types of launch.json.

"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 @@ -29,6 +29,7 @@ export enum Command {
NewMinitestFile = "rubyLsp.newMinitestFile",
CollectRubyLspInfo = "rubyLsp.collectRubyLspInfo",
StartServerInDebugMode = "rubyLsp.startServerInDebugMode",
MigrateLaunchConfiguration = "rubyLsp.migrateLaunchConfiguration",
}

export interface RubyInterface {
Expand Down
12 changes: 7 additions & 5 deletions vscode/src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
// 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()}`);

// 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);
}
}
62 changes: 62 additions & 0 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,68 @@
},
),
);
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 626 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Unexpected template string expression

Check warning on line 626 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 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;

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
Loading