25
25
26
26
local function byte2pos (byte )
27
27
local line = call_function (" byte2line" , { byte })
28
- -- local col = byte - vim.api.nvim_buf_get_offset(buffer, line)
29
28
local col = byte - call_function (" line2byte" , { line })
30
29
return line , col
31
30
end
@@ -36,43 +35,44 @@ local function get_contents (buffer)
36
35
return table.concat (lines )
37
36
end
38
37
39
- local function highlight (buffer , namespace )
38
+ local function highlight (buffer , namespace , firstline )
40
39
local contents = get_contents (buffer )
41
40
local events = rust .get_offsets (contents )
42
41
for _ , event in ipairs (events ) do
43
- local sline , scol = byte2pos (event .first )
44
- local eline , ecol = byte2pos (event .last )
45
- if sline < eline then
46
- buf_add_highlight (buffer , namespace , event .group , sline - 1 , scol , - 1 )
47
- sline = sline + 1
48
- while sline < eline do
49
- buf_add_highlight (buffer , namespace , event .group , sline - 1 , 0 , - 1 )
42
+ repeat -- Allow continue in for loop
43
+ local sline , scol = byte2pos (event .first )
44
+ if sline < firstline then break end
45
+ local eline , ecol = byte2pos (event .last )
46
+ if sline < eline then
47
+ buf_add_highlight (buffer , namespace , event .group , sline - 1 , scol , - 1 )
50
48
sline = sline + 1
49
+ while sline < eline do
50
+ buf_add_highlight (buffer , namespace , event .group , sline - 1 , 0 , - 1 )
51
+ sline = sline + 1
52
+ end
53
+ buf_add_highlight (buffer , namespace , event .group , sline - 1 , 0 , ecol )
54
+ else
55
+ buf_add_highlight (buffer , namespace , event .group , sline - 1 , scol , ecol )
51
56
end
52
- buf_add_highlight (buffer , namespace , event .group , sline - 1 , 0 , ecol )
53
- else
54
- buf_add_highlight (buffer , namespace , event .group , sline - 1 , scol , ecol )
55
- end
57
+ until true
56
58
end
57
59
end
58
60
59
61
function commonmarker :detach (buffer )
60
- dump (self ._attachments )
61
62
self ._attachments [buffer ] = nil
62
63
buf_clear_namespace (buffer , self ._namespace , 0 , - 1 )
63
64
end
64
65
65
66
function commonmarker :attach (buffer )
66
67
if self ._attachments [buffer ] then return end
67
68
self ._attachments [buffer ] = true
68
- highlight (buffer , self ._namespace )
69
+ highlight (buffer , self ._namespace , 0 )
69
70
buf_attach (buffer , false , {
70
- on_lines = function (_ , _ , _ , _ , _ , _ )
71
- dump (self )
72
- buf_clear_namespace (buffer , self ._namespace , 0 , - 1 )
71
+ on_lines = function (_ , _ , _ , firstline , _ , _ )
72
+ buf_clear_namespace (buffer , self ._namespace , firstline , - 1 )
73
73
-- Returning true here detaches, we thought we should have been already
74
74
if not self ._attachments [buffer ] then return true end
75
- highlight (buffer , self ._namespace )
75
+ highlight (buffer , self ._namespace , firstline )
76
76
end ,
77
77
on_detach = function (_ )
78
78
self ._attachments [buffer ] = nil
0 commit comments