mirror of
https://github.com/windwp/nvim-ts-autotag.git
synced 2025-01-23 11:23:58 -06:00
Merge a485f97de9bf36bdd77c2d7f3c5e2494ebd843b5 into 323a3e16ed603e2e17b26b1c836d1e86c279f726
This commit is contained in:
commit
dda6f9d0d0
@ -242,6 +242,42 @@ local function check_close_tag(close_slash_tag)
|
||||
return false
|
||||
end
|
||||
|
||||
local function is_react_file()
|
||||
local ft = vim.bo.ft
|
||||
-- check filetypes first.
|
||||
if ft == "javascriptreact" or "typescriptreact" then
|
||||
return true
|
||||
elseif ft ~= "javascript" then
|
||||
return false
|
||||
end
|
||||
|
||||
local ok, buf_parser = pcall(vim.treesitter.get_parser)
|
||||
if not ok then
|
||||
return false
|
||||
end
|
||||
|
||||
local tree = buf_parser:parse(true)
|
||||
if not tree then
|
||||
return false
|
||||
end
|
||||
|
||||
local root = tree[1]:root()
|
||||
-- parse the tree for jsx nodes
|
||||
local query = vim.treesitter.query.parse("javascript", [[
|
||||
(jsx_element)
|
||||
(jsx_self_closing_element)
|
||||
]])
|
||||
|
||||
-- iterate over nodes to find jsx nodes
|
||||
for _, node in query:iter_captures(root, 0, 0, -1) do
|
||||
if node then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
M.close_tag = function()
|
||||
local ok, buf_parser = pcall(vim.treesitter.get_parser)
|
||||
if not ok then
|
||||
@ -252,6 +288,9 @@ M.close_tag = function()
|
||||
if result == true and tag_name ~= nil then
|
||||
vim.api.nvim_put({ string.format("</%s>", tag_name) }, "", true, false)
|
||||
vim.cmd([[normal! F>]])
|
||||
elseif is_react_file() then
|
||||
vim.api.nvim_put({ "</>" }, "", true, false)
|
||||
vim.cmd([[normal! F>]])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -130,25 +130,7 @@ local data = {
|
||||
after = [[{(card.data >| 0) && <div></div>}]],
|
||||
},
|
||||
{
|
||||
name = "15 vue auto close tag",
|
||||
filepath = "./sample/index.vue",
|
||||
filetype = "vue",
|
||||
linenr = 4,
|
||||
key = [[>]],
|
||||
before = [[<Img| ]],
|
||||
after = [[<Img>|</Img>]],
|
||||
},
|
||||
{
|
||||
name = "16 vue not close on script",
|
||||
filepath = "./sample/index.vue",
|
||||
filetype = "vue",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[const data:Array<string| ]],
|
||||
after = [[const data:Array<string>| ]],
|
||||
},
|
||||
{
|
||||
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 = [[<Opt.Input>|</Opt.Input> ]],
|
||||
},
|
||||
{
|
||||
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 = [[<Img| ]],
|
||||
after = [[<Img>|</Img>]],
|
||||
},
|
||||
{
|
||||
name = "18 vue not close on script",
|
||||
filepath = "./sample/index.vue",
|
||||
filetype = "vue",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[const data:Array<string| ]],
|
||||
after = [[const data:Array<string>| ]],
|
||||
},
|
||||
{
|
||||
name = "19 php div ",
|
||||
filepath = "./sample/index.php",
|
||||
filetype = "php",
|
||||
linenr = 25,
|
||||
@ -175,7 +184,7 @@ local data = {
|
||||
-- after = [[<div>|</div> ]],
|
||||
-- },
|
||||
{
|
||||
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 = [[<div>|</div> ]],
|
||||
},
|
||||
{
|
||||
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 = [[<div>|</div> ]],
|
||||
},
|
||||
{
|
||||
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 = [[<%= <div>| %> ]],
|
||||
},
|
||||
{
|
||||
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 = [[<div>|</div>]],
|
||||
},
|
||||
{
|
||||
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 = [[<div clas="laa">|</div>]],
|
||||
},
|
||||
{
|
||||
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 = [[<div>aa</div>|]],
|
||||
},
|
||||
{
|
||||
name = "24 templ not close on input tag",
|
||||
name = "26 templ not close on input tag",
|
||||
filepath = "./sample/index.templ",
|
||||
filetype = "templ",
|
||||
linenr = 10,
|
||||
|
Loading…
x
Reference in New Issue
Block a user