local M = {} local typescript_filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx", } local function find_root(bufnr, markers) local filename = vim.api.nvim_buf_get_name(bufnr) local path = filename ~= "" and vim.fs.dirname(filename) or vim.uv.cwd() local marker = vim.fs.find(markers, { path = path, upward = true })[1] return marker and vim.fs.dirname(marker) or nil end local function deno_root(bufnr) return find_root(bufnr, { "deno.json", "deno.jsonc" }) end local function node_root(bufnr) -- A Deno project wins even when it also contains a package.json. if deno_root(bufnr) then return nil end return find_root(bufnr, { "package.json", "bun.lock", "bun.lockb", "bunfig.toml", "tsconfig.json", "jsconfig.json", }) end local function disable_formatting(client) -- Conform owns JS/TS formatting (oxfmt/prettier). client.server_capabilities.documentFormattingProvider = false client.server_capabilities.documentRangeFormattingProvider = false end M.vtsls = { filetypes = typescript_filetypes, root_dir = function(bufnr, on_dir) local root = node_root(bufnr) if root then on_dir(root) end end, on_attach = disable_formatting, settings = { vtsls = { autoUseWorkspaceTsdk = true, }, typescript = { inlayHints = { enable = true, includeInlayParameterNameHints = "all", includeInlayParameterNameHintsWhenArgumentMatchesName = false, includeInlayFunctionParameterTypeHints = true, includeInlayVariableTypeHints = true, includeInlayVariableTypeHintsWhenTypeMatchesName = false, includeInlayPropertyDeclarationTypeHints = true, includeInlayFunctionLikeReturnTypeHints = true, includeInlayEnumMemberValueHints = true, }, }, }, } M.denols = { filetypes = typescript_filetypes, root_dir = function(bufnr, on_dir) local root = deno_root(bufnr) if root then on_dir(root) end end, on_attach = disable_formatting, settings = { deno = { enable = true, lint = true, unstable = true, }, }, } return M