diff options
| author | William Boman <william@redwill.se> | 2021-10-30 11:05:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-30 11:05:50 +0200 |
| commit | 8e6615916de6f7d2491e47f8a97870eef0ad36d3 (patch) | |
| tree | 762def1fb61a0fc8a3aaaaa072da3e2c1c535817 /lua/nvim-lsp-installer/installers | |
| parent | doc: add some docs (diff) | |
| download | mason-8e6615916de6f7d2491e47f8a97870eef0ad36d3.tar mason-8e6615916de6f7d2491e47f8a97870eef0ad36d3.tar.gz mason-8e6615916de6f7d2491e47f8a97870eef0ad36d3.tar.bz2 mason-8e6615916de6f7d2491e47f8a97870eef0ad36d3.tar.lz mason-8e6615916de6f7d2491e47f8a97870eef0ad36d3.tar.xz mason-8e6615916de6f7d2491e47f8a97870eef0ad36d3.tar.zst mason-8e6615916de6f7d2491e47f8a97870eef0ad36d3.zip | |
run installations in tmpdir (#199)
Resolves #154.
Diffstat (limited to 'lua/nvim-lsp-installer/installers')
| -rw-r--r-- | lua/nvim-lsp-installer/installers/composer.lua | 10 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/gem.lua | 4 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/go.lua | 8 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/init.lua | 1 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/npm.lua | 18 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/pip3.lua | 6 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/shell.lua | 4 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/std.lua | 81 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/zx.lua | 5 |
9 files changed, 82 insertions, 55 deletions
diff --git a/lua/nvim-lsp-installer/installers/composer.lua b/lua/nvim-lsp-installer/installers/composer.lua index ebe591d4..a046575b 100644 --- a/lua/nvim-lsp-installer/installers/composer.lua +++ b/lua/nvim-lsp-installer/installers/composer.lua @@ -25,13 +25,13 @@ local M = {} function M.packages(packages) return ensure_composer( ---@type ServerInstallerFunction - function(server, callback, context) + function(_, callback, context) local c = process.chain { - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, } - if not (fs.file_exists(path.concat { server.root_dir, "composer.json" })) then + if not (fs.file_exists(path.concat { context.install_dir, "composer.json" })) then c.run(composer, { "init", "--no-interaction", "--stability=dev" }) c.run(composer, { "config", "prefer-stable", "true" }) end @@ -51,7 +51,7 @@ end function M.install() return ensure_composer( ---@type ServerInstallerFunction - function(server, callback, context) + function(_, callback, context) process.spawn(composer, { args = { "install", @@ -60,7 +60,7 @@ function M.install() "--optimize-autoloader", "--classmap-authoritative", }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }, callback) end diff --git a/lua/nvim-lsp-installer/installers/gem.lua b/lua/nvim-lsp-installer/installers/gem.lua index 331be055..727af496 100644 --- a/lua/nvim-lsp-installer/installers/gem.lua +++ b/lua/nvim-lsp-installer/installers/gem.lua @@ -17,7 +17,7 @@ function M.packages(packages) { "gem", "gem was not found in path, refer to https://wiki.openstack.org/wiki/RubyGems." }, }, ---@type ServerInstallerFunction - function(server, callback, context) + function(_, callback, context) local pkgs = Data.list_copy(packages or {}) if context.requested_server_version then -- The "head" package is the recipient for the requested version. It's.. by design... don't ask. @@ -33,7 +33,7 @@ function M.packages(packages) "--no-document", table.concat(pkgs, " "), }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }, callback) end, diff --git a/lua/nvim-lsp-installer/installers/go.lua b/lua/nvim-lsp-installer/installers/go.lua index c2dbcb37..7fbc1ddc 100644 --- a/lua/nvim-lsp-installer/installers/go.lua +++ b/lua/nvim-lsp-installer/installers/go.lua @@ -11,15 +11,15 @@ function M.packages(packages) return installers.pipe { std.ensure_executables { { "go", "go was not found in path, refer to https://golang.org/doc/install." } }, ---@type ServerInstallerFunction - function(server, callback, context) + function(_, callback, context) local pkgs = Data.list_copy(packages or {}) local c = process.chain { env = process.graft_env { GO111MODULE = "on", - GOBIN = server.root_dir, - GOPATH = server.root_dir, + GOBIN = context.install_dir, + GOPATH = context.install_dir, }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, } diff --git a/lua/nvim-lsp-installer/installers/init.lua b/lua/nvim-lsp-installer/installers/init.lua index a9adb74d..08218945 100644 --- a/lua/nvim-lsp-installer/installers/init.lua +++ b/lua/nvim-lsp-installer/installers/init.lua @@ -10,6 +10,7 @@ local M = {} ---@field requested_server_version string|nil @The version requested by the user. ---@field stdio_sink StdioSink ---@field github_release_file string|nil @Only available if context.use_github_release_file has been called. +---@field install_dir string ---@alias ServerInstallerFunction fun(server: Server, callback: ServerInstallCallback, context: ServerInstallContext) diff --git a/lua/nvim-lsp-installer/installers/npm.lua b/lua/nvim-lsp-installer/installers/npm.lua index d6805b0e..93c33532 100644 --- a/lua/nvim-lsp-installer/installers/npm.lua +++ b/lua/nvim-lsp-installer/installers/npm.lua @@ -29,15 +29,15 @@ local function create_installer(read_version_from_context) return function(packages) return ensure_npm( ---@type ServerInstallerFunction - function(server, callback, context) + function(_, callback, context) local pkgs = Data.list_copy(packages or {}) local c = process.chain { - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, } -- stylua: ignore start - if not (fs.dir_exists(path.concat { server.root_dir, "node_modules" }) or - fs.file_exists(path.concat { server.root_dir, "package.json" })) + if not (fs.dir_exists(path.concat { context.install_dir, "node_modules" }) or + fs.file_exists(path.concat { context.install_dir, "package.json" })) then c.run(npm, { "init", "--yes", "--scope=lsp-installer" }) end @@ -66,10 +66,10 @@ M.install = create_installer(false) ---@param args string[] function M.exec(executable, args) ---@type ServerInstallerFunction - return function(server, callback, context) - process.spawn(M.executable(server.root_dir, executable), { + return function(_, callback, context) + process.spawn(M.executable(context.install_dir, executable), { args = args, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }, callback) end @@ -80,10 +80,10 @@ end function M.run(script) return ensure_npm( ---@type ServerInstallerFunction - function(server, callback, context) + function(_, callback, context) process.spawn(npm, { args = { "run", script }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }, callback) end diff --git a/lua/nvim-lsp-installer/installers/pip3.lua b/lua/nvim-lsp-installer/installers/pip3.lua index 6b593858..0d2b9338 100644 --- a/lua/nvim-lsp-installer/installers/pip3.lua +++ b/lua/nvim-lsp-installer/installers/pip3.lua @@ -21,10 +21,10 @@ local function create_installer(python_executable, packages) }, }, ---@type ServerInstallerFunction - function(server, callback, context) + function(_, callback, context) local pkgs = Data.list_copy(packages or {}) local c = process.chain { - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, } @@ -36,7 +36,7 @@ local function create_installer(python_executable, packages) local install_command = { "-m", "pip", "install", "-U" } vim.list_extend(install_command, settings.current.pip.install_args) - c.run(M.executable(server.root_dir, "python"), vim.list_extend(install_command, pkgs)) + c.run(M.executable(context.install_dir, "python"), vim.list_extend(install_command, pkgs)) c.spawn(callback) end, diff --git a/lua/nvim-lsp-installer/installers/shell.lua b/lua/nvim-lsp-installer/installers/shell.lua index eef0e01d..53feda70 100644 --- a/lua/nvim-lsp-installer/installers/shell.lua +++ b/lua/nvim-lsp-installer/installers/shell.lua @@ -6,10 +6,10 @@ local M = {} ---@param opts {shell: string, cmd: string[], env: table|nil} local function shell(opts) ---@type ServerInstallerFunction - return function(server, callback, context) + return function(_, callback, context) local _, stdio = process.spawn(opts.shell, { args = opts.args, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, env = process.graft_env(opts.env or {}), }, callback) diff --git a/lua/nvim-lsp-installer/installers/std.lua b/lua/nvim-lsp-installer/installers/std.lua index 25d35dba..780e8415 100644 --- a/lua/nvim-lsp-installer/installers/std.lua +++ b/lua/nvim-lsp-installer/installers/std.lua @@ -12,18 +12,18 @@ local M = {} function M.download_file(url, out_file) return installers.when { ---@type ServerInstallerFunction - unix = function(server, callback, context) + unix = function(_, callback, context) context.stdio_sink.stdout(("Downloading file %q...\n"):format(url)) process.attempt { jobs = { process.lazy_spawn("wget", { args = { "-nv", "-O", out_file, url }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }), process.lazy_spawn("curl", { args = { "-fsSL", "-o", out_file, url }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }), }, @@ -40,10 +40,10 @@ function M.unzip(file, dest) return installers.pipe { installers.when { ---@type ServerInstallerFunction - unix = function(server, callback, context) + unix = function(_, callback, context) process.spawn("unzip", { args = { "-d", dest, file }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }, callback) end, @@ -66,10 +66,10 @@ end function M.untar(file) return installers.pipe { ---@type ServerInstallerFunction - function(server, callback, context) + function(_, callback, context) process.spawn("tar", { args = { "-xvf", file }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }, callback) end, @@ -81,21 +81,21 @@ end local function win_extract(file) return installers.pipe { ---@type ServerInstallerFunction - function(server, callback, context) + function(_, callback, context) -- The trademarked "throw shit until it sticks" technique local sevenzip = process.lazy_spawn("7z", { args = { "x", "-y", "-r", file }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }) local peazip = process.lazy_spawn("peazip", { - args = { "-ext2here", path.concat { server.root_dir, file } }, -- peazip require absolute paths, or else! - cwd = server.root_dir, + args = { "-ext2here", path.concat { context.install_dir, file } }, -- peazip require absolute paths, or else! + cwd = context.install_dir, stdio_sink = context.stdio_sink, }) local winzip = process.lazy_spawn("wzunzip", { args = { file }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }) process.attempt { @@ -119,11 +119,11 @@ end local function win_arc_unarchive(file) return installers.pipe { ---@type ServerInstallerFunction - function(server, callback, context) + function(_, callback, context) context.stdio_sink.stdout "Attempting to unarchive using arc." process.spawn("arc", { args = { "unarchive", file }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }, callback) end, @@ -157,10 +157,10 @@ end function M.gunzip(file) return installers.when { ---@type ServerInstallerFunction - unix = function(server, callback, context) + unix = function(_, callback, context) process.spawn("gzip", { args = { "-d", file }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }, callback) end, @@ -184,8 +184,8 @@ end ---@param rel_path string @The relative path to the file/directory to remove. function M.rmrf(rel_path) ---@type ServerInstallerFunction - return function(server, callback, context) - local abs_path = path.concat { server.root_dir, rel_path } + return function(_, callback, context) + local abs_path = path.concat { context.install_dir, rel_path } context.stdio_sink.stdout(("Deleting %q\n"):format(abs_path)) vim.schedule(function() local ok = pcall(fs.rmrf, abs_path) @@ -199,13 +199,38 @@ function M.rmrf(rel_path) end end +---@param rel_path string @The relative path to the file to write. +---@param contents string @The file contents. +function M.write_file(rel_path, contents) + ---@type ServerInstallerFunction + return function(_, callback, ctx) + local file = path.concat { ctx.install_dir, rel_path } + ctx.stdio_sink.stdout(("Writing file %q\n"):format(file)) + fs.write_file(file, contents) + callback(true) + end +end + +---@param script_rel_path string @The relative path to the script file to write. +---@param abs_target_executable_path string @The absolute path to the executable that is being aliased. +function M.executable_alias(script_rel_path, abs_target_executable_path) + local windows_script = "@call %q %%" + local unix_script = [[#!/usr/bin/env sh +exec %q +]] + return installers.when { + unix = M.write_file(script_rel_path, unix_script:format(abs_target_executable_path)), + win = M.write_file(script_rel_path, windows_script:format(abs_target_executable_path)), + } +end + ---Shallow git clone. ---@param repo_url string function M.git_clone(repo_url) ---@type ServerInstallerFunction - return function(server, callback, context) + return function(_, callback, context) local c = process.chain { - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, } @@ -223,10 +248,10 @@ end ---@param opts {args: string[]} function M.gradlew(opts) ---@type ServerInstallerFunction - return function(server, callback, context) - process.spawn(path.concat { server.root_dir, platform.is_win and "gradlew.bat" or "gradlew" }, { + return function(_, callback, context) + process.spawn(path.concat { context.install_dir, platform.is_win and "gradlew.bat" or "gradlew" }, { args = opts.args, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }, callback) end @@ -258,11 +283,11 @@ end ---@path new_path string @The relative path to what to rename the file/dir to. function M.rename(old_path, new_path) ---@type ServerInstallerFunction - return function(server, callback, context) + return function(_, callback, context) local ok = pcall( fs.rename, - path.concat { server.root_dir, old_path }, - path.concat { server.root_dir, new_path } + path.concat { context.install_dir, old_path }, + path.concat { context.install_dir, new_path } ) if not ok then context.stdio_sink.stderr(("Failed to rename %q to %q.\n"):format(old_path, new_path)) @@ -276,10 +301,10 @@ end function M.chmod(flags, files) return installers.on { ---@type ServerInstallerFunction - unix = function(server, callback, context) + unix = function(_, callback, context) process.spawn("chmod", { args = vim.list_extend({ flags }, files), - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }, callback) end, diff --git a/lua/nvim-lsp-installer/installers/zx.lua b/lua/nvim-lsp-installer/installers/zx.lua index 067abfd0..0bba8583 100644 --- a/lua/nvim-lsp-installer/installers/zx.lua +++ b/lua/nvim-lsp-installer/installers/zx.lua @@ -57,10 +57,11 @@ local function zx_installer(force) end local function exec(file) - return function(server, callback, context) + ---@type ServerInstallerFunction + return function(_, callback, context) process.spawn(ZX_EXECUTABLE, { args = { file }, - cwd = server.root_dir, + cwd = context.install_dir, stdio_sink = context.stdio_sink, }, callback) end |
