From cf43e2c226f3d28ffd15abef733fdf06de253e40 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Thu, 21 Sep 2023 22:21:56 +0200 Subject: Add DAP --- config/nvim/lua/dap_config.lua | 112 +++++++++++++++++++++++++++++++++++++++++ config/nvim/lua/plugins.lua | 9 ++++ 2 files changed, 121 insertions(+) create mode 100644 config/nvim/lua/dap_config.lua (limited to 'config/nvim/lua') diff --git a/config/nvim/lua/dap_config.lua b/config/nvim/lua/dap_config.lua new file mode 100644 index 0000000..446315a --- /dev/null +++ b/config/nvim/lua/dap_config.lua @@ -0,0 +1,112 @@ +local dap = require('dap') + +dap.adapters.node2 = { + type = 'executable', + command = 'node', + args = {os.getenv('HOME') .. '/projects/tools/vscode-node-debug2/out/src/nodeDebug.js'}, +} +dap.configurations.javascript = { + { + name = 'Launch', + type = 'node2', + request = 'launch', + program = '${file}', + cwd = vim.fn.getcwd(), + sourceMaps = true, + protocol = 'inspector', + console = 'integratedTerminal', + }, + { + -- For this to work you need to make sure the node process is started with the `--inspect` flag. + name = 'Attach to process', + type = 'node2', + request = 'attach', + processId = require'dap.utils'.pick_process, + }, +} + +dap.adapters.firefox = { + type = 'executable', + command = 'node', + args = {os.getenv('HOME') .. '/projects/tools/vscode-firefox-debug/dist/adapter.bundle.js'}, +} + +dap.configurations.typescript = { + { + name = 'Debug with Firefox', + type = 'firefox', + request = 'launch', + reAttach = true, + url = 'http://localhost:3000', + webRoot = '${workspaceFolder}', + firefoxExecutable = '/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox' + } +} + +dap.configurations.typescriptreact = { + { + name = 'Debug with Firefox', + type = 'firefox', + request = 'launch', + reAttach = true, + url = 'http://localhost:3000', + webRoot = '${workspaceFolder}', + firefoxExecutable = '/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox' + } +} + +dap.adapters.python = function(cb, config) + if config.request == 'attach' then + ---@diagnostic disable-next-line: undefined-field + local port = (config.connect or config).port + ---@diagnostic disable-next-line: undefined-field + local host = (config.connect or config).host or '127.0.0.1' + cb({ + type = 'server', + port = assert(port, '`connect.port` is required for a python `attach` configuration'), + host = host, + options = { + source_filetype = 'python', + }, + }) + else + cb({ + type = 'executable', + command = os.getenv('HOME') .. '/.asdf/shims/python', + args = { '-m', 'debugpy.adapter' }, + options = { + source_filetype = 'python', + }, + }) + end +end + +dap.configurations.python = { + { + -- 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 + + program = "${file}"; -- This configuration will launch the current file if used. + pythonPath = function() + -- debugpy supports launching an application with a different interpreter then the one used to launch debugpy itself. + -- The code below looks for a `venv` or `.venv` folder in the current directly and uses the python within. + -- You could adapt this - to for example use the `VIRTUAL_ENV` environment variable. + local cwd = vim.fn.getcwd() + if vim.fn.executable(cwd .. '/venv/bin/python') == 1 then + return cwd .. '/venv/bin/python' + elseif vim.fn.executable(cwd .. '/.venv/bin/python') == 1 then + return cwd .. '/.venv/bin/python' + else + return os.getenv('HOME') .. '/.asdf/shims/python' + end + end; + }, +} + +require('neodev').setup({ + library = { plugins = { "nvim-dap-ui" }, types = true } +}) diff --git a/config/nvim/lua/plugins.lua b/config/nvim/lua/plugins.lua index 7a34348..971c441 100644 --- a/config/nvim/lua/plugins.lua +++ b/config/nvim/lua/plugins.lua @@ -60,6 +60,12 @@ require('lazy').setup({ 'dart-lang/dart-vim-plugin', 'ziglang/zig.vim', + -- Debugging + 'neovim/nvim-lspconfig', + 'folke/neodev.nvim', + 'mfussenegger/nvim-dap', + 'rcarriga/nvim-dap-ui', + -- Editing 'tpope/vim-endwise', 'rstacruz/vim-closer', @@ -71,3 +77,6 @@ require('lazy').setup({ 'tpope/vim-fugitive', 'milkypostman/vim-togglelist' }) + +require('dap_config') +require("dapui").setup() -- cgit