From fa9ba544bc8c8f4398cd2138841b7d464bb3963a Mon Sep 17 00:00:00 2001 From: "Vito G. Graffagnino" Date: Fri, 22 Jul 2022 16:42:35 +0100 Subject: Tidied up dap, and the handlers --- lua/user/dap.lua | 36 ++++++++++++++++++++++++++++++++---- lua/user/keymaps.lua | 2 +- lua/user/lsp/handlers.lua | 8 +++----- 3 files changed, 36 insertions(+), 10 deletions(-) (limited to 'lua/user') diff --git a/lua/user/dap.lua b/lua/user/dap.lua index b51dfd7..fb95eee 100644 --- a/lua/user/dap.lua +++ b/lua/user/dap.lua @@ -13,16 +13,44 @@ if not dap_ui_status_ok then return end -if not dap_install_status_ok then - return -end - dap_install.setup({ installation_path = vim.fn.stdpath('data') .. "/dapinstall/", }) dap_install.config("python", {}) +--dap setup + +dap.adapters.python = { + type = 'executable'; + command = 'python'; + args = { '-m', 'debugpy.adapter' }; +} +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 '/usr/bin/python' + end + end; + }, +} -- dapui.setup() dapui.setup({ icons = { expanded = "▾", collapsed = "▸" }, diff --git a/lua/user/keymaps.lua b/lua/user/keymaps.lua index af377f5..10a8ee8 100644 --- a/lua/user/keymaps.lua +++ b/lua/user/keymaps.lua @@ -82,7 +82,7 @@ keymap("n", "ro", ":MagmaShowOutput", opts) -- LSP -- keymap("n", "la", "lua vim.lsp.buf.code_action()", opts) keymap("n", "ld", "Telescope lsp_document_diagnostics", opts) -keymap("n", "lf", "lua vim.lsp.buf.formatting()", opts) +keymap("n", "lf", "lua vim.lsp.buf.formatting_sync()", opts) keymap("n", "lF", "LspToggleAutoFormat", opts) keymap("n", "li", "LspInfo", opts) keymap("n", "lI", "LspInstallInfo", opts) diff --git a/lua/user/lsp/handlers.lua b/lua/user/lsp/handlers.lua index fc5d7d3..e668ad2 100644 --- a/lua/user/lsp/handlers.lua +++ b/lua/user/lsp/handlers.lua @@ -73,16 +73,14 @@ local function lsp_keymaps(bufnr) vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "lua vim.lsp.buf.implementation()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "", "lua vim.lsp.buf.signature_help()", opts) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "ca", "lua vim.lsp.buf.code_action()", opts) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "f", "lua vim.diagnostic.open_float()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", 'lua vim.diagnostic.goto_prev({ border = "rounded" })', opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gl", "lua vim.lsp.diagnostic.open_float()", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "gl", "lua vim.lsp.diagnostic.open_float()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gl", "lua vim.diagnostic.open_float()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", 'lua vim.diagnostic.goto_next({ border = "rounded" })', opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "q", "lua vim.diagnostic.setloclist()", opts) - vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]] + vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting_sync()' ]] end M.on_attach = function(client, bufnr) -- cgit v1.2.3