on master help sign in
Add REPL commands for who calls who
commit7bc8bfdd4e236df46c2cb086439e82870ca3b47b authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateTue 15 Apr 2014, 16:15 (13 years ago) parent418a6b6
4 files changed+26
src/Idris/AbsSyntaxTree.hs+2 src/Idris/Help.hs+2 src/Idris/REPL.hs+20 src/Idris/REPLParser.hs+2
src/Idris/AbsSyntaxTree.hs+2
@@ -306,6 +306,8 @@ data Command = Quit
306306 | ListErrorHandlers
307307 | SetConsoleWidth ConsoleWidth
308308 | Apropos String
309+ | WhoCalls Name
310+ | CallsWho Name
309311
310312data Opt = Filename String
311313 | Ver
src/Idris/Help.hs+2
@@ -30,6 +30,8 @@ help =
3030 ([":miss", ":missing"], NameArg, "Show missing clauses"),
3131 ([":doc"], NameArg, "Show internal documentation"),
3232 ([":apropos"], NoArg, "Search names, types, and documentation"),
33+ ([":whocalls", ":wc"], NameArg, "List the callers of some name"),
34+ ([":callswho", ":cw"], NameArg, "List the callees of some name"),
3335 ([":i", ":info"], NameArg, "Display information about a type class"),
3436 ([":total"], NameArg, "Check the totality of a name"),
3537 ([":r",":reload"], NoArg, "Reload current file"),
src/Idris/REPL.hs+20
@@ -456,6 +456,8 @@ ideslaveProcess fn (SetConsoleWidth w) = do process stdout fn (SetConsoleWidth w
456456 iPrintResult ""
457457ideslaveProcess fn (Apropos a) = do process stdout fn (Apropos a)
458458 iPrintResult ""
459+ideslaveProcess fn (WhoCalls n) = process stdout fn (WhoCalls n)
460+ideslaveProcess fn (CallsWho n) = process stdout fn (CallsWho n)
459461ideslaveProcess fn _ = iPrintError "command not recognized or not supported"
460462
461463
@@ -1092,6 +1094,24 @@ process h fn (Apropos a) =
10921094 isUN (NS n _) = isUN n
10931095 isUN _ = False
10941096
1097+process h fn (WhoCalls n) =
1098+ do calls <- whoCalls n
1099+ ist <- getIState
1100+ ihRenderResult h . vsep $
1101+ map (\(n, ns) ->
1102+ text "Callers of" <+> prettyName True [] n <$>
1103+ indent 1 (vsep (map ((text "*" <+>) . align . prettyName True []) ns)))
1104+ calls
1105+
1106+process h fn (CallsWho n) =
1107+ do calls <- callsWho n
1108+ ist <- getIState
1109+ ihRenderResult h . vsep $
1110+ map (\(n, ns) ->
1111+ prettyName True [] n <+> text "calls:" <$>
1112+ indent 1 (vsep (map ((text "*" <+>) . align . prettyName True []) ns)))
1113+ calls
1114+
10951115classInfo :: ClassInfo -> Idris (Doc OutputAnnotation)
10961116classInfo ci = do ist <- getIState
10971117 ctxt <- getContext
src/Idris/REPLParser.hs+2
@@ -99,6 +99,8 @@ pCmd = do P.whiteSpace; try (do cmd ["q", "quit"]; eof; return Quit)
9999 <|> try (do cmd ["errorhandlers"]; eof ; return ListErrorHandlers)
100100 <|> try (do cmd ["consolewidth"]; w <- pConsoleWidth ; return (SetConsoleWidth w))
101101 <|> try (do cmd ["apropos"]; str <- many anyChar ; return (Apropos str))
102+ <|> try (do cmd ["wc", "whocalls"]; P.whiteSpace; n <- P.fnName ; return (WhoCalls n))
103+ <|> try (do cmd ["cw", "callswho"]; P.whiteSpace; n <- P.fnName ; return (CallsWho n))
102104 <|> do P.whiteSpace; do eof; return NOP
103105 <|> do t <- P.fullExpr defaultSyntax; return (Eval t)
104106