aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/servers/clangd/init.lua
blob: 5217894c3aa28d328ca55951bff10c91defd55a1 (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
local server = require "nvim-lsp-installer.server"
local path = require "nvim-lsp-installer.path"
local Data = require "nvim-lsp-installer.data"
local std = require "nvim-lsp-installer.installers.std"
local platform = require "nvim-lsp-installer.platform"
local context = require "nvim-lsp-installer.installers.context"

return function(name, root_dir)
    local script_name = platform.is_win and "clangd.bat" or "clangd"

    return server.Server:new {
        name = name,
        root_dir = root_dir,
        homepage = "https://clangd.llvm.org",
        languages = { "c", "c++" },
        installer = {
            context.use_github_release_file("clangd/clangd", function(version)
                return Data.coalesce(
                    Data.when(platform.is_mac, "clangd-mac-%s.zip"),
                    Data.when(platform.is_linux and platform.arch == "x64", "clangd-linux-%s.zip"),
                    Data.when(platform.is_win, "clangd-windows-%s.zip")
                ):format(version)
            end),
            context.capture(function(ctx)
                return std.unzip_remote(ctx.github_release_file)
            end),
            context.capture(function(ctx)
                -- Preferably we'd not have to write a script file that captures the installed version.
                -- But in order to not break backwards compatibility for existing installations of clangd, we do it.
                return std.executable_alias(
                    script_name,
                    path.concat {
                        root_dir,
                        ("clangd_%s"):format(ctx.requested_server_version),
                        "bin",
                        platform.is_win and "clangd.exe" or "clangd",
                    }
                )
            end),
            std.chmod("+x", { "clangd" }),
        },
        default_options = {
            cmd = { path.concat { root_dir, script_name } },
        },
    }
end