summaryrefslogtreecommitdiffstats
path: root/modules/plugins/debugger/nvim-dap/nvim-dap.nix
blob: 53783791a3dd19340e3c93f0d40308f682d390d4 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
{
  config,
  lib,
  ...
}: let
  inherit (lib.options) mkEnableOption mkOption;
  inherit (lib.types) bool attrsOf str submodule anything either enum listOf nullOr int addCheck;
  inherit (lib.nvim.types) mkPluginSetupOption luaInline;
  inherit (lib.nvim.lua) isLuaInline;
  inherit (config.vim.lib) mkMappingOption;

  adapterSubmodule = submodule {
    freeformType = attrsOf anything;
    options = {
      type = mkOption {
        type = enum ["executable" "server" "pipe"];
        description = "Type of adapter";
      };

      # executable

      command = mkOption {
        type = nullOr str;
        default = null;
        description = "Command to invoke";
      };

      args = mkOption {
        type = nullOr (listOf str);
        default = null;
        description = "Argument to the command";
      };

      # server

      host = mkOption {
        type = nullOr str;
        default = null;
        defaultText = "127.0.0.1"; # plugin default
        description = "Host to connect to";
      };

      port = mkOption {
        type = nullOr (either int (enum ["\${port}"]));
        default = null;
        description = ''
          Port to connect to. Use "''${port}" for a dynamically resolved free
          port. This is intended to be used with executable.args.
        '';
      };

      # pipe

      pipe = mkOption {
        type = nullOr str;
        default = null;
        description = ''
          Absolute path to the pipe file. Use \"''${pipe}\" for a dynamically
          generated temporary filename
        '';
      };
    };
  };

  adapterType = let
    submod = addCheck adapterSubmodule (x: !(isLuaInline x));
  in
    (either luaInline submod)
    // {
      getSubOptions = prefix: submod.getSubOptions prefix;
      inherit (submod) getSubModules;
      substSubModules = _: adapterType;
    };

  configurationType = submodule {
    freeformType = attrsOf anything;
    # These 3 options are required, everything else is passed to the debug
    # adapter
    options = {
      type = mkOption {
        type = str;
        description = "Which debug adapter to use";
      };

      request = mkOption {
        type = enum ["attach" "launch"];
        description = ''
          Indicates whether the debug adapter should launch a debuggee or attach
          to one that is already running.
        '';
      };

      name = mkOption {
        type = str;
        description = "A user-readable name for the configuration";
      };
    };
  };
in {
  options.vim.debugger.nvim-dap = {
    enable = mkEnableOption "debugging via nvim-dap";

    ui = {
      enable = mkEnableOption "UI extension for nvim-dap";

      setupOpts = mkPluginSetupOption "nvim-dap-ui" {};

      autoStart = mkOption {
        type = bool;
        default = true;
        description = ''
          Automatically Opens and Closes DAP-UI upon starting/closing a
          debugging session
        '';
      };
    };

    sources = mkOption {
      default = {};
      description = "List of debuggers to install";
      type = attrsOf str;
    };

    adapters = mkOption {
      type = attrsOf adapterType;
      default = {};
      description = "Adapter configurations. See `:help dap-adapter`";
    };

    configurations = mkOption {
      type = attrsOf (listOf configurationType);
      default = {};
      description = ''
        Mapping of filetype to list of debuggee configurations.

        See `:help dap-configuration`.
      '';
    };

    mappings = {
      continue = mkMappingOption "Continue" "<leader>dc";
      restart = mkMappingOption "Restart" "<leader>dR";
      terminate = mkMappingOption "Terminate" "<leader>dq";
      runLast = mkMappingOption "Re-run Last Debug Session" "<leader>d.";

      toggleRepl = mkMappingOption "Toggle Repl" "<leader>dr";
      hover = mkMappingOption "Hover" "<leader>dh";
      toggleBreakpoint = mkMappingOption "Toggle breakpoint" "<leader>db";

      runToCursor = mkMappingOption "Continue to the current cursor" "<leader>dgc";
      stepInto = mkMappingOption "Step into function" "<leader>dgi";
      stepOut = mkMappingOption "Step out of function" "<leader>dgo";
      stepOver = mkMappingOption "Next step" "<leader>dgj";
      stepBack = mkMappingOption "Step back" "<leader>dgk";

      goUp = mkMappingOption "Go up stacktrace" "<leader>dvo";
      goDown = mkMappingOption "Go down stacktrace" "<leader>dvi";

      toggleDapUI = mkMappingOption "Toggle DAP-UI" "<leader>du";
    };
  };
}