diff options
| author | jdhao <jdhao@hotmail.com> | 2023-07-25 22:57:50 +0200 |
|---|---|---|
| committer | jdhao <jdhao@hotmail.com> | 2023-07-25 22:59:06 +0200 |
| commit | 450f058da5eb9e5f41825c6ddafaee90de44a1ea (patch) | |
| tree | 6d98178aa2f40dc1f466690eca4673a67a612070 /lua/config/lsp.lua | |
| parent | e2f348cb371e53d2d45bc2cd8f9a23d63db2d539 (diff) | |
feat: support venv in Mypy
Specify the correct python executable path for mypy to work well.
Diffstat (limited to 'lua/config/lsp.lua')
| -rw-r--r-- | lua/config/lsp.lua | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 765a2ef..a3c5595 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -114,6 +114,15 @@ local capabilities = require('cmp_nvim_lsp').default_capabilities() local lspconfig = require("lspconfig") 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 { on_attach = custom_attach, settings = { @@ -129,7 +138,12 @@ if utils.executable("pylsp") then pyflakes = { enabled = false }, pycodestyle = { enabled = false }, -- 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 jedi_completion = { fuzzy = true }, -- import sorting |
