File: .lake/packages/importGraph/ImportGraph/Imports.lean

full_name: Lean.Environment.importsOf
code: /--
Find the imports of a given module.
-/
def importsOf (env : Environment) (n : Name) : Array Name 
goal: Array Lean.Name

full_name: Lean.Environment.importGraph.process
code: /--
Construct the import graph of the current file.
-/
partial def importGraph (env : Environment) : NameMap (Array Name) 
goal: Lean.NameMap (Array Lean.Name)

full_name: Lean.Environment.importGraph
code: /--
Construct the import graph of the current file.
-/
partial def importGraph (env : Environment) : NameMap (Array Name) 
goal: Lean.NameMap (Array Lean.Name)

full_name: Lean.Environment.findRedundantImports.visit
code: /--
Return the redundant imports (i.e. those transitively implied by another import)
amongst a candidate list of imports.
-/
partial def findRedundantImports (env : Environment) (imports : Array Name) : NameSet 
goal: Lean.NameSet × Lean.NameSet

full_name: Lean.Environment.findRedundantImports
code: /--
Return the redundant imports (i.e. those transitively implied by another import)
amongst a candidate list of imports.
-/
partial def findRedundantImports (env : Environment) (imports : Array Name) : NameSet 
goal: Lean.NameSet

full_name: Lean.NameMap.transitiveClosure
code: /--
Compute the transitive closure of an import graph.
-/
partial def transitiveClosure (m : NameMap (Array Name)) : NameMap NameSet 
goal: Lean.NameMap Lean.NameSet

full_name: Lean.NameMap.transitiveClosure.process
code: /--
Compute the transitive closure of an import graph.
-/
partial def transitiveClosure (m : NameMap (Array Name)) : NameMap NameSet 
goal: Lean.NameMap Lean.NameSet

full_name: Lean.NameMap.transitiveReduction
code: /--
Compute the transitive reduction of an import graph.

Typical usage is `transitiveReduction (← importGraph)`.
-/
def transitiveReduction (m : NameMap (Array Name)) : NameMap (Array Name) 
goal: Lean.NameMap (Array Lean.Name)

full_name: Lean.NameMap.downstreamOf
code: /-- Restrict an import graph to only the downstream dependencies of some set of modules. -/
def downstreamOf (m : NameMap (Array Name)) (targets : NameSet) : NameMap (Array Name) 
goal: Lean.NameMap (Array Lean.Name)

full_name: Lean.NameMap.upstreamOf
code: /-- Restrict an import graph to only the transitive imports of some set of modules. -/
def upstreamOf (m : NameMap (Array Name)) (targets : NameSet) : NameMap (Array Name) 
goal: Lean.NameMap (Array Lean.Name)

full_name: Lean.NameMap.transitiveFilteredUpstream
code: /--
Filter the list of edges `… → node` inside `graph` by the function `filter`.

Any such upstream node `source` where `filter source` returns true will be replaced
by all its upstream nodes. This results in a list of all unfiltered nodes
in the `graph` that either had an edge to `node`
or had an indirect edge to `node` going through filtered nodes.

Will panic if the `node` is not in the `graph`.
-/
partial
def transitiveFilteredUpstream (node : Name) (graph : NameMap (Array Name))
    (filter : Name → Bool) (replacement : Option Name := none):
    List Name 
goal: List Lean.Name

full_name: Lean.NameMap.filterGraph
code: /--
Filters the `graph` removing all nodes where `filter n` returns false. Additionally,
replace edges from removed nodes by all the transitive edges.

This means there is a path between two nodes in the filtered graph iff there exists
such a path in the original graph.

If the optional `(replacement : Name)` is provided, a corresponding node will be
added together with edges to all nodes which had an incoming edge from any
filtered node.
-/
def filterGraph (graph : NameMap (Array Name)) (filter : Name → Bool)
    (replacement : Option Name := none) : NameMap (Array Name) 
goal: Lean.NameMap (Array Lean.Name)

full_name: redundantImports
code: /--
Return the redundant imports (i.e. those transitively implied by another import)
of a specified module (or the current module if `none` is specified).
-/
def redundantImports (n? : Option Name := none) : CoreM NameSet 
goal: Lean.CoreM Lean.NameSet

