From 147c7926138ec7f4721feb47da44f05e20be5e2c Mon Sep 17 00:00:00 2001 From: Karen Grigoryan Date: Thu, 18 Sep 2025 01:29:49 +0200 Subject: [PATCH 1/2] feat: add new ts support --- lua/dim.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/dim.lua b/lua/dim.lua index 6c0aed2..8e98ca3 100644 --- a/lua/dim.lua +++ b/lua/dim.lua @@ -1,8 +1,8 @@ local dim = {} local util = {} -local highlighter = require("vim.treesitter.highlighter") -local ts_utils = require("nvim-treesitter.ts_utils") +local ts = vim.treesitter +local _, ts_utils = pcall(require, "nvim-treesitter.ts_utils") ------------------------ --## UTIL FUNCTIONS ##-- @@ -85,7 +85,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 +115,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_utils and ts_utils.node_in_range(node, row, col) or 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) From 2554533ab520ee2d3accc5414c42a14ddb138fe5 Mon Sep 17 00:00:00 2001 From: Karen Grigoryan Date: Fri, 19 Sep 2025 07:44:52 +0200 Subject: [PATCH 2/2] fix: regression and error handling --- lua/dim.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lua/dim.lua b/lua/dim.lua index 8e98ca3..bf70eca 100644 --- a/lua/dim.lua +++ b/lua/dim.lua @@ -2,7 +2,11 @@ local dim = {} local util = {} local ts = vim.treesitter -local _, ts_utils = pcall(require, "nvim-treesitter.ts_utils") +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 = ts.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 and ts_utils.node_in_range(node, row, col) or ts.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)