aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/installers/go.lua
blob: d7857498454340a11f7ad87987234be3ae1a1842 (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
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 package string The Go package to install.
function M.package(package)
    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,
            }

            ctx.receipt:with_primary_source(ctx.receipt.go(package))

            local version = ctx.requested_server_version or "latest"
            local pkg = ("%s@%s"):format(package, version)

            c.run("go", { "install", "-v", pkg })

            c.spawn(callback)
        end,
    }
end

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

return M