From f53b5f10585b1d4c939e45faf0dd2f4dacbca013 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 25 Aug 2020 13:31:11 +0200 Subject: Add getDoc() function --- src/nix/repl.cc | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/nix') diff --git a/src/nix/repl.cc b/src/nix/repl.cc index c7f8af742..8ecf11900 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -514,23 +514,22 @@ bool NixRepl::processLine(string line) else if (command == ":doc") { Value v; evalString(arg, v); - if (v.type == tPrimOp || v.type == tPrimOpApp) { - auto v2 = &v; - while (v2->type == tPrimOpApp) - v2 = v2->primOpApp.left; - if (v2->primOp->doc) { - auto args = v2->primOp->args; + if (auto doc = state->getDoc(v)) { + std::string markdown; + + if (!doc->args.empty() && doc->name) { + auto args = doc->args; for (auto & arg : args) arg = "*" + arg + "*"; - auto markdown = - "**Synopsis:** `builtins." + (std::string) v2->primOp->name + "` " - + concatStringsSep(" ", args) + "\n\n" - + trim(stripIndentation(v2->primOp->doc)); + markdown += + "**Synopsis:** `builtins." + (std::string) (*doc->name) + "` " + + concatStringsSep(" ", args) + "\n\n"; + } + + markdown += trim(stripIndentation(doc->doc)); - std::cout << renderMarkdownToTerminal(markdown); - } else - throw Error("builtin function '%s' does not have documentation", v2->primOp->name); + std::cout << renderMarkdownToTerminal(markdown); } else throw Error("value does not have documentation"); } -- cgit v1.2.3