Zulip Chat Archive
Stream: lean4
Topic: Feature request - button to replace with minimized imports
Seewoo Lee (Dec 31 2025 at 07:40):
Would it be possible to add a small button in VSCode extension for #min_imports, where clicking it automatically replaces all the imports with minimized imports? (I always copy-paste manually.)
Damiano Testa (Dec 31 2025 at 07:57):
It might be possible to make it produce a Try this suggestion.
Seewoo Lee (Jan 01 2026 at 23:13):
I left this as an issue in vscode-lean4.
Henrik Böving (Jan 01 2026 at 23:15):
That's not really an issue for vscode-lean4, #min_imports is mathlib code.
Seewoo Lee (Jan 01 2026 at 23:18):
Oops sorry, then where should I ask this? Issue in actual mathlib? I don't know much about how other Try this suggestions works in vscode extension.
Damiano Testa (Jan 02 2026 at 10:31):
Here is a possible implementation: I called it #min_imports' simply to distinguish it from the other.
import ImportGraph.Meta
import Lean.Meta.Tactic.TryThis
open Lean Elab Command Parser Meta.Tactic.TryThis in
elab "#min_imports'" : command => do
let imports := (← getEnv).minimalRequiredModules.qsort (·.toString < ·.toString)
|>.toList.map (s!"import {·}")
let newImports := "\n".intercalate imports
let fm ← getFileMap
let (imps, _) ← parseHeader {inputString := fm.source, fileName := ← getFileName, fileMap := fm}
liftTermElabM do addSuggestion (origSpan? := imps) (← getRef) newImports
#min_imports'
Damiano Testa (Jan 02 2026 at 10:32):
Note that if the imports are interspersed with comments, those will get erased by the Try this suggestion.
Damiano Testa (Jan 02 2026 at 10:33):
Leading/trailing comments are preserved, though.
Damiano Testa (Jan 02 2026 at 10:33):
-- survives `Try this`
import Lean -- this comment gets erased
import Mathlib -- this comment also survives
Kim Morrison (Jan 03 2026 at 10:26):
The new shake will do a much better job than #min_imports, which is essentially obsolete now. Once we're actually shipping the new shake we will probably add a VSCode extension menu item for it.
Last updated: Feb 28 2026 at 14:05 UTC