Getting the vim angular language server working inside a NX monorepo

Getting the vim angular language server working inside a NX monorepo
Date
Tags
Vim
Nx
Lsp
Angular

The angular language server in vim acts up when started inside the NX monorepo. This can easily be solved.

When working on an Angular project inside an NX Monorepo, the angular language server has problems finding the root directory. This problem arises because the server relies on the presence of the “angular.json” file to determine the root directory. However, we can easily resolve this inconvenience by incorporating the “nx.json” file into the root directory pattern.

To address this matter effectively, we can utilize the NeoVim plugin called lsp-zero. Here’s an example of how to set it up:

local lsp = require("lsp-zero")
lsp.preset("recommended")

lsp.configure('angularls', {
  root_dir = require("lspconfig")["util"].root_pattern("angular.json", "nx.json")
})

lsp.setup()

Or if we are using LazyVim and nvim-lspconfig we can use the following configuration:

{
  "neovim/nvim-lspconfig",
  opts = {
    setup = {
      angularls = function(_, opts)
        opts.root_dir = require("lspconfig.util").root_pattern("angular.json", "nx.json")
        require("lspconfig").angularls.setup({ { server = opts } })
      end,
    },
  },
}

More Articles