nvim-lspconfig icon indicating copy to clipboard operation
nvim-lspconfig copied to clipboard

feat(ts_ls)!: rename `tsserver` to `ts_ls`

Open ofseed opened this issue 1 year ago • 9 comments

tsserver cannot be used as an abbreviation for typescript-language-server, because there is tsserver already and it is completely different from typescript-language-server. This is misleading.

As the README of typescript-language-server says, it's a wrapper of tsserver. This abuse has been around for so many time in lspconfig that people don't realize they are two different things, and are then confused by replacements of typescript-language-server like typescript-tools.nvim and vtsls.

ofseed avatar Jul 12 '24 11:07 ofseed

Note that server_configurations.md or server_configurations.txt will be regenerated by the docgen CI process. Edit the Lua source file instead. For details on generating documentation, see: https://github.com/neovim/nvim-lspconfig/blob/master/CONTRIBUTING.md#generating-docs

github-actions[bot] avatar Jul 12 '24 11:07 github-actions[bot]

Now the server_configuration.md is generated, not manually edited.

ofseed avatar Jul 12 '24 11:07 ofseed

@glepnir Could you please review it?

ofseed avatar Jul 15 '24 12:07 ofseed

https://github.com/search?q=lspconfig.tsserver&type=code

quick search it has 5.6k files.. so hasty merge will only result in a lot of complaints. best approach is to popup a notify and keep it available and remove it in the next release.

glepnir avatar Jul 15 '24 12:07 glepnir

best approach is to popup a notify and keep it available and remove it in the next release.

It does, you can see in there, the snippet redirects tsserver to ts_ls and notify tsserver is outdated, will not break users' configuration brutally.

But considering your search result, I will do extra PR for mason.nvim and mason-lspconfig.nvim, and then we can merge them as much as possible at the same time so that most of the users who use mason will not be affected. I will let you know when my PR for mason and mason-lspconfig is ready.

ofseed avatar Jul 15 '24 14:07 ofseed

Could just wait for https://github.com/microsoft/TypeScript/issues/39459 to be resolved and then do something about it then.

polyzen avatar Jul 16 '24 02:07 polyzen

@polyzen Not that related. There are two points I want to emphasize.

  1. Changing the name will not break users' configurations, lspconfig.tsserver.setup{} is still valid and will only have a warning that tsserver is deprecated suggest using ts_ls instead. In fact, we've already done that for lua_ls, formerly called sumneko_lua, which I think most neovim users will setup no matter what language they are mainly writing. The breaking change should not be that painful.

  2. One of the reasons for creating this PR is to prepare the issue you linked to be resolved. If we do not merge this PR and then merge it after the real tsserver implements LSP, the name tsserver will refer to a different thing after that. That is, tsserver in lspconfig is formerly to be typescript-language-server, but then be the real tsserver. This will cause the meaning of lspconfig.tsserver.setup changed silently, and users' configurations will setup the real tsserver, not typescript-language-server. It should be very difficult for users to find out what happened.

ofseed avatar Jul 16 '24 03:07 ofseed

seems like lsp-mode also use ts_ls.. but I'm wondering if this abbreviation is appropriate. How about typescript_ls? ts is a bit ambiguous.

glepnir avatar Jul 16 '24 12:07 glepnir

Keep my recommendation still. ts in the editor area could be tree-sitter or TypeScript, but in the context of Language Server Protocol, I think it will not be confused with tree-sitter, what's more, the former name tsserver using ts as an abbreviation of TypeScript and ts is a well-known abbreviation for its developers. Honestly, the naming of these servers in lspconfig is a mess, foo language server sometimes be foo_ls and sometimes be foo_language_server, I prefer a shorter name if we could name it, otherwise choose the typescript_language_server to make it the same with the repository name.

ofseed avatar Jul 16 '24 15:07 ofseed

Well reasoned. Thank you

justinmk avatar Sep 05 '24 08:09 justinmk

So, umm guys, I now get "tsserver is deprecated, use ts_ls instead" in my neovim after updating. How can I fix this? Do I need to edit some config file and change the name to ts_ls or what? I am asking this because mason doesn't have a separate ts_ls option to install within it.

SannanOfficial avatar Sep 05 '24 09:09 SannanOfficial

No idea about mason. Wherever you set "tsserver", change that to "ts_ls".

justinmk avatar Sep 05 '24 09:09 justinmk

So, umm guys, I now get "tsserver is deprecated, use ts_ls instead" in my neovim after updating. How can I fix this? Do I need to edit some config file and change the name to ts_ls or what? I am asking this because mason doesn't have a separate ts_ls option to install within it.

I was also blindsided by this. Here's what I did ( not the full config but you can see how I handle the name change ):

	{
		"williamboman/mason.nvim",
		dependencies = {
			"williamboman/mason-lspconfig.nvim",
			"neovim/nvim-lspconfig",
			"hrsh7th/nvim-cmp",
		},
		config = function()
			require("mason").setup()
			require("mason-lspconfig").setup({
				ensure_installed = {
					"lua_ls",
					"pyright",
					"ruff_lsp",
					"tsserver",
					"eslint",
					"tailwindcss",
					"emmet_language_server",
					"jsonls",
				},
			})

			require("mason-lspconfig").setup()

			-- automatically install ensure_installed servers
			require("mason-lspconfig").setup_handlers({
				-- Will be called for each installed server that doesn't have
				-- a dedicated handler.
				--
				function(server_name) -- default handler (optional)
					-- https://github.com/neovim/nvim-lspconfig/pull/3232
					if server_name == "tsserver" then
						server_name = "ts_ls"
					end
					local capabilities = require("cmp_nvim_lsp").default_capabilities()
					require("lspconfig")[server_name].setup({

						capabilities = capabilities,
					})
				end,
			})

ic-768 avatar Sep 05 '24 09:09 ic-768

@ic-768 Thanks a lot, that was very swift of you, and I will go ahead and give that a try.

SannanOfficial avatar Sep 05 '24 09:09 SannanOfficial

Why not just change the "tsserver" item in ensure_installed to "ts_ls" ?

justinmk avatar Sep 05 '24 09:09 justinmk

Why not just change the "tsserver" item in ensure_installed to "ts_ls" ?

Because that would tell mason to install the ts_ls package and no such package exists. It only has tsserver

ic-768 avatar Sep 05 '24 09:09 ic-768

@ic-768 Hey, I tried to use your code, but I still get the same warning on startup, "tsserver is deprecated, use ts_ls instead", while I can see that tsserver is actually renamed to ts_ls regardless, because it actually says, "Configured servers: { "cssls", "css_variables", "pylsp", "ts_ls" }". Also, there's an error now that says, "/home/sannan/.config/nvim/lua/config/lsp_zero.lua:28: attempt to call field 'setup' (a nil value)" which is quite weird.

Any idea what I might be doing wrong here?

SannanOfficial avatar Sep 05 '24 09:09 SannanOfficial

@SannanOfficial I don't use lsp_zero and I'm not getting any errors, so there might be some conflict with that plugin that needs fixing?

ic-768 avatar Sep 05 '24 09:09 ic-768

@ic-768 Perhaps, I will look into it. Thanks for the help.

SannanOfficial avatar Sep 05 '24 09:09 SannanOfficial

Originally, I planned to change the package name in mason-registry so that we could merge without many breaking changes, but I noticed a lot of pending pull requests in its repo (maybe the maintainer is busy now) so I did not.

Whenever you have a problem that is difficult to solve, I recommend switching to vtsls. You will have almost the same experience because they are both tsserver under the hood. On top of this, if you installed nvim-vtsls, you could get extra commands that typescript-language-server does not provide.

ofseed avatar Sep 05 '24 10:09 ofseed

@ofseed Spent about an hour trying to get this to work for me, but couldn't for now. So I will try and switch to vtsls as you suggested for the time being. Thanks.

Edit: vtsls works, thanks again.

SannanOfficial avatar Sep 05 '24 11:09 SannanOfficial

if server_name == "tsserver" then
    server_name = "ts_ls"
end

Just came across this but you can also just use a simple one-liner to do the same thing:

server_name = server_name == 'tsserver' and 'ts_ls' or server_name

aw1875 avatar Sep 05 '24 14:09 aw1875

cd ~/.local/share/nvim/lazy/nvim-lspconfig git checkout HEAD~1

jepeake avatar Sep 05 '24 21:09 jepeake

temporary fix for vim-plug users:

require('mason').setup()
require('mason-lspconfig').setup({
  ensure_installed = {'tsserver','pyright', 'jsonls', 'rust_analyzer'},
  handlers = {
    -- lsp_zero.default_setup,
    function(server_name)
      if server_name == 'tsserver' then
        server_name = 'ts_ls'
      else
        lsp_zero.default_setup(server_name)
      end
    end
  },
})

emanuele-em avatar Sep 06 '24 08:09 emanuele-em