Can't get custom diagnostics to work #1192
-
👋🏻 I would like to create a custom diagnostics using the tool tfproviderlintx but I have a few issues...
Here is my Lua configuration for null-ls and the custom diagnostic helper (for the use { "jose-elias-alvarez/null-ls.nvim",
config = function()
local null_ls = require("null-ls")
local helpers = require("null-ls.helpers")
null_ls.setup({
sources = {
require("null-ls").builtins.diagnostics.checkmake, -- https://github.com/mrtazz/checkmake
}
})
-- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/HELPERS.md
local tfproviderlintx = {
method = null_ls.methods.DIAGNOSTICS,
filetypes = { "go" },
generator = null_ls.generator({
command = "tfproviderlintx",
args = { "-XAT001=false", "-R018=false", "$FILENAME" },
to_stdin = true,
from_stderr = true,
format = "line",
check_exit_code = function(code, stderr)
local success = code <= 1
if not success then
print(stderr)
end
return success
end,
on_output = helpers.diagnostics.from_patterns({
{
pattern = [[(^[^:]+):(\d+):(\d+):\s([^:]+):\s(.+)$]], -- https://regex101.com/r/wytcMN/1
groups = { "path", "row", "col", "message", "code", "message" },
},
}),
}),
}
null_ls.register(tfproviderlintx)
end
} I hope someone can help me understand what I'm doing wrong. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Hi @jose-elias-alvarez thanks for clarifying, so I modified the code based on what I had learnt about Lua patterns compared to regexes and it looks like I only really needed to change But I'm still not seeing the command getting run 🤔 You'll see that I even stick in a use { "jose-elias-alvarez/null-ls.nvim",
config = function()
local null_ls = require("null-ls")
local helpers = require("null-ls.helpers")
null_ls.setup({
sources = {
require("null-ls").builtins.diagnostics.checkmake, -- https://github.com/mrtazz/checkmake
}
})
-- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/HELPERS.md
local tfproviderlintx = {
name = "tfproviderlintx",
method = null_ls.methods.DIAGNOSTICS,
filetypes = { "go" },
runtime_condition = function(params)
print(params)
return true
end,
generator = null_ls.generator({
command = "tfproviderlintx",
args = { "-XAT001=false", "-R018=false", "$FILENAME" },
to_stdin = true,
from_stderr = true,
format = "line",
check_exit_code = function(code, stderr)
local success = code <= 1
if not success then
print(stderr)
end
return success
end,
on_output = helpers.diagnostics.from_patterns({
{
pattern = [[(^[^:]+):(%d+):(%d+):%s([^:]+):%s(.+)$]], -- https://regex101.com/r/wytcMN/1 (converted using non-regex Lua patterns https://www.lua.org/pil/20.2.html)
groups = { "path", "row", "col", "message", "code", "message" },
},
}),
}),
}
null_ls.register(tfproviderlintx)
end
} |
Beta Was this translation helpful? Give feedback.
-
This is the final solution: use { "jose-elias-alvarez/null-ls.nvim",
config = function()
local null_ls = require("null-ls")
local helpers = require("null-ls.helpers")
local tfproviderlintx = {
name = "tfproviderlintx",
method = null_ls.methods.DIAGNOSTICS,
filetypes = { "go" },
generator = helpers.generator_factory({
args = { "-XAT001=false", "-R018=false", "$FILENAME" },
check_exit_code = function(code, stderr)
local success = code < 1
if not success then
print(stderr)
end
return success
end,
command = "tfproviderlintx",
format = "line",
from_stderr = true,
on_output = helpers.diagnostics.from_patterns({
{
pattern = [[([^:]+):(%d+):(%d+):%s([^:]+):%s(.+)]],
groups = { "path", "row", "col", "code", "message" },
},
}),
runtime_condition = function(params)
return params.bufname:find("terraform%-provider%-") ~= nil
end,
to_stdin = true,
}),
}
null_ls.setup({
sources = {
tfproviderlintx,
require("null-ls").builtins.diagnostics.checkmake,
}
})
end
} |
Beta Was this translation helpful? Give feedback.
This is the final solution: