summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/lsp/null-ls/formatters.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-10-05 08:46:35 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-10-05 08:46:35 +0200
commit77cdf208765ad351e48724ed5ad57e55703eca61 (patch)
tree7f19757b255ab66895d9240a5aca77a35cef8aac /.config/nvim/lua/lsp/null-ls/formatters.lua
parent4fd170aa9d55b7bcd1f0a9445c9e136b560e3220 (diff)
Add major update to LSP from lunarvim
Diffstat (limited to '.config/nvim/lua/lsp/null-ls/formatters.lua')
-rw-r--r--.config/nvim/lua/lsp/null-ls/formatters.lua38
1 files changed, 12 insertions, 26 deletions
diff --git a/.config/nvim/lua/lsp/null-ls/formatters.lua b/.config/nvim/lua/lsp/null-ls/formatters.lua
index 651d6f1..0d3505f 100644
--- a/.config/nvim/lua/lsp/null-ls/formatters.lua
+++ b/.config/nvim/lua/lsp/null-ls/formatters.lua
@@ -1,29 +1,14 @@
local M = {}
-local formatters_by_ft = {}
local null_ls = require "null-ls"
local services = require "lsp.null-ls.services"
-local Log = require("core.log")
-
-local function list_names(formatters, option)
- option = option or {}
- local filter = option.filter or "supported"
-
- return vim.tbl_keys(formatters[filter])
-end
+local Log = require "core.log"
function M.list_supported_names(filetype)
- if not formatters_by_ft[filetype] then
- return {}
- end
- return list_names(formatters_by_ft[filetype], { filter = "supported" })
-end
-
-function M.list_unsupported_names(filetype)
- if not formatters_by_ft[filetype] then
- return {}
- end
- return list_names(formatters_by_ft[filetype], { filter = "unsupported" })
+ local null_ls_methods = require "null-ls.methods"
+ local formatter_method = null_ls_methods.internal["FORMATTING"]
+ local registered_providers = services.list_registered_providers_names(filetype)
+ return registered_providers[formatter_method] or {}
end
function M.list_available(filetype)
@@ -45,15 +30,15 @@ function M.list_configured(formatter_configs)
local formatter = null_ls.builtins.formatting[fmt_config.exe]
if not formatter then
- Log:error("Not a valid formatter:" .. fmt_config.exe)
+ Log:error("Not a valid formatter: " .. fmt_config.exe)
errors[fmt_config.exe] = {} -- Add data here when necessary
else
local formatter_cmd = services.find_command(formatter._opts.command)
if not formatter_cmd then
- Log:warn("Not found:" .. formatter._opts.command)
+ Log:warn("Not found: " .. formatter._opts.command)
errors[fmt_config.exe] = {} -- Add data here when necessary
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,
@@ -65,12 +50,13 @@ function M.list_configured(formatter_configs)
return { supported = formatters, unsupported = errors }
end
-function M.setup(filetype, option)
- if not options.lang[filetype] or (formatters_by_ft[filetype] and not option.force_reload) then
+function M.setup(formatter_configs, filetype)
+ if vim.tbl_isempty(formatter_configs) then
return
end
- formatters_by_ft[filetype] = M.list_configured(options.lang[filetype].formatters)
+ local formatters_by_ft = {}
+ formatters_by_ft[filetype] = M.list_configured(formatter_configs)
null_ls.register { sources = formatters_by_ft[filetype].supported }
end