diff --git a/lua/lsp/linter.lua b/lua/lsp/linter.lua index d034bbc..60e7baa 100644 --- a/lua/lsp/linter.lua +++ b/lua/lsp/linter.lua @@ -80,7 +80,8 @@ function M:run(bufnr) input = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) end - vim.system( + local ok, resp = pcall( + vim.system, self.config.cmd, { stdin = input }, vim.schedule_wrap(function(out) @@ -105,16 +106,18 @@ function M:run(bufnr) if not ok then utils.err(tostring(resp)) return - elseif not resp then - utils.err(("Failed to parse linter output:\n%s"):format(line)) + elseif resp then + resp.source = self.config.source + table.insert(diagnostics, resp) end - - resp.source = self.config.source - table.insert(diagnostics, resp) end vim.diagnostic.set(self.namespace, bufnr, diagnostics) end) ) + + if not ok then + utils.err(("Failed to run %s:\n%s"):format(self.config.cmd[1], resp)) + end end function M:init(bufnr) diff --git a/lua/lsp/server.lua b/lua/lsp/server.lua index 13d4e61..ec127da 100644 --- a/lua/lsp/server.lua +++ b/lua/lsp/server.lua @@ -190,7 +190,12 @@ function M:on_attach(client, bufnr) keymap:init(self, bufnr) if self.linters then 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