null-ls.nvim
null-ls.nvim copied to clipboard
diagnostics source for asyncapi
Issues
- [X] I have checked existing issues and there are no existing ones with the same request.
Feature description
Diagnostics source for the asyncapi CLI.
Help
Yes
Implementation help
I have an implementation of this in my personal dotfiles, so I will drop that here in case someone else wants to use it as a base for patching it into null-ls.
If not, I plan on carving out some time to add this patch.
{
name = "asyncapi",
method = require("null-ls.methods").internal.DIAGNOSTICS,
filetypes = { "yaml" },
generator = null_ls.generator {
command = "asyncapi",
args = { "validate", "$FILENAME", "--diagnostics-format", "json" },
format = "json_raw",
to_stdin = false,
ignore_stderr = true,
to_temp_file = true,
on_output = function(params)
local h = require("null-ls.helpers")
local severities = {
h.diagnostics.severities.error,
h.diagnostics.severities.warning,
h.diagnostics.severities.info,
}
params.messages = {}
local output = vim.split(params.output, "\n", { trimempty = true })
local json = vim.fn.join { unpack(output, 2) }
for _, message in ipairs(vim.json.decode(json)) do
table.insert(params.messages, {
row = message.range.start.line + 1,
col = message.range.start.character + 1,
end_row = message.range["end"].line + 1,
end_col = message.range["end"].character + 1,
message = message.message,
severity = severities[message.severity],
filename = params.bufname,
})
end
return params.messages
end,
},
},