-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add refresh-config and open-config command #1803
Add refresh-config and open-config command #1803
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable, just some cleanup:
helix-term/src/commands/typed.rs
Outdated
@@ -881,6 +879,9 @@ fn setting( | |||
_ => anyhow::bail!("Unknown key `{}`.", args[0]), | |||
} | |||
|
|||
cx.editor | |||
.config_events | |||
.push(tokio_stream::once(ConfigEvent::Update(runtime_config))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the change to put the editor config behind dynamic dispatch, we now have to send updates back up to the application, and let it make the changes there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it took me a few days for another look, was trying to think of a way to avoid that extra channel in the event loop but I think this is the simplest implementation for now.
Just some minor changes
(By the way, feel free to join us on the Matrix channel!) |
Co-authored-by: Blaž Hrastnik <[email protected]>
I've made all requested changes:
And also:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting closer, some thoughts about the keymaps type
helix-term/src/ui/editor.rs
Outdated
.keymaps | ||
.load() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keymaps()
?
helix-term/src/ui/editor.rs
Outdated
.clone() | ||
.get_mut(&mode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear on why this was doing get_mut()
before, you could probably avoid the .clone()
by using .get()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a glance, it looks like it was done because of the unwrap()
after it
edit: The .get
after the unwrap()
is actually &mut self
helix-term/src/application.rs
Outdated
Box::new(Map::new(Arc::clone(&config), |config: &Config| { | ||
&config.editor | ||
})), | ||
); | ||
|
||
let editor_view = Box::new(ui::EditorView::new(std::mem::take(&mut config.keys))); | ||
let keymaps = Box::new(Map::new(Arc::clone(&config), |config: &Config| { | ||
&config.keys | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid boxing by using Map<>
directly? For that to work you will probably need to use a fn
as the last parameter rather than a closure, so that you can name it on the type
This reverts commit 06bad8c.
15d963b
to
c5d7242
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@archseer made changes and actually got it working! I left some comments inline describing some of the changes.
helix-term/src/keymap.rs
Outdated
"a" => goto_prev_parameter, | ||
"o" => goto_prev_comment, | ||
"space" => add_newline_above, | ||
fn default_keymaps() -> HashMap<Mode, Keymap> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(1/2) Had to move the default keymaps into its own function, this was to allow...
helix-term/src/keymap.rs
Outdated
let mut delta = std::mem::take(&mut config.keys); | ||
for (mode, keys) in &mut config.keys.map { | ||
keys.merge(delta.map.remove(mode).unwrap_or_default()) | ||
let mut delta = std::mem::replace(&mut config.keys, default_keymaps()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(2/2) ...this merge to continue working
@@ -12,7 +14,7 @@ pub struct Config { | |||
#[serde(default)] | |||
pub lsp: LspConfig, | |||
#[serde(default)] | |||
pub keys: Keymaps, | |||
pub keys: HashMap<Mode, Keymap>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Keymaps" struct is now divorced from the config. Since the Keymaps
encapsulated view state alongside config, it wasn't quite fitting, and had to be changed for config projection to work accordingly.
edit: Oops just realized the #[serde(default)]
, that needs to be updated to return the proper default HashMap
edit edit: This has now been updated to use the proper default HashMap
pub sticky: Option<KeyTrieNode>, | ||
} | ||
|
||
impl Keymaps { | ||
pub fn new(map: HashMap<Mode, Keymap>) -> Self { | ||
pub fn new(map: Box<dyn DynAccess<HashMap<Mode, Keymap>>>) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept this as Box<dyn DynAccess<T>>
because defining a projection function here would prevent using arc_swap::access::Constant
which is useful for testing.
pub use alt; | ||
pub use ctrl; | ||
pub use key; | ||
pub use keymap; | ||
pub use shift; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is necessary? macro_export
should be enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caught me off guard as well, macro_export
is a bit different from macro_use
:
https://stackoverflow.com/a/31749071/11886888
Without the pub use
, it can't be imported from other files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works great! I'm quite happy with the keymap refactor too, thanks for working on this! 🎉
This PR aims to enable config refreshes while in the editor, and provide an in-editor alternative to
--edit-config
.It adds two new
:commands
:refresh-config
open-config
Basically what happens is:
refresh-command
, it fires off an event up to the applicationcommentary:
I couldn't get dynamic dispatch working using DynAccess. This would presumably save a lot of work when updating the config and propagating changes.Figured it out, but I had to remove#[derive(Debug)]
fromEditor
.This is also my first time using
tokio
andarc_swap
. I actually don't know what I'm doing, I'm being carried heavily by the compiler rnrelated issues: