Documentation

ImportGraph.Imports.FromSource

Source-File-Based Import Analysis #

This module provides functions for analyzing imports by parsing source files directly, as an alternative to Environment-based analysis (e.g. in ImportGraph.Imports). Specifically:

Like parseImports', but pure. Instead of returning the fileName:pos <msg> error of parseImports' of parseImports', returns (fileMap, pos, <msg>).

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    Parse the header of the source file at path, returning its ModuleHeader.

    This is a thin wrapper around Lean.parseImports' which:

    • Reads the file from disk
    • Parses the import statements

    Note that it does not filter out Init modules. See ModuleHeader.filterInit.

    Equations
    Instances For

      Removes every import in the Init namespace (Init itself and Init.*) from a ModuleHeader.

      Equations
      Instances For

        Parses the header of the current file via the source string present in the ambient FileMap.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[deprecated "Use `ImportGraph.System.FilePath.parseImports'` and `ImportGraph.Lean.ModuleHeader.filterInit` instead" (since := "2026-09-13")]

          Parse all imports in a source file at path and return their module names.

          This is a thin wrapper around Lean.parseImports' that:

          • Reads the file from disk
          • Parses the import statements
          • Filters out Init (part of the prelude)

          Note: This only sees syntactic imports in the source file. It does not account for what declarations are actually used.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            Like modToFilePath, but does not demand base. Example: modToRelFilePath A.B.C "lean" results in A/B/C.lean. (Note that modToFilePath "" mod ext inserts a leading file separator, and would result in /A/B/C.lean.)

            Equations
            Instances For

              Compute the transitive closure of imports starting from a source file.

              Returns a NameSet of all modules that are transitively imported by the given file, by recursively parsing source files.

              Example:

              -- Get all transitive Mathlib imports
              let imports ← findTransitiveImportsFromSource "Mathlib/Algebra/Ring/Basic.lean" (some `Mathlib)
              
              -- Get all transitive imports regardless of namespace
              let allImports ← findTransitiveImportsFromSource "MyFile.lean"
              
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For