on master help sign in
completions for REPL
commit52f5e731a377e388ea29f5f75e4963f09ad3faaa authorHannes Mehnert <hannes@mehnert.org> dateSat 13 Apr 2013, 16:49 (14 years ago) parent79b8732
2 files changed+14−9
src/Idris/IdeSlave.hs+9−6 src/Idris/REPL.hs+5−3
src/Idris/IdeSlave.hs+9−6
@@ -46,6 +46,9 @@ instance (SExpable a) => SExpable (Maybe a) where
4646instance (SExpable a) => SExpable [a] where
4747 toSExp l = List (map toSExp l)
4848
49+instance (SExpable a, SExpable b) => SExpable (a, b) where
50+ toSExp (l, r) = List [toSExp l, toSExp r]
51+
4952escape :: String -> String
5053escape = concatMap escapeChar
5154 where
@@ -74,15 +77,15 @@ quotedChar = noneOf "\""
7477parseSExp :: String -> Either ParseError SExp
7578parseSExp input = parse pSExp "(unknown)" input
7679
77−data IdeSlaveCommand = Version
80+data IdeSlaveCommand = REPLCompletions String
7881 | Interpret String
7982 deriving Show
8083
8184sexpToCommand :: SExp -> Maybe IdeSlaveCommand
82−sexpToCommand (List (x:[])) = sexpToCommand x
83−sexpToCommand (List [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
84−sexpToCommand (SymbolAtom "version") = Just Version
85−sexpToCommand _ = Nothing
85+sexpToCommand (List (x:[])) = sexpToCommand x
86+sexpToCommand (List [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
87+sexpToCommand (List [SymbolAtom "repl-completions", StringAtom prefix]) = Just (REPLCompletions prefix)
88+sexpToCommand _ = Nothing
8689
8790receiveMessage :: IO (SExp)
8891receiveMessage
@@ -106,7 +109,7 @@ sendMessage id s =
106109 -- TODO: get real output here!!!
107110 case s of
108111 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])
110113 where conv sexp =
111114 let str = sExpToString (List [SymbolAtom "return", sexp, IntegerAtom id]) in (getHexLength str) ++ str
112115
src/Idris/REPL.hs+5−3
@@ -89,7 +89,6 @@ ideslave orig mods
8989 case x of
9090 (List [(SymbolAtom "emacs-rex"), cmd, (IntegerAtom id)]) ->
9191 case sexpToCommand cmd of
92− Nothing -> do liftIO $ sendMessage id (Left "did not understand")
9392 Just (Interpret cmd) ->
9493 do i <- getIState
9594 let fn = case mods of
@@ -98,8 +97,11 @@ ideslave orig mods
9897 case parseCmd i cmd of
9998 Left err -> do liftIO $ sendMessage id (Left (show err))
10099 Right cmd -> do idrisCatch (do xs <- process fn cmd
101− liftIO $ sendMessage id (Right xs))
102− (\e -> do liftIO $ sendMessage id (Left (show e))))
100+ liftIO $ sendMessage id (Right (xs, "no output")))
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"))
103105 (\e -> do liftIO $ sendMessage 0 (Left (show e)))
104106 ideslave orig mods
105107