From fecd93079da2fa5c278d5f11e681872e0406b37e Mon Sep 17 00:00:00 2001 From: Fymyte <34305318+Fymyte@users.noreply.github.com> Date: Wed, 8 Dec 2021 00:48:06 +0100 Subject: add :PylspInstall command for managing 3rd party pylsp plugins (#318) --- lua/nvim-lsp-installer/servers/pylsp/init.lua | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lua/nvim-lsp-installer/servers/pylsp/init.lua') 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 -- cgit v1.2.3-70-g09d2