diff options
| author | William Boman <william@redwill.se> | 2022-04-11 01:04:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-11 01:04:06 +0200 |
| commit | 89abfcd2fbd56c3246772726a85ed0e548d77d3b (patch) | |
| tree | 5a90c3277ee853fe6c1c04be09982b94472f45ab /lua/nvim-lsp-installer/core/managers/go | |
| parent | sumneko_lua: support Linux arm64 (#391) (diff) | |
| download | mason-89abfcd2fbd56c3246772726a85ed0e548d77d3b.tar mason-89abfcd2fbd56c3246772726a85ed0e548d77d3b.tar.gz mason-89abfcd2fbd56c3246772726a85ed0e548d77d3b.tar.bz2 mason-89abfcd2fbd56c3246772726a85ed0e548d77d3b.tar.lz mason-89abfcd2fbd56c3246772726a85ed0e548d77d3b.tar.xz mason-89abfcd2fbd56c3246772726a85ed0e548d77d3b.tar.zst mason-89abfcd2fbd56c3246772726a85ed0e548d77d3b.zip | |
make install context available via coroutine context (#586)
Diffstat (limited to 'lua/nvim-lsp-installer/core/managers/go')
| -rw-r--r-- | lua/nvim-lsp-installer/core/managers/go/init.lua | 65 |
1 files changed, 43 insertions, 22 deletions
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[]} |
