summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/custom/plugins/nvim-dap.lua
blob: 0dd44c53f28bc8aa8a2cb6daa51c2113ed1035bb (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
return {
    'mfussenegger/nvim-dap',
    dependencies = { 'williamboman/mason.nvim' },
    opts = function()
        local dap = require('dap')

        -- Setup C/C++ dap
        if not dap.adapters['codelldb'] then
            dap.adapters['codelldb'] = {
                type = 'server',
                host = 'localhost',
                port = '${port}',
                executable = {
                    command = 'codelldb',
                    args = {
                        '--port',
                        '${port}',
                    },
                },
            }
        end
        for _, lang in ipairs({ 'c', 'cpp' }) do
            dap.configurations[lang] = {
                {
                    type = 'codelldb',
                    request = 'launch',
                    name = 'Launch file',
                    program = function()
                        if vim.g.dap_codelldb_exe then
                            return vim.fn.getcwd() .. '/' .. vim.g.dap_codelldb_exe
                        end
                        return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
                    end,
                    cwd = '${workspaceFolder}',
                },
                {
                    type = 'codelldb',
                    request = 'attach',
                    name = 'Attach to process',
                    pid = require('dap.utils').pick_process,
                    cwd = '${workspaceFolder}',
                },
            }
        end
    end,
}