aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/installers/go.lua
blob: bfa7bc5471f801a6fbe88d67520712eae4111eea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
local std = require "nvim-lsp-installer.installers.std"
local installers = require "nvim-lsp-installer.installers"
local process = require "nvim-lsp-installer.process"

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)
    return installers.pipe {
        std.ensure_executables { { "go", "go was not found in path, refer to https://golang.org/doc/install." } },
        ---@type ServerInstallerFunction
        function(_, callback, ctx)
            local c = process.chain {
                env = process.graft_env {
                    GOBIN = ctx.install_dir,
                },
                cwd = ctx.install_dir,
                stdio_sink = ctx.stdio_sink,
            }

            -- Install the head package
            do
                local head_package = packages[1]
                ctx.receipt:with_primary_source(ctx.receipt.go(head_package))
                local version = ctx.requested_server_version or "latest"
                c.run("go", { "install", "-v", ("%s@%s"):format(head_package, version) })
            end

            -- Install secondary packages
            for i = 2, #packages do
                local package = packages[i]
                ctx.receipt:with_secondary_source(ctx.receipt.go(package))
                c.run("go", { "install", "-v", ("%s@latest"):format(package) })
            end

            c.spawn(callback)
        end,
    }
end

function M.env(root_dir)
    return {
        PATH = process.extend_path { root_dir },
    }
end

return M