This repository has been archived by the owner on Aug 12, 2023. It is now read-only.
Is there a way to restart null-ls with a new configuration? #1397
-
I use git-worktree.nvim. When I change the active worktree, my null-ls source configuration can be different from the previous cwd or worktree. I would like to automatically restart null-ls when I change the active worktree to account for this. Is there an easy way to restart null-ls? Here is why my source can be different in different working directories: local function file_contains_text(file_name, text)
-- vim returns 0 for false, but that is truthy in lua
if vim.fn.filereadable(file_name) == 0 then
return false
end
local matching_line_count_string = vim.fn.system("cat " .. file_name .. " | grep '" .. text .. "' | wc -l")
local converted_ok, matching_line_count = pcall(tonumber, matching_line_count_string)
return converted_ok and matching_line_count >= 1
end
local function local_rubocop_source()
local null_ls = require "null-ls"
return null_ls.builtins.diagnostics.rubocop.with({
command = { "bundle", "exec", "rubocop" }
})
end
local function default_rubocop_source()
local null_ls = require "null-ls"
return null_ls.builtins.diagnostics.rubocop
end
local function rubocop_source()
local file_name = "Gemfile.lock"
local search_string = "^ rubocop "
local gemfile_has_rubocop = file_contains_text(file_name, search_string)
if gemfile_has_rubocop then
return local_rubocop_source()
else
return default_rubocop_source()
end
end
return function(config)
config.sources = {
rubocop_source()
}
return config
end |
Beta Was this translation helpful? Give feedback.
Answered by
jose-elias-alvarez
Feb 13, 2023
Replies: 1 comment 1 reply
-
No, there's no way to do this now. See #859 which describes a workaround. As I mention there, I'm open to a PR that makes this possible without significant additional complexity. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
brandoncc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No, there's no way to do this now. See #859 which describes a workaround. As I mention there, I'm open to a PR that makes this possible without significant additional complexity.