Solve nvim lsp denols vs tsserver clash

_hariti

abdellah ht

Posted on June 5, 2022

Solve nvim lsp denols vs tsserver clash

Recently I started using Deno for some personal projects, and when I installed the Deno lsp client on neovim, it clashed with tsserver as it has no idea what Deno types are and some other annoying diagnostics.

The official documentation instructs you to specify the root_dir param in the server:setup(options), but I thought that was a lot of hassle as it would not work for when you don't have a Deno project, but have no package.json either.

My solution was to use a programmatic way to have fine grained control over when to start which. Basically when tsserver wants to start, it checks if denols is in the active clients (which you can get using vim.lsp.get_active_clients()) and not continue setup, and denols does the same check to see if tsserver is attached to a file that belongs to it and kills it.

here's the full snippet:

      local active_clients = vim.lsp.get_active_clients()
      if client.name == 'denols' then
        for _, client_ in pairs(active_clients) do
          -- stop tsserver if denols is already active
          if client_.name == 'tsserver' then
            client_.stop()
          end
        end
      elseif client.name == 'tsserver' then
        for _, client_ in pairs(active_clients) do
          -- prevent tsserver from starting if denols is already active
          if client_.name == 'denols' then
            client.stop()
          end
        end
      end
Enter fullscreen mode Exit fullscreen mode

I hope it saves you some time.

💖 💪 🙅 🚩
_hariti
abdellah ht

Posted on June 5, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related