Documentation

Lean.Server.Rpc.Basic

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.

class Lean.Server.MonadRpcSession (m : TypeType) :
Type

Monads with an RPC session in their state.

Instances
instance Lean.Server.instMonadRpcSession {m : TypeType} {n : TypeType} [inst : MonadLift m n] [inst : Lean.Server.MonadRpcSession m] :
Equations
  • One or more equations did not get rendered due to their size.
class Lean.Server.RpcEncoding (α : Type) (β : outParam Type) :
Type 1

RpcEncoding α β means that α may participate in RPC calls with its on-the-wire LSP encoding being β. This is useful when α contains fields which must be marshalled in a special way. In particular, we encode WithRpcRef fields as opaque references rather than send their content.

Structures with From/ToJson use JSON as their RpcEncoding. Structures containing non-JSON-serializable fields can be auto-encoded in two ways:

Instances
instance Lean.Server.instRpcEncoding {α : Type} [inst : Lean.FromJson α] [inst : Lean.ToJson α] :
Equations
instance Lean.Server.instRpcEncodingOption {α : Type} {β : Type} [inst : Lean.Server.RpcEncoding α β] :
Equations
  • One or more equations did not get rendered due to their size.
instance Lean.Server.instRpcEncodingArray {α : Type} {β : Type} [inst : Lean.Server.RpcEncoding α β] :
Equations
  • One or more equations did not get rendered due to their size.
instance Lean.Server.instRpcEncodingProd {α : Type} {α' : Type} {β : Type} {β' : Type} [inst : Lean.Server.RpcEncoding α α'] [inst : Lean.Server.RpcEncoding β β'] :
Lean.Server.RpcEncoding (α × β) (α' × β')
Equations
  • One or more equations did not get rendered due to their size.
structure Lean.Server.WithRpcRef (α : Type u) :
Type u
  • val : α

Marks fields to encode as opaque references in LSP packets.

instance Lean.Server.instInhabitedWithRpcRef:
{a : Type u_1} → [inst : Inhabited a] → Inhabited (Lean.Server.WithRpcRef a)
Equations
  • Lean.Server.instInhabitedWithRpcRef = { default := { val := default } }
unsafe def Lean.Server.WithRpcRef.encodeUnsafe {m : TypeType} [inst : Lean.Server.MonadRpcSession m] {α : Type u_1} [inst : Monad m] (typeName : Lean.Name) (r : Lean.Server.WithRpcRef α) :

This is unsafe because we must ensure that:

  • the stored NonScalar is never used to access the value as a type other than α
  • the type α is not a scalar
Equations
unsafe def Lean.Server.WithRpcRef.decodeUnsafeAs {m : TypeType} [inst : Monad m] [inst : Lean.Server.MonadRpcSession m] (α : Type) (typeName : Lean.Name) (r : Lean.Lsp.RpcRef) :
Equations
  • One or more equations did not get rendered due to their size.