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 : Lean.Lsp.RpcRef) => 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 := st.aliveRefs.insert { 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 (__do_lift.aliveRefs.find? r)
Instances For
Equations
Instances For
RpcEncodable α
means that α
can be deserialized from and serialized into JSON
for the purpose of receiving arguments to and sending return values from
Remote Procedure Calls (RPCs).
Any type with FromJson
and ToJson
instances is RpcEncodable
.
Furthermore, types that do not have these instances may still be RpcEncodable
.
Use deriving RpcEncodable
to automatically derive instances for such types.
This occurs when α
contains data that should not or cannot be serialized:
for instance, heavy objects such as Lean.Environment
, or closures.
For such data, we use the WithRpcRef
marker.
Note that for WithRpcRef α
to be RpcEncodable
,
α
must have a TypeName
instance
On the server side, WithRpcRef α
is just a structure
containing a value of type α
.
On the client side, it is an opaque reference of (structural) type Lsp.RpcRef
.
Thus, WithRpcRef α
is cheap to transmit over the network
but may only be accessed on the server side.
In practice, it is used by the client to pass data
between various RPC methods provided by the server.
- rpcEncode : α → StateM Lean.Server.RpcObjectStore Lean.Json
Instances
Equations
- ⋯ = ⋯
Equations
- Lean.Server.instRpcEncodableOfFromJsonOfToJson = { rpcEncode := fun (a : α) => pure (Lean.toJson a), rpcDecode := fun (j : Lean.Json) => 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.
Equations
- One or more equations did not get rendered due to their size.
Marks values to be encoded as opaque references in RPC packets.
See the docstring for RpcEncodable
.
- val : α
Instances For
Equations
- Lean.Server.instInhabitedWithRpcRef = { default := { val := default } }
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Server.instRpcEncodableWithRpcRefOfTypeName.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.