Skip to content

Commit

Permalink
♻ Refactor keymap of dap
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen-Hoang-Nam committed Jan 2, 2022
1 parent 8ace846 commit 8defa7a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lua/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local utils_core = require('utils.core')
local format = require('format')
local dap = require('dap')
local goto_preview = require('goto-preview')
local utils_dap = require('utils.dap')

local options = { noremap = true }
local cmd_options = { noremap = true, silent = true }
Expand Down Expand Up @@ -46,15 +47,13 @@ map('n', '<Leader>e', [[<Cmd>lua require('telescope.builtin').symbols{ sources =

map('n', '<Leader>g', '', cmd_option(utils_core.git_hover))

map('n', '<Leader>1', '', cmd_option(require('jdtls.dap').setup_dap_main_class_configs))
map('n', '<Leader>2', '', cmd_option(dap.continue))
map('n', '<Leader>3', '', cmd_option(dap.disconnect))
map('n', '<Leader>4', '', cmd_option(dap.step_over))
map('n', '<Leader>5', '', cmd_option(dap.step_into))
map('n', '<Leader>6', '', cmd_option(dap.step_out))
map('n', '<Leader>0', '', cmd_option(utils_dap.toggle_breakpoint))
map('n', '<Leader>1', '', cmd_option(utils_dap.toggle_debug))
map('n', '<Leader>2', '', cmd_option(dap.step_over))
map('n', '<Leader>3', '', cmd_option(dap.step_into))
map('n', '<Leader>4', '', cmd_option(dap.step_out))
map('n', '<Leader>8', [[<Cmd>lua require'dapui'.float_element("scopes")<CR>]], cmd_options)
map('n', '<Leader>9', [[<Cmd>lua require'dapui'.toggle("sidebar")<CR>]], cmd_options)
map('n', '<Leader>0', '', cmd_option(dap.toggle_breakpoint))

map('n', '<Leader>/', [[<Cmd>CommentToggle<CR>]], cmd_options)
map('v', '<Leader>/', [[:CommentToggle<CR>]], cmd_options)
Expand Down
31 changes: 31 additions & 0 deletions lua/utils/dap.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local dap = require('dap')
local jdtls_dap = require('jdtls.dap')

local M = {}

M.breakpoint = false
M.debug = false

function M.toggle_breakpoint()
if not M.breakpoint then
if vim.bo.filetype == 'java' then
jdtls_dap.setup_dap_main_class_configs()
end

M.breakpoint = true
end

dap.toggle_breakpoint()
end

function M.toggle_debug()
if not M.debug then
M.debug = true
dap.continue()
else
M.debug = false
dap.disconnect()
end
end

return M

0 comments on commit 8defa7a

Please sign in to comment.