From 6cd237d7a7b9aba04444ef458e3218207c2e8cfe Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Sat, 30 Jul 2022 10:23:07 +0800 Subject: [PATCH] feat: debugging --- cli/vim/neovim/lua/keybindings.lua | 30 ++++++++++++++++++++++++ cli/vim/neovim/lua/plugins.lua | 7 ++++++ cli/vim/neovim/lua/plugins/debugging.lua | 25 ++++++++++++++++++++ cli/vim/neovim/lua/plugins/lsp.lua | 4 +--- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 cli/vim/neovim/lua/plugins/debugging.lua diff --git a/cli/vim/neovim/lua/keybindings.lua b/cli/vim/neovim/lua/keybindings.lua index 47c614f..bfb03e4 100644 --- a/cli/vim/neovim/lua/keybindings.lua +++ b/cli/vim/neovim/lua/keybindings.lua @@ -84,3 +84,33 @@ keymap(COMMAND, '', '', { noremap = true }) -- keymap(INSERT, '', '', { noremap = true }) vim.g.AutoPairsShortcutToggle = "ap" + + +-- search and replace highlighted +keymap(VISUAL, '/', "y/\\V=escape(@\",'/\\')", { noremap = true }) +keymap(NORMAL, 'r', ':%s///g', { noremap = true }) +-- xnoremap r :s///g + +-- debugger +local dap_ok, dap = pcall(require, "dap") +if dap_ok then + vim.keymap.set('n', 'db', function() dap.toggle_breakpoint() end) + vim.keymap.set('n', 'dc', function() dap.set_breakpoint(vim.fn.input('Breakpoint condition: ')) end) + vim.keymap.set('n', '', function() dap.step_out() end) + vim.keymap.set('n', "", function() dap.step_into() end) + vim.keymap.set('n', '', function() dap.step_over() end) + vim.keymap.set('n', '', function() dap.continue() end) + vim.keymap.set('n', 'dl', function() dap.run_to_cursor() end) + vim.keymap.set('n', 'de', function() dap.terminate() end) + vim.keymap.set('n', 'dB', function() dap.clear_breakpoints() end) + -- vim.keymap.set('n', 'de', function() dap.set_exception_breakpoints({ "all" }) end) + vim.keymap.set('n', 'da', function() require "debugHelper".attach() end) + vim.keymap.set('n', 'dA', function() require "debugHelper".attachToRemote() end) + vim.keymap.set('n', 'dh', function() require "dap.ui.widgets".hover() end) + vim.keymap.set('n', 'd?', function() local w = require "dap.ui.widgets"; w.centered_float(w.scopes) end) + vim.keymap.set('n', 'dk', function() dap.up() end) + vim.keymap.set('n', 'dj', function() dap.down() end) + vim.keymap.set('n', 'dr', function() dap.repl.toggle({}, "vsplit") end) + vim.keymap.set('n', 'tds', ':Telescope dap frames') + vim.keymap.set('n', 'tdb', ':Telescope dap list_breakpoints') +end diff --git a/cli/vim/neovim/lua/plugins.lua b/cli/vim/neovim/lua/plugins.lua index 9dbd239..c084231 100644 --- a/cli/vim/neovim/lua/plugins.lua +++ b/cli/vim/neovim/lua/plugins.lua @@ -64,6 +64,12 @@ require("packer").startup(function(use) "/home/klesh/Projects/klesh/nvim-runscript", config = function() require("nvim-runscript").setup({}) end } + + + -- debugger + use 'mfussenegger/nvim-dap' + use 'leoluz/nvim-dap-go' + use 'nvim-telescope/telescope-dap.nvim' end) @@ -75,3 +81,4 @@ require("plugins/comment") require("plugins/tree") require("plugins/searchinfolder") require("plugins/treesitter") +require("plugins/debugging") diff --git a/cli/vim/neovim/lua/plugins/debugging.lua b/cli/vim/neovim/lua/plugins/debugging.lua new file mode 100644 index 0000000..926d5ba --- /dev/null +++ b/cli/vim/neovim/lua/plugins/debugging.lua @@ -0,0 +1,25 @@ +local dap_go_ok, dap_go = pcall(require, "dap-go") +if dap_go_ok then + dap_go.setup() +end + + +local dap_ok, dap = pcall(require, "dap") +if dap_ok then + dap.defaults.fallback.terminal_win_cmd = '20split new' + -- vim.fn.sign_define('DapBreakpoint', { text = '🟥', texthl = '', linehl = '', numhl = '' }) + -- vim.fn.sign_define('DapBreakpointRejected', { text = '🟦', texthl = '', linehl = '', numhl = '' }) + -- vim.fn.sign_define('DapStopped', { text = '⭐️', texthl = '', linehl = '', numhl = '' }) +end +-- dap.adapters.node2 = { +-- type = 'executable', +-- command = 'node', +-- args = {os.getenv('HOME') .. '/apps/node/out/src/nodeDebug.js'}, +-- } + +-- require('dap').set_log_level('INFO') + +local telescope_ok, telescope = pcall(require, "telescope") +if telescope_ok then + telescope.load_extension("dap") +end diff --git a/cli/vim/neovim/lua/plugins/lsp.lua b/cli/vim/neovim/lua/plugins/lsp.lua index 9e83075..8be7302 100644 --- a/cli/vim/neovim/lua/plugins/lsp.lua +++ b/cli/vim/neovim/lua/plugins/lsp.lua @@ -18,7 +18,7 @@ local language_servers = { }, diagnostics = { -- Get the language server to recognize the `vim` global - globals = { 'vim' }, + globals = { 'vim', 'root', 'client', 'awesome', 'screen', 'mouse', 'keyboardgrabber', 'mousegrabber' }, }, workspace = { -- Make the server aware of Neovim runtime files @@ -138,5 +138,3 @@ null_ls.setup({ null_ls.builtins.formatting.gofumpt, }, }) - -