windwp/nvim-ts-autotag

Doesn't work even though installed + setup + autotag enabled

Closed this issue · 5 comments

Sorry to bother with a niche problem but I could never get this plugin working after hours of researching.
I'm using lazy.nvim + nvim 0.9.5 and AFAIK to enable this plugin I'll have to:

  1. Enable autotag in treesitter
local options = {
  ensure_installed = { "lua", "vim", "vimdoc" },

  highlight = {
    enable = true,
    use_languagetree = true,
  },

  autotag = {
    enable = true,
  },

  indent = { enable = true },
}
return options
  1. Install through lazy.nvim and setup
  {
    "windwp/nvim-ts-autotag",
    lazy = false,
    dependencies = "nvim-treesitter/nvim-treesitter",
    config = function()
      require 'nvim-ts-autotag'.setup()
    end,
  },

Am I missing anything? You can see my config file here
I'm mainly working on .jsx files but html files don't work as well.

Alright, this has become enough of a problem that I need to add documentation around this 😅.

So for your case, try adding html and other languages you want autotag support in to your ensure_installed section for nvim-treesitter. You can see how we do this for our test suite:

require("nvim-treesitter.configs").setup({
sync_install = true,
ensure_installed = {
"html",
"javascript",
"typescript",
"svelte",
"vue",
"tsx",
"php",
"glimmer",
"rescript",
"embedded_template",
},
})

Alternatively, you can set auto_install = true for nvim-treesitter which will install the parsers as needed. Autotag won't/can't work without the associated treesitter parser installed for a given language.

See #64 (comment) for a response to a previous issue of this sort.

I'll keep this issue open and create a PR to update documentation and close it from there.

omg that response was quick 💯
Setting auto_install = true shows this error:

Nvim Treesitter Setup is deprecated, use `require('nvim-ts-autotag').setup()` instead.                                                            
This feature will be removed in nvim-ts-autotag version 1.0.0  

but setting ensure_installed works. Thanks!

Setting auto_install = true shows this error:

Remove these lines from your config.

We no longer use nvim-treesitter modules.

Use the plain require("nvim-ts-autotag").setup method.

That was it!!! 🎉 🎉

uwla commented

I had to add

   config = function()
      require 'nvim-ts-autotag'.setup()
    end,

to the lazy.nvim config, otherwise this plugin would not work.

Adding opts = {} also works. Without adding config function or opts it does not work.

Would be good if this is added to the documentation