Skip to content

Commit

Permalink
feat(typescript)!: replace typescript-tools with vtsls (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter authored May 24, 2024
1 parent a7dfa7b commit 300a8c6
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 53 deletions.
4 changes: 2 additions & 2 deletions lua/astrocommunity/pack/typescript-all-in-one/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ return {
if curr_client and curr_client.name == "denols" then
local clients = (vim.lsp.get_clients or vim.lsp.get_active_clients) {
bufnr = bufnr,
name = "typescript-tools",
name = "vtsls",
}
for _, client in ipairs(clients) do
vim.lsp.stop_client(client.id, true)
end
end

-- if tsserver attached, stop it if there is a denols server attached
if curr_client and curr_client.name == "typescript-tools" then
if curr_client and curr_client.name == "vtsls" then
if next((vim.lsp.get_clients or vim.lsp.get_active_clients) { bufnr = bufnr, name = "denols" }) then
vim.lsp.stop_client(curr_client.id, true)
end
Expand Down
4 changes: 2 additions & 2 deletions lua/astrocommunity/pack/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
This plugin pack does the following:

- Adds `typescript`, `javascript`, `tsx`, and `jsdoc` Treesitter parsers
- Adds `tsserver` and `vscode-eslint` language server
- Adds `vtsls` and `eslint` language server
- Adds `prettierd` formatter
- Adds [JSON language support](../json)
- Adds support for dap for JS
- Adds [typescript.nvim](https://github.com/jose-elias-alvarez/typescript.nvim) for language specific tooling
- Adds [nvim-vtsls](https://github.com/yioneko/nvim-vtsls) for language specific tooling
- Adds [package-info.nvim](https://github.com/vuki656/package-info.nvim) for project package management
- Adds [nvim-lsp-file-operations](https://github.com/antosha417/nvim-lsp-file-operations) to handles file imports on rename or move within neo-tree

Expand Down
115 changes: 66 additions & 49 deletions lua/astrocommunity/pack/typescript/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,58 @@ return {
end
end,
},
{
"AstroNvim/astrolsp",
---@type AstroLSPOpts
opts = {
autocmds = {
eslint_fix_on_save = {
cond = function(client) return client.name == "eslint" and vim.fn.exists ":EslintFixAll" > 0 end,
{
event = "BufWritePost",
desc = "Fix all eslint errors",
callback = function() vim.cmd.EslintFixAll() end,
},
},
},
---@diagnostic disable: missing-fields
config = {
vtsls = {
settings = {
typescript = {
updateImportsOnFileMove = { enabled = "always" },
inlayHints = {
parameterNames = { enabled = "all" },
parameterTypes = { enabled = true },
variableTypes = { enabled = true },
propertyDeclarationTypes = { enabled = true },
functionLikeReturnTypes = { enabled = true },
enumMemberValues = { enabled = true },
},
},
javascript = {
updateImportsOnFileMove = { enabled = "always" },
inlayHints = {
parameterNames = { enabled = "literals" },
parameterTypes = { enabled = true },
variableTypes = { enabled = true },
propertyDeclarationTypes = { enabled = true },
functionLikeReturnTypes = { enabled = true },
enumMemberValues = { enabled = true },
},
},
vtsls = {
enableMoveToFileCodeAction = true,
},
},
},
},
},
},
{
"williamboman/mason-lspconfig.nvim",
opts = function(_, opts)
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "tsserver", "eslint" })
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "vtsls", "eslint" })
end,
},
{
Expand Down Expand Up @@ -121,7 +169,7 @@ return {
opts = function(_, opts)
opts.ensure_installed = require("astrocore").list_insert_unique(
opts.ensure_installed,
{ "typescript-language-server", "eslint-lsp", "prettierd", "js-debug-adapter" }
{ "vtsls", "eslint-lsp", "prettierd", "js-debug-adapter" }
)
end,
},
Expand All @@ -132,59 +180,28 @@ return {
event = "BufRead package.json",
},
{
"pmizio/typescript-tools.nvim",
"yioneko/nvim-vtsls",
lazy = true,
dependencies = {
{
-- HACK: fix issue where `shiftwidth = 0` isn't correctly handled by typescript-tools.nvim
-- Remove when PR merged: https://github.com/pmizio/typescript-tools.nvim/pull/270
"AstroNvim/astrocore",
opts = function(_, opts)
local local_vim = opts.options
if local_vim.opt.shiftwidth == 0 then local_vim.opt.shiftwidth = local_vim.opt.tabstop end
end,
},
{
---@type AstroLSPOpts
"AstroNvim/astrolsp",
optional = true,
---@diagnostic disable: missing-fields
opts = {
autocmds = {
eslint_fix_on_save = {
cond = function(client) return client.name == "eslint" and vim.fn.exists ":EslintFixAll" > 0 end,
{
event = "BufWritePost",
desc = "Fix all eslint errors",
callback = function() vim.cmd.EslintFixAll() end,
},
},
},
handlers = { tsserver = false }, -- disable tsserver setup, this plugin does it
config = {
["typescript-tools"] = { -- enable inlay hints by default for `typescript-tools`
settings = {
tsserver_file_preferences = {
includeInlayParameterNameHints = "all",
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayVariableTypeHintsWhenTypeMatchesName = false,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
},
},
"AstroNvim/astrocore",
opts = {
autocmds = {
nvim_vtsls = {
{
event = "LspAttach",
desc = "Load nvim-vtsls with vtsls",
callback = function(args)
if assert(vim.lsp.get_client_by_id(args.data.client_id)).name == "vtsls" then
require("vtsls")._on_attach(args.data.client_id, args.buf)
vim.api.nvim_del_augroup_by_name "nvim_vtsls"
end
end,
},
},
},
},
},
ft = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx" },
-- get AstroLSP provided options like `on_attach` and `capabilities`
opts = function()
local astrolsp_avail, astrolsp = pcall(require, "astrolsp")
if astrolsp_avail then return astrolsp.lsp_opts "typescript-tools" end
end,
config = function(_, opts) require("vtsls").config(opts) end,
},
{
"dmmulroy/tsc.nvim",
Expand Down

0 comments on commit 300a8c6

Please sign in to comment.