How do you configure an LSP to disable another LSP

For example, say I have the Svelte, Vue, or Ember/Glint language servers. They are all replacement for tsserver, and having tsserver running at the same time as each of those will cause duplicate diagnostics.

So, I’d like to configure each of these (I’ll PR to lspconfigs where I feel comfortable) to disable tsserver when they become active.

The VSCode folks have had similar desires:

I get close by doing this:

require('lspconfig').glint.setup {
  on_attach = function()
    for i, server in ipairs(vim.lsp.buf_get_clients()) do
      print(server.name)
      if server.name == 'tsserver' then
        vim.lsp.get_client_by_id(server.id).stop()
      end
    end
  end,
}

Unfortunately, it only works for the first buffer. When I open a second buffer, both tsserver and the glint server fire.:

   app/components/header.ts  2 
 │     Function lacks ending return statement and return type does not include 'undefined'. typescript (2366) [15, 15]
 │     Function lacks ending return statement and return type does not include 'undefined'. glint:ts(2366) [15, 15]
   app/components/map.ts  1 
 │     A 'get' accessor must return a value. glint:ts(2378) [15, 7]

i use plugin GitHub - windwp/nvim-projectconfig: neovim projectconfig.

add this on your projectconfig file

vim.g.list_of_lsp_server = { ‘svelte’ , …}

on your lspconfig you can check if that variable have value . you can start server on that list only and skip another server

remeber you need to call projectconfig.setup first before lspconfig

i use plugin

But as an ecosystem contributor, we’re looking to solve this problem for everyone using this server configuration / combination – not just trying to solve “our” problem.

The other JavaScript/TypeScript ecosystems would benefit from such server-config control as well. We know that we 100% do not need tsserver when X is active (per buffer (need to stipulate this because in monorepos, it’s totally reasonable to have two projects open, one using X and one with tsserver))