diff --git a/lua/nvim-ts-autotag.lua b/lua/nvim-ts-autotag.lua index 2ae6595..1ab1f04 100644 --- a/lua/nvim-ts-autotag.lua +++ b/lua/nvim-ts-autotag.lua @@ -21,9 +21,6 @@ local HTML_TAG = { close_name_tag_pattern = 'erroneous_end_tag_name', element_tag = 'element', skip_tag_pattern = {'quoted_attribute_value', 'end_tag'}, - - close_tag = 'start_tag', - close_name_tag = 'tag_name', } local JSX_TAG = { start_tag_pattern = 'jsx_opening_element', @@ -34,11 +31,9 @@ local JSX_TAG = { close_name_tag_pattern = 'identifier', element_tag = 'jsx_element', skip_tag_pattern = {'jsx_closing_element','jsx_expression', 'string', 'jsx_attribute'}, - - close_name_tag = 'jsx_opening_element>identifier', - close_tag = 'jsx_element', } + M.test = false M.enableRename = true M.enableClose = true @@ -53,7 +48,6 @@ M.setup = function (opts) vim.cmd[[augroup end]] end - local function is_in_table(tbl, val) if tbl == nil then return false end for _, value in pairs(tbl) do @@ -174,8 +168,8 @@ end local function checkCloseTag() local ts_tag = get_ts_tag() local tag_node = find_tag_node({ - tag_pattern = ts_tag.close_tag, - name_tag_pattern = ts_tag.close_name_tag, + tag_pattern = ts_tag.start_tag_pattern, + name_tag_pattern = ts_tag.start_name_tag_pattern, skip_tag_pattern = ts_tag.skip_tag_pattern }) if tag_node ~=nil then @@ -184,25 +178,6 @@ local function checkCloseTag() return false end return true,tag_name - -- tag_node = find_parent_match({ - -- target = tag_node, - -- pattern = ts_tag.element_tag, - -- max_depth = 2 - -- }) - -- local close_tag_node = find_close_tag_node({ - -- target = tag_node, - -- tag_pattern = ts_tag.end_tag_pattern, - -- name_tag_pattern = ts_tag.end_name_tag_pattern, - -- }) - -- -- check if already have exist tag - -- if close_tag_node ~= nil then - -- local close_tag_name = get_tag_name(close_tag_node) - -- if tag_name ~= close_tag_name then - -- return true ,tag_name - -- end - -- else - -- return true,tag_name - -- end end return false end diff --git a/sample/index.tsx b/sample/index.tsx index 20f8fff..3ebbf66 100644 --- a/sample/index.tsx +++ b/sample/index.tsx @@ -2,7 +2,7 @@ import React, { useCallback, useEffect } from 'react' const SamplePage: React.FC = () => { - const [state, setstate] = useState(initialState) + const [state, setstate] = useState(initialState) useEffect(() => { },[]) diff --git a/tests/closetag_spec.lua b/tests/closetag_spec.lua index 3afb597..a5c4db7 100644 --- a/tests/closetag_spec.lua +++ b/tests/closetag_spec.lua @@ -42,7 +42,7 @@ local data = { linenr = 10, key = [[>]], before = [[
aaaa
]] + after = [[
aa
|]] }, { name = "html not close on input tag" , @@ -89,6 +89,25 @@ local data = { before = [[|]] }, + { + name = "typescriptreact not close on exist tag" , + filepath = './sample/index.tsx', + filetype = "typescriptreact", + linenr = 12, + key = [[>]], + before = [[const a = () =>
|
]] + }, + + { + name = "typescriptreact close tag" , + filepath = './sample/index.tsx', + filetype = "typescriptreact", + linenr = 12, + key = [[>]], + before = [[|]] + }, { name = "typescriptreact not close on close tag" , filepath = './sample/index.tsx', @@ -176,9 +195,9 @@ local function Test(test_data) -- autotag.closeTag() helpers.insert(value.key) local result = vim.fn.getline(line) - -- local pos = vim.fn.getpos('.') + local pos = vim.fn.getpos('.') eq(after, result , "\n\n [ERROR TEXT]: " .. value.name .. "\n") - -- eq(p_after, pos[3] + 1, "\n\n [ERROR POS]: " .. value.name .. "\n") + eq(p_after, pos[3] + 1, "\n\n [ERROR POS]: " .. value.name .. "\n") else eq(false, true, "\n\n file not exist " .. value.filepath .. "\n") end