diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-lsp-installer/core/async/init.lua | 6 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/installer/init.lua | 40 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/managers/cargo/init.lua | 62 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/managers/composer/init.lua | 70 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/managers/dotnet/init.lua | 51 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/managers/gem/init.lua | 57 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/managers/git/init.lua | 33 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/managers/go/init.lua | 65 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/managers/npm/init.lua | 87 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/managers/opam/init.lua | 55 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/managers/pip3/init.lua | 81 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/servers/ansiblels/init.lua | 11 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/servers/nickel_ls/init.lua | 24 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/servers/phpactor/init.lua | 13 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/servers/psalm/init.lua | 2 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/servers/rome/init.lua | 17 |
16 files changed, 411 insertions, 263 deletions
diff --git a/lua/nvim-lsp-installer/core/async/init.lua b/lua/nvim-lsp-installer/core/async/init.lua index 0c278373..d448bc30 100644 --- a/lua/nvim-lsp-installer/core/async/init.lua +++ b/lua/nvim-lsp-installer/core/async/init.lua @@ -72,7 +72,11 @@ local function new_execution_context(suspend_fn, callback, ...) end local ok, promise_or_result = co.resume(thread, ...) if ok then - if getmetatable(promise_or_result) == Promise then + if co.status(thread) == "suspended" then + assert( + getmetatable(promise_or_result) == Promise, + "Expected Promise to have been yielded in async coroutine." + ) promise_or_result(step) else callback(true, promise_or_result) diff --git a/lua/nvim-lsp-installer/core/installer/init.lua b/lua/nvim-lsp-installer/core/installer/init.lua index 03b2de01..0159e1e0 100644 --- a/lua/nvim-lsp-installer/core/installer/init.lua +++ b/lua/nvim-lsp-installer/core/installer/init.lua @@ -21,6 +21,33 @@ local function write_receipt(context) end end +local CONTEXT_REQUEST = {} + +---@return InstallContext +function M.context() + return coroutine.yield(CONTEXT_REQUEST) +end + +---@async +---@param context InstallContext +---@param installer async fun(context: InstallContext) +function M.run_installer(context, installer) + local thread = coroutine.create(installer) + local step + step = function(...) + local ok, result = coroutine.resume(thread, ...) + if not ok then + error(result, 0) + elseif result == CONTEXT_REQUEST then + step(context) + elseif coroutine.status(thread) == "suspended" then + -- yield to parent coroutine + step(coroutine.yield(result)) + end + end + step(context) +end + ---@async ---@param context InstallContext ---@param installer async fun(ctx: InstallContext) @@ -37,7 +64,7 @@ function M.execute(context, installer) context.cwd:set(tmp_installation_dir) -- 2. run installer - installer(context) + M.run_installer(context, installer) -- 3. finalize write_receipt(context) @@ -51,15 +78,4 @@ function M.execute(context, installer) end) end ----@param installers async fun(ctx: InstallContext)[] -function M.serial(installers) - ---@async - ---@param ctx InstallContext - return function(ctx) - for _, installer_step in pairs(installers) do - installer_step(ctx) - end - end -end - return M diff --git a/lua/nvim-lsp-installer/core/managers/cargo/init.lua b/lua/nvim-lsp-installer/core/managers/cargo/init.lua index 29c07868..5d74e010 100644 --- a/lua/nvim-lsp-installer/core/managers/cargo/init.lua +++ b/lua/nvim-lsp-installer/core/managers/cargo/init.lua @@ -5,38 +5,56 @@ local a = require "nvim-lsp-installer.core.async" local Optional = require "nvim-lsp-installer.core.optional" local crates = require "nvim-lsp-installer.core.clients.crates" local Result = require "nvim-lsp-installer.core.result" +local installer = require "nvim-lsp-installer.core.installer" local fetch_crate = a.promisify(crates.fetch_crate, true) +---@param crate string +local function with_receipt(crate) + return function() + local ctx = installer.context() + ctx.receipt:with_primary_source(ctx.receipt.cargo(crate)) + end +end + local M = {} +---@async ---@param crate string The crate to install. ---@param opts {git:boolean, features:string|nil} function M.crate(crate, opts) - ---@async - ---@param ctx InstallContext - return function(ctx) - opts = opts or {} - ctx.requested_version:if_present(function() - assert(not opts.git, "Providing a version when installing a git crate is not allowed.") - end) + return function() + return M.install(crate, opts).with_receipt() + end +end - ctx.receipt:with_primary_source(ctx.receipt.cargo(crate)) +---@async +---@param crate string The crate to install. +---@param opts {git:boolean, features:string|nil} +function M.install(crate, opts) + local ctx = installer.context() + opts = opts or {} + ctx.requested_version:if_present(function() + assert(not opts.git, "Providing a version when installing a git crate is not allowed.") + end) - ctx.spawn.cargo { - "install", - "--root", - ".", - "--locked", - ctx.requested_version - :map(function(version) - return { "--version", version } - end) - :or_else(vim.NIL), - opts.features and { "--features", opts.features } or vim.NIL, - opts.git and { "--git", crate } or crate, - } - end + ctx.spawn.cargo { + "install", + "--root", + ".", + "--locked", + ctx.requested_version + :map(function(version) + return { "--version", version } + end) + :or_else(vim.NIL), + opts.features and { "--features", opts.features } or vim.NIL, + opts.git and { "--git", crate } or crate, + } + + return { + with_receipt = with_receipt(crate), + } end ---@param output string @The `cargo install --list` output. diff --git a/lua/nvim-lsp-installer/core/managers/composer/init.lua b/lua/nvim-lsp-installer/core/managers/composer/init.lua index 9a1e2dd4..17018524 100644 --- a/lua/nvim-lsp-installer/core/managers/composer/init.lua +++ b/lua/nvim-lsp-installer/core/managers/composer/init.lua @@ -4,47 +4,63 @@ local path = require "nvim-lsp-installer.path" local Result = require "nvim-lsp-installer.core.result" local spawn = require "nvim-lsp-installer.core.spawn" local Optional = require "nvim-lsp-installer.core.optional" +local installer = require "nvim-lsp-installer.core.installer" local list_copy, list_find_first = Data.list_copy, Data.list_find_first local M = {} ----@param packages string[] The composer packages to install. The first item in this list will be the recipient of the server version, should the user request a specific one. -function M.require(packages) - ---@async - ---@param ctx InstallContext - return function(ctx) - local pkgs = list_copy(packages) +---@param packages string[] +local function with_receipt(packages) + return function() + local ctx = installer.context() - ctx.receipt:with_primary_source(ctx.receipt.composer(pkgs[1])) - for i = 2, #pkgs do - ctx.receipt:with_secondary_source(ctx.receipt.composer(pkgs[i])) + ctx.receipt:with_primary_source(ctx.receipt.composer(packages[1])) + for i = 2, #packages do + ctx.receipt:with_secondary_source(ctx.receipt.composer(packages[i])) end + end +end - if not ctx.fs:file_exists "composer.json" then - ctx.spawn.composer { "init", "--no-interaction", "--stability=stable" } - end +---@async +---@param packages string[] The composer packages to install. The first item in this list will be the recipient of the server version, should the user request a specific one. +function M.packages(packages) + return function() + return M.require(packages).with_receipt() + end +end - ctx.requested_version:if_present(function(version) - pkgs[1] = ("%s:%s"):format(pkgs[1], version) - end) +---@async +---@param packages string[] The composer packages to install. The first item in this list will be the recipient of the server version, should the user request a specific one. +function M.require(packages) + local ctx = installer.context() + local pkgs = list_copy(packages) - ctx.spawn.composer { "require", pkgs } + if not ctx.fs:file_exists "composer.json" then + ctx.spawn.composer { "init", "--no-interaction", "--stability=stable" } end + + ctx.requested_version:if_present(function(version) + pkgs[1] = ("%s:%s"):format(pkgs[1], version) + end) + + ctx.spawn.composer { "require", pkgs } + + return { + with_receipt = with_receipt(packages), + } end +---@async function M.install() - ---@async - ---@param ctx InstallContext - return function(ctx) - ctx.spawn.composer { - "install", - "--no-interaction", - "--no-dev", - "--optimize-autoloader", - "--classmap-authoritative", - } - end + local ctx = installer.context() + ctx.spawn.composer { + "install", + "--no-interaction", + "--no-dev", + "--optimize-autoloader", + "--classmap-authoritative", + } end ---@async diff --git a/lua/nvim-lsp-installer/core/managers/dotnet/init.lua b/lua/nvim-lsp-installer/core/managers/dotnet/init.lua index c862146f..b985dc02 100644 --- a/lua/nvim-lsp-installer/core/managers/dotnet/init.lua +++ b/lua/nvim-lsp-installer/core/managers/dotnet/init.lua @@ -1,27 +1,46 @@ local process = require "nvim-lsp-installer.process" +local installer = require "nvim-lsp-installer.core.installer" + local M = {} ---@param package string -function M.package(package) - ---@async - ---@param ctx InstallContext - return function(ctx) +local function with_receipt(package) + return function() + local ctx = installer.context() ctx.receipt:with_primary_source(ctx.receipt.dotnet(package)) - ctx.spawn.dotnet { - "tool", - "update", - "--tool-path", - ".", - ctx.requested_version - :map(function(version) - return { "--version", version } - end) - :or_else(vim.NIL), - package, - } end end +---@async +---@param package string +function M.package(package) + return function() + return M.install(package).with_receipt() + end +end + +---@async +---@param package string +function M.install(package) + local ctx = installer.context() + ctx.spawn.dotnet { + "tool", + "update", + "--tool-path", + ".", + ctx.requested_version + :map(function(version) + return { "--version", version } + end) + :or_else(vim.NIL), + package, + } + + return { + with_receipt = with_receipt(package), + } +end + function M.env(root_dir) return { PATH = process.extend_path { root_dir }, diff --git a/lua/nvim-lsp-installer/core/managers/gem/init.lua b/lua/nvim-lsp-installer/core/managers/gem/init.lua index 7b030797..f40cb736 100644 --- a/lua/nvim-lsp-installer/core/managers/gem/init.lua +++ b/lua/nvim-lsp-installer/core/managers/gem/init.lua @@ -4,36 +4,53 @@ local path = require "nvim-lsp-installer.path" local Result = require "nvim-lsp-installer.core.result" local spawn = require "nvim-lsp-installer.core.spawn" local Optional = require "nvim-lsp-installer.core.optional" +local installer = require "nvim-lsp-installer.core.installer" local list_copy, list_find_first = Data.list_copy, Data.list_find_first local M = {} +---@param packages string[] +local function with_receipt(packages) + return function() + local ctx = installer.context() + ctx.receipt:with_primary_source(ctx.receipt.gem(packages[1])) + for i = 2, #packages do + ctx.receipt:with_secondary_source(ctx.receipt.gem(packages[i])) + end + end +end + +---@async ---@param packages string[] @The Gem packages to install. The first item in this list will be the recipient of the server version, should the user request a specific one. function M.packages(packages) - ---@async - ---@param ctx InstallContext - return function(ctx) - local pkgs = list_copy(packages or {}) + return function() + return M.install(packages).with_receipt() + end +end - ctx.receipt:with_primary_source(ctx.receipt.gem(pkgs[1])) - for i = 2, #pkgs do - ctx.receipt:with_secondary_source(ctx.receipt.gem(pkgs[i])) - end +---@async +---@param packages string[] @The Gem packages to install. The first item in this list will be the recipient of the server version, should the user request a specific one. +function M.install(packages) + local ctx = installer.context() + local pkgs = list_copy(packages or {}) - ctx.requested_version:if_present(function(version) - pkgs[1] = ("%s:%s"):format(pkgs[1], version) - end) + ctx.requested_version:if_present(function(version) + pkgs[1] = ("%s:%s"):format(pkgs[1], version) + end) - ctx.spawn.gem { - "install", - "--no-user-install", - "--install-dir=.", - "--bindir=bin", - "--no-document", - pkgs, - } - end + ctx.spawn.gem { + "install", + "--no-user-install", + "--install-dir=.", + "--bindir=bin", + "--no-document", + pkgs, + } + + return { + with_receipt = with_receipt(packages), + } end ---@alias GemOutdatedPackage {name:string, current_version: string, latest_version: string} diff --git a/lua/nvim-lsp-installer/core/managers/git/init.lua b/lua/nvim-lsp-installer/core/managers/git/init.lua index bdd79917..f3c6ee65 100644 --- a/lua/nvim-lsp-installer/core/managers/git/init.lua +++ b/lua/nvim-lsp-installer/core/managers/git/init.lua @@ -1,23 +1,34 @@ local spawn = require "nvim-lsp-installer.core.spawn" local Result = require "nvim-lsp-installer.core.result" +local installer = require "nvim-lsp-installer.core.installer" + local M = {} ----@param opts {[1]:string} @The first item in the table is the repository to clone. -function M.clone(opts) - ---@async - ---@param ctx InstallContext - return function(ctx) - local repo = assert(opts[1], "No git URL provided.") - ctx.spawn.git { "clone", "--depth", "1", repo, "." } - ctx.requested_version:if_present(function(version) - ctx.spawn.git { "fetch", "--depth", "1", "origin", version } - ctx.spawn.git { "checkout", "FETCH_HEAD" } - end) +---@param repo string +local function with_receipt(repo) + return function() + local ctx = installer.context() ctx.receipt:with_primary_source(ctx.receipt.git_remote(repo)) end end ---@async +---@param opts {[1]:string} @The first item in the table is the repository to clone. +function M.clone(opts) + local ctx = installer.context() + local repo = assert(opts[1], "No git URL provided.") + ctx.spawn.git { "clone", "--depth", "1", repo, "." } + ctx.requested_version:if_present(function(version) + ctx.spawn.git { "fetch", "--depth", "1", "origin", version } + ctx.spawn.git { "checkout", "FETCH_HEAD" } + end) + + return { + with_receipt = with_receipt(repo), + } +end + +---@async ---@param receipt InstallReceipt ---@param install_dir string function M.check_outdated_git_clone(receipt, install_dir) diff --git a/lua/nvim-lsp-installer/core/managers/go/init.lua b/lua/nvim-lsp-installer/core/managers/go/init.lua index d73a250c..99be5618 100644 --- a/lua/nvim-lsp-installer/core/managers/go/init.lua +++ b/lua/nvim-lsp-installer/core/managers/go/init.lua @@ -1,3 +1,4 @@ +local installer = require "nvim-lsp-installer.core.installer" local process = require "nvim-lsp-installer.process" local platform = require "nvim-lsp-installer.platform" local spawn = require "nvim-lsp-installer.core.spawn" @@ -6,36 +7,56 @@ local Optional = require "nvim-lsp-installer.core.optional" local M = {} ----@param packages string[] The Go packages to install. The first item in this list will be the recipient of the server version, should the user request a specific one. -function M.packages(packages) - ---@async - ---@param ctx InstallContext - return function(ctx) - local env = process.graft_env { - GOBIN = ctx.cwd:get(), - } - -- Install the head package - do - local head_package = packages[1] - ctx.receipt:with_primary_source(ctx.receipt.go(head_package)) - local version = ctx.requested_version:or_else "latest" - ctx.spawn.go { - "install", - "-v", - ("%s@%s"):format(head_package, version), - env = env, - } - end - +---@param packages string[] +local function with_receipt(packages) + return function() + local ctx = installer.context() + ctx.receipt:with_primary_source(ctx.receipt.go(packages[1])) -- Install secondary packages for i = 2, #packages do local package = packages[i] ctx.receipt:with_secondary_source(ctx.receipt.go(package)) - ctx.spawn.go { "install", "-v", ("%s@latest"):format(package), env = env } end end end +---@async +---@param packages string[] The Go packages to install. The first item in this list will be the recipient of the server version, should the user request a specific one. +function M.packages(packages) + return function() + M.install(packages).with_receipt() + end +end + +---@async +---@param packages string[] The Go packages to install. The first item in this list will be the recipient of the server version, should the user request a specific one. +function M.install(packages) + local ctx = installer.context() + local env = process.graft_env { + GOBIN = ctx.cwd:get(), + } + -- Install the head package + do + local head_package = packages[1] + local version = ctx.requested_version:or_else "latest" + ctx.spawn.go { + "install", + "-v", + ("%s@%s"):format(head_package, version), + env = env, + } + end + + -- Install secondary packages + for i = 2, #packages do + ctx.spawn.go { "install", "-v", ("%s@latest"):format(packages[i]), env = env } + end + + return { + with_receipt = with_receipt(packages), + } +end + ---@param output string @The output from `go version -m` command. function M.parse_mod_version_output(output) ---@type {path: string[], mod: string[], dep: string[], build: string[]} diff --git a/lua/nvim-lsp-installer/core/managers/npm/init.lua b/lua/nvim-lsp-installer/core/managers/npm/init.lua index c3be01da..a4631e42 100644 --- a/lua/nvim-lsp-installer/core/managers/npm/init.lua +++ b/lua/nvim-lsp-installer/core/managers/npm/init.lua @@ -1,6 +1,7 @@ local Data = require "nvim-lsp-installer.data" local spawn = require "nvim-lsp-installer.core.spawn" local Optional = require "nvim-lsp-installer.core.optional" +local installer = require "nvim-lsp-installer.core.installer" local Result = require "nvim-lsp-installer.core.result" local process = require "nvim-lsp-installer.process" local path = require "nvim-lsp-installer.path" @@ -18,62 +19,64 @@ local function ensure_npm_root(ctx) end end ----@param packages string[] @The npm packages to install. The first item in this list will be the recipient of the requested version, if set. -function M.packages(packages) - ---@async - ---@param ctx InstallContext - return function(ctx) - local pkgs = list_copy(packages) - - -- Use global-style. The reasons for this are: - -- a) To avoid polluting the executables (aka bin-links) that npm creates. - -- b) The installation is, after all, more similar to a "global" installation. We don't really gain - -- any of the benefits of not using global style (e.g., deduping the dependency tree). - -- - -- We write to .npmrc manually instead of going through npm because managing a local .npmrc file - -- is a bit unreliable across npm versions (especially <7), so we take extra measures to avoid - -- inadvertently polluting global npm config. - ctx.fs:append_file(".npmrc", "global-style=true") - - ctx.receipt:with_primary_source(ctx.receipt.npm(pkgs[1])) - for i = 2, #pkgs do - ctx.receipt:with_secondary_source(ctx.receipt.npm(pkgs[i])) +---@param packages string[] +local function with_receipt(packages) + return function() + local ctx = installer.context() + ctx.receipt:with_primary_source(ctx.receipt.npm(packages[1])) + for i = 2, #packages do + ctx.receipt:with_secondary_source(ctx.receipt.npm(packages[i])) end + end +end - ctx.requested_version:if_present(function(version) - pkgs[1] = ("%s@%s"):format(pkgs[1], version) - end) - - M.install(pkgs)(ctx) +---@async +---@param packages string[] @The npm packages to install. The first item in this list will be the recipient of the requested version, if set. +function M.packages(packages) + return function() + return M.install(packages).with_receipt() end end ----@param packages string[] @The npm packages to install. +---@async +---@param packages string[] @The npm packages to install. The first item in this list will be the recipient of the requested version, if set. function M.install(packages) - ---@async - ---@param ctx InstallContext - return function(ctx) - ensure_npm_root(ctx) - ctx.spawn.npm { "install", packages } - end + local ctx = installer.context() + local pkgs = list_copy(packages) + ctx.requested_version:if_present(function(version) + pkgs[1] = ("%s@%s"):format(pkgs[1], version) + end) + + -- Use global-style. The reasons for this are: + -- a) To avoid polluting the executables (aka bin-links) that npm creates. + -- b) The installation is, after all, more similar to a "global" installation. We don't really gain + -- any of the benefits of not using global style (e.g., deduping the dependency tree). + -- + -- We write to .npmrc manually instead of going through npm because managing a local .npmrc file + -- is a bit unreliable across npm versions (especially <7), so we take extra measures to avoid + -- inadvertently polluting global npm config. + ctx.fs:append_file(".npmrc", "global-style=true") + + ensure_npm_root(ctx) + ctx.spawn.npm { "install", pkgs } + + return { + with_receipt = with_receipt(packages), + } end +---@async ---@param exec_args string[] @The arguments to pass to npm exec. function M.exec(exec_args) - ---@async - ---@param ctx InstallContext - return function(ctx) - ctx.spawn.npm { "exec", "--yes", exec_args } - end + local ctx = installer.context() + ctx.spawn.npm { "exec", "--yes", exec_args } end +---@async ---@param script string @The npm script to run. function M.run(script) - ---@async - ---@param ctx InstallContext - return function(ctx) - ctx.spawn.npm { "run", script } - end + local ctx = installer.context() + ctx.spawn.npm { "run", script } end ---@async diff --git a/lua/nvim-lsp-installer/core/managers/opam/init.lua b/lua/nvim-lsp-installer/core/managers/opam/init.lua index 8fd60de7..f6f906c2 100644 --- a/lua/nvim-lsp-installer/core/managers/opam/init.lua +++ b/lua/nvim-lsp-installer/core/managers/opam/init.lua @@ -1,35 +1,52 @@ local Data = require "nvim-lsp-installer.data" local path = require "nvim-lsp-installer.path" local process = require "nvim-lsp-installer.process" +local installer = require "nvim-lsp-installer.core.installer" local M = {} local list_copy = Data.list_copy +---@param packages string[] +local function with_receipt(packages) + return function() + local ctx = installer.context() + ctx.receipt:with_primary_source(ctx.receipt.opam(packages[1])) + for i = 2, #packages do + ctx.receipt:with_secondary_source(ctx.receipt.opam(packages[i])) + end + end +end + +---@async ---@param packages string[] @The opam packages to install. The first item in this list will be the recipient of the requested version, if set. function M.packages(packages) - ---@async - ---@param ctx InstallContext - return function(ctx) - local pkgs = list_copy(packages) + return function() + return M.install(packages).with_receipt() + end +end - ctx.receipt:with_primary_source(ctx.receipt.opam(pkgs[1])) - for i = 2, #pkgs do - ctx.receipt:with_secondary_source(ctx.receipt.opam(pkgs[i])) - end +---@async +---@param packages string[] @The opam packages to install. The first item in this list will be the recipient of the requested version, if set. +function M.install(packages) + local ctx = installer.context() + local pkgs = list_copy(packages) - ctx.requested_version:if_present(function(version) - pkgs[1] = ("%s.%s"):format(pkgs[1], version) - end) + ctx.requested_version:if_present(function(version) + pkgs[1] = ("%s.%s"):format(pkgs[1], version) + end) - ctx.spawn.opam { - "install", - "--destdir=.", - "--yes", - "--verbose", - pkgs, - } - end + ctx.spawn.opam { + "install", + "--destdir=.", + "--yes", + "--verbose", + pkgs, + } + + return { + with_receipt = with_receipt(packages), + } end function M.env(root_dir) diff --git a/lua/nvim-lsp-installer/core/managers/pip3/init.lua b/lua/nvim-lsp-installer/core/managers/pip3/init.lua index 13198b3b..ab2ce221 100644 --- a/lua/nvim-lsp-installer/core/managers/pip3/init.lua +++ b/lua/nvim-lsp-installer/core/managers/pip3/init.lua @@ -4,6 +4,7 @@ local process = require "nvim-lsp-installer.process" local path = require "nvim-lsp-installer.path" local platform = require "nvim-lsp-installer.platform" local Optional = require "nvim-lsp-installer.core.optional" +local installer = require "nvim-lsp-installer.core.installer" local Result = require "nvim-lsp-installer.core.result" local spawn = require "nvim-lsp-installer.core.spawn" @@ -12,47 +13,63 @@ local VENV_DIR = "venv" local M = {} +---@param packages string[] +local function with_receipt(packages) + return function() + local ctx = installer.context() + ctx.receipt:with_primary_source(ctx.receipt.pip3(packages[1])) + for i = 2, #packages do + ctx.receipt:with_secondary_source(ctx.receipt.pip3(packages[i])) + end + end +end + +---@async ---@param packages string[] @The pip packages to install. The first item in this list will be the recipient of the requested version, if set. function M.packages(packages) - ---@async - ---@param ctx InstallContext - return function(ctx) - local pkgs = list_copy(packages) + return function() + return M.install(packages).with_receipt() + end +end - ctx.receipt:with_primary_source(ctx.receipt.pip3(pkgs[1])) - for i = 2, #pkgs do - ctx.receipt:with_secondary_source(ctx.receipt.pip3(pkgs[i])) - end +---@async +---@param packages string[] @The pip packages to install. The first item in this list will be the recipient of the requested version, if set. +function M.install(packages) + local ctx = installer.context() + local pkgs = list_copy(packages) - ctx.requested_version:if_present(function(version) - pkgs[1] = ("%s==%s"):format(pkgs[1], version) - end) + ctx.requested_version:if_present(function(version) + pkgs[1] = ("%s==%s"):format(pkgs[1], version) + end) - local executables = platform.is_win and list_not_nil(vim.g.python3_host_prog, "python", "python3") - or list_not_nil(vim.g.python3_host_prog, "python3", "python") + local executables = platform.is_win and list_not_nil(vim.g.python3_host_prog, "python", "python3") + or list_not_nil(vim.g.python3_host_prog, "python3", "python") - -- pip3 will hardcode the full path to venv executables, so we need to promote cwd to make sure pip uses the final destination path. - ctx:promote_cwd() + -- pip3 will hardcode the full path to venv executables, so we need to promote cwd to make sure pip uses the final destination path. + ctx:promote_cwd() - -- Find first executable that manages to create venv - local executable = list_find_first(executables, function(executable) - return pcall(ctx.spawn[executable], { "-m", "venv", VENV_DIR }) + -- Find first executable that manages to create venv + local executable = list_find_first(executables, function(executable) + return pcall(ctx.spawn[executable], { "-m", "venv", VENV_DIR }) + end) + + Optional.of_nilable(executable) + :if_present(function() + ctx.spawn.python { + env = process.graft_env(M.env(ctx.cwd:get())), -- use venv env + "-m", + "pip", + "install", + "-U", + settings.current.pip.install_args, + pkgs, + } end) + :or_else_throw "Unable to create python3 venv environment." - Optional.of_nilable(executable) - :if_present(function() - ctx.spawn.python { - env = process.graft_env(M.env(ctx.cwd:get())), -- use venv env - "-m", - "pip", - "install", - "-U", - settings.current.pip.install_args, - pkgs, - } - end) - :or_else_throw "Unable to create python3 venv environment." - end + return { + with_receipt = with_receipt(packages), + } end ---@param package string diff --git a/lua/nvim-lsp-installer/servers/ansiblels/init.lua b/lua/nvim-lsp-installer/servers/ansiblels/init.lua index 92541e56..3c3c753d 100644 --- a/lua/nvim-lsp-installer/servers/ansiblels/init.lua +++ b/lua/nvim-lsp-installer/servers/ansiblels/init.lua @@ -2,7 +2,6 @@ local server = require "nvim-lsp-installer.server" local path = require "nvim-lsp-installer.path" local npm = require "nvim-lsp-installer.core.managers.npm" local git = require "nvim-lsp-installer.core.managers.git" -local installer = require "nvim-lsp-installer.core.installer" return function(name, root_dir) return server.Server:new { @@ -11,13 +10,13 @@ return function(name, root_dir) languages = { "ansible" }, homepage = "https://github.com/ansible/ansible-language-server", async = true, - installer = installer.serial { - git.clone { "https://github.com/ansible/ansible-language-server" }, + installer = function() + git.clone({ "https://github.com/ansible/ansible-language-server" }).with_receipt() -- ansiblels has quite a strict npm version requirement. -- Install dependencies using the the latest npm version. - npm.exec { "npm@latest", "install" }, - npm.run { "compile" }, - }, + npm.exec { "npm@latest", "install" } + npm.run { "compile" } + end, default_options = { cmd = { "node", path.concat { root_dir, "out", "server", "src", "server.js" }, "--stdio" }, }, diff --git a/lua/nvim-lsp-installer/servers/nickel_ls/init.lua b/lua/nvim-lsp-installer/servers/nickel_ls/init.lua index bf87cd21..01bf1004 100644 --- a/lua/nvim-lsp-installer/servers/nickel_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/nickel_ls/init.lua @@ -1,6 +1,5 @@ local path = require "nvim-lsp-installer.path" local server = require "nvim-lsp-installer.server" -local installer = require "nvim-lsp-installer.core.installer" local cargo = require "nvim-lsp-installer.core.managers.cargo" local git = require "nvim-lsp-installer.core.managers.git" @@ -11,19 +10,16 @@ return function(name, root_dir) homepage = "https://nickel-lang.org/", languages = { "nickel" }, async = true, - installer = installer.serial { - git.clone { "https://github.com/tweag/nickel" }, - ---@param ctx InstallContext - function(ctx) - ctx.spawn.cargo { - "install", - "--root", - ".", - "--path", - path.concat { "lsp", "nls" }, - } - end, - }, + installer = function(ctx) + git.clone({ "https://github.com/tweag/nickel" }).with_receipt() + ctx.spawn.cargo { + "install", + "--root", + ".", + "--path", + path.concat { "lsp", "nls" }, + } + end, default_options = { cmd_env = cargo.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/phpactor/init.lua b/lua/nvim-lsp-installer/servers/phpactor/init.lua index af5d863c..1425ae2e 100644 --- a/lua/nvim-lsp-installer/servers/phpactor/init.lua +++ b/lua/nvim-lsp-installer/servers/phpactor/init.lua @@ -2,7 +2,6 @@ local path = require "nvim-lsp-installer.path" local server = require "nvim-lsp-installer.server" local composer = require "nvim-lsp-installer.core.managers.composer" local git = require "nvim-lsp-installer.core.managers.git" -local installer = require "nvim-lsp-installer.core.installer" local process = require "nvim-lsp-installer.process" local platform = require "nvim-lsp-installer.platform" @@ -13,13 +12,11 @@ return function(name, root_dir) homepage = "https://phpactor.readthedocs.io/en/master/", languages = { "php" }, async = true, - installer = installer.serial { - function() - assert(platform.is_unix, "Phpactor only supports UNIX environments.") - end, - git.clone { "https://github.com/phpactor/phpactor.git" }, - composer.install(), - }, + installer = function() + assert(platform.is_unix, "Phpactor only supports UNIX environments.") + git.clone({ "https://github.com/phpactor/phpactor.git" }).with_receipt() + composer.install() + end, default_options = { cmd_env = { PATH = process.extend_path { path.concat { root_dir, "bin" } }, diff --git a/lua/nvim-lsp-installer/servers/psalm/init.lua b/lua/nvim-lsp-installer/servers/psalm/init.lua index 8c8b9be3..b6f63064 100644 --- a/lua/nvim-lsp-installer/servers/psalm/init.lua +++ b/lua/nvim-lsp-installer/servers/psalm/init.lua @@ -8,7 +8,7 @@ return function(name, root_dir) homepage = "https://psalm.dev/", languages = { "php" }, async = true, - installer = composer.require { "vimeo/psalm" }, + installer = composer.packages { "vimeo/psalm" }, default_options = { cmd_env = composer.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/rome/init.lua b/lua/nvim-lsp-installer/servers/rome/init.lua index 7a20384c..aa0613a0 100644 --- a/lua/nvim-lsp-installer/servers/rome/init.lua +++ b/lua/nvim-lsp-installer/servers/rome/init.lua @@ -1,6 +1,5 @@ local server = require "nvim-lsp-installer.server" local npm = require "nvim-lsp-installer.core.managers.npm" -local installer = require "nvim-lsp-installer.core.installer" local Optional = require "nvim-lsp-installer.core.optional" return function(name, root_dir) @@ -9,15 +8,13 @@ return function(name, root_dir) root_dir = root_dir, languages = { "typescript", "javascript" }, homepage = "https://rome.tools", - installer = installer.serial { - ---@param ctx InstallContext - function(ctx) - ctx.requested_version = ctx.requested_version:or_(function() - return Optional.of "10.0.7-nightly.2021.7.27" - end) - end, - npm.packages { "rome" }, - }, + ---@param ctx InstallContext + installer = function(ctx) + ctx.requested_version = ctx.requested_version:or_(function() + return Optional.of "10.0.7-nightly.2021.7.27" + end) + npm.install({ "rome" }).with_receipt() + end, async = true, default_options = { cmd_env = npm.env(root_dir), |
