Open baco opened 1 year ago
Hello! Ah hm I wasn't aware the [all]
specifier would install all plugins, I assumed it was for something else. Am I correct in assuming that the :PylspInstall
command is pretty redundant then, as most of those sub-packages are already installed?
This relates to https://github.com/williamboman/mason.nvim/issues/392 which I'm working on atm
I don't think :PylspInstall
is redundant, because without it, at the moment, python-lsp-server[all]
won't install, for instance, pylsp-mypy
as it is a third-party plugin.
python-lsp-server[all]
(or a sub-set [pylint,flake8]
) installs all official plugins, but not the third-party ones.
The behavior I want is to, even for third-party plugins, have a setting in mason-lspconfig
that gets them installed automatically as it is with most servers.
I suggested copying the same syntax pip
uses to install sub-packages, but the detection of which are official plugins and which not, in that case, remains to the core of mason
to be able to form the line for the installer
A work around for not having this functionality:
{
"williamboman/mason.nvim",
cmd = { "Mason", "MasonInstall", "MasonUninstall" },
config = function()
require("mason").setup()
require("mason-registry"):on("package:install:success", require("...").mason_post_install)
end
}
M.mason_post_install = function(pkg)
if pkg.name ~= "python-lsp-server" then
return
end
local venv = vim.fn.stdpath("data") .. "/mason/packages/python-lsp-server/venv"
local job = require("plenary.job")
job:new({
command = venv .. "/bin/pip",
args = {
"install",
"-U",
"--disable-pip-version-check",
"pylsp-mypy",
"python-lsp-ruff",
},
cwd = venv,
env = { VIRTUAL_ENV = venv },
on_exit = function()
vim.notify("Finished installing pylsp modules.")
end,
on_start = function()
vim.notify("Installing pylsp modules...")
end,
}):start()
end
In case someone has a hard time making @dsully's solution work. I had two issues with it:
plenary.nvim
not being loaded at the callback moment: In my case it was lazy loaded so adding it to dependencies here solves it:
return {
"williamboman/mason.nvim",
cmd = { "Mason", "MasonInstall", "MasonUninstall" },
dependencies = { "nvim-lua/plenary.nvim" }, -- needed for mason_post_install
config = function()
...
nvim-notify
installed: I don't have this plugin and the default vim.notify
call would throw and error during execution. You can comment those out, or change to print
.Thank you, @dsully and @octvs - exactly what I needed! Due to some issues with my machine, the PylspInstall
command wasn't working. This solved the problem altogether and automates the installation for future use. Brilliant!
Is your feature request related to a problem? Please describe.
I'd like to be able to parametrize (it could be via
ensure_installed
orautomatic_installation
, or something) the installation of the server.Describe the solution you'd like
to be able to achieve 2 behaviors:
python-lsp-server[pylint,flake8]
instead of the defaultpython-lsp-server[all]
, to avoid installing plugins I don't use, or that could clash with others in system.init.lua
file, as well as I have theautomatic_installation
setting for the automatic installation of the server, a way to automatically install certain third-party plugins. For example I want to be able to saypython-lsp-server[pylsp-mypy]
in such setting, without having to manually run:PylspInstall pylsp-mypy
once the server was installed.Describe potential alternatives you've considered
I can achieve installation like this myself if I control the virtualenvironments in which I install the server.
Additional context
No response