2023-06-21 23:44:34 +02:00
|
|
|
local lsp_present, lspconfig = pcall(require, "lspconfig")
|
|
|
|
|
|
|
|
if not lsp_present then
|
|
|
|
return
|
|
|
|
end
|
2023-02-11 02:36:46 +01:00
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
M.setup = function(opts)
|
2023-07-01 20:23:44 +02:00
|
|
|
lspconfig.astro.setup(opts)
|
2023-07-04 21:20:01 +02:00
|
|
|
lspconfig.cssls.setup(opts)
|
2023-06-22 01:13:57 +02:00
|
|
|
lspconfig.emmet_ls.setup(opts)
|
2023-06-21 23:44:34 +02:00
|
|
|
lspconfig.graphql.setup(vim.tbl_extend("keep", {
|
2023-03-17 09:23:43 +01:00
|
|
|
filetypes = {
|
|
|
|
"graphql",
|
|
|
|
"typescriptreact",
|
|
|
|
"javascriptreact",
|
|
|
|
"typescript",
|
|
|
|
},
|
2023-06-21 23:44:34 +02:00
|
|
|
}, opts))
|
2023-07-04 21:20:01 +02:00
|
|
|
lspconfig.html.setup(opts)
|
2023-06-21 23:44:34 +02:00
|
|
|
lspconfig.intelephense.setup(opts)
|
|
|
|
lspconfig.tailwindcss.setup(vim.tbl_extend("keep", {
|
2023-02-11 02:36:46 +01:00
|
|
|
filetypes = {
|
2023-07-01 20:23:44 +02:00
|
|
|
"astro",
|
2023-02-11 02:36:46 +01:00
|
|
|
"javascriptreact",
|
|
|
|
"typescriptreact",
|
|
|
|
"html",
|
|
|
|
"css",
|
|
|
|
},
|
2023-06-21 23:44:34 +02:00
|
|
|
}, opts))
|
|
|
|
|
2023-02-11 02:36:46 +01:00
|
|
|
-- attach tsserver only when there's a 'package.json' file in the CWD
|
2023-08-17 04:25:26 +02:00
|
|
|
require("typescript-tools").setup({
|
|
|
|
single_file_support = false,
|
|
|
|
root_dir = function(fname)
|
|
|
|
local root_dir = lspconfig.util.root_pattern("tsconfig.json")(fname)
|
|
|
|
|
|
|
|
-- this is needed to make sure we don't pick up root_dir inside node_modules
|
|
|
|
local node_modules_index = root_dir
|
|
|
|
and root_dir:find("node_modules", 1, true)
|
|
|
|
if node_modules_index and node_modules_index > 0 then
|
|
|
|
---@diagnostic disable-next-line: need-check-nil
|
|
|
|
root_dir = root_dir:sub(1, node_modules_index - 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
return root_dir
|
|
|
|
end,
|
|
|
|
settings = {
|
|
|
|
expose_as_code_action = {
|
|
|
|
"add_missing_imports",
|
|
|
|
"fix_all",
|
|
|
|
"remove_unused",
|
|
|
|
},
|
|
|
|
-- Nix silliness
|
|
|
|
-- stylua: ignore
|
|
|
|
tsserver_path = vim.fn.resolve(vim.fn.exepath("tsserver") .. "/../../lib/node_modules/typescript/bin/tsserver"),
|
|
|
|
},
|
|
|
|
})
|
2023-06-21 23:44:34 +02:00
|
|
|
|
2023-02-11 02:36:46 +01:00
|
|
|
-- attach deno only when there's a 'deps.ts' file in the CWD
|
2023-06-21 23:44:34 +02:00
|
|
|
lspconfig.denols.setup(vim.tbl_extend("keep", {
|
2023-08-17 04:25:26 +02:00
|
|
|
root_dir = lspconfig.util.root_pattern("deno.json", "deno.jsonc"),
|
2023-02-11 02:36:46 +01:00
|
|
|
single_file_support = false,
|
2023-06-21 23:44:34 +02:00
|
|
|
}, opts))
|
2023-02-11 02:36:46 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|