@@ -52,6 +52,57 @@ conds.is_endwise_node = function(nodes)
55+conds.is_in_range = function(callback, position)
57+ type(callback) == 'function' and type(position) == 'function',
58+ 'callback and position should be a function'
60+ return function(opts)
61+ log.debug('is_in_range')
62+ if not parsers.has_parser() then
65+ local cursor = position()
67+ type(cursor) == 'table' and #cursor == 2,
68+ 'position should be return a table like {line, col}'
70+ local line = cursor[1]
71+ local col = cursor[2]
74+ local root_lang_tree = parsers.get_parser(bufnr)
75+ local lang_tree = root_lang_tree:language_for_range({ line, col, line, col })
79+ for _, tree in ipairs(lang_tree:trees()) do
80+ local root = tree:root()
81+ if root and ts_utils.is_in_node_range(root, line, col) then
82+ local node = root:named_descendant_for_range(line, col, line, col)
83+ local anonymous_node = root:descendant_for_range(
92+ lang = lang_tree:lang(),
94+ cursor = vim.api.nvim_win_get_cursor(0),
95+ line = vim.api.nvim_buf_get_lines(bufnr, line, line + 1, true)[1],
96+ range = { node:range() },
97+ anonymous = anonymous_node:type(),
102+ return callback(result)
55conds.is_ts_node = function(nodes)
106conds.is_ts_node = function(nodes)
56 if type(nodes) == 'string' then nodes = {nodes} end
107 if type(nodes) == 'string' then nodes = {nodes} end
57 assert(nodes ~= nil, "ts nodes should be string or table")
108 assert(nodes ~= nil, "ts nodes should be string or table")