File: .lake/packages/lean4/src/lean/Lean/Server/Rpc/Basic.lean

full_name: Lean.Lsp.RpcRef
code: /-- An object which RPC clients can refer to without marshalling. -/
structure RpcRef where
  /- NOTE(WN): It is important for this to be a single-field structure
  in order to deserialize as an `Object` on the JS side. -/
  p : USize
  deriving BEq, Hashable, FromJson, ToJson
goal: Type

full_name: Lean.Lsp.RpcRef.p
code: /-- An object which RPC clients can refer to without marshalling. -/
structure RpcRef where
  /- NOTE(WN): It is important for this to be a single-field structure
  in order to deserialize as an `Object` on the JS side. -/
  p : USize
  deriving BEq, Hashable, FromJson, ToJson
goal: USize

full_name: Lean.Lsp.instBEqRpcRef
code: /-- An object which RPC clients can refer to without marshalling. -/
structure RpcRef where
  /- NOTE(WN): It is important for this to be a single-field structure
  in order to deserialize as an `Object` on the JS side. -/
  p : USize
  deriving BEq, Hashable, FromJson, ToJson
goal: BEq Lean.Lsp.RpcRef

full_name: Lean.Lsp.instHashableRpcRef
code: /-- An object which RPC clients can refer to without marshalling. -/
structure RpcRef where
  /- NOTE(WN): It is important for this to be a single-field structure
  in order to deserialize as an `Object` on the JS side. -/
  p : USize
  deriving BEq, Hashable, FromJson, ToJson
goal: Hashable Lean.Lsp.RpcRef

full_name: Lean.Lsp.instFromJsonRpcRef
code: FromJson
goal: Lean.FromJson Lean.Lsp.RpcRef

full_name: Lean.Lsp.instToJsonRpcRef
code: ToJson
goal: Lean.ToJson Lean.Lsp.RpcRef

full_name: Lean.Lsp.instToStringRpcRef
code: instance : ToString RpcRef 
goal: ToString Lean.Lsp.RpcRef

full_name: Lean.Server.RpcObjectStore.aliveRefs
code: structure RpcObjectStore : Type where
  /-- 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. -/
  aliveRefs : PersistentHashMap Lsp.RpcRef Dynamic := {}
  /-- Value to use for the next `RpcRef`. It is monotonically increasing to avoid any possible
  bugs resulting from its reuse. -/
  nextRef   : USize := 0
goal: Lean.PersistentHashMap Lean.Lsp.RpcRef Dynamic

full_name: Lean.Server.RpcObjectStore
code: structure RpcObjectStore : Type where
  /-- 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. -/
  aliveRefs : PersistentHashMap Lsp.RpcRef Dynamic := {}
  /-- Value to use for the next `RpcRef`. It is monotonically increasing to avoid any possible
  bugs resulting from its reuse. -/
  nextRef   : USize := 0
goal: Type

full_name: Lean.Server.RpcObjectStore.nextRef
code: structure RpcObjectStore : Type where
  /-- 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. -/
  aliveRefs : PersistentHashMap Lsp.RpcRef Dynamic := {}
  /-- Value to use for the next `RpcRef`. It is monotonically increasing to avoid any possible
  bugs resulting from its reuse. -/
  nextRef   : USize := 0
goal: USize

full_name: Lean.Server.rpcStoreRef
code: def rpcStoreRef (any : Dynamic) : StateM RpcObjectStore Lsp.RpcRef 
goal: StateM Lean.Server.RpcObjectStore Lean.Lsp.RpcRef

full_name: Lean.Server.rpcGetRef
code: def rpcGetRef (r : Lsp.RpcRef) : ReaderT RpcObjectStore Id (Option Dynamic) 
goal: ReaderT Lean.Server.RpcObjectStore Id (Option Dynamic)

full_name: Lean.Server.rpcReleaseRef
code: def rpcReleaseRef (r : Lsp.RpcRef) : StateM RpcObjectStore Bool 
goal: StateM Lean.Server.RpcObjectStore Bool

full_name: Lean.Server.RpcEncodable.rpcEncode
code: /-- `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. -/
-- TODO(WN): for Lean.js, compile `WithRpcRef` to "opaque reference" on the client
class RpcEncodable (α : Type) where
  rpcEncode : α → StateM RpcObjectStore Json
  rpcDecode : Json → ExceptT String (ReaderT RpcObjectStore Id) α
goal: α → StateM Lean.Server.RpcObjectStore Lean.Json

full_name: Lean.Server.RpcEncodable.rpcDecode
code: /-- `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. -/
-- TODO(WN): for Lean.js, compile `WithRpcRef` to "opaque reference" on the client
class RpcEncodable (α : Type) where
  rpcEncode : α → StateM RpcObjectStore Json
  rpcDecode : Json → ExceptT String (ReaderT RpcObjectStore Id) α
goal: Lean.Json → ExceptT String (ReaderT Lean.Server.RpcObjectStore Id) α

full_name: Lean.Server.RpcEncodable
code: /-- `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. -/
-- TODO(WN): for Lean.js, compile `WithRpcRef` to "opaque reference" on the client
class RpcEncodable (α : Type) where
  rpcEncode : α → StateM RpcObjectStore Json
  rpcDecode : Json → ExceptT String (ReaderT RpcObjectStore Id) α
goal: Type

full_name: Lean.Server.instNonemptyRpcEncodable
code: instance : Nonempty (RpcEncodable α) 
goal: Nonempty (Lean.Server.RpcEncodable α)

full_name: Lean.Server.instRpcEncodableOfFromJsonOfToJson
code: instance [FromJson α] [ToJson α] : RpcEncodable α 
goal: Lean.Server.RpcEncodable α

full_name: Lean.Server.instRpcEncodableOption
code: instance [RpcEncodable α] : RpcEncodable (Option α) 
goal: Lean.Server.RpcEncodable (Option α)

full_name: Lean.Server.instRpcEncodableArray
code: instance [RpcEncodable α] : RpcEncodable (Array α) 
goal: Lean.Server.RpcEncodable (Array α)

full_name: Lean.Server.instRpcEncodableProd
code: instance [RpcEncodable α] [RpcEncodable β] : RpcEncodable (α × β) 
goal: Lean.Server.RpcEncodable (α × β)

full_name: Lean.Server.instRpcEncodableStateMRpcObjectStore
code: instance [RpcEncodable α] : RpcEncodable (StateM RpcObjectStore α) 
goal: Lean.Server.RpcEncodable (StateM Lean.Server.RpcObjectStore α)

full_name: Lean.Server.WithRpcRef.val
code: /-- Marks values to be encoded as opaque references in RPC packets.

See the docstring for `RpcEncodable`. -/
structure WithRpcRef (α : Type u) where
  val : α
  deriving Inhabited
goal: α

full_name: Lean.Server.instInhabitedWithRpcRef
code: /-- Marks values to be encoded as opaque references in RPC packets.

See the docstring for `RpcEncodable`. -/
structure WithRpcRef (α : Type u) where
  val : α
  deriving Inhabited
goal: {a : Type u_1} → [inst : Inhabited a] → Inhabited (Lean.Server.WithRpcRef a)

full_name: Lean.Server.WithRpcRef
code: /-- Marks values to be encoded as opaque references in RPC packets.

See the docstring for `RpcEncodable`. -/
structure WithRpcRef (α : Type u) where
  val : α
  deriving Inhabited
goal: Type u

full_name: Lean.Server.instRpcEncodableWithRpcRefOfTypeName.rpcDecode
code: instance [TypeName α] : RpcEncodable (WithRpcRef α) 
goal: ExceptT String (ReaderT Lean.Server.RpcObjectStore Id) (Lean.Server.WithRpcRef α)

full_name: Lean.Server.instRpcEncodableWithRpcRefOfTypeName.rpcEncode
code: instance [TypeName α] : RpcEncodable (WithRpcRef α) 
goal: StateM Lean.Server.RpcObjectStore Lean.Json

full_name: Lean.Server.instRpcEncodableWithRpcRefOfTypeName
code: instance [TypeName α] : RpcEncodable (WithRpcRef α) 
goal: Lean.Server.RpcEncodable (Lean.Server.WithRpcRef α)