Skip to content

Angular language server extra functionality for Neovim LSP

License

Notifications You must be signed in to change notification settings

joeveiga/ng.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ng.nvim

Angular language server client for Neovim LSP. This extension adds extra commands exposed by vscode-ng-language-server, such as:

  • Go to template for component under cursor
  • Go to component(s) for template
  • Display template typecheck block

Kapture 2022-06-15 at 17 03 40

Getting started

Required dependencies

This extension WILL NOT config an angular language server (not yet, at least). If you use nvim-lspconfig you can follow these steps.

Installation

Using packer.nvim

use { 'joeveiga/ng.nvim'}

Usage

local opts = { noremap = true, silent = true }
local ng = require("ng");
vim.keymap.set("n", "<leader>at", ng.goto_template_for_component, opts)
vim.keymap.set("n", "<leader>ac", ng.goto_component_with_template_file, opts)
vim.keymap.set("n", "<leader>aT", ng.get_template_tcb, opts)

By default, both goto_component_with_template_file and goto_template_for_component will open the buffer in the same window where the command was executed, regardless of whether the target location is already open in a different window. If you want to jump to the existing window, you can pass the { reuse_window = true } option to the function:

-- ...
vim.keymap.set("n", "<leader>at", function()
  ng.goto_template_for_component({ reuse_window = true })
end, opts)

Here is an example of the difference in behavior:

Kapture 2024-04-30 at 23 21 00

FAQ

How can I restart the angular language service?

VSCode provides a Angular: Restart Angular Language Server command to restart the service. Unfortunately ng.nvim does not manage the lifecycle of the server at the moment. However, you can use nvim-lspconfig to accomplish this with the :LspRestart command.

Kapture 2022-06-15 at 21 59 23

Can I access the angular server logs?

I don't plan to support VSCode's Angular: Open Language Server Log command at the moment (at least not the functionality to automatically enable logging). PRs are welcome though ;). If you want to do this via lspconfig, you can add it to your angularls config cmd like so:

local cmd = {
 "ngserver",
 "--stdio",
 "--tsProbeLocations",
 "<typescript_path>",
 "--ngProbeLocations",
 "<angular_language_service_path>",
 -- THESE ARE THE RELEVANT OPTIONS
 "--logFile",
 "<path_to_logs>/nglangsvc.log",
 "--logVerbosity",
 "verbose" -- terse|normal|verbose|requestTime
}

lspconfig.angularls.setup({
 cmd = cmd,
 capabilities = capabilities,
 on_new_config = function(new_config, new_root_dir)
   new_config.cmd = cmd
 end
})

-- ...
-- you can then add a mapping to open the file
vim.keymap.set("n", "<leader>al", '<cmd>view <path_to_logs>/nglangsvc.log<cr>', opts)

Related Projects

About

Angular language server extra functionality for Neovim LSP

Topics

Resources

License

Stars

Watchers

Forks

Languages