full_name: «_aux_.lake_packages_importGraph_ImportGraph_Imports___elabRules_command#redundant_imports_1»
code: /--
List the imports in this file which can be removed
because they are transitively implied by another import.
-/
elab "#redundant_imports" : command => do
  let redundant := (← Elab.Command.liftCoreM do redundantImports)
  if redundant.isEmpty then
    logInfo "No transitively redundant imports found."
  else
    logInfo <| "Found the following transitively redundant imports:\n" ++
      m!"{Format.joinSep redundant.toList "\n"}"
goal: Lean.Elab.Command.CommandElab

full_name: «command#redundant_imports»
code: /--
List the imports in this file which can be removed
because they are transitively implied by another import.
-/
elab "#redundant_imports" : command => do
  let redundant := (← Elab.Command.liftCoreM do redundantImports)
  if redundant.isEmpty then
    logInfo "No transitively redundant imports found."
  else
    logInfo <| "Found the following transitively redundant imports:\n" ++
      m!"{Format.joinSep redundant.toList "\n"}"
goal: Lean.ParserDescr

full_name: Lean.Environment.minimalRequiredModules
code: /--
Return the names of the modules in which constants used in the current file were defined,
with modules already transitively imported removed.

Note that this will *not* account for tactics and syntax used in the file,
so the results may not suffice as imports.
-/
def Lean.Environment.minimalRequiredModules (env : Environment) : Array Name 
goal: Array Lean.Name

full_name: «_aux_.lake_packages_importGraph_ImportGraph_Imports___elabRules_command#min_imports_1»
code: /--
Try to compute a minimal set of imports for this file,
by analyzing the declarations.

This must be run at the end of the file,
and is not aware of syntax and tactics,
so the results will likely need to be adjusted by hand.
-/
elab "#min_imports" : command => do
  let imports := (← getEnv).minimalRequiredModules.qsort Name.lt
    |>.toList.map (fun n => "import " ++ n.toString)
  logInfo <| Format.joinSep imports "\n"
goal: Lean.Elab.Command.CommandElab

full_name: «command#min_imports»
code: /--
Try to compute a minimal set of imports for this file,
by analyzing the declarations.

This must be run at the end of the file,
and is not aware of syntax and tactics,
so the results will likely need to be adjusted by hand.
-/
elab "#min_imports" : command => do
  let imports := (← getEnv).minimalRequiredModules.qsort Name.lt
    |>.toList.map (fun n => "import " ++ n.toString)
  logInfo <| Format.joinSep imports "\n"
goal: Lean.ParserDescr

full_name: «_aux_.lake_packages_importGraph_ImportGraph_Imports___elabRules_command#minimize_imports_1»
code: elab "#minimize_imports" : command => do
  logWarning m!"'#minimize_imports' is deprecated: please use '#min_imports'"
  Elab.Command.elabCommand (← `(command| #min_imports))
goal: Lean.Elab.Command.CommandElab

full_name: «command#minimize_imports»
code: elab "#minimize_imports" : command => do
  logWarning m!"'#minimize_imports' is deprecated: please use '#min_imports'"
  Elab.Command.elabCommand (← `(command| #min_imports))
goal: Lean.ParserDescr

full_name: Lean.Name.findHome
code: /--
Find locations as high as possible in the import hierarchy
where the named declaration could live.
-/
def Lean.Name.findHome (n : Name) (env : Option Environment) : CoreM NameSet 
goal: Lean.CoreM Lean.NameSet

full_name: getModuleUri
code: /-- Tries to resolve the module `modName` to a source file URI.
This has to be done in the Lean server
since the `Environment` does not keep track of source URIs. -/
@[server_rpc_method]
def getModuleUri (modName : Name) : RequestM (RequestTask Lsp.DocumentUri) 
goal: Lean.Server.RequestM (Lean.Server.RequestTask Lean.Lsp.DocumentUri)

full_name: GoToModuleLinkProps
code: structure GoToModuleLinkProps where
  modName : Name
  deriving Server.RpcEncodable
goal: Type

full_name: GoToModuleLinkProps.modName
code: structure GoToModuleLinkProps where
  modName : Name
  deriving Server.RpcEncodable
goal: Lean.Name

full_name: GoToModuleLinkProps.instRpcEncodable.dec._@..lake.packages.importGraph.ImportGraph.Imports._hyg.1807
code: Server.RpcEncodable
goal: Lean.Json → ExceptT String (ReaderT Lean.Server.RpcObjectStore Id) GoToModuleLinkProps

full_name: GoToModuleLinkProps.instRpcEncodable
code: Server.RpcEncodable
goal: Lean.Server.RpcEncodable GoToModuleLinkProps

full_name: GoToModuleLinkProps.instFromJsonRpcEncodablePacket
code: Server.RpcEncodable
goal: Lean.FromJson GoToModuleLinkProps.RpcEncodablePacket✝

full_name: GoToModuleLinkProps.instToJsonRpcEncodablePacket
code: Server.RpcEncodable
goal: Lean.ToJson GoToModuleLinkProps.RpcEncodablePacket✝

full_name: GoToModuleLinkProps.instRpcEncodable.enc._@..lake.packages.importGraph.ImportGraph.Imports._hyg.1807
code: Server.RpcEncodable
goal: GoToModuleLinkProps → StateM Lean.Server.RpcObjectStore Lean.Json

full_name: GoToModuleLinkProps.RpcEncodablePacket._@..lake.packages.importGraph.ImportGraph.Imports._hyg.1807
code: Server.RpcEncodable
goal: Type

full_name: GoToModuleLink
code: /-- When clicked, this widget component jumps to the source of the module `modName`,
assuming a source URI can be found for the module. -/
@[widget_module]
def GoToModuleLink : Widget.Module 
goal: Lean.Widget.Module

full_name: «_aux_.lake_packages_importGraph_ImportGraph_Imports___elabRules_command#find_home!__1»
code: /--
Find locations as high as possible in the import hierarchy
where the named declaration could live.
Using `#find_home!` will forcefully remove the current file.
Note that this works best if used in a file with `import Mathlib`.

The current file could still be the only suggestion, even using `#find_home! lemma`.
The reason is that `#find_home!` scans the import graph below the current file,
selects all the files containing declarations appearing in `lemma`, excluding
the current file itself and looks for all least upper bounds of such files.

For a simple example, if `lemma` is in a file importing only `A.lean` and `B.lean` and
uses one lemma from each, then `#find_home! lemma` returns the current file.
-/
elab "#find_home" bang:"!"? n:ident : command => do
  let stx ← getRef
  let mut homes : Array MessageData := #[]
  let n ← liftCoreM <| realizeGlobalConstNoOverloadWithInfo n
  let env? ← bang.mapM fun _ => getEnv
  for modName in (← Elab.Command.liftCoreM do n.findHome env?) do
    let p : GoToModuleLinkProps := { modName }
    homes := homes.push $ .ofWidget
      (← liftCoreM $ Widget.WidgetInstance.ofHash
        GoToModuleLink.javascriptHash $
        Server.RpcEncodable.rpcEncode p)
      (toString modName)
  logInfoAt stx[0] m!"{homes}"
goal: Lean.Elab.Command.CommandElab

full_name: «command#find_home!_»
code: /--
Find locations as high as possible in the import hierarchy
where the named declaration could live.
Using `#find_home!` will forcefully remove the current file.
Note that this works best if used in a file with `import Mathlib`.

The current file could still be the only suggestion, even using `#find_home! lemma`.
The reason is that `#find_home!` scans the import graph below the current file,
selects all the files containing declarations appearing in `lemma`, excluding
the current file itself and looks for all least upper bounds of such files.

For a simple example, if `lemma` is in a file importing only `A.lean` and `B.lean` and
uses one lemma from each, then `#find_home! lemma` returns the current file.
-/
elab "#find_home" bang:"!"? n:ident : command => do
  let stx ← getRef
  let mut homes : Array MessageData := #[]
  let n ← liftCoreM <| realizeGlobalConstNoOverloadWithInfo n
  let env? ← bang.mapM fun _ => getEnv
  for modName in (← Elab.Command.liftCoreM do n.findHome env?) do
    let p : GoToModuleLinkProps := { modName }
    homes := homes.push $ .ofWidget
      (← liftCoreM $ Widget.WidgetInstance.ofHash
        GoToModuleLink.javascriptHash $
        Server.RpcEncodable.rpcEncode p)
      (toString modName)
  logInfoAt stx[0] m!"{homes}"
goal: Lean.ParserDescr