aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-lspconfig/server_configurations/pylsp/init.lua
blob: 9626fdca0460080a1a87f6cc2829ae54ff40f75f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local a = require "mason-core.async"
local _ = require "mason-core.functional"
local pip3 = require "mason-core.managers.pip3"
local process = require "mason-core.process"
local notify = require "mason-core.notify"
local spawn = require "mason-core.spawn"

---@param install_dir string
return function(install_dir)
    vim.api.nvim_create_user_command(
        "PylspInstall",
        a.scope(function(opts)
            local plugins = opts.fargs
            local plugins_str = table.concat(plugins, ", ")
            notify(("Installing %s..."):format(plugins_str))
            local result = spawn.pip {
                "install",
                "-U",
                "--disable-pip-version-check",
                plugins,
                stdio_sink = process.simple_sink(),
                with_paths = { pip3.venv_path(install_dir) },
            }
            if vim.in_fast_event() then
                a.scheduler()
            end
            result
                :on_success(function()
                    notify(("Successfully installed pylsp plugins %s"):format(plugins_str))
                end)
                :on_failure(function()
                    notify("Failed to install requested pylsp plugins.", vim.log.levels.ERROR)
                end)
        end),
        {
            desc = "[mason.nvim] Installs the provided packages in the same venv as pylsp.",
            nargs = "+",
            complete = _.always {
                "pyls-flake8",
                "pylsp-mypy",
                "pyls-spyder",
                "pyls-isort",
                "python-lsp-black",
                "pyls-memestra",
                "pylsp-rope",
            },
        }
    )

    return {}
end