101101function M .diag_fmt (buf , lnum_start , col_start , message , severity , source , lnum_end , col_end )
102102 return {
103103 bufnr = buf ,
104- col = col_start or 0 ,
104+ col = col_start ,
105105 end_col = col_end or col_start ,
106- lnum = lnum_start or 0 ,
106+ lnum = lnum_start ,
107107 end_lnum = lnum_end or lnum_start ,
108108 message = message or ' ' ,
109109 namespace = ns ,
@@ -153,6 +153,16 @@ local function attr_value(mes, attribute)
153153 return type (attribute ) == ' function' and attribute (mes ) or mes [attribute ]
154154end
155155
156+ --- @param nr any ?
157+ --- @param off number
158+ local function normalize (nr , off )
159+ return tonumber (nr or off ) - off
160+ end
161+
162+ local function json_get_offset (mes , attr , off )
163+ return normalize (attr_value (mes , attr ), off )
164+ end
165+
156166function M .from_json (opts )
157167 opts = vim .tbl_deep_extend (' force' , from_opts , opts or {})
158168 opts = vim .tbl_deep_extend (' force' , json_opts , opts )
@@ -165,26 +175,30 @@ function M.from_json(opts)
165175 vim .tbl_map (function (line )
166176 local offence = opts .get_diagnostics (line )
167177 if offence then
168- offences [ # offences + 1 ] = offence
178+ table.insert ( offences , offence )
169179 end
170180 end , vim .split (result , ' \r ?\n ' , { trimempty = true }))
171181 else
172182 offences = opts .get_diagnostics (result )
173183 end
174184
185+ local attr = opts .attributes
186+ local off = opts .offset
175187 vim .tbl_map (function (mes )
176- local attr = opts .attributes
177188 local message = attr_value (mes , attr .message )
178189 local code = attr_value (mes , attr .code )
179- diags [# diags + 1 ] = M .diag_fmt (
180- buf ,
181- tonumber (attr_value (mes , attr .lnum )) - opts .offset ,
182- tonumber (attr_value (mes , attr .col )) - opts .offset ,
183- formulate_msg (message , code ),
184- opts .severities [attr_value (mes , attr .severity )],
185- opts .source ,
186- tonumber (attr_value (mes , attr .lnum_end or attr .lnum )) - opts .offset ,
187- tonumber (attr_value (mes , attr .col_end or attr .lnum )) - opts .offset
190+ table.insert (
191+ diags ,
192+ M .diag_fmt (
193+ buf ,
194+ json_get_offset (mes , attr .lnum , off ),
195+ json_get_offset (mes , attr .col , off ),
196+ formulate_msg (message , code ),
197+ opts .severities [attr_value (mes , attr .severity )],
198+ opts .source ,
199+ json_get_offset (mes , attr .lnum_end or attr .lnum , off ),
200+ json_get_offset (mes , attr .col_end or attr .col , off )
201+ )
188202 )
189203 end , offences or {})
190204
@@ -212,20 +226,24 @@ function M.from_regex(opts)
212226 offence [opts .groups [i ]] = matches [i ]
213227 end
214228
215- offences [ # offences + 1 ] = offence
229+ table.insert ( offences , offence )
216230 end
217231 end
218232
233+ local off = opts .offset
219234 vim .tbl_map (function (mes )
220- diags [# diags + 1 ] = M .diag_fmt (
221- buf ,
222- tonumber (mes .lnum ) - opts .offset ,
223- tonumber (mes .col ) - opts .offset ,
224- formulate_msg (mes .message , mes .code ),
225- opts .severities [mes .severity ],
226- opts .source ,
227- tonumber (mes .lnum_end or mes .lnum ) - opts .offset ,
228- tonumber (mes .col_end or mes .col ) - opts .offset
235+ table.insert (
236+ diags ,
237+ M .diag_fmt (
238+ buf ,
239+ normalize (mes .lnum , off ),
240+ normalize (mes .col , off ),
241+ formulate_msg (mes .message , mes .code ),
242+ opts .severities [mes .severity ],
243+ opts .source ,
244+ normalize (mes .lnum_end or mes .lnum , off ),
245+ normalize (mes .col_end or mes .lnum , off )
246+ )
229247 )
230248 end , offences )
231249
0 commit comments