Extends Lean's incremental reporting and reuse between commands into various steps inside declarations: * headers and bodies of each (mutual) definition/theorem * `theorem ... := by` for each contained tactic step, including recursively inside supported combinators currently consisting of * `·` (cdot), `case`, `next` * `induction`, `cases` * macros such as `next` unfolding to the above  *Incremental reuse* means not recomputing any such steps if they are not affected by a document change. *Incremental reporting* includes the parts seen in the recording above: the progress bar and messages. Other language server features such as hover etc. are *not yet* supported incrementally, i.e. they are shown only when the declaration has been fully processed as before. --------- Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
28 lines
1.2 KiB
Text
28 lines
1.2 KiB
Text
import Lean.Elab.Frontend
|
||
|
||
open Lean Elab
|
||
|
||
unsafe def processInput (input : String) (initializers := false) :
|
||
IO (Environment × List Message) := do
|
||
let fileName := "<input>"
|
||
let inputCtx := Parser.mkInputContext input fileName
|
||
if initializers then enableInitializersExecution
|
||
let (header, parserState, messages) ← Parser.parseHeader inputCtx
|
||
let (env, messages) ← processHeader header {} messages inputCtx
|
||
let s ← IO.processCommands inputCtx parserState (Command.mkState env messages {}) <&> Frontend.State.commandState
|
||
pure (s.env, s.messages.toList)
|
||
|
||
open System in
|
||
def findLean (mod : Name) : IO FilePath := do
|
||
let olean ← findOLean mod
|
||
-- Remove a ".lake/build/lib/" substring from the path.
|
||
let lean := olean.toString.replace (toString (FilePath.mk ".lake" / "build" / "lib") ++ FilePath.pathSeparator.toString) ""
|
||
return FilePath.mk lean |>.withExtension "lean"
|
||
|
||
/-- Read the source code of the named module. -/
|
||
def moduleSource (mod : Name) : IO String := do
|
||
IO.FS.readFile (← findLean mod)
|
||
|
||
unsafe def compileModule (mod : Name) (initializers := false) :
|
||
IO (Environment × List Message) := do
|
||
processInput (← moduleSource mod) initializers
|