Skip to content

Commit eca30ba

Browse files
committed
feat: expose diagnostic.code in from_json & from_regex
1 parent c1d2b66 commit eca30ba

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

lua/guard/lint.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ end
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
}
156158
end
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-
195193
local function attr_value(mes, attribute)
196194
return type(attribute) == 'function' and attribute(mes) or mes[attribute]
197195
end
@@ -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

Comments
 (0)