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

return function(name, root_dir)
    local bin_dir = Data.coalesce(
        Data.when(platform.is_mac, "macOS"),
        Data.when(platform.is_linux, "Linux"),
        Data.when(platform.is_win, "Windows")
    )

    return server.Server:new {
        name = name,
        root_dir = root_dir,
        homepage = "https://github.com/sumneko/lua-language-server",
        installer = {
            context.use_github_release_file("sumneko/vscode-lua", function(version)
                return ("lua-%s.vsix"):format(version:gsub("^v", ""))
            end),
            context.capture(function(ctx)
                return std.unzip_remote(ctx.github_release_file)
            end),
            -- see https://github.com/sumneko/vscode-lua/pull/43
            std.chmod(
                "+x",
                { "extension/server/bin/macOS/lua-language-server", "extension/server/bin/Linux/lua-language-server" }
            ),
        },
        default_options = {
            cmd = {
                -- We need to provide a _full path_ to the executable (sumneko_lua uses it to determine... things)
                path.concat { root_dir, "extension", "server", "bin", bin_dir, "lua-language-server" },
                "-E",
                path.concat { root_dir, "extension", "server", "main.lua" },
            },
            settings = {
                Lua = {
                    diagnostics = {
                        -- Get the language server to recognize the `vim` global
                        globals = { "vim" },
                    },
                    workspace = {
                        -- Make the server aware of Neovim runtime files
                        library = {
                            [vim.fn.expand "$VIMRUNTIME/lua"] = true,
                            [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
                        },
                        maxPreload = 10000,
                    },
                },
            },
        },
    }
end