repl: Print message when adding variable

I've always been annoyed that it just silently succeeded without any
feedback, but now with the upcoming improvements on defining variables
this is more necessary than ever.

Change-Id: I565897fa2f97cf6f567d4449dcc8d4ad4eb73fce
This commit is contained in:
piegames
2025-02-28 17:13:53 +01:00
parent 708f1ea342
commit 336f467b3f
2 changed files with 6 additions and 1 deletions
+1
View File
@@ -10,3 +10,4 @@ The REPL has seen various minor improvements:
- Better error messages overall
- The `:env` command to print currently available variables now also works outside of debug mode
- Adding variables to the REPL now prints a small message on success
+5 -1
View File
@@ -1088,8 +1088,12 @@ void NixRepl::addVarToScope(const Symbol name, Value & v)
{
if (displ >= envSize)
throw Error("environment full; cannot add more variables");
if (auto oldVar = staticEnv->find(name); oldVar != staticEnv->vars.end())
if (auto oldVar = staticEnv->find(name); oldVar != staticEnv->vars.end()) {
staticEnv->vars.erase(oldVar);
notice("Updated %s.", evaluator.symbols[name]);
} else {
notice("Added %s.", evaluator.symbols[name]);
}
staticEnv->vars.emplace_back(name, displ);
staticEnv->sort();
env->values[displ++] = &v;