diff options
| author | bee <beebeeb5k@gmail.com> | 2026-05-05 22:37:10 +0530 |
|---|---|---|
| committer | bee <beebeeb5k@gmail.com> | 2026-05-05 22:37:10 +0530 |
| commit | 9365a8e96827cbf7bc5adad6d29bcd05b4d761b2 (patch) | |
| tree | 0998a5dcfc4517e4112a2c589e04ac0dbc1e011b /lua/bee/utils/init.lua | |
| parent | 0c50f17133b90c60735f1f51943f51f60372bdd3 (diff) | |
Migrate from nixcats to nix-wrapper-modules
Diffstat (limited to 'lua/bee/utils/init.lua')
| -rw-r--r-- | lua/bee/utils/init.lua | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/lua/bee/utils/init.lua b/lua/bee/utils/init.lua new file mode 100644 index 0000000..4296561 --- /dev/null +++ b/lua/bee/utils/init.lua @@ -0,0 +1,77 @@ +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 |
