@@ -8,24 +8,36 @@ local languages = {
8
8
local M = {}
9
9
10
10
function M .has_syntax (lnum , col )
11
- local col = col - 1
12
11
local bufnr = vim .api .nvim_get_current_buf ()
13
- local filetype = vim .api .nvim_buf_get_option (bufnr , ' ft' )
14
- local lang = languages [filetype ] or filetype
15
- if not require " vim.treesitter.language" .require_language (lang , nil , true ) then
16
- return false
17
- end
18
- local query = require " vim.treesitter.query" .get_query (lang , " highlights" )
19
- local tstree = vim .treesitter .get_parser (bufnr , lang ):parse ()[1 ]
20
- local tsnode = tstree :root ()
12
+ -- vim.treesitter.highlighter.hl_map was removed with Neovim 0.8.0 release.
13
+ -- see: https://github.com/neovim/neovim/pull/19931
14
+ if vim .fn .has (" nvim-0.5.0" ) == 1 and vim .fn .has (" nvim-0.8.0" ) == 0 then
15
+ local col = col - 1
16
+ local filetype = vim .api .nvim_buf_get_option (bufnr , " ft" )
17
+ local lang = languages [filetype ] or filetype
18
+ if not require (" vim.treesitter.language" ).require_language (lang , nil , true ) then
19
+ return false
20
+ end
21
+ local query = require (" vim.treesitter.query" ).get_query (lang , " highlights" )
22
+ local tstree = vim .treesitter .get_parser (bufnr , lang ):parse ()[1 ]
23
+ local tsnode = tstree :root ()
21
24
22
- for _ , match in query :iter_matches (tsnode , bufnr , lnum - 1 , lnum ) do
23
- for id , node in pairs (match ) do
24
- local _ , start_col , _ , end_col = node :range ()
25
- local name = query .captures [id ]
26
- local highlight = vim .treesitter .highlighter .hl_map [name ] or ' '
25
+ for _ , match in query :iter_matches (tsnode , bufnr , lnum - 1 , lnum ) do
26
+ for id , node in pairs (match ) do
27
+ local _ , start_col , _ , end_col = node :range ()
28
+ local name = query .captures [id ]
29
+ local highlight = vim .treesitter .highlighter .hl_map [name ]
27
30
28
- if col >= start_col and col < end_col and string.match (highlight , ' Comment' ) then
31
+ if col >= start_col and col < end_col and string.match (highlight , " Comment" ) then
32
+ return true
33
+ end
34
+ end
35
+ end
36
+ elseif vim .fn .has (" nvim-0.8.0" ) == 1 then
37
+ -- vim.treesitter.get_captures_at_pos using 0-based coordinate
38
+ local captures = vim .treesitter .get_captures_at_pos (bufnr , lnum - 1 , col - 1 )
39
+ for _ , capture in ipairs (captures ) do
40
+ if capture .capture == " comment" then
29
41
return true
30
42
end
31
43
end
0 commit comments