Skip to content

Commit 2554533

Browse files
committed
fix: regression and error handling
1 parent 147c792 commit 2554533

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lua/dim.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ local dim = {}
22
local util = {}
33

44
local ts = vim.treesitter
5-
local _, ts_utils = pcall(require, "nvim-treesitter.ts_utils")
5+
local ok, ts_utils = pcall(require, "nvim-treesitter.ts_utils")
6+
7+
local ts_highlighter = ts.highlighter
8+
---@type (fun(node: TSNode, line: integer, col: integer): boolean) | false
9+
local ts_is_in_node_range = ts.is_in_node_range or (ok and ts_utils.is_in_node_range)
610

711
------------------------
812
--## UTIL FUNCTIONS ##--
@@ -85,7 +89,7 @@ function util.get_treesitter_hl(row, col)
8589
end, matches)
8690
end
8791

88-
local self = ts.highlighter.active[buf]
92+
local self = ts_highlighter.active[buf]
8993
if not self then
9094
return {}
9195
end
@@ -115,7 +119,7 @@ function util.get_treesitter_hl(row, col)
115119
for capture, node, _ in iter do
116120
local hl = query.hl_cache[capture]
117121

118-
if hl and ts_utils and ts_utils.node_in_range(node, row, col) or ts.is_in_node_range(node, row, col) then
122+
if hl and ts_is_in_node_range and ts_is_in_node_range(node, row, col) then
119123
local c = query._query.captures[capture] -- name of the capture in the query
120124
if c ~= nil then
121125
local general_hl = query:_get_hl_from_capture(capture)

0 commit comments

Comments
 (0)