1
1
local M = {}
2
2
3
- local INITIAL_UUID = 999999999999
3
+ local INITIAL_UID = 1
4
+ local MAX_UID = 2 ^ 32 - 1
4
5
local DIAGNOSTIC_NAMESPACE = vim .api .nvim_create_namespace (" TinyInlineDiagnostic" )
5
6
6
7
local state = {
7
- uuid_counter = INITIAL_UUID ,
8
+ uid_counter = INITIAL_UID ,
8
9
skip_lines = {
9
10
count = 0 ,
10
11
start_line = 0 ,
@@ -18,12 +19,12 @@ local function is_valid_buffer(buf)
18
19
end
19
20
20
21
--- @return number
21
- local function generate_uuid ()
22
- state .uuid_counter = state .uuid_counter - 1
23
- if state .uuid_counter < 0 then
24
- state .uuid_counter = INITIAL_UUID
22
+ local function generate_uid ()
23
+ state .uid_counter = state .uid_counter + 1
24
+ if state .uid_counter > MAX_UID then
25
+ state .uid_counter = INITIAL_UID
25
26
end
26
- return state .uuid_counter
27
+ return state .uid_counter
27
28
end
28
29
29
30
--- @return { row : number , col : number }
@@ -54,7 +55,7 @@ local function set_extmark(buf, line, virt_text, win_col, priority, pos)
54
55
end
55
56
56
57
vim .api .nvim_buf_set_extmark (buf , DIAGNOSTIC_NAMESPACE , line , 0 , {
57
- id = generate_uuid (),
58
+ id = generate_uid (),
58
59
line_hl_group = line == 0 and " TinyInlineDiagnosticVirtualTextBg" or nil ,
59
60
virt_text_pos = pos or " eol" ,
60
61
virt_text = virt_text ,
@@ -76,7 +77,7 @@ local function create_multiline_extmark(buf, curline, virt_lines, priority)
76
77
end
77
78
78
79
vim .api .nvim_buf_set_extmark (buf , DIAGNOSTIC_NAMESPACE , curline , 0 , {
79
- id = curline + 1000 ,
80
+ id = generate_uid () ,
80
81
virt_text_pos = " eol" ,
81
82
virt_text = virt_lines [1 ],
82
83
virt_lines = remaining_lines ,
@@ -91,7 +92,7 @@ local function handle_under_cursor_case(buf, curline, virt_lines, buf_lines_coun
91
92
end
92
93
93
94
vim .api .nvim_buf_set_extmark (buf , DIAGNOSTIC_NAMESPACE , curline + 1 , 0 , {
94
- id = generate_uuid (),
95
+ id = generate_uid (),
95
96
virt_text_pos = " overlay" ,
96
97
virt_text_win_col = 0 ,
97
98
virt_text = virt_lines [2 ],
@@ -121,7 +122,7 @@ local function handle_overflow_case(buf, curline, virt_lines, win_col, offset, p
121
122
122
123
if # overflow_lines > 0 then
123
124
vim .api .nvim_buf_set_extmark (buf , DIAGNOSTIC_NAMESPACE , buf_lines_count - 1 , 0 , {
124
- id = generate_uuid (),
125
+ id = generate_uid (),
125
126
virt_lines_above = false ,
126
127
virt_lines = overflow_lines ,
127
128
priority = priority ,
@@ -216,12 +217,12 @@ end
216
217
217
218
--- @param opts DiagnosticConfig
218
219
--- @param event table
219
- --- @param curline number
220
+ --- @param diag_line number
220
221
--- @param virt_lines table
221
222
--- @param offset number
222
223
--- @param need_to_be_under boolean
223
224
--- @param virt_priority number
224
- function M .create_extmarks (opts , event , curline , virt_lines , offset , need_to_be_under , virt_priority )
225
+ function M .create_extmarks (opts , event , diag_line , virt_lines , offset , need_to_be_under , virt_priority )
225
226
if not is_valid_buffer (event .buf ) then
226
227
return
227
228
end
@@ -239,32 +240,35 @@ function M.create_extmarks(opts, event, curline, virt_lines, offset, need_to_be_
239
240
end
240
241
241
242
-- Handle multiline mode
242
- if opts .options .multilines and curline ~= cursor_line then
243
- if should_skip_line (curline ) then
243
+ if opts .options .multilines and diag_line ~= cursor_line then
244
+ if should_skip_line (diag_line ) then
244
245
return
245
246
end
246
- create_multiline_extmark (event .buf , curline , virt_lines , virt_priority )
247
+ create_multiline_extmark (event .buf , diag_line , virt_lines , virt_priority )
248
+
249
+ state .skip_lines .count = 0
250
+ state .skip_lines .start_line = diag_line
247
251
return
248
252
end
249
253
250
254
state .skip_lines .count = # virt_lines
251
- state .skip_lines .start_line = curline
255
+ state .skip_lines .start_line = diag_line
252
256
253
257
-- Handle under-cursor case
254
258
if need_to_be_under then
255
- handle_under_cursor_case (event .buf , curline , virt_lines , buf_lines_count , virt_priority )
259
+ handle_under_cursor_case (event .buf , diag_line , virt_lines , buf_lines_count , virt_priority )
256
260
table.remove (virt_lines , 2 )
257
261
win_col = 0
258
- if curline < buf_lines_count - 1 then
259
- curline = curline + 1
262
+ if diag_line < buf_lines_count - 1 then
263
+ diag_line = diag_line + 1
260
264
end
261
265
end
262
266
263
267
-- Handle overflow case
264
- if curline - 1 + # virt_lines > buf_lines_count - 1 then
265
- handle_overflow_case (event .buf , curline , virt_lines , win_col , offset , virt_priority , buf_lines_count )
268
+ if diag_line - 1 + # virt_lines > buf_lines_count - 1 then
269
+ handle_overflow_case (event .buf , diag_line , virt_lines , win_col , offset , virt_priority , buf_lines_count )
266
270
else
267
- handle_normal_case (event .buf , curline , virt_lines , win_col , offset , virt_priority )
271
+ handle_normal_case (event .buf , diag_line , virt_lines , win_col , offset , virt_priority )
268
272
end
269
273
end
270
274
0 commit comments