aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-registry/julia-lsp/init.lua
blob: d3dacdfeb127d0f03e032f2dbc81613e699b5c74 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local Pkg = require "mason-core.package"
local path = require "mason-core.path"
local std = require "mason-core.managers.std"
local github = require "mason-core.managers.github"
local platform = require "mason-core.platform"

local server_script = [[
if VERSION < v"1.0.0"
    error("julia language server only works with julia 1.0.0+")
end

import Pkg
version_specific_env_path = joinpath(@__DIR__, "scripts", "environments", "languageserver", "v$(VERSION.major).$(VERSION.minor)")
if isdir(version_specific_env_path)
    Pkg.activate(version_specific_env_path)
else
    Pkg.activate(joinpath(@__DIR__, "scripts", "environments", "languageserver", "fallback"))
end

using LanguageServer, SymbolServer, Pkg

OLD_DEPOT_PATH = ARGS[1]
ENV_PATH = ARGS[2]

runserver(
    stdin,
    stdout,
    ENV_PATH,
    OLD_DEPOT_PATH,
    nothing,
    ENV["SYMBOLSTORE_PATH"]
)
]]

return Pkg.new {
    name = "julia-lsp",
    desc = [[An implementation of the Microsoft Language Server Protocol for the Julia language.]],
    homepage = "https://github.com/julia-vscode/LanguageServer.jl",
    languages = { Pkg.Lang.Julia },
    categories = { Pkg.Cat.LSP },
    ---@async
    ---@param ctx InstallContext
    install = function(ctx)
        std.ensure_executable("julia", { help_url = "https://julialang.org/downloads/" })

        ctx.fs:mkdir "vscode-package"
        ctx:chdir("vscode-package", function()
            github
                .unzip_release_file({
                    repo = "julia-vscode/julia-vscode",
                    asset_file = function(version)
                        local version_number = version:gsub("^v", "")
                        return ("language-julia-%s.vsix"):format(version_number)
                    end,
                })
                .with_receipt()
        end)

        ctx.fs:rename(
            path.concat {
                "vscode-package",
                "extension",
                "scripts",
            },
            "scripts"
        )
        ctx.fs:rmrf "vscode-package"

        ctx.fs:write_file("nvim-lsp.jl", server_script)
        ctx:link_bin(
            "julia-lsp",
            ctx:write_shell_exec_wrapper(
                "julia-lsp",
                ("julia --startup-file=no --history-file=no --depwarn=no %q"):format(path.concat {
                    ctx.package:get_install_path(),
                    "nvim-lsp.jl",
                }),
                {
                    SYMBOLSTORE_PATH = path.concat { ctx.package:get_install_path(), "symbolstorev5" },
                    JULIA_DEPOT_PATH = path.concat { ctx.package:get_install_path(), "lsdepot" },
                    JULIA_LOAD_PATH = platform.is.win and ";" or ":",
                }
            )
        )
    end,
}