diff options
| author | William Boman <william@redwill.se> | 2021-09-10 13:38:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-10 13:38:39 +0200 |
| commit | d2ec0c0070c01ba0e3e8926031cfe848a016df44 (patch) | |
| tree | bf57f20725e11125ed51caac547c483d4e642831 /lua/nvim-lsp-installer/installers/std.lua | |
| parent | CUSTOM_SERVERS.md: update docs (diff) | |
| download | mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar.gz mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar.bz2 mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar.lz mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar.xz mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar.zst mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.zip | |
rewrite some installers for broader cross-platform support (#85)
- Remove all usage of zx in favour of native Lua (via libuv)
- Introduce new set of `std` installers
The following servers will have to be reinstalled due to this change:
1. clangd
2. solargraph
3. sumneko_lua
4. tailwindcss
Diffstat (limited to 'lua/nvim-lsp-installer/installers/std.lua')
| -rw-r--r-- | lua/nvim-lsp-installer/installers/std.lua | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/lua/nvim-lsp-installer/installers/std.lua b/lua/nvim-lsp-installer/installers/std.lua new file mode 100644 index 00000000..0a4aa40a --- /dev/null +++ b/lua/nvim-lsp-installer/installers/std.lua @@ -0,0 +1,142 @@ +local path = require "nvim-lsp-installer.path" +local process = require "nvim-lsp-installer.process" +local installers = require "nvim-lsp-installer.installers" +local shell = require "nvim-lsp-installer.installers.shell" + +local M = {} + +function M.download_file(url, out_file) + return installers.when { + unix = function(server, callback, context) + process.spawn("wget", { + args = { "-nv", "-O", out_file, url }, + cwd = server.root_dir, + stdio_sink = context.stdio_sink, + }, callback) + end, + win = shell.powershell(("iwr -Uri %q -OutFile %q"):format(url, out_file)), + } +end + +function M.unzip(file, dest) + return installers.when { + unix = function(server, callback, context) + process.spawn("unzip", { + args = { "-d", dest, file }, + cwd = server.root_dir, + stdio_sink = context.stdio_sink, + }, callback) + end, + win = shell.powershell(("Expand-Archive -Path %q -DestinationPath %q"):format(file, dest)), + } +end + +function M.unzip_remote(url, dest) + return installers.pipe { + M.download_file(url, "archive.zip"), + M.unzip("archive.zip", dest or "."), + installers.always_succeed(M.delete_file "archive.zip"), + } +end + +function M.untar(file) + return installers.pipe { + function(server, callback, context) + process.spawn("tar", { + args = { "-xvf", file }, + cwd = server.root_dir, + stdio_sink = context.stdio_sink, + }, callback) + end, + installers.always_succeed(M.delete_file(file)), + } +end + +function M.untargz_remote(url) + return installers.pipe { + M.download_file(url, "archive.tar.gz"), + M.gunzip "archive.tar.gz", + M.untar "archive.tar", + installers.always_succeed(M.delete_file "archive.tar"), + } +end + +function M.gunzip(file) + return function(server, callback, context) + process.spawn("gzip", { + args = { "-d", file }, + cwd = server.root_dir, + stdio_sink = context.stdio_sink, + }, callback) + end +end + +function M.gunzip_remote(url, out_file) + local archive = ("%s.gz"):format(out_file or "archive") + return installers.pipe { + M.download_file(url, archive), + M.gunzip(archive), + installers.always_succeed(M.delete_file(archive)), + } +end + +function M.delete_file(file) + return installers.when { + unix = function(server, callback, context) + process.spawn("rm", { + args = { "-f", file }, + cwd = server.root_dir, + stdio_sink = context.stdio_sink, + }, callback) + end, + win = shell.powershell(("rm %q"):format(file)), + } +end + +function M.git_clone(repo_url) + return function(server, callback, context) + process.spawn("git", { + args = { "clone", "--depth", "1", repo_url, "." }, + cwd = server.root_dir, + stdio_sink = context.stdio_sink, + }, callback) + end +end + +function M.gradlew(opts) + return function(server, callback, context) + process.spawn(path.concat { server.root_dir, "gradlew" }, { + args = opts.args, + cwd = server.root_dir, + stdio_sink = context.stdio_sink, + }, callback) + end +end + +function M.ensure_executables(executables) + return vim.schedule_wrap(function(_, callback, context) + for i = 1, #executables do + local executable = executables[i] + if vim.fn.executable(executable) ~= 1 then + context.stdio_sink.stderr(("Missing required %q executable."):format(executable)) + callback(false) + return + end + end + callback(true) + end) +end + +function M.chmod(flags, files) + return installers.on { + unix = function(server, callback, context) + process.spawn("chmod", { + args = vim.list_extend({ flags }, files), + cwd = server.root_dir, + stdio_sink = context.stdio_sink, + }, callback) + end, + } +end + +return M |
