code action with telescope, dap debug restart

pull/50/head
ray-x 3 years ago
parent cfeab3d398
commit 3329238deb

@ -216,6 +216,7 @@ e.g:
| ---------------- | ------------------------------------------------ |
| GoDebug | start debug session |
| GoDebug test | start debug session for go test file |
| GoDebug restart | restart debug session for go test file |
| GoDebug nearest | start debug session for nearest go test function |
| GoDebug file | same as GoDebug |
| GoDebug stop | stop debug session |

@ -162,7 +162,7 @@ end
go.dbg_complete = function(arglead, cmdline, cursorpos)
-- richgo, go test, richgo, dlv, ginkgo
local testopts = {"test", "nearest", "file", "stop"}
local testopts = {"test", "nearest", "file", "stop", "restart"}
return table.concat(testopts, '\n')
end
return go

@ -93,8 +93,17 @@ M.run = function(...)
local mode = select(1, ...)
if mode == 'stop' then
return require"go.dap".stop()
return require"go.dap".stop(true)
end
if mode == 'restart' then
require'go.dap'.stop()
mode = M.pre_mode or 'test'
else
M.pre_mode = mode
end
-- testopts = {"test", "nearest", "file", "stop", "restart"}
log("plugin loaded", mode)
if _GO_NVIM_CFG.dap_debug_gui then
require("dapui").setup()
@ -178,7 +187,7 @@ M.run = function(...)
log(args)
end
M.stop = function()
local unmap = function()
local keys = {
"r", "c", "n", "s", "o", "S", "u", "D", "C", "b", "P", "p", "K", "B", "R", "O", "a", "w"
}
@ -188,10 +197,20 @@ M.stop = function()
end
vim.cmd([[silent! vunmap p]])
end
M.stop = function(unm)
if unm then
unmap()
end
require'dap'.disconnect()
require'dap'.close();
require"dap".repl.close()
require("dapui").close()
local has_dapui, dapui = pcall(require, "dapui")
if has_dapui then
dapui.close()
end
end
function M.ultest_post()

@ -37,11 +37,10 @@ local on_attach = function(client, bufnr)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wl',
'<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', '<space>ca', '<cmd>lua require"go.lsp".telescope_code_actions()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
@ -61,7 +60,13 @@ local gopls = {
"gopls", -- share the gopls instance if there is one already
"-remote.debug=:0"
},
root_dir = function(fname)
local has_lsp, lspconfig = pcall(require, "lspconfig")
if has_lsp then
local util = lspconfig.util
return util.root_pattern("go.mod", ".git")(fname) or util.path.dirname(fname)
end
end,
flags = {allow_incremental_sync = true, debounce_text_changes = 500},
settings = {
gopls = {
@ -184,4 +189,19 @@ M.codeaction = function(action, only, wait_ms)
end
end
function M.telescope_code_actions()
local ok, _ = utils.load_plugin('telescope', "builtin")
if ok then
local themes = require('telescope.themes')
local opts = themes.get_dropdown {
winblend = 10,
border = true,
previewer = false,
shorten_path = false
}
require('telescope.builtin').lsp_code_actions(opts)
else
vim.lsp.buf.code_action()
end
end
return M

Loading…
Cancel
Save