isInUserProject method
Checks whether uri
is inside the users project. This is used to support
debugging "Just My Code" (via isExternalPackageLibrary) and also for
stack trace highlighting, where non-user code will be faded.
Implementation
bool isInUserProject(Uri targetUri) {
if (!isSupportedFileScheme(targetUri)) {
return false;
}
// We could already be 'file', or we could be another supported file scheme
// like dart-macro+file, but we can only call toFilePath() on a file URI
// and we use the equivalent path to decide if this is within the workspace.
var targetPath = targetUri.replace(scheme: 'file').toFilePath();
// Always compare paths case-insensitively to avoid any issues where APIs
// may have returned different casing (e.g. Windows drive letters). It's
// almost certain a user wouldn't have a "local" package and an "external"
// package with paths differing only be case.
targetPath = targetPath.toLowerCase();
return projectPaths
.map((projectPath) => projectPath.toLowerCase())
.any((projectPath) => path.isWithin(projectPath, targetPath));
}