Skip to content
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

Continue loading the config on error #1814

Closed

Conversation

antoyo
Copy link
Contributor

@antoyo antoyo commented Mar 15, 2022

Fix #1732

There are cases where this improve the error that is shown to the user, but in some cases, the error message gets worse, i.e. it loses its context (key name) and/or position.
I'll try to find a way to improve this, but I'm not sure how, so suggestions are welcomed! (I tried serde-path-to-error, but it does not seem like it works when called from ok_or_default.)

I'm submitting this PR now to gather early reviews.

@antoyo antoyo marked this pull request as draft March 15, 2022 02:30
@antoyo antoyo force-pushed the feature/partial-config-load branch from 2b523af to 605ce52 Compare March 16, 2022 00:58

use crate::keyboard::{KeyCode, KeyModifiers};

static HAD_CONFIG_ERROR: AtomicBool = AtomicBool::new(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing global variable for this will make stuff hard later, doing it as variable passing in rust is more common and less error prone.

@archseer
Copy link
Member

Hmm, rather than partial parsing, how about reloading the config via #1803 but if the config fails to parse we don't swap to the new config?

That won't help if you start the editor with a broken config, but at least it won't break your setup if you're working on your config and "live reloading".

@antoyo
Copy link
Contributor Author

antoyo commented Mar 17, 2022

Hmm, rather than partial parsing, how about reloading the config via #1803 but if the config fails to parse we don't swap to the new config?

That won't help if you start the editor with a broken config, but at least it won't break your setup if you're working on your config and "live reloading".

I see this as a different feature.
As a user of an alternative keyboard layout, I find it very inconvenient if I ever have to edit a file without my remapped "hjkl", so I find this PR very important.

Is there anything you don't like about it?

@antoyo antoyo force-pushed the feature/partial-config-load branch from 605ce52 to cf6c874 Compare April 2, 2022 16:11
@antoyo antoyo force-pushed the feature/partial-config-load branch from cf6c874 to 9319c32 Compare April 2, 2022 16:13
@antoyo
Copy link
Contributor Author

antoyo commented May 3, 2022

@archseer Any update on this?

@the-mikedavis the-mikedavis added the S-needs-discussion Status: Needs discussion or design. label May 18, 2022
if !ignored_keys.is_empty() {
let keys = ignored_keys.into_iter().collect::<Vec<_>>().join(", ");
eprintln!("Ignored keys in config: {}", keys);
set_config_error();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we do it this way with global static variable, later for reloading config, we need to handle this, I wonder if it would be better if we can just propagate the error upwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that serde is it's own thing, so it's not that easy.
Anyway, I'm still waiting for the answer in the discussion as it seems some people are against the idea of this PR.

Maybe the way this is handled will change after we discuss the design.

@kirawi kirawi added the A-helix-term Area: Helix term improvements label Sep 13, 2022
@antoyo
Copy link
Contributor Author

antoyo commented Apr 11, 2023

@archseer @pascalkuthe @the-mikedavis @sudormrfbin: I'd like to get some thoughts on this PR. Is it that you don't want to support this in Helix? If so, I could also do a simpler version where it only loads key mappings in case of a bad config. If that's really unwanted, any alternative you would consider for the use case of having a remapped hjkl when a config file is broken?

@the-mikedavis
Copy link
Member

IMO it's not worth adding to or complicating the config parsing code to cover this case. It seems to me that having a broken config file should be a rare and temporary problem, especially with how error messages have improved (TOML parsing failures with the toml crate update in #5656 and otherwise invalid commands/configs in #3931). Specifically about hjkl and motion: the default config should have mouse support and arrow keys enabled so even if it isn't very comfortable, you should be able to move around in your config file to fix issues.

If you're trying out different configs often you could work around errors by using the -c/--config CLI flag either to point to the experimental config or a safe minimal one you know will work. Or you could use :config-reload when editing the config file which will not apply the config if there are errors.

@antoyo
Copy link
Contributor Author

antoyo commented Apr 13, 2023

Ok, I understand.

Would you also be against something that would attempt loading multiple config files or a fallback config file?

@pascalkuthe
Copy link
Member

pascalkuthe commented Apr 13, 2023

Ok, I understand.

Would you also be against something that would attempt loading multiple config files or a fallback config file?

The fallback config for helix is the default config. Helix prides itself on having a good default config so its a pretty decent fallback. Adding cascading fallbacks for the global config.toml seems a little odd to me since it's unclear in what order they would be loaded and you can still mess up those files as well so it wouldn't really fix the issue. As Mike mentioned you can easily use arrow keys on international keyboards that don't have hjkl at all. Helix config files are intended to be very simple so if you run into problems just comment out the offending lines with c-c and :config-reload. You can also just start helix with a working config and edit the config while testing with :config-reload while editing the config file until the new config works.

The markdown config is a stopgap until a scripting language (scheme) based config is implemented in the future. I think we want to keep the config-related code as simple as possible until then and with a script partial config evaluation becomes basically impossible anyway.

@antoyo
Copy link
Contributor Author

antoyo commented Apr 14, 2023

Ok, thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-needs-discussion Status: Needs discussion or design.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Partially load the config even when there is an error
6 participants