mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-23 04:51:08 +00:00
## Description
Uses a less hacky and now officially-supported way of getting the
debugpy DAP adapter path for nvim-dap-python.
Since https://github.com/mfussenegger/nvim-dap-python/pull/184,
nvim-dap-python can start the debugpy adapter using the
`debugpy-adapter` executable. Since
[Mason](f7c1c2fde2/packages/debugpy/package.yaml (L17))
and [now debugpy itself](https://github.com/microsoft/debugpy/pull/1870)
provide this executable, there's no need to get the `python` executable
from debugpy's venv.
I've gone with just `"debugpy-adapter"` rather than
`LazyVim.get_pkg_path("debugpy", "debugpy-adapter")` so that a
system-wide installation of debugpy can also be used.
## Related Issue(s)
<!--
If this PR fixes any issues, please link to the issue here.
- Fixes #<issue_number>
-->
## Screenshots
<!-- Add screenshots of the changes if applicable. -->
## Checklist
- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
143 lines
3.6 KiB
Lua
143 lines
3.6 KiB
Lua
if lazyvim_docs then
|
|
-- LSP Server to use for Python.
|
|
-- Set to "basedpyright" to use basedpyright instead of pyright.
|
|
vim.g.lazyvim_python_lsp = "pyright"
|
|
-- Set to "ruff_lsp" to use the old LSP implementation version.
|
|
vim.g.lazyvim_python_ruff = "ruff"
|
|
end
|
|
|
|
local lsp = vim.g.lazyvim_python_lsp or "pyright"
|
|
local ruff = vim.g.lazyvim_python_ruff or "ruff"
|
|
|
|
return {
|
|
recommended = function()
|
|
return LazyVim.extras.wants({
|
|
ft = "python",
|
|
root = {
|
|
"pyproject.toml",
|
|
"setup.py",
|
|
"setup.cfg",
|
|
"requirements.txt",
|
|
"Pipfile",
|
|
"pyrightconfig.json",
|
|
},
|
|
})
|
|
end,
|
|
{
|
|
"nvim-treesitter/nvim-treesitter",
|
|
opts = { ensure_installed = { "ninja", "rst" } },
|
|
},
|
|
{
|
|
"neovim/nvim-lspconfig",
|
|
opts = {
|
|
servers = {
|
|
ruff = {
|
|
cmd_env = { RUFF_TRACE = "messages" },
|
|
init_options = {
|
|
settings = {
|
|
logLevel = "error",
|
|
},
|
|
},
|
|
keys = {
|
|
{
|
|
"<leader>co",
|
|
LazyVim.lsp.action["source.organizeImports"],
|
|
desc = "Organize Imports",
|
|
},
|
|
},
|
|
},
|
|
ruff_lsp = {
|
|
keys = {
|
|
{
|
|
"<leader>co",
|
|
LazyVim.lsp.action["source.organizeImports"],
|
|
desc = "Organize Imports",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
setup = {
|
|
[ruff] = function()
|
|
LazyVim.lsp.on_attach(function(client, _)
|
|
-- Disable hover in favor of Pyright
|
|
client.server_capabilities.hoverProvider = false
|
|
end, ruff)
|
|
end,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"neovim/nvim-lspconfig",
|
|
opts = function(_, opts)
|
|
local servers = { "pyright", "basedpyright", "ruff", "ruff_lsp", ruff, lsp }
|
|
for _, server in ipairs(servers) do
|
|
opts.servers[server] = opts.servers[server] or {}
|
|
opts.servers[server].enabled = server == lsp or server == ruff
|
|
end
|
|
end,
|
|
},
|
|
{
|
|
"nvim-neotest/neotest",
|
|
optional = true,
|
|
dependencies = {
|
|
"nvim-neotest/neotest-python",
|
|
},
|
|
opts = {
|
|
adapters = {
|
|
["neotest-python"] = {
|
|
-- Here you can specify the settings for the adapter, i.e.
|
|
-- runner = "pytest",
|
|
-- python = ".venv/bin/python",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"mfussenegger/nvim-dap",
|
|
optional = true,
|
|
dependencies = {
|
|
"mfussenegger/nvim-dap-python",
|
|
-- stylua: ignore
|
|
keys = {
|
|
{ "<leader>dPt", function() require('dap-python').test_method() end, desc = "Debug Method", ft = "python" },
|
|
{ "<leader>dPc", function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" },
|
|
},
|
|
config = function()
|
|
require("dap-python").setup("debugpy-adapter")
|
|
end,
|
|
},
|
|
},
|
|
|
|
{
|
|
"linux-cultist/venv-selector.nvim",
|
|
cmd = "VenvSelect",
|
|
opts = {
|
|
options = {
|
|
notify_user_on_venv_activation = true,
|
|
},
|
|
},
|
|
-- Call config for Python files and load the cached venv automatically
|
|
ft = "python",
|
|
keys = { { "<leader>cv", "<cmd>:VenvSelect<cr>", desc = "Select VirtualEnv", ft = "python" } },
|
|
},
|
|
|
|
{
|
|
"hrsh7th/nvim-cmp",
|
|
optional = true,
|
|
opts = function(_, opts)
|
|
opts.auto_brackets = opts.auto_brackets or {}
|
|
table.insert(opts.auto_brackets, "python")
|
|
end,
|
|
},
|
|
|
|
-- Don't mess up DAP adapters provided by nvim-dap-python
|
|
{
|
|
"jay-babu/mason-nvim-dap.nvim",
|
|
optional = true,
|
|
opts = {
|
|
handlers = {
|
|
python = function() end,
|
|
},
|
|
},
|
|
},
|
|
}
|