fix(linter): improve error reporting
This commit is contained in:
+9
-6
@@ -80,7 +80,8 @@ function M:run(bufnr)
|
|||||||
input = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
input = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.system(
|
local ok, resp = pcall(
|
||||||
|
vim.system,
|
||||||
self.config.cmd,
|
self.config.cmd,
|
||||||
{ stdin = input },
|
{ stdin = input },
|
||||||
vim.schedule_wrap(function(out)
|
vim.schedule_wrap(function(out)
|
||||||
@@ -105,16 +106,18 @@ function M:run(bufnr)
|
|||||||
if not ok then
|
if not ok then
|
||||||
utils.err(tostring(resp))
|
utils.err(tostring(resp))
|
||||||
return
|
return
|
||||||
elseif not resp then
|
elseif resp then
|
||||||
utils.err(("Failed to parse linter output:\n%s"):format(line))
|
resp.source = self.config.source
|
||||||
|
table.insert(diagnostics, resp)
|
||||||
end
|
end
|
||||||
|
|
||||||
resp.source = self.config.source
|
|
||||||
table.insert(diagnostics, resp)
|
|
||||||
end
|
end
|
||||||
vim.diagnostic.set(self.namespace, bufnr, diagnostics)
|
vim.diagnostic.set(self.namespace, bufnr, diagnostics)
|
||||||
end)
|
end)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not ok then
|
||||||
|
utils.err(("Failed to run %s:\n%s"):format(self.config.cmd[1], resp))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:init(bufnr)
|
function M:init(bufnr)
|
||||||
|
|||||||
+6
-1
@@ -190,7 +190,12 @@ function M:on_attach(client, bufnr)
|
|||||||
keymap:init(self, bufnr)
|
keymap:init(self, bufnr)
|
||||||
if self.linters then
|
if self.linters then
|
||||||
for _, linter in ipairs(self.linters) do
|
for _, linter in ipairs(self.linters) do
|
||||||
linter:init(bufnr)
|
local bin = linter.config.cmd[1]
|
||||||
|
if utils.is_executable(bin) then
|
||||||
|
linter:init(bufnr)
|
||||||
|
else
|
||||||
|
utils.warn(("Not adding %s because it is not installed"):format(bin))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user