From bde55c5fedf9812b1ee91337d8132fb4eb420be6 Mon Sep 17 00:00:00 2001 From: Jerens Lensun Date: Sat, 14 Feb 2026 19:30:42 +0800 Subject: [PATCH] feat: add plugin Signed-off-by: Jerens Lensun --- init.lua | 291 +++++++++++++++++++++------- lua/custom/plugins/git-conflict.lua | 11 ++ lua/custom/plugins/git-worktree.lua | 12 ++ lua/custom/plugins/none-ls.lua | 87 +++++++++ lua/custom/plugins/rust.lua | 7 + lua/custom/plugins/tmux.lua | 20 ++ lua/custom/plugins/typescript.lua | 7 + lua/kickstart/plugins/debug.lua | 260 ++++++++++++++----------- 8 files changed, 513 insertions(+), 182 deletions(-) create mode 100644 lua/custom/plugins/git-conflict.lua create mode 100644 lua/custom/plugins/git-worktree.lua create mode 100644 lua/custom/plugins/none-ls.lua create mode 100644 lua/custom/plugins/rust.lua create mode 100644 lua/custom/plugins/tmux.lua create mode 100644 lua/custom/plugins/typescript.lua diff --git a/init.lua b/init.lua index b98ffc6198a..89ce57cea8f 100644 --- a/init.lua +++ b/init.lua @@ -93,6 +93,90 @@ vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal vim.g.have_nerd_font = false +-- [[ LSP ]] +vim.g.rustaceanvim = function() + -- Update this path + local mason_registry = require 'mason-registry' + + local codelldb = vim.fn.expand '$MASON/packages/codelldb' + local extension_path = codelldb .. '/extension/' + local codelldb_path = extension_path .. 'adapter/codelldb' + local liblldb_path = extension_path .. 'lldb/lib/liblldb' + local this_os = vim.uv.os_uname().sysname + + -- The path is different on Windows + if this_os:find 'Windows' then + codelldb_path = extension_path .. 'adapter\\codelldb.exe' + liblldb_path = extension_path .. 'lldb\\bin\\liblldb.dll' + else + -- The liblldb extension is .so for Linux and .dylib for MacOS + liblldb_path = liblldb_path .. (this_os == 'Linux' and '.so' or '.dylib') + end + + local cfg = require 'rustaceanvim.config' + return { + --- Plugin configuration + tools = {}, + --- LSP Configuration + server = { + on_attach = function(client, bufnr) + -- you can also put keymaps in here + local opts = { noremap = true, silent = true } + + vim.api.nvim_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', { noremap = true, silent = true }) + end, + default_settings = { + -- rust-analyzer language server configuration + ['rust-analyzer'] = { + procMacro = { enable = true }, + cachePriming = { + enable = true, + numThreads = 12, + }, + diagnostics = { + enableExperimental = false, + }, + check = { + command = 'clippy', + allTargets = false, + allFeatures = false, + }, + cargo = { + allFeatures = false, + loadOutDirsFromCheck = true, + runBuildScripts = true, + }, + }, + }, + }, + -- DAP configuration + dap = { + adapter = cfg.get_codelldb_adapter(codelldb_path, liblldb_path), + }, + } +end + +vim.lsp.config('pyrefly', { + cmd = { 'pyrefly', 'lsp' }, + filetypes = { 'python' }, + root_dir = vim.fs.root(0, { 'pyproject.toml', 'setup.cfg', 'setup.py', '.git' }), + single_file_support = true, +}) + +vim.lsp.enable 'pyrefly' + +vim.api.nvim_create_autocmd('User', { + pattern = 'GitConflictDetected', + callback = function() + vim.notify('Conflict detected in ' .. vim.fn.expand '') + vim.keymap.set('n', 'cww', function() + engage.conflict_buster() + create_buffer_local_mappings() + end) + end, +}) + -- [[ Setting options ]] -- See `:help vim.o` -- NOTE: You can change these options as you wish! @@ -102,7 +186,7 @@ vim.g.have_nerd_font = false vim.o.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.o.relativenumber = true +vim.o.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.o.mouse = 'a' @@ -110,6 +194,18 @@ vim.o.mouse = 'a' -- Don't show the mode, since it's already in the status line vim.o.showmode = false +-- A in file is 2 spaces +vim.opt.tabstop = 2 + +-- Indentation amount +vim.opt.shiftwidth = 2 + +-- Editing behavior (backspace/del) +vim.opt.softtabstop = 2 + +-- Use spaces, not tabs +vim.opt.expandtab = true + -- Sync clipboard between OS and Neovim. -- Schedule the setting after `UiEnter` because it can increase startup-time. -- Remove this option if you want your OS clipboard to remain independent. @@ -174,6 +270,7 @@ vim.o.confirm = true vim.keymap.set('n', '', 'nohlsearch') -- Diagnostic keymaps +vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror message' }) vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier @@ -437,6 +534,14 @@ require('lazy').setup({ vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + -- Git Worktree + vim.keymap.set('n', 'gw', "lua require('telescope').extensions.git_worktree()CR", { + desc = 'Git Worktrees', + }) + vim.keymap.set('n', 'gW', "lua require('telescope').extensions.create_git_worktree()CR", { + desc = 'Create Git Worktree', + }) + -- Slightly advanced example of overriding default behavior and theme vim.keymap.set('n', '/', function() -- You can pass additional configuration to Telescope to change the theme, layout, etc. @@ -660,7 +765,7 @@ require('lazy').setup({ -- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities. -- So, we create new capabilities with blink.cmp, and then broadcast that to the servers. local capabilities = require('blink.cmp').get_lsp_capabilities() - + capabilities.offsetEncoding = { 'utf-8' } -- Enable the following language servers -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. -- @@ -673,7 +778,13 @@ require('lazy').setup({ local servers = { -- clangd = {}, -- gopls = {}, - -- pyright = {}, + -- pyright = { + -- settings = { + -- python = { + -- pythonPath = './.venv/bin/python', + -- }, + -- }, + -- }, -- rust_analyzer = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- @@ -682,7 +793,51 @@ require('lazy').setup({ -- -- But for many setups, the LSP (`ts_ls`) will work just fine -- ts_ls = {}, - -- + tailwindcss = { + filetypes = { 'html', 'css', 'javascriptreact', 'typescriptreact', 'vue', 'svelte' }, + -- If you need to add custom filetypes or logic: + -- settings = { + -- tailwindCSS = { + -- includeLanguages = { + -- elixir = "html-eex", + -- heex = "html-eex", + -- }, + -- }, + -- }, + }, + pylsp = { + settings = { + pylsp = { + plugins = { + pyflakes = { enabled = false }, + pycodestyle = { enabled = false }, + autopep8 = { enabled = false }, + yapf = { enabled = false }, + mccabe = { enabled = false }, + pylsp_mypy = { enabled = false }, + pylsp_black = { enabled = false }, + pylsp_isort = { enabled = false }, + }, + }, + }, + }, + ruff = { + -- Notes on code actions: https://github.com/astral-sh/ruff-lsp/issues/119#issuecomment-1595628355 + -- Get isort like behavior: https://github.com/astral-sh/ruff/issues/8926#issuecomment-1834048218 + commands = { + RuffAutofix = { + function() + vim.lsp.buf.execute_command { + command = 'ruff.applyAutofix', + arguments = { + { uri = vim.uri_from_bufnr(0) }, + }, + } + end, + description = 'Ruff: Fix all auto-fixable problems', + }, + }, + }, lua_ls = { -- cmd = { ... }, @@ -719,63 +874,59 @@ require('lazy').setup({ }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } - require('mason-lspconfig').setup { - ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) - automatic_installation = false, - handlers = { - function(server_name) - local server = servers[server_name] or {} - -- This handles overriding only values explicitly passed - -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for ts_ls) - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - require('lspconfig')[server_name].setup(server) - end, - }, - } + for server, cfg in pairs(servers) do + -- For each LSP server (cfg), we merge: + -- 1. A fresh empty table (to avoid mutating capabilities globally) + -- 2. Your capabilities object with Neovim + cmp features + -- 3. Any server-specific cfg.capabilities if defined in `servers` + cfg.capabilities = vim.tbl_deep_extend('force', {}, capabilities, cfg.capabilities or {}) + + vim.lsp.config(server, cfg) + vim.lsp.enable(server) + end end, }, - { -- Autoformat - 'stevearc/conform.nvim', - event = { 'BufWritePre' }, - cmd = { 'ConformInfo' }, - keys = { - { - 'f', - function() - require('conform').format { async = true, lsp_format = 'fallback' } - end, - mode = '', - desc = '[F]ormat buffer', - }, - }, - opts = { - notify_on_error = false, - format_on_save = function(bufnr) - -- Disable "format_on_save lsp_fallback" for languages that don't - -- have a well standardized coding style. You can add additional - -- languages here or re-enable it for the disabled ones. - local disable_filetypes = { c = true, cpp = true } - if disable_filetypes[vim.bo[bufnr].filetype] then - return nil - else - return { - timeout_ms = 500, - lsp_format = 'fallback', - } - end - end, - formatters_by_ft = { - lua = { 'stylua' }, - -- Conform can also run multiple formatters sequentially - -- python = { "isort", "black" }, - -- - -- You can use 'stop_after_first' to run the first available formatter from the list - -- javascript = { "prettierd", "prettier", stop_after_first = true }, - }, - }, - }, + -- { -- Autoformat + -- 'stevearc/conform.nvim', + -- event = { 'BufWritePre' }, + -- cmd = { 'ConformInfo' }, + -- keys = { + -- { + -- 'f', + -- function() + -- require('conform').format { async = true, lsp_format = 'fallback' } + -- end, + -- mode = '', + -- desc = '[F]ormat buffer', + -- }, + -- }, + -- opts = { + -- notify_on_error = false, + -- format_on_save = function(bufnr) + -- -- Disable "format_on_save lsp_fallback" for languages that don't + -- -- have a well standardized coding style. You can add additional + -- -- languages here or re-enable it for the disabled ones. + -- local disable_filetypes = { c = true, cpp = true } + -- if disable_filetypes[vim.bo[bufnr].filetype] then + -- return nil + -- else + -- return { + -- timeout_ms = 500, + -- lsp_format = 'fallback', + -- } + -- end + -- end, + -- formatters_by_ft = { + -- lua = { 'stylua' }, + -- -- Conform can also run multiple formatters sequentially + -- -- python = { "isort", "black" }, + -- -- + -- -- You can use 'stop_after_first' to run the first available formatter from the list + -- -- javascript = { "prettierd", "prettier", stop_after_first = true }, + -- }, + -- }, + -- }, { -- Autocompletion 'saghen/blink.cmp', @@ -799,12 +950,12 @@ require('lazy').setup({ -- `friendly-snippets` contains a variety of premade snippets. -- See the README about individual language/framework/plugin snippets: -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, + { + 'rafamadriz/friendly-snippets', + config = function() + require('luasnip.loaders.from_vscode').lazy_load() + end, + }, }, opts = {}, }, @@ -944,7 +1095,7 @@ require('lazy').setup({ main = 'nvim-treesitter.configs', -- Sets main module to use for opts -- [[ Configure Treesitter ]] See `:help nvim-treesitter` opts = { - ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, + ensure_installed = { 'python', 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, -- Autoinstall languages that are not installed auto_install = true, highlight = { @@ -973,18 +1124,18 @@ require('lazy').setup({ -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - -- require 'kickstart.plugins.debug', + require 'kickstart.plugins.debug', -- require 'kickstart.plugins.indent_line', - -- require 'kickstart.plugins.lint', + require 'kickstart.plugins.lint', -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', - -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps + require 'kickstart.plugins.neo-tree', + require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! diff --git a/lua/custom/plugins/git-conflict.lua b/lua/custom/plugins/git-conflict.lua new file mode 100644 index 00000000000..aa718bc35bd --- /dev/null +++ b/lua/custom/plugins/git-conflict.lua @@ -0,0 +1,11 @@ +-- You can add your own plugins here or in other files in this directory! +-- I promise not to create any merge conflicts in this directory :) +-- +-- See the kickstart.nvim README for more information +return { + { + 'akinsho/git-conflict.nvim', + version = '*', + config = true, + }, +} diff --git a/lua/custom/plugins/git-worktree.lua b/lua/custom/plugins/git-worktree.lua new file mode 100644 index 00000000000..fdb209d71bf --- /dev/null +++ b/lua/custom/plugins/git-worktree.lua @@ -0,0 +1,12 @@ +return { + { + 'ThePrimeagen/git-worktree.nvim', + dependencies = { + 'nvim-telescope/telescope.nvim', + }, + config = function() + require('git-worktree').setup() + require('telescope').load_extension 'git_worktree' + end, + }, +} diff --git a/lua/custom/plugins/none-ls.lua b/lua/custom/plugins/none-ls.lua new file mode 100644 index 00000000000..ddf05778f12 --- /dev/null +++ b/lua/custom/plugins/none-ls.lua @@ -0,0 +1,87 @@ +-- Format on save and linters +return { + { + 'nvimtools/none-ls.nvim', + dependencies = { + 'nvimtools/none-ls-extras.nvim', + 'jayp0521/mason-null-ls.nvim', -- ensure dependencies are installed + }, + config = function() + local null_ls = require 'null-ls' + local formatting = null_ls.builtins.formatting -- to setup formatters + local diagnostics = null_ls.builtins.diagnostics -- to setup linters + + -- list of formatters & linters for mason to install + require('mason-null-ls').setup { + ensure_installed = { + 'checkmake', + 'prettier', -- ts/js formatter + 'stylua', -- lua formatter + 'eslint_d', -- ts/js linter + 'shfmt', + 'ruff', + }, + -- auto-install configured formatters & linters (with null-ls) + automatic_installation = true, + } + + local sources = { + -- Linters + diagnostics.checkmake, + + -- ESLint diagnostics (ESLint 9 compatible) + require('none-ls.diagnostics.eslint_d').with { + prefer_local = 'node_modules/.bin', + filetypes = { + 'javascript', + 'typescript', + 'javascriptreact', + 'typescriptreact', + }, + condition = function(utils) + return utils.root_has_file { + 'eslint.config.js', + 'eslint.config.mjs', + 'eslint.config.cjs', + } + end, + }, + + -- ESLint code actions + require('none-ls.code_actions.eslint_d').with { + prefer_local = 'node_modules/.bin', + }, + + -- Formatters + formatting.prettier.with { + filetypes = { 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'html', 'json', 'yaml', 'markdown' }, + }, + + formatting.stylua, + formatting.shfmt.with { args = { '-i', '4' } }, + formatting.terraform_fmt, + require('none-ls.formatting.ruff').with { extra_args = { '--config=pyproject.toml' } }, + -- require('none-ls.formatting.ruff_format').with { extra_args = { '--config=pyproject.toml' } }, + } + + local augroup = vim.api.nvim_create_augroup('LspFormatting', {}) + null_ls.setup { + -- debug = true, -- Enable debug mode. Inspect logs with :NullLsLog. + sources = sources, + -- you can reuse a shared lspconfig on_attach callback here + on_attach = function(client, bufnr) + if client.supports_method 'textDocument/formatting' then + vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr } + vim.api.nvim_create_autocmd('BufWritePre', { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format { async = false } + end, + }) + end + end, + } + end, + }, +} diff --git a/lua/custom/plugins/rust.lua b/lua/custom/plugins/rust.lua new file mode 100644 index 00000000000..03186ac9ef0 --- /dev/null +++ b/lua/custom/plugins/rust.lua @@ -0,0 +1,7 @@ +return { + { + 'mrcjkb/rustaceanvim', + version = '^6', -- Recommended + lazy = false, -- This plugin is already lazy + }, +} diff --git a/lua/custom/plugins/tmux.lua b/lua/custom/plugins/tmux.lua new file mode 100644 index 00000000000..2ffb7a4fb2e --- /dev/null +++ b/lua/custom/plugins/tmux.lua @@ -0,0 +1,20 @@ +return { + { + 'christoomey/vim-tmux-navigator', + cmd = { + 'TmuxNavigateLeft', + 'TmuxNavigateDown', + 'TmuxNavigateUp', + 'TmuxNavigateRight', + 'TmuxNavigatePrevious', + 'TmuxNavigatorProcessList', + }, + keys = { + { '', 'TmuxNavigateLeft' }, + { '', 'TmuxNavigateDown' }, + { '', 'TmuxNavigateUp' }, + { '', 'TmuxNavigateRight' }, + { '', 'TmuxNavigatePrevious' }, + }, + }, +} diff --git a/lua/custom/plugins/typescript.lua b/lua/custom/plugins/typescript.lua new file mode 100644 index 00000000000..368002074d2 --- /dev/null +++ b/lua/custom/plugins/typescript.lua @@ -0,0 +1,7 @@ +return { + { + 'pmizio/typescript-tools.nvim', + dependencies = { 'nvim-lua/plenary.nvim', 'neovim/nvim-lspconfig' }, + opts = {}, + }, +} diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 8e332bf2ff9..dd9350cb3d5 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -7,142 +7,178 @@ -- kickstart.nvim and not kitchen-sink.nvim ;) return { - -- NOTE: Yes, you can install new plugins here! 'mfussenegger/nvim-dap', - -- NOTE: And you can specify dependencies as well dependencies = { - -- Creates a beautiful debugger UI + -- Create a beutifull debugger UI 'rcarriga/nvim-dap-ui', - - -- Required dependency for nvim-dap-ui + -- Required dependency for nvim dap ui + 'theHamsta/nvim-dap-virtual-text', 'nvim-neotest/nvim-nio', - - -- Installs the debug adapters for you - 'mason-org/mason.nvim', + -- Install the debug adapter for you + 'williamboman/mason.nvim', 'jay-babu/mason-nvim-dap.nvim', - - -- Add your own debuggers here + -- Add your own debugger here + 'mfussenegger/nvim-dap-python', 'leoluz/nvim-dap-go', }, - keys = { - -- Basic debugging keymaps, feel free to change to your liking! - { - '', - function() - require('dap').continue() - end, - desc = 'Debug: Start/Continue', - }, - { - '', - function() - require('dap').step_into() - end, - desc = 'Debug: Step Into', - }, - { - '', - function() - require('dap').step_over() - end, - desc = 'Debug: Step Over', - }, - { - '', - function() - require('dap').step_out() - end, - desc = 'Debug: Step Out', - }, - { - 'b', - function() - require('dap').toggle_breakpoint() - end, - desc = 'Debug: Toggle Breakpoint', - }, - { - 'B', - function() - require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') - end, - desc = 'Debug: Set Breakpoint', - }, - -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. - { - '', - function() - require('dapui').toggle() - end, - desc = 'Debug: See last session result.', - }, - }, config = function() local dap = require 'dap' - local dapui = require 'dapui' + local ui = require 'dapui' + + require('dapui').setup() + require('dap-go').setup() require('mason-nvim-dap').setup { - -- Makes a best effort to setup the various debuggers with - -- reasonable debug configurations - automatic_installation = true, + automatic_instalation = true, - -- You can provide additional configuration to the handlers, - -- see mason-nvim-dap README for more information handlers = {}, - -- You'll need to check that you have the required things installed - -- online, please don't ask me how to install them :) ensure_installed = { - -- Update this to ensure that you have the debuggers for the langs you want 'delve', + 'python', }, } - -- Dap UI setup - -- For more information, see |:help nvim-dap-ui| - dapui.setup { - -- Set icons to characters that are more likely to work in every terminal. - -- Feel free to remove or use ones that you like more! :) - -- Don't feel like these are good choices. - icons = { expanded = '▾', collapsed = '▸', current_frame = '*' }, - controls = { - icons = { - pause = '⏸', - play = '▶', - step_into = '⏎', - step_over = '⏭', - step_out = '⏮', - step_back = 'b', - run_last = '▶▶', - terminate = '⏹', - disconnect = '⏏', + require('nvim-dap-virtual-text').setup { + display_callback = function(variable) + local name = string.lower(variable.name) + local value = string.lower(variable.value) + if name:match 'secret' or name:match 'api' or value:match 'secret' or value:match 'api' then + return '*****' + end + + if #variable.value > 15 then + return ' ' .. string.sub(variable.value, 1, 15) .. '... ' + end + + return ' ' .. variable.value + end, + } + + -- Handled by nvim-dap-go + -- dap.adapters.go = { + -- type = "server", + -- port = "${port}", + -- executable = { + -- command = "dlv", + -- args = { "dap", "-l", "127.0.0.1:${port}" }, + -- }, + -- } + + local elixir_ls_debugger = vim.fn.exepath 'elixir-ls-debugger' + if elixir_ls_debugger ~= '' then + dap.adapters.mix_task = { + type = 'executable', + command = elixir_ls_debugger, + } + + dap.configurations.elixir = { + { + type = 'mix_task', + name = 'phoenix server', + task = 'phx.server', + request = 'launch', + projectDir = '${workspaceFolder}', + exitAfterTaskReturns = false, + debugAutoInterpretAllModules = false, }, + } + end + + -- CodeLLDB debug adapter location + local codelldb = vim.fn.expand '$MASON/packages/codelldb' + local extension_path = codelldb .. '/extension/' + local codelldb_path = extension_path .. 'adapter/codelldb' + + -- Configure the LLDB adapter + dap.adapters.codelldb = { + type = 'server', + port = '${port}', + executable = { + command = codelldb_path, + args = { '--port', '${port}' }, }, + enrich_config = function(config, on_config) + -- If the configuration(s) in `launch.json` contains a `cargo` section + -- send the configuration off to the cargo_inspector. + if config['cargo'] ~= nil then + on_config(cargo_inspector(config)) + end + end, } - -- 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, + -- Configure LLDB adapter + dap.adapters.lldb = { + type = 'server', + port = '${port}', + executable = { + command = codelldb_path, + args = { '--port', '${port}' }, + detached = false, }, } + + -- Default debug configuration for C, C++ + dap.configurations.c = { + { + name = 'Debug an Executable', + type = 'lldb', + request = 'launch', + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + }, + } + + dap.configurations.cpp = dap.configurations.c + dap.configurations.rust = { + { + name = 'Debug an Executable', + type = 'lldb', + request = 'launch', + program = function() + local cwd = vim.fn.getcwd() + local default_binary = cwd .. '/target/debug/' .. vim.fn.fnamemodify(cwd, ':t') + return vim.fn.input('Path to executable: ', default_binary, 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + }, + } + + -- Override default configurations with `launch.json` + require('dap.ext.vscode').load_launchjs('.nvim/launch.json', { lldb = { 'c', 'cpp', 'rust' } }) + + vim.keymap.set('n', 'b', dap.toggle_breakpoint) + vim.keymap.set('n', 'gb', dap.run_to_cursor) + + -- Eval var under cursor + vim.keymap.set('n', '?', function() + require('dapui').eval(nil, { enter = true }) + end) + + vim.keymap.set('n', '', dap.continue) + vim.keymap.set('n', '', dap.step_into) + vim.keymap.set('n', '', dap.step_over) + vim.keymap.set('n', '', dap.step_out) + vim.keymap.set('n', '', dap.step_back) + vim.keymap.set('n', '', dap.restart) + + dap.listeners.before.attach.dapui_config = function() + ui.open() + end + dap.listeners.before.launch.dapui_config = function() + ui.open() + end + dap.listeners.before.event_terminated.dapui_config = function() + ui.close() + end + dap.listeners.before.event_exited.dapui_config = function() + ui.close() + end + + require('dap-python').setup() end, }