commit 9578d72144f4c9a98a175c949e739fffc3bec1a9
parent f748ace52aaadc5e7f2b1b5e11e6ed5979154084
Author: Lou Woell <lou.woell@posteo.de>
Date:   Fri, 19 Sep 2025 01:55:19 +0200

[resolve] resolve local symbols relative to harepath

`harehelper -p . resolve scan ./cmd/harehelper/util.ha` now returns
`cmd::harehelper::scan` instead of `scan`.

This ensures that haredoc always will be able to find symbols returned by
harehelper, if they use the same harepath.

Diffstat:
Mcmd/harehelper/resolve.ha | 39++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/cmd/harehelper/resolve.ha b/cmd/harehelper/resolve.ha @@ -23,6 +23,8 @@ use hare::parse; use hare::unparse; use io; use os; +use path; +use strings; fn resolve(cmd: getopt::command, ctx: *module::context) void = { @@ -48,10 +50,45 @@ fn resolve(cmd: getopt::command, ctx: *module::context) void = { printident(id_exp, trailing); ast::ident_free(id_exp); case => - printident(id, trailing); + match (resolve_local(ctx, id, file)) { + case let id: ast::ident => + printident(id, trailing); + free(id); + case => + printident(id, trailing); + }; }; }; +// Prepend id with path to file (relative to HAREPATH). Components of return +// value are borrowed from input. Slice itself must be freed. +fn resolve_local ( + ctx: *module::context, + id: ast::ident, + file: str, +) (ast::ident | void) = { + + let hp = strings::split(ctx.harepath, ":")!; + defer free(hp); + + let new_id: ast::ident = []; + + for (let p .. hp) { + if (strings::hasprefix(file, p)) { + let new_path = strings::trimprefix(file, p); + new_path = strings::trimprefix(new_path, "/"); + new_path = path::dirname(new_path); + new_id = strings::split(new_path, "/")!; + for (let s .. id) { + append(new_id, s)!; + }; + return new_id; + }; + }; + + return void; +}; + fn list_imports (path: str) []ast::import = { const input = match (os::open(path)) {