cmp-nvim-lsp icon indicating copy to clipboard operation
cmp-nvim-lsp copied to clipboard

Move from after/plugin to plugin and follow plugin best pratices

Open tvercruyssen opened this issue 2 years ago • 10 comments

Resolves #60

tvercruyssen avatar Sep 02 '23 10:09 tvercruyssen

Don't think adding global variables is the desired solution.

gegoune avatar Sep 02 '23 11:09 gegoune

Don't think adding global variables is the desired solution.

I disagree, this is regarded as the best practice to allow users to disable your plugin from loading, and or for it not to redo it's work (which might e.g create duplicate autocmd). Source with respect to regarded: examples of a few popular plugins (by vim-awesome):

tvercruyssen avatar Sep 02 '23 12:09 tvercruyssen

It should be achievable without global variables though.

gegoune avatar Sep 02 '23 16:09 gegoune

In lua, we can use package.loaded[mod]

- if vim.g.loaded_cmp_nvim_lsp then
+ if package.loaded['cmp_nvim_lsp'] then
    return
  end
- vim.g.loaded_cmp_nvim_lsp = true

  require("cmp_nvim_lsp").setup()

fitrh avatar Oct 04 '23 08:10 fitrh

I think global load_... variables for plugin is fine, as it's a very common convention.

wookayin avatar Nov 16 '23 20:11 wookayin

Common from vim as there was no other way. @fitrh solution is way cleaner.

gegoune avatar Nov 16 '23 21:11 gegoune

I prefer @fitrh's method. Could you please change it like that?

hrsh7th avatar Dec 10 '23 10:12 hrsh7th

While I understand the point as to why you would prefer the latter method in a Lua package. I might offer one last disadvantage, that is that we're not compatible with the way you can disable builtin plugins in Neovim using:

local disabled_builtin_plugins = {
    "netrw",
   -- ...
}

for _, plugin in ipairs(disabled_builtin_plugins) do
    vim.g["loaded_" .. plugin] = true
end

If regardless of that we still want this change I'll make the adjustment.

tvercruyssen avatar Jan 22 '24 21:01 tvercruyssen

I prefer @fitrh's method. Could you please change it like that?

Done

tvercruyssen avatar Jun 28 '24 19:06 tvercruyssen