3 | import public Libraries.Data.Span
5 | import public Protocol.IDE.Command as Protocol.IDE
6 | import public Protocol.IDE.Decoration as Protocol.IDE
7 | import public Protocol.IDE.Formatting as Protocol.IDE
8 | import public Protocol.IDE.FileContext as Protocol.IDE
9 | import public Protocol.IDE.Holes as Protocol.IDE
10 | import public Protocol.IDE.Result as Protocol.IDE
11 | import public Protocol.IDE.Highlight as Protocol.IDE
13 | import Protocol.SExp
14 | import Protocol.SExp.Parser
21 | Highlighting = List (Span Properties)
24 | SExpable a => SExpable (Span a) where
25 | toSExp (MkSpan start width ann)
26 | = SExpList [ IntegerAtom (cast start)
27 | , IntegerAtom (cast width)
32 | FromSExpable a => FromSExpable (Span a) where
33 | fromSExp (SExpList [ start
36 | ]) = do pure $
MkSpan { start = !(fromSExp start)
37 | , length = !(fromSExp width)
38 | , property = !(fromSExp ann)}
39 | fromSExp _ = Nothing
45 | OK Result Highlighting
46 | | HighlightSource (List SourceHighlight)
47 | | Error String Highlighting
50 | SExpable ReplyPayload where
51 | toSExp (OK result hl) = SExpList (SymbolAtom "ok" :: toSExp result ::
54 | _ => [SExpList (map toSExp hl)])
55 | toSExp (HighlightSource hls) = SExpList
58 | [ SymbolAtom "highlight-source"
61 | toSExp (Error msg hl) = SExpList (SymbolAtom "error" :: toSExp msg ::
64 | _ => [SExpList (map toSExp hl)])
69 | FromSExpable ReplyPayload where
73 | [ SymbolAtom "highlight-source"
75 | ]) = do pure $
HighlightSource !(fromSExp hls)
76 | fromSExp (SExpList [SymbolAtom "ok", result])
77 | = do pure $
OK !(fromSExp result) []
78 | fromSExp (SExpList [SymbolAtom "ok", result, hl])
79 | = do pure $
OK !(fromSExp result) !(fromSExp hl)
80 | fromSExp (SExpList [SymbolAtom "error", msg])
81 | = do pure $
Error !(fromSExp msg) []
82 | fromSExp (SExpList [SymbolAtom "error", msg, hl])
83 | = do pure $
Error !(fromSExp msg) !(fromSExp hl)
84 | fromSExp _ = Nothing
88 | ProtocolVersion Int Int
89 | | Immediate ReplyPayload Integer
90 | | Intermediate ReplyPayload Integer
91 | | WriteString String Integer
92 | | SetPrompt String Integer
93 | | Warning FileContext String Highlighting Integer
96 | SExpable Reply where
97 | toSExp (ProtocolVersion maj min) = toSExp (SymbolAtom "protocol-version", maj, min)
98 | toSExp ( Immediate payload id) = SExpList [SymbolAtom "return",
99 | toSExp payload, toSExp id]
100 | toSExp (Intermediate payload id) = SExpList [SymbolAtom "output",
101 | toSExp payload, toSExp id]
102 | toSExp (WriteString str id) = SExpList [SymbolAtom "write-string", toSExp str, toSExp id]
103 | toSExp (SetPrompt str id) = SExpList [SymbolAtom "set-prompt" , toSExp str, toSExp id]
104 | toSExp (Warning fc str spans id) = SExpList [SymbolAtom "warning",
105 | SExpList $
toSExp fc.file :: toSExp (fc.range.startLine, fc.range.startCol)
106 | :: toSExp (fc.range.endLine , fc.range.endCol )
107 | :: toSExp str :: case spans of
109 | _ => [SExpList (map toSExp spans)]
113 | FromSExpable Reply where
114 | fromSExp (SExpList [SymbolAtom "protocol-version", major, minor]) =
115 | do Just $
ProtocolVersion !(fromSExp major) !(fromSExp minor)
116 | fromSExp (SExpList [SymbolAtom "return", payload, iden]) =
117 | do Just $
Immediate !(fromSExp payload) !(fromSExp iden)
118 | fromSExp (SExpList [SymbolAtom "output", payload, iden]) =
119 | do Just $
Intermediate !(fromSExp payload) !(fromSExp iden)
120 | fromSExp (SExpList [SymbolAtom "write-string", str, iden]) =
121 | do Just $
WriteString !(fromSExp str) !(fromSExp iden)
122 | fromSExp (SExpList [SymbolAtom "set-prompt", str, iden]) =
123 | do Just $
SetPrompt !(fromSExp str) !(fromSExp iden)
124 | fromSExp (SExpList [SymbolAtom "warning"
125 | , SExpList [filename, SExpList [startLine, startCol]
126 | , SExpList [endLine , endCol ]
129 | pure $
Warning (MkFileContext
130 | { file = !(fromSExp filename)
131 | , range = MkBounds { startLine = !(fromSExp startLine)
132 | , startCol = !(fromSExp startCol)
133 | , endLine = !(fromSExp endLine)
134 | , endCol = !(fromSExp endCol)}
139 | fromSExp (SExpList [SymbolAtom "warning"
140 | , SExpList [filename, SExpList [startLine, startCol]
141 | , SExpList [endLine , endCol ]
144 | pure $
Warning (MkFileContext
145 | { file = !(fromSExp filename)
146 | , range = MkBounds { startLine = !(fromSExp startLine)
147 | , startCol = !(fromSExp startCol)
148 | , endLine = !(fromSExp endLine)
149 | , endCol = !(fromSExp endCol)}
154 | fromSExp _ = Nothing
161 | SExpable Request where
162 | toSExp (Cmd cmd) = toSExp cmd
165 | FromSExpable Request where
166 | fromSExp cmd = do pure $
Cmd !(fromSExp cmd)