nvim-neorocks / rocks-config.nvim

Allow rocks.nvim to help configure your plugins.
GNU General Public License v3.0
55 stars 2 forks source link

rocks-config loads configs twice #29

Closed tarcisioe closed 4 months ago

tarcisioe commented 4 months ago

Hey there! Really liking rocks.nvim and its extensions, thanks!

I noticed my config for nvim-lspconfig was being loaded twice because I have a custom set function that detects if a global keymap is being set twice. By inspecting rocks-config.nvim code I noticed that right here plugin_heuristics contained duplicate possibilities:

{ "rocks-git-nvim", "rocks-git", "rocks-git-nvim", "rocks-git-nvim-nvim" }
{ "tree-sitter-lua", "tree-sitter-lua", "tree-sitter-lua", "tree-sitter-lua-nvim" }
{ "tree-sitter-markdown", "tree-sitter-markdown", "tree-sitter-markdown", "tree-sitter-markdown-nvim" }
{ "coq_nvim", "coq_nvim", "coq_nvim", "coq_nvim-nvim" }
{ "emmet-vim", "emmet", "emmet-vim", "emmet-vim-nvim" }
{ "pytest-vim", "pytest", "pytest-vim", "pytest-vim-nvim" }
{ "vim-indent-object", "indent-object", "vim-indent-object", "vim-indent-object-nvim" }
{ "vim-over", "over", "vim-over", "vim-over-nvim" }
{ "vim-repeat", "repeat", "vim-repeat", "vim-repeat-nvim" }
{ "vim-surround", "surround", "vim-surround", "vim-surround-nvim" }
{ "zenburn-nvim", "zenburn", "zenburn-nvim", "zenburn-nvim-nvim" }
{ "lualine-nvim", "lualine", "lualine-nvim", "lualine-nvim-nvim" }
{ "none-ls-nvim", "none-ls", "none-ls-nvim", "none-ls-nvim-nvim" }
{ "nvim-lspconfig", "lspconfig", "nvim-lspconfig", "nvim-lspconfig-nvim" }
{ "nvim-treesitter", "treesitter", "nvim-treesitter", "nvim-treesitter-nvim" }
{ "plenary-nvim", "plenary", "plenary-nvim", "plenary-nvim-nvim" }
{ "rocks-config-nvim", "rocks-config", "rocks-config-nvim", "rocks-config-nvim-nvim" }
{ "rocks-nvim", "rocks", "rocks-nvim", "rocks-nvim-nvim" }

Notice that for every plugin the first and the third possibilities are the same. I'm not absolutely sure if that's intended (although I'm not sure if this makes much sense). But because of this the following for loop loads my configs twice, because that's the matching name I used for my files.

My "fix" here was adding a break to the for loop:

        for _, possible_match in ipairs(plugin_heuristics) do
            local mod_name = table.concat({ config.config.plugins_dir, possible_match }, ".")
            local ok = try_load_config(mod_name)
            found_custom_configuration = found_custom_configuration or ok
            if found_custom_configuration then
                break
            end
        end

And I guess I could open a Pull Request with that if that solution is reasonable. I think the plugin_heuristics table should be deduplicated, but even then, I believe once a plugin config is loaded the plugin should be considered configured and the search should stop anyway ¯_(ツ)_/.

I'll get a PR ready here if my solution is reasonable.