on master help sign in
Add REPL commands for who calls who
7bc8bfdDavid Raymond Christiansen
src/Idris/AbsSyntaxTree.hs+2
@@ -306,6 +306,8 @@ data Command = Quit
306 | ListErrorHandlers
306 | ListErrorHandlers
307 | SetConsoleWidth ConsoleWidth
307 | SetConsoleWidth ConsoleWidth
308 | Apropos String
308 | Apropos String
309+ | WhoCalls Name
310+ | CallsWho Name
309
311
310data Opt = Filename String
312data Opt = Filename String
311 | Ver
313 | Ver
src/Idris/Help.hs+2
@@ -30,6 +30,8 @@ help =
30 ([":miss", ":missing"], NameArg, "Show missing clauses"),
30 ([":miss", ":missing"], NameArg, "Show missing clauses"),
31 ([":doc"], NameArg, "Show internal documentation"),
31 ([":doc"], NameArg, "Show internal documentation"),
32 ([":apropos"], NoArg, "Search names, types, and documentation"),
32 ([":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"),
33 ([":i", ":info"], NameArg, "Display information about a type class"),
35 ([":i", ":info"], NameArg, "Display information about a type class"),
34 ([":total"], NameArg, "Check the totality of a name"),
36 ([":total"], NameArg, "Check the totality of a name"),
35 ([":r",":reload"], NoArg, "Reload current file"),
37 ([":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
456 iPrintResult ""
456 iPrintResult ""
457ideslaveProcess fn (Apropos a) = do process stdout fn (Apropos a)
457ideslaveProcess fn (Apropos a) = do process stdout fn (Apropos a)
458 iPrintResult ""
458 iPrintResult ""
459+ideslaveProcess fn (WhoCalls n) = process stdout fn (WhoCalls n)
460+ideslaveProcess fn (CallsWho n) = process stdout fn (CallsWho n)
459ideslaveProcess fn _ = iPrintError "command not recognized or not supported"
461ideslaveProcess fn _ = iPrintError "command not recognized or not supported"
460
462
461
463
@@ -1092,6 +1094,24 @@ process h fn (Apropos a) =
1092 isUN (NS n _) = isUN n
1094 isUN (NS n _) = isUN n
1093 isUN _ = False
1095 isUN _ = False
1094
1096
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+
1095classInfo :: ClassInfo -> Idris (Doc OutputAnnotation)
1115classInfo :: ClassInfo -> Idris (Doc OutputAnnotation)
1096classInfo ci = do ist <- getIState
1116classInfo ci = do ist <- getIState
1097 ctxt <- getContext
1117 ctxt <- getContext
src/Idris/REPLParser.hs+2
@@ -99,6 +99,8 @@ pCmd = do P.whiteSpace; try (do cmd ["q", "quit"]; eof; return Quit)
99 <|> try (do cmd ["errorhandlers"]; eof ; return ListErrorHandlers)
99 <|> try (do cmd ["errorhandlers"]; eof ; return ListErrorHandlers)
100 <|> try (do cmd ["consolewidth"]; w <- pConsoleWidth ; return (SetConsoleWidth w))
100 <|> try (do cmd ["consolewidth"]; w <- pConsoleWidth ; return (SetConsoleWidth w))
101 <|> try (do cmd ["apropos"]; str <- many anyChar ; return (Apropos str))
101 <|> 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))
102 <|> do P.whiteSpace; do eof; return NOP
104 <|> do P.whiteSpace; do eof; return NOP
103 <|> do t <- P.fullExpr defaultSyntax; return (Eval t)
105 <|> do t <- P.fullExpr defaultSyntax; return (Eval t)
104
106