2022-02-25 10:38:52 +01:00
|
|
|
local null_ls = require("null-ls")
|
2022-03-08 20:20:22 +01:00
|
|
|
local lsp = require("ambroisie.lsp")
|
2022-03-01 11:20:50 +01:00
|
|
|
local utils = require("ambroisie.utils")
|
|
|
|
|
2022-02-25 10:38:52 +01:00
|
|
|
null_ls.setup({
|
2022-03-08 20:20:22 +01:00
|
|
|
on_attach = lsp.on_attach,
|
2022-02-25 10:38:52 +01:00
|
|
|
})
|
2022-03-01 11:20:50 +01:00
|
|
|
|
|
|
|
-- C, C++
|
|
|
|
null_ls.register({
|
|
|
|
null_ls.builtins.formatting.clang_format.with({
|
2022-03-02 20:25:42 +01:00
|
|
|
-- 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,
|
2022-03-01 11:20:50 +01:00
|
|
|
}),
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Haskell
|
|
|
|
null_ls.register({
|
|
|
|
null_ls.builtins.formatting.brittany.with({
|
|
|
|
-- Only used if available
|
|
|
|
condition = utils.is_executable_condition("brittany"),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Nix
|
|
|
|
null_ls.register({
|
|
|
|
null_ls.builtins.formatting.nixpkgs_fmt.with({
|
2022-03-04 14:21:28 +01:00
|
|
|
-- Only used if available, but prefer rnix if available
|
|
|
|
condition = function()
|
|
|
|
return utils.is_executable("nixpkgs-fmt") and not utils.is_executable("rnix-lsp")
|
|
|
|
end,
|
2022-03-01 11:20:50 +01:00
|
|
|
}),
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Python
|
|
|
|
null_ls.register({
|
|
|
|
null_ls.builtins.diagnostics.flake8.with({
|
2022-03-11 14:30:24 +01:00
|
|
|
-- Only used if available, but prefer pflake8 if available
|
|
|
|
condition = function()
|
|
|
|
return utils.is_executable("flake8") and not utils.is_executable("pflake8")
|
|
|
|
end,
|
|
|
|
}),
|
|
|
|
null_ls.builtins.diagnostics.pyproject_flake8.with({
|
2022-03-01 11:20:50 +01:00
|
|
|
-- Only used if available
|
2022-03-11 14:30:24 +01:00
|
|
|
condition = utils.is_executable_condition("pflake8"),
|
2022-03-01 11:20:50 +01:00
|
|
|
}),
|
|
|
|
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({
|
2022-03-04 12:44:46 +01:00
|
|
|
null_ls.builtins.code_actions.shellcheck.with({
|
|
|
|
-- Restrict to bash and zsh
|
|
|
|
filetypes = { "bash", "zsh" },
|
|
|
|
-- Only used if available
|
|
|
|
condition = utils.is_executable_condition("shellcheck"),
|
|
|
|
}),
|
2022-03-01 11:20:50 +01:00
|
|
|
null_ls.builtins.diagnostics.shellcheck.with({
|
|
|
|
-- Show error code in message
|
|
|
|
diagnostics_format = "[#{c}] #{m}",
|
|
|
|
-- Require explicit empty string test, use bash dialect
|
|
|
|
extra_args = { "-s", "bash", "-o", "avoid-nullary-conditions" },
|
|
|
|
-- Restrict to bash and zsh
|
|
|
|
filetypes = { "bash", "zsh" },
|
|
|
|
-- Only used if available
|
|
|
|
condition = utils.is_executable_condition("shellcheck"),
|
|
|
|
}),
|
|
|
|
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({
|
2022-03-04 12:44:46 +01:00
|
|
|
null_ls.builtins.code_actions.shellcheck.with({
|
2023-05-06 19:58:30 +02:00
|
|
|
-- Restrict to POSIX sh
|
2022-03-04 12:44:46 +01:00
|
|
|
filetypes = { "sh" },
|
|
|
|
-- Only used if available
|
|
|
|
condition = utils.is_executable_condition("shellcheck"),
|
|
|
|
}),
|
2022-03-01 11:20:50 +01:00
|
|
|
null_ls.builtins.diagnostics.shellcheck.with({
|
|
|
|
-- Show error code in message
|
|
|
|
diagnostics_format = "[#{c}] #{m}",
|
|
|
|
-- Require explicit empty string test
|
|
|
|
extra_args = { "-o", "avoid-nullary-conditions" },
|
|
|
|
-- Restrict to POSIX sh
|
|
|
|
filetypes = { "sh" },
|
|
|
|
-- Only used if available
|
|
|
|
condition = utils.is_executable_condition("shellcheck"),
|
|
|
|
}),
|
|
|
|
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" },
|
|
|
|
-- Only used if available
|
|
|
|
condition = utils.is_executable_condition("shfmt"),
|
|
|
|
}),
|
|
|
|
})
|