Skip to content

Commit 3ed4bba

Browse files
committed
fix: use higher-level API to get capture names
The recent breaking change of capture-based Treesitter highlight groups [0] removed the `_get_hl_from_capture` method available on `TSHighlighterQuery`. `get_captures_at_position` should be used instead. The highlight group name is the capture name prefixed by the `@` symbol. This fixes the plugin on Neovim nightly while preserving old functionality on older versions when `get_captures_at_position` is not available. [0]: neovim/neovim#14090 (comment)
1 parent 5e35a9f commit 3ed4bba

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

lua/dim.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ end
7777
function util.get_treesitter_hl(row, col)
7878
local buf = vim.api.nvim_get_current_buf()
7979

80+
-- NOTE: use new functionality from https://github.com/neovim/neovim/issues/14090#issuecomment-1228444035
81+
if vim.treesitter.get_captures_at_position ~= nil then
82+
local matches = vim.treesitter.get_captures_at_position(buf, row, col)
83+
return vim.tbl_map(function(match)
84+
return "@" .. match.capture
85+
end, matches)
86+
end
87+
8088
local self = highlighter.active[buf]
8189
if not self then
8290
return {}

0 commit comments

Comments
 (0)