recommit fix for #145 due to merge failure

pull/148/head
ray-x 2 years ago
parent 1fd353947b
commit eae9af9c1d

@ -349,11 +349,10 @@ or simply put your cursor in a struct and do
| command | Description |
| ---------------- | ------------------------------------------------ |
| GoDebug | start debug session |
| GoDebug | start debug session, Note 1 |
| GoDebug -h | show helps info |
| GoDebug -c | compile only |
| GoDebug -t | start debug session for go test file |
| GoDebug -r | start debug if test existed, run test, else run current func|
| GoDebug -t | start debug session for go test file, Note 2 |
| GoDebug -R | restart debug session |
| GoDebug -n | start debug session for nearest go test function |
| GoDebug -p | launch package test and start debug |
@ -362,6 +361,12 @@ or simply put your cursor in a struct and do
| GoBreakToggle | GoDebug -b |
| BreakCondition | conditional break |
Notes:
1. Without any argument, will check if launch.json existed or not, if existed, using launch.json and popup input.
If launch.json not existed, will start debug session for current file, if current file is package main will run
main(), else will start debug package test
2. with -t option, if current file is not test file, will switch to test file and run test for current function
## Switch between go and test file
| command | Description |

@ -256,10 +256,12 @@ COMMANDS *go-nvim-commands*
:GoDebug {options} *:GoDebug*
Start debuger
options: -t(test), -R(restart), -n(nearest), -f(file), -s(stop), -b(breakpoint)
-h(help), -c(compile), -a (attach remote)
If no option provided, will
1) check launch.json and launch the valid configuration from
launch.json
2) fallback to GoDebug file
With -t option, if current file is not test file, will switch to test file and run test for current function
:GoDebugConfig *:GoDebugConfig*
Open launch.json

@ -23,7 +23,7 @@ local opts = "tcraRsnpfsbhT:"
local function help()
return "Usage: GoDebug [OPTION]\n"
.. "Options:\n"
.. " -c, --compile compile and run\n"
.. " -c, --compile compile\n"
.. " -r, --run run\n"
.. " -t, --test run tests\n"
.. " -R, --restart restart\n"
@ -32,10 +32,10 @@ local function help()
.. " -n, --nearest debug nearest file\n"
.. " -p, --package debug package\n"
.. " -f, --file display file\n"
.. " -b, --breakpoint set breakpoint\n"
.. " -T, --tag set tag"
.. " -b, --breakpoint set breakpoint"
end
-- not sure if anyone still use telescope for debug
local function setup_telescope()
require("telescope").setup()
require("telescope").load_extension("dap")
@ -192,7 +192,7 @@ end
local stdout, stderr, handle
M.run = function(...)
local args = { ... }
local mode = select(1, ...)
local mode = "test"
local optarg, optind = getopt.get_opts(args, opts, long_opts)
log(optarg, optind)
@ -220,6 +220,10 @@ M.run = function(...)
return
end
if optarg["b"] then
return require("dap").toggle_breakpoint()
end
local guihua = utils.load_plugin("guihua.lua", "guihua.gui")
local original_select = vim.ui.select
@ -254,16 +258,18 @@ M.run = function(...)
vim.notify("debug session already start, press c to continue", vim.lsp.log_levels.INFO)
return
end
local run_cur = optarg["r"]
local run_cur = optarg["r"] -- undocumented mode, smartrun current program in interactive mode
-- e.g. edit and run
local testfunc
if not run_cur then
keybind()
else
M.stop()
M.stop() -- rerun
testfunc = require("go.gotest").get_test_func_name()
if not string.find(testfunc.name, "[T|t]est") then
log("no test func found", testfunc.name)
testfunc = nil -- no test func avalible
testfunc = nil -- no test func avalible, run main
end
end
@ -300,7 +306,9 @@ M.run = function(...)
return
end
if data:find("couldn't start") then
utils.error(data)
vim.schedule(function()
utils.error(data)
end)
end
vim.schedule(function()
@ -366,9 +374,12 @@ M.run = function(...)
end
testfunc = require("go.gotest").get_test_func_name()
log(testfunc)
if testfunc then
optarg["t"] = true
if testfunc.name ~= "main" then
optarg["t"] = true
end
end
if optarg["t"] then
dap_cfg.name = dap_cfg.name .. " test"
@ -423,20 +434,25 @@ M.run = function(...)
dap.continue()
-- dap.run_to_cursor()
elseif cfg_exist then
log("using cfg")
log("using launch cfg")
launch.load()
log(dap.configurations.go)
for _, cfg in ipairs(dap.configurations.go) do
cfg.dlvToolPath = vim.fn.exepath("dlv")
end
dap.continue()
else
else -- no args
log("debug main")
dap_cfg.program = sep .. "${relativeFileDirname}"
dap_cfg.args = args
dap_cfg.mode = "debug"
dap_cfg.request = "launch"
dap.configurations.go = { dap_cfg }
dap.continue()
end
log(dap_cfg, args)
log(dap_cfg, args, optarg)
M.pre_mode = dap_cfg.mode or M.pre_mode
vim.ui.select = original_select
end

@ -91,6 +91,10 @@ local function get_test_filebufnr()
local uri = vim.uri_from_fname(fn)
bufnr = vim.uri_to_bufnr(uri)
log(fn, bufnr, uri)
if vfn.filereadable(vim.uri_to_fname(uri)) == 0 then
-- no test file existed
return 0, "no test file"
end
if not vim.api.nvim_buf_is_loaded(bufnr) then
vfn.bufload(bufnr)
end

@ -15,7 +15,6 @@ local function load_plugins()
require("packer").startup({
function(use)
use({ "wbthomason/packer.nvim" })
use({ "ray-x/guihua.lua" })
use({
"nvim-treesitter/nvim-treesitter",
config = function()
@ -29,6 +28,12 @@ local function load_plugins()
use({ "neovim/nvim-lspconfig" })
use({
plugin_folder() .. "ray-x/go.nvim",
requires = {
"mfussenegger/nvim-dap", -- Debug Adapter Protocol
"rcarriga/nvim-dap-ui",
"theHamsta/nvim-dap-virtual-text",
"ray-x/guihua.lua",
},
config = function()
require("go").setup({
verbose = true,

Loading…
Cancel
Save