aboutsummaryrefslogtreecommitdiff
path: root/env/.config/nvim/after/plugin/dap.lua
blob: 6c678f7d83d526af0b245d3d21ee2945d61820e6 (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
local ok, dap = pcall(require, 'dap')
if ok then
    -- vim.api.nvim_set_hl(namespace, 'DapBreakpoint', { fg='#993939', bg='#31353f' })
    -- vim.api.nvim_set_hl(namespace, 'DapLogPoint', { fg='#61afef', bg='#31353f' })
    -- vim.api.nvim_set_hl(namespace, 'DapStopped', { fg='#98c379', bg='#31353f' })

    -- Reuse current SignColumn background (except for DapStoppedLine)
    local sign_column_hl = vim.api.nvim_get_hl(0, { name = 'SignColumn' })
    -- if bg or ctermbg aren't found, use bg = 'bg' (which means current Normal) and ctermbg = 'Black'
    -- convert to 6 digit hex value starting with #
    local sign_column_bg = (sign_column_hl.bg ~= nil) and ('#%06x'):format(sign_column_hl.bg) or 'bg'
    local sign_column_ctermbg = (sign_column_hl.ctermbg ~= nil) and sign_column_hl.ctermbg or 'Black'

    --vim.api.nvim_set_hl(0, 'DapStopped', { fg = '#00ff00', bg = sign_column_bg, ctermbg = sign_column_ctermbg })
    vim.api.nvim_set_hl(0, 'DapStopped', { fg = '#00ff00', bg = '#1e1e2e', ctermbg = sign_column_ctermbg })
    vim.api.nvim_set_hl(0, 'DapStoppedLine', { bg = '#2e4d3d', ctermbg = 'Green' })
    --vim.api.nvim_set_hl(0, 'DapBreakpoint', { fg = '#c23127', bg = sign_column_bg, ctermbg = sign_column_ctermbg })
    vim.api.nvim_set_hl(0, 'DapBreakpoint', { fg = '#c23127', bg = '#1e1e2e', ctermbg = sign_column_ctermbg })
    --vim.api.nvim_set_hl(0, 'DapBreakpointRejected', { fg = '#888ca6', bg = sign_column_bg, ctermbg = sign_column_ctermbg })
    vim.api.nvim_set_hl(0, 'DapBreakpointRejected', { fg = '#888ca6', bg = '#1e1e2e', ctermbg = sign_column_ctermbg })
    --vim.api.nvim_set_hl(0, 'DapLogPoint', { fg = '#61afef', bg = sign_column_bg, ctermbg = sign_column_ctermbg })
    vim.api.nvim_set_hl(0, 'DapLogPoint', { fg = '#61afef', bg = '#1e1e2e', ctermbg = sign_column_ctermbg })


    vim.fn.sign_define('DapBreakpoint', { text='•', texthl='DapBreakpoint', linehl='DapBreakpoint', numhl='DapBreakpoint' })
    vim.fn.sign_define('DapBreakpointCondition', { text='ﳁ', texthl='DapBreakpoint', linehl='DapBreakpoint', numhl='DapBreakpoint' })
    vim.fn.sign_define('DapBreakpointRejected', { text='', texthl='DapBreakpoint', linehl='DapBreakpoint', numhl= 'DapBreakpoint' })
    vim.fn.sign_define('DapLogPoint', { text='', texthl='DapLogPoint', linehl='DapLogPoint', numhl= 'DapLogPoint' })
    vim.fn.sign_define('DapStopped', { text='', texthl='DapStopped', linehl='DapStopped', numhl= 'DapStopped' })


    dap.configurations.rust = {
        {
            name = "Launch",
            type = "codelldb",
            request = "launch",
            program = function()
                --return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
                vim.fn.jobstart('cargo build')
                if vim.fn.expand("%:t:r") == "main" then
                    return vim.fn.getcwd() .. "/target/debug/" .. vim.fn.fnamemodify(vim.fn.getcwd(), ':t')
                else
                    return vim.fn.getcwd() .. "/target/debug/" .. vim.fn.fnameescape(vim.fn.expand("%:t:r"))
                end
            end,
            cwd = "${workspaceFolder}",
            stopOnEntry = false,
        },
    }

    dap.configurations.c = {
        {
            name = "Launch file",
            type = "codelldb",
            request = "launch",
            program = function()
                return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
                --return vim.fn.getcwd() .. "/" .. vim.fn.fnamemodify(vim.fn.getcwd(), ':t')
            end,
            cwd = '${workspaceFolder}',
            stopOnEntry = false,
            env = {
                ASAN_OPTIONS = "detect_leaks=0"
            },
        },
    }


    local ok, dapui = pcall(require, 'dapui')
    if ok then
        dapui.setup()

        vim.keymap.set("n", "<Leader>dl", function() dap.step_into() end)
        vim.keymap.set("n", "<Leader>dj", function() dap.step_over() end)
        vim.keymap.set("n", "<Leader>dk", function() dap.step_out() end)
        --vim.keymap.set("n", "<Leader>dc", function() dap.run(dap.configurations.rust[1]) end)
        vim.keymap.set("n", "<Leader>dc", function()
            local ft = vim.bo.filetype
            local configs = dap.configurations[ft]

            if type(configs) == "table" and configs[1] then
                dap.run(configs[1])
            else
                vim.notify("No DAP configuration found for filetype: " .. ft, vim.log.levels.ERROR)
            end
        end)
        vim.keymap.set("n", "<Leader>dC", function() dap.continue() end)
        vim.keymap.set("n", "<Leader>db", function() dap.toggle_breakpoint() end)
        vim.keymap.set("n", "<Leader>dB", function()
            dap.set_breakpoint(vim.fn.input('Breakpoint condition: '))
        end)
        vim.keymap.set("n", "<Leader>dd", function() dap.terminate() end)
        vim.keymap.set("n", "<Leader>dr", function() dap.run_last() end)
        --vim.keymap.set("n", "<Leader>dt", "<cmd>lua vim.cmd('RustLsp testables')<Cr>")
        vim.keymap.set("n", "<Leader>ds", function() dapui.toggle() end)

        --[[
        dap.listeners.before.attach.dapui_config = function()
            dapui.open()
        end
        dap.listeners.before.launch.dapui_config = function()
            dapui.open()
        end
        dap.listeners.before.event_terminated.dapui_config = function()
            dapui.close()
        end
        dap.listeners.before.event_exited.dapui_config = function()
            dapui.close()
        end
        ]]--
    end
end