Skip to content

Commit 0fecd0c

Browse files
committed
feat: add protocol overview
1 parent 4583535 commit 0fecd0c

File tree

4 files changed

+531
-23
lines changed

4 files changed

+531
-23
lines changed

src/Lean/Data/JsonRpc.lean

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,24 @@ Namely:
400400
def parseMessageMetaData (input : String) : Except String MessageMetaData :=
401401
messageMetaDataParser input |>.run input
402402

403+
public inductive MessageDirection where
404+
| clientToServer
405+
| serverToClient
406+
deriving Inhabited, FromJson, ToJson
407+
408+
inductive MessageKind where
409+
| request
410+
| notification
411+
| response
412+
| responseError
413+
deriving FromJson, ToJson
414+
415+
def MessageKind.ofMessage : Message → MessageKind
416+
| .request .. => .request
417+
| .notification .. => .notification
418+
| .response .. => .response
419+
| .responseError .. => .responseError
420+
403421
end Lean.JsonRpc
404422

405423
namespace IO.FS.Stream

src/Lean/Server/Logging.lean

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,6 @@ where
9191
method? : Option MessageMethod :=
9292
messageMethod? msg <|> (do pending.get? (← messageId? msg))
9393

94-
public inductive MessageDirection where
95-
| clientToServer
96-
| serverToClient
97-
deriving Inhabited, FromJson, ToJson
98-
99-
inductive MessageKind where
100-
| request
101-
| notification
102-
| response
103-
| responseError
104-
deriving FromJson, ToJson
105-
106-
def MessageKind.ofMessage : JsonRpc.Message → MessageKind
107-
| .request .. => .request
108-
| .notification .. => .notification
109-
| .response .. => .response
110-
| .responseError .. => .responseError
111-
11294
local instance : ToJson Std.Time.ZonedDateTime where
11395
toJson dt := dt.toISO8601String
11496

@@ -119,13 +101,13 @@ local instance : FromJson Std.Time.ZonedDateTime where
119101

120102
structure LogEntry where
121103
time : Std.Time.ZonedDateTime
122-
direction : MessageDirection
123-
kind : MessageKind
104+
direction : JsonRpc.MessageDirection
105+
kind : JsonRpc.MessageKind
124106
msg : JsonRpc.Message
125107
deriving FromJson, ToJson
126108

127109
public def writeLogEntry (cfg : LogConfig) (pending : Std.HashMap JsonRpc.RequestID MessageMethod)
128-
(log : IO.FS.Handle) (direction : MessageDirection) (msg : JsonRpc.Message) : IO Unit := do
110+
(log : IO.FS.Handle) (direction : JsonRpc.MessageDirection) (msg : JsonRpc.Message) : IO Unit := do
129111
if ! isMsgAllowed cfg pending msg then
130112
return
131113
let entry : LogEntry := {

0 commit comments

Comments
 (0)