@@ -2,36 +2,38 @@ local queries = require "nvim-treesitter.query"
2
2
local nsid = vim .api .nvim_create_namespace (" rainbow_ns" )
3
3
local colors = require " rainbow.colors"
4
4
5
- local function color_no (mynode )
5
+ local function color_no (mynode , len )
6
6
local counter = 0
7
7
local current = mynode
8
8
while current :parent () ~= nil do
9
9
counter = counter + 1
10
10
current = current :parent ()
11
11
end
12
- if (counter % 7 == 0 ) then
13
- return 7
12
+ if (counter % len == 0 ) then
13
+ return len
14
14
else
15
- return (counter % 7 )
15
+ return (counter % len )
16
16
end
17
17
end
18
18
19
19
local callbackfn = function (bufnr )
20
20
local matches = queries .get_capture_matches (bufnr , " @punctuation.bracket" , " highlights" )
21
21
for _ , node in ipairs (matches ) do
22
22
-- set colour for this nesting level
23
- if (node ~= nil and node .node ~= nil ) then
24
- local color_no_ = color_no (node .node )
25
- local _ , _ , endRow , endCol = node .node :range () -- range of the capture, zero-indexed
26
- vim .highlight .range (
27
- bufnr ,
28
- nsid ,
29
- (" rainbowcol" .. color_no_ ),
30
- {endRow , endCol - 1 },
31
- {endRow , endCol - 1 },
32
- " blockwise" ,
33
- true
34
- )
23
+ if node ~= nil then
24
+ if node .node ~= nil then
25
+ local color_no_ = color_no (node .node , # colors )
26
+ local _ , _ , endRow , endCol = node .node :range () -- range of the capture, zero-indexed
27
+ vim .highlight .range (
28
+ bufnr ,
29
+ nsid ,
30
+ (" rainbowcol" .. color_no_ ),
31
+ {endRow , endCol - 1 },
32
+ {endRow , endCol - 1 },
33
+ " blockwise" ,
34
+ true
35
+ )
36
+ end
35
37
end
36
38
end
37
39
end
@@ -69,12 +71,13 @@ function M.detach(bufnr)
69
71
vim .api .nvim_buf_attach (
70
72
bufnr ,
71
73
false ,
72
- {on_lines = function () return true end }
74
+ {on_lines = function ()
75
+ return true
76
+ end }
73
77
)
74
78
require " nvim-treesitter.highlight"
75
79
local hlmap = vim .treesitter .highlighter .hl_map
76
80
hlmap [" punctuation.bracket" ] = " TSPunctBracket"
77
- -- vim.cmd[[highlight link TSPunctBracket Delimiter]]
78
81
end
79
82
80
83
return M
0 commit comments