mirror of
https://github.com/windwp/nvim-ts-autotag.git
synced 2024-12-29 13:39:15 -06:00
fix #60
This commit is contained in:
parent
0339338316
commit
044a05c4c5
@ -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
|
||||
|
@ -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('=============================')
|
||||
|
Loading…
Reference in New Issue
Block a user