From 472208ea954296d11c0d2614b6c730b9b0570e34 Mon Sep 17 00:00:00 2001 From: Martin Larsson Date: Sat, 11 Jan 2025 19:08:40 +0100 Subject: [PATCH] Setup debug adapters for codelldb, debugpy and gopls. Also remove nvim-dap-profiles :( Apparently there is a way to do the same thing using launch.json built into dap, much better than my solution. --- home/.config/nvim/init.lua | 5 ++- .../nvim/lua/dap/adapters/codelldb.lua | 8 ++++ .../.config/nvim/lua/dap/adapters/debugpy.lua | 0 home/.config/nvim/lua/dap/setup.lua | 45 +++++++++++++++++++ home/.config/nvim/lua/lsp/servers/pyright.lua | 21 +++++++++ home/.config/nvim/lua/plugs/mason.lua | 4 ++ .../nvim/lua/plugs/{dap.lua => nvim-dap.lua} | 18 +++++--- home/.config/nvim/lua/plugs/treesitter.lua | 1 + 8 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 home/.config/nvim/lua/dap/adapters/codelldb.lua create mode 100644 home/.config/nvim/lua/dap/adapters/debugpy.lua create mode 100644 home/.config/nvim/lua/dap/setup.lua create mode 100644 home/.config/nvim/lua/lsp/servers/pyright.lua rename home/.config/nvim/lua/plugs/{dap.lua => nvim-dap.lua} (94%) diff --git a/home/.config/nvim/init.lua b/home/.config/nvim/init.lua index 1913108..788d0a1 100644 --- a/home/.config/nvim/init.lua +++ b/home/.config/nvim/init.lua @@ -29,7 +29,10 @@ require("terminal") require("window_management").setup() -- Set configs for servers and enable them in the Neovim LSP Client -require("lsp") +require("lsp/setup") + +-- Set configs for nvim-dap so we can debug +require("dap/setup") -- See ":help vim.highlight.on_yank()" setup_yank_highlight() diff --git a/home/.config/nvim/lua/dap/adapters/codelldb.lua b/home/.config/nvim/lua/dap/adapters/codelldb.lua new file mode 100644 index 0000000..d193344 --- /dev/null +++ b/home/.config/nvim/lua/dap/adapters/codelldb.lua @@ -0,0 +1,8 @@ +return { + type = "server", + port = "${port}", + executable = { + command = vim.fn.exepath("codelldb"), -- Update with your codelldb binary path + args = { "--port", "${port}" }, + }, +} diff --git a/home/.config/nvim/lua/dap/adapters/debugpy.lua b/home/.config/nvim/lua/dap/adapters/debugpy.lua new file mode 100644 index 0000000..e69de29 diff --git a/home/.config/nvim/lua/dap/setup.lua b/home/.config/nvim/lua/dap/setup.lua new file mode 100644 index 0000000..98ceff5 --- /dev/null +++ b/home/.config/nvim/lua/dap/setup.lua @@ -0,0 +1,45 @@ +local utils = require("utils") +local dap = require("dap") + +--[[ +.vscode/launch.json: +---------------------------- +{ + "version": "0.2.0", + "configurations": [ + { + "type": "name_of_adapter", + "request": "launch/attach", + "name": "Friendly name", + "program": "${workspaceFolder}/path/to/executable", + "cwd": "${workspaceFolder}", + "args": [], + "stopOnEntry": false, + "environment": [] + } + ] +} +---------------------------- +]] + +local dir_path = "dap/adapters" +utils.foreach(utils.get_file_names_in_dir(dir_path, "*.lua", true), function(adapter) + dap.adapters[adapter] = require(dir_path .. "/" .. adapter) +end) + +-- Do not define default fallbacks until I have a better way of handling a default selected configuration. +-- I never want to be prompted for a configuration, we should have ae serialized active config which is always run unless changed. +-- -- Define configurations +-- dap.configurations.cpp = { +-- { +-- name = "Launch File", +-- type = "codelldb", +-- request = "launch", +-- program = function() +-- return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") +-- end, +-- cwd = "${workspaceFolder}", +-- stopOnEntry = false, +-- args = {}, +-- }, +-- } diff --git a/home/.config/nvim/lua/lsp/servers/pyright.lua b/home/.config/nvim/lua/lsp/servers/pyright.lua new file mode 100644 index 0000000..e92ae42 --- /dev/null +++ b/home/.config/nvim/lua/lsp/servers/pyright.lua @@ -0,0 +1,21 @@ +return { + cmd = { "pyright-langserver", "--stdio" }, + filetypes = { "python", "py" }, + root_markers = { + "pyproject.toml", + "setup.py", + "setup.cfg", + "requirements.txt", + "Pipfile", + "pyrightconfig.json", + }, + settings = { + python = { + analysis = { + autoSearchPaths = true, + useLibraryCodeForTypes = true, + diagnosticMode = "openFilesOnly", + }, + }, + }, +} diff --git a/home/.config/nvim/lua/plugs/mason.lua b/home/.config/nvim/lua/plugs/mason.lua index 8adf2c2..71707b7 100644 --- a/home/.config/nvim/lua/plugs/mason.lua +++ b/home/.config/nvim/lua/plugs/mason.lua @@ -26,6 +26,10 @@ return { -- CMake "cmake-language-server", "cmakelang", + + -- Python + "debugpy", + "pyright", }, }) end diff --git a/home/.config/nvim/lua/plugs/dap.lua b/home/.config/nvim/lua/plugs/nvim-dap.lua similarity index 94% rename from home/.config/nvim/lua/plugs/dap.lua rename to home/.config/nvim/lua/plugs/nvim-dap.lua index 10df314..0fb52d3 100644 --- a/home/.config/nvim/lua/plugs/dap.lua +++ b/home/.config/nvim/lua/plugs/nvim-dap.lua @@ -5,24 +5,30 @@ return { "mfussenegger/nvim-dap", dependencies = { "rcarriga/nvim-dap-ui", + + -- Special adapters + "leoluz/nvim-dap-go", + "mfussenegger/nvim-dap-python", + { "nvim-neotest/nvim-nio", lazy = true }, "LiadOz/nvim-dap-repl-highlights", "theHamsta/nvim-dap-virtual-text", "Weissle/persistent-breakpoints.nvim", - { - "LarssonMartin1998/nvim-dap-profiles", - opts = {}, - }, - "leoluz/nvim-dap-go", }, config = function() local dap = require("dap") local dapui = require("dapui") + dapui.setup() + -- Special adapters + require("dap-go").setup() + require("dap-python").setup("python3") + -- Special adapters + + require("dap.ext.vscode").load_launchjs() require("persistent-breakpoints").setup { load_breakpoints_event = { "BufReadPost" } } - require("dap-go").setup() local stepping_keymaps = { n = { diff --git a/home/.config/nvim/lua/plugs/treesitter.lua b/home/.config/nvim/lua/plugs/treesitter.lua index de4a56b..dbed89d 100644 --- a/home/.config/nvim/lua/plugs/treesitter.lua +++ b/home/.config/nvim/lua/plugs/treesitter.lua @@ -46,6 +46,7 @@ return { "regex", "dap_repl", "muttrc", + "python", }, sync_install = false, -- This can be updated to a list of languages instead of defaulting to true