commit 3b7793a9596d2f165393bd9afd71f428439de50d
parent b8725d36fc808349472909c6957a7b72d0aca760
Author: Lou Woell <lou.woell@posteo.de>
Date: Thu, 11 Sep 2025 16:41:44 +0200
[locate] locate modules
Diffstat:
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/cmd/harehelper/+test/locate_test.ha b/cmd/harehelper/+test/locate_test.ha
@@ -88,3 +88,12 @@ fn loc_test_fn (in: str, out: lex::location) void = {
...
});
};
+
+@test fn locate_module () void = {
+ loc_test_fn("os", lex::location {
+ path = "os",
+ line = 0,
+ col = 0,
+ ...
+ });
+};
diff --git a/cmd/harehelper/+test/resolve_test.ha b/cmd/harehelper/+test/resolve_test.ha
@@ -22,7 +22,7 @@ fn resolve_test_fn (in: str, out: str) void = {
const id = parse::identstr(in)!;
const exp = parse::identstr(out)!;
- const res = find_uid(&ctx, id, "./cmd/harehelper/+test/resolve_test.ha");
+ const res = resolve_uid(&ctx, id, "./cmd/harehelper/+test/resolve_test.ha");
match(res) {
case void => abort();
diff --git a/cmd/harehelper/locate.ha b/cmd/harehelper/locate.ha
@@ -48,7 +48,22 @@ fn locate_symbol (
id: ast::ident
) (lex::location | void) = {
+ // Check if id is a module
+ match (module::find(ctx, id)) {
+ case module::error => void;
+ case let r: (str, module::srcset) =>
+ defer module::finish_srcset(&r.1);
+ return lex::location {
+ path = strings::dup(r.0)!,
+ line = 0,
+ col = 0,
+ off = 0,
+ };
+ };
+
+ // else: treat id as having the form namespace::symbol.
let ns: module::location = ident_ns(id);
+ // if no namespace prefix is present look for a declaration in the cwd.
if (len(id) <= 1) {
let p = path::init(os::getcwd())!;
ns = &p;