@@ -152,18 +152,28 @@ function M.decode_pos(c) return bit.rshift(c, 16), bit.band(bit.rshift(c, 6), 10
152152
153153--- Get a list of registered null-ls providers for a given filetype
154154--- @param filetype string the filetype to search null-ls for
155+ --- @param params table ? optional parameters to use for checking ` runtime_condition`
155156--- @return table # a table of null-ls sources
156- function M .null_ls_providers (filetype )
157+ function M .null_ls_providers (filetype , params )
157158 local registered = {}
158159 -- try to load null-ls
159160 local sources_avail , sources = pcall (require , " null-ls.sources" )
160161 if sources_avail then
161162 -- get the available sources of a given filetype
162163 for _ , source in ipairs (sources .get_available (filetype )) do
163164 -- get each source name
165+ local runtime_condition = params and vim .tbl_get (source , " generator" , " opts" , " runtime_condition" )
164166 for method in pairs (source .methods ) do
165- registered [method ] = registered [method ] or {}
166- table.insert (registered [method ], source .name )
167+ local source_activated = true
168+ if runtime_condition then -- try to calculate runtime_condition with supported parameters
169+ params .source_id = vim .tbl_get (source , " generator" , " source_id" )
170+ local condition_calculated , condition = pcall (runtime_condition , params )
171+ if condition_calculated then source_activated = condition == true end
172+ end
173+ if source_activated then
174+ registered [method ] = registered [method ] or {}
175+ table.insert (registered [method ], source .name )
176+ end
167177 end
168178 end
169179 end
@@ -174,10 +184,11 @@ end
174184--- Get the null-ls sources for a given null-ls method
175185--- @param filetype string the filetype to search null-ls for
176186--- @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`
177188--- @return string[] # the available sources for the given filetype and method
178- function M .null_ls_sources (filetype , method )
189+ function M .null_ls_sources (filetype , method , params )
179190 local methods_avail , methods = pcall (require , " null-ls.methods" )
180- return methods_avail and M .null_ls_providers (filetype )[methods .internal [method ]] or {}
191+ return methods_avail and M .null_ls_providers (filetype , params )[methods .internal [method ]] or {}
181192end
182193
183194--- 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