diff --git a/README.md b/README.md index 65b87c7..b706d2d 100644 --- a/README.md +++ b/README.md @@ -360,6 +360,8 @@ or simply put your cursor in a struct and do | GoDebug -s | stop debug session and unmap debug keymap | | GoDbgKeys | show debug keymaps in a floating window (guihua) | | GoBreakToggle | GoDebug -b | +| GoDbgStop | Same as GoDebug -s | +| GoDbgContinue | Continue debug session | | BreakCondition | conditional break | Notes: @@ -573,6 +575,7 @@ require('go').setup({ dap_debug = true, -- set to false to disable dap dap_debug_keymap = true, -- true: use keymap for debugger defined in go/dap.lua -- false: do not use keymap in go/dap.lua. you must define your own. + -- windows: use visual studio keymap dap_debug_gui = true, -- set to true to enable dap gui, highly recommand dap_debug_vt = true, -- set to true to enable dap virtual text build_tags = "tag1,tag2", -- set default build tags diff --git a/doc/go.txt b/doc/go.txt index 925b587..cf3c6b3 100644 --- a/doc/go.txt +++ b/doc/go.txt @@ -269,6 +269,12 @@ COMMANDS *go-nvim-commands* :GoDbgKeys *:GoDbgKeys* Display keymaps for debuger +:GoDbgStop *:GoDbgStop* + Stop debug session and unmap all keymaps, same as GoDebug -s + +:GoDbgContinue *:GoDbgStop* + Continue debug session, keymap `c` + :GoCreateLaunch *:GoCreateLaunch* Create alaunch.json @@ -338,6 +344,7 @@ You can setup go.nvim with following options: dap_debug_gui = true, dap_debug_keymap = true, -- true: use keymap for debugger defined in go/dap.lua -- false: do not use keymap in go/dap.lua. you must define your own. + -- windows: use visual studio style of keymap dap_vt = true, -- false, true and 'all frames' textobjects = true, gopls_cmd = nil, --- you can provide gopls path and cmd if it not in PATH, e.g. cmd = { "/home/ray/.local/nvim/data/lspinstall/go/gopls" } diff --git a/lua/go.lua b/lua/go.lua index 94ac7f0..139e84b 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -229,7 +229,8 @@ function go.setup(cfg) vim.cmd([[command! DapUiFloat lua require("dapui").float_element()]]) vim.cmd([[command! DapUiToggle lua require("dapui").toggle()]]) - vim.cmd([[command! GoDbgStop lua require'go.dap'.stop()]]) + vim.cmd([[command! GoDbgStop lua require'go.dap'.stop(true)]]) + vim.cmd([[command! GoDbgContinue lua require'dap'.continue()]]) end require("go.project").load_project() diff --git a/lua/go/dap.lua b/lua/go/dap.lua index ca0ba50..0879bbf 100644 --- a/lua/go/dap.lua +++ b/lua/go/dap.lua @@ -68,6 +68,21 @@ local function keybind() ["n|P"] = 'lua require"dap".pause()', -- } + if _GO_NVIM_CFG.dap_debug_keymap == "windows" then + keys = { + -- DAP -- + -- run + + ["n|"] = 'lua require"dap".toggle_breakpoint()', + ["n|"] = 'lua require"dap".continue()', + ["n|"] = 'lua require"dap".step_over()', + ["n|"] = 'lua require"dap".run_to_cursor()', + ["n|"] = 'lua require"dap".step_into()', + ["n|"] = 'lua require"dap".step_out()', + ["n|"] = 'lua require"go.dap".stop()', + -- + } + end if _GO_NVIM_CFG.dap_debug_gui then keys["n|p"] = 'lua require("dapui").eval()' keys["v|p"] = 'lua require("dapui").eval()' @@ -99,7 +114,6 @@ local M = {} function M.debug_keys() local keymap_help = {} for key, val in pairs(keys) do - local m = vim.fn.matchlist(val, [[\v(\p+)\.(\p+\(\p*\))]]) -- match last function e.g.float_element("repl") table.insert(keymap_help, key .. " -> " .. m[3]) @@ -119,7 +133,6 @@ function M.debug_keys() }) end - local close_events = { "CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre" } local config = { close_events = close_events, focusable = true, border = "single" } vim.lsp.util.open_floating_preview(keymap_help, "lua", config) @@ -529,6 +542,17 @@ local unmap = function() "a", "w", } + if _GO_NVIM_CFG.dap_debug_keymap == "windows" then + keys = { + "", + "", + "", + "", + "", + "", + "", + } + end for _, value in pairs(keys) do local cmd = "silent! unmap " .. value vim.cmd(cmd)