diff --git a/lua/dim.lua b/lua/dim.lua index 6c0aed2..bf70eca 100644 --- a/lua/dim.lua +++ b/lua/dim.lua @@ -1,8 +1,12 @@ local dim = {} local util = {} -local highlighter = require("vim.treesitter.highlighter") -local ts_utils = require("nvim-treesitter.ts_utils") +local ts = vim.treesitter +local ok, ts_utils = pcall(require, "nvim-treesitter.ts_utils") + +local ts_highlighter = ts.highlighter +---@type (fun(node: TSNode, line: integer, col: integer): boolean) | false +local ts_is_in_node_range = ts.is_in_node_range or (ok and ts_utils.is_in_node_range) ------------------------ --## UTIL FUNCTIONS ##-- @@ -85,7 +89,7 @@ function util.get_treesitter_hl(row, col) end, matches) end - local self = highlighter.active[buf] + local self = ts_highlighter.active[buf] if not self then return {} end @@ -115,7 +119,7 @@ function util.get_treesitter_hl(row, col) for capture, node, _ in iter do local hl = query.hl_cache[capture] - if hl and ts_utils.is_in_node_range(node, row, col) then + if hl and ts_is_in_node_range and ts_is_in_node_range(node, row, col) then local c = query._query.captures[capture] -- name of the capture in the query if c ~= nil then local general_hl = query:_get_hl_from_capture(capture)