feat: misc server additions

This commit is contained in:
Wojciech Nawrocki 2021-08-02 14:55:21 -04:00 committed by Leonardo de Moura
parent 2f16d5f121
commit dae1a94d53
3 changed files with 16 additions and 3 deletions

View file

@ -40,7 +40,7 @@ instance : ToJson String := ⟨fun s => s⟩
instance [FromJson α] : FromJson (Array α) where
fromJson?
| Json.arr a => a.mapM fromJson?
| _ => throw "JSON array expected"
| j => throw s!"expected JSON array, got '{j}'"
instance [ToJson α] : ToJson (Array α) :=
⟨fun a => Json.arr (a.map toJson)⟩
@ -55,6 +55,17 @@ instance [ToJson α] : ToJson (Option α) :=
| none => Json.null
| some a => toJson a⟩
instance [FromJson α] [FromJson β] : FromJson (α × β) where
fromJson?
| Json.arr #[ja, jb] => do
let a ← fromJson? ja
let b ← fromJson? jb
return (a, b)
| j => throw s!"expected pair, got '{j}'"
instance [ToJson α] [ToJson β] : ToJson (α × β) where
toJson := fun (a, b) => Json.arr #[toJson a, toJson b]
instance : FromJson Name where
fromJson? j := do
let s ← j.getStr?
@ -101,7 +112,7 @@ namespace Json
instance : FromJson Structured := ⟨fun
| arr a => Structured.arr a
| obj o => Structured.obj o
| _ => throw "structured object expected"⟩
| j => throw s!"expected structured object, got '{j}'"⟩
instance : ToJson Structured := ⟨fun
| Structured.arr a => arr a

View file

@ -84,7 +84,8 @@ end RpcSessionState
structure RpcSession where
sessionId : UInt64
clientConnected : Bool
-- A single `Ref` ensures atomic transactions.
/-- We allow asynchronous elab tasks and request handlers to modify the state.
A single `Ref` ensures atomic transactions. -/
state : IO.Ref RpcSessionState
namespace RpcSession

View file

@ -82,6 +82,7 @@ structure RpcEncoding.DerivingParams where
/-- Marks fields to encode as opaque references in LSP packets. -/
structure WithRpcRef (α : Type u) where
val : α
deriving Inhabited
namespace WithRpcRef