Skip to content
sciencesakura edited this page May 10, 2021 · 16 revisions

TypeScript

The typescript-language-server is capable of giving intelligent LSP functionality for both TypeScript and JavaScript. This will show you how to set things up for TypeScript. See JavaScript for details on how to set up the typescript-language-server for JavaScript.

Installing server

Note: tsserver is searched in workspace node_modules followed by global install. Use -g to install globally.

npm install -g typescript typescript-language-server

Once the typescript-language-server is installed, you can register the typescript-language-server in your .vimrc

Registering in .vimrc

Here's an example that shows how to manually setup a language server for TypeScript.

if executable('typescript-language-server')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'typescript-language-server',
        \ 'cmd': {server_info->[&shell, &shellcmdflag, 'typescript-language-server --stdio']},
        \ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'tsconfig.json'))},
        \ 'whitelist': ['typescript', 'typescript.tsx', 'typescriptreact'],
        \ })
endif