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.
The address of an object in an RpcObjectStore that clients can refer to.
Its JSON encoding depends on the RPC wire format.
The language server may serve the same RpcRef multiple times.
It maintains a reference count to track how many times it has served the reference.
If clients want to release the object associated with an RpcRef,
they must release the reference as many times as they have received it from the server.
- p : USize
Instances For
Equations
Equations
Instances For
Equations
Equations
- Lean.Lsp.instBEqRpcRef.beq { p := a } { p := b } = (a == b)
- Lean.Lsp.instBEqRpcRef.beq x✝¹ x✝ = false
Instances For
Equations
Instances For
Equations
- Lean.Lsp.instToStringRpcRef = { toString := fun (r : Lean.Lsp.RpcRef) => toString r.p }
The RPC wire format specifies how user data is encoded in RPC requests.
- v0 : RpcWireFormat
Version
0uses JSON. Serialized RPC data is stored directly inRpcCallParams.paramsand inJsonRpc.Response.result(as opposed to being wrapped in additional metadata). General types (except RPC references) are (de)serialized viaToJson/FromJson. RPC references are serialized as{"p": n}. - v1 : RpcWireFormat
Version
1is like0, except that RPC references are serialized as{"__rpcref": n}.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Equations
- Lean.Lsp.RpcWireFormat.v0.refFieldName = "p"
- Lean.Lsp.RpcWireFormat.v1.refFieldName = "__rpcref"
Instances For
WithRpcRef α marks values that RPC clients should see as opaque references.
This includes heavy objects such as Lean.Environments
and non-serializable objects such as closures.
In the Lean server, WithRpcRef α is a structure containing a value of type α
and an associated id.
In an RPC client (e.g. the infoview), it is an opaque reference.
Thus, WithRpcRef α is cheap to transmit, but its data may only be accessed server-side.
In practice, this is used by client code to pass data
between various RPC methods provided by the server.
Two WithRpcRefs with the same id will yield the same client-side reference.
See also the docstring for RpcEncodable.
- mk' :: (
- val : α
- id : USize
- )
Instances For
Instances For
Equations
Creates an WithRpcRef instance with a unique id.
As long as the client holds at least one reference to this WithRpcRef,
serving it again will yield the same client-side reference.
Thus, when used as React deps,
client-side references can help preserve UI state across RPC requests.
Equations
- Lean.Server.WithRpcRef.mk val = do let id ← ST.Ref.modifyGet Lean.Server.freshWithRpcRefId fun (id : USize) => (id, id + 1) pure { val := val, id := id }
Instances For
- aliveRefs : PersistentHashMap Lsp.RpcRef ReferencedObject
Objects that are being kept alive for the RPC client, together with their type names, mapped to by their RPC reference.
- refsById : PersistentHashMap USize Lsp.RpcRef
- nextRef : USize
Value to use for the next fresh
RpcRef, monotonically increasing. - wireFormat : Lsp.RpcWireFormat
The RPC wire format to follow.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
RpcEncodable α means α can be used as an argument or return value
in Remote Procedure Call (RPC) methods.
The following types are RpcEncodable by default:
- Any type with both
FromJsonandToJsoninstances. - Any type all of whose components
(meaning the fields of a
structure, or the arguments toinductiveconstructors) areRpcEncodable. Usederiving RpcEncodableto construct an instance in this case. - Certain common containers, if containing
RpcEncodabledata (see instances below). - Any
WithRpcRef αwhere[TypeName α].
Some names are reserved for internal use and must not appear
as the name of a field or constructor argument in any RpcEncodable type,
or as an object key in any nested JSON.
The following are currently reserved:
__rpcref
It is also possible (but discouraged for non-experts)
to implement custom RpcEncodable instances.
These must respect the RpcObjectStore.wireFormat.
- rpcEncode : α → StateM RpcObjectStore Json
Instances
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.
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.
Instances For
Equations
- One or more equations did not get rendered due to their size.