describe method

String describe({
  1. String? relativeTo,
})

path/to/file.dart:12:5, with relativeTo stripped when it matches.

An absolute URI is the truth and a relative path is what anyone reading the output wants, so this keeps the first and prints the second.

A tree read over the VM service reaches above the user's code into the framework, and those files are genuinely outside the worktree — so relativeTo has nothing to strip and the reader got the whole of /Users/…/.flutterware/sdks/3.47.0-0.1.pre/packages/flutter/lib/src/widgets/binding.dart, six wrapped lines of it in a detail pane. _packageUri folds those back to package:flutter/src/widgets/binding.dart: shorter, and the name a reader would have used anyway.

The worktree wins when both could apply. A path inside the checkout is one the reader can open, and app/lib/src/shell/shell_view.dart says where it is where a package URI only says what it belongs to.

The relative path is a name, so it reads with / on every host — the same file says the same thing from a Mac, a Windows box and the web export. An absolute one stays as the platform spells it: that one is for opening.

Implementation

String describe({String? relativeTo}) {
  var path = Uri.tryParse(file)?.toFilePath() ?? file;
  // Non-empty, because the web export passes `''` — every path starts with
  // the empty string, so the old test matched, stripped nothing, and then
  // ate the leading slash on its way out.
  if (relativeTo != null &&
      relativeTo.isNotEmpty &&
      p.isWithin(relativeTo, path)) {
    var name = p.url.joinAll(p.split(p.relative(path, from: relativeTo)));
    return '$name:$line:$column';
  }
  return '${_packageUri(path) ?? path}:$line:$column';
}