From 28e47008c303f384fabf20803d1b74e966a2bcec Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 15 Mar 2021 01:42:51 +0100 Subject: [PATCH] :art: *Improve did you mean* --- src/parse/check.c | 4 ++-- src/parse/did_you_mean.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/parse/check.c b/src/parse/check.c index d2e479c9..213cba36 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -289,8 +289,8 @@ ANN static Type prim_id_non_res(const Env env, const Symbol *data) { const Symbol sym = *data; const Value v = check_non_res_value(env, data); if(!v || !vflag(v, vflag_valid) || (v->from->ctx && v->from->ctx->error)) { - env_err(env, prim_pos(data), - _("variable %s not legit at this point."), s_name(sym)); + gwerr_basic(_("Invalid variable"), _("not legit at this point."), "did you mean:", + env->name, prim_pos(data), 0); did_you_mean_nspc(v ? value_owner(env, v) : env->curr, s_name(sym)); return NULL; } diff --git a/src/parse/did_you_mean.c b/src/parse/did_you_mean.c index 11e4f0d6..01665eb6 100644 --- a/src/parse/did_you_mean.c +++ b/src/parse/did_you_mean.c @@ -45,6 +45,7 @@ ANN static void ressembles(const Vector v, const Nspc nspc, const char* name) { #define MAX_NAME_LEN 16 #define CHECK_LEN(name) if(strlen(name) > MAX_NAME_LEN) return; +#define DYM_FMT "`{/+}%s{0}`?\n" #undef did_you_mean_nspc ANN void did_you_mean_nspc(Nspc nspc, const char* name) { @@ -54,7 +55,7 @@ ANN void did_you_mean_nspc(Nspc nspc, const char* name) { do ressembles(&v, nspc, name); while((nspc = nspc->parent)); for(m_uint i = 0; i < vector_size(&v); ++i) - gw_err(_(" (did you mean '%s'?)\n"), (m_str)vector_at(&v, i)); + gw_err(DYM_FMT, (m_str)vector_at(&v, i)); vector_release(&v); } @@ -67,6 +68,6 @@ ANN void did_you_mean_type(Type type, const char* name) { do ressembles(&v, t->nspc, name); while((t = t->info->parent) && t->nspc); for(m_uint i = 0; i < vector_size(&v); ++i) - gw_err(_(" (did you mean '%s'?)\n"), (m_str)vector_at(&v, i)); + gw_err(DYM_FMT, (m_str)vector_at(&v, i)); vector_release(&v); } -- 2.43.0