This PR adds the experimental `idbg e`, a new do-element (and term) syntax for live debugging between the language server and a running compiled Lean program. When placed in a `do` block, `idbg` captures all local variables in scope and expression `e`, then: - **In the language server**: starts a TCP server on localhost waiting for the running program to connect; the editor will mark this part of the program as "in progress" during this wait but that will not block `lake build` of the project. - **In the compiled program**: on first execution of the `idbg` call site, connects to the server, receives the expression, compiles and evaluates it using the program's actual runtime values, and sends the `repr` result back. The result is displayed as an info diagnostic on the `idbg` keyword. The expression `e` can be edited while the program is running - each edit triggers re-elaboration of `e`, a new TCP exchange, and an updated result. This makes `idbg` a live REPL for inspecting and experimenting with program state at a specific point in execution. Only when `idbg` is inserted, moved, or removed does the program need to be recompiled and restarted. # Known Limitations * The program will poll for the server for up to 10 minutes and needs to be killed manually otherwise. * Use of multiple `idbg` at once untested, likely too much overhead from overlapping imports without further changes. * `LEAN_PATH` must be properly set up so compiled program can import its origin module. * Untested on Windows and macOS.
13 lines
436 B
Text
13 lines
436 B
Text
module
|
|
|
|
import Lean
|
|
|
|
/-! ## idbg syntax compiles in a do block -/
|
|
|
|
-- Verify the idbg syntax is accepted and type-checks.
|
|
-- We can't run this (the client loop would try to connect), just check elaboration.
|
|
-- Disable inServer so the elaborator doesn't block waiting for TCP connection
|
|
set_option Elab.inServer false in
|
|
set_option backward.do.legacy false in
|
|
def idbgTypeCheck (x : Nat) (s : String) : IO Unit := do
|
|
idbg x + s.length
|