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
No known key found for this signature in database
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
end
function M.list_configured(formatter_configs)
function M.list_configured(formatter_configs, filetype)
local formatters, errors = {}, {}
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
else
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
@ -52,9 +56,8 @@ function M.setup(formatter_configs, filetype)
return
end
local formatters_by_ft = {}
formatters_by_ft[filetype] = M.list_configured(formatter_configs)
null_ls.register { sources = formatters_by_ft[filetype].supported }
local formatters_by_ft = M.list_configured(formatter_configs, filetype)
null_ls.register { sources = formatters_by_ft.supported }
end
return M