on master help sign in
Simplify protocol to IDESlave and :who-calls, :calls-who
commit39e40222fef0fb5ee464ba1f2ead8174e0c82f8d authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateTue 15 Apr 2014, 19:12 (13 years ago) parent7bc8bfd
2 files changed+16−43
src/Idris/IdeSlave.hs+4−5 src/Idris/REPL.hs+12−38
src/Idris/IdeSlave.hs+4−5
@@ -152,9 +152,8 @@ data IdeSlaveCommand = REPLCompletions String
152152 | GetOpts
153153 | SetOpt Opt Bool
154154 | Metavariables Int -- ^^ the Int is the column count for pretty-printing
155− | WhoCalls String Integer -- ^^ Integer is recursion depth
156− | CallsWho String Integer -- ^^ Integer is recursion depth
157− deriving Show
155+ | WhoCalls String
156+ | CallsWho String
158157
159158sexpToCommand :: SExp -> Maybe IdeSlaveCommand
160159sexpToCommand (SexpList (x:[])) = sexpToCommand x
@@ -178,8 +177,8 @@ sexpToCommand (SexpList [SymbolAtom "set-option", SymbolAtom s, BoolAtom b])
178177 | Just opt <- lookup s opts = Just (SetOpt opt b)
179178 where opts = [("show-implicits", ShowImpl), ("error-context", ErrContext)] --TODO support more
180179sexpToCommand (SexpList [SymbolAtom "metavariables", IntegerAtom cols]) = Just (Metavariables (fromIntegral cols))
181−sexpToCommand (SexpList [SymbolAtom "who-calls", StringAtom name, IntegerAtom depth]) = Just (WhoCalls name depth)
182−sexpToCommand (SexpList [SymbolAtom "calls-who", StringAtom name, IntegerAtom depth]) = Just (CallsWho name depth)
180+sexpToCommand (SexpList [SymbolAtom "who-calls", StringAtom name]) = Just (WhoCalls name)
181+sexpToCommand (SexpList [SymbolAtom "calls-who", StringAtom name]) = Just (CallsWho name)
183182sexpToCommand _ = Nothing
184183
185184parseMessage :: String -> Either Err (SExp, Integer)
src/Idris/REPL.hs+12−38
@@ -338,53 +338,27 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.Metavariables cols) =
338338 pprintPTerm imp (zip ns (repeat False)) [] t
339339 rest = sexpGoal ist cols imp (n:ns) (ps, concl)
340340 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) =
342342 case splitName n of
343343 Left err -> iPrintError err
344− Right n -> do res <- findCallers d n
345− let msg = (IdeSlave.SymbolAtom "ok", res)
344+ Right n -> do calls <- whoCalls n
345+ ist <- getIState
346+ let msg = (IdeSlave.SymbolAtom "ok",
347+ map (\ (n,ns) -> (pn ist n, map (pn ist) ns)) calls)
346348 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 .
363350 renderPretty 0.9 1000 .
364351 fmap (fancifyAnnots ist) .
365352 prettyName True []
366−runIdeSlaveCommand id orig fn mods (IdeSlave.CallsWho n d) =
353+runIdeSlaveCommand id orig fn mods (IdeSlave.CallsWho n) =
367354 case splitName n of
368355 Left err -> iPrintError err
369− Right n -> do res <- findCallees d n
370− let msg = (IdeSlave.SymbolAtom "ok", res)
356+ Right n -> do calls <- callsWho n
357+ ist <- getIState
358+ let msg = (IdeSlave.SymbolAtom "ok",
359+ map (\ (n,ns) -> (pn ist n, map (pn ist) ns)) calls)
371360 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 .
388362 renderPretty 0.9 1000 .
389363 fmap (fancifyAnnots ist) .
390364 prettyName True []