aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/servers/angularls/init.lua
blob: 5a545cd2752b8e5582cec4cda510d053f155e252 (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
local util = require "lspconfig/util"
local server = require "nvim-lsp-installer.server"
local npm = require "nvim-lsp-installer.installers.npm"

-- Angular requires a node_modules directory to probe for @angular/language-service and typescript
-- in order to use your projects configured versions.
-- This defaults to the vim cwd, but will get overwritten by the resolved root of the file.
local function get_probe_dir(root_dir)
    local project_root = util.find_node_modules_ancestor(root_dir)

    return project_root and (project_root .. "/node_modules") or ""
end

return function(name, root_dir)
    local default_probe_dir = get_probe_dir(vim.fn.getcwd())
    local executable_path = npm.executable(root_dir, "ngserver")

    return server.Server:new {
        name = name,
        root_dir = root_dir,
        homepage = "https://angular.io/guide/language-service",
        installer = npm.packages { "@angular/language-server" },
        default_options = {
            cmd = {
                executable_path,
                "--stdio",
                "--tsProbeLocations",
                default_probe_dir,
                "--ngProbeLocations",
                default_probe_dir,
            },
            on_new_config = function(new_config, new_root_dir)
                local new_probe_dir = get_probe_dir(new_root_dir)

                -- We need to check our probe directories because they may have changed.
                new_config.cmd = {
                    executable_path,
                    "--stdio",
                    "--tsProbeLocations",
                    new_probe_dir,
                    "--ngProbeLocations",
                    new_probe_dir,
                }
            end,
        },
    }
end