aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/installers
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-09-07 02:44:09 +0200
committerGitHub <noreply@github.com>2021-09-07 02:44:09 +0200
commit00294b84031711013a385f18c0fb0e8db84ebaf9 (patch)
treee45de668229c6b41643c5d1fa0fdb5beb0ff60fa /lua/nvim-lsp-installer/installers
parentlazily require servers for faster startup times (#77) (diff)
downloadmason-00294b84031711013a385f18c0fb0e8db84ebaf9.tar
mason-00294b84031711013a385f18c0fb0e8db84ebaf9.tar.gz
mason-00294b84031711013a385f18c0fb0e8db84ebaf9.tar.bz2
mason-00294b84031711013a385f18c0fb0e8db84ebaf9.tar.lz
mason-00294b84031711013a385f18c0fb0e8db84ebaf9.tar.xz
mason-00294b84031711013a385f18c0fb0e8db84ebaf9.tar.zst
mason-00294b84031711013a385f18c0fb0e8db84ebaf9.zip
add direct integration with libuv instead of going through termopen, also implement a UI (#79)
* add direct integration with libuv instead of going through termopen, also implement a UI * alleged free perf boosts yo that's free cycles
Diffstat (limited to 'lua/nvim-lsp-installer/installers')
-rw-r--r--lua/nvim-lsp-installer/installers/go.lua28
-rw-r--r--lua/nvim-lsp-installer/installers/init.lua41
-rw-r--r--lua/nvim-lsp-installer/installers/npm.lua10
-rw-r--r--lua/nvim-lsp-installer/installers/pip3.lua21
-rw-r--r--lua/nvim-lsp-installer/installers/shell.lua38
-rw-r--r--lua/nvim-lsp-installer/installers/zx.lua52
6 files changed, 102 insertions, 88 deletions
diff --git a/lua/nvim-lsp-installer/installers/go.lua b/lua/nvim-lsp-installer/installers/go.lua
index 9c9a1ad5..61e29383 100644
--- a/lua/nvim-lsp-installer/installers/go.lua
+++ b/lua/nvim-lsp-installer/installers/go.lua
@@ -1,22 +1,24 @@
local path = require "nvim-lsp-installer.path"
-local shell = require "nvim-lsp-installer.installers.shell"
+local process = require "nvim-lsp-installer.process"
local M = {}
function M.packages(packages)
- return function(server, callback)
- local shell_installer = shell.polyshell(
- ("go get -v %s && go clean -modcache"):format(table.concat(packages, " ")),
- {
- env = {
- GO111MODULE = "on",
- GOBIN = server._root_dir,
- GOPATH = server._root_dir,
- },
- }
- )
+ return function(server, callback, context)
+ local c = process.chain {
+ env = process.graft_env {
+ GO111MODULE = "on",
+ GOBIN = server.root_dir,
+ GOPATH = server.root_dir,
+ },
+ cwd = server.root_dir,
+ stdio_sink = context.stdio_sink,
+ }
- shell_installer(server, callback)
+ c.run("go", vim.list_extend({ "get", "-v" }, packages))
+ c.run("go", { "clean", "-modcache" })
+
+ c.spawn(callback)
end
end
diff --git a/lua/nvim-lsp-installer/installers/init.lua b/lua/nvim-lsp-installer/installers/init.lua
index f394a33d..991c773e 100644
--- a/lua/nvim-lsp-installer/installers/init.lua
+++ b/lua/nvim-lsp-installer/installers/init.lua
@@ -1,48 +1,57 @@
local platform = require "nvim-lsp-installer.platform"
+local Data = require "nvim-lsp-installer.data"
local M = {}
-function M.compose(installers)
+function M.join(installers)
if #installers == 0 then
- error "No installers to compose."
+ error "No installers to join."
end
- return function(server, callback)
+ return function(server, callback, context)
local function execute(idx)
- installers[idx](server, function(success, result)
+ installers[idx](server, function(success)
if not success then
-- oh no, error. exit early
- callback(success, result)
- elseif installers[idx - 1] then
+ callback(success)
+ elseif installers[idx + 1] then
-- iterate
- execute(idx - 1)
+ execute(idx + 1)
else
-- we done
- callback(success, result)
+ callback(success)
end
- end)
+ end, context)
end
- execute(#installers)
+ execute(1)
end
end
+-- much fp, very wow
+function M.compose(installers)
+ return M.join(Data.list_reverse(installers))
+end
+
function M.when(platform_table)
- return function(server, callback)
+ return function(server, callback, context)
if platform.is_unix() then
if platform_table.unix then
- platform_table.unix(server, callback)
+ platform_table.unix(server, callback, context)
else
- callback(false, ("Unix is not yet supported for server %q."):format(server.name))
+ context.stdio_sink.stderr(("Unix is not yet supported for server %q."):format(server.name))
+ callback(false)
end
elseif platform.is_win() then
if platform_table.win then
- platform_table.win(server, callback)
+ platform_table.win(server, callback, context)
else
- callback(false, ("Windows is not yet supported for server %q."):format(server.name))
+ context.stdio_sink.stderr(("Windows is not yet supported for server %q."):format(server.name))
+ callback(false)
end
else
- callback(false, "installers.when: Could not find installer for current platform.")
+ context.sdtio_sink.stderr "installers.when: Could not find installer for current platform."
+ callback(false)
end
end
end
diff --git a/lua/nvim-lsp-installer/installers/npm.lua b/lua/nvim-lsp-installer/installers/npm.lua
index 6b6b820e..d3c8167f 100644
--- a/lua/nvim-lsp-installer/installers/npm.lua
+++ b/lua/nvim-lsp-installer/installers/npm.lua
@@ -1,11 +1,17 @@
local path = require "nvim-lsp-installer.path"
local platform = require "nvim-lsp-installer.platform"
-local shell = require "nvim-lsp-installer.installers.shell"
+local process = require "nvim-lsp-installer.process"
local M = {}
function M.packages(packages)
- return shell.polyshell(("npm install %s"):format(table.concat(packages, " ")))
+ return function(server, callback, context)
+ process.spawn(platform.is_win() and "npm.cmd" or "npm", {
+ args = vim.list_extend({ "install" }, packages),
+ cwd = server.root_dir,
+ stdio_sink = context.stdio_sink,
+ }, callback)
+ end
end
function M.executable(root_dir, executable)
diff --git a/lua/nvim-lsp-installer/installers/pip3.lua b/lua/nvim-lsp-installer/installers/pip3.lua
index 79fbb0f7..5aefe372 100644
--- a/lua/nvim-lsp-installer/installers/pip3.lua
+++ b/lua/nvim-lsp-installer/installers/pip3.lua
@@ -1,22 +1,23 @@
local path = require "nvim-lsp-installer.path"
local platform = require "nvim-lsp-installer.platform"
-local shell = require "nvim-lsp-installer.installers.shell"
+local process = require "nvim-lsp-installer.process"
local M = {}
local REL_INSTALL_DIR = "venv"
function M.packages(packages)
- local venv_activate_cmd = platform.is_win() and (".\\%s\\Scripts\\activate"):format(REL_INSTALL_DIR)
- or ("source ./%s/bin/activate"):format(REL_INSTALL_DIR)
+ return function(server, callback, context)
+ local c = process.chain {
+ cwd = server.root_dir,
+ stdio_sink = context.stdio_sink,
+ }
- return shell.polyshell(
- ("python3 -m venv %q && %s && pip3 install -U %s"):format(
- REL_INSTALL_DIR,
- venv_activate_cmd,
- table.concat(packages, " ")
- )
- )
+ c.run("python3", { "-m", "venv", REL_INSTALL_DIR })
+ c.run(M.executable(server.root_dir, "pip3"), vim.list_extend({ "install", "-U" }, packages))
+
+ c.spawn(callback)
+ end
end
function M.executable(root_dir, executable)
diff --git a/lua/nvim-lsp-installer/installers/shell.lua b/lua/nvim-lsp-installer/installers/shell.lua
index 98f12103..37b5e03f 100644
--- a/lua/nvim-lsp-installer/installers/shell.lua
+++ b/lua/nvim-lsp-installer/installers/shell.lua
@@ -1,31 +1,21 @@
local installers = require "nvim-lsp-installer.installers"
+local process = require "nvim-lsp-installer.process"
local M = {}
-local function termopen(opts)
- return function(server, callback)
- local jobstart_opts = {
- cwd = server._root_dir,
- on_exit = function(_, exit_code)
- if exit_code ~= 0 then
- callback(false, ("Exit code %d"):format(exit_code))
- else
- callback(true, nil)
- end
- end,
- }
+local function shell(opts)
+ return function(server, callback, installer_opts)
+ local _, stdio = process.spawn(opts.shell, {
+ cwd = server.root_dir,
+ stdio_sink = installer_opts.stdio_sink,
+ env = process.graft_env(opts.env or {}),
+ }, callback)
- if type(opts.env) == "table" and vim.tbl_count(opts.env) > 0 then
- -- passing an empty Lua table causes E475, for whatever reason
- jobstart_opts.env = opts.env
- end
+ local stdin = stdio[1]
- local orig_shell = vim.o.shell
- vim.o.shell = opts.shell
- vim.cmd [[new]]
- vim.fn.termopen(opts.cmd, jobstart_opts)
- vim.o.shell = orig_shell
- vim.cmd [[startinsert]] -- so that we tail the term log nicely ¯\_(ツ)_/¯
+ stdin:write(opts.cmd)
+ stdin:write "\n"
+ stdin:close()
end
end
@@ -36,7 +26,7 @@ function M.bash(raw_script, opts)
}
opts = vim.tbl_deep_extend("force", default_opts, opts or {})
- return termopen {
+ return shell {
shell = "/bin/bash",
cmd = (opts.prefix or "") .. raw_script,
env = opts.env,
@@ -53,7 +43,7 @@ function M.cmd(raw_script, opts)
}
opts = vim.tbl_deep_extend("force", default_opts, opts or {})
- return termopen {
+ return shell {
shell = "cmd.exe",
cmd = raw_script,
env = opts.env,
diff --git a/lua/nvim-lsp-installer/installers/zx.lua b/lua/nvim-lsp-installer/installers/zx.lua
index b713b4ec..9b24e1af 100644
--- a/lua/nvim-lsp-installer/installers/zx.lua
+++ b/lua/nvim-lsp-installer/installers/zx.lua
@@ -1,12 +1,9 @@
local fs = require "nvim-lsp-installer.fs"
local path = require "nvim-lsp-installer.path"
-local notify = require "nvim-lsp-installer.notify"
local installers = require "nvim-lsp-installer.installers"
local platform = require "nvim-lsp-installer.platform"
-local shell = require "nvim-lsp-installer.installers.shell"
local npm = require "nvim-lsp-installer.installers.npm"
-
-local uv = vim.loop
+local process = require "nvim-lsp-installer.process"
local M = {}
@@ -18,7 +15,7 @@ local has_installed_zx = false
local function zx_installer(force)
force = force or false -- be careful with boolean logic if flipping this
- return function(_, callback)
+ return function(_, callback, opts)
if has_installed_zx and not force then
callback(true, "zx already installed")
return
@@ -33,38 +30,47 @@ local function zx_installer(force)
local npm_command = is_zx_already_installed and "update" or "install"
if not is_zx_already_installed then
- notify(("Preparing for :LspInstall… ($ npm %s zx)"):format(npm_command))
+ opts.stdio_sink.stdout(("Preparing for installation… (npm %s zx)"):format(npm_command))
end
fs.mkdirp(INSTALL_DIR)
- local handle, pid = uv.spawn(
- platform.is_win() and "npm.cmd" or "npm",
- {
- args = { npm_command, "zx@1" },
- cwd = INSTALL_DIR,
- },
- vim.schedule_wrap(function(code)
- if code ~= 0 then
- callback(false, "Failed to install zx.")
- return
- end
+ -- todo use process installer
+ local handle, pid = process.spawn(platform.is_win() and "npm.cmd" or "npm", {
+ args = { npm_command, "zx@1" },
+ cwd = INSTALL_DIR,
+ stdio_sink = opts.stdio_sink,
+ }, function(success)
+ if success then
has_installed_zx = true
- vim.cmd [[ echon "" ]] -- clear the previously printed feedback message… ¯\_(ツ)_/¯
- callback(true, nil)
- end)
- )
+ callback(true)
+ else
+ opts.stdio_sink.stderr "Failed to install zx."
+ callback(false)
+ end
+ end)
if handle == nil then
- callback(false, ("Failed to install/update zx. %s"):format(pid))
+ opts.stdio_sink.stderr(("Failed to install/update zx. %s"):format(pid))
+ callback(false)
end
end
end
+local function exec(file)
+ return function(server, callback, context)
+ process.spawn(ZX_EXECUTABLE, {
+ args = { file },
+ cwd = server.root_dir,
+ stdio_sink = context.stdio_sink,
+ }, callback)
+ end
+end
+
function M.file(relpath)
local script_path = path.realpath(relpath, 3)
return installers.compose {
- shell.polyshell(("%q %q"):format(ZX_EXECUTABLE, ("file:///%s"):format(script_path))),
+ exec(("file:///%s"):format(script_path)),
zx_installer(false),
}
end