feat: switch from lazy to vim.pack

This commit is contained in:
2026-04-10 14:42:25 +02:00
parent 190b3ecebd
commit 28c45c8390
35 changed files with 1168 additions and 1455 deletions
+141 -206
View File
@@ -1,217 +1,152 @@
-- https://github.com/mfussenegger/nvim-dap
local hover = require("dap.hover")
local log = require("log")
local dap = require("dap")
---@type LazyPluginSpec
return {
"mfussenegger/nvim-dap",
lazy = false,
keys = {
{
"<Leader>db",
function()
require("dap").toggle_breakpoint()
end,
},
{
"<Leader>df",
function()
require("dap").focus_frame()
end,
},
{
"<PageUp>",
function()
require("dap").up()
end,
},
{
"<PageDown>",
function()
require("dap").down()
end,
},
{
"<Leader>dh",
hover,
mode = { "n", "x" },
},
{
"<Leader>dr",
function()
require("dap").repl.toggle()
end,
mode = { "n", "x" },
},
{
"<F2>",
function()
require("dap").step_into()
end,
},
{
"<F3>",
function()
require("dap").step_over()
end,
},
{
"<F4>",
function()
require("dap").step_out()
end,
},
{
"<F5>",
function()
require("dap").continue()
end,
},
{
"<F9>",
function()
require("dap").terminate()
end,
},
},
config = function()
local dap = require("dap")
vim.api.nvim_set_hl(0, "DebugPC", {
bg = "NONE",
fg = "NONE",
})
vim.api.nvim_set_hl(0, "DebugPC", {
bg = "NONE",
fg = "NONE",
})
vim.api.nvim_create_user_command(
"Debug",
---@param opts vim.api.keyset.create_user_command.command_args
function(opts)
local cfgs = dap.configurations[vim.bo.filetype]
if not cfgs then
log.error(
"No configurations available for filetype %s",
vim.bo.filetype
)
return
end
vim.api.nvim_create_user_command(
"Debug",
---@param opts vim.api.keyset.create_user_command.command_args
function(opts)
local cfgs = dap.configurations[vim.bo.filetype]
if not cfgs then
log.error(
"No configurations available for filetype %s",
vim.bo.filetype
)
return
end
local function run_config(cfg)
local all_args = vim.fn.split(opts.args)
cfg.program = all_args[1]
local function run_config(cfg)
local all_args = vim.fn.split(opts.args)
cfg.program = all_args[1]
local args = {}
for i = 2, #all_args do
table.insert(args, all_args[i])
end
cfg.args = args
local args = {}
for i = 2, #all_args do
table.insert(args, all_args[i])
end
cfg.args = args
dap.run(cfg)
end
dap.run(cfg)
end
if #cfgs == 1 then
run_config(cfgs[1])
return
end
if #cfgs == 1 then
run_config(cfgs[1])
return
end
local names = {}
for _, c in ipairs(cfgs) do
table.insert(names, c.name)
end
local names = {}
for _, c in ipairs(cfgs) do
table.insert(names, c.name)
end
vim.ui.select(names, {
prompt = "Select DAP configuration to use:",
}, function(choice, idx)
if choice and idx then
run_config(cfgs[idx])
end
end)
end,
{
nargs = "+",
---@param ArgLead string
---@param CmdLine string
complete = function(ArgLead, CmdLine, CursorPos)
local _, spaces = CmdLine:sub(1, CursorPos):gsub("%s+", "")
if spaces == 1 then
return vim.fn.getcompletion(ArgLead, "file")
end
end,
}
)
-- https://sourceware.org/gdb/current/onlinedocs/gdb#Debugger-Adapter-Protocol
dap.adapters.gdb = {
type = "executable",
command = "gdb",
args = { "--interpreter=dap" },
}
dap.adapters.lldb = {
type = "executable",
command = "lldb-dap",
}
dap.adapters.python = {
type = "executable",
command = "python",
args = { "-m", "debugpy.adapter" },
}
dap.configurations.c = {
{
type = "gdb",
request = "launch",
name = "Launch",
program = function()
local path = vim.fn.input({
prompt = "Path to executable: ",
default = vim.fn.getcwd() .. "/",
completion = "file",
})
return (path and path ~= "") and path or dap.ABORT
end,
cwd = "${workspaceFolder}",
stopAtBeginningOfMainSubprogram = false,
},
}
-- dap.configurations.c = {
-- {
-- type = "lldb",
-- request = "launch",
-- name = "Launch",
-- program = function()
-- local path = vim.fn.input({
-- prompt = "Path to executable: ",
-- default = vim.fn.getcwd() .. "/",
-- completion = "file",
-- })
-- return (path and path ~= "") and path or dap.ABORT
-- end,
-- cwd = "${workspaceFolder}",
-- stopAtBeginningOfMainSubprogram = false,
-- console = "internalConsole",
-- },
-- }
dap.configurations.cpp = dap.configurations.c
dap.configurations.python = {
{
type = "python",
request = "launch",
name = "Launch",
program = function()
local path = vim.fn.input({
prompt = "Path to executable: ",
default = vim.fn.getcwd() .. "/",
completion = "file",
})
return (path and path ~= "") and path or dap.ABORT
end,
cwd = "${workspaceFolder}",
},
}
vim.ui.select(names, {
prompt = "Select DAP configuration to use:",
}, function(choice, idx)
if choice and idx then
run_config(cfgs[idx])
end
end)
end,
{
nargs = "+",
---@param ArgLead string
---@param CmdLine string
complete = function(ArgLead, CmdLine, CursorPos)
local _, spaces = CmdLine:sub(1, CursorPos):gsub("%s+", "")
if spaces == 1 then
return vim.fn.getcompletion(ArgLead, "file")
end
end,
}
)
-- https://sourceware.org/gdb/current/onlinedocs/gdb#Debugger-Adapter-Protocol
dap.adapters.gdb = {
type = "executable",
command = "gdb",
args = { "--interpreter=dap" },
}
dap.adapters.lldb = {
type = "executable",
command = "lldb-dap",
}
dap.adapters.python = {
type = "executable",
command = "python",
args = { "-m", "debugpy.adapter" },
}
dap.configurations.c = {
{
type = "gdb",
request = "launch",
name = "Launch",
program = function()
local path = vim.fn.input({
prompt = "Path to executable: ",
default = vim.fn.getcwd() .. "/",
completion = "file",
})
return (path and path ~= "") and path or dap.ABORT
end,
cwd = "${workspaceFolder}",
stopAtBeginningOfMainSubprogram = false,
},
}
-- dap.configurations.c = {
-- {
-- type = "lldb",
-- request = "launch",
-- name = "Launch",
-- program = function()
-- local path = vim.fn.input({
-- prompt = "Path to executable: ",
-- default = vim.fn.getcwd() .. "/",
-- completion = "file",
-- })
-- return (path and path ~= "") and path or dap.ABORT
-- end,
-- cwd = "${workspaceFolder}",
-- stopAtBeginningOfMainSubprogram = false,
-- console = "internalConsole",
-- },
-- }
dap.configurations.cpp = dap.configurations.c
dap.configurations.python = {
{
type = "python",
request = "launch",
name = "Launch",
program = function()
local path = vim.fn.input({
prompt = "Path to executable: ",
default = vim.fn.getcwd() .. "/",
completion = "file",
})
return (path and path ~= "") and path or dap.ABORT
end,
cwd = "${workspaceFolder}",
},
}
vim.keymap.set("n", "<Leader>db", dap.toggle_breakpoint)
vim.keymap.set("n", "<Leader>df", dap.focus_frame)
vim.keymap.set("n", "<PageUp>", dap.up)
vim.keymap.set("n", "<PageDown>", dap.down)
vim.keymap.set({ "n", "x" }, "<Leader>dh", require("dap.hover"))
vim.keymap.set({ "n", "x" }, "<Leader>dr", dap.repl.toggle)
vim.keymap.set("n", "<F2>", dap.step_into)
vim.keymap.set("n", "<F3>", dap.step_over)
vim.keymap.set("n", "<F4>", dap.step_out)
vim.keymap.set("n", "<F5>", dap.continue)
vim.keymap.set("n", "<F9>", dap.terminate)