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

Clear definition between install and update hooks #1050

Open
itmecho opened this issue Sep 5, 2022 · 4 comments
Open

Clear definition between install and update hooks #1050

itmecho opened this issue Sep 5, 2022 · 4 comments

Comments

@itmecho
Copy link

itmecho commented Sep 5, 2022

Describe the feature

I've got this minimal init.lua which installs packer and then nvim-treesitter. I've got run = ':TSUpdate' set but I get an error that TSUpdate is not an editor command. I'm not sure if this is a bug or if it's only supposed to be run on update rather than install? If it isn't a bug, how can I tell in a run function whether it's being run as part of an install or update hook?

Demo

Use the init.lua below, remove any packer files with rm -Rf ~/.local/share/nvim/site/pack/packer ~/.config/nvim/plugin/packer_compiled.lua, then open neovim

init.lua
local ensure_packer = function()
  local fn = vim.fn
  local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
  if fn.empty(fn.glob(install_path)) > 0 then
    fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
    vim.cmd([[packadd packer.nvim]])
    return true
  end
  return false
end

local packer_bootstrap = ensure_packer()

return require("packer").startup(function(use)
  use("wbthomason/packer.nvim")

  use({
    "nvim-treesitter/nvim-treesitter",
    run = ":TSUpdate",
    config = function()
      require("nvim-treesitter.configs").setup({
        hightlight = {
          enabled = true,
        },
      })
    end,
  })

  -- Automatically set up your configuration after cloning packer.nvim
  -- Put this at the end after all plugins
  if packer_bootstrap then
    require("packer").sync()
  end
end)
@wbthomason
Copy link
Owner

Right now, packer doesn't differentiate between install and update hooks - run executes for both events. If you'd like finer-grained control, this would be pretty easy to add, and I'm happy to help guide a PR.

@itmecho
Copy link
Author

itmecho commented Sep 6, 2022

Thanks for the reply! For the moment, I've got around the issue by changing run to a function that only runs the command if it exists:

  ...
  run = function()
    if vim.fn.exists(':TSUpdate') == 2 then
      vim.cmd(':TSUpdate')
    end
  end,
  ...

@itmecho
Copy link
Author

itmecho commented Sep 6, 2022

I've done a small PR that implements a solution for this, let me know if it's what you had in mind!

@masaeedu
Copy link

masaeedu commented Dec 7, 2022

The odd thing is that:

use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }

is actually given as an example in the README, but copying this example exactly into one's packer config leads to the error you are observing.

Forgetting about the specifics of treesitter for the moment, if a plugin requires that you run some setup code once, immediately after installation, and this setup code depends on the plugin being loaded, is run the wrong place to put it? Should there be some other mechanism for doing so?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants