diff --git a/lua/guard/lint.lua b/lua/guard/lint.lua index a37cca5..6bb6f15 100644 --- a/lua/guard/lint.lua +++ b/lua/guard/lint.lua @@ -141,7 +141,8 @@ end ---@param message string? ---@param severity number? ---@param source string? -function M.diag_fmt(buf, lnum_start, col_start, message, severity, source, lnum_end, col_end) +---@param code string? +function M.diag_fmt(buf, lnum_start, col_start, message, severity, source, lnum_end, col_end, code) return { bufnr = buf, col = col_start, @@ -152,6 +153,7 @@ function M.diag_fmt(buf, lnum_start, col_start, message, severity, source, lnum_ namespace = ns, severity = severity or vim.diagnostic.severity.HINT, source = source or 'Guard', + code = code, } end @@ -188,10 +190,6 @@ local json_opts = { lines = nil, } -local function formulate_msg(msg, code) - return (msg or '') .. (code and ('[%s]'):format(code) or '') -end - local function attr_value(mes, attribute) return type(attribute) == 'function' and attribute(mes) or mes[attribute] end @@ -239,11 +237,12 @@ function M.from_json(opts) buf, json_get_offset(mes, attr.lnum, off), json_get_offset(mes, attr.col, off), - formulate_msg(message, code), + message, opts.severities[attr_value(mes, attr.severity)], opts.source, json_get_offset(mes, attr.lnum_end or attr.lnum, off), - json_get_offset(mes, attr.col_end or attr.col, off) + json_get_offset(mes, attr.col_end or attr.col, off), + code ) ) end, offences or {}) @@ -282,11 +281,12 @@ function M.from_regex(opts) buf, normalize(mes.lnum, off), normalize(mes.col, off), - formulate_msg(mes.message, mes.code), + mes.message, opts.severities[mes.severity], opts.source, normalize(mes.lnum_end or mes.lnum, off), - normalize(mes.col_end or mes.lnum, off) + normalize(mes.col_end or mes.lnum, off), + mes.code ) ) end, offences) diff --git a/spec/lint_spec.lua b/spec/lint_spec.lua index 2f6516d..4e08eda 100644 --- a/spec/lint_spec.lua +++ b/spec/lint_spec.lua @@ -112,7 +112,8 @@ describe('lint module', function() end_col = 1, lnum = 1, end_lnum = 1, - message = 'Very important error message[error code 114514]', + message = 'Very important error message', + code = 'error code 114514', namespace = ns, severity = 2, }, @@ -136,7 +137,8 @@ describe('lint module', function() end_col = 1, lnum = 1, end_lnum = 1, - message = 'Very important error message[error code 114514]', + message = 'Very important error message', + code = 'error code 114514', namespace = ns, severity = 2, }, @@ -146,7 +148,8 @@ describe('lint module', function() end_col = 0, end_lnum = 0, lnum = 0, - message = 'Very important error message[warning]', + message = 'Very important error message', + code = 'warning', namespace = ns, severity = 2, source = 'mock_linter_json', diff --git a/spec/settings_spec.lua b/spec/settings_spec.lua index b41139f..52d8692 100644 --- a/spec/settings_spec.lua +++ b/spec/settings_spec.lua @@ -150,7 +150,7 @@ describe('settings', function() same(true, util.getopt('auto_lint')) vim.cmd('silent! write!') vim.wait(500) - same('Very important error message[error code 114514]', vd.get()[1].message) + same('Very important error message', vd.get()[1].message) vim.g.guard_config = { auto_lint = false } same(false, util.getopt('auto_lint'))