build icon indicating copy to clipboard operation
build copied to clipboard

emit OSC 8 terminal hyperlinks for file paths and error locations

Open ryanhanks-bestow opened this issue 1 month ago • 1 comments

Feature Request: Add OSC 8 Hyperlink Support

build_runner currently prints file paths and error locations (both relative paths and package: URIs) as plain text.

Modern terminal emulators and editors (including JetBrains + VS Code) support OSC 8 hyperlinks. These make file paths and error locations clickable, instantly opening the file (optionally, at an exact line and column.)

Adding this to build_runner would improve developer productivity.

Official Specification & References

  1. Primary specification – Xterm control sequences (updated June 2025)
    https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

  2. Detailed practical documentation – mintty wiki
    https://github.com/mintty/mintty/wiki/CtrlSeqs#hyperlinks

Implementation Notes

  • The Dart SDK already has reusable ANSI utilities (detect ANSI support via stdout.supportsAnsiEscapes). Optionally add a --no-hyperlinks flag for CI environments if necessary.
  • Resolve the hyperlink target to an absolute file:// URI (required for reliable opening in all terminals/IDEs):
    • Relative paths (e.g. lib/src/utils.dart:45) → resolve against the project root using the path package or Directory.current.
    • package: URIs (e.g. package:my_app/utils.dart:120) → resolve via package_config or Uri.base.resolve() to the real on-disk location (local package or .pub-cache).
  • Keep the display text exactly as currently printed (relative or package: form) — only the invisible hyperlink target changes.

Example:

lib/src/utils.dart:45:8      → clickable → file:///Users/me/project/lib/src/utils.dart:45:8
package:my_app/foo.dart:23   → clickable → file:///Users/me/.pub-cache/hosted/pub.dev/my_app-1.2.3/lib/foo.dart:23

Thank you for considering this enhancement!

ryanhanks-bestow avatar Nov 23 '25 21:11 ryanhanks-bestow

An good idea, thanks!

It would definitely be useful to have a clickable link to the primary input of a failed/warned build step, since that's the mostly place where you need to do the fix.

I'm not sure when I'll get a chance to look into it, if someone wants to experiment before then the place to do it would be

https://github.com/dart-lang/build/blob/master/build_runner/lib/src/logging/build_log.dart

which already has a concept of whether it's outputting plain text or with control codes

https://github.com/dart-lang/build/blob/1d3959ce384bf1611bf8e00e999bc17303a82239/build_runner/lib/src/logging/ansi_buffer.dart#L178

davidmorgan avatar Nov 24 '25 08:11 davidmorgan