commit 18dbd57e9ff789bd4b1d64b27659bd97e4477dce
parent c443ed5f22402f882298a1228e155946749e00f1
Author: Lou Woell <lou.woell@posteo.de>
Date:   Tue, 17 Feb 2026 03:43:48 +0100

[locate] support locating enums by members

Diffstat:
Mcmd/harehelper/locate.ha | 33+++++++++++++++++++++++++--------
1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/cmd/harehelper/locate.ha b/cmd/harehelper/locate.ha @@ -49,6 +49,12 @@ fn locate_symbol ( module: bool = false, ) (lex::location | error) = { + // Assumed name for the declaration. This is needed later because for + // enum members we're looking for the declaration of the enum, which is + // not identical with the last segment of the id (that being the enum + // member itself). + let decl_name = ident_last(id); + let ns: module::location = if (module) { // if we know id is a module we can use id as the namespace for // the lookup. @@ -59,7 +65,7 @@ fn locate_symbol ( let p = path::init(os::getcwd())!; let dirname = match (path::peek(&p)) { case void => - yield "/"; + yield "/"; case let s: str => yield s; }; @@ -88,10 +94,21 @@ fn locate_symbol ( case let e: module::error => match (module::unwrap_error(e)) { case module::not_found => - // free error and try finding id as module. + // free error module::finish_error(e); - module = true; - yield :module, module::find(ctx, id)?; + match (ns) { + // Move up one level in namespaces. This allows finding + // enum members. + case let loc_ns: ast::ident => + decl_name = ident_last(loc_ns); + ns = ident_ns(loc_ns); + yield :module, module::find(ctx, ns)?; + // This case is hit when ns was set to cwd above and no + // module was found there, so we try finding id as + // module. + case let ns: *path::buffer => + yield :module, module::find(ctx, id)?; + }; case => return e; }; @@ -121,13 +138,13 @@ fn locate_symbol ( match (decl.decl) { case let d: ast::decl_const => - found = ast::ident_eq(ident_last(id), d.ident); + found = ast::ident_eq(decl_name, d.ident); case let d: ast::decl_global => - found = ast::ident_eq(ident_last(id), d.ident); + found = ast::ident_eq(decl_name, d.ident); case let d: ast::decl_type => - found = ast::ident_eq(ident_last(id), d.ident); + found = ast::ident_eq(decl_name, d.ident); case let d: ast::decl_func => - found = ast::ident_eq(ident_last(id), d.ident); + found = ast::ident_eq(decl_name, d.ident); case ast::assert_expr => void; };