JoosepAlviste / nvim-ts-context-commentstring

Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.
MIT License
1.14k stars 34 forks source link

Error when nvim-treesitter is added as opt package in packer #15

Closed hiddenruins closed 3 years ago

hiddenruins commented 3 years ago

Hi, thanks for the awesome plugin. Neovim shows an error when nvim-treesitter is made an optional package in packer.nvim.

Here's the error message image

Relevant Packer config image

Treesitter config

vim.cmd[[packadd nvim-treesitter]]

local ts_config = require('nvim-treesitter.configs')

ts_config.setup({
  -- ensure_installed = 'maintained',
  highlight = { enable = true },
  incremental_selection = { enable = true },
  indent = { enable = true },

  context_commentstring = { enable = true },

})
JoosepAlviste commented 3 years ago

Hey @hiddenruins! Unfortunately, I don't know too much about opt packages. Is it correct that the only difference is that you need to packadd mypackage for it to be registered/started?

Would it make sense to make nvim-ts-context-commenstring a dependency of nvim-treesitter?

use {
  'nvim-treesitter/nvim-treesitter',
  opt = true,
  run = ':TSUpdate',
  requires = {'JoosepAlviste/nvim-ts-context-commentstring'},
}

Then, Packer should make this plugin opt as well if I understand correctly (transitive_opt = true, -- Make dependencies of opt plugins also opt by default in Packer default conf) and load it when nvim-treesitter is loaded. Does that work for you?

I'm not sure what could be done in this plugin. Do you have any ideas?

clason commented 3 years ago

I think what you want is wants to make sure nvim-treesitter is loaded before ntcc (your plugin's name is too long :P):

use {
'JoosepAlviste/nvim-ts-context-commentstring', cmd = '...', 
wants = 'nvim-treesitter'
}

This is assuming you have nvim-treesitter already set up separately.

(Presumably you want to lazy-load this plugin (which implies opt, so no need to specify it), otherwise there is no point in putting this -- and nvim-treesitter, which is a hard requirement -- in opt instead of start.)

hiddenruins commented 3 years ago

Thank you @clason @JoosepAlviste . Adding after="nvim-treesitter" in use seemed to do the trick.