From 9fc834ca2e5a12352a81920e770218ac66946b75 Mon Sep 17 00:00:00 2001 From: Jon Eugster Date: Wed, 7 Aug 2024 15:05:50 +0200 Subject: [PATCH] use lexicographic sorting Co-authored-by: Moritz Firsching --- ImportGraph/Imports.lean | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ImportGraph/Imports.lean b/ImportGraph/Imports.lean index 970ae7e..a92154b 100644 --- a/ImportGraph/Imports.lean +++ b/ImportGraph/Imports.lean @@ -205,6 +205,10 @@ def Lean.Environment.minimalRequiredModules (env : Environment) : Array Name := let redundant := findRedundantImports env required required.filter fun n => ¬ redundant.contains n +/-- Lexikographic order of Names for sorting imports -/ +def sortImportsLt : Name → Name → Bool + | a, b => a.toString < b.toString + /-- Try to compute a minimal set of imports for this file, by analyzing the declarations. @@ -214,7 +218,7 @@ 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 + let imports := (← getEnv).minimalRequiredModules.qsort sortImportsLt |>.toList.map (fun n => "import " ++ n.toString) logInfo <| Format.joinSep imports "\n"