Skip to content

Commit

Permalink
fix(nvim): dapconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Apr 26, 2024
1 parent c6e4c78 commit 0af21ea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 71 deletions.
64 changes: 9 additions & 55 deletions root/.config/nvim/lua/dapconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,19 @@ local M = {}

function M.dapconfig()
local dap, dapui = require("dap"), require("dapui")
dapui.setup({
layouts = {
{
elements = {
-- Provide as ID strings or tables with "id" and "size" keys
{
id = "scopes",
size = 0.2, -- Can be float or integer > 1
},
{ id = "breakpoints", size = 0.2 },
{ id = "stacks", size = 0.2 },
{ id = "watches", size = 0.2 },
{ id = "console", size = 0.2 }
},
size = 40,
position = "left",
},
{ elements = { "repl" }, size = 10, position = "bottom" },
},
-- Requires Nvim version >= 0.8
controls = {
enabled = true,
-- Display controls in this session
element = "repl",
},
floating = {
max_height = nil,
max_width = nil,
mappings = { close = { "q", "<Esc>" } },
},
windows = { indent = 1 },
})
dapui.setup()

dap.listeners.after.event_initialized["dapui_config"] = function()
-- 自动开启/关闭dapui
dap.listeners.before.attach.dapui_config = function()
dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dap.listeners.before.launch.dapui_config = function()
dapui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dap.listeners.before.event_exited.dapui_config = function()
dapui.close()
end

Expand Down Expand Up @@ -86,26 +59,7 @@ function M.dapconfig()
dap.configurations.c = dap.configurations.cpp
dap.configurations.rust = dap.configurations.cpp

-- pip install debugpy
dap.adapters.python = {
type = 'executable',
command = 'python3',
args = { '-m', 'debugpy.adapter' },
}

dap.configurations.python = {
-- same as vscode launch.json
{
-- The first three options are required by nvim-dap
type = 'python', -- the type here established the link to the adapter definition: `dap.adapters.python`
request = 'launch',
name = "Launch file",
-- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options
console = "integratedTerminal",
program = "${file}", -- This configuration will launch the current file if used.
pythonPath = 'python3',
},
}
require("dap-python").setup("python3")
end

return M
40 changes: 24 additions & 16 deletions root/.config/nvim/lua/plugins/dap.lua
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
if vim.g.vim_dap == 'nvim-dap' then
-- alternate: https://github.com/sakhnik/nvim-gdb
if vim.g.vim_dap == "nvim-dap" then
return {
{
'rcarriga/nvim-dap-ui',
lazy = true,
cmd = {
"DapContinue",
"DapToggleRepl",
"DapSetLogLevel",
"DapLoadLaunchJSON",
"DapToggleBreakpoint",
},
"rcarriga/nvim-dap-ui",
dependencies = {
'mfussenegger/nvim-dap',
"mfussenegger/nvim-dap",
"nvim-neotest/nvim-nio",
'theHamsta/nvim-dap-virtual-text',
"theHamsta/nvim-dap-virtual-text",
"mfussenegger/nvim-dap-python",
},
config = require('dapconfig').dapconfig
config = require("dapconfig").dapconfig,
},
{
'theHamsta/nvim-dap-virtual-text',
"mfussenegger/nvim-dap",
lazy = true,
opts = {
commented = true
config = function()
vim.fn.sign_define("DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" })
end,
},
{
lazy = true,
"mfussenegger/nvim-dap-python",
dependencies = {
"mfussenegger/nvim-dap",
}
},
{
"theHamsta/nvim-dap-virtual-text",
lazy = true,
opts = {
commented = true,
},
},
}
else
return {}
Expand Down

0 comments on commit 0af21ea

Please sign in to comment.