From: Ruben Beltran del Rio Date: Thu, 21 Sep 2023 20:21:56 +0000 (+0200) Subject: Add DAP X-Git-Url: https://git.r.bdr.sh/rbdr/dotfiles/commitdiff_plain/cf43e2c226f3d28ffd15abef733fdf06de253e40?ds=sidebyside Add DAP --- diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 7a3c907..9395a00 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -99,5 +99,9 @@ vim.keymap.set('n', 'gy', '(coc-type-definition)', {silent = true}) vim.keymap.set('n', 'gi', '(coc-implementation)', {silent = true}) vim.keymap.set('n', 'gr', '(coc-references)', {silent = true}) +vim.keymap.set('n', 'd', function() + require("dapui").toggle() +end) + -- Plugins require('plugins') diff --git a/config/nvim/lazy-lock.json b/config/nvim/lazy-lock.json index ae87723..2416b59 100644 --- a/config/nvim/lazy-lock.json +++ b/config/nvim/lazy-lock.json @@ -1,18 +1,22 @@ { "LargeFile": { "branch": "master", "commit": "3941a37b2b0288524300348a39521a46539bf9f6" }, "api-notation.vim": { "branch": "master", "commit": "b6f0708fb9f009b7051db514423e9ebf86bc9af4" }, - "coc.nvim": { "branch": "release", "commit": "a18ac7e9c34d6b0d7bc4d81dedc0db1d9e229371" }, + "coc.nvim": { "branch": "release", "commit": "e4cee8e6c310663d2d81489dd9155889bbcd8d12" }, "dart-vim-plugin": { "branch": "master", "commit": "928302ec931caf0dcf21835cca284ccd2b192f7b" }, - "fzf-lua": { "branch": "main", "commit": "2a00373bd60245a1397bdf010bd23b2b51b2a25a" }, + "fzf-lua": { "branch": "main", "commit": "335f908b912504015fefeeccacb4c325029d2bfc" }, "gemini.vim": { "branch": "master", "commit": "c9efb59c97b71c28d4678c79fd21fbdd3a69d196" }, "kotlin-vim": { "branch": "master", "commit": "53fe045906df8eeb07cb77b078fc93acda6c90b8" }, "lazy.nvim": { "branch": "main", "commit": "2a9354c7d2368d78cbd5575a51a2af5bd8a6ad01" }, + "neodev.nvim": { "branch": "main", "commit": "e9dd1535759794635a951644c183beb327879407" }, + "nvim-dap": { "branch": "master", "commit": "b3d4408e29d924fe130c9397a7c3b3630b3ea671" }, + "nvim-dap-ui": { "branch": "master", "commit": "34160a7ce6072ef332f350ae1d4a6a501daf0159" }, + "nvim-lspconfig": { "branch": "master", "commit": "4266f9bb36b4fb09edd19b67d95043cf7ff88ddf" }, "rust.vim": { "branch": "master", "commit": "889b9a7515db477f4cb6808bef1769e53493c578" }, "snes-syntax-vim": { "branch": "master", "commit": "a6a699c8905f7b6119bf91e44f960667d9f03d59" }, "typescript-vim": { "branch": "master", "commit": "31ede5ad905ce4159a5e285073a391daa3bf83fa" }, "vim-closer": { "branch": "master", "commit": "6007d9db0a35e983af246b667282606612076b07" }, "vim-endwise": { "branch": "master", "commit": "e714ac3bcfd5a90038de49c3254eded7c70ae3c3" }, - "vim-fugitive": { "branch": "master", "commit": "6fcb0ad03982de646e3fecb6915e585651b9a9fb" }, + "vim-fugitive": { "branch": "master", "commit": "99db68d9b3304580bd383da7aaee05c7a954a344" }, "vim-glsl": { "branch": "master", "commit": "bfd330a271933c3372fcfa8ce052970746c8e9dd" }, "vim-graphql": { "branch": "master", "commit": "6089a44e89e76f9eba138fb68bfd132420404ff7" }, "vim-indent-object": { "branch": "master", "commit": "5c5b24c959478929b54a9e831a8e2e651a465965" }, 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()