You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Merge two TOML documents, merging values from `right` onto `left`////// `merge_depth` sets the nesting depth up to which values are merged instead/// of overridden.////// When a table exists in both `left` and `right`, the merged table consists of/// all keys in `left`'s table unioned with all keys in `right` with the values/// of `right` being merged recursively onto values of `left`.////// `crate::merge_toml_values(a, b, 3)` combines, for example:////// b:/// ```toml/// [[language]]/// name = "toml"/// language-server = { command = "taplo", args = ["lsp", "stdio"] }/// ```/// a:/// ```toml/// [[language]]/// language-server = { command = "/usr/bin/taplo" }/// ```////// into:/// ```toml/// [[language]]/// name = "toml"/// language-server = { command = "/usr/bin/taplo" }/// ```////// thus it overrides the third depth-level of b with values of a if they exist,/// but otherwise merges their valuespubfnmerge_toml_values(left: toml::Value,right: toml::Value,merge_depth:usize) -> toml::Value{use toml::Value;fnget_name(v:&Value) -> Option<&str>{
v.get("name").and_then(Value::as_str)}match(left, right){(Value::Array(mut left_items),Value::Array(right_items)) => {if merge_depth > 0{
left_items.reserve(right_items.len());for rvalue in right_items {let lvalue = get_name(&rvalue).and_then(|rname| {
left_items.iter().position(|v| get_name(v) == Some(rname))}).map(|lpos| left_items.remove(lpos));let mvalue = match lvalue {Some(lvalue) => merge_toml_values(lvalue, rvalue, merge_depth - 1),None => rvalue,};
left_items.push(mvalue);}Value::Array(left_items)}else{Value::Array(right_items)}}(Value::Table(mut left_map),Value::Table(right_map)) => {if merge_depth > 0{for(rname, rvalue)in right_map {match left_map.remove(&rname){Some(lvalue) => {let merged_value = merge_toml_values(lvalue, rvalue, merge_depth - 1);
left_map.insert(rname, merged_value);}None => {
left_map.insert(rname, rvalue);}}}Value::Table(left_map)}else{Value::Table(right_map)}}// Catch everything else we didn't handle, and use the right value(_, value) => value,}}
I have the following questions:
Why the example result is that? I have tested with a program like this:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I found the following merge functions in codebase: https://github.com/helix-editor/helix/blob/master/helix-loader/src/lib.rs#L187
I have the following questions:
Then I used the same a.toml and b.toml as args, got this result:
Does the function doc have a mistake?
And one more question, how does key remapping works. For the following
config.toml
:As space depth is 3, then it should override the default keybindings. But when I use this config, default d &c still works.
Beta Was this translation helpful? Give feedback.
All reactions