Skip to content

Commit a3a0dce

Browse files
authored
Merge pull request #22 from kapral18/feat/add-new-ts-support
feat: add new ts support
2 parents e7d7428 + 2554533 commit a3a0dce

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lua/dim.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
local dim = {}
22
local util = {}
33

4-
local highlighter = require("vim.treesitter.highlighter")
5-
local ts_utils = require("nvim-treesitter.ts_utils")
4+
local ts = vim.treesitter
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 = 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.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)