Bruno BELANYI
dc27b59912
Since `none-ls` has removed their `shellcheck` built-in. This actually makes the diagnostics more robust to POSIX/non-POSIX scripts (the LSP server detects it at runtime, which is more robust than the `ftdetect` scripts). Nice bonus: the shellcheck code is shown in the diagnostics message without any configuration! I'm not sure if I can configure `avoid-nullary-conditions` -- though it seems like this check is broken at the moment (I couldn't get it to trigger during my tests).
89 lines
2.7 KiB
Lua
89 lines
2.7 KiB
Lua
local null_ls = require("null-ls")
|
|
local lsp = require("ambroisie.lsp")
|
|
local utils = require("ambroisie.utils")
|
|
|
|
null_ls.setup({
|
|
on_attach = lsp.on_attach,
|
|
})
|
|
|
|
-- Bazel
|
|
null_ls.register({
|
|
null_ls.builtins.diagnostics.buildifier.with({
|
|
-- Only used if available
|
|
condition = utils.is_executable_condition("buildifier"),
|
|
}),
|
|
null_ls.builtins.formatting.buildifier.with({
|
|
-- Only used if available
|
|
condition = utils.is_executable_condition("buildifier"),
|
|
}),
|
|
})
|
|
|
|
-- C, C++
|
|
null_ls.register({
|
|
null_ls.builtins.formatting.clang_format.with({
|
|
-- Only used if available, but prefer clangd formatting if available
|
|
condition = function()
|
|
return utils.is_executable("clang-format") and not utils.is_executable("clangd")
|
|
end,
|
|
}),
|
|
})
|
|
|
|
-- Nix
|
|
null_ls.register({
|
|
null_ls.builtins.formatting.nixpkgs_fmt.with({
|
|
-- Only used if available, but prefer rnix if available
|
|
condition = function()
|
|
return utils.is_executable("nixpkgs-fmt")
|
|
and not utils.is_executable("rnix-lsp")
|
|
and not utils.is_executable("nil")
|
|
end,
|
|
}),
|
|
})
|
|
|
|
-- Python
|
|
null_ls.register({
|
|
null_ls.builtins.diagnostics.mypy.with({
|
|
-- Only used if available
|
|
condition = utils.is_executable_condition("mypy"),
|
|
}),
|
|
null_ls.builtins.diagnostics.pylint.with({
|
|
-- Only used if available
|
|
condition = utils.is_executable_condition("pylint"),
|
|
}),
|
|
null_ls.builtins.formatting.black.with({
|
|
extra_args = { "--fast" },
|
|
-- Only used if available
|
|
condition = utils.is_executable_condition("black"),
|
|
}),
|
|
null_ls.builtins.formatting.isort.with({
|
|
-- Only used if available
|
|
condition = utils.is_executable_condition("isort"),
|
|
}),
|
|
})
|
|
|
|
-- Shell (non-POSIX)
|
|
null_ls.register({
|
|
null_ls.builtins.formatting.shfmt.with({
|
|
-- Indent with 4 spaces, simplify the code, indent switch cases,
|
|
-- add space after redirection, use bash dialect
|
|
extra_args = { "-i", "4", "-s", "-ci", "-sr", "-ln", "bash" },
|
|
-- Restrict to bash and zsh
|
|
filetypes = { "bash", "zsh" },
|
|
-- Only used if available
|
|
condition = utils.is_executable_condition("shfmt"),
|
|
}),
|
|
})
|
|
|
|
-- Shell (POSIX)
|
|
null_ls.register({
|
|
null_ls.builtins.formatting.shfmt.with({
|
|
-- Indent with 4 spaces, simplify the code, indent switch cases,
|
|
-- add space after redirection, use POSIX
|
|
extra_args = { "-i", "4", "-s", "-ci", "-sr", "-ln", "posix" },
|
|
-- Restrict to POSIX sh
|
|
filetypes = { "sh" },
|
|
-- Only used if available
|
|
condition = utils.is_executable_condition("shfmt"),
|
|
}),
|
|
})
|