on master help sign in
Simplify protocol to IDESlave and :who-calls, :calls-who
39e4022David Raymond Christiansen
src/Idris/IdeSlave.hs+4−5
@@ -152,9 +152,8 @@ data IdeSlaveCommand = REPLCompletions String
152 | GetOpts
152 | GetOpts
153 | SetOpt Opt Bool
153 | SetOpt Opt Bool
154 | Metavariables Int -- ^^ the Int is the column count for pretty-printing
154 | Metavariables Int -- ^^ the Int is the column count for pretty-printing
155− | WhoCalls String Integer -- ^^ Integer is recursion depth
155+ | WhoCalls String
156− | CallsWho String Integer -- ^^ Integer is recursion depth
156+ | CallsWho String
157− deriving Show
158
157
159sexpToCommand :: SExp -> Maybe IdeSlaveCommand
158sexpToCommand :: SExp -> Maybe IdeSlaveCommand
160sexpToCommand (SexpList (x:[])) = sexpToCommand x
159sexpToCommand (SexpList (x:[])) = sexpToCommand x
@@ -178,8 +177,8 @@ sexpToCommand (SexpList [SymbolAtom "set-option", SymbolAtom s, BoolAtom b])
178 | Just opt <- lookup s opts = Just (SetOpt opt b)
177 | Just opt <- lookup s opts = Just (SetOpt opt b)
179 where opts = [("show-implicits", ShowImpl), ("error-context", ErrContext)] --TODO support more
178 where opts = [("show-implicits", ShowImpl), ("error-context", ErrContext)] --TODO support more
180sexpToCommand (SexpList [SymbolAtom "metavariables", IntegerAtom cols]) = Just (Metavariables (fromIntegral cols))
179sexpToCommand (SexpList [SymbolAtom "metavariables", IntegerAtom cols]) = Just (Metavariables (fromIntegral cols))
181−sexpToCommand (SexpList [SymbolAtom "who-calls", StringAtom name, IntegerAtom depth]) = Just (WhoCalls name depth)
180+sexpToCommand (SexpList [SymbolAtom "who-calls", StringAtom name]) = Just (WhoCalls name)
182−sexpToCommand (SexpList [SymbolAtom "calls-who", StringAtom name, IntegerAtom depth]) = Just (CallsWho name depth)
181+sexpToCommand (SexpList [SymbolAtom "calls-who", StringAtom name]) = Just (CallsWho name)
183sexpToCommand _ = Nothing
182sexpToCommand _ = Nothing
184
183
185parseMessage :: String -> Either Err (SExp, Integer)
184parseMessage :: String -> Either Err (SExp, Integer)
src/Idris/REPL.hs+12−38
@@ -338,53 +338,27 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.Metavariables cols) =
338 pprintPTerm imp (zip ns (repeat False)) [] t
338 pprintPTerm imp (zip ns (repeat False)) [] t
339 rest = sexpGoal ist cols imp (n:ns) (ps, concl)
339 rest = sexpGoal ist cols imp (n:ns) (ps, concl)
340 in ((n', t', spans) : fst rest, snd rest)
340 in ((n', t', spans) : fst rest, snd rest)
341−runIdeSlaveCommand id orig fn mods (IdeSlave.WhoCalls n d) =
341+runIdeSlaveCommand id orig fn mods (IdeSlave.WhoCalls n) =
342 case splitName n of
342 case splitName n of
343 Left err -> iPrintError err
343 Left err -> iPrintError err
344− Right n -> do res <- findCallers d n
344+ Right n -> do calls <- whoCalls n
345+ ist <- getIState
345− let msg = (IdeSlave.SymbolAtom "ok", res)
346+ let msg = (IdeSlave.SymbolAtom "ok",
347+ map (\ (n,ns) -> (pn ist n, map (pn ist) ns)) calls)
346 runIO . putStrLn $ IdeSlave.convSExp "return" msg id
348 runIO . putStrLn $ IdeSlave.convSExp "return" msg id
347− where findCallers d n | d > 1 = do calls <- whoCalls n
348− ist <- getIState
349− out <- mapM (\(n, ns) ->
350− do ns' <- mapM (findCallers (d-1)) ns
351− return (pn ist n, zip (map (pn ist) ns) ns'))
352− calls
353− return $ IdeSlave.toSExp out
354− | otherwise = do calls <- whoCalls n
355− ist <- getIState
356− return . IdeSlave.toSExp $
357− map (\(n, ns) ->
358− (pn ist n,
359− map (\n -> (pn ist n, nil)) ns))
360− calls
361− nil = IdeSlave.SexpList []
362− pn ist = displaySpans .
349+ where pn ist = displaySpans .
363 renderPretty 0.9 1000 .
350 renderPretty 0.9 1000 .
364 fmap (fancifyAnnots ist) .
351 fmap (fancifyAnnots ist) .
365 prettyName True []
352 prettyName True []
366−runIdeSlaveCommand id orig fn mods (IdeSlave.CallsWho n d) =
353+runIdeSlaveCommand id orig fn mods (IdeSlave.CallsWho n) =
367 case splitName n of
354 case splitName n of
368 Left err -> iPrintError err
355 Left err -> iPrintError err
369− Right n -> do res <- findCallees d n
356+ Right n -> do calls <- callsWho n
357+ ist <- getIState
370− let msg = (IdeSlave.SymbolAtom "ok", res)
358+ let msg = (IdeSlave.SymbolAtom "ok",
359+ map (\ (n,ns) -> (pn ist n, map (pn ist) ns)) calls)
371 runIO . putStrLn $ IdeSlave.convSExp "return" msg id
360 runIO . putStrLn $ IdeSlave.convSExp "return" msg id
372− where findCallees d n | d > 1 = do calls <- callsWho n
373− ist <- getIState
374− out <- mapM (\(n, ns) ->
375− do ns' <- mapM (findCallees (d-1)) ns
376− return (pn ist n, zip (map (pn ist) ns) ns'))
377− calls
378− return $ IdeSlave.toSExp out
379− | otherwise = do calls <- callsWho n
380− ist <- getIState
381− return . IdeSlave.toSExp $
382− map (\(n, ns) ->
383− (pn ist n,
384− map (\n -> (pn ist n, nil)) ns))
385− calls
386− nil = IdeSlave.SexpList []
387− pn ist = displaySpans .
361+ where pn ist = displaySpans .
388 renderPretty 0.9 1000 .
362 renderPretty 0.9 1000 .
389 fmap (fancifyAnnots ist) .
363 fmap (fancifyAnnots ist) .
390 prettyName True []
364 prettyName True []