diff options
| author | Fymyte <34305318+Fymyte@users.noreply.github.com> | 2021-12-08 00:48:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-08 00:48:06 +0100 |
| commit | fecd93079da2fa5c278d5f11e681872e0406b37e (patch) | |
| tree | 8c9ae6e2cc0f9c1f87e0bfeb80fa6cf9a645c503 /lua | |
| parent | initial healthcheck integration (#321) (diff) | |
| download | mason-fecd93079da2fa5c278d5f11e681872e0406b37e.tar mason-fecd93079da2fa5c278d5f11e681872e0406b37e.tar.gz mason-fecd93079da2fa5c278d5f11e681872e0406b37e.tar.bz2 mason-fecd93079da2fa5c278d5f11e681872e0406b37e.tar.lz mason-fecd93079da2fa5c278d5f11e681872e0406b37e.tar.xz mason-fecd93079da2fa5c278d5f11e681872e0406b37e.tar.zst mason-fecd93079da2fa5c278d5f11e681872e0406b37e.zip | |
add :PylspInstall command for managing 3rd party pylsp plugins (#318)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-lsp-installer/servers/pylsp/README.md | 9 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/servers/pylsp/init.lua | 28 |
2 files changed, 37 insertions, 0 deletions
diff --git a/lua/nvim-lsp-installer/servers/pylsp/README.md b/lua/nvim-lsp-installer/servers/pylsp/README.md new file mode 100644 index 00000000..ce756de3 --- /dev/null +++ b/lua/nvim-lsp-installer/servers/pylsp/README.md @@ -0,0 +1,9 @@ +# Pylsp + +## Installing pylsp plugins +Pylsp has [third party plugins](https://github.com/python-lsp/python-lsp-server#3rd-party-plugins) which are not installed by default. + +In order for these plugins to work with the `pylsp` server managed by this plugin, they need to be installed in the same [virtual environment](https://docs.python.org/3/library/venv.html) as `pylsp`. For these reasons, there's a convenient `:PylspInstall <packages>` command that does this for you, for example: +```vim +:PylspInstall pyls-flake8 pylsp-mypy pyls-isort +``` diff --git a/lua/nvim-lsp-installer/servers/pylsp/init.lua b/lua/nvim-lsp-installer/servers/pylsp/init.lua index e3da8e21..9905dd68 100644 --- a/lua/nvim-lsp-installer/servers/pylsp/init.lua +++ b/lua/nvim-lsp-installer/servers/pylsp/init.lua @@ -1,5 +1,7 @@ local server = require "nvim-lsp-installer.server" local pip3 = require "nvim-lsp-installer.installers.pip3" +local process = require "nvim-lsp-installer.process" +local notify = require "nvim-lsp-installer.notify" return function(name, root_dir) return server.Server:new { @@ -10,6 +12,32 @@ return function(name, root_dir) installer = pip3.packages { "python-lsp-server[all]" }, default_options = { cmd = { pip3.executable(root_dir, "pylsp") }, + commands = { + PylspInstall = { + function(...) + -- `nargs+` requires at least one argument -> no empty table + local plugins = { ... } + local plugins_str = table.concat(plugins, ", ") + notify(("Installing %q..."):format(plugins_str)) + process.spawn( + pip3.executable(root_dir, "pip"), + { + args = vim.list_extend({ "install", "-U", "--disable-pip-version-check" }, plugins), + stdio_sink = process.simple_sink(), + }, + vim.schedule_wrap(function(success) + if success then + notify(("Successfully installed %q"):format(plugins_str)) + else + notify("Failed to install requested plugins.", vim.log.levels.ERROR) + end + end) + ) + end, + description = "Installs the provided packages in the same venv as pylsp.", + ["nargs=+"] = true, + }, + }, }, } end |
