aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/servers/apex_ls/init.lua
blob: 2ed778a9e5fa19a0cafeea71c2d4e3f1f5369535 (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
local server = require "nvim-lsp-installer.server"
local github = require "nvim-lsp-installer.core.managers.github"
local github_client = require "nvim-lsp-installer.core.managers.github.client"
local Optional = require "nvim-lsp-installer.core.optional"
local path = require "nvim-lsp-installer.core.path"
local _ = require "nvim-lsp-installer.core.functional"

return function(name, root_dir)
    local JAR_FILE = "apex-jorje-lsp.jar"

    return server.Server:new {
        name = name,
        root_dir = root_dir,
        homepage = "https://github.com/forcedotcom/salesforcedx-vscode",
        languages = { "apex" },
        ---@async
        ---@param ctx InstallContext
        installer = function(ctx)
            local repo = "forcedotcom/salesforcedx-vscode"

            -- See https://github.com/forcedotcom/salesforcedx-vscode/issues/4184#issuecomment-1146052086
            ---@type GitHubRelease
            local release = github_client
                .fetch_releases(repo)
                :map(_.find_first(_.prop_satisfies(_.compose(_.gt(0), _.length), "assets")))
                :map(Optional.of_nilable)
                :get_or_throw() -- Result unwrap
                :or_else_throw "Failed to find release with assets." -- Optional unwrap

            github.unzip_release_file({
                version = Optional.of(release.tag_name),
                asset_file = _.compose(_.format "salesforcedx-vscode-apex-%s.vsix", _.gsub("^v", "")),
                repo = repo,
            }).with_receipt()

            ctx.fs:rename(path.concat { "extension", "out", JAR_FILE }, JAR_FILE)
            ctx.fs:rmrf "extension"
        end,
        default_options = {
            apex_jar_path = path.concat { root_dir, JAR_FILE },
        },
    }
end