2022-01-12 17:21:57 +00:00
|
|
|
local M = {}
|
|
|
|
local utils = require("utils")
|
|
|
|
|
2022-01-12 22:56:08 +00:00
|
|
|
local function disable_formatter_filetypes_for_existing_servers(sources, preserve)
|
|
|
|
-- Aggregate filetypes with language servers
|
|
|
|
local server_filetypes = {}
|
|
|
|
utils.try_require("lspconfig", function(lsp_config)
|
2023-06-02 00:11:50 +00:00
|
|
|
local available_servers
|
|
|
|
if lsp_config["util"] and lsp_config.util["available_servers"] then
|
|
|
|
available_servers = lsp_config.util.available_servers()
|
|
|
|
else
|
2023-11-15 17:22:17 +00:00
|
|
|
-- HACK: For lspconfig versions lower than 0.1.4, which is required for nvim <0.7.0
|
2023-06-02 00:11:50 +00:00
|
|
|
available_servers = lsp_config.available_servers()
|
|
|
|
end
|
2022-01-12 22:56:08 +00:00
|
|
|
vim.tbl_map(function(server)
|
2022-09-08 19:23:41 +00:00
|
|
|
if lsp_config[server].filetypes ~= nil then
|
|
|
|
vim.list_extend(server_filetypes, lsp_config[server].filetypes)
|
|
|
|
end
|
2023-06-02 00:11:50 +00:00
|
|
|
end, available_servers)
|
2022-01-12 22:56:08 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- Remove filetypes for formatters I want to preserve
|
|
|
|
server_filetypes = vim.tbl_filter(function(ft)
|
|
|
|
return not vim.tbl_contains(preserve or {}, ft)
|
|
|
|
end, server_filetypes)
|
|
|
|
|
2022-01-22 05:21:54 +00:00
|
|
|
local NULL_LS_FORMATTING = require("null-ls").methods.FORMATTING
|
2022-01-12 17:21:57 +00:00
|
|
|
|
2022-01-12 22:56:08 +00:00
|
|
|
-- Apply with statement to all filtered formatters to disable filetypes
|
2022-01-22 05:21:54 +00:00
|
|
|
sources = vim.tbl_map(function(builtin)
|
|
|
|
if
|
|
|
|
builtin.method == NULL_LS_FORMATTING
|
2023-06-09 19:10:55 +00:00
|
|
|
or (type(builtin.method) == "table" and vim.tbl_contains(builtin.method, NULL_LS_FORMATTING))
|
2022-01-22 05:21:54 +00:00
|
|
|
then
|
|
|
|
return builtin.with({ disabled_filetypes = server_filetypes })
|
|
|
|
end
|
|
|
|
|
|
|
|
return builtin
|
|
|
|
end, sources)
|
2022-01-12 17:21:57 +00:00
|
|
|
|
2022-01-12 22:56:08 +00:00
|
|
|
return sources
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.configure(options)
|
|
|
|
utils.try_require("null-ls", function(null_ls)
|
2022-01-12 17:21:57 +00:00
|
|
|
local sources = {
|
|
|
|
-- Generic
|
|
|
|
null_ls.builtins.formatting.prettier,
|
|
|
|
null_ls.builtins.formatting.trim_whitespace,
|
|
|
|
null_ls.builtins.formatting.trim_newlines,
|
2023-06-13 23:47:03 +00:00
|
|
|
-- Ansible
|
|
|
|
null_ls.builtins.diagnostics.ansiblelint.with({ filetypes = { "yaml.ansible" } }),
|
2022-01-12 17:21:57 +00:00
|
|
|
-- Fish
|
|
|
|
null_ls.builtins.formatting.fish_indent,
|
|
|
|
-- Python
|
|
|
|
null_ls.builtins.formatting.reorder_python_imports,
|
|
|
|
null_ls.builtins.formatting.black,
|
|
|
|
null_ls.builtins.diagnostics.mypy,
|
|
|
|
-- Go
|
|
|
|
null_ls.builtins.diagnostics.golangci_lint,
|
|
|
|
-- Text
|
|
|
|
null_ls.builtins.code_actions.proselint,
|
|
|
|
null_ls.builtins.diagnostics.proselint,
|
2023-06-13 23:47:03 +00:00
|
|
|
null_ls.builtins.diagnostics.alex,
|
2022-03-01 00:32:42 +00:00
|
|
|
null_ls.builtins.diagnostics.write_good.with({
|
|
|
|
extra_args = { "--no-adverb" },
|
|
|
|
diagnostics_postprocess = function(diagnostic)
|
|
|
|
diagnostic.severity = vim.diagnostic.severity.WARN
|
|
|
|
end,
|
|
|
|
}),
|
2022-01-12 17:21:57 +00:00
|
|
|
-- Shell
|
|
|
|
null_ls.builtins.diagnostics.shellcheck,
|
|
|
|
-- Lua
|
|
|
|
null_ls.builtins.diagnostics.luacheck,
|
|
|
|
null_ls.builtins.formatting.stylua,
|
|
|
|
-- Docker
|
|
|
|
null_ls.builtins.diagnostics.hadolint,
|
|
|
|
}
|
|
|
|
|
2023-06-13 23:14:25 +00:00
|
|
|
sources = disable_formatter_filetypes_for_existing_servers(sources, { "python", "lua" })
|
2022-01-12 22:35:07 +00:00
|
|
|
|
|
|
|
-- Setup or configure null_ls
|
2023-06-13 23:47:03 +00:00
|
|
|
options.sources = sources
|
|
|
|
null_ls.setup(options)
|
2022-01-12 17:21:57 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|