on master help sign in
completions for REPL
52f5e73Hannes Mehnert
src/Idris/IdeSlave.hs+9−6
@@ -46,6 +46,9 @@ instance (SExpable a) => SExpable (Maybe a) where
46instance (SExpable a) => SExpable [a] where
46instance (SExpable a) => SExpable [a] where
47 toSExp l = List (map toSExp l)
47 toSExp l = List (map toSExp l)
48
48
49+instance (SExpable a, SExpable b) => SExpable (a, b) where
50+ toSExp (l, r) = List [toSExp l, toSExp r]
51+
49escape :: String -> String
52escape :: String -> String
50escape = concatMap escapeChar
53escape = concatMap escapeChar
51 where
54 where
@@ -74,15 +77,15 @@ quotedChar = noneOf "\""
74parseSExp :: String -> Either ParseError SExp
77parseSExp :: String -> Either ParseError SExp
75parseSExp input = parse pSExp "(unknown)" input
78parseSExp input = parse pSExp "(unknown)" input
76
79
77−data IdeSlaveCommand = Version
80+data IdeSlaveCommand = REPLCompletions String
78 | Interpret String
81 | Interpret String
79 deriving Show
82 deriving Show
80
83
81sexpToCommand :: SExp -> Maybe IdeSlaveCommand
84sexpToCommand :: SExp -> Maybe IdeSlaveCommand
82−sexpToCommand (List (x:[])) = sexpToCommand x
85+sexpToCommand (List (x:[])) = sexpToCommand x
83−sexpToCommand (List [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
86+sexpToCommand (List [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
84−sexpToCommand (SymbolAtom "version") = Just Version
87+sexpToCommand (List [SymbolAtom "repl-completions", StringAtom prefix]) = Just (REPLCompletions prefix)
85−sexpToCommand _ = Nothing
88+sexpToCommand _ = Nothing
86
89
87receiveMessage :: IO (SExp)
90receiveMessage :: IO (SExp)
88receiveMessage
91receiveMessage
@@ -106,7 +109,7 @@ sendMessage id s =
106 -- TODO: get real output here!!!
109 -- TODO: get real output here!!!
107 case s of
110 case s of
108 Left err -> putStrLn $ conv (List [SymbolAtom "abort", toSExp err])
111 Left err -> putStrLn $ conv (List [SymbolAtom "abort", toSExp err])
109− Right succ -> putStrLn $ conv (List [SymbolAtom "ok", List [toSExp succ, StringAtom "no output"]])
112+ Right succ -> putStrLn $ conv (List [SymbolAtom "ok", toSExp succ])
110 where conv sexp =
113 where conv sexp =
111 let str = sExpToString (List [SymbolAtom "return", sexp, IntegerAtom id]) in (getHexLength str) ++ str
114 let str = sExpToString (List [SymbolAtom "return", sexp, IntegerAtom id]) in (getHexLength str) ++ str
112
115
src/Idris/REPL.hs+5−3
@@ -89,7 +89,6 @@ ideslave orig mods
89 case x of
89 case x of
90 (List [(SymbolAtom "emacs-rex"), cmd, (IntegerAtom id)]) ->
90 (List [(SymbolAtom "emacs-rex"), cmd, (IntegerAtom id)]) ->
91 case sexpToCommand cmd of
91 case sexpToCommand cmd of
92− Nothing -> do liftIO $ sendMessage id (Left "did not understand")
93 Just (Interpret cmd) ->
92 Just (Interpret cmd) ->
94 do i <- getIState
93 do i <- getIState
95 let fn = case mods of
94 let fn = case mods of
@@ -98,8 +97,11 @@ ideslave orig mods
98 case parseCmd i cmd of
97 case parseCmd i cmd of
99 Left err -> do liftIO $ sendMessage id (Left (show err))
98 Left err -> do liftIO $ sendMessage id (Left (show err))
100 Right cmd -> do idrisCatch (do xs <- process fn cmd
99 Right cmd -> do idrisCatch (do xs <- process fn cmd
101− liftIO $ sendMessage id (Right xs))
100+ liftIO $ sendMessage id (Right (xs, "no output")))
102− (\e -> do liftIO $ sendMessage id (Left (show e))))
101+ (\e -> do liftIO $ sendMessage id (Left (show e)))
102+ Just (REPLCompletions str) -> do (unused, compls) <- replCompletion (reverse str, "")
103+ liftIO $ sendMessage id (Right (map replacement compls, reverse unused))
104+ Nothing -> do liftIO $ sendMessage id (Left "did not understand"))
103 (\e -> do liftIO $ sendMessage 0 (Left (show e)))
105 (\e -> do liftIO $ sendMessage 0 (Left (show e)))
104 ideslave orig mods
106 ideslave orig mods
105
107