This commit is contained in:
zztrieuzz 2022-04-22 08:46:34 +07:00
parent 0339338316
commit 044a05c4c5
2 changed files with 16 additions and 11 deletions

View File

@ -1,5 +1,5 @@
local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')
local get_node_text = vim.treesitter.query.get_node_text
local get_node_text = require('nvim-ts-autotag.utils').get_node_text
local configs = require'nvim-treesitter.configs'
local parsers = require'nvim-treesitter.parsers'
@ -163,7 +163,7 @@ local function find_parent_match(opts)
local function get_tag_name(node)
local tag_name = nil
if node ~= nil then
tag_name = get_node_text(node, vim.api.nvim_get_current_buf())
tag_name = get_node_text(node, vim.api.nvim_get_current_buf())[1]
end
return tag_name
end

View File

@ -1,9 +1,15 @@
local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')
local log = require('nvim-ts-autotag._log')
local M={}
local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')
local get_node_text = vim.treesitter.query.get_node_text or ts_utils.get_node_text
local M = {}
M.get_node_text = function(...)
local txt = get_node_text(...)
return vim.split(txt, '\n')
end
M.dump_node = function(node)
local text=ts_utils.get_node_text(node)
local text = M.get_node_text(node)
for _, txt in pairs(text) do
print(txt)
end
@ -12,19 +18,18 @@ end
M.is_close_empty_node = function(node)
local tag_name = ''
if node ~= nil then
local text = ts_utils.get_node_text(node)
tag_name = text[#text-1]
local text = M.get_node_text(node)
tag_name = text[#text - 1]
end
return tag_name:match("%<%/%>$")
return tag_name:match('%<%/%>$')
end
M.dump_node_text = function(target)
log.debug('=============================')
for node in target:iter_children() do
local node_type = node:type()
local text = ts_utils.get_node_text(node)
log.debug("type:" .. node_type .. " ")
local text = M.get_node_text(node)
log.debug('type:' .. node_type .. ' ')
log.debug(text)
end
log.debug('=============================')