dev-resources.site
for different kinds of informations.
Avoid conflicts between denols and tsserver in Neovim
Published at
2/9/2024
Categories
neovim
typescript
lsp
deno
Author
davidecavaliere
Author
15 person written this
davidecavaliere
open
Recently I've been working on a project in a monorepo were I've got nodejs/typescript and deno projects. This is notoriously annoying because any ts
file will start both tsserver
and denols
language services.
If you've got here you know what I'm talking about π
I'm setting up my lsp with lspconfig
.
This is how denols
is configured
lspconfig.denols.setup({
root_dir = lspconfig.util.root_pattern("deno.json", "deno.jsonc"),
init_options = {
lint = true,
unstable = true,
suggest = {
imports = {
hosts = {
["https://deno.land"] = true,
["https://cdn.nest.land"] = true,
["https://crux.land"] = true,
},
},
},
},
on_attach = on_attach,
})
And this is the hack to avoid tsserver
to start on a file that belongs to a deno project.
spconfig.tsserver.setup({
on_attach = function (client, bufnr)
on_attach(client, bufnr);
vim.keymap.set('n', '<leader>ro', function()
vim.lsp.buf.execute_command({
command = "_typescript.organizeImports",
arguments = { vim.fn.expand("%:p") }
})
end, { buffer = bufnr, remap = false });
end,
root_dir = function (filename, bufnr)
local denoRootDir = lspconfig.util.root_pattern("deno.json", "deno.json")(filename);
if denoRootDir then
-- print('this seems to be a deno project; returning nil so that tsserver does not attach');
return nil;
-- else
-- print('this seems to be a ts project; return root dir based on package.json')
end
return lspconfig.util.root_pattern("package.json")(filename);
end,
single_file_support = false,
})
This leverage the fact that if root_dir
function returns nil
then lspconfig
wont's start a language service for that file. π
lsp Article's
30 articles in total
How to Setup Vim for Kotlin Development
read article
Managing LSPs in Neovim: Enable/Disable for the Entire Session
read article
Integrating the ruff language server
read article
Series Belajar Solid Principle - Liskov Substitution Principle (LSP)
read article
Avoid conflicts between denols and tsserver in Neovim
currently reading
Avoid conflicts between denols and tsserver in Neovim
read article
Implementing Payment Gateways with the Liskov Substitution Principle
read article
SOLID Principles: Liskov Substitution Principle (LSP)
read article
Configure Helix to use ElixirLS
read article
The Power of Liskov Substitution Principle in Improving Software Design
read article
Neovim config from scratch (Part II)
read article
Neovim config from scratch (Part I)
read article
Integrating a Language Server (LSP) in a VS Code Extension
read article
My Neovim setup for React, TypeScript, Tailwind CSS, etc
read article
How i setup neovim for speed up React, Js, Ts, etc
read article
Solve nvim lsp denols vs tsserver clash
read article
Perl Navigator - Language Server for Perl
read article
Neovim LSP Setup + Code Completion Engine
read article
NeoVim: init.lua, built in LSP e mais
read article
How to fix [deno-ts 2339] in the code for Deno Deploy
read article
SOLID e o princΓpio do 6 por meia dΓΊzia
read article
Java LSP in Sublime Text
read article
Neovim: Migrando do coc.vim para nvim-lsp
read article
Integrating Scala Metals with Doom Emacs using LSP on Pop!_OS/Ubuntu 20.04 LTS
read article
Builtin Solidity Language Server
read article
Liskov Substitution Principle
read article
Emacs as SQL client with LSP
read article
Vim Configuration from Minimal to Complete
read article
LSP and ISP: The LI of SOLID
read article
Go LSP in Sublime Text
read article
Featured ones: