summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/nvim-dap.lua
blob: 5a6d1ae2a9b76b6ecf49f9588ebfe0bf91535c06 (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
-- Debugger
-- https://github.com/mfussenegger/nvim-dap
return {
  "mfussenegger/nvim-dap",
  event = "BufRead",
  dependencies = {
    "rcarriga/nvim-dap-ui",
    "theHamsta/nvim-dap-virtual-text",
    "nvim-telescope/telescope-dap.nvim",
    "nvim-neotest/nvim-nio"
  },
  config = function()
    local dap = require("dap")
    local dapui = require("dapui")
    local virtual_text = require("nvim-dap-virtual-text")

   dap.adapters.lldb = {
      type = 'executable',
      command = '/usr/bin/lldb-dap',
      name = 'lldb'
    }

    local lldb = {
      name = "Launch lldb",
      type = "lldb",
      request = "launch",
      program = function()
        return vim.fn.input(
          "Path to executable: ", vim.fn.getcwd() .. "/", "file"
        )
      end,
      cwd = "${workspaceFolder}",
      stopOnEntry = false,
      args = {},
      runInTerminal = false,
    }

    dap.configurations.rust = {lldb}
    dap.configurations.c = {lldb}

    dapui.setup(
      {
        controls = {
          element = "repl",
          enabled = true,
          icons = {
            disconnect = "🔗❌",
            pause = "⏸",
            play = "▶",
            run_last = "⏭",
            step_back = "↶",
            step_into = "↓",
            step_out = "↑",
            step_over = "↷",
            terminate = "⏹"
          }
        },
        element_mappings = {},
        expand_lines = true,
        floating = {
          border = "single",
          mappings = {
            close = { "q", "<Esc>" }
          }
        },
        force_buffers = true,
        icons = {
          collapsed = "",
          current_frame = "",
          expanded = ""
        },
        layouts = {
          {
            elements = {
              {
                id = "scopes",
                size = 0.25
              },
              {
                id = "breakpoints",
                size = 0.25
              },
              {
                id = "stacks",
                size = 0.25
              },
              {
                id = "watches",
                size = 0.25
              }
            },
            position = "left",
            size = 40
          },
          {
            elements = {
              {
                id = "repl",
                size = 0.5
              },
              {
                id = "console",
                size = 0.5
              }
            },
            position = "bottom",
            size = 10
          }
        },
        mappings = {
          edit = "e",
          expand = { "<CR>", "<2-LeftMouse>" },
          open = "o",
          remove = "d",
          repl = "r",
          toggle = "t"
        },
        render = {
          indent = 1,
          max_value_lines = 100
        }
      }
    )

    virtual_text.setup()

    vim.api.nvim_create_user_command(
      "Debug",
      function()
        dapui.toggle()
      end,
      {}
    )
    vim.keymap.set('n', "<Leader>b", dap.toggle_breakpoint, {})
    vim.keymap.set('n', "<F2>", dap.continue, {})
    vim.keymap.set('n', "<F3>", dap.step_over, {})
    vim.keymap.set('n', "<F4>", dap.step_back, {})
    vim.keymap.set('n', "<F5>", dap.step_into, {})
    vim.keymap.set('n', "<F6>", dap.step_out, {})
    vim.keymap.set('n', "<Leader>n", dap.restart, {})
  end
}