aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2025-06-27 22:01:27 -0400
committerEugene Triguba <eugenetriguba@gmail.com>2025-06-27 22:01:27 -0400
commit224fb93bb7a5c78b1ae5969dbe075423a49d8991 (patch)
tree7b51dd6123b241ab20946d5fcdf17ff0d8575b9e
parentUpdate deps and set python3 host prog in neovim (diff)
downloaddotfiles-224fb93bb7a5c78b1ae5969dbe075423a49d8991.zip
Add zig to dap, refactor debug config, and add build to blink
-rw-r--r--nvim/.config/nvim/lua/plugins/blink.lua3
-rw-r--r--nvim/.config/nvim/lua/plugins/debug.lua335
2 files changed, 222 insertions, 116 deletions
diff --git a/nvim/.config/nvim/lua/plugins/blink.lua b/nvim/.config/nvim/lua/plugins/blink.lua
index d83ee7f..9df552a 100644
--- a/nvim/.config/nvim/lua/plugins/blink.lua
+++ b/nvim/.config/nvim/lua/plugins/blink.lua
@@ -1,8 +1,9 @@
return {
{ -- Autocompletion
'saghen/blink.cmp',
+ build = 'cargo +nightly build --release',
event = 'VimEnter',
- version = '1.*',
+ version = '*',
dependencies = {
-- Snippet Engine
{
diff --git a/nvim/.config/nvim/lua/plugins/debug.lua b/nvim/.config/nvim/lua/plugins/debug.lua
index 239410f..668323e 100644
--- a/nvim/.config/nvim/lua/plugins/debug.lua
+++ b/nvim/.config/nvim/lua/plugins/debug.lua
@@ -1,134 +1,239 @@
-- debug.lua
--
--- Shows how to use the DAP plugin to debug your code.
+-- Configures the DAP plugin to debug code.
-return {
- 'mfussenegger/nvim-dap',
- dependencies = {
- -- Creates a beautiful debugger UI
- 'rcarriga/nvim-dap-ui',
- -- Required dependency for nvim-dap-ui
- 'nvim-neotest/nvim-nio',
- -- Installs the debug adapters
- 'williamboman/mason.nvim',
- 'jay-babu/mason-nvim-dap.nvim',
- -- Debugger adapters
- 'leoluz/nvim-dap-go',
- 'mfussenegger/nvim-dap-python',
- },
- keys = {
- {
- '<F5>',
- function()
- require('dap').continue()
- end,
- desc = 'Debug: Start/Continue',
+---@class DapConfig
+---@field name string Configuration name
+---@field type string Debug adapter type
+---@field request string Launch type ('launch' or 'attach')
+---@field program function|string Path to executable or function returning path
+---@field cwd string Working directory
+---@field stopOnEntry boolean Whether to stop at entry point
+---@field args table Command line arguments
+---@field runInTerminal boolean Whether to run in terminal
+
+---@class DapAdapter
+---@field type string Adapter type ('server', 'executable', etc.)
+---@field port string Port configuration
+---@field executable table Executable configuration with command and args
+
+-- Go debugging adapter setup
+-- Configures delve debugger for Go with platform-specific settings
+---@return nil
+local function setup_go_adapter()
+ require('dap-go').setup {
+ delve = {
+ -- On Windows delve must be run attached or it crashes
+ detached = vim.fn.has 'win32' == 0,
},
- {
- '<F1>',
- function()
- require('dap').step_into()
- end,
- desc = 'Debug: Step Into',
+ }
+end
+
+-- Python debugging adapter setup
+-- Configures Python debugger using python3 interpreter
+---@return nil
+local function setup_python_adapter()
+ require('dap-python').setup 'python3'
+end
+
+-- CodeLLDB adapter setup
+-- Configures LLDB-based debugger for native languages (C, C++, Rust, Zig)
+---@param dap table # DAP module instance
+---@return nil
+local function setup_codelldb_adapter(dap)
+ ---@type DapAdapter
+ dap.adapters.codelldb = {
+ type = 'server',
+ port = '${port}',
+ executable = {
+ command = vim.fn.exepath 'codelldb',
+ args = { '--port', '${port}' },
},
+ }
+end
+
+-- Build and find the newly-built Zig executable by running
+-- 'zig build' and attempting to locate the resulting executable.
+-- If the executable is unable to be automatically found, the user
+-- will be prompted to give the path to the executable.
+--
+---@return string|nil # Path to executable or nil if build the failed
+local function build_and_find_zig_executable()
+ local build_result = vim.fn.system 'zig build'
+ if vim.v.shell_error ~= 0 then
+ vim.notify('Build failed: ' .. build_result, vim.log.levels.ERROR)
+ return nil
+ end
+
+ local exe_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t')
+ local possible_paths = { 'zig-out/bin/' .. exe_name }
+
+ for _, path in ipairs(possible_paths) do
+ local full_path = vim.fn.getcwd() .. '/' .. path
+ if vim.fn.executable(full_path) == 1 then
+ return full_path
+ end
+ end
+
+ return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/zig-out/bin/', 'file')
+end
+
+-- Build and find the Zig test executable by running
+-- 'zig build test' and prompting the user for the test
+-- executable location.
+--
+---@return string # Path to test executable
+local function build_and_find_zig_test()
+ vim.fn.system 'zig build test'
+ return vim.fn.input('Path to test executable: ', vim.fn.getcwd() .. '/zig-cache/o/', 'file')
+end
+
+-- Zig debugging configuration
+-- Sets up debugging configurations for Zig programs and tests
+---@param dap table # DAP module instance
+---@return nil
+local function setup_zig_configuration(dap)
+ ---@type DapConfig[]
+ dap.configurations.zig = {
{
- '<F2>',
- function()
- require('dap').step_over()
- end,
- desc = 'Debug: Step Over',
+ name = 'Build and Launch Zig Program',
+ type = 'codelldb',
+ request = 'launch',
+ program = build_and_find_zig_executable,
+ cwd = '${workspaceFolder}',
+ stopOnEntry = false,
+ args = {},
+ runInTerminal = false,
},
{
- '<F3>',
- function()
- require('dap').step_out()
- end,
- desc = 'Debug: Step Out',
+ name = 'Launch Zig Test',
+ type = 'codelldb',
+ request = 'launch',
+ program = build_and_find_zig_test,
+ cwd = '${workspaceFolder}',
+ stopOnEntry = false,
+ args = {},
+ runInTerminal = false,
},
- {
- '<leader>b',
+ }
+end
+
+-- Language adapters and configurations
+-- Sets up debugging support for all supported languages
+---@param dap table # DAP module instance
+---@return nil
+local function setup_language_adapters(dap)
+ setup_go_adapter()
+ setup_python_adapter()
+ setup_codelldb_adapter(dap)
+ setup_zig_configuration(dap)
+end
+
+-- Key mappings setup
+-- Configures function keys and leader key combinations for debugging actions
+---@param dap table # DAP module instance
+---@param dapui table # DAP UI module instance
+---@return nil
+local function setup_keymaps(dap, dapui)
+ ---@type table<string, {[1]: function, [2]: string}>
+ local keymaps = {
+ ['<F5>'] = { dap.continue, 'Debug: Start/Continue' },
+ ['<F1>'] = { dap.step_into, 'Debug: Step Into' },
+ ['<F2>'] = { dap.step_over, 'Debug: Step Over' },
+ ['<F3>'] = { dap.step_out, 'Debug: Step Out' },
+ ['<F7>'] = { dapui.toggle, 'Debug: See last session result' },
+ ['<leader>tb'] = { dap.toggle_breakpoint, 'Debug: Toggle Breakpoint' },
+ ['<leader>B'] = {
function()
- require('dap').toggle_breakpoint()
+ dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ')
end,
- desc = 'Debug: Toggle Breakpoint',
+ 'Debug: Set Breakpoint',
},
- {
- '<leader>B',
- function()
- require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ')
- end,
- desc = 'Debug: Set Breakpoint',
+ }
+
+ for key, config in pairs(keymaps) do
+ vim.keymap.set('n', key, config[1], { desc = config[2] })
+ end
+end
+
+-- Event listeners setup
+-- Configures automatic UI opening/closing based on debug session events
+---@param dap table # DAP module instance
+---@param dapui table # DAP UI module instance
+---@return nil
+local function setup_dap_listeners(dap, dapui)
+ local dapui_config = 'dapui_config'
+ dap.listeners.after.event_initialized[dapui_config] = dapui.open
+ dap.listeners.before.event_terminated[dapui_config] = dapui.close
+ dap.listeners.before.event_exited[dapui_config] = dapui.close
+end
+
+-- DAP UI configuration
+-- Sets up the debugging user interface with custom icons and controls
+---@param dapui table # DAP UI module instance
+---@return nil
+local function setup_dapui_config(dapui)
+ dapui.setup {
+ icons = {
+ expanded = '▾',
+ collapsed = '▸',
+ current_frame = '*',
},
- -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
- {
- '<F7>',
- function()
- require('dapui').toggle()
- end,
- desc = 'Debug: See last session result.',
+ controls = {
+ icons = {
+ pause = '⏸',
+ play = '▶',
+ step_into = '⏎',
+ step_over = '⏭',
+ step_out = '⏮',
+ step_back = 'b',
+ run_last = '▶▶',
+ terminate = '⏹',
+ disconnect = '⏏',
+ },
},
- },
- config = function()
- local dap = require 'dap'
- local dapui = require 'dapui'
+ }
+end
- require('mason-nvim-dap').setup {
- -- Makes a best effort to setup the various debuggers with
- -- reasonable debug configurations
- automatic_installation = true,
+-- Mason DAP configuration
+-- Automatically installs and configures debug adapters through Mason
+---@return nil
+local function setup_mason_dap()
+ require('mason-nvim-dap').setup {
+ automatic_installation = true,
+ handlers = {},
+ ensure_installed = { 'delve', 'python', 'codelldb' },
+ }
+end
- -- see mason-nvim-dap README for more information
- handlers = {},
+-- Main configuration orchestrator
+-- Sets up all debugging components in the correct order
+---@return nil
+local function setup_dap()
+ local dap = require 'dap'
+ local dapui = require 'dapui'
- ensure_installed = {
- 'delve',
- 'python',
- },
- }
-
- -- Dap UI setup
- -- For more information, see |:help nvim-dap-ui|
- dapui.setup {
- icons = { expanded = '▾', collapsed = '▸', current_frame = '*' },
- controls = {
- icons = {
- pause = '⏸',
- play = '▶',
- step_into = '⏎',
- step_over = '⏭',
- step_out = '⏮',
- step_back = 'b',
- run_last = '▶▶',
- terminate = '⏹',
- disconnect = '⏏',
- },
- },
- }
-
- -- Change breakpoint icons
- -- vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' })
- -- vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' })
- -- local breakpoint_icons = vim.g.have_nerd_font
- -- and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' }
- -- or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' }
- -- for type, icon in pairs(breakpoint_icons) do
- -- local tp = 'Dap' .. type
- -- local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak'
- -- vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl })
- -- end
-
- dap.listeners.after.event_initialized['dapui_config'] = dapui.open
- dap.listeners.before.event_terminated['dapui_config'] = dapui.close
- dap.listeners.before.event_exited['dapui_config'] = dapui.close
-
- -- Install golang specific config
- require('dap-go').setup {
- delve = {
- -- On Windows delve must be run attached or it crashes.
- -- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md#configuring
- detached = vim.fn.has 'win32' == 0,
- },
- }
- require('dap-python').setup 'python3'
+ setup_mason_dap()
+ setup_dapui_config(dapui)
+ setup_dap_listeners(dap, dapui)
+ setup_language_adapters(dap)
+ setup_keymaps(dap, dapui)
+end
+
+-- Plugin specification
+-- Configures nvim-dap with all necessary dependencies for debugging
+---@return table # Plugin specification for lazy.nvim
+return {
+ 'mfussenegger/nvim-dap',
+ dependencies = {
+ 'rcarriga/nvim-dap-ui', -- Beautiful debugger UI
+ 'nvim-neotest/nvim-nio', -- Required dependency for nvim-dap-ui
+ 'williamboman/mason.nvim', -- Package manager for debug adapters
+ 'jay-babu/mason-nvim-dap.nvim', -- Mason integration for DAP
+ 'leoluz/nvim-dap-go', -- Go debugging support
+ 'mfussenegger/nvim-dap-python', -- Python debugging support
+ },
+ config = function()
+ setup_dap()
end,
}