mirror of
https://github.com/ViViDboarder/vim-settings.git
synced 2024-12-22 23:07:35 +00:00
Refactor null-ls again, again
Avoid removing filetypes for non-formatters and extract into method
This commit is contained in:
parent
0c05f9db2a
commit
a307c7e930
@ -1,8 +1,7 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
|
|
||||||
function M.configure(options)
|
local function disable_formatter_filetypes_for_existing_servers(sources, preserve)
|
||||||
utils.try_require("null-ls", function(null_ls)
|
|
||||||
-- Aggregate filetypes with language servers
|
-- Aggregate filetypes with language servers
|
||||||
local server_filetypes = {}
|
local server_filetypes = {}
|
||||||
utils.try_require("lspconfig", function(lsp_config)
|
utils.try_require("lspconfig", function(lsp_config)
|
||||||
@ -11,12 +10,27 @@ function M.configure(options)
|
|||||||
end, lsp_config.available_servers())
|
end, lsp_config.available_servers())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Remove filetypes for Language servers I want to override
|
-- Remove filetypes for formatters I want to preserve
|
||||||
local override_filetypes = { "python" }
|
|
||||||
server_filetypes = vim.tbl_filter(function(ft)
|
server_filetypes = vim.tbl_filter(function(ft)
|
||||||
return not vim.tbl_contains(override_filetypes, ft)
|
return not vim.tbl_contains(preserve or {}, ft)
|
||||||
end, server_filetypes)
|
end, server_filetypes)
|
||||||
|
|
||||||
|
-- Map disabled filetypes onto list of sources
|
||||||
|
local NULL_LS_FORMATTING = require("null-ls.methods").FORMATTING
|
||||||
|
local formatters = vim.tbl_filter(function(builtin)
|
||||||
|
return builtin.METHOD == NULL_LS_FORMATTING
|
||||||
|
end, sources)
|
||||||
|
|
||||||
|
-- Apply with statement to all filtered formatters to disable filetypes
|
||||||
|
vim.tbl_map(function(builtin)
|
||||||
|
return builtin.with({ disabled_filetypes = server_filetypes })
|
||||||
|
end, formatters)
|
||||||
|
|
||||||
|
return sources
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.configure(options)
|
||||||
|
utils.try_require("null-ls", function(null_ls)
|
||||||
local sources = {
|
local sources = {
|
||||||
-- Generic
|
-- Generic
|
||||||
null_ls.builtins.formatting.prettier,
|
null_ls.builtins.formatting.prettier,
|
||||||
@ -46,10 +60,7 @@ function M.configure(options)
|
|||||||
null_ls.builtins.diagnostics.hadolint,
|
null_ls.builtins.diagnostics.hadolint,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Map disabled filetypes onto list of sources
|
disable_formatter_filetypes_for_existing_servers(sources, { "python" })
|
||||||
vim.tbl_map(function(builtin)
|
|
||||||
return builtin.with({ disabled_filetypes = server_filetypes })
|
|
||||||
end, sources)
|
|
||||||
|
|
||||||
-- Add custom or modified sources
|
-- Add custom or modified sources
|
||||||
vim.list_extend(sources, {
|
vim.list_extend(sources, {
|
||||||
|
Loading…
Reference in New Issue
Block a user