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

Recent change to core.utils.load_override broke using functions for plugin override #1239

Closed
endoze opened this issue Jun 19, 2022 · 1 comment · Fixed by #1240
Closed

Recent change to core.utils.load_override broke using functions for plugin override #1239

endoze opened this issue Jun 19, 2022 · 1 comment · Fixed by #1240

Comments

@endoze
Copy link
Contributor

endoze commented Jun 19, 2022

Describe the bug
This recent change to core.utils broke using a function to configure plugin override

To Reproduce
Steps to reproduce the behavior:

-- lua/custom/chadrc.lua
local M = {}

M.plugins = {
  override = {
    ["nvim-telescope/telescope.nvim"] = function()
      local actions = require('telescope.actions')

      return {
        defaults = {
          mappings = {
            i = {
              ["<C-j>"] = actions.move_selection_next,
              ["<C-k>"] = actions.move_selection_previous,
            }
          }
        }
      }
    end
  }
}

return M

Expected behavior
This configuration in chadrc.lua should add additional keybinds to telescope in insert mode for navigation.

Desktop (please complete the following information):

  • MacOS
  • iTerm2
  • NVIM v0.7.0

Additional context
The reason this recent change broke is previously the function returned a table, then this table was merged with the default configuration for any particular plugin. By combining all of the logic into one if/elseif/else statement, we lose merging the table returned from the function into the default_table.

The following could be fixed by reverting the code to something similar depending on needs:

-- lua/core/utils.lua

M.load_override = function(default_table, plugin_name)
   local user_table = M.load_config().plugins.override[plugin_name]

    if type(user_table) == "function" then
       user_table = user_table()
    end

    if type(user_table) == "table" then
       default_table = merge_tb("force", default_table, user_table)
    else
       default_table = default_table
   end

   return default_table
end
@siduck
Copy link
Member

siduck commented Jun 19, 2022

@endoze send a PR for it, busy atm

endoze added a commit to endoze/NvChad that referenced this issue Jun 19, 2022
In order to ensure that plugin configuration that is overridden with a
function instead of a table is still merged with the default plugin
configuration, this commit splits up the if/elseif/else statement in
lua/core/utils.lua.

This is necessary as we want to take the resulting table returned from
the override function and merge it with the default_table before setting
up the plugin.

Fixes [this issue](NvChad#1239)
siduck pushed a commit that referenced this issue Jun 19, 2022
In order to ensure that plugin configuration that is overridden with a
function instead of a table is still merged with the default plugin
configuration, this commit splits up the if/elseif/else statement in
lua/core/utils.lua.

This is necessary as we want to take the resulting table returned from
the override function and merge it with the default_table before setting
up the plugin.

Fixes [this issue](#1239)
reflog pushed a commit to reflog/NvChad that referenced this issue Aug 12, 2022
In order to ensure that plugin configuration that is overridden with a
function instead of a table is still merged with the default plugin
configuration, this commit splits up the if/elseif/else statement in
lua/core/utils.lua.

This is necessary as we want to take the resulting table returned from
the override function and merge it with the default_table before setting
up the plugin.

Fixes [this issue](NvChad#1239)
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 a pull request may close this issue.

2 participants