Skip to content

Commit 33ee639

Browse files
committed
feat: print target names formatted as file hyperlinks
This resolves #15401
1 parent 0e93c5b commit 33ee639

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/cargo/util/workspace.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ use anyhow::bail;
77
use cargo_util::paths::normalize_path;
88
use cargo_util::ProcessBuilder;
99
use std::fmt::Write;
10+
use std::path::Path;
1011
use std::path::PathBuf;
1112

13+
const ITEM_INDENT: &str = " ";
14+
1215
fn get_available_targets<'a>(
1316
filter_fn: fn(&Target) -> bool,
1417
ws: &'a Workspace<'_>,
1518
options: &'a CompileOptions,
16-
) -> CargoResult<Vec<&'a str>> {
19+
) -> CargoResult<Vec<(&'a str, &'a Path)>> {
1720
let packages = options.spec.get_packages(ws)?;
1821

1922
let mut targets: Vec<_> = packages
@@ -24,7 +27,12 @@ fn get_available_targets<'a>(
2427
.iter()
2528
.filter(|target| filter_fn(target))
2629
})
27-
.map(Target::name)
30+
.map(|target| {
31+
(
32+
target.name(),
33+
target.src_path().path().expect("Target is not a `Metabuild` but one of `Bin` | `Test` | `Bench` | `ExampleBin`")
34+
)
35+
})
2836
.collect();
2937

3038
targets.sort();
@@ -48,8 +56,10 @@ fn print_available_targets(
4856
writeln!(output, "No {} available.", plural_name)?;
4957
} else {
5058
writeln!(output, "Available {}:", plural_name)?;
51-
for target in targets {
52-
writeln!(output, " {}", target)?;
59+
let mut shell = ws.gctx().shell();
60+
for (name, src_path) in targets {
61+
let link = shell.err_file_hyperlink(src_path);
62+
writeln!(output, "{ITEM_INDENT}{link}{}{link:#}", name)?;
5363
}
5464
}
5565
bail!("{}", output)
@@ -58,7 +68,7 @@ fn print_available_targets(
5868
pub fn print_available_packages(ws: &Workspace<'_>) -> CargoResult<()> {
5969
let packages = ws
6070
.members()
61-
.map(|pkg| pkg.name().as_str())
71+
.map(|pkg| (pkg.name().as_str(), pkg.manifest_path()))
6272
.collect::<Vec<_>>();
6373

6474
let mut output = "\"--package <SPEC>\" requires a SPEC format value, \
@@ -72,8 +82,10 @@ pub fn print_available_packages(ws: &Workspace<'_>) -> CargoResult<()> {
7282
writeln!(output, "No packages available.")?;
7383
} else {
7484
writeln!(output, "Possible packages/workspace members:")?;
75-
for package in packages {
76-
writeln!(output, " {}", package)?;
85+
let mut shell = ws.gctx().shell();
86+
for (name, manifest_path) in packages {
87+
let link = shell.err_file_hyperlink(manifest_path);
88+
writeln!(output, "{ITEM_INDENT}{link}{}{link:#}", name)?;
7789
}
7890
}
7991
bail!("{}", output)

0 commit comments

Comments
 (0)