Skip to content

Fix merge bug in Config::load #13332

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thomie
Copy link

@thomie thomie commented Apr 11, 2025

Currently Config::load merges editor configs with merge_toml_values(global, local, 3).

Besides the puzzling use of the magic number 3, this is a bug, because it concatenates arrays from the global config file with those from the local config file.

For example editor.shell=["bash", "-c"] and editor.shell=["fish", "-c"] would become editor.shell=["bash", "-c", "fish", "-c"].

This commit adds a new function merge_toml_values_with_strategy and changes Config::load to call:

  merge_toml_values_with_strategy(
    global,
    local,
    &MergeStrategy {
      array: MergeMode::Never,
      table: MergeMode::Always,
    },
  )

For backward compatability, the original function merge_toml_values calls:

  merge_toml_values_with_strategy(
    left,
    right,
    &MergeStrategy {
      array: MergeMode::MaxDepth(max_merge_depth),
      table: MergeMode::MaxDepth(max_merge_depth),
    },
  )

, so there should be no change in the way themes and languages.toml are merged.

Also update doc string and add tests.

Currently `Config::load` merges editor configs with
`merge_toml_values(global, local, 3)`

Besides the puzzling use of the magic number `3`, this is a bug,
because it concatenates arrays from the global config file with
those from the local config file.

For example `editor.shell=["bash", "-c"]` and
`editor.shell=["fish", "-c"]` would become
`editor.shell=["bash", "-c", "fish", "-c"]`.

This commit adds a new function `merge_toml_values_with_strategy` and
changes `Config::load` to call:
```
  merge_toml_values_with_strategy(
    global,
    local,
    &MergeStrategy {
      array: MergeMode::Never,
      table: MergeMode::Always,
    },
  )
```

For backward compatability, the original function `merge_toml_values`
calls:
```
  merge_toml_values_with_strategy(
    left,
    right,
    &MergeStrategy {
      array: MergeMode::MaxDepth(max_merge_depth),
      table: MergeMode::MaxDepth(max_merge_depth),
    },
  )
```
, so there should be no change in the way themes and languages.toml
are merged.

Also update doc string and add tests.
thomie added a commit to thomie/helix that referenced this pull request Apr 11, 2025
Split `Config::load` into 2 smaller functions:
 1. A function to load a `ConfigRaw` from a path
 2. A function to apply a `ConfigRaw` to a `Config`

The resulting code is both shorter, more readable, and more extensible
(e.g., it can support more than two config files).

This refactor revealed the bug described in helix-editor#13332.
thomie added a commit to thomie/helix that referenced this pull request Apr 11, 2025
Split `Config::load` into 2 smaller functions:
 1. A function to load a `ConfigRaw` from a path
 2. A function to apply a `ConfigRaw` to a `Config`

The resulting code is both shorter, more readable, and more extensible
(e.g., it can support more than two config files).

This refactor revealed the bug described in helix-editor#13332.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant