Add neovim-dap and configure it for go

Should probably put it in a separate file, TODO
This commit is contained in:
Bad 2021-10-19 22:14:27 +02:00
parent 9202c932ad
commit 3f2f33c19c

View file

@ -31,6 +31,91 @@
plugin = iceberg-vim;
config = "colorscheme iceberg";
}
{
plugin = nvim-dap;
config = ''
lua <<EOF
local dap = require'dap'
dap.adapters.go = function(callback, config)
local stdout = vim.loop.new_pipe(false)
local handle
local pid_or_err
local port = 38697
local opts = {
stdio = {nil, stdout},
args = {"dap", "-l", "127.0.0.1:" .. port},
detached = true
}
handle, pid_or_err = vim.loop.spawn("dlv", opts, function(code)
stdout:close()
handle:close()
if code ~= 0 then
print('dlv exited with code', code)
end
end)
assert(handle, 'Error running dlv: ' .. tostring(pid_or_err))
stdout:read_start(function(err, chunk)
assert(not err, err)
if chunk then
vim.schedule(function()
require('dap.repl').append(chunk)
end)
end
end)
-- Wait for delve to start
vim.defer_fn(
function()
callback({type = "server", host = "127.0.0.1", port = port})
end,
100)
end
-- https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md
dap.configurations.go = {
-- works with go.mod packages and sub packages
{
type = "go",
name = "Debug (go.mod)",
request = "launch",
program = "''${workspaceFolder}"
},
{
type = "go",
name = "Debug test (go.mod)",
request = "launch",
mode = "test",
program = "''${workspaceFolder}"
},
{
type = "go",
name = "Debug",
request = "launch",
program = "''${file}"
},
{
type = "go",
name = "Debug test", -- configuration for debugging test files
request = "launch",
mode = "test",
program = "''${file}"
},
}
EOF
nnoremap <silent> <F5> :lua require'dap'.continue()<CR>
nnoremap <silent> <F10> :lua require'dap'.step_over()<CR>
nnoremap <silent> <F11> :lua require'dap'.step_into()<CR>
nnoremap <silent> <F12> :lua require'dap'.step_out()<CR>
nnoremap <silent> <leader>b :lua require'dap'.toggle_breakpoint()<CR>
nnoremap <silent> <leader>B :lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR>
nnoremap <silent> <leader>lp :lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR>
nnoremap <silent> <leader>dr :lua require'dap'.repl.open()<CR>
nnoremap <silent> <leader>dl :lua require'dap'.run_last()<CR>
'';
}
{
plugin = nvim-dap-ui;
config = "lua require('dapui').setup()";
}
vim-sleuth
vim-nix
pkgs.go-fold-if-err-nil