fix: register null-ls providers per filetype (#1709)

This commit is contained in:
kylo252 2021-10-08 08:57:11 +02:00 committed by GitHub
parent 68d2678af3
commit f4899e3165
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 15 deletions

View file

@ -23,7 +23,7 @@ function M.list_available(filetype)
return formatters return formatters
end end
function M.list_configured(formatter_configs) function M.list_configured(formatter_configs, filetype)
local formatters, errors = {}, {} local formatters, errors = {}, {}
for _, fmt_config in ipairs(formatter_configs) do for _, fmt_config in ipairs(formatter_configs) do
@ -39,7 +39,11 @@ function M.list_configured(formatter_configs)
errors[fmt_config.exe] = {} -- Add data here when necessary errors[fmt_config.exe] = {} -- Add data here when necessary
else else
Log:debug("Using formatter: " .. formatter_cmd) Log:debug("Using formatter: " .. formatter_cmd)
formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args } formatters[fmt_config.exe] = formatter.with {
command = formatter_cmd,
extra_args = fmt_config.args,
filetypes = { filetype },
}
end end
end end
end end
@ -52,9 +56,8 @@ function M.setup(formatter_configs, filetype)
return return
end end
local formatters_by_ft = {} local formatters_by_ft = M.list_configured(formatter_configs, filetype)
formatters_by_ft[filetype] = M.list_configured(formatter_configs) null_ls.register { sources = formatters_by_ft.supported }
null_ls.register { sources = formatters_by_ft[filetype].supported }
end end
return M return M

View file

@ -13,12 +13,12 @@ function M:setup()
null_ls.config() null_ls.config()
require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup)
for _, filetype in pairs(lvim.lang) do for filetype, config in pairs(lvim.lang) do
if filetype.formatters then if not vim.tbl_isempty(config.formatters) then
formatters.setup(filetype.formatters, filetype) formatters.setup(config.formatters, filetype)
end end
if filetype.linters then if not vim.tbl_isempty(config.linters) then
linters.setup(filetype.linters, filetype) linters.setup(config.linters, filetype)
end end
end end
end end

View file

@ -23,7 +23,7 @@ function M.list_available(filetype)
return linters return linters
end end
function M.list_configured(linter_configs) function M.list_configured(linter_configs, filetype)
local linters, errors = {}, {} local linters, errors = {}, {}
for _, lnt_config in pairs(linter_configs) do for _, lnt_config in pairs(linter_configs) do
@ -39,7 +39,11 @@ function M.list_configured(linter_configs)
errors[lnt_config.exe] = {} -- Add data here when necessary errors[lnt_config.exe] = {} -- Add data here when necessary
else else
Log:debug("Using linter: " .. linter_cmd) Log:debug("Using linter: " .. linter_cmd)
linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args } linters[lnt_config.exe] = linter.with {
command = linter_cmd,
extra_args = lnt_config.args,
filetypes = { filetype },
}
end end
end end
end end
@ -52,9 +56,8 @@ function M.setup(linter_configs, filetype)
return return
end end
local linters_by_ft = {} local linters_by_ft = M.list_configured(linter_configs, filetype)
linters_by_ft[filetype] = M.list_configured(linter_configs) null_ls.register { sources = linters_by_ft.supported }
null_ls.register { sources = linters_by_ft[filetype].supported }
end end
return M return M