summaryrefslogtreecommitdiffstats
path: root/modules/plugins/debugger/nvim-dap/presets/debugpy.nix
blob: c2e81d8f99e0c0077d6a9a3f297b795190007ab1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
  lib,
  pkgs,
  config,
  ...
}: let
  inherit (lib.modules) mkIf;
  inherit (lib.generators) mkLuaInline;
  inherit (lib.meta) getExe;
  inherit (lib.nvim.types) mkDapPresetEnableOption;

  cfg = config.vim.debugger.nvim-dap.presets.debugpy;
  package = pkgs.python3.withPackages (ps: with ps; [debugpy]);
in {
  options.vim.debugger.nvim-dap.presets.debugpy = {
    enable = mkDapPresetEnableOption {
      option = "debugpy";
      display = "`debugpy`";
      extra = ''
        See <https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings>
        for supported options.
      '';
    };
  };

  config.vim.debugger.nvim-dap.adapters = mkIf cfg.enable {
    debugpy = mkLuaInline ''
      function(cb, config)
        if config.request == "attach" then
          local port = (config.connect or config).port
          local host = (config.connect or config).host or "127.0.0.1"
          cb({
            type = "server",
            port = assert(port, "`connect.port` is required for a python `attach` configuration"),
            host = host,
            options = {
              source_filetype = "python",
            },
          })
        else
          cb({
            type = "executable",
            command = "${getExe package}",
            args = { "-m", "debugpy.adapter" },
            options = {
              source_filetype = "python",
            },
          })
        end
      end
    '';
  };
}