diff --git a/lua/nvim-ts-autotag.lua b/lua/nvim-ts-autotag.lua index 118388c..8e334e1 100644 --- a/lua/nvim-ts-autotag.lua +++ b/lua/nvim-ts-autotag.lua @@ -9,6 +9,9 @@ function M.init() if not nvim_ts then return end + if nvim_ts.define_modules == nil then + return + end nvim_ts.define_modules({ autotag = { attach = function(bufnr, _) diff --git a/lua/nvim-ts-autotag/internal.lua b/lua/nvim-ts-autotag/internal.lua index 123fb04..0eced70 100644 --- a/lua/nvim-ts-autotag/internal.lua +++ b/lua/nvim-ts-autotag/internal.lua @@ -245,9 +245,9 @@ end local function is_react_file() local ft = vim.bo.ft -- check filetypes first. - if ft == 'javascriptreact' or 'typescriptreact' then + if ft == "javascriptreact" or "typescriptreact" then return true - elseif ft ~= 'javascript' then + elseif ft ~= "javascript" then return false end @@ -263,7 +263,7 @@ local function is_react_file() local root = tree[1]:root() -- parse the tree for jsx nodes - local query = vim.treesitter.query.parse('javascript', [[ + local query = vim.treesitter.query.parse("javascript", [[ (jsx_element) (jsx_self_closing_element) ]]) @@ -494,7 +494,7 @@ M.attach = function(bufnr) if TagConfigs:get(vim.bo.filetype) ~= nil then setup_ts_tag() - local group = vim.api.nvim_create_augroup("nvim-ts-autotag", { clear = true }) + local group = vim.api.nvim_create_augroup("nvim-ts-autotag-" .. bufnr, { clear = true }) if Setup.get_opts(vim.bo.filetype).enable_close then vim.keymap.set("i", ">", function() local row, col = unpack(vim.api.nvim_win_get_cursor(0)) @@ -524,12 +524,9 @@ M.attach = function(bufnr) }) end if Setup.get_opts(vim.bo.filetype).enable_rename then - -- HACK: This does not bind to a specific buffer, unfortunately it seems doing so will - -- break rename when switching between different buffers. Making it *not* bind to a - -- specific buffer shouldn't cause any problems in theory. Ideally it would be bound per - -- buffer, but for now this works (and I'm lazy). vim.api.nvim_create_autocmd("InsertLeave", { group = group, + buffer = bufnr, callback = M.rename_tag, }) end diff --git a/tests/specs/closetag_spec.lua b/tests/specs/closetag_spec.lua index a48ee15..fc9f127 100644 --- a/tests/specs/closetag_spec.lua +++ b/tests/specs/closetag_spec.lua @@ -130,25 +130,7 @@ local data = { after = [[{(card.data >| 0) &&
}]], }, { - name = "15 vue auto close tag", - filepath = "./sample/index.vue", - filetype = "vue", - linenr = 4, - key = [[>]], - before = [[|]], - }, - { - name = "16 vue not close on script", - filepath = "./sample/index.vue", - filetype = "vue", - linenr = 12, - key = [[>]], - before = [[const data:Array| ]], - }, - { - name = "17 typescriptreact nested indentifer ", + name = "15 typescriptreact nested indentifer ", filepath = "./sample/index.tsx", filetype = "typescriptreact", linenr = 12, @@ -157,7 +139,34 @@ local data = { after = [[| ]], }, { - name = "18 php div ", + name = "16 typescriptreact autoclose fragment", + filepath = "./sample/index.tsx", + filetype = "typescriptreact", + linenr = 12, + key = [[>]], + before = [[<]], + after = [[<>|]] + }, + { + name = "17 vue auto close tag", + filepath = "./sample/index.vue", + filetype = "vue", + linenr = 4, + key = [[>]], + before = [[|]], + }, + { + name = "18 vue not close on script", + filepath = "./sample/index.vue", + filetype = "vue", + linenr = 12, + key = [[>]], + before = [[const data:Array| ]], + }, + { + name = "19 php div ", filepath = "./sample/index.php", filetype = "php", linenr = 25, @@ -175,7 +184,7 @@ local data = { -- after = [[
|
]], -- }, { - name = "19 lit template div", + name = "20 lit template div", filepath = "./sample/index.ts", filetype = "typescript", linenr = 3, @@ -184,7 +193,7 @@ local data = { after = [[
|
]], }, { - name = "20 eruby template div", + name = "21 eruby template div", filepath = "./sample/index.html.erb", filetype = "eruby", linenr = 10, @@ -193,7 +202,7 @@ local data = { after = [[
|
]], }, { - name = "20 eruby template ruby string", + name = "22 eruby template ruby string", filepath = "./sample/index.html.erb", filetype = "eruby", linenr = 10, @@ -202,7 +211,7 @@ local data = { after = [[<%=
| %> ]], }, { - name = "21 templ close tag", + name = "23 templ close tag", filepath = "./sample/index.templ", filetype = "templ", linenr = 10, @@ -211,7 +220,7 @@ local data = { after = [[
|
]], }, { - name = "22 templ close tag", + name = "24 templ close tag", filepath = "./sample/index.templ", filetype = "templ", linenr = 10, @@ -220,7 +229,7 @@ local data = { after = [[
|
]], }, { - name = "23 templ not close tag on close tag", + name = "25 templ not close tag on close tag", filepath = "./sample/index.templ", filetype = "templ", linenr = 10, @@ -229,7 +238,7 @@ local data = { after = [[
aa
|]], }, { - name = "24 templ not close on input tag", + name = "26 templ not close on input tag", filepath = "./sample/index.templ", filetype = "templ", linenr = 10,