For general server architecture, see README.md
. For details of IPC communication, see Watchdog.lean
.
This module implements per-file worker processes.
File processing and requests+notifications against a file should be concurrent for two reasons:
- By the LSP standard, requests should be cancellable.
- Since Lean allows arbitrary user code to be executed during elaboration via the tactic framework, elaboration can be extremely slow and even not halt in some cases. Users should be able to work with the file while this is happening, e.g. make new changes to the file or send requests.
To achieve these goals, elaboration is executed in a chain of tasks, where each task corresponds to the elaboration of one command. When the elaboration of one command is done, the next task is spawned. On didChange notifications, we search for the task in which the change occured. If we stumble across a task that has not yet finished before finding the task we're looking for, we terminate it and start the elaboration there, otherwise we start the elaboration at the task where the change occured.
Requests iterate over tasks until they find the command that they need to answer the request. In order to not block the main thread, this is done in a request task. If a task that the request task waits for is terminated, a change occured somewhere before the command that the request is looking for and the request sends a "content changed" error.
- hIn : IO.FS.Stream
- hOut : IO.FS.Stream
- hLog : IO.FS.Stream
- headerTask : Task (Except IO.Error (Lean.Server.Snapshots.Snapshot × Lean.SearchPath))
- initParams : Lean.Lsp.InitializeParams
- clientHasWidgets : Bool
- snaps : Array Lean.Server.Snapshots.Snapshot
Elaborates all commands after the last snap (at least the header snap is assumed to exist), emitting the diagnostics into hOut
.
Equations
- One or more equations did not get rendered due to their size.
Equations
- pendingRequests : Lean.Server.FileWorker.PendingRequestMap
A map of RPC session IDs. We allow asynchronous elab tasks and request handlers to modify sessions. A single
Ref
ensures atomic transactions.rpcSessions : Std.RBMap UInt64 (IO.Ref Lean.Server.FileWorker.RpcSession) compare
Use lake print-paths
to compile dependencies on the fly and add them to LEAN_PATH
.
Compilation progress is reported to hOut
via LSP notifications. Return the search path for
source files.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Server.FileWorker.updatePendingRequests map = modify fun st => { doc := st.doc, pendingRequests := map st.pendingRequests, rpcSessions := st.rpcSessions }
Given the new document, updates editable doc state.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Server.FileWorker.handleCancelRequest p = Lean.Server.FileWorker.updatePendingRequests fun pendingRequests => Std.RBMap.erase pendingRequests p.id
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Requests here are handled synchronously rather than in the asynchronous RequestM
.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Server.FileWorker.queueRequest id requestTask = Lean.Server.FileWorker.updatePendingRequests fun pendingRequests => Std.RBMap.insert pendingRequests id requestTask
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.