Repository navigation
fix(config): reject a keybindings or menus list with an entry it can't read - #19438
kronberger-droid merged 6 commits into
Conversation
Since assigning `$env.config.keybindings` or `menus` replaces the list, there was no way back to the defaults in a running shell short of spawning `nu -n`. `(config default).keybindings` is the list nushell ships, so assigning it restores the defaults, and a config that starts with that line before its `++=` entries builds the same list each time it is sourced instead of growing it. It holds the entries nushell adds, such as the Tab completion menu, and not reedline's own base bindings, which `keybindings default` lists.
…t read
A keybinding or menu with a modifier, keycode, mode or layout that
can't be read used to be accepted by the assignment and then fail every
prompt, thus a fixed copy that a reload appended later did not replace
it and Tab stayed broken until a restart. Assigning such a list is now
rejected as a whole and the previous list stays, like any config value
that can't be read.
The grammar moved from `nu-cli` to `nu-protocol`, which has no
`crossterm`, and `nu-cli` maps it onto reedline's types, so both read an
entry the same way. An `event` needs reedline's types and is still read
when the prompt is built.
A menu without a `layout`, such as `type: {}`, is rejected on assignment
now. It only failed at the prompt before.
|
Hey, just a bot checking in! You edited files related to the configuration. |
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
Rejecting a bad layout on assignment does what the PR says: a reload with the fixed copy gets Tab back, where main stays stuck. config default matches the $env.config of a fresh nu -n with no differences. Left to do: the new command breaks a nu-lsp test, and other menu fields still get stuck until a restart.
Findings: 0
Open (6)
config defaultbreaks a nu-lsp completion test Other menu fields still break Tab until a restart Doc says the rest of the config applies, but config.nu stops Rejection error names no setting and stops at the first entry Keycode error asks for "a crossterm KeyCode"the_default_keybindings_buildrepeats an existing test
Notes from my clanker, checked on 5bd32dd. Built the branch and ran cargo test -p nu-protocol --lib -- config (50 passed), -p nu-cli --lib -- reedline_config (36 passed), -p nu-command --lib -- config_default (1 passed), --test tests -- repl::test_config (59 passed) and -p nu-lsp --lib (112 passed, 1 failed). Clippy with CI's flags on nu-protocol, nu-cli and nu-command is clean, and so are fmt and typos. Each case ran on the branch binary and on main (c27defb), the prompt cases in a real REPL through a pty. I didn't run the rest of the workspace tests or anything on Linux or Windows.
A menu with an `input_mode`, `only_buffer_difference` or `output_mode` that can't be read was still accepted and only failed when the prompt was built, thus a fixed copy appended on reload did not replace it. The names moved to `key_spec.rs` next to `MenuLayout` and `nu-cli` maps them onto reedline's types. The fields that belong to one layout, such as `columns`, are still read at the prompt. From review: the keycode error lists the valid names instead of naming crossterm, `doc_config.nu` says a rejected assignment stops `config.nu` at that line, the `nu-lsp` completion test expects `config default` as the second `config ` entry, and tests that repeated others are dropped.
|
Fine to land from my side. Included most of the review points. @fdncred |
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
All 6 threads are resolved on 1e06717. Five are fixed, and the error-reporting one moves to the follow-up we agreed on. A bad input_mode, output_mode or only_buffer_difference is now rejected on assignment, and a reload with the fixed copy brings Tab back. Two new lows are left, both about wording.
Findings: 0
Open (2)
Notes from my clanker, checked on 1e06717. Built the branch and ran probe.sh, recheck.sh, menu_fields.sh and new recheck2.sh and recheck3.sh against it and main (c27defb) on macOS, including Tab at a live REPL prompt for each input and output mode. cargo test -p nu-lsp --lib gives 113 passed. With the keycode suggestion applied locally, cargo test -p nu-protocol --lib key_spec gives 15 passed; I reverted it after. CI is green on this head, so I didn't run clippy or the full test suite myself, and Linux and Windows rest on CI.
Co-authored-by: Darren Schroeder <[email protected]>
Co-authored-by: Darren Schroeder <[email protected]>



Description
Follow-up to #19418.
A keybinding or menu with a modifier, keycode, mode, layout, input mode or output mode that can't be read used to be accepted and then failed at every prompt.
A fixed copy that a reload appended did not replace it, since
++=only adds, thus Tab stayed broken until a restart.Assigning such a list is now rejected as a whole and the previous list stays, like for any other config value that can't be read.
The grammar moved from
nu-clitonu-protocol(config/key_spec.rs) for that, sincenu-protocolhas nocrossterm, andnu-clionly maps it onto reedline's types.This also adds
config default, which returns the default config as a record.A config that gets sourced again needs it to start from the defaults, and it replaces the
^$nu.current-exe -n -c ...hack indoc_config.nu.User-facing changes (Release notes)
Invalid keybindings and menus are rejected on assignment
Assigning
$env.config.keybindingsor$env.config.menuswith an entry that can't be read is now an error, and the old list is kept.That covers the
modifier,keycodeandmodeof a keybinding, and thelayout,input_mode(oronly_buffer_difference) andoutput_modeof a menu.Before, it was accepted and failed on every prompt.
In
config.nu, the lines after the rejected assignment don't run.A menu without a
layout, such astype: {}, is rejected on assignment now.New command
config default, which returns the default config as a record.A config that is sourced again adds its
++=entries each time, and=drops the defaults, so start from the defaults to keep the list stable:Additional notes
Unit tests in
nu-protocolcover the grammar and the rejected lists, and repl tests cover the reload scenario.Out of scope:
eventand the fields of one menu layout (columns,page_size,description_position) are still read when the prompt is built.nu-tuistill reads keybinding strings with its own looser rules (normalize_binding).