0 | module Idris.IDEMode.Commands
 1 |
 2 | import Core.Context.Log
 3 | import public Idris.REPL.Opts
 4 | import Protocol.Hex
 5 |
 6 | import System.File
 7 |
 8 | import public Protocol.IDE
 9 | import public Protocol.SExp
10 |
11 | %default total
12 |
13 | export
14 | Cast (FileName, NonEmptyFC) FileContext where
15 |   cast (filename, _, (startLine, startCol), (endLine, endCol)) =
16 |     MkFileContext
17 |       { file  = filename
18 |       , range = MkBounds {startLine, startCol, endLine, endCol}
19 |       }
20 |
21 | export
22 | getMsg : SExp -> Maybe (IDECommand, Integer)
23 | getMsg (SExpList [cmdexp, IntegerAtom num])
24 |    = do cmd <- fromSExp cmdexp
25 |         pure (cmd, num)
26 | getMsg _ = Nothing
27 |
28 | export
29 | SExpable Name where
30 |   toSExp = SymbolAtom . show
31 |
32 | sendStr : File -> String -> IO ()
33 | sendStr f st =
34 |   map (const ()) (fPutStr f st)
35 |
36 | export
37 | send : {auto c : Ref Ctxt Defs} -> File -> Reply -> Core ()
38 | send f resp
39 |     = do let r = show (toSExp resp) ++ "\n"
40 |          log "ide-mode.send" 20 r
41 |          coreLift $ sendStr f $ leftPad '0' 6 (asHex (cast (length r)))
42 |          coreLift $ sendStr f r
43 |          coreLift $ fflush f
44 |