diff options
| author | Matthieu Coudron <mattator@gmail.com> | 2020-11-14 18:23:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-14 18:23:05 +0100 |
| commit | bd7127daf7129b0f81d44980825da54ec0461ebe (patch) | |
| tree | cff07455d7366bf2f976bd3d4836c8ae3cda9fa8 | |
| parent | [docgen] Update README.md (diff) | |
| parent | [docgen] Update README.md (diff) | |
| download | nvim-lspconfig-bd7127daf7129b0f81d44980825da54ec0461ebe.tar nvim-lspconfig-bd7127daf7129b0f81d44980825da54ec0461ebe.tar.gz nvim-lspconfig-bd7127daf7129b0f81d44980825da54ec0461ebe.tar.bz2 nvim-lspconfig-bd7127daf7129b0f81d44980825da54ec0461ebe.tar.lz nvim-lspconfig-bd7127daf7129b0f81d44980825da54ec0461ebe.tar.xz nvim-lspconfig-bd7127daf7129b0f81d44980825da54ec0461ebe.tar.zst nvim-lspconfig-bd7127daf7129b0f81d44980825da54ec0461ebe.zip | |
Merge pull request #238 from steelsojka/angular-ls
feat(angular-ls): add angular language service
| -rw-r--r-- | README.md | 25 | ||||
| -rw-r--r-- | lua/nvim_lsp/angularls.lua | 72 | ||||
| -rw-r--r-- | lua/nvim_lsp/configs.lua | 4 | ||||
| -rw-r--r-- | scripts/README_template.md | 2 |
4 files changed, 99 insertions, 4 deletions
@@ -233,7 +233,7 @@ nvim_lsp.SERVER.setup{config} the second parameter instead. Useful for doing buffer-local setup. {on_new_config} - `function(new_config)` will be executed after a new configuration has been + `function(new_config, new_root_dir)` will be executed after a new configuration has been created as a result of {root_dir} returning a unique value. You can use this as an opportunity to further modify the new_config or use it before it is sent to |vim.lsp.start_client()|. @@ -245,6 +245,7 @@ The following LSP configs are included. Follow a link to find documentation for that config. - [als](#als) +- [angularls](#angularls) - [bashls](#bashls) - [ccls](#ccls) - [clangd](#clangd) @@ -331,6 +332,28 @@ require'nvim_lsp'.als.setup{} root_dir = util.root_pattern("Makefile", ".git") ``` +## angularls + +https://github.com/angular/vscode-ng-language-service + +`angular-language-server` can be installed via `:LspInstall angularls` + +If you prefer to install this yourself you can through 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` + +Can be installed in Nvim with `:LspInstall angularls` + +```lua +require'nvim_lsp'.angularls.setup{} + + Commands: + + Default Values: + cmd = { "/home/runner/.cache/nvim/nvim_lsp/angularls/node_modules/.bin/angularls", "--stdio", "--tsProbeLocations", "", "--ngProbeLocations", "" } + filetypes = { "typescript", "html", "typescriptreact", "typescript.tsx" } + root_dir = root_pattern("angular.json", ".git") +``` + ## bashls https://github.com/mads-hartmann/bash-language-server diff --git a/lua/nvim_lsp/angularls.lua b/lua/nvim_lsp/angularls.lua new file mode 100644 index 00000000..88006f62 --- /dev/null +++ b/lua/nvim_lsp/angularls.lua @@ -0,0 +1,72 @@ +local configs = require 'nvim_lsp/configs' +local util = require 'nvim_lsp/util' + +local server_name = 'angularls' +local bin_name = server_name +local install_loc = util.base_install_dir .. '/' .. server_name +local script_loc = install_loc .. '/node_modules/@angular/language-server/index.js' +local bin_loc = install_loc .. '/node_modules/.bin/angularls' + +local installer = util.npm_installer { + server_name = server_name; + packages = { '@angular/language-server' }; + binaries = { bin_name }; + -- angular-language-service doesn't expose a binary, so we create an execution wrapper. + post_install_script = + 'echo "#! /bin/sh\n' .. 'node ' .. script_loc .. ' \\$*' .. '" > ' .. bin_loc .. '\n' .. + 'chmod +x ' .. bin_loc; +} + +-- 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 = { + bin_loc, + '--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 = { + bin_loc, + '--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 `:LspInstall angularls` + +If you prefer to install this yourself you can through 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` + ]]; + default_config = { + root_dir = [[root_pattern("angular.json", ".git")]]; + }; + } +} + +configs[server_name].install = installer.install +configs[server_name].install_info = installer.info diff --git a/lua/nvim_lsp/configs.lua b/lua/nvim_lsp/configs.lua index 8bbc6082..deca856e 100644 --- a/lua/nvim_lsp/configs.lua +++ b/lua/nvim_lsp/configs.lua @@ -126,10 +126,10 @@ function configs.__newindex(t, config_name, config_def) add_callbacks(new_config) if config_def.on_new_config then - pcall(config_def.on_new_config, new_config) + pcall(config_def.on_new_config, new_config, _root_dir) end if config.on_new_config then - pcall(config.on_new_config, new_config) + pcall(config.on_new_config, new_config, _root_dir) end new_config.on_init = util.add_hook_after(new_config.on_init, function(client, _result) diff --git a/scripts/README_template.md b/scripts/README_template.md index bb590cc1..311a9717 100644 --- a/scripts/README_template.md +++ b/scripts/README_template.md @@ -233,7 +233,7 @@ nvim_lsp.SERVER.setup{config} the second parameter instead. Useful for doing buffer-local setup. {on_new_config} - `function(new_config)` will be executed after a new configuration has been + `function(new_config, new_root_dir)` will be executed after a new configuration has been created as a result of {root_dir} returning a unique value. You can use this as an opportunity to further modify the new_config or use it before it is sent to |vim.lsp.start_client()|. |
