From 0cb76eea80e9c73b88880f0ca78fbd04c5bdcac7 Mon Sep 17 00:00:00 2001 From: Angel Kozlev Date: Thu, 15 Aug 2024 01:12:53 +0100 Subject: [PATCH] fix: Don't auto tag fragment if not in jsx (#210) --- lua/nvim-ts-autotag/utils.lua | 7 +++++++ tests/specs/closetag_spec.lua | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/lua/nvim-ts-autotag/utils.lua b/lua/nvim-ts-autotag/utils.lua index 4bffa26..e79e815 100644 --- a/lua/nvim-ts-autotag/utils.lua +++ b/lua/nvim-ts-autotag/utils.lua @@ -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) diff --git a/tests/specs/closetag_spec.lua b/tests/specs/closetag_spec.lua index 4e2284d..ea587af 100644 --- a/tests/specs/closetag_spec.lua +++ b/tests/specs/closetag_spec.lua @@ -255,6 +255,15 @@ local data = { before = [[| ]], }, + { + 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")