Skip to content

Commit 98aa3b9

Browse files
committed
better runnables support
1 parent 5de25c8 commit 98aa3b9

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

tools/rust_analyzer/aquery.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,15 @@ fn consolidate_crate_specs(crate_specs: Vec<CrateSpec>) -> anyhow::Result<BTreeS
226226
if spec.crate_type == CrateType::Rlib {
227227
existing.display_name = spec.display_name;
228228
existing.crate_type = CrateType::Rlib;
229-
existing.build = spec.build;
230229
existing.is_test = spec.is_test;
231230
}
232231

232+
// We want to use the test target's build label to provide
233+
// unit tests codelens actions for library crates in IDEs.
234+
if spec.is_test {
235+
existing.build = spec.build;
236+
}
237+
233238
// For proc-macro crates that exist within the workspace, there will be a
234239
// generated crate-spec in both the fastbuild and opt-exec configuration.
235240
// Prefer proc macro paths with an opt-exec component in the path.

tools/rust_analyzer/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,5 @@ fn generate_rust_project(
161161
let sysroot_src = &toolchain_info["sysroot_src"];
162162
let sysroot = &toolchain_info["sysroot"];
163163

164-
rust_project::generate_rust_project(workspace, sysroot, sysroot_src, &crate_specs)
164+
rust_project::generate_rust_project(bazel, workspace, sysroot, sysroot_src, &crate_specs)
165165
}

tools/rust_analyzer/rust_project.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub struct Build {
150150
pub target_kind: TargetKind,
151151
}
152152

153-
#[derive(Clone, Copy, Debug, Serialize)]
153+
#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
154154
#[serde(rename_all = "camelCase")]
155155
pub enum TargetKind {
156156
Bin,
@@ -213,6 +213,7 @@ pub enum RunnableKind {
213213
}
214214

215215
pub fn generate_rust_project(
216+
bazel: &Utf8Path,
216217
workspace: &Utf8Path,
217218
sysroot: &str,
218219
sysroot_src: &str,
@@ -224,13 +225,13 @@ pub fn generate_rust_project(
224225
crates: Vec::new(),
225226
runnables: vec![
226227
Runnable {
227-
program: "bazel".to_owned(),
228+
program: bazel.to_string(),
228229
args: vec!["build".to_owned(), "{label}".to_owned()],
229230
cwd: workspace.to_owned(),
230231
kind: RunnableKind::Check,
231232
},
232233
Runnable {
233-
program: "bazel".to_owned(),
234+
program: bazel.to_string(),
234235
args: vec![
235236
"test".to_owned(),
236237
"{label}".to_owned(),
@@ -284,6 +285,17 @@ pub fn generate_rust_project(
284285
| CrateType::ProcMacro => TargetKind::Lib,
285286
};
286287

288+
if let Some(build) = &c.build {
289+
if target_kind == TargetKind::Bin {
290+
project.runnables.push(Runnable {
291+
program: bazel.to_string(),
292+
args: vec!["run".to_string(), build.label.to_owned()],
293+
cwd: workspace.to_owned(),
294+
kind: RunnableKind::Run,
295+
});
296+
}
297+
}
298+
287299
project.crates.push(Crate {
288300
display_name: Some(c.display_name.clone()),
289301
root_module: c.root_module.clone(),

0 commit comments

Comments
 (0)