Allows LSP clients to make Remote Procedure Calls to the server.
The single use case for these is to allow the infoview UI to refer to and manipulate heavy-weight
objects residing on the server. It would be inefficient to serialize these into JSON and send over.
For example, the client can format an Expr
without transporting the whole Environment
.
All RPC requests are relative to an open file and an RPC session for that file. The client must
first connect to the session using $/lean/rpc/connect
.
Equations
- Lean.Lsp.instBEqRpcRef = { beq := Lean.Lsp.beqRpcRef✝ }
Equations
- Lean.Lsp.instHashableRpcRef = { hash := Lean.Lsp.hashRpcRef✝ }
Equations
- Lean.Lsp.instFromJsonRpcRef = { fromJson? := Lean.Lsp.fromJsonRpcRef✝ }
Equations
- Lean.Lsp.instToJsonRpcRef = { toJson := Lean.Lsp.toJsonRpcRef✝ }
Equations
- Lean.Lsp.instToStringRpcRef = { toString := fun r => toString r.p }
- aliveRefs : Lean.PersistentHashMap Lean.Lsp.RpcRef Dynamic
Objects that are being kept alive for the RPC client, together with their type names, mapped to by their RPC reference.
Note that we may currently have multiple references to the same object. It is only disposed of once all of those are gone. This simplifies the client a bit as it can drop every reference received separately.
- nextRef : USize
Value to use for the next
RpcRef
. It is monotonically increasing to avoid any possible bugs resulting from its reuse.
Instances For
Equations
- Lean.Server.rpcStoreRef any = do let st ← get set { aliveRefs := Lean.PersistentHashMap.insert st.aliveRefs { p := st.nextRef } any, nextRef := st.nextRef + 1 } pure { p := st.nextRef }
Instances For
Equations
- Lean.Server.rpcGetRef r = do let __do_lift ← read pure (Lean.PersistentHashMap.find? __do_lift.aliveRefs r)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
- rpcEncode : α → StateM Lean.Server.RpcObjectStore Lean.Json
RpcEncodable α
means that α
can be serialized in the RPC system of the Lean server.
This is required when α
contains fields which should be serialized as an RPC reference
instead of being sent in full.
The type wrapper WithRpcRef
is used for these fields which should be sent as
a reference.
- Any type with
FromJson
andToJson
instance is automaticallyRpcEncodable
. - If a type has an
Dynamic
instance, thenWithRpcRef
can be used for its references. deriving RpcEncodable
acts likeFromJson
/ToJson
but marshalls anyWithRpcRef
fields asLsp.RpcRef
s.
Instances
Equations
- Lean.Server.instRpcEncodable = { rpcEncode := fun a => pure (Lean.toJson a), rpcDecode := fun j => ofExcept (Lean.fromJson? j) }
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.
- val : α
Marks fields to encode as opaque references in LSP packets.
Instances For
Equations
- Lean.Server.instInhabitedWithRpcRef = { default := { val := default } }
Equations
- Lean.Server.instRpcEncodableWithRpcRef = { rpcEncode := Lean.Server.instRpcEncodableWithRpcRef.rpcEncode, rpcDecode := Lean.Server.instRpcEncodableWithRpcRef.rpcDecode }
Equations
- Lean.Server.instRpcEncodableWithRpcRef.rpcEncode r = Lean.toJson <$> Lean.Server.rpcStoreRef (Dynamic.mk r.val)
Instances For
Equations
- One or more equations did not get rendered due to their size.