-
Notifications
You must be signed in to change notification settings - Fork 309
Servers TypeScript
Ryan Olson edited this page May 10, 2018
·
16 revisions
Note: tsserver is searched in workspace node_modules followed by global install. Use -g to install globally.
npm install -g typescript typescript-language-serverOnce the typescript-language-server is installed, you can either:
- Install vim-lsp-typescript OR
- Register the
typescript-language-serveryourself in your .vimrc
Installing vim-lsp-typescript
If you'd like the vim-lsp-typescript plugin to register the typescript-language-server for you, install the vim-lsp-typescript plugin:
" After vim-lsp, etc
Plug 'ryanolsonx/vim-lsp-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'],
\ })
endifJavaScript is TypeScript, so the language server would provide you with some utility for JavaScript projects as well.
Since the .tsconfig.json file is missing you can set it up the following way:
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_directory(lsp#utils#get_buffer_path(), '.git/..'))},
\ 'whitelist': ['typescript', 'javascript', 'javascript.jsx']
\ })
endif