mirror of
https://github.com/ViViDboarder/vim-settings.git
synced 2024-12-22 12:57:37 +00:00
Refactor null-ls again
Now building a list of filetypes that already have language servers configured and then excluding those filetypes from null-ls. There is an override where they can be forced enabled for language servers that may not have a formatter or where the null-ls formatter is preferred. Eg. Python where I want to format with black.
This commit is contained in:
parent
aef826f76b
commit
0c05f9db2a
@ -186,19 +186,13 @@ function M.config_lsp()
|
||||
utils.try_require("lspconfig", function(lsp_config)
|
||||
local capabilities = merged_capabilities()
|
||||
|
||||
-- Config null-ls
|
||||
require("plugins.null-ls").configure({ capabilities = capabilities, on_attach = get_default_attach() })
|
||||
|
||||
-- Attach options to disable formatting
|
||||
local no_format = { document_formatting = false, document_range_formatting = false }
|
||||
|
||||
-- Configure each server
|
||||
lsp_config.bashls.setup({ capabilities = capabilities, on_attach = get_default_attach() })
|
||||
lsp_config.gopls.setup({ capabilities = capabilities, on_attach = get_default_attach(no_format) })
|
||||
lsp_config.pyright.setup({ capabilities = capabilities, on_attach = get_default_attach(no_format) })
|
||||
lsp_config.gopls.setup({ capabilities = capabilities, on_attach = get_default_attach() })
|
||||
lsp_config.pyright.setup({ capabilities = capabilities, on_attach = get_default_attach() })
|
||||
lsp_config.rls.setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = get_default_attach(no_format),
|
||||
on_attach = get_default_attach(),
|
||||
settings = {
|
||||
rust = {
|
||||
build_on_save = false,
|
||||
@ -207,6 +201,9 @@ function M.config_lsp()
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- Config null-ls after lsps so we can disable for languages that have language servers
|
||||
require("plugins.null-ls").configure({ capabilities = capabilities, on_attach = get_default_attach() })
|
||||
end)
|
||||
end
|
||||
|
||||
|
@ -3,12 +3,19 @@ local utils = require("utils")
|
||||
|
||||
function M.configure(options)
|
||||
utils.try_require("null-ls", function(null_ls)
|
||||
-- Load newer versions of plugins
|
||||
local alex = require("plugins.null-ls.linters").alex
|
||||
local ansiblelint = require("plugins.null-ls.linters").ansiblelint
|
||||
-- Aggregate filetypes with language servers
|
||||
local server_filetypes = {}
|
||||
utils.try_require("lspconfig", function(lsp_config)
|
||||
vim.tbl_map(function(server)
|
||||
vim.list_extend(server_filetypes, lsp_config[server].filetypes)
|
||||
end, lsp_config.available_servers())
|
||||
end)
|
||||
|
||||
-- Use ansiblelint for only ansible files
|
||||
-- null_ls.builtins.diagnostics.ansiblelint.filetypes = { "yaml.ansible" }
|
||||
-- Remove filetypes for Language servers I want to override
|
||||
local override_filetypes = { "python" }
|
||||
server_filetypes = vim.tbl_filter(function(ft)
|
||||
return not vim.tbl_contains(override_filetypes, ft)
|
||||
end, server_filetypes)
|
||||
|
||||
local sources = {
|
||||
-- Generic
|
||||
@ -23,20 +30,15 @@ function M.configure(options)
|
||||
null_ls.builtins.diagnostics.mypy,
|
||||
-- Go
|
||||
null_ls.builtins.diagnostics.golangci_lint,
|
||||
null_ls.builtins.formatting.gofmt,
|
||||
-- Text
|
||||
null_ls.builtins.code_actions.proselint,
|
||||
null_ls.builtins.diagnostics.proselint,
|
||||
null_ls.builtins.diagnostics.write_good,
|
||||
-- null_ls.builtins.diagnostics.alex
|
||||
alex,
|
||||
-- Ansible
|
||||
-- null_ls.builtins.diagnostics.ansiblelint,
|
||||
ansiblelint,
|
||||
-- null_ls.builtins.diagnostics.ansiblelint.with({filetypes={"yaml.ansible"}}),
|
||||
-- Shell
|
||||
null_ls.builtins.diagnostics.shellcheck,
|
||||
-- Rust
|
||||
null_ls.builtins.formatting.rustfmt,
|
||||
-- Lua
|
||||
null_ls.builtins.diagnostics.luacheck,
|
||||
null_ls.builtins.formatting.stylua,
|
||||
@ -44,6 +46,18 @@ function M.configure(options)
|
||||
null_ls.builtins.diagnostics.hadolint,
|
||||
}
|
||||
|
||||
-- Map disabled filetypes onto list of sources
|
||||
vim.tbl_map(function(builtin)
|
||||
return builtin.with({ disabled_filetypes = server_filetypes })
|
||||
end, sources)
|
||||
|
||||
-- Add custom or modified sources
|
||||
vim.list_extend(sources, {
|
||||
require("plugins.null-ls.linters").alex,
|
||||
require("plugins.null-ls.linters").ansiblelint,
|
||||
})
|
||||
|
||||
-- Setup or configure null_ls
|
||||
if null_ls["setup"] ~= nil then
|
||||
options.sources = sources
|
||||
null_ls.setup(options)
|
||||
|
Loading…
Reference in New Issue
Block a user