williamboman / mason-lspconfig.nvim

Extension to mason.nvim that makes it easier to use lspconfig with mason.nvim.
Apache License 2.0
2.55k stars 154 forks source link

Add some python-lsp-server configuration customization #58

Open baco opened 1 year ago

baco commented 1 year ago

Is your feature request related to a problem? Please describe.

I'd like to be able to parametrize (it could be via ensure_installed or automatic_installation, or something) the installation of the server.

Describe the solution you'd like

to be able to achieve 2 behaviors:

  1. Being able to install some (not all) of the plugins the server has. Say I want to be able to specify python-lsp-server[pylint,flake8] instead of the default python-lsp-server[all], to avoid installing plugins I don't use, or that could clash with others in system.
  2. Being able to specify a way to install automatically, alongside the server, some third-party plugins. For instance, I would like to be able to set on my Neovim init.lua file, as well as I have the automatic_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 say python-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

williamboman commented 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

baco commented 1 year ago

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

dsully commented 1 year ago

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
octvs commented 11 months ago

In case someone has a hard time making @dsully's solution work. I had two issues with it:

PBHDK commented 10 months ago

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!