diff options
| author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-11-24 23:01:07 -0500 |
|---|---|---|
| committer | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-11-25 23:46:21 -0500 |
| commit | 6c2fb86c6a03e20abea5ddd17d735885f0b7cb5e (patch) | |
| tree | 7f2bf25ca5456b23304295dba8fe0005e85a5c10 /lua/lspconfig/server_configurations/angularls.lua | |
| parent | fix: only set cmd_cwd if filepath exists (#1485) (diff) | |
| download | nvim-lspconfig-6c2fb86c6a03e20abea5ddd17d735885f0b7cb5e.tar nvim-lspconfig-6c2fb86c6a03e20abea5ddd17d735885f0b7cb5e.tar.gz nvim-lspconfig-6c2fb86c6a03e20abea5ddd17d735885f0b7cb5e.tar.bz2 nvim-lspconfig-6c2fb86c6a03e20abea5ddd17d735885f0b7cb5e.tar.lz nvim-lspconfig-6c2fb86c6a03e20abea5ddd17d735885f0b7cb5e.tar.xz nvim-lspconfig-6c2fb86c6a03e20abea5ddd17d735885f0b7cb5e.tar.zst nvim-lspconfig-6c2fb86c6a03e20abea5ddd17d735885f0b7cb5e.zip | |
feat: expose configs
Diffstat (limited to 'lua/lspconfig/server_configurations/angularls.lua')
| -rw-r--r-- | lua/lspconfig/server_configurations/angularls.lua | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lua/lspconfig/server_configurations/angularls.lua b/lua/lspconfig/server_configurations/angularls.lua new file mode 100644 index 00000000..8f98e700 --- /dev/null +++ b/lua/lspconfig/server_configurations/angularls.lua @@ -0,0 +1,67 @@ +local util = require 'lspconfig/util' + +-- 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()) + +return { + default_config = { + cmd = { + 'ngserver', + '--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 = { + 'ngserver', + '--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 -g @angular/language-server`. + +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 = {"ngserver", "--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")]], + }, + }, +} |
