Dev.to WebDev ๐Ÿ›  Dev ๐Ÿ‘ 0

How to add new TypeScript 7 LSP server to Neovim

Microsoft has released the stable version of their new TypeScript compiler written golang that is 10x faster than the previous TypeScript based implimentation on benchmarks. This also comes with the LSP server built in

How to add new TypeScript 7 LSP server to Neovim

Microsoft has released the stable version of their new TypeScript compiler written golang that is 10x faster than the previous TypeScript based implimentation on benchmarks.

This also comes with the LSP server built in and we can plug it into Neovim right now!

In this article, I will be showing how to plug it to the Neovim's built in LSP client.

Prerequisites

  1. Neovim v11 or above
  2. npm (or any other node package manager)

Steps

  1. Download and install the new typescript version from npm registry.
npm i -g typescript
  1. Check version. It should show v7.0.0 or above. (the new executable uses the name tsc)
tsc --version
  1. Add the server to the init.lua file or define it in a new file and import to init.lua.
-- define the LSP server
vim.lsp.config['tsc'] = {
    cmd = {'tsc', '--lsp', '--stdio'},
    filetypes = {'javascript', 'javascriptreact', 'typescript', 'typescriptreact'},
    root_markers = {'package.json', 'tsconfig.json', '.git'},
}

-- enable
vim.lsp.enable('tsc')
  1. Open up a TypeScript/JavaScript project and test.

Hover Action
Neovim Hover action using new typescript v7

Completions
Neovim autocompleteions with blinkcmp and typescript v7

  1. Upon exploring a huge codebase, you should feel the snapiness in goto definitions, references and completions popup.

Enjoy writing TypeScript!

๐Ÿ“ฐ Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.