Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tsx node renaming #201

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: tsx node renaming
inferst committed Jul 13, 2024
commit 220fe15d97ce0e3170f6fe662c0ae6532bd91953
14 changes: 13 additions & 1 deletion lua/nvim-ts-autotag/internal.lua
Original file line number Diff line number Diff line change
@@ -284,8 +284,20 @@ local function validate_tag_regex(node, start_regex, end_regex)
if node == nil then
return false
end

local texts = utils.get_node_text(node)
if string.match(texts[1], start_regex) and string.match(texts[#texts], end_regex) then
local filtered = {}

-- For some nodes (tsx) 'vim.treesitter.get_node_text' can return empty lines or lines with spaces
-- We have to exclude them
for i = 1, #texts do
local text = texts[i]:gsub("^%s*(.-)%s*$", "%1")
if text ~= "" then
filtered[#filtered + 1] = text
end
end

if string.match(filtered[1], start_regex) and string.match(filtered[#filtered], end_regex) then
return true
end
return false