fix(nvim): deno/typescript-tools compat

This commit is contained in:
winston 2023-08-17 04:25:26 +02:00
parent 179e7b2dc9
commit 0bdfb3c0bc
Signed by: winston
GPG key ID: 3786770EDBC2B481
2 changed files with 29 additions and 7 deletions

View file

@ -53,10 +53,10 @@
nodePackages.graphql
nodePackages.graphql-language-service-cli
nodePackages.intelephense
nodePackages.typescript
nodePackages.typescript-language-server
nodePackages.vscode-langservers-extracted
nodePackages.yaml-language-server
yarn
# rust
cargo
@ -85,6 +85,7 @@
# needed for some plugin build steps
gnumake
unzip
yarn
];
};

View file

@ -31,15 +31,36 @@ M.setup = function(opts)
}, opts))
-- attach tsserver only when there's a 'package.json' file in the CWD
require("typescript-tools").setup({ on_attach = opts.on_attach })
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"),
},
})
-- attach deno only when there's a 'deps.ts' file in the CWD
lspconfig.denols.setup(vim.tbl_extend("keep", {
root_dir = lspconfig.util.root_pattern(
"deno.json",
"deno.jsonc",
"deps.ts"
),
root_dir = lspconfig.util.root_pattern("deno.json", "deno.jsonc"),
single_file_support = false,
}, opts))
end