vim-closetag icon indicating copy to clipboard operation
vim-closetag copied to clipboard

Autoclose dosent work on jsx and tsx

Open AadhilPaul opened this issue 2 years ago • 13 comments

` call s:Declare('g:closetag_filetypes', 'html,xhtml,phtml') call s:Declare('g:closetag_xhtml_filetypes', 'xhtml')

call s:Declare('g:closetag_filenames', '*.html,*.xhtml,*.phtml,*.js,*.jsx,*.ts,*.tsx')
call s:Declare('g:closetag_xhtml_filenames', '*.xhtml,*.js,*.jsx,*.ts,*.tsx')

call s:Declare('g:closetag_shortcut', '>')
call s:Declare('g:closetag_close_shortcut', '')

call s:Declare('g:closetag_emptyTags_caseSensitive', 1)

call s:Declare('g:closetag_enable_react_fragment', 1)

call s:Declare('g:closetag_regions', {
    \ 'typescript.tsx': 'jsxRegion,tsxRegion',
    \ 'javascript.jsx': 'jsxRegion',
    \ 'typescriptreact': 'jsxRegion,tsxRegion',
    \ 'javascriptreact': 'jsxRegion',
    \ })

` it works on .js files and .ts files but not for jsx and tsx, any help would be appreaciated :)

AadhilPaul avatar Jun 17 '22 17:06 AadhilPaul

For me only works in html files, doesn't work for js and jsx files

wenanoshe avatar Jun 24 '22 21:06 wenanoshe

I´m using this in my init.vim, and it´s working fine for jsx and tsx.

let g:closetag_filenames = '*.html,*.xhtml,*.jsx,*.tsx'
let g:closetag_xhtml_filenames = '*.xhtml,*.jsx,*.tsx'
let g:closetag_filetypes = 'html,js'
let g:closetag_xhtml_filetype = 'xhtml,jsx,tsx'
let g:closetag_emptyTags_caseSensitive = 1
let g:closetag_regions = {
  \ 'typescript.tsx': 'jsxRegion,tsxRegion',
  \ 'javascript.jsx': 'jsxRegion',
  \ }
let g:closetag_shortcut = '>'

Hdoc1509 avatar Sep 19 '22 17:09 Hdoc1509

I'm using in my init.lua with nvim but some feature is not work. Please help me.

HTML = WORK JSX = WORK TSX = NOT WORK !! <<<<

-- set vim options here (vim.<first_key>.<second_key> = value) options = { opt = { -- set to true or false etc. relativenumber = true, -- sets vim.opt.relativenumber number = true, -- sets vim.opt.number spell = false, -- sets vim.opt.spell signcolumn = "auto", -- sets vim.opt.signcolumn to auto wrap = false, -- sets vim.opt.wrap }, g = { mapleader = " ", -- sets vim.g.mapleader autoformat_enabled = true, -- enable or disable auto formatting at start (lsp.formatting.format_on_save must be enabled) cmp_enabled = true, -- enable completion at start autopairs_enabled = true, -- enable autopairs at start diagnostics_enabled = true, -- enable diagnostics at start status_diagnostics_enabled = true, -- enable diagnostics in statusline icons_enabled = true, -- disable icons in the UI (disable if no nerd font is available, requires :PackerSync after changing) ui_notifications_enabled = true, -- disable notifications when toggling UI elements transparent_enabled = true, -- enable transparent background closetag_filenames = ".html,.xhtml,.phtml", closetag_xhtml_filenames = ".xhtml,*.{t,j}sx", closetag_filetypes = "html,xhtml,phtml", closetag_xhtml_filetypes = "xhtml,{t,j}sx", closetag_shortcut = ">", closetag_close_shortcut = ">", closetag_enable_react_fragment = 1, }, },

RedRx avatar Nov 24 '22 10:11 RedRx

In my init.lua this works

vim.cmd([[
let g:closetag_filenames = '*.html,*.xhtml,*.jsx,*.tsx'
let g:closetag_xhtml_filenames = '*.xhtml,*.jsx,*.tsx'
let g:closetag_filetypes = 'html,js'
let g:closetag_xhtml_filetype = 'xhtml,jsx,tsx'
let g:closetag_emptyTags_caseSensitive = 1
let g:closetag_regions = {
  \ 'typescript.tsx': 'jsxRegion,tsxRegion',
  \ 'javascript.jsx': 'jsxRegion',
  \ }
let g:closetag_shortcut = '>'
]])

northnSouth avatar Jan 23 '23 02:01 northnSouth

@northnSouth Thanks, I experienced the same problem in TSX files, I had my configs in a .vim file but I tried using your solution and it worked,

bkerz avatar Jan 25 '23 00:01 bkerz

I also have this issue but with any filetype different than html. I'm currently trying to use this with eelixir and eruby, but it just does not work, don't know why. This is my whole init.lua right now:

local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    'https://github.com/folke/lazy.nvim.git',
    '--branch=stable', -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require('lazy').setup({
  {
    'alvan/vim-closetag',
    lazy = false,
    config = function()
      vim.cmd("let g:closetag_filetypes='html,eelixir,eruby'")
    end,
    },
})

If I manually change the filetype of any file to html, it starts working 😅

I have tried the same configs shown in this thread and it just does not work for any of those filetypes (js, jsx etc), nor it works for erb and eex when I add it to closetag_filetypes. I have also tried to add *.erb and *.eex to closetag_filenames but to no avail. This plugin just suddenly stopped working )):: Which is really sad, since it is a very good plugin!

Edit: I have also tried to run the command :CloseTagEnableBuffer inside a .eex file (eelixir filetype), but it still does not activate it.

lucassperez avatar Mar 04 '23 18:03 lucassperez

I´m using this in my init.vim, and it´s working fine for jsx and tsx.

let g:closetag_filenames = '*.html,*.xhtml,*.jsx,*.tsx'
let g:closetag_xhtml_filenames = '*.xhtml,*.jsx,*.tsx'
let g:closetag_filetypes = 'html,js'
let g:closetag_xhtml_filetype = 'xhtml,jsx,tsx'
let g:closetag_emptyTags_caseSensitive = 1
let g:closetag_regions = {
  \ 'typescript.tsx': 'jsxRegion,tsxRegion',
  \ 'javascript.jsx': 'jsxRegion',
  \ }
let g:closetag_shortcut = '>'

Hi @Hdoc1509 , I'm quite confusing on this configuration. Why remove

    \ 'typescriptreact': 'jsxRegion,tsxRegion',
    \ 'javascriptreact': 'jsxRegion',

from g:closetag_regions ?

linrongbin16 avatar Mar 16 '23 08:03 linrongbin16

I cannot make the configuration work for all of js/jsx/ts/tsx at the same time. Could anyone help me?

linrongbin16 avatar Mar 16 '23 09:03 linrongbin16

I also have this issue but with any filetype different than html. I'm currently trying to use this with eelixir and eruby, but it just does not work, don't know why. This is my whole init.lua right now:

local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    'https://github.com/folke/lazy.nvim.git',
    '--branch=stable', -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require('lazy').setup({
  {
    'alvan/vim-closetag',
    lazy = false,
    config = function()
      vim.cmd("let g:closetag_filetypes='html,eelixir,eruby'")
    end,
    },
})

If I manually change the filetype of any file to html, it starts working 😅

I have tried the same configs shown in this thread and it just does not work for any of those filetypes (js, jsx etc), nor it works for erb and eex when I add it to closetag_filetypes. I have also tried to add *.erb and *.eex to closetag_filenames but to no avail. This plugin just suddenly stopped working )):: Which is really sad, since it is a very good plugin!

Edit: I have also tried to run the command :CloseTagEnableBuffer inside a .eex file (eelixir filetype), but it still does not activate it.

In lazy, you need to specify these global variables in init, so this plugin will recognize them when loading.

linrongbin16 avatar Mar 16 '23 12:03 linrongbin16

For me this seems to be the minimal config to get this working Neovim v0.8.3

vim.g.closetag_filetypes = 'html,js,typescriptreact'
vim.g.closetag_emptyTags_caseSensitive = 1
vim.g.closetag_regions = {
  ['typescript.tsx'] = 'jsxRegion,tsxRegion',
  ['javascript.jsx'] = 'jsxRegion',
}

JakeElder avatar Mar 20 '23 11:03 JakeElder

anyone solve the problem where the the auto close tag is applying outside the region??

GZLiew avatar Feb 28 '24 02:02 GZLiew

For me this seems to be the minimal config to get this working Neovim v0.8.3

vim.g.closetag_filetypes = 'html,js,typescriptreact'
vim.g.closetag_emptyTags_caseSensitive = 1
vim.g.closetag_regions = {
  ['typescript.tsx'] = 'jsxRegion,tsxRegion',
  ['javascript.jsx'] = 'jsxRegion',
}

are you appending this to your init.lua file if not where ?

Aryan-kamboj avatar Mar 20 '24 21:03 Aryan-kamboj

I´m using this in my init.vim, and it´s working fine for jsx and tsx.

let g:closetag_filenames = '*.html,*.xhtml,*.jsx,*.tsx'
let g:closetag_xhtml_filenames = '*.xhtml,*.jsx,*.tsx'
let g:closetag_filetypes = 'html,js'
let g:closetag_xhtml_filetype = 'xhtml,jsx,tsx'
let g:closetag_emptyTags_caseSensitive = 1
let g:closetag_regions = {
  \ 'typescript.tsx': 'jsxRegion,tsxRegion',
  \ 'javascript.jsx': 'jsxRegion',
  \ }
let g:closetag_shortcut = '>'

Hi @Hdoc1509 , I'm quite confusing on this configuration. Why remove

    \ 'typescriptreact': 'jsxRegion,tsxRegion',
    \ 'javascriptreact': 'jsxRegion',

from g:closetag_regions ?

Hi @linrongbin16, I only set those options and everything worked fine. You can check the config file in this commit from my nvim-config on that time.

At this moment, I'm using nvim-ts-autotag. Additionally, you can check out my current treesitter config where nvim-ts-autotag is setup.

Hdoc1509 avatar Mar 21 '24 22:03 Hdoc1509