|
| 1 | +{ |
| 2 | + lib, |
| 3 | + pkgs, |
| 4 | + ... |
| 5 | +}: |
| 6 | +let |
| 7 | + inherit (lib) |
| 8 | + optionalString |
| 9 | + types |
| 10 | + ; |
| 11 | + inherit (lib.nixvim) |
| 12 | + defaultNullOpts |
| 13 | + mkNullOrOption |
| 14 | + toLuaObject |
| 15 | + ; |
| 16 | + |
| 17 | + dapHelpers = import ../dap/dapHelpers.nix { inherit lib; }; |
| 18 | +in |
| 19 | +lib.nixvim.plugins.mkNeovimPlugin { |
| 20 | + name = "dap-python"; |
| 21 | + package = "nvim-dap-python"; |
| 22 | + |
| 23 | + maintainers = [ lib.maintainers.khaneliman ]; |
| 24 | + |
| 25 | + extraOptions = { |
| 26 | + adapterPythonPath = lib.mkOption { |
| 27 | + default = lib.getExe (pkgs.python3.withPackages (ps: [ ps.debugpy ])); |
| 28 | + defaultText = lib.literalExpression '' |
| 29 | + lib.getExe (pkgs.python3.withPackages (ps: [ ps.debugpy ])) |
| 30 | + ''; |
| 31 | + description = '' |
| 32 | + Path to the python interpreter. |
| 33 | + Path must be absolute or in $PATH and needs to have the `debugpy` package installed. |
| 34 | + ''; |
| 35 | + type = types.str; |
| 36 | + }; |
| 37 | + |
| 38 | + customConfigurations = mkNullOrOption (types.listOf dapHelpers.configurationOption) "Custom python configurations for dap."; |
| 39 | + |
| 40 | + resolvePython = defaultNullOpts.mkLuaFn null '' |
| 41 | + Function to resolve path to python to use for program or test execution. |
| 42 | + By default the `VIRTUAL_ENV` and `CONDA_PREFIX` environment variables are used if present. |
| 43 | + ''; |
| 44 | + |
| 45 | + testRunner = defaultNullOpts.mkLuaFn' { |
| 46 | + description = "The name of test runner to use by default."; |
| 47 | + pluginDefault = lib.literalMD '' |
| 48 | + The default value is dynamic and depends on `pytest.ini` or `manage.py` markers. |
| 49 | + If neither are found, `"unittest"` is used. |
| 50 | + ''; |
| 51 | + }; |
| 52 | + |
| 53 | + testRunners = mkNullOrOption (with lib.types; attrsOf strLuaFn) '' |
| 54 | + Set to register test runners. |
| 55 | +
|
| 56 | + Built-in test runners include: `unittest`, `pytest` and `django`. |
| 57 | +
|
| 58 | + The key is the test runner name, the value a function to generate the |
| 59 | + module name to run and its arguments. |
| 60 | +
|
| 61 | + See `|dap-python.TestRunner|`. |
| 62 | + ''; |
| 63 | + }; |
| 64 | + |
| 65 | + settingsOptions = { |
| 66 | + console = defaultNullOpts.mkEnumFirstDefault [ |
| 67 | + "integratedTerminal" |
| 68 | + "internalConsole" |
| 69 | + "externalTerminal" |
| 70 | + ] "Debugpy console."; |
| 71 | + |
| 72 | + includeConfigs = defaultNullOpts.mkBool true "Add default configurations."; |
| 73 | + }; |
| 74 | + |
| 75 | + # Manually supplied to nvim-dap config module |
| 76 | + callSetup = false; |
| 77 | + extraConfig = cfg: { |
| 78 | + plugins.dap = { |
| 79 | + enable = true; |
| 80 | + |
| 81 | + extensionConfigLua = |
| 82 | + '' |
| 83 | + require("dap-python").setup("${cfg.adapterPythonPath}", ${toLuaObject cfg.settings}) |
| 84 | + '' |
| 85 | + + (optionalString (cfg.testRunners != null) '' |
| 86 | + table.insert(require("dap-python").test_runners, |
| 87 | + ${toLuaObject (builtins.mapAttrs (_: lib.nixvim.mkRaw) cfg.testRunners)}) |
| 88 | + '') |
| 89 | + + (optionalString (cfg.customConfigurations != null) '' |
| 90 | + table.insert(require("dap").configurations.python, ${toLuaObject cfg.customConfigurations}) |
| 91 | + '') |
| 92 | + + (optionalString (cfg.resolvePython != null) '' |
| 93 | + require("dap-python").resolve_python = ${toLuaObject cfg.resolvePython} |
| 94 | + '') |
| 95 | + + (optionalString (cfg.testRunner != null) '' |
| 96 | + require("dap-python").test_runner = ${toLuaObject cfg.testRunner}; |
| 97 | + ''); |
| 98 | + }; |
| 99 | + }; |
| 100 | + |
| 101 | + # NOTE: Renames added in https://github.com/nix-community/nixvim/pull/2897 (2025-01-26) |
| 102 | + imports = [ ./deprecations.nix ]; |
| 103 | +} |
0 commit comments