Mercurial > forks > helix
changeset 6700:1e2d84240390
Fix out of date comments on merge_toml_values (#13253)
merge_toplevel_arrays is no longer a parameter for this method, and the
example fits better in a doc comment.
author | Austin L Wolfgram <austinwolfy@gmail.com> |
---|---|
date | Sun, 06 Apr 2025 20:00:18 +0200 |
parents | 6e635a5f3112 |
children | c669fff516c7 |
files | helix-loader/src/config.rs helix-loader/src/lib.rs |
diffstat | 2 files changed, 29 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/helix-loader/src/config.rs Sun Apr 06 19:23:34 2025 +0200 +++ b/helix-loader/src/config.rs Sun Apr 06 20:00:18 2025 +0200 @@ -23,22 +23,6 @@ .collect::<Result<Vec<_>, _>>()? .into_iter() .fold(default_lang_config(), |a, b| { - // combines for example - // b: - // [[language]] - // name = "toml" - // language-server = { command = "taplo", args = ["lsp", "stdio"] } - // - // a: - // [[language]] - // language-server = { command = "/usr/bin/taplo" } - // - // into: - // [[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 values crate::merge_toml_values(a, b, 3) });
--- a/helix-loader/src/lib.rs Sun Apr 06 19:23:34 2025 +0200 +++ b/helix-loader/src/lib.rs Sun Apr 06 20:00:18 2025 +0200 @@ -154,17 +154,36 @@ /// Merge two TOML documents, merging values from `right` onto `left` /// -/// When an array exists in both `left` and `right`, `right`'s array is -/// used. 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`. +/// `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: /// -/// `merge_toplevel_arrays` controls whether a top-level array in the TOML -/// document is merged instead of overridden. This is useful for TOML -/// documents that use a top-level array of values like the `languages.toml`, -/// where one usually wants to override or add to the array instead of -/// replacing it altogether. +/// 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 values pub fn merge_toml_values(left: toml::Value, right: toml::Value, merge_depth: usize) -> toml::Value { use toml::Value; @@ -174,11 +193,6 @@ match (left, right) { (Value::Array(mut left_items), Value::Array(right_items)) => { - // The top-level arrays should be merged but nested arrays should - // act as overrides. For the `languages.toml` config, this means - // that you can specify a sub-set of languages in an overriding - // `languages.toml` but that nested arrays like Language Server - // arguments are replaced instead of merged. if merge_depth > 0 { left_items.reserve(right_items.len()); for rvalue in right_items {