Skip to content

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 1 commit into from
Apr 7, 2025

Conversation

kpbaks
Copy link
Contributor

@kpbaks kpbaks commented Apr 6, 2025

Resolves #15401

Here is an example of the feature in kitty 0.40.1 with the following config set in ~/.config/kitty/kitty.conf

underline_hyperlinks always
show_hyperlink_targets yes
allow_hyperlinks yes
# ...

cargo-target-file-hyperlik-kitty-showcase

Tested on uname -a:

Linux nixos 6.14.0 #1-NixOS SMP PREEMPT_DYNAMIC Mon Mar 24 14:02:41 UTC 2025 x86_64 GNU/Linux

Terminals tested with:

image

The following cargo invocations will have their output be modified by this change:

cargo run # If multiple binaries are defined in the manifest and [package.default-bin] is not defined
cargo run --bin
cargo run --example
cargo run --package
cargo build --bin
cargo build --example
cargo build --package
cargo test --test
cargo test --bench

In addition I have done a slight refactor to have the printed indent of targets and packages be the same by using a shared constant named const ITEM_INDENT: &str = " ";

This is my first PR to the cargo codebase, so I am not familiar with what is expected in terms of test for a feature such as this.

@rustbot
Copy link
Collaborator

rustbot commented Apr 6, 2025

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-workspaces Area: workspaces S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 6, 2025
@tcanabrava
Copy link

this would also work on vte and konsole.

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks you.

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)?;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
writeln!(output, "{ITEM_INDENT}{link}{}{link:#}", name)?;
writeln!(output, "{ITEM_INDENT}{link}{name}{link:#}")?;

Copy link
Member

Choose a reason for hiding this comment

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

On macOS:

  • ghostty 1.0.1 opened the default editor.
  • kitty 0.38.1 opened the default editor.
  • iterm2 3.5.11 didn't render any link, even the old existing ones. Anyway, I tried
    printf '\e]8;;file:///Users/user/foo/Cargo.toml\e\\This is a link\e]8;;\e\\'
    
    It tried to scp at the first attempt as we found in feat: Make browser links out of HTML file paths #12889 (comment). However in subsequent attempts it worked correctly and opened the default editor.
  • alacritty 0.15.1 didn't render any link just like iterm2. With the same test link above it worked and opened the default editor.

@ehuss would you happen to know why iterm2 doesn't really render those links? Finished dev profile [unoptimized + debuginfo] target(s) in 0.04s should also have a rendered link, but on iterm2 I didn't see it.

Copy link
Member

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 :)

Copy link
Contributor

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

if std::env::var_os("TERM_PROGRAM").as_deref() == Some(std::ffi::OsStr::new("iTerm.app")) {
.

Copy link
Member

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.

@weihanglo weihanglo added this pull request to the merge queue Apr 7, 2025
Merged via the queue into rust-lang:master with commit 9bdf6b0 Apr 7, 2025
23 checks passed
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 12, 2025
Update cargo

12 commits in 0e93c5bf6a1d5ee7bc2af63d1afb16cd28793601..864f74d4eadcaea3eeda37a2e7f4d34de233d51e
2025-04-05 00:00:24 +0000 to 2025-04-11 20:37:27 +0000
- chore: Bump build-rs version (rust-lang/cargo#15421)
- fix(build): Correct name of CARGO_CFG_FEATURE (rust-lang/cargo#15420)
- Revert "fix(package): detect dirtiness for symlinks to submodule" (rust-lang/cargo#15419)
- Improved error message when build-dir template var is invalid (rust-lang/cargo#15418)
- Added validation for unmatched brackets in build-dir template (rust-lang/cargo#15414)
- fix(package): detect dirtiness for symlinks to submodule  (rust-lang/cargo#15416)
- chore(deps): bump crossbeam-channel from 0.5.14 to 0.5.15 (rust-lang/cargo#15415)
- docs(metadata): Added build_directory to cargo metadata documentation (rust-lang/cargo#15410)
- Added symlink resolution for `workspace-path-hash` (rust-lang/cargo#15400)
- feat: print target and package names formatted as file hyperlinks (rust-lang/cargo#15405)
- docs(ref): Use better example value in `CARGO_CFG_TARGET_ABI` (rust-lang/cargo#15404)
- chore: Bump cargo-util-schemas to 0.8.2 (rust-lang/cargo#15403)

r? ghost
@rustbot rustbot added this to the 1.88.0 milestone Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-workspaces Area: workspaces 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.

Use file hyperlinks when outputting target names when running cargo run --bin and the like.
5 participants