67 lines
2.5 KiB
Lua
67 lines
2.5 KiB
Lua
--- @type LazyPluginSpec
|
|
return {
|
|
"pmizio/typescript-tools.nvim",
|
|
dependencies = {
|
|
"nvim-lua/plenary.nvim",
|
|
"neovim/nvim-lspconfig",
|
|
"hrsh7th/cmp-nvim-lsp",
|
|
},
|
|
event = { "BufReadPre", "BufNewFile" },
|
|
config = function()
|
|
local typescript_tools = require("typescript-tools")
|
|
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
|
|
|
local on_attach = require("taken.utils.on_attach")
|
|
local capabilities = cmp_nvim_lsp.default_capabilities()
|
|
local augroup = vim.api.nvim_create_augroup("Typescript_tools", {})
|
|
|
|
local cwd = vim.fn.getcwd()
|
|
local tsserver_path = cwd .. "/node_modules/.bin/tsserver"
|
|
|
|
local cmd = ""
|
|
if vim.loop.fs_stat(tsserver_path) then
|
|
cmd = tsserver_path
|
|
else
|
|
cmd = "typescript-language-server"
|
|
end
|
|
local prettier_config = vim.fn.glob(cwd .. "/*prettierrc*", false, true)
|
|
|
|
typescript_tools.setup({
|
|
capabilities = capabilities,
|
|
on_attach = function(client, bufnr)
|
|
on_attach(client, bufnr)
|
|
if cmd == "typescript-language-server" then
|
|
print("Using global tsserver")
|
|
end
|
|
if prettier_config == "" then
|
|
print("Using prettier to format")
|
|
return
|
|
else
|
|
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
group = augroup,
|
|
buffer = bufnr,
|
|
callback = function()
|
|
vim.lsp.buf.format({ async = false })
|
|
end,
|
|
})
|
|
end
|
|
end,
|
|
settings = {
|
|
cmd = { cmd, "--stdio" },
|
|
tsserver_file_preferences = {
|
|
includeInlayParameterNameHints = "all",
|
|
includeInlayParameterNameHintsWhenArgumentMatchesName = true,
|
|
includeInlayFunctionParameterTypeHints = true,
|
|
includeInlayVariableTypeHints = true,
|
|
includeInlayVariableTypeHintsWhenTypeMatchesName = true,
|
|
includeInlayPropertyDeclarationTypeHints = true,
|
|
includeInlayFunctionLikeReturnTypeHints = true,
|
|
includeInlayEnumMemberValueHints = true,
|
|
quotePreference = "auto",
|
|
},
|
|
},
|
|
})
|
|
end,
|
|
}
|