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
I hope it saves you some time.
Top comments (6)
Made an account just to say thanks!
I dumped this into my
on_attach
and so far it's working beautifully!Very new to nvim so I'm not sure if there's a better way to handle
tsserver
anddenols
conflicts by now, but I'd love to hear it if there is :)I just hacked it after a long google search with no satisfying results
There could be a better solution for this
Thank you for posting this. It helped me much!
Combining @beck 's solution, my code is like this:
This is why I love the internet
I think I found a better approach π
dev.to/davidecavaliere/avoid-confl...
Thanks for this!