Repository navigation
feat: lock $env.config.history.path after REPL startup - #18190
Conversation
|
Hey, just a bot checking in! You edited files related to the configuration. |
|
If the goal is to unify the behavior of setting the history option, I believe an error should not be thrown. Currently, for the history option, except for If, after discussion, we only need to label which options are for the startup phase and which are for the REPL phase, then we do not need the changes in this PR. |
|
Fair point on consistency. To clarify the scope I was working from: this PR was specifically implementing the behavior @fdncred suggested in #18188 (comment), "disallow $env.config.history.path changing from the repl and give an error" you're right though that max_size, file_format, and probably isolation have the same silent-no-op problem and aren't covered here.
I'm happy with any of them, but the call on which direction (and whether the broader "annotate all $env.config entries / split into a $env.config_repl" idea is worth taking on) feels like a core-team design decision rather than something to settle in this PR. @fdncred, any thoughts 😄 |
|
Thanks @kx0101 for being so willing to help. I think all repl-immutable options should give an error explaining that it cannot be set in the repl but only in config.nu with a restart. I'm not sure what all those options are though. I think it would just be good to pack all the history ones in this PR. |
|
@fdncred of course, happy to help! 😄 I'll work on it this weekend, if you don't mind. I'm currently on a business trip until Saturday It's noted though, I'll share an update by Sunday! |
|
@fdncred @ErrorPower2001 just pushed an update extending the lock to the rest of the startup-only history fields ( tested manually and added unit tests for each field. Doc note in |
|
thanks. restarted ci. it pukes inexplicably sometimes |
|
all good, thanks! Let's see |
|
Can you update the user-facing-changes part so that it lists all the keys that are immutable after startup? This part will go in the release notes. |
|
@fdncred how's that? 😄 |
|
Looks great! Thanks for working on this! |
|
@fdncred of course! happy to help 😄 see you in the next one! |
|
looking for to more great work from you! |
Description
Reedline takes ownership of the history backend the moment the REPL finishes calling
setup_history. After that point, mutating$env.config.history.pathfrom the prompt has no effect, reedline keeps writing to wherever it was originally pointed, which is what was reported in #18188Per the discussion in the issue, this PR matches the approach @fdncred suggested: instead of trying to live-reload
reedline's history backend, refuse the assignment from the REPL with a clear error. This is conceptually similar to how
$nu is protected today, but enforced one layer down (at config-apply time) since
$envitself has to remain mutableHow it works:
history_path_locked: boolflag onEngineState(defaults tofalse) gets flipped to true immediately aftersetup_historysucceeds inget_line_editorStack::update_configreads that flag and forwards it to a newConfig::update_from_value_with_options(..., history_path_locked). The originalupdate_from_valueis kept as a thin wrapper for non-REPL callersConfigErrors, soHistoryConfig::updatecan check it when handling the path field. If the lock is set and the new value differs from the current one, it pushes a newConfigError::LockedAfterStartupinstead of applying$env.configrecord doesn't trigger spurious errorsconfig.nu,--config, env-based config, and-care all unaffected because the lock is only flipped aftersetup_historyruns, which happens after config has already been loaded.User-facing changes (Release notes)
Locked history related config values during REPL
The following
$env.config.historyfields are now read-only after the REPL starts, since reedline only reads them once at startup and silently ignored later changes:$env.config.history.path$env.config.history.max_size$env.config.history.file_format$env.config.history.isolationsync_on_enterandignore_space_prefixedremain mutable from the REPL since they are re-read on each prompt.Attempting to change one of the locked fields from the REPL now produces a clear error instead of being silently ignored:
Additional notes
Closes #18188