1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

feat: support venv in Mypy

Specify the correct python executable path for mypy to work well.
This commit is contained in:
jdhao 2023-07-25 22:57:50 +02:00
parent e2f348cb37
commit 450f058da5

View File

@ -114,6 +114,15 @@ local capabilities = require('cmp_nvim_lsp').default_capabilities()
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
if utils.executable("pylsp") then if utils.executable("pylsp") then
local venv_path = os.getenv('VIRTUAL_ENV')
local py_path = nil
-- decide which python executable to use for mypy
if venv_path ~= nil then
py_path = venv_path .. "/bin/python3"
else
py_path = vim.g.python3_host_prog
end
lspconfig.pylsp.setup { lspconfig.pylsp.setup {
on_attach = custom_attach, on_attach = custom_attach,
settings = { settings = {
@ -129,7 +138,12 @@ if utils.executable("pylsp") then
pyflakes = { enabled = false }, pyflakes = { enabled = false },
pycodestyle = { enabled = false }, pycodestyle = { enabled = false },
-- type checker -- type checker
pylsp_mypy = { enabled = true, report_progress = true, live_mode = false }, pylsp_mypy = {
enabled = true,
overrides = { "--python-executable", py_path, true },
report_progress = true,
live_mode = false
},
-- auto-completion options -- auto-completion options
jedi_completion = { fuzzy = true }, jedi_completion = { fuzzy = true },
-- import sorting -- import sorting