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

Don't work. #64

Closed
seriiserii825 opened this issue May 27, 2022 · 39 comments
Closed

Don't work. #64

seriiserii825 opened this issue May 27, 2022 · 39 comments

Comments

@seriiserii825
Copy link

Install plugins in neovim + lua.

  use "nvim-treesitter/nvim-treesitter"
  use "windwp/nvim-ts-autotag"

Create a file tree-sitter.lua and include in init.lua

require 'nvim-treesitter.configs'.setup {
  -- A list of parser names, or "all"
  ensure_installed = { "lua" },
  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,
  
  autotag = {
    enable = true,
    filetypes = { "html", "xml", "php", "vue" },
  },

  highlight = {
    -- `false` will disable the whole extension
    enable = true,

    -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
    -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
    -- the name of the parser)
    -- list of language that will be disabled
    disable = { "c", "rust" },

    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
}

In html file i can't rename html tag.

@tomspeak
Copy link

not working for me either, no errors, using the default set up. I am on a new version of NeoVim though.

neovim: NVIM v0.8.0-dev+406-g502f03fc0
windwp/nvim-ts-autotag: latest master

@tiagaoalb
Copy link

Same here.

@YoungeonLee
Copy link

Have you ran :TSInstall html?

@danilobjr
Copy link

Have you ran :TSInstall html?

@YoungeonLee I have, but still the same.

I'm trying to run on LunarVim.

$ lvim -v
NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@HMBRW-A-001-M1-004.local

@YoungeonLee
Copy link

@danilobjr Try adding

lvim.builtin.treesitter.autotag.enable = true 

to your config. If that doesn't work, try running :TSEnable autotag.

@danilobjr
Copy link

lvim.builtin.treesitter.autotag.enable = true

@YoungeonLee This works like a charm now. Thank you so much! 🎉

@kristupas-g
Copy link

kristupas-g commented Aug 6, 2022

require("nvim-treesitter.configs").setup({ ensure_installed = { "c", "c_sharp", "css", "go", "graphql", "html", "json", "http", "javascript", "lua", "markdown", "python", "rust", "typescript", "yaml", "bash", "comment", "java", }, sync_install = false, highlight = { enable = true, additional_vim_regex_highlighting = true, }, indent = { enable = true, disable = { "yaml" } }, rainbow = { enable = true, extended_mode = true, max_file_lines = nil, }, context_commentstring = { enable = true, enable_autocmd = false, }, autotag = { enable = true, }, })
This is my setup and it only works in html files, no jsx or tsx files

PS
Seems like adding tsx parser solved the problem for me

@vricop
Copy link

vricop commented Oct 5, 2022

@danilobjr Try adding

lvim.builtin.treesitter.autotag.enable = true 

to your config. If that doesn't work, try running :TSEnable autotag.

That worked, thanks man!

@Gnarus-G
Copy link

I'm having the same problem. It just doesn't work. I tried in html, and tsx. Neither autotagging nor autorenaming
Here is the setup I tried with.
image
Here is my treesitter setup.
image

I'm on nvim 0.8

@zRich
Copy link

zRich commented Nov 15, 2022

Finally, I figured out how to make it work.

image

Content of plugins.configs.treesitter

local options = {
  auto_install = true,
  ensure_installed = {
    "lua",
    "vim",
    "go",
    "toml",
    "css",
    "tsx",
    "css",
    "html",
    "lua"
  },
  highlight = {
    enable = true,
    use_languagetree = true,
  },
  autotag = {
    enable = true,
    filetypes = {
      'html', 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'svelte', 'vue', 'tsx', 'jsx', 'rescript',
      'css', 'lua', 'xml', 'php', 'markdown'
    },
  },
  indent = { enable = true },
}

require('nvim-treesitter.configs').setup(options)

I enabled auto install lang parsers.

I am on neovim 0.8

@stale
Copy link

stale bot commented Jan 14, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jan 14, 2023
@angelollima
Copy link

@danilobjr Try adding

lvim.builtin.treesitter.autotag.enable = true 

to your config. If that doesn't work, try running :TSEnable autotag.

works well with html, how could i do it with jsx?

@stale stale bot removed the wontfix This will not be worked on label Jan 17, 2023
@angelollima
Copy link

@danilobjr Try adding

lvim.builtin.treesitter.autotag.enable = true 

to your config. If that doesn't work, try running :TSEnable autotag.

Where do i have to put this line?

@peskovdev
Copy link

peskovdev commented Feb 18, 2023

Same for me. nvim-ts-autotag closes tags, but doesn't rename.

Update! It works!

But r or x mappings to change/delete one character don't trigger plugin!

@ghost
Copy link

ghost commented Mar 2, 2023

Yeah, this isn't working for me either. I followed the instructions exactly as they are in the readme and nothing happens.

@gwapocom
Copy link

gwapocom commented Mar 3, 2023

same here even tried this but nothing for PHP and TS files

Finally, I figured out how to make it work.

image

Content of plugins.configs.treesitter

local options = {
  auto_install = true,
  ensure_installed = {
    "lua",
    "vim",
    "go",
    "toml",
    "css",
    "tsx",
    "css",
    "html",
    "lua"
  },
  highlight = {
    enable = true,
    use_languagetree = true,
  },
  autotag = {
    enable = true,
    filetypes = {
      'html', 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'svelte', 'vue', 'tsx', 'jsx', 'rescript',
      'css', 'lua', 'xml', 'php', 'markdown'
    },
  },
  indent = { enable = true },
}

require('nvim-treesitter.configs').setup(options)

I enabled auto install lang parsers.

I am on neovim 0.8

@nmsobri
Copy link

nmsobri commented Mar 14, 2023

it's sad, this plugin doesn't documented properly on how to install.. i need to find open ticket just to figure out on how to install it properly

@hvquy001
Copy link

Many people, including myself, initially believe that simply configuring nvim-treesitter with the following code will make it work:

  autotag = {
    enable = true
  }

However, to ensure it functions correctly, you also need to install the package using your Package Manager.

In my case, using NvChad and Lazy, the configuration should be:

{
    "nvim-treesitter/nvim-treesitter",
    opts = overrides.treesitter,
  },
  {
    "windwp/nvim-ts-autotag",
    dependencies = "nvim-treesitter/nvim-treesitter",
    config = function ()
      require('nvim-ts-autotag').setup({
        -- your config
      })
    end,
    lazy = true,
    event = "VeryLazy"
  },

It would be helpful to include this information in the documentation.

@thenewvu
Copy link

For me, I have to disable alvan/vim-closetag plugin to make this plug-in work.

@acdesouza
Copy link

acdesouza commented Apr 24, 2023

I'm using lazy.nvim.
I could make it work on HTML files. But, it didn't work on ERB(Ruby template language)

I did a :TSEnable autotag on a erb file and it wasn't able to end a p tag.

Screen.Recording.2023-04-24.at.09.53.43.mov
Screen.Recording.2023-04-24.at.09.55.30.mov

Note the different attempts by using embedded_template, erb, and eruby.

  {
    'nvim-treesitter/nvim-treesitter',
    build = function()
      require("nvim-treesitter.install").update({ with_sync = true })
    end,
    dependencies = {
      "RRethy/nvim-treesitter-endwise", -- Needed to prevent treesitter ident issue with Ruby: https://github.com/tree-sitter/tree-sitter-ruby/issues/230#issuecomment-1312403487
      'windwp/nvim-ts-autotag'
    },
    config = function()
      require'nvim-treesitter.configs'.setup {
        ensure_installed = { "ruby", "html", "embedded_template", "css", "scss", "javascript" },
        highlight = {
          disable = { "lua" },
          enable  = { "ruby", "html", "embedded_template", "eruby", "css", "scss", "javascript" }
        },
        additional_vim_regex_highlighting = false,
        endwise = {
          enable = true,
        },
        autotag = {
          enable = true,
          filetypes = { "html" , "xml", "eruby", "erb", "embedded_template" },
        }
      }
    end
  },

UPDATE:
After reading this #85 (comment), applying the suggested patch, and changed to call the setup on nvim-ts-autotag, I got the same behavior.

@acdesouza
Copy link

I'm using lazy.nvim. I could make it work on HTML files. But, it didn't work on ERB(Ruby template language)...

If my tests are correct, this PR #104 fixed the issue for eruby files.

I need to config it separately, this way:

  {
    'windwp/nvim-ts-autotag',
    config = function()
      require('nvim-ts-autotag').setup({
        filetypes = { "html" , "xml", "eruby", "embedded_template" }
      })
    end
  }
Screen.Recording.2023-04-29.at.22.30.19.mov

@tienpvse1
Copy link

Turn out, it missing the tsx module for treesitting for my case, make sure you have it installed by

:TSInstall tsx

@kleinepls
Copy link

The plugin only seems to work when exiting insert mode with esc, and not with ctrl-c

@K4R7IK
Copy link

K4R7IK commented Jul 9, 2023

Many people, including myself, initially believe that simply configuring nvim-treesitter with the following code will make it work:

  autotag = {
    enable = true
  }

However, to ensure it functions correctly, you also need to install the package using your Package Manager.

In my case, using NvChad and Lazy, the configuration should be:

{
    "nvim-treesitter/nvim-treesitter",
    opts = overrides.treesitter,
  },
  {
    "windwp/nvim-ts-autotag",
    dependencies = "nvim-treesitter/nvim-treesitter",
    config = function ()
      require('nvim-ts-autotag').setup({
        -- your config
      })
    end,
    lazy = true,
    event = "VeryLazy"
  },

It would be helpful to include this information in the documentation.

@hvquy001 if you would not mind, I would like to update README using your information. This will help in proper installation. I myself struggle with the installation process until found your comment. Thanks

@exosyphon
Copy link

Many people, including myself, initially believe that simply configuring nvim-treesitter with the following code will make it work:

  autotag = {
    enable = true
  }

However, to ensure it functions correctly, you also need to install the package using your Package Manager.
In my case, using NvChad and Lazy, the configuration should be:

{
    "nvim-treesitter/nvim-treesitter",
    opts = overrides.treesitter,
  },
  {
    "windwp/nvim-ts-autotag",
    dependencies = "nvim-treesitter/nvim-treesitter",
    config = function ()
      require('nvim-ts-autotag').setup({
        -- your config
      })
    end,
    lazy = true,
    event = "VeryLazy"
  },

It would be helpful to include this information in the documentation.

@hvquy001 if you would not mind, I would like to update README using your information. This will help in proper installation. I myself struggle with the installation process until found your comment. Thanks

Thank you for posting this. I got this to work immediately with lazy.nvim using this config.

@idelice
Copy link

idelice commented Sep 3, 2023

This worked for me as well

Something this crucial should be documented imo...

@dongalor
Copy link

dongalor commented Sep 26, 2023

Hey there!

I have autotag = { enable = true, } in my treesitter config, but it works only after I execute :TSEnable autotag after starting nvim.

How to enable it automatically?

Thanks!

Update:

I discovered that it enables automatically when I open a file from NerdTree after starting nvim in a directory, rather than directly opening a path from the command line. It's possible to live with that, but I'd love to know whether it's possible to fix. :)

@griffinbaker12
Copy link

This config worked for me by throwing it in my packer.lua:
use { 'windwp/nvim-ts-autotag', config = function() require('nvim-ts-autotag').setup({ filetypes = { "html", "javascript", "javascriptreact", "typescriptreact"} })

@pedroferreira37
Copy link

pedroferreira37 commented Dec 24, 2023

I'm facing the autotag issue in html, but it only happens when script tag is in the buffer, weird behavior.

@guoliang
Copy link

For me auto tag doesn't work in .html files, but it works in .ts files. haven't found a solution.

I have tried the proposed solution which worked for some here, but it doesn't work in my case.

@dexterspg
Copy link

dexterspg commented Feb 28, 2024

I am using lazy vim
It does not work for xml files for me.

ensure_installed = { "c", "query", "vimdoc", "vim", "lua", "xml", "javascript", "typescript", "css", "java", "html", "python", "vue" }, autotag = { enable = true, enable_rename = true, enable_close = true, enable_close_on_slash = true, filetypes = { "html", "xml", "vue", "typescript" }, },

@tolu-c
Copy link

tolu-c commented Mar 12, 2024

Mine doesn't work yet,

custom/plugins.lua

...
{
    "windwp/nvim-ts-autotag",
    ft = {
      "javascript", "typescript", 'javascriptreact', 'typescriptreact'
    },
    config = function()
      require('nvim-ts-autotag').setup()
    end,
    lazy = true,
    event = "VeryLazy"
  },
  {
    "nvim-treesitter/nvim-treesitter",
    opts = function()
      opts = require "plugins.configs.treesitter"
      opts.ensure_installed = {
        "lua", "javascript", "typescript", "jsx", "tsx", "css", "ts", "js"
      }
      return opts
    end
  }
...

plugins/configs/treesitter.lua

local options = {
  ensure_installed = { "lua", "vim", "vimdoc" },

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

  indent = { enable = true },
  autotag = { enable = true },
}

return options

Please help, Thanks.

@renatomoor
Copy link

renatomoor commented Mar 19, 2024

I managed to get it work inspired by #64 (comment)
This config is working for me using NvChad and Lazy:

  {
    "nvim-treesitter/nvim-treesitter",
      opts = {
        auto_install = true,
        autotag = {
           enable = true,
           filetypes = {
            'html', 'javascript', 'typescript', 'svelte', 'vue', 'tsx', 'jsx', 'rescript',
            'css', 'lua', 'xml', 'php', 'markdown'
           },
        },
        indent = { enable = true },
        ensure_installed = {
           -- defaults 
          "vim",
          "lua",
          "vimdoc",

          -- web dev 
          "html",
          "css",
          "javascript",
          "typescript",
          "tsx",
          "astro",
          "vue",
          "svelte",
          "markdown",
          "markdown_inline",
          "json",
          "scss",
          "yaml"
        }
      }
  },

  {
    "windwp/nvim-ts-autotag",
    dependencies = "nvim-treesitter/nvim-treesitter",
    config = function ()
      require('nvim-ts-autotag').setup()
    end,
    lazy = true,
    event = "VeryLazy"
  },

@GNITOAHC
Copy link

Mine isn't working with markdown, too.

local status_ok, configs = pcall(require, "nvim-treesitter.configs")
if not status_ok then
    return
end

local autotag_filetypes = {
    'html', 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'svelte', 'vue', 'tsx', 'jsx', 'rescript',
    'xml',
    'php',
    'markdown',
    'glimmer','handlebars','hbs'
}

configs.setup {
    ensure_installed = { "c", "cpp", "lua", "python", "c_sharp", "typescript", "javascript", "markdown", "scss", "fish", "vim" },
    sync_install = false,
    ignore_install = { "" }, -- List of parsers to ignore installing
    autopairs = {
        enable = true,
    },
    autotag = {
        enable = true,
        filetypes = autotag_filetypes,
    },
    highlight = {
        enable = true, -- false will disable the whole extension
        disable = { "" }, -- list of language that will be disabled
        additional_vim_regex_highlighting = false,
    },
    indent = { enable = true, disable = { "yaml" } },
    rainbow = {
        enable = true,
        extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean
        max_file_lines = nil, -- Do not enable for files with more than n lines, int
    }
}

@ishaan-kapoor
Copy link

ishaan-kapoor commented Apr 14, 2024

Many people, including myself, initially believe that simply configuring nvim-treesitter with the following code will make it work:

  autotag = {
    enable = true
  }

However, to ensure it functions correctly, you also need to install the package using your Package Manager.

In my case, using NvChad and Lazy, the configuration should be:

{
    "nvim-treesitter/nvim-treesitter",
    opts = overrides.treesitter,
  },
  {
    "windwp/nvim-ts-autotag",
    dependencies = "nvim-treesitter/nvim-treesitter",
    config = function ()
      require('nvim-ts-autotag').setup({
        -- your config
      })
    end,
    lazy = true,
    event = "VeryLazy"
  },

It would be helpful to include this information in the documentation.

I am using vanilla NeoVim with lazy package manager, ans this does not work for me
(Stable) NVIM v0.9.6-dev-0ef2718 - Released: 19th Jan, 2024

UPDATE: Works now, just TSInstall the parser for whatever filetype you want

@PriceHiller
Copy link
Collaborator

Hey folks, I highly encourage you to check out the new changes on main.

This plugin will not work for certain filetypes unless you have their associated treesitter parser installed.

nvim-treesitter does include an auto_install flag in its config to automatically install parsers for known filetypes. Recommend you give that a shot or install the parsers as needed.

@windwp am I ok to close this issue? Been open since 2022 and the core solution is to install the correct parsers (or let nvim-treesitter auto install them).

@windwp
Copy link
Owner

windwp commented May 20, 2024

We can close it. The old setting configuration will not work with the current version, so it's better to open a new issue.

@windwp windwp closed this as completed May 20, 2024
@nigelnindodev
Copy link

Many people, including myself, initially believe that simply configuring nvim-treesitter with the following code will make it work:

  autotag = {
    enable = true
  }

However, to ensure it functions correctly, you also need to install the package using your Package Manager.

In my case, using NvChad and Lazy, the configuration should be:

{
    "nvim-treesitter/nvim-treesitter",
    opts = overrides.treesitter,
  },
  {
    "windwp/nvim-ts-autotag",
    dependencies = "nvim-treesitter/nvim-treesitter",
    config = function ()
      require('nvim-ts-autotag').setup({
        -- your config
      })
    end,
    lazy = true,
    event = "VeryLazy"
  },

It would be helpful to include this information in the documentation.

Thanks a lot! What's missing in this answer is to verify if your target language is in ensure_installed (I was missing html):
Screenshot from 2024-05-27 20-02-28

@alfredbaudisch
Copy link

alfredbaudisch commented Jun 6, 2024

There's now a deprecation message when adding autotag inside treesitter.setup or when creating a standalone config for nvim-ts-autotag.

Correct usage is to add import nvim-ts-autotag inside the treesitter config:

require('nvim-ts-autotag').setup({
	enable = true,
	filetypes = { "html", "xml", "tsx" },
})

My full working setup:

return {
	"nvim-treesitter/nvim-treesitter",
	event = { "BufReadPre", "BufNewFile" },
	build = ":TSUpdate",
	dependencies = {
		"windwp/nvim-ts-autotag",
	},
	config = function()
		-- import nvim-treesitter plugin
		local treesitter = require("nvim-treesitter.configs")

		require('nvim-ts-autotag').setup({
			enable = true,
			filetypes = { "html", "xml", "tsx" },
		})

		-- configure treesitter
		treesitter.setup({ -- enable syntax highlighting
			highlight = {
				enable = true,
			},
			-- enable indentation
			indent = { enable = true },

			-- ensure these language parsers are installed
			ensure_installed = {
				"json", "html", -- add others here
			},
			incremental_selection = {
				enable = true,
				keymaps = {
					init_selection = "<C-space>",
					node_incremental = "<C-space>",
					scope_incremental = false,
					node_decremental = "<bs>",
				},
			},
		})
	end,
}

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

No branches or pull requests