nvim: add debug adapter config
Anirudh Oppiliappan x@icyphox.sh
Wed, 01 Nov 2023 14:55:19 +0200
7 files changed,
145 insertions(+),
30 deletions(-)
M
config/nvim/_init.lua
→
config/nvim/_init.lua
@@ -21,6 +21,7 @@ require 'lsp.rust'
-- plugins not in nixpkgs require 'packer'.startup(function(use) - use 'kana/vim-textobj-user' use 'preservim/vim-textobj-quote' end) + +require 'dapx'
M
config/nvim/lua/completion.lua
→
config/nvim/lua/completion.lua
@@ -61,14 +61,14 @@ { name = 'luasnip' }
} }) -cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'path' } - }, { - { name = 'cmdline' } - }) -}) +-- cmp.setup.cmdline(':', { +-- mapping = cmp.mapping.preset.cmdline(), +-- sources = cmp.config.sources({ +-- { name = 'path' } +-- }, { +-- { name = 'cmdline' } +-- }) +-- }) local capabilities = require('cmp_nvim_lsp').default_capabilities() require('lspconfig')['gopls'].setup {
A
config/nvim/lua/dapx.lua
@@ -0,0 +1,91 @@
+local dap = require 'dap' + +dap.set_log_level('INFO') + +dap.configurations.go = { + { + type = "go", + name = "Debug", + request = "launch", + program = "${file}", + }, +} + +dap.adapters.go = { + type = "server", + port = "${port}", + executable = { + command = 'dlv', + args = { "dap", "-l", "127.0.0.1:${port}" }, + }, +} + +require 'dap-go'.setup { + dap_configurations = { + { + type = "go", + name = "Debug (main.go)", + request = "launch", + program = "${workspaceFolderBasename}/cmd/main.go", + }, + }, +} + +require 'dapui'.setup({ + controls = { + element = "repl", + enabled = true, + icons = { + disconnect = "■", + pause = "", + play = "▶", + run_last = "≪", + step_back = "←", + step_into = "↓", + step_out = "↑", + step_over = "→", + terminate = "✗" + } + }, + icons = { expanded = "▾", collapsed = "▸" }, + mappings = { + open = "o", + remove = "d", + edit = "e", + repl = "r", + toggle = "t", + }, + layouts = { + { + elements = { + "scopes", + }, + size = 0.2, + position = "left" + }, + { + elements = { + "repl", + "breakpoints" + }, + size = 0.3, + position = "bottom", + }, + }, + floating = { + max_height = nil, + max_width = nil, + border = "single", + mappings = { + close = { "q", "<Esc>" }, + }, + }, + windows = { indent = 1 }, + render = { + max_type_length = nil, + }, +}) + +vim.fn.sign_define('DapBreakpoint', {text = '•'}) + +require 'dapui.config.highlights'.setup()
M
config/nvim/lua/maps.lua
→
config/nvim/lua/maps.lua
@@ -1,5 +1,6 @@
local cmd = vim.cmd local map = vim.keymap.set +local dap = require 'dap' local u = require 'utils' local M = {}@@ -78,22 +79,18 @@
-- lspconfig function M.on_attach(client, bufnr) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end - local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', options) buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', options) buf_set_keymap('n', 'ga', '<Cmd>lua vim.lsp.buf.code_action()<CR>', options) buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', options) + buf_set_keymap('n', 'L', '<Cmd>lua vim.lsp.buf.signature_help()<CR>', options) buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', options) buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', options) buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', options) buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', options) - - if client.server_capabilities.document_formatting then - buf_set_keymap('n', 'ff', '<cmd>lua vim.lsp.buf.format()<CR>', options) - elseif client.server_capabilities.document_range_formatting then - buf_set_keymap('n', 'ff', '<cmd>lua vim.lsp.buf.range_formatting()<CR>', options) - end + map('n', 'ff', function() + vim.lsp.buf.format { async = true } + end) end -- vim.api.nvim_exec([[@@ -111,5 +108,32 @@ do
table.insert(stars, star) u.iabbrev(n .. '*', table.concat(stars)) end + + +-- dap +-- Start debugging session +map("n", "<leader>ds", function() + dap.continue() + require 'dapui'.toggle() + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-w>=", false, true, true), "n", false) -- Spaces buffers evenly +end) + +-- Set breakpoints, get variable values, step into/out of functions, etc. +map("n", "<leader>dl", require("dap.ui.widgets").hover) +map("n", "<leader>dc", dap.continue) +map("n", "<leader>db", dap.toggle_breakpoint) +map("n", "<leader>dn", dap.step_over) +map("n", "<leader>di", dap.step_into) +map("n", "<leader>do", dap.step_out) +map("n", "<leader>dC", dap.clear_breakpoints) + +-- Close debugger and clear breakpoints +map("n", "<leader>de", function() + dap.clear_breakpoints() + require 'dapui'.toggle() + dap.terminate() + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-w>=", false, true, true), "n", false) +end) + return M
M
config/nvim/lua/settings.lua
→
config/nvim/lua/settings.lua
@@ -87,7 +87,7 @@ end,
}) -- unknown files are 'text' -autocmd('BufNewFile,BufRead', { +autocmd({'BufNewFile', 'BufRead'}, { pattern = '*', callback = function() if vim.bo.filetype == "" then@@ -97,7 +97,7 @@ end,
}) -- keymap files are dts -autocmd('BufEnter,BufNewFile,BufRead', { +autocmd({'BufEnter','BufNewFile','BufRead'}, { pattern = '*.keymap', callback = function() vim.bo.filetype = 'dts'@@ -105,7 +105,7 @@ end
}) -- vim-textobj-quote only in ~/docs/writing -autocmd('BufEnter,BufNewFile,BufRead', { +autocmd({'BufEnter','BufNewFile','BufRead'}, { pattern = '*.md', callback = function() local cwd = vim.fn.expand('%:p')@@ -121,7 +121,7 @@ end
}) -- mdx files are markdown -autocmd('BufEnter,BufNewFile,BufRead', { +autocmd({'BufEnter','BufNewFile','BufRead'}, { pattern = '*.mdx', callback = function() vim.bo.filetype = 'markdown'
M
nix/programs/neovim.nix
→
nix/programs/neovim.nix
@@ -16,13 +16,6 @@ nixpkgs-fmt
gotools gopls go - cargo - rust-analyzer - rustc - # nodePackages.vscode-langservers-extracted - nodePackages.typescript-language-server - nodePackages.typescript - nodePackages.eslint sumneko-lua-language-server tree-sitter-grammars.tree-sitter-bash@@ -36,6 +29,7 @@ tree-sitter-grammars.tree-sitter-vim
tree-sitter-grammars.tree-sitter-nix zf + delve ]; extraConfig = '' runtime _init.lua@@ -50,7 +44,6 @@ cmp-nvim-lsp
cmp-treesitter cmp-path - nvim-lspconfig luasnip playground@@ -62,6 +55,12 @@ nvim-treesitter-textobjects
conflict-marker-vim vim-jsonnet vim-pencil + + nvim-dap + nvim-dap-ui + nvim-dap-go + vim-textobj-user + dressing-nvim ]; }; }
M
nix/programs/tmux.nix
→
nix/programs/tmux.nix
@@ -34,7 +34,7 @@ set -g base-index 1
setw -g pane-base-index 1 # pane binds - bind -n M-n select-pane -D + bind -n M-n select-pane -D bind -n M-e select-pane -U bind -n M-y select-pane -L bind -n M-o select-pane -R