Skip to content

feat(lsp): add debugOverrideCommand option#22236

Open
shorwood wants to merge 2 commits into
rust-lang:masterfrom
shorwood:feat/lsp-debug-override-command
Open

feat(lsp): add debugOverrideCommand option#22236
shorwood wants to merge 2 commits into
rust-lang:masterfrom
shorwood:feat/lsp-debug-override-command

Conversation

@shorwood
Copy link
Copy Markdown
Contributor

@shorwood shorwood commented May 1, 2026

Closes #22128

Adds debugOverrideCommand for test and bench runnables so debug can use a different command from Run. This is needed for runners like nextest, where running a test and debugging a test require different command shapes.

The setting is opt-in. Existing overrideCommand, Cargo debug config generation, and matching launch.json entries keep their current behavior.

For reference, here's my setup with this PR active.

{
    "rust-analyzer.server.path": "$HOME/Workspaces/rust-analyzer/target/debug/rust-analyzer",
    "rust-analyzer.runnables.test.overrideCommand": [
        "nix",
        "shell",
        "nixpkgs#cargo-nextest",
        "-c",
        "cargo",
        "nextest",
        "run",
        "--config",
        "profile.dev.debug=2",
        "--package",
        "${package}",
        "${target_arg}",
        "${target}",
        "--",
        "${test_name}",
        "${exact}",
        "${include_ignored}"
    ],
    "rust-analyzer.runnables.test.debugOverrideCommand": [
        "nix",
        "shell",
        "nixpkgs#cargo-nextest",
        "-c",
        "cargo",
        "nextest",
        "run",
        "--config",
        "profile.dev.debug=2",
        "--package",
        "${package}",
        "${target_arg}",
        "${target}",
        "--debugger",
        "$HOME/.vscode/extensions/vadimcn.vscode-lldb-1.12.1/bin/codelldb-launch --connect 127.0.0.1:12345 --",
        "--",
        "${test_name}",
        "${exact}",
        "${include_ignored}"
    ],
    "rust-analyzer.runnables.extraEnv": {
        "CODELLDB_LAUNCH_CONFIG": "{ token: 'secret' }"
    },
    "lldb.rpcServer": {
        "host": "127.0.0.1",
        "port": 12345,
        "token": "secret"
    }
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 1, 2026
@rustbot

This comment has been minimized.

@shorwood shorwood force-pushed the feat/lsp-debug-override-command branch from a7a3150 to 0e6e8b5 Compare May 1, 2026 08:26
@rustbot

This comment has been minimized.

Comment thread crates/rust-analyzer/src/lsp/ext.rs Outdated
@@ -453,6 +453,15 @@ pub struct Runnable {
pub location: Option<lsp_types::LocationLink>,
pub kind: RunnableKind,
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 7, 2026

Choose a reason for hiding this comment

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

Makes sense to also use RunnableCommand here? You can use serde(flatten).

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

location: Some(location),
kind: lsp_ext::RunnableKind::Shell,
args: lsp_ext::RunnableArgs::Shell(runnable_args),
debug: None,
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 7, 2026

Choose a reason for hiding this comment

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

Why don't we pass debug here too? It's even more useful for rust-project.json.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

agree, patched it

executable_args,
environment: Default::default(),
}),
debug: None,
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 7, 2026

Choose a reason for hiding this comment

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

Comment thread crates/rust-analyzer/src/config.rs Outdated
/// - `${include_ignored}`: always empty for benchmarks.
/// - `${executable_args}`: all of the above binary args bundled together
/// (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
runnables_bench_debugOverrideCommand: Option<Vec<String>> = None,
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 7, 2026

Choose a reason for hiding this comment

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

overrideDebugCommand makes more sense, the current name sounds like we're debugging the override.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread editors/code/src/run.ts
Comment on lines +190 to +196
env: includeShellExtraEnv
? prepareEnv(
true,
runnableArgs.environment,
config.runnablesExtraEnv(runnable.label),
)
: prepareBaseEnv(true),
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 7, 2026

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

@shorwood shorwood May 15, 2026

Choose a reason for hiding this comment

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

This only affects shell commands launched by the VS Code Debug action. Regular shell Run actions from overrideCommand or rust-project.json keep their existing environment behavior. Debug shell tasks can use rust-analyzer.runnables.extraEnv, for example to pass CODELLDB_LAUNCH_CONFIG for CodeLLDB + nextest.

@shorwood shorwood force-pushed the feat/lsp-debug-override-command branch from 5aea419 to 6547d35 Compare May 15, 2026 16:29
@shorwood shorwood force-pushed the feat/lsp-debug-override-command branch from 6547d35 to ec796ea Compare May 15, 2026 16:36
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 15, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom rust-analyzer.runnables.test.overrideCommand breaks Debug runnable button

3 participants