isInUserProject method

bool isInUserProject(
  1. Uri targetUri
)

Checks whether targetUri 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 (!targetUri.isScheme('file')) {
    return false;
  }

  final targetPath = targetUri
      .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.
      .toLowerCase();

  return projectPaths
      .map((projectPath) => projectPath.toLowerCase())
      .any((projectPath) => path.isWithin(projectPath, targetPath));
}