How to set up Angular Language Service in Neovim

7.3k Views Asked by At

My setup at the moment looks like this:

local cwd = vim.fn.getcwd()
local project_library_path = cwd .. "/node_modules"

local cmd = {
    DATA_PATH .. "/lsp_servers/angularls/node_modules/@angular/language-server/bin/ngserver",
    "--ngProbeLocations",
    project_library_path,
    "--tsProbeLocations",
    project_library_path ,
    "--stdio",
}

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

On :LspInfo, I can see that the cmd is executable, but somehow it doesn't attach.

I have difficulty to differentiate @angular/language-server from @angular/language-service...

I am not sure what the tsProbeLocations and ngProbeLocations do and if my path is correct.

Finally, I red from Angular Language Service website and there isn't a good guideline for neovim. (except for coc-angular, but I don't use coc.)

3

There are 3 best solutions below

0
On

I had a similar setup and the same problem. Make sure that version of the installed language-server matches the major-version of the angular-version used in your project. That solved the issue for me:

npm -g uninstall @angular/language-server
npm -g install @angular/language-server@[the latest matching angular-version]  

With that, the standard lua require'lspconfig'.angularls.setup({}) should work without problems.

0
On

I used the default require'lspconfig'.angularls.setup{} for my lspconfig and also installed @angular/language-server as a dev dependency in the angular project and it worked.

With angular language server installed globally with npm and the default lspconfig, I also saw that the cmd is executable with no client attaching to the buffer.

0
On

Replace

local project_library_path = "/usr/lib/node_modules/@angular/language-server/"