Skip to content

Commit

Permalink
fix: Don't auto tag fragment if not in jsx (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
akozlev authored Aug 15, 2024
1 parent dc5e168 commit 0cb76ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lua/nvim-ts-autotag/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ end

---@return boolean
function M.is_react_fragment()
local node = vim.treesitter.get_node()

-- Bail out if the treesitter doesn't recognize `<>` as jsx_opening_element
if not node or node:type() ~= "jsx_opening_element" then
return false
end

local line = vim.fn.getline(".")
local col = vim.fn.col(".") - 2
local strpart = vim.fn.strpart(line, col)
Expand Down
9 changes: 9 additions & 0 deletions tests/specs/closetag_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ local data = {
before = [[<input| ]],
after = [[<input>| ]],
},
{
name = "28 typescriptreact not close fragment in generic argument delimeters",
filepath = "./sample/index.tsx",
filetype = "typescriptreact",
linenr = 1,
key = [[>]],
before = [[type Foo = Bar<| ]],
after = [[type Foo = Bar<>]],
},
}

local autotag = require("nvim-ts-autotag")
Expand Down

0 comments on commit 0cb76ee

Please sign in to comment.