nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.72k stars 896 forks source link

Incorrect installation instructions for lazy.nvim #7276

Open skiss9 opened 2 days ago

skiss9 commented 2 days ago

In the Installation section, the instructions for lazy.nvim mention adding the following to init.lua:

require("lazy").setup({{"nvim-treesitter/nvim-treesitter", build = ":TSUpdate"}})

But lazy.nvim (latest version v11.14.1) doesn't support this format and throws an error:

Re-sourcing your config is not supported by lazy.nvim

Instead, what works is to add a file (e.g. treesitter.lua) to the /lua/plugins directory, with the following format:

return {
  {
    "nvim-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    config = function()
      require("nvim-treesitter.configs").setup({
        highlight = {
          enable = true,
          additional_vim_regex_highlighting = false,
        },
      })
    end,
  },
  { "nvim-treesitter/nvim-treesitter-textobjects" },
}

Instructions for adding plugins in lazy.nvim are here: https://lazy.folke.io/installation (bottom of the page) https://lazy.folke.io/spec https://lazy.folke.io/spec/examples

skiss9 commented 2 days ago

Adding a table item to the existing lazy setup call in config/lazy.lua after the { import = "plugins" } also works, but is not the recommended format. Plugins are meant to be added to the /plugins dir.

-- config/lazy.lua
require("lazy").setup({
  spec = {
    -- import your plugins
    { import = "plugins" },
    {
      "nvim-treesitter/nvim-treesitter",
      build = ":TSUpdate",
      config = function()
        local configs = require("nvim-treesitter.configs")
        configs.setup({
          ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "elixir", "heex", "javascript", "html" },
          sync_install = false,
          highlight = { enable = true },
          indent = { enable = true },
        })
      end,
    },
  },
  install = { colorscheme = { "nord" } },
})