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

Autoclose dosent work on jsx and tsx #76

Open
AadhilPaul opened this issue Jun 17, 2022 · 13 comments
Open

Autoclose dosent work on jsx and tsx #76

AadhilPaul opened this issue Jun 17, 2022 · 13 comments

Comments

@AadhilPaul
Copy link

`
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 :)

@wenanoshe
Copy link

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

@Hdoc1509
Copy link

Hdoc1509 commented Sep 19, 2022

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 = '>'

@RedRx
Copy link

RedRx commented Nov 24, 2022

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,
},
},

@northnSouth
Copy link

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 = '>'
]])

@bkerz
Copy link

bkerz commented Jan 25, 2023

@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,

@lucassperez
Copy link

lucassperez commented Mar 4, 2023

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.

@linrongbin16
Copy link

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
Copy link

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

@linrongbin16
Copy link

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.

@JakeElder
Copy link

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',
}

@GZLiew
Copy link

GZLiew commented Feb 28, 2024

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

@Aryan-kamboj
Copy link

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 ?

@Hdoc1509
Copy link

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.

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