@@ -13,27 +13,66 @@ return h.make_builtin({
1313 filetypes = { " markdown" , " tex" },
1414 generator_opts = {
1515 command = " proselint" ,
16- args = { " -- json" },
16+ args = { " check " , " --output-format= json" },
1717 format = " json" ,
1818 to_stdin = true ,
1919 check_exit_code = function (c )
2020 return c <= 1
2121 end ,
2222 on_output = function (params )
2323 local actions = {}
24- for _ , d in ipairs (params .output .data .errors ) do
25- if d .replacements ~= vim .NIL and params .row == d .line then
26- local row = d .line - 1
27- local col_beg = d .column - 1
28- local col_end = d .column + d .extent - 2
29- table.insert (actions , {
30- title = d .message ,
31- action = function ()
32- vim .api .nvim_buf_set_text (params .bufnr , row , col_beg , row , col_end , { d .replacements })
33- end ,
34- })
24+
25+ local output = params .output
26+ if not output or output .error then
27+ return actions
28+ end
29+
30+ local result = output .result
31+ if not result then
32+ return actions
33+ end
34+
35+ local buf = params .bufnr
36+ local text = table.concat (vim .api .nvim_buf_get_lines (buf , 0 , - 1 , false ), " \n " )
37+
38+ for _ , file_output in pairs (result ) do
39+ if file_output .diagnostics then
40+ for _ , d in ipairs (file_output .diagnostics ) do
41+ if d .replacements and d .replacements ~= vim .NIL then
42+ -- byte offsets (1-based)
43+ local byte_start = d .span [1 ]
44+ local byte_end = d .span [2 ]
45+
46+ -- turn into 0-based Lua string indices
47+ local sub = text :sub (byte_start , byte_end )
48+
49+ -- find the (line, col) from byte indices
50+ local before = text :sub (1 , byte_start - 1 )
51+ local line = select (2 , before :gsub (" \n " , " " )) + 1
52+ local col = # before :match (" [^\n ]*$" ) + 1
53+
54+ -- end col
55+ local length = # sub
56+ local end_col = col + length - 1
57+
58+ table.insert (actions , {
59+ title = d .message ,
60+ action = function ()
61+ vim .api .nvim_buf_set_text (
62+ buf ,
63+ line - 1 ,
64+ col - 1 ,
65+ line - 1 ,
66+ end_col ,
67+ { d .replacements }
68+ )
69+ end ,
70+ })
71+ end
72+ end
3573 end
3674 end
75+
3776 return actions
3877 end ,
3978 },
0 commit comments