Skip to content

Commit 4e81c0a

Browse files
committed
refactor(utils)!: streamline parameters for null-ls helper functions
1 parent eeb187e commit 4e81c0a

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

lua/astroui/status/provider.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ function M.lsp_client_names(opts)
529529
{ client_id = client.id, bufname = vim.api.nvim_buf_get_name(bufnr), bufnr = bufnr, filetype = ft, ft = ft }
530530
for _, type in ipairs { "FORMATTING", "DIAGNOSTICS" } do
531531
params.method = type
532-
for _, source in ipairs(status_utils.null_ls_sources(ft, type, params)) do
532+
for _, source in ipairs(status_utils.null_ls_sources(params)) do
533533
null_ls_sources[source] = true
534534
end
535535
end

lua/astroui/status/utils.lua

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,17 @@ function M.encode_pos(line, col, winnr) return bit.bor(bit.lshift(line, 16), bit
151151
function M.decode_pos(c) return bit.rshift(c, 16), bit.band(bit.rshift(c, 6), 1023), bit.band(c, 63) end
152152

153153
--- Get a list of registered null-ls providers for a given filetype
154-
---@param filetype string the filetype to search null-ls for
155-
---@param params table? optional parameters to use for checking `runtime_condition`
154+
---@param params table parameters to use for null-ls providers
156155
---@return table # a table of null-ls sources
157-
function M.null_ls_providers(filetype, params)
156+
function M.null_ls_providers(params)
158157
local registered = {}
159158
-- try to load null-ls
160159
local sources_avail, sources = pcall(require, "null-ls.sources")
161160
if sources_avail then
162161
-- get the available sources of a given filetype
163-
for _, source in ipairs(sources.get_available(filetype)) do
162+
for _, source in ipairs(sources.get_available(params.filetype)) do
164163
-- get each source name
165-
local runtime_condition = params and vim.tbl_get(source, "generator", "opts", "runtime_condition")
164+
local runtime_condition = vim.tbl_get(source, "generator", "opts", "runtime_condition")
166165
for method in pairs(source.methods) do
167166
local source_activated = true
168167
if runtime_condition then -- try to calculate runtime_condition with supported parameters
@@ -182,13 +181,11 @@ function M.null_ls_providers(filetype, params)
182181
end
183182

184183
--- Get the null-ls sources for a given null-ls method
185-
---@param filetype string the filetype to search null-ls for
186-
---@param method string the null-ls method (check null-ls documentation for available methods)
187-
---@param params table? optional parameters to use for checking `runtime_condition`
184+
---@param params table parameters to use for checking null-ls sources
188185
---@return string[] # the available sources for the given filetype and method
189-
function M.null_ls_sources(filetype, method, params)
186+
function M.null_ls_sources(params)
190187
local methods_avail, methods = pcall(require, "null-ls.methods")
191-
return methods_avail and M.null_ls_providers(filetype, params)[methods.internal[method]] or {}
188+
return methods_avail and M.null_ls_providers(params)[methods.internal[params.method]] or {}
192189
end
193190

194191
--- A helper function for decoding statuscolumn click events with mouse click pressed, modifier keys, as well as which signcolumn sign was clicked if any

0 commit comments

Comments
 (0)