windwp / nvim-ts-autotag

Use treesitter to auto close and auto rename html tag
MIT License
1.65k stars 87 forks source link

Nvim Treesitter Setup is deprecated #192

Closed savchenko closed 3 months ago

savchenko commented 3 months ago

The error is returned despite using the recommended setup method. Using latest versions of the plugin, treesitter and nVim (v0.10.0).

Configuration

{
    url = 'https://github.com/windwp/nvim-ts-autotag',
    config = function()
        require('nvim-ts-autotag').setup({
            opts = {
                enable_close = true,
                enable_rename = true,
                enable_close_on_slash = true
            }
        })
    end
}

Error

Nvim Treesitter Setup is deprecated, use `require('nvim-ts-autotag').setup()` instead.                                                                                                          
Feature will be removed in nvim-ts-autotag 1.0.0                                                                                                                                                
stack traceback:                                                                                                                                                                                
        .../share/nvim/lazy/nvim-ts-autotag/lua/nvim-ts-autotag.lua:15: in function 'attach'                                                                                                    
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:509: in function 'attach_module'                                                                                            
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:532: in function 'reattach_module'                                                                                          
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:133: in function <...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:132>                                          
        [C]: in function 'nvim_cmd'                                                                                                                                                             
        /usr/share/nvim/runtime/filetype.lua:36: in function </usr/share/nvim/runtime/filetype.lua:35>                                                                                          
        [C]: in function 'nvim_buf_call'                                                                                                                                                        
        /usr/share/nvim/runtime/filetype.lua:35: in function </usr/share/nvim/runtime/filetype.lua:10> 
PriceHiller commented 3 months ago

That means you still have a treesitter module setup method somewhere in your config.

Look for something like require("nvim-treesitter.configs").setup and remove the related autotag section from it.

Feel free to reopen this if you can confirm you're not setting up via nvim-treesitter at all and still facing this.

Thanks 🙂

cool-pants commented 3 months ago

I am still facing a similar issue. The below configuration leads to me getting a Deprecation warning on the first time I enter a buffer. Is there any way to turn off this warning? From what I checked, I have not set the autotag value in treesitter config.

Treesitter configuration (conf.nvim_treesitter)

require("nvim-treesitter.configs").setup({
  ensure_installed = {
      "python",
      "bash",
      "lua",
      "vim",

      "go",
      "gomod",
      "gosum",
      "gowork",
      "gotmpl",

      "rust",
  },
  highlight = {
      enable = true,
      disable = function(_, buf)
          local max_filesize = 240 * 1024
          local ok, stats = pcall(vim.uv.fs_stat, vim.api.nvim_buf_get_name(buf))
          if ok and stats and stats.size > max_filesize then
              return true
          end
      end,
  },
})

autotag config (conf.ts_autotag)

require("nvim-ts-autotag").setup({
        -- Defaults
        enable = true,
        filetypes = {
            "html",
            "javascriptreact",
            "javascript",
            "typescript",
            "typescriptreact",
            "tsx",
            "jsx",
        },
        enable_close = true, -- Auto close tags
        enable_rename = true, -- Auto rename pairs of tags
        enable_close_on_slash = false, -- Auto close on trailing </
        -- Also override individual filetype configs, these take priority.
        -- Empty by default, useful if one of the "opts" global settings
        -- doesn't work well in a specific filetype
        per_filetype = {
            ["html"] = {
                enable_close = false,
            },
        },
    })

Lazy package loading (Lazy.nvim)

packadd({
    "nvim-treesitter/nvim-treesitter",
    event = "BufRead",
    build = ":TSUpdate",
    config = conf.nvim_treesitter,
})

packadd({
    "windwp/nvim-ts-autotag",
    event = "BufReadPre",
    config = conf.ts_autotag,
})

Screenshots

image

marcusluis-s commented 2 months ago

@cool-pants Hi. I was facing the same probem and to fix this problem I just set autotag to false on treesitter config:

autotag = {
    enable = false,
},

This is my treesitter file:

return {
    "nvim-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    config = function()
        require("nvim-treesitter.configs").setup {
            ensure_installed = {
                "lua",
                "luadoc",
                "bash",
                "c",
                "cmake",
                "make",
                "html",
                "css",
                "scss",
                "markdown",
                "markdown_inline",
                "vim",
                "vimdoc",
                "query",
                "dockerfile",
                "gitignore",
                "javascript",
                "jsdoc",
                "typescript",
                "tsx",
                "python",
                "diff",
            },
            -- Autoinstall parsers that are not installed
            auto_install = true,
            autopairs = {
                enable = true,
            },
            autotag = {
                enable = false,
            },
            endwise = {
                enable = true,
            },
            highlight = {
                enable = true,
            },
            indent = {
                enable = true,
            },
            incremental_selection = {
                enable = true,
                keymaps = {
                    init_selection = "gnn",
                    node_incremental = "grn",
                    scope_incremental = "grc",
                    node_decremental = "grm",
                },
            },
        }
    end
}
mainak-affinsys commented 2 months ago

@cool-pants Hi. I was facing the same probem and to fix this problem I just set autotag to false on treesitter config:

autotag = {
    enable = false,
},

This is my treesitter file:

return {
    "nvim-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    config = function()
        require("nvim-treesitter.configs").setup {
            ensure_installed = {
                "lua",
                "luadoc",
                "bash",
                "c",
                "cmake",
                "make",
                "html",
                "css",
                "scss",
                "markdown",
                "markdown_inline",
                "vim",
                "vimdoc",
                "query",
                "dockerfile",
                "gitignore",
                "javascript",
                "jsdoc",
                "typescript",
                "tsx",
                "python",
                "diff",
            },
            -- Autoinstall parsers that are not installed
            auto_install = true,
            autopairs = {
                enable = true,
            },
            autotag = {
                enable = false,
            },
            endwise = {
                enable = true,
            },
            highlight = {
                enable = true,
            },
            indent = {
                enable = true,
            },
            incremental_selection = {
                enable = true,
                keymaps = {
                    init_selection = "gnn",
                    node_incremental = "grn",
                    scope_incremental = "grc",
                    node_decremental = "grm",
                },
            },
        }
    end
}

This seems to solve my issue as well. Thanks 🫡