aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/installers
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-09-01 10:29:23 +0200
committerGitHub <noreply@github.com>2021-09-01 10:29:23 +0200
commitbfbf5fbd39fa75847bf23da2c46d12fe2728fb78 (patch)
treef05d2f041f895ff639684c10f57d19f1d4a433e0 /lua/nvim-lsp-installer/installers
parentREADME: simplify example a bit, add clarifying comment (diff)
downloadmason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar
mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar.gz
mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar.bz2
mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar.lz
mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar.xz
mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar.zst
mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.zip
add Windows support (#70)
Diffstat (limited to 'lua/nvim-lsp-installer/installers')
-rw-r--r--lua/nvim-lsp-installer/installers/go.lua17
-rw-r--r--lua/nvim-lsp-installer/installers/init.lua22
-rw-r--r--lua/nvim-lsp-installer/installers/npm.lua10
-rw-r--r--lua/nvim-lsp-installer/installers/pip3.lua16
-rw-r--r--lua/nvim-lsp-installer/installers/shell.lua62
-rw-r--r--lua/nvim-lsp-installer/installers/zx.lua11
6 files changed, 109 insertions, 29 deletions
diff --git a/lua/nvim-lsp-installer/installers/go.lua b/lua/nvim-lsp-installer/installers/go.lua
index 1f1b730f..9c9a1ad5 100644
--- a/lua/nvim-lsp-installer/installers/go.lua
+++ b/lua/nvim-lsp-installer/installers/go.lua
@@ -5,13 +5,16 @@ local M = {}
function M.packages(packages)
return function(server, callback)
- local shell_installer = shell.raw(("go get -v %s; go clean -modcache;"):format(table.concat(packages, " ")), {
- env = {
- GO111MODULE = "on",
- GOBIN = server._root_dir,
- GOPATH = server._root_dir,
- },
- })
+ 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,
+ },
+ }
+ )
shell_installer(server, callback)
end
diff --git a/lua/nvim-lsp-installer/installers/init.lua b/lua/nvim-lsp-installer/installers/init.lua
index e9d99138..f394a33d 100644
--- a/lua/nvim-lsp-installer/installers/init.lua
+++ b/lua/nvim-lsp-installer/installers/init.lua
@@ -1,3 +1,5 @@
+local platform = require "nvim-lsp-installer.platform"
+
local M = {}
function M.compose(installers)
@@ -25,4 +27,24 @@ function M.compose(installers)
end
end
+function M.when(platform_table)
+ return function(server, callback)
+ if platform.is_unix() then
+ if platform_table.unix then
+ platform_table.unix(server, callback)
+ else
+ callback(false, ("Unix is not yet supported for server %q."):format(server.name))
+ end
+ elseif platform.is_win() then
+ if platform_table.win then
+ platform_table.win(server, callback)
+ else
+ callback(false, ("Windows is not yet supported for server %q."):format(server.name))
+ end
+ else
+ callback(false, "installers.when: Could not find installer for current platform.")
+ end
+ end
+end
+
return M
diff --git a/lua/nvim-lsp-installer/installers/npm.lua b/lua/nvim-lsp-installer/installers/npm.lua
index 02c2f533..6b6b820e 100644
--- a/lua/nvim-lsp-installer/installers/npm.lua
+++ b/lua/nvim-lsp-installer/installers/npm.lua
@@ -1,14 +1,20 @@
local path = require "nvim-lsp-installer.path"
+local platform = require "nvim-lsp-installer.platform"
local shell = require "nvim-lsp-installer.installers.shell"
local M = {}
function M.packages(packages)
- return shell.raw(("npm install %s"):format(table.concat(packages, " ")))
+ return shell.polyshell(("npm install %s"):format(table.concat(packages, " ")))
end
function M.executable(root_dir, executable)
- return path.concat { root_dir, "node_modules", ".bin", executable }
+ return path.concat {
+ root_dir,
+ "node_modules",
+ ".bin",
+ platform.is_win() and ("%s.cmd"):format(executable) or executable,
+ }
end
return M
diff --git a/lua/nvim-lsp-installer/installers/pip3.lua b/lua/nvim-lsp-installer/installers/pip3.lua
index 62996196..79fbb0f7 100644
--- a/lua/nvim-lsp-installer/installers/pip3.lua
+++ b/lua/nvim-lsp-installer/installers/pip3.lua
@@ -1,4 +1,5 @@
local path = require "nvim-lsp-installer.path"
+local platform = require "nvim-lsp-installer.platform"
local shell = require "nvim-lsp-installer.installers.shell"
local M = {}
@@ -6,13 +7,20 @@ local M = {}
local REL_INSTALL_DIR = "venv"
function M.packages(packages)
- return shell.raw(("./%s/bin/pip3 install -U %s"):format(REL_INSTALL_DIR, table.concat(packages, " ")), {
- prefix = ("set -euo pipefail; python3 -m venv %q;"):format(REL_INSTALL_DIR),
- })
+ 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 shell.polyshell(
+ ("python3 -m venv %q && %s && pip3 install -U %s"):format(
+ REL_INSTALL_DIR,
+ venv_activate_cmd,
+ table.concat(packages, " ")
+ )
+ )
end
function M.executable(root_dir, executable)
- return path.concat { root_dir, REL_INSTALL_DIR, "bin", executable }
+ return path.concat { root_dir, REL_INSTALL_DIR, platform.is_win() and "Scripts" or "bin", executable }
end
return M
diff --git a/lua/nvim-lsp-installer/installers/shell.lua b/lua/nvim-lsp-installer/installers/shell.lua
index bfdb5dea..98f12103 100644
--- a/lua/nvim-lsp-installer/installers/shell.lua
+++ b/lua/nvim-lsp-installer/installers/shell.lua
@@ -1,11 +1,8 @@
-local M = {}
+local installers = require "nvim-lsp-installer.installers"
-local default_opts = {
- prefix = "set -euo pipefail;",
-}
+local M = {}
-function M.raw(raw_script, opts)
- opts = opts or {}
+local function termopen(opts)
return function(server, callback)
local jobstart_opts = {
cwd = server._root_dir,
@@ -18,22 +15,61 @@ function M.raw(raw_script, opts)
end,
}
- if type(opts.env) == "table" and vim.tbl_count(opts.env) then
+ 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 shell = vim.o.shell
- vim.o.shell = "/bin/bash"
+ local orig_shell = vim.o.shell
+ vim.o.shell = opts.shell
vim.cmd [[new]]
- vim.fn.termopen((opts.prefix or default_opts.prefix) .. raw_script, jobstart_opts)
- vim.o.shell = shell
+ vim.fn.termopen(opts.cmd, jobstart_opts)
+ vim.o.shell = orig_shell
vim.cmd [[startinsert]] -- so that we tail the term log nicely ¯\_(ツ)_/¯
end
end
-function M.remote(url, opts)
- return M.raw(("wget -nv -O - %q | bash"):format(url), opts)
+function M.bash(raw_script, opts)
+ local default_opts = {
+ prefix = "set -euo pipefail;",
+ env = {},
+ }
+ opts = vim.tbl_deep_extend("force", default_opts, opts or {})
+
+ return termopen {
+ shell = "/bin/bash",
+ cmd = (opts.prefix or "") .. raw_script,
+ env = opts.env,
+ }
+end
+
+function M.remote_bash(url, opts)
+ return M.bash(("wget -nv -O - %q | bash"):format(url), opts)
+end
+
+function M.cmd(raw_script, opts)
+ local default_opts = {
+ env = {},
+ }
+ opts = vim.tbl_deep_extend("force", default_opts, opts or {})
+
+ return termopen {
+ shell = "cmd.exe",
+ cmd = raw_script,
+ env = opts.env,
+ }
+end
+
+function M.polyshell(raw_script, opts)
+ local default_opts = {
+ env = {},
+ }
+ opts = vim.tbl_deep_extend("force", default_opts, opts or {})
+
+ return installers.when {
+ unix = M.bash(raw_script, { env = opts.env }),
+ win = M.cmd(raw_script, { env = opts.env }),
+ }
end
return M
diff --git a/lua/nvim-lsp-installer/installers/zx.lua b/lua/nvim-lsp-installer/installers/zx.lua
index 5308ac66..b713b4ec 100644
--- a/lua/nvim-lsp-installer/installers/zx.lua
+++ b/lua/nvim-lsp-installer/installers/zx.lua
@@ -2,6 +2,7 @@ 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"
@@ -37,8 +38,8 @@ local function zx_installer(force)
fs.mkdirp(INSTALL_DIR)
- uv.spawn(
- "npm",
+ local handle, pid = uv.spawn(
+ platform.is_win() and "npm.cmd" or "npm",
{
args = { npm_command, "zx@1" },
cwd = INSTALL_DIR,
@@ -53,13 +54,17 @@ local function zx_installer(force)
callback(true, nil)
end)
)
+
+ if handle == nil then
+ callback(false, ("Failed to install/update zx. %s"):format(pid))
+ end
end
end
function M.file(relpath)
local script_path = path.realpath(relpath, 3)
return installers.compose {
- shell.raw(("%q %q"):format(ZX_EXECUTABLE, script_path)),
+ shell.polyshell(("%q %q"):format(ZX_EXECUTABLE, ("file:///%s"):format(script_path))),
zx_installer(false),
}
end