mirror of
https://github.com/windwp/nvim-ts-autotag.git
synced 2024-12-30 14:09:14 -06:00
fix: force a full reparse of ts source
PERF: This will impact performance, something to keep an eye on. Prior to this commit, some parsers like php were failing in tests. By forcing a full reparse, the php parser among others get the correct tree.
This commit is contained in:
parent
fb7393d0f5
commit
b02430fa42
@ -253,13 +253,6 @@ local function find_tag_node(opt)
|
||||
local name_tag_pattern = opt.name_tag_pattern
|
||||
local skip_tag_pattern = opt.skip_tag_pattern
|
||||
local find_child = opt.find_child or false
|
||||
--- PERF: Some parsers don't seemingly pick up their trees correctly, so we have to reparse the
|
||||
--- entire source. This is slow, see if we can avoid this.
|
||||
if target and target:has_changes() then
|
||||
local parser = vim.treesitter.get_parser()
|
||||
_ = (parser and parser:parse(true) or nil)
|
||||
target = ts_utils.get_node_at_cursor()
|
||||
end
|
||||
local node
|
||||
if find_child then
|
||||
node = find_child_match({
|
||||
@ -378,7 +371,7 @@ M.close_tag = function()
|
||||
if not buf_parser then
|
||||
return
|
||||
end
|
||||
buf_parser:parse()
|
||||
buf_parser:parse(true)
|
||||
local result, tag_name = check_close_tag()
|
||||
if result == true and tag_name ~= nil then
|
||||
vim.api.nvim_put({ string.format("</%s>", tag_name) }, "", true, false)
|
||||
@ -391,7 +384,7 @@ M.close_slash_tag = function()
|
||||
if not buf_parser then
|
||||
return
|
||||
end
|
||||
buf_parser:parse()
|
||||
buf_parser:parse(true)
|
||||
local result, tag_name = check_close_tag(true)
|
||||
if result == true and tag_name ~= nil then
|
||||
vim.api.nvim_put({ string.format("%s>", tag_name) }, "", true, true)
|
||||
@ -560,13 +553,10 @@ local is_before_word = is_before("%w", 1)
|
||||
local is_before_arrow = is_before("<", 0)
|
||||
|
||||
M.rename_tag = function()
|
||||
if is_before_word() then
|
||||
local ok, parser = pcall(vim.treesitter.get_parser)
|
||||
if ok then
|
||||
parser:parse()
|
||||
rename_start_tag()
|
||||
rename_end_tag()
|
||||
end
|
||||
if is_before_word() and parsers.has_parser() then
|
||||
parsers.get_parser():parse(true)
|
||||
rename_start_tag()
|
||||
rename_end_tag()
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user