Skip to content

Instantly share code, notes, and snippets.

@githubmo
Created January 5, 2024 12:29
Show Gist options
  • Save githubmo/56f0f28bc32130851cfb038a90ed56ac to your computer and use it in GitHub Desktop.
Save githubmo/56f0f28bc32130851cfb038a90ed56ac to your computer and use it in GitHub Desktop.
return {
-- Add `pyright` to mason
-- TODO: check following tools -> mypy types-requests types-docutils
{
"williamboman/mason.nvim",
opts = function(_, opts)
-- vim.list_extend(opts.ensure_installed, { "pyright", "black", "ruff-lsp", "ruff" })
vim.list_extend(opts.ensure_installed, {
"pyright",
"black",
"isort",
})
end,
},
-- Setup adapters as nvim-dap dependencies
{
"mfussenegger/nvim-dap",
dependencies = {
"mfussenegger/nvim-dap-python",
-- stylua: ignore
keys = {
{ "<leader>dPt", function() require('dap-python').test_method() end, desc = "Debug Method" },
{ "<leader>dPc", function() require('dap-python').test_class() end, desc = "Debug Class" },
},
config = function()
local path = require("mason-registry").get_package("debugpy"):get_install_path()
require("dap-python").setup(path .. "/venv/bin/python")
end,
},
},
-- Add `python` debugger to mason DAP to auto-install
-- Not absolutely necessary to declare adapter in `ensure_installed`, since `mason-nvim-dap`
-- has `automatic-install = true` in LazyVim by default and it automatically installs adapters
-- that are are set up (via dap) but not yet installed. Might as well skip the lines below as
-- a whole.
-- Add which-key namespace for Python debugging
{
"folke/which-key.nvim",
optional = true,
opts = {
defaults = {
["<leader>dP"] = { name = "+Python" },
},
},
},
-- Setup `neotest`
{
"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",
},
},
},
},
-- Add `server` and setup lspconfig
{
"neovim/nvim-lspconfig",
dependencies = {},
opts = {
servers = {
pyright = {},
-- ruff_lsp = {
-- -- handlers = {
-- -- ["textDocument/publishDiagnostics"] = function() end,
-- -- },
-- },
-- jedi_language_server = {},
},
setup = {
pyright = function()
require("lazyvim.util").lsp.on_attach(function(client, _)
if client.name == "pyright" then
-- disable hover in favor of jedi-language-server
client.server_capabilities.hoverProvider = false
end
end)
end,
},
},
},
-- Setup up format with new `conform.nvim`
{
"stevearc/conform.nvim",
optional = true,
opts = {
formatters_by_ft = {
["python"] = { { "black", "isort" } },
},
},
},
-- For selecting virtual envs
{
"linux-cultist/venv-selector.nvim",
dependencies = {
"mfussenegger/nvim-dap-python",
},
cmd = "VenvSelect",
opts = {
dap_enabled = true,
},
keys = { { "<leader>cv", "<cmd>:VenvSelect<cr>", desc = "Select VirtualEnv" } },
},
}
@githubmo
Copy link
Author

githubmo commented Jan 5, 2024

A python configuration for Astronvim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment