aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/installers/cargo.lua
blob: 1779980b6a3e7a854fd1fecc23b2ab9235309689 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
local process = require "nvim-lsp-installer.process"
local path = require "nvim-lsp-installer.path"

local M = {}

---@param crate string The crate to install.
---@param opts {git:boolean, features:string|nil}
function M.crate(crate, opts)
    ---@type ServerInstallerFunction
    return function(_, callback, ctx)
        opts = opts or {}
        local args = { "install", "--root", ".", "--locked" }

        if ctx.requested_server_version then
            vim.list_extend(args, { "--version", ctx.requested_server_version })
        end

        if opts.features then
            vim.list_extend(args, { "--features", opts.features })
        end

        if opts.git then
            vim.list_extend(args, { "--git", crate })
        else
            vim.list_extend(args, { crate })
        end

        ctx.receipt:with_primary_source(ctx.receipt.cargo(crate))

        process.spawn("cargo", {
            args = args,
            cwd = ctx.install_dir,
            stdio_sink = ctx.stdio_sink,
        }, callback)
    end
end

---@param opts {path:string|nil}
function M.install(opts)
    ---@type ServerInstallerFunction
    return function(_, callback, ctx)
        opts = opts or {}
        local args = { "install", "--root", "." }
        if opts.path then
            vim.list_extend(args, { "--path", opts.path })
        end
        process.spawn("cargo", {
            args = args,
            cwd = ctx.install_dir,
            stdio_sink = ctx.stdio_sink,
        }, callback)
    end
end

---@param root_dir string The directory to resolve the executable from.
function M.env(root_dir)
    return {
        PATH = process.extend_path { path.concat { root_dir, "bin" } },
    }
end

return M