aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/servers/pylsp/init.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-05-30 01:57:00 +0200
committerGitHub <noreply@github.com>2022-05-30 01:57:00 +0200
commit9cc15aa044e26e4947a46b691a74664621331228 (patch)
treea8a93742a15e4825b6957b05dfa940d2a6d1da4e /lua/nvim-lsp-installer/servers/pylsp/init.lua
parentrefactor(pip3): use with_paths to set venv path (#736) (diff)
downloadmason-9cc15aa044e26e4947a46b691a74664621331228.tar
mason-9cc15aa044e26e4947a46b691a74664621331228.tar.gz
mason-9cc15aa044e26e4947a46b691a74664621331228.tar.bz2
mason-9cc15aa044e26e4947a46b691a74664621331228.tar.lz
mason-9cc15aa044e26e4947a46b691a74664621331228.tar.xz
mason-9cc15aa044e26e4947a46b691a74664621331228.tar.zst
mason-9cc15aa044e26e4947a46b691a74664621331228.zip
refactor: specify commands independently, not via lspconfig (#737)
This is not a desirable solution, but it's better than as-is. There's a couple of reasons for this: 1) lspconfig only enables these commands upon successful attachment of servers, which doesn't really fit their use case. 2) We gain direct access to new Lua APIs for defining user commands, allowing us to leverage Lua callbacks and functions instead of intermediary global variables.
Diffstat (limited to 'lua/nvim-lsp-installer/servers/pylsp/init.lua')
-rw-r--r--lua/nvim-lsp-installer/servers/pylsp/init.lua86
1 files changed, 46 insertions, 40 deletions
diff --git a/lua/nvim-lsp-installer/servers/pylsp/init.lua b/lua/nvim-lsp-installer/servers/pylsp/init.lua
index 54e6861d..4f0a01d1 100644
--- a/lua/nvim-lsp-installer/servers/pylsp/init.lua
+++ b/lua/nvim-lsp-installer/servers/pylsp/init.lua
@@ -1,21 +1,55 @@
+local a = require "nvim-lsp-installer.core.async"
+local _ = require "nvim-lsp-installer.core.functional"
local server = require "nvim-lsp-installer.server"
local pip3 = require "nvim-lsp-installer.core.managers.pip3"
local process = require "nvim-lsp-installer.core.process"
local notify = require "nvim-lsp-installer.notify"
-
-function _G.lsp_installer_pylsp_install_completion()
- return table.concat({
- "pyls-flake8",
- "pylsp-mypy",
- "pyls-spyder",
- "pyls-isort",
- "python-lsp-black",
- "pyls-memestra",
- "pylsp-rope",
- }, "\n")
-end
+local middleware = require "nvim-lsp-installer.middleware"
+local spawn = require "nvim-lsp-installer.core.spawn"
return function(name, root_dir)
+ middleware.register_server_hook(name, function()
+ 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(root_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 = "[nvim-lsp-installer] 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",
+ },
+ }
+ )
+ end)
+
return server.Server:new {
name = name,
root_dir = root_dir,
@@ -24,34 +58,6 @@ return function(name, root_dir)
installer = pip3.packages { "python-lsp-server[all]" },
default_options = {
cmd_env = pip3.env(root_dir),
- 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(
- "pip",
- {
- args = vim.list_extend({ "install", "-U", "--disable-pip-version-check" }, plugins),
- stdio_sink = process.simple_sink(),
- env = process.graft_env(pip3.env(root_dir)),
- },
- 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,
- ["complete=custom,v:lua.lsp_installer_pylsp_install_completion"] = true,
- },
- },
},
}
end