- str: String → Lean.JsonRpc.RequestID
- num: Lean.JsonNumber → Lean.JsonRpc.RequestID
- null: Lean.JsonRpc.RequestID
Equations
- Lean.JsonRpc.instBEqRequestID = { beq := [anonymous] }
Equations
- Lean.JsonRpc.instOrdRequestID = { compare := [anonymous] }
Equations
- Lean.JsonRpc.instInhabitedRequestID = { default := Lean.JsonRpc.RequestID.str default }
Equations
- Lean.JsonRpc.instOfNatRequestID = { ofNat := Lean.JsonRpc.RequestID.num (Lean.JsonNumber.fromNat n) }
Equations
- Lean.JsonRpc.instToStringRequestID = { toString := fun x => match x with | Lean.JsonRpc.RequestID.str s => toString "\"s\"" | Lean.JsonRpc.RequestID.num n => toString n | Lean.JsonRpc.RequestID.null => "null" }
- parseError: Lean.JsonRpc.ErrorCode
- invalidRequest: Lean.JsonRpc.ErrorCode
- methodNotFound: Lean.JsonRpc.ErrorCode
- invalidParams: Lean.JsonRpc.ErrorCode
- internalError: Lean.JsonRpc.ErrorCode
- serverNotInitialized: Lean.JsonRpc.ErrorCode
- unknownErrorCode: Lean.JsonRpc.ErrorCode
- contentModified: Lean.JsonRpc.ErrorCode
- requestCancelled: Lean.JsonRpc.ErrorCode
- rpcNeedsReconnect: Lean.JsonRpc.ErrorCode
Equations
Equations
- Lean.JsonRpc.instBEqErrorCode = { beq := [anonymous] }
Equations
- Lean.JsonRpc.instFromJsonErrorCode = { fromJson? := fun x => match x with | Lean.Json.num { mantissa := Int.negSucc 32699, exponent := 0 } => pure Lean.JsonRpc.ErrorCode.parseError | Lean.Json.num { mantissa := Int.negSucc 32599, exponent := 0 } => pure Lean.JsonRpc.ErrorCode.invalidRequest | Lean.Json.num { mantissa := Int.negSucc 32600, exponent := 0 } => pure Lean.JsonRpc.ErrorCode.methodNotFound | Lean.Json.num { mantissa := Int.negSucc 32601, exponent := 0 } => pure Lean.JsonRpc.ErrorCode.invalidParams | Lean.Json.num { mantissa := Int.negSucc 32602, exponent := 0 } => pure Lean.JsonRpc.ErrorCode.internalError | Lean.Json.num { mantissa := Int.negSucc 32001, exponent := 0 } => pure Lean.JsonRpc.ErrorCode.serverNotInitialized | Lean.Json.num { mantissa := Int.negSucc 32000, exponent := 0 } => pure Lean.JsonRpc.ErrorCode.unknownErrorCode | Lean.Json.num { mantissa := Int.negSucc 32800, exponent := 0 } => pure Lean.JsonRpc.ErrorCode.contentModified | Lean.Json.num { mantissa := Int.negSucc 32799, exponent := 0 } => pure Lean.JsonRpc.ErrorCode.requestCancelled | Lean.Json.num { mantissa := Int.negSucc 32899, exponent := 0 } => pure Lean.JsonRpc.ErrorCode.rpcNeedsReconnect | x => throw "expected error code" }
Equations
- Lean.JsonRpc.instToJsonErrorCode = { toJson := fun x => match x with | Lean.JsonRpc.ErrorCode.parseError => Lean.Json.num (Lean.JsonNumber.fromInt (-32700)) | Lean.JsonRpc.ErrorCode.invalidRequest => Lean.Json.num (Lean.JsonNumber.fromInt (-32600)) | Lean.JsonRpc.ErrorCode.methodNotFound => Lean.Json.num (Lean.JsonNumber.fromInt (-32601)) | Lean.JsonRpc.ErrorCode.invalidParams => Lean.Json.num (Lean.JsonNumber.fromInt (-32602)) | Lean.JsonRpc.ErrorCode.internalError => Lean.Json.num (Lean.JsonNumber.fromInt (-32603)) | Lean.JsonRpc.ErrorCode.serverNotInitialized => Lean.Json.num (Lean.JsonNumber.fromInt (-32002)) | Lean.JsonRpc.ErrorCode.unknownErrorCode => Lean.Json.num (Lean.JsonNumber.fromInt (-32001)) | Lean.JsonRpc.ErrorCode.contentModified => Lean.Json.num (Lean.JsonNumber.fromInt (-32801)) | Lean.JsonRpc.ErrorCode.requestCancelled => Lean.Json.num (Lean.JsonNumber.fromInt (-32800)) | Lean.JsonRpc.ErrorCode.rpcNeedsReconnect => Lean.Json.num (Lean.JsonNumber.fromInt (-32900)) }
- request: Lean.JsonRpc.RequestID → String → Option Lean.Json.Structured → Lean.JsonRpc.Message
- notification: String → Option Lean.Json.Structured → Lean.JsonRpc.Message
- response: Lean.JsonRpc.RequestID → Lean.Json → Lean.JsonRpc.Message
- responseError: Lean.JsonRpc.RequestID → Lean.JsonRpc.ErrorCode → String → Option Lean.Json → Lean.JsonRpc.Message
Equations
- id : Lean.JsonRpc.RequestID
- method : String
- param : α
instance
Lean.JsonRpc.instInhabitedRequest
:
{a : Type u_1} → [inst : Inhabited a] → Inhabited (Lean.JsonRpc.Request a)
Equations
- Lean.JsonRpc.instInhabitedRequest = { default := { id := default, method := default, param := default } }
instance
Lean.JsonRpc.instBEqRequest
:
{α : Type u_1} → [inst : BEq α] → BEq (Lean.JsonRpc.Request α)
Equations
- Lean.JsonRpc.instBEqRequest = { beq := [anonymous] }
Equations
- Lean.JsonRpc.instCoeRequestMessage = { coe := fun r => Lean.JsonRpc.Message.request r.id r.method (Except.toOption (Lean.Json.toStructured? r.param)) }
instance
Lean.JsonRpc.instBEqNotification
:
{α : Type u_1} → [inst : BEq α] → BEq (Lean.JsonRpc.Notification α)
Equations
- Lean.JsonRpc.instBEqNotification = { beq := [anonymous] }
instance
Lean.JsonRpc.instInhabitedNotification
:
{a : Type u_1} → [inst : Inhabited a] → Inhabited (Lean.JsonRpc.Notification a)
Equations
- Lean.JsonRpc.instInhabitedNotification = { default := { method := default, param := default } }
Equations
- Lean.JsonRpc.instCoeNotificationMessage = { coe := fun r => Lean.JsonRpc.Message.notification r.method (Except.toOption (Lean.Json.toStructured? r.param)) }
instance
Lean.JsonRpc.instBEqResponse
:
{α : Type u_1} → [inst : BEq α] → BEq (Lean.JsonRpc.Response α)
Equations
- Lean.JsonRpc.instBEqResponse = { beq := [anonymous] }
instance
Lean.JsonRpc.instInhabitedResponse
:
{a : Type u_1} → [inst : Inhabited a] → Inhabited (Lean.JsonRpc.Response a)
Equations
- Lean.JsonRpc.instInhabitedResponse = { default := { id := default, result := default } }
Equations
- Lean.JsonRpc.instCoeResponseMessage = { coe := fun r => Lean.JsonRpc.Message.response r.id (Lean.toJson r.result) }
- id : Lean.JsonRpc.RequestID
- code : Lean.JsonRpc.ErrorCode
- message : String
- data? : Option α
instance
Lean.JsonRpc.instBEqResponseError
:
{α : Type u_1} → [inst : BEq α] → BEq (Lean.JsonRpc.ResponseError α)
Equations
- Lean.JsonRpc.instBEqResponseError = { beq := [anonymous] }
instance
Lean.JsonRpc.instInhabitedResponseError
:
{a : Type u_1} → Inhabited (Lean.JsonRpc.ResponseError a)
Equations
- Lean.JsonRpc.instInhabitedResponseError = { default := { id := default, code := default, message := default, data? := default } }
Equations
- Lean.JsonRpc.instCoeResponseErrorMessage = { coe := fun r => Lean.JsonRpc.Message.responseError r.id r.code r.message (Option.map Lean.toJson r.data?) }
Equations
Equations
instance
Lean.JsonRpc.instDecidableLtRequestIDInstLTRequestID
(a : Lean.JsonRpc.RequestID)
(b : Lean.JsonRpc.RequestID)
:
Equations
Equations
- Lean.JsonRpc.instFromJsonRequestID = { fromJson? := fun j => match j with | Lean.Json.str s => pure (Lean.JsonRpc.RequestID.str s) | Lean.Json.num n => pure (Lean.JsonRpc.RequestID.num n) | x => throw "a request id needs to be a number or a string" }
Equations
- Lean.JsonRpc.instToJsonRequestID = { toJson := fun rid => match rid with | Lean.JsonRpc.RequestID.str s => Lean.Json.str s | Lean.JsonRpc.RequestID.num n => Lean.Json.num n | Lean.JsonRpc.RequestID.null => Lean.Json.null }
Equations
- Lean.JsonRpc.instToJsonMessage = { toJson := fun m => Lean.Json.mkObj (("jsonrpc", Lean.Json.str "2.0") :: match m with | Lean.JsonRpc.Message.request id method params? => [("id", Lean.toJson id), ("method", Lean.Json.str method)] ++ Lean.Json.opt "params" params? | Lean.JsonRpc.Message.notification method params? => ("method", Lean.Json.str method) :: Lean.Json.opt "params" params? | Lean.JsonRpc.Message.response id result => [("id", Lean.toJson id), ("result", result)] | Lean.JsonRpc.Message.responseError id code message data? => [("id", Lean.toJson id), ("error", Lean.Json.mkObj ([("code", Lean.toJson code), ("message", Lean.Json.str message)] ++ Lean.Json.opt "data" data?))]) }
Equations
- Lean.JsonRpc.instFromJsonMessage = { fromJson? := fun j => do let discr ← Lean.Json.getObjVal? j "jsonrpc" match discr with | Lean.Json.str "2.0" => HOrElse.hOrElse (do let id ← Lean.Json.getObjValAs? j Lean.JsonRpc.RequestID "id" let method ← Lean.Json.getObjValAs? j String "method" let params? : Except String Lean.Json.Structured := Lean.Json.getObjValAs? j Lean.Json.Structured "params" pure (Lean.JsonRpc.Message.request id method (Except.toOption params?))) fun x => HOrElse.hOrElse (do let method ← Lean.Json.getObjValAs? j String "method" let params? : Except String Lean.Json.Structured := Lean.Json.getObjValAs? j Lean.Json.Structured "params" pure (Lean.JsonRpc.Message.notification method (Except.toOption params?))) fun x => HOrElse.hOrElse (do let id ← Lean.Json.getObjValAs? j Lean.JsonRpc.RequestID "id" let result ← Lean.Json.getObjVal? j "result" pure (Lean.JsonRpc.Message.response id result)) fun x => do let id ← Lean.Json.getObjValAs? j Lean.JsonRpc.RequestID "id" let err ← Lean.Json.getObjVal? j "error" let code ← Lean.Json.getObjValAs? err Lean.JsonRpc.ErrorCode "code" let message ← Lean.Json.getObjValAs? err String "message" let data? : Except String Lean.Json := Lean.Json.getObjVal? err "data" pure (Lean.JsonRpc.Message.responseError id code message (Except.toOption data?)) | x => throw "only version 2.0 of JSON RPC is supported" }
Equations
- Lean.JsonRpc.instFromJsonNotification = { fromJson? := fun j => do let msg ← Lean.fromJson? j match msg with | Lean.JsonRpc.Message.notification method params? => do let params ← pure params? let param ← Lean.fromJson? (Lean.toJson params) pure { method := method, param := param } | x => throw "not a notfication" }
Equations
- IO.FS.Stream.readMessage h nBytes = do let j ← IO.FS.Stream.readJson h nBytes match Lean.fromJson? j with | Except.ok m => pure m | Except.error inner => throw (IO.userError (toString "JSON '" ++ toString (Lean.Json.compress j) ++ toString "' did not have the format of a JSON-RPC message.\n" ++ toString inner ++ toString ""))
def
IO.FS.Stream.readRequestAs
(h : IO.FS.Stream)
(nBytes : Nat)
(expectedMethod : String)
(α : Type)
[inst : Lean.FromJson α]
:
Equations
- IO.FS.Stream.readRequestAs h nBytes expectedMethod α = do let m ← IO.FS.Stream.readMessage h nBytes match m with | Lean.JsonRpc.Message.request id method params? => if method = expectedMethod then let j := Lean.toJson params?; match Lean.fromJson? j with | Except.ok v => pure { id := id, method := expectedMethod, param := v } | Except.error inner => throw (IO.userError (toString "Unexpected param '" ++ toString (Lean.Json.compress j) ++ toString "' for method '" ++ toString expectedMethod ++ toString "'\n" ++ toString inner ++ toString "")) else throw (IO.userError (toString "Expected method '" ++ toString expectedMethod ++ toString "', got method '" ++ toString method ++ toString "'")) | x => throw (IO.userError (toString "Expected JSON-RPC request, got: '" ++ toString (Lean.Json.compress (Lean.toJson m)) ++ toString "'"))
def
IO.FS.Stream.readNotificationAs
(h : IO.FS.Stream)
(nBytes : Nat)
(expectedMethod : String)
(α : Type)
[inst : Lean.FromJson α]
:
Equations
- IO.FS.Stream.readNotificationAs h nBytes expectedMethod α = do let m ← IO.FS.Stream.readMessage h nBytes match m with | Lean.JsonRpc.Message.notification method params? => if method = expectedMethod then let j := Lean.toJson params?; match Lean.fromJson? j with | Except.ok v => pure { method := expectedMethod, param := v } | Except.error inner => throw (IO.userError (toString "Unexpected param '" ++ toString (Lean.Json.compress j) ++ toString "' for method '" ++ toString expectedMethod ++ toString "'\n" ++ toString inner ++ toString "")) else throw (IO.userError (toString "Expected method '" ++ toString expectedMethod ++ toString "', got method '" ++ toString method ++ toString "'")) | x => throw (IO.userError (toString "Expected JSON-RPC notification, got: '" ++ toString (Lean.Json.compress (Lean.toJson m)) ++ toString "'"))
partial def
IO.FS.Stream.readResponseAs
(h : IO.FS.Stream)
(nBytes : Nat)
(expectedID : Lean.JsonRpc.RequestID)
(α : Type)
[inst : Lean.FromJson α]
:
Equations
def
IO.FS.Stream.writeRequest
{α : Type u_1}
[inst : Lean.ToJson α]
(h : IO.FS.Stream)
(r : Lean.JsonRpc.Request α)
:
Equations
- IO.FS.Stream.writeRequest h r = IO.FS.Stream.writeMessage h (Lean.JsonRpc.Message.request r.id r.method (Except.toOption (Lean.Json.toStructured? r.param)))
def
IO.FS.Stream.writeNotification
{α : Type u_1}
[inst : Lean.ToJson α]
(h : IO.FS.Stream)
(n : Lean.JsonRpc.Notification α)
:
Equations
- IO.FS.Stream.writeNotification h n = IO.FS.Stream.writeMessage h (Lean.JsonRpc.Message.notification n.method (Except.toOption (Lean.Json.toStructured? n.param)))
def
IO.FS.Stream.writeResponse
{α : Type u_1}
[inst : Lean.ToJson α]
(h : IO.FS.Stream)
(r : Lean.JsonRpc.Response α)
:
Equations
- IO.FS.Stream.writeResponse h r = IO.FS.Stream.writeMessage h (Lean.JsonRpc.Message.response r.id (Lean.toJson r.result))
Equations
- IO.FS.Stream.writeResponseError h e = IO.FS.Stream.writeMessage h (Lean.JsonRpc.Message.responseError e.id e.code e.message none)
def
IO.FS.Stream.writeResponseErrorWithData
{α : Type u_1}
[inst : Lean.ToJson α]
(h : IO.FS.Stream)
(e : Lean.JsonRpc.ResponseError α)
:
Equations
- IO.FS.Stream.writeResponseErrorWithData h e = IO.FS.Stream.writeMessage h (Lean.JsonRpc.Message.responseError e.id e.code e.message (Option.map Lean.toJson e.data?))