dap_debug_keymap missing issue #57

pull/59/head
ray-x 3 years ago
parent c7c3ab885a
commit 124d2e269c

@ -1,21 +1,24 @@
local bind = require("go.keybind")
local map_cr = bind.map_cr
local utils = require('go.utils')
local utils = require("go.utils")
local log = utils.log
local sep = '.' .. utils.sep()
local sep = "." .. utils.sep()
local function setup_telescope()
require('telescope').setup()
require('telescope').load_extension('dap')
require("telescope").setup()
require("telescope").load_extension("dap")
local ts_keys = {
["n|lb"] = map_cr('<cmd>lua require"telescope".extensions.dap.list_breakpoints{}'):with_noremap():with_silent(),
["n|tv"] = map_cr('<cmd>lua require"telescope".extensions.dap.variables{}'):with_noremap():with_silent(),
["n|bt"] = map_cr('<cmd>lua require"telescope".extensions.dap.frames{}'):with_noremap():with_silent()
["n|bt"] = map_cr('<cmd>lua require"telescope".extensions.dap.frames{}'):with_noremap():with_silent(),
}
bind.nvim_load_mapping(ts_keys)
end
local function keybind()
if not _GO_NVIM_CFG.dap_debug_keymap then
return
end
local keys = {
-- DAP --
-- run
@ -29,7 +32,7 @@ local function keybind()
["n|D"] = map_cr('<cmd>lua require"dap".down()<CR>'):with_noremap():with_silent(),
["n|C"] = map_cr('<cmd>lua require"dap".run_to_cursor()<CR>'):with_noremap():with_silent(),
["n|b"] = map_cr('<cmd>lua require"dap".toggle_breakpoint()<CR>'):with_noremap():with_silent(),
["n|P"] = map_cr('<cmd>lua require"dap".pause()<CR>'):with_noremap():with_silent()
["n|P"] = map_cr('<cmd>lua require"dap".pause()<CR>'):with_noremap():with_silent(),
--
}
if _GO_NVIM_CFG.dap_debug_gui then
@ -46,7 +49,6 @@ local function keybind()
keys["v|p"] = map_cr('<cmd>lua require"dap.ui.widgets".hover()<CR>'):with_noremap():with_silent()
end
bind.nvim_load_mapping(keys)
end
local function get_build_flags()
@ -60,45 +62,47 @@ end
local M = {}
M.prepare = function()
utils.load_plugin('nvim-dap', "dap")
vim.fn.sign_define('DapBreakpoint', {
utils.load_plugin("nvim-dap", "dap")
vim.fn.sign_define("DapBreakpoint", {
text = _GO_NVIM_CFG.icons.breakpoint,
texthl = '',
linehl = '',
numhl = ''
texthl = "",
linehl = "",
numhl = "",
})
vim.fn.sign_define('DapStopped', {
vim.fn.sign_define("DapStopped", {
text = _GO_NVIM_CFG.icons.currentpos,
texthl = '',
linehl = '',
numhl = ''
texthl = "",
linehl = "",
numhl = "",
})
if _GO_NVIM_CFG.dap_debug_gui then
utils.load_plugin('nvim-dap-ui', "dapui")
local vt = utils.load_plugin('nvim-dap-virtual-text')
vt.setup({enabled_commands = true, all_frames = true})
utils.load_plugin("nvim-dap-ui", "dapui")
if _GO_NVIM_CFG.dap_debug_vt then
local vt = utils.load_plugin("nvim-dap-virtual-text")
end
vt.setup({ enabled_commands = true, all_frames = true })
end
end
M.breakpt = function()
M.prepare()
require"dap".toggle_breakpoint()
require("dap").toggle_breakpoint()
end
M.run = function(...)
keybind()
M.prepare()
local args = {...}
local args = { ... }
local mode = select(1, ...)
if mode == 'stop' then
return require"go.dap".stop(true)
if mode == "stop" then
return require("go.dap").stop(true)
end
if mode == 'restart' then
require'go.dap'.stop()
mode = M.pre_mode or 'test'
if mode == "restart" then
require("go.dap").stop()
mode = M.pre_mode or "test"
else
M.pre_mode = mode
end
@ -109,16 +113,16 @@ M.run = function(...)
require("dapui").setup()
require("dapui").open()
end
local dap = require "dap"
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
handle, pid_or_err = vim.loop.spawn("dlv", {
stdio = {nil, stdout},
args = {"dap", "-l", "127.0.0.1:" .. port},
detached = true
stdio = { nil, stdout },
args = { "dap", "-l", "127.0.0.1:" .. port },
detached = true,
}, function(code)
stdout:close()
handle:close()
@ -138,7 +142,7 @@ M.run = function(...)
-- Wait 100ms for delve to start
vim.defer_fn(function()
dap.repl.open()
callback({type = "server", host = "127.0.0.1", port = port})
callback({ type = "server", host = "127.0.0.1", port = port })
end, 100)
end
@ -147,8 +151,7 @@ M.run = function(...)
name = "Debug",
request = "launch",
dlvToolPath = vim.fn.exepath("dlv"),
buildFlags = get_build_flags()
buildFlags = get_build_flags(),
}
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
@ -156,40 +159,60 @@ M.run = function(...)
local ns = require("go.ts.go").get_func_method_node_at_pos(row, col)
if ns == nil or ns == {} then
log('ts not not found, debug while file')
if mode == 'nearest' then
mode = 'test'
log("ts not not found, debug while file")
if mode == "nearest" then
mode = "test"
end
end
if mode == 'test' then
dap_cfg.name = dap_cfg.name .. ' test'
if mode == "test" then
dap_cfg.name = dap_cfg.name .. " test"
dap_cfg.mode = "test"
-- dap_cfg.program = "${workspaceFolder}"
-- dap_cfg.program = "${file}"
dap_cfg.program = sep .. "${relativeFileDirname}"
dap.configurations.go = {dap_cfg}
dap.configurations.go = { dap_cfg }
dap.continue()
elseif mode == 'nearest' then
dap_cfg.name = dap_cfg.name .. ' test_nearest'
elseif mode == "nearest" then
dap_cfg.name = dap_cfg.name .. " test_nearest"
dap_cfg.mode = "test"
dap_cfg.program = sep .. "${relativeFileDirname}"
dap_cfg.args = {'-test.run', '^' .. ns.name}
dap_cfg.args = { "-test.run", "^" .. ns.name }
log(dap_cfg)
dap.configurations.go = {dap_cfg}
dap.configurations.go = { dap_cfg }
dap.continue()
else
dap_cfg.program = sep .. "${relativeFileDirname}"
dap_cfg.args = args
dap.configurations.go = {dap_cfg}
dap.configurations.go = { dap_cfg }
dap.continue()
end
log(args)
end
local unmap = function()
if not _GO_NVIM_CFG.dap_debug_keymap then
return
end
local keys = {
"r", "c", "n", "s", "o", "S", "u", "D", "C", "b", "P", "p", "K", "B", "R", "O", "a", "w"
"r",
"c",
"n",
"s",
"o",
"S",
"u",
"D",
"C",
"b",
"P",
"p",
"K",
"B",
"R",
"O",
"a",
"w",
}
for _, value in pairs(keys) do
local cmd = "silent! unmap " .. value
@ -203,9 +226,9 @@ M.stop = function(unm)
if unm then
unmap()
end
require'dap'.disconnect()
require'dap'.close();
require"dap".repl.close()
require("dap").disconnect()
require("dap").close()
require("dap").repl.close()
local has_dapui, dapui = pcall(require, "dapui")
if has_dapui then
@ -234,18 +257,18 @@ function M.ultest_post()
program = sep .. "${relativeFileDirname}",
dlvToolPath = vim.fn.exepath("dlv"),
args = args,
buildFlags = get_build_flags()
buildFlags = get_build_flags(),
},
parse_result = function(lines)
return lines[#lines] == "FAIL" and 1 or 0
end
end,
}
end
end,
}
ok, ul = utils.load_plugin('vim-ultest', "ultest")
ok, ul = utils.load_plugin("vim-ultest", "ultest")
ul.setup({builders = builders})
ul.setup({ builders = builders })
end
return M

Loading…
Cancel
Save