nixvim
nixvim copied to clipboard
[Feature Request] pylsp option to change python version
Currently there is no easy way to change the version python used to get pylsp. It seems to use pkgs.python3Packages by default, but changing the package from the default packages fails since there are a bunch of overrides done to the package by default in order to make the plugin work.
I'm hoping for something like this to work :
plugins.lsp.pylsp.package = pkgs.python312Packages.python-language-server;
At the moment, not being able to easily do this means that python 3.12 language features(like generic types in class and function definitions) won't be detected, regardless of whether you change the mypy python executable or not (at least I wasn't able to get it working).
Currently these are my settings for pylsp:
plugins.lsp.servers.pylsp = {
enable = true;
package = pkgs.python312Packages.python-lsp-server;
settings = {
plugins = {
#black.enabled=true;
#flake8.enabled=true;
isort.enabled=true;
jedi_completion.enabled=true;
jedi_hover.enabled=true;
jedi_references.enabled=true;
#jedi_signature_help=true;
#jedi_symbols=true;
pylsp_mypy = {
enabled=true;
report_progress=true;
overrides = ["--python-executable" (helpers.mkRaw "py_path") true] ;
};
rope.enabled=true;
rope_autoimport.enabled=true;
rope_completion.enabled=true;
ruff.enabled=true;
};
};
};
extraConfigLuaPre = ''
local venv_path = os.getenv('VIRTUAL_ENV') -- or vim.fn.exepath('python')
local path_python = vim.fn.exepath('python')
local py_path = nil
if venv_path ~= nil then
py_path = venv_path .. "/bin/python3"
elseif path_python ~=nil then
py_path = path_python
else
py_path = vim.g.python3_host_prog
end
print(py_path)
'';
The code in extraConfigLuaPre does correctly change the python executable for mypy(when the path changes in a dev shell), but despite this, it won't work for 3.12 features due to originating from the 3.11 package set(as far as I can tell).