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

feature: make it easy to run plugin commands on first install #1911

Open
1 task done
oliverdain opened this issue Feb 2, 2025 · 1 comment
Open
1 task done

feature: make it easy to run plugin commands on first install #1911

oliverdain opened this issue Feb 2, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@oliverdain
Copy link

Did you check the docs?

  • I have read all the lazy.nvim docs

Is your feature request related to a problem? Please describe.

Some plugins require a little bit of extra setup. For example, coc.nvim needs support for specific languages to be installed via :CocInstall and vimspector needs similar config. These are commands that install yet more things but they're installed by the plugin itself so you want to run them only once, after the plugin is installed for the first time. The build config is kind of the right thing except that it runs before the plugin is available so commands like :CocInstall or :VimspectorInstall aren't available yet.

Describe the solution you'd like

I can solve this by doing something like writing a "done" file somewhere as a marker that the post-install has run, then checking for that file in the config function, etc. but it's a bit of work. It'd be really nice if there was a post-install function you can specify in your config that's just like build but it runs after build and after the plugin has loaded.

Describe alternatives you've considered

Writing some kind of marker file whose existence I check in the config function.

Additional context

No response

@oliverdain oliverdain added the enhancement New feature or request label Feb 2, 2025
@oliverdain
Copy link
Author

For what it's worth, I was able to build some that works, it'd just be nicer if it was part of lazy. Specifically I put this in lua/utils.lua:

local mod = {}

function mod.run_once(name, fn)
  local post_install_file = vim.fn.stdpath("data") .. "/post_installs/" .. name

  if vim.fn.filereadable(post_install_file) == 1 then
    return
  end

  fn()

  -- Create directory if it doesn't exist
  vim.fn.mkdir(vim.fn.fnamemodify(post_install_file, ":h"), "p")
  
  -- Create empty file
  local file = io.open(post_install_file, "w")
  file:close()
end

return mod

And then for things like coc.nvim I can have a lazy setup like this:

return {
   {
      "neoclide/coc.nvim",
      branch="release",
      config = function()
         utils = require("utils")
         utils.run_once("coc", function()
            vim.cmd([[:CocInstall coc-json coc-yaml coc-markdownlint coc-explorer coc-sh coc-pyright]])
            vim.cmd([[:CocInstall coc-lists coc-html coc-tsserver coc-go]])
         end)
      end
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant