Skip to content

Commit e9d025b

Browse files
committed
fixup! feat: add debug code lens
avoid repetition of `--no-run`
1 parent a034257 commit e9d025b

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

crates/rust-analyzer/src/main_loop/handlers.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -795,24 +795,27 @@ pub fn handle_code_lens(
795795
RunnableKind::Bin => "Run",
796796
}
797797
.to_string();
798-
let r = to_lsp_runnable(&world, file_id, runnable)?;
799-
let range = r.range;
800-
let arguments = vec![to_value(r).unwrap()];
798+
let mut r = to_lsp_runnable(&world, file_id, runnable)?;
801799
let lens = CodeLens {
802-
range: range.clone(),
800+
range: r.range,
803801
command: Some(Command {
804802
title,
805803
command: "rust-analyzer.runSingle".into(),
806-
arguments: Some(arguments.clone()),
804+
arguments: Some(vec![to_value(&r).unwrap()]),
807805
}),
808806
data: None,
809807
};
808+
if r.args[0] == "run" {
809+
r.args[0] = "build".into();
810+
} else {
811+
r.args.push("--no-run".into());
812+
}
810813
let debug_lens = CodeLens {
811-
range,
814+
range: r.range,
812815
command: Some(Command {
813816
title: "Debug".into(),
814817
command: "rust-analyzer.debugSingle".into(),
815-
arguments: Some(arguments.clone()),
818+
arguments: Some(vec![to_value(r).unwrap()]),
816819
}),
817820
data: None,
818821
};

crates/rust-analyzer/tests/heavy_tests/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ fn main() {}
143143

144144
server.wait_until_workspace_is_loaded();
145145
server.request::<Runnables>(
146-
RunnablesParams {
147-
text_document: server.doc_id("foo/tests/spam.rs"),
148-
position: None,
149-
},
146+
RunnablesParams { text_document: server.doc_id("foo/tests/spam.rs"), position: None },
150147
json!([
151148
{
152149
"args": [ "test", "--package", "foo", "--test", "spam" ],
@@ -184,7 +181,7 @@ fn main() {}
184181
}
185182
}
186183
}
187-
])
184+
]),
188185
);
189186
}
190187

editors/code/src/commands/runnables.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ export function debugSingle(ctx: Ctx): Cmd {
6767
const editor = ctx.activeRustEditor;
6868
if (!editor) return;
6969

70-
if (config.args[0] === 'run') {
71-
config.args[0] = 'build';
72-
} else {
73-
config.args.push('--no-run');
74-
}
75-
7670
const debugConfig = {
7771
type: "lldb",
7872
request: "launch",
@@ -83,6 +77,7 @@ export function debugSingle(ctx: Ctx): Cmd {
8377
args: config.extraArgs,
8478
cwd: config.cwd
8579
};
80+
8681
return vscode.debug.startDebugging(undefined, debugConfig);
8782
};
8883
}

0 commit comments

Comments
 (0)