-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: print target and package names formatted as file hyperlinks #15405
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,13 +7,16 @@ use anyhow::bail; | |||||
use cargo_util::paths::normalize_path; | ||||||
use cargo_util::ProcessBuilder; | ||||||
use std::fmt::Write; | ||||||
use std::path::Path; | ||||||
use std::path::PathBuf; | ||||||
|
||||||
const ITEM_INDENT: &str = " "; | ||||||
|
||||||
fn get_available_targets<'a>( | ||||||
filter_fn: fn(&Target) -> bool, | ||||||
ws: &'a Workspace<'_>, | ||||||
options: &'a CompileOptions, | ||||||
) -> CargoResult<Vec<&'a str>> { | ||||||
) -> CargoResult<Vec<(&'a str, &'a Path)>> { | ||||||
let packages = options.spec.get_packages(ws)?; | ||||||
|
||||||
let mut targets: Vec<_> = packages | ||||||
|
@@ -24,7 +27,12 @@ fn get_available_targets<'a>( | |||||
.iter() | ||||||
.filter(|target| filter_fn(target)) | ||||||
}) | ||||||
.map(Target::name) | ||||||
.map(|target| { | ||||||
( | ||||||
target.name(), | ||||||
target.src_path().path().expect("Target is not a `Metabuild` but one of `Bin` | `Test` | `Bench` | `ExampleBin`") | ||||||
) | ||||||
}) | ||||||
.collect(); | ||||||
|
||||||
targets.sort(); | ||||||
|
@@ -48,8 +56,10 @@ fn print_available_targets( | |||||
writeln!(output, "No {} available.", plural_name)?; | ||||||
} else { | ||||||
writeln!(output, "Available {}:", plural_name)?; | ||||||
for target in targets { | ||||||
writeln!(output, " {}", target)?; | ||||||
let mut shell = ws.gctx().shell(); | ||||||
for (name, src_path) in targets { | ||||||
let link = shell.err_file_hyperlink(src_path); | ||||||
writeln!(output, "{ITEM_INDENT}{link}{}{link:#}", name)?; | ||||||
} | ||||||
} | ||||||
bail!("{}", output) | ||||||
|
@@ -58,7 +68,7 @@ fn print_available_targets( | |||||
pub fn print_available_packages(ws: &Workspace<'_>) -> CargoResult<()> { | ||||||
let packages = ws | ||||||
.members() | ||||||
.map(|pkg| pkg.name().as_str()) | ||||||
.map(|pkg| (pkg.name().as_str(), pkg.manifest_path())) | ||||||
.collect::<Vec<_>>(); | ||||||
|
||||||
let mut output = "\"--package <SPEC>\" requires a SPEC format value, \ | ||||||
|
@@ -72,8 +82,10 @@ pub fn print_available_packages(ws: &Workspace<'_>) -> CargoResult<()> { | |||||
writeln!(output, "No packages available.")?; | ||||||
} else { | ||||||
writeln!(output, "Possible packages/workspace members:")?; | ||||||
for package in packages { | ||||||
writeln!(output, " {}", package)?; | ||||||
let mut shell = ws.gctx().shell(); | ||||||
for (name, manifest_path) in packages { | ||||||
let link = shell.err_file_hyperlink(manifest_path); | ||||||
writeln!(output, "{ITEM_INDENT}{link}{}{link:#}", name)?; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
bail!("{}", output) | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On macOS:
@ehuss would you happen to know why iterm2 doesn't really render those links?
Finished
devprofile [unoptimized + debuginfo] target(s) in 0.04s
should also have a rendered link, but on iterm2 I didn't see it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is a two-way door decision, and we already provide a way to disable the behavior, so the bar accepting this should be fairly low. However, as @ehuss has raised a concern of iterm2, I'd like to hear opinions from them :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, it is disabled via
cargo/src/cargo/core/shell.rs
Line 584 in c7be060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah and by turning hyperlink on always, both alacritty and iTerm2 work for me. I am going to merge this since iTerm2 is already always disabled.