Skip to content

Commit

Permalink
fix(pack): fix typescript-tsserver-denols attaching
Browse files Browse the repository at this point in the history
Co-authored-by: Olivier Wittek <[email protected]>
  • Loading branch information
mehalter and owittek committed Apr 7, 2023
1 parent ca102a7 commit 9578b7c
Showing 1 changed file with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
return {
{ import = "astrocommunity.pack.typescript-tsserver" },
{ import = "astrocommunity.pack.typescript-denols" },
{
"jose-elias-alvarez/typescript.nvim",
opts = function()
local tsserver = require("astronvim.utils.lsp").config "tsserver"
tsserver.root_dir = require("lspconfig.util").root_pattern "package.json"
return { server = tsserver }
end,
},
{
"sigmasd/deno-nvim",
opts = function()
local denols = require("astronvim.utils.lsp").config "denols"
denols.root_dir = require("lspconfig.util").root_pattern("deno.json", "deno.jsonc")
return { server = denols }
opts = function(_, opts)
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local bufnr = args.buf
local curr_client = vim.lsp.get_client_by_id(args.data.client_id)
-- if deno attached, stop all typescript servers
if curr_client.name == "denols" then
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id)
if client.name == "tsserver" then vim.lsp.stop_client(client_id, true) end
end)
-- if tsserver attached, stop it if there is a denols server attached
elseif curr_client.name == "tsserver" then
for _, client in ipairs(vim.lsp.get_active_clients { bufnr = bufnr }) do
if client.name == "denols" then
vim.lsp.stop_client(curr_client.id, true)
break
end
end
end
end,
})
opts.server = require("astronvim.utils.lsp").config "denols"
opts.server.root_dir = require("lspconfig.util").root_pattern("deno.json", "deno.jsonc")
end,
},
{
"jay-babu/mason-null-ls.nvim",
config = function(_, opts)
local mason_null_ls = require "mason-null-ls"
local null_ls = require "null-ls"

mason_null_ls.setup(opts)
mason_null_ls.setup_handlers {
opts = {
handlers = {
prettierd = function()
local null_ls = require "null-ls"
null_ls.register(null_ls.builtins.formatting.prettierd.with {
condition = function(utils)
return utils.root_has_file "package.json"
Expand All @@ -35,7 +43,7 @@ return {
end,
})
end,
}
end,
},
},
},
}

0 comments on commit 9578b7c

Please sign in to comment.