141141--- @param message string ?
142142--- @param severity number ?
143143--- @param source string ?
144- function M .diag_fmt (buf , lnum_start , col_start , message , severity , source , lnum_end , col_end )
144+ --- @param code string ?
145+ function M .diag_fmt (buf , lnum_start , col_start , message , severity , source , lnum_end , col_end , code )
145146 return {
146147 bufnr = buf ,
147148 col = col_start ,
@@ -152,6 +153,7 @@ function M.diag_fmt(buf, lnum_start, col_start, message, severity, source, lnum_
152153 namespace = ns ,
153154 severity = severity or vim .diagnostic .severity .HINT ,
154155 source = source or ' Guard' ,
156+ code = code ,
155157 }
156158end
157159
@@ -188,10 +190,6 @@ local json_opts = {
188190 lines = nil ,
189191}
190192
191- local function formulate_msg (msg , code )
192- return (msg or ' ' ) .. (code and (' [%s]' ):format (code ) or ' ' )
193- end
194-
195193local function attr_value (mes , attribute )
196194 return type (attribute ) == ' function' and attribute (mes ) or mes [attribute ]
197195end
@@ -239,11 +237,12 @@ function M.from_json(opts)
239237 buf ,
240238 json_get_offset (mes , attr .lnum , off ),
241239 json_get_offset (mes , attr .col , off ),
242- formulate_msg ( message , code ) ,
240+ message ,
243241 opts .severities [attr_value (mes , attr .severity )],
244242 opts .source ,
245243 json_get_offset (mes , attr .lnum_end or attr .lnum , off ),
246- json_get_offset (mes , attr .col_end or attr .col , off )
244+ json_get_offset (mes , attr .col_end or attr .col , off ),
245+ code
247246 )
248247 )
249248 end , offences or {})
@@ -282,11 +281,12 @@ function M.from_regex(opts)
282281 buf ,
283282 normalize (mes .lnum , off ),
284283 normalize (mes .col , off ),
285- formulate_msg ( mes .message , mes . code ) ,
284+ mes .message ,
286285 opts .severities [mes .severity ],
287286 opts .source ,
288287 normalize (mes .lnum_end or mes .lnum , off ),
289- normalize (mes .col_end or mes .lnum , off )
288+ normalize (mes .col_end or mes .lnum , off ),
289+ mes .code
290290 )
291291 )
292292 end , offences )
0 commit comments