local M = {} local nixInfo = _G.nixInfo or function(default, ...) return default end function M.get_nix_plugin_path(name) if vim.g.nix_info_plugin_name then return nixInfo(nil, "plugins", "lazy", name) or nixInfo(nil, "plugins", "start", name) else return vim.api.nvim_get_runtime_file("pack/*/*/" .. name, false)[1] end end function M.lsp_ft_fallback(name) local nvimlspcfg = M.get_nix_plugin_path("nvim-lspconfig") if not nvimlspcfg then local matches = vim.api.nvim_get_runtime_file("pack/*/*/nvim-lspconfig", false) nvimlspcfg = assert(matches[1], "nvim-lspconfig not found!") end vim.api.nvim_create_user_command("LspGetFiletypesToClipboard", function(opts) local lspname = assert(opts.fargs[1] or vim.fn.getreg("+") or name, "no name to search for provided or in clipboard") local ok, lspcfg = pcall(dofile, nvimlspcfg .. "/lsp/" .. lspname .. ".lua") if not ok or not lspcfg then error("failed to get config for lsp: " .. lspname) end vim.fn.setreg("+", "filetypes = " .. vim.inspect(lspcfg.filetypes or {}) .. ",") end, { nargs = "?" }) vim.schedule(function() vim.notify((name or "lsp") .. " not provided filetype", vim.log.levels.WARN) end) return name and dofile(nvimlspcfg .. "/lsp/" .. name .. ".lua").filetypes or {} end M.auto_enable_handler = { spec_field = "auto_enable", set_lazy = false, modify = function(plugin) if vim.g.nix_info_plugin_name then if type(plugin.auto_enable) == "table" then for _, name in pairs(plugin.auto_enable) do if not M.get_nix_plugin_path(name) then plugin.enabled = false break end end elseif type(plugin.auto_enable) == "string" then if not M.get_nix_plugin_path(plugin.auto_enable) then plugin.enabled = false end elseif type(plugin.auto_enable) == "boolean" and plugin.auto_enable then if not M.get_nix_plugin_path(plugin.name) then plugin.enabled = false end end end return plugin end, } M.for_cat_handler = { spec_field = "for_cat", set_lazy = false, modify = function(plugin) if vim.g.nix_info_plugin_name then if type(plugin.for_cat) == "table" then plugin.enabled = nixInfo(plugin.for_cat.default, "settings", "cats", plugin.for_cat.cat) elseif type(plugin.for_cat) == "string" then plugin.enabled = nixInfo(false, "settings", "cats", plugin.for_cat) end end return plugin end, } return M