Skip to content

clang: make file paths with spaces clickable via OSC 8 hyperlinks#4368

Closed
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-osc8-hyperlinks-in-clang
Closed

clang: make file paths with spaces clickable via OSC 8 hyperlinks#4368
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-osc8-hyperlinks-in-clang

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 2, 2026

Error messages referencing paths like C:\Program Files (x86)\Windows Kits\... are not clickable in terminals because spaces break link detection. OSC 8 hyperlinks solve this by embedding the URI separately from the display text.

  • error.rs
    • hyperlink_path(): wraps the raw file path with OSC 8 escape sequences only when stderr is an interactive TTY (std::io::IsTerminal); falls back to plain text for piped/redirected output. The raw file path is used directly as the OSC 8 URI — no file:// conversion is needed.
    • Error::fmt: calls hyperlink_path() when emitting the file path portion of error messages

Note: The TTY guard means hyperlinks are only emitted when the process's stderr is directly connected to an interactive console. In build-script and cargo test contexts, cargo pipes stderr, so is_terminal() returns false and plain paths are produced — which is the correct behaviour for those environments.

Error output in a supporting terminal (e.g. Windows Terminal, VS Code, iTerm2) when running a binary directly:

error: unknown type name 'ACME'
 --> C:\Program Files (x86)\Windows Kits\10\include\10.0.32000.1\um\acme.h:294:9
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      (entire path is a clickable hyperlink)

Copilot AI changed the title [WIP] Fix clickable file paths with spaces using OSC 8 hyperlinks in clang clang: make file paths with spaces clickable via OSC 8 hyperlinks May 2, 2026
Copilot AI requested a review from riverar May 2, 2026 06:09
Copilot finished work on behalf of riverar May 2, 2026 06:09
Comment thread crates/libs/rdl/src/error.rs Outdated
Copilot finished work on behalf of riverar May 2, 2026 07:28
Copilot AI requested a review from riverar May 2, 2026 07:28
Comment thread crates/tests/libs/clang/tests/panic.rs Outdated
Copilot finished work on behalf of riverar May 2, 2026 16:29
Copilot AI requested a review from riverar May 2, 2026 16:29
@riverar riverar marked this pull request as ready for review May 2, 2026 17:20
@riverar riverar marked this pull request as draft May 2, 2026 17:25
@riverar
Copy link
Copy Markdown
Collaborator

riverar commented May 2, 2026

Hold up, something squirrely I need to check.

@riverar
Copy link
Copy Markdown
Collaborator

riverar commented May 2, 2026

@copilot

The following code, regardless of terminal:

windows_rdl::clang()
        .args(["-x", "c++"])
        .input_str(&format!(
            r#"
            #include <imm.h>
            "#
        ))
        .output("src/bindings.rs")
        .namespace("AAA")
        .write()
        .unwrap();

Results in output with a non-hyperlinked path:

...
error: unknown type name 'DWORD'
 --> C:\Program Files (x86)\Windows Kits\10\\include\10.0.28000.0\\um\imm.h:34:9

I'm not interested in resolving the error--that's known and expected.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 2, 2026

@copilot

The following code, regardless of terminal:
...

The is_terminal() check evaluates stderr at format time. When the code runs inside cargo test or a build script, cargo pipes the process's stderr, so is_terminal() correctly returns false and no OSC 8 sequences are emitted. Hyperlinks only appear when the binary runs directly in an interactive console where the process's stderr is connected to a real terminal handle.

Removing the is_terminal() guard would emit OSC 8 unconditionally (relying on the terminal to silently ignore sequences it doesn't understand), but that would require updating the panic.rs expected string — which conflicts with the earlier request to leave that test unchanged.

Happy to either revert the feature entirely, or remove the guard and accept the test update — whichever direction you'd prefer.

Copilot finished work on behalf of riverar May 2, 2026 17:40
Copilot AI requested a review from riverar May 2, 2026 17:40
@riverar
Copy link
Copy Markdown
Collaborator

riverar commented May 2, 2026

Closing for now, need to noodle on this further.

@riverar riverar closed this May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

windows-rdl / clang: make file paths with spaces clickable with OSC 8 hyperlinks

3 participants