aboutsummaryrefslogtreecommitdiffstats
path: root/lua/lspconfig/angularls.lua
blob: 04525ec7d0c36aadb1ba636120b553310bcc7628 (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
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'

local server_name = 'angularls'

-- 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

local default_probe_dir = get_probe_dir(vim.fn.getcwd())

configs[server_name] = {
  default_config = {
    cmd = {
      'angularls',
      '--stdio',
      '--tsProbeLocations', default_probe_dir,
      '--ngProbeLocations', default_probe_dir
    };
    filetypes = {'typescript', 'html', 'typescriptreact', 'typescript.tsx'};
    -- Check for angular.json or .git first since that is the root of the project.
    -- Don't check for tsconfig.json or package.json since there are multiple of these
    -- in an angular monorepo setup.
    root_dir = util.root_pattern('angular.json', '.git');
  };
  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 = {
      'angularls',
      '--stdio',
      '--tsProbeLocations', new_probe_dir,
      '--ngProbeLocations', new_probe_dir
    }
  end;
  docs = {
    description = [[
https://github.com/angular/vscode-ng-language-service

`angular-language-server` can be installed via npm `npm install @angular/language-server`.
Be aware there is no global binary and must be run via `node_modules/@angular/language-server/index.js` which can be added as the default cmd.

Note, that if you override the default `cmd`, you must also update `on_new_config` to set `new_config.cmd` during startup.

```lua
local project_library_path = "/path/to/project/lib"
local cmd = {"node", "/path/to/node_modules/@angular/language-server/index.js", "--stdio", "--tsProbeLocations", project_library_path , "--ngProbeLocations", project_library_path}

require'lspconfig'.angularls.setup{
  cmd = cmd,
  on_new_config = function(new_config,new_root_dir)
    new_config.cmd = cmd
  end,
}
```
    ]];
    default_config = {
      root_dir = [[root_pattern("angular.json", ".git")]];
    };
  }
}