return { { "mfussenegger/nvim-dap", config = function() local dap = require("dap") dap.adapters.go = { type = "server", port = "${port}", executable = { command = "dlv", args = { "dap", "-l", "127.0.0.1:${port}" }, }, } -- Хранение истории аргументов для каждой точки входа local _args_history = {} -- Функция для запроса аргументов у пользователя с историей (возвращает строку для парсинга) local function get_args(entry_point) local cache_key = entry_point local default = _args_history[cache_key] or "" local prompt = "Arguments for " .. entry_point .. ": " local input = vim.fn.input(prompt, default) if input and #input > 0 then _args_history[cache_key] = input end return _args_history[cache_key] end -- Генерация конфигураций для Go на основе точек входа local function generate_go_configs() local workspace_folder = vim.fn.getcwd() -- Проверка существования .env файла в корне проекта local env_file = nil if vim.fn.filereadable(workspace_folder .. "/.env") == 1 then env_file = "${workspaceFolder}/.env" end local configs = {} local entry_points = {} -- Поиск точки входа: main.go в корне или cmd/*/main.go if vim.fn.filereadable(workspace_folder .. "/main.go") == 1 then table.insert(entry_points, { name = "main", path = "${workspaceFolder}", }) end -- Поиск cmd/*/main.go local cmd_dirs = vim.fn.glob(workspace_folder .. "/cmd/*", 0, 1) for _, cmd_dir in ipairs(cmd_dirs) do local main_path = cmd_dir .. "/main.go" if vim.fn.filereadable(main_path) == 1 then local entry_name = vim.fn.fnamemodify(cmd_dir, ":t") table.insert(entry_points, { name = entry_name, path = cmd_dir, }) end end -- Генерация конфигураций для каждой точки входа for _, entry in ipairs(entry_points) do -- Базовая конфигурация без аргументов table.insert(configs, { type = "go", name = "Debug " .. entry.name, request = "launch", program = entry.path, cwd = "${workspaceFolder}", envFile = env_file, buildFlags = "", outputMode = "remote", }) -- Конфигурация с аргументами (функция для запроса при запуске) table.insert(configs, { type = "go", name = "Debug " .. entry.name .. " (args)", request = "launch", program = entry.path, cwd = "${workspaceFolder}", envFile = env_file, buildFlags = "", outputMode = "remote", args = function() local args_str = get_args(entry.name) -- Разбиваем строку аргументов на массив local args = {} for arg in args_str:gmatch("%S+") do table.insert(args, arg) end return args end, }) end -- Remote attach конфигурация для подключения к уже запущенному delve table.insert(configs, { type = "go", name = "Remote attach (127.0.0.1:43000)", request = "attach", mode = "remote", port = "43000", host = "127.0.0.1", }) return configs end -- Установка конфигураций Go dap.configurations.go = generate_go_configs() -- Автообновление конфигураций при открытии Go файла vim.api.nvim_create_autocmd("BufReadPost", { pattern = "*.go", callback = function() dap.configurations.go = generate_go_configs() end, }) end, keys = { { "", function() require("dap").continue() end, desc = "Debug continue", }, { "", function() -- S-F5 require("dap").restart() end, desc = "Debug restart", }, { "", function() -- C-F5 require("dap").terminate() end, desc = "Debug terminate", }, { "", function() require("dap").step_over() end, desc = "Debug step over", }, { "", function() require("dap").step_into() end, desc = "Debug step into", }, { "", function() -- S-F7 require("dap").step_out() end, desc = "Debug step out", }, { "", function() require("dap").toggle_breakpoint() end, desc = "Toggle breakpoint", }, { "", function() local widgets = require("dap.ui.widgets") widgets.centered_float(widgets.scopes) end, desc = "Debug scopes", }, }, }, { "rcarriga/nvim-dap-ui", dependencies = { "mfussenegger/nvim-dap", "nvim-neotest/nvim-nio", }, config = function() local dapui = require("dapui") dapui.setup({ icons = { expanded = "▼", collapsed = "▶", current_frame = "→", }, controls = { enabled = false, }, mappings = { open = "o", remove = "d", edit = "e", repl = "r", toggle = "t", }, expand_lines = vim.fn.has("nvim-0.7"), layouts = { { elements = { "repl", "scopes", }, size = 0.3, position = "bottom", }, }, floating = { max_height = nil, max_width = nil, border = "single", mappings = { close = { "q", "" }, }, }, windows = { indent = 1 }, render = { max_type_length = nil, }, }) local dap = require("dap") dap.listeners.after.event_initialized["dapui_config"] = function() dapui.open() end end, keys = { { "", function() require("dapui").toggle() end, desc = "Toggle debug UI", }, { "dh", function() require("dap.ui.widgets").hover() end, desc = "Debug hover", }, { "dp", function() require("dap.ui.widgets").preview() end, desc = "Debug preview", }, }, }, { "leoluz/nvim-dap-go", dependencies = { "mfussenegger/nvim-dap" }, ft = "go", -- Не используем автоconfig - конфигурации управляются в nvim-dap keys = { { "dt", function() require("dap-go").debug_test() end, desc = "Debug test", }, }, }, }