diff --git a/plugins/by-name/whichpy/default.nix b/plugins/by-name/whichpy/default.nix new file mode 100644 index 00000000..386f1101 --- /dev/null +++ b/plugins/by-name/whichpy/default.nix @@ -0,0 +1,56 @@ +{ + lib, + config, + ... +}: +lib.nixvim.plugins.mkNeovimPlugin { + name = "whichpy"; + packPathName = "whichpy.nvim"; + package = "whichpy-nvim"; + + maintainers = [ lib.maintainers.wvffle ]; + + settingsExample = { + update_path_env = true; + locator = { + workspace.depth = 3; + uv.enable = true; + }; + }; + + extraOptions = { + neotestIntegration = lib.mkEnableOption "neotest-integration for whichpy-nvim."; + }; + + extraConfig = cfg: { + plugins.neotest.adapters.python.settings = lib.mkIf cfg.neotestIntegration { + python = lib.nixvim.mkRaw '' + function() + local whichpy_python = require("whichpy.envs").current_selected() + if whichpy_python then + return whichpy_python + end + return require("neotest-python.base").get_python_command + end + ''; + }; + + warnings = lib.nixvim.mkWarnings "plugins.whichpy" [ + { + when = cfg.neotestIntegration && !config.plugins.neotest.enable; + message = '' + You have enabled the neotest integration with whichpy but `plugins.neotest` is not enabled. + ''; + } + { + when = + cfg.neotestIntegration + && config.plugins.neotest.enable + && !config.plugins.neotest.adapters.python.enable; + message = '' + You have enabled the neotest integration with whichpy but `plugins.neotest.adapters.python` is not enabled. + ''; + } + ]; + }; +} diff --git a/tests/test-sources/plugins/by-name/whichpy/default.nix b/tests/test-sources/plugins/by-name/whichpy/default.nix new file mode 100644 index 00000000..09449a50 --- /dev/null +++ b/tests/test-sources/plugins/by-name/whichpy/default.nix @@ -0,0 +1,85 @@ +{ + empty = { + plugins.whichpy.enable = true; + }; + + defaults = { + plugins.whichpy = { + enable = true; + + settings = { + cache_dir.__raw = "vim.fn.stdpath('cache') .. '/whichpy.nvim'"; + update_path_env = false; + after_handle_select = null; + picker = { + name = "builtin"; + }; + locator = { + workspace = { + display_name = "Workspace"; + search_pattern = ".*env.*"; + depth = 2; + ignore_dirs = [ + ".git" + ".mypy_cache" + ".pytest_cache" + ".ruff_cache" + "__pycache__" + "__pypackages__" + ]; + }; + global = { + display_name = "Global"; + }; + global_virtual_environment = { + display_name = "Global Virtual Environment"; + dirs = [ + "~/envs" + "~/.direnv" + "~/.venvs" + "~/.virtualenvs" + "~/.local/share/virtualenvs" + [ + "~/Envs" + "Windows_NT" + ] + { __raw = "vim.env.WORKON_HOME"; } + ]; + }; + pyenv = { + display_name = "Pyenv"; + venv_only = true; + }; + poetry = { + display_name = "Poetry"; + }; + pdm = { + display_name = "PDM"; + }; + conda = { + display_name = "Conda"; + }; + }; + lsp = { + pylsp.__raw = "require('whichpy.lsp.handlers.pylsp').new()"; + pyright.__raw = "require('whichpy.lsp.handlers.pyright').new()"; + basedpyright.__raw = "require('whichpy.lsp.handlers.pyright').new()"; + }; + }; + }; + }; + + example = { + plugins.whichpy = { + enable = true; + + settings = { + update_path_env = true; + locator = { + workspace.depth = 3; + uv.enable = true; + }; + }; + }; + }; +}