hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit f3364fcb0e43deaa00b39073d2e94ebe65d6168f
parent 1513c82824edd42abeabdbf6b8b56396fa1a5db4
Author: Sebastian <sebastian@sebsite.pw>
Date:   Tue, 17 Oct 2023 22:30:13 -0400

haredoc: print message when no decls are exported

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mcmd/haredoc/doc/tty.ha | 38++++++++++++++++++++++++++++++--------
Mcmd/haredoc/doc/util.ha | 2++
2 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/cmd/haredoc/doc/tty.ha b/cmd/haredoc/doc/tty.ha @@ -12,7 +12,6 @@ use os; use strings; use types; -let firstline: bool = true; let no_color: bool = false; // Formats output as Hare source code (prototypes) with syntax highlighting @@ -63,20 +62,42 @@ export fn emit_tty(ctx: *context) (void | error) = { emit_submodules_tty(ctx)?; // XXX: Should we emit the dependencies, too? + let printed = false; for (let i = 0z; i < len(summary.types); i += 1) { - details_tty(ctx, summary.types[i])?; + if (details_tty(ctx, summary.types[i])?) { + printed = true; + }; }; for (let i = 0z; i < len(summary.constants); i += 1) { - details_tty(ctx, summary.constants[i])?; + if (details_tty(ctx, summary.constants[i])?) { + printed = true; + }; }; for (let i = 0z; i < len(summary.errors); i += 1) { - details_tty(ctx, summary.errors[i])?; + if (details_tty(ctx, summary.errors[i])?) { + printed = true; + }; }; for (let i = 0z; i < len(summary.globals); i += 1) { - details_tty(ctx, summary.globals[i])?; + if (details_tty(ctx, summary.globals[i])?) { + printed = true; + }; }; for (let i = 0z; i < len(summary.funcs); i += 1) { - details_tty(ctx, summary.funcs[i])?; + if (details_tty(ctx, summary.funcs[i])?) { + printed = true; + }; + }; + + if (!printed) { + if (!firstline) { + fmt::fprintln(ctx.out)?; + }; + if (!no_color) fmt::fprintf(ctx.out, "\x1b[{}m", + color(unparse::synkind::COMMENT))?; + fmt::fprint(ctx.out, "// No exported declarations")?; + if (!no_color) fmt::fprint(ctx.out, "\x1b[m")?; + fmt::fprintln(ctx.out)?; }; }; @@ -105,9 +126,9 @@ fn emit_submodules_tty(ctx: *context) (void | error) = { }; }; -fn details_tty(ctx: *context, decl: ast::decl) (void | error) = { +fn details_tty(ctx: *context, decl: ast::decl) (bool | error) = { if (len(decl.docs) == 0 && !ctx.show_undocumented) { - return; + return false; }; if (!no_color) fmt::fprint(ctx.out, "\x1b[m")?; // reset styling @@ -118,6 +139,7 @@ fn details_tty(ctx: *context, decl: ast::decl) (void | error) = { unparse::decl(ctx.out, &syn_tty, decl)?; fmt::fprintln(ctx.out)?; + return true; }; fn syn_tty( diff --git a/cmd/haredoc/doc/util.ha b/cmd/haredoc/doc/util.ha @@ -12,6 +12,8 @@ use sort; use sort::cmp; use strings; +let firstline: bool = true; + fn trim_comment(s: str) str = { let trimmed = memio::dynamic(); let tok = strings::tokenize(s, "\n");