1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-02 22:20:06 +08:00

Improve lang#typescript layer (#1870)

* Improve lang#typescript layer

* Improve lang#typescript layer

* Use next branch of lsc

* Update wiki
This commit is contained in:
Wang Shidong 2018-06-26 21:29:48 +08:00 committed by GitHub
parent 2e6aac03df
commit 9d9ad29a4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 20 deletions

View File

@ -8,33 +8,66 @@
function! SpaceVim#layers#lang#typescript#plugins() abort
let plugins = []
call add(plugins, ['leafgarland/typescript-vim'])
let plugins = []
call add(plugins, ['leafgarland/typescript-vim'])
if !SpaceVim#layers#lsp#check_filetype('typescript')
if has('nvim')
call add(plugins, ['mhartington/nvim-typescript'])
call add(plugins, ['mhartington/nvim-typescript'])
else
call add(plugins, ['Quramy/tsuquyomi'])
call add(plugins, ['Quramy/tsuquyomi'])
endif
return plugins
endif
return plugins
endfunction
function! SpaceVim#layers#lang#typescript#config() abort
if !has('nvim')
autocmd FileType typescript setlocal omnifunc=tsuquyomi#complete
endif
if !has('nvim') && !SpaceVim#layers#lsp#check_filetype('typescript')
augroup SpaceVim_lang_typescript
autocmd!
autocmd FileType typescript setlocal omnifunc=tsuquyomi#complete
augroup END
endif
if SpaceVim#layers#lsp#check_filetype('typescript')
call SpaceVim#mapping#gd#add('typescript',
\ function('SpaceVim#lsp#go_to_def'))
endif
call SpaceVim#mapping#space#regesit_lang_mappings('javascript',
\ function('s:on_ft'))
endfunction
function! SpaceVim#layers#lang#typescript#set_variable(var) abort
if has('nvim')
let g:nvim_typescript#server_path =
\ get(a:var, 'typescript_server_path',
\ './node_modules/.bin/tsserver')
else
let tsserver_path = get(a:var, 'typescript_server_path', '')
if !empty(tsserver_path)
let g:tsuquyomi_use_dev_node_module = 2
let g:tsuquyomi_tsserver_path = tsserver_path
endif
if has('nvim')
let g:nvim_typescript#server_path =
\ get(a:var, 'typescript_server_path',
\ './node_modules/.bin/tsserver')
else
let tsserver_path = get(a:var, 'typescript_server_path', '')
if !empty(tsserver_path)
let g:tsuquyomi_use_dev_node_module = 2
let g:tsuquyomi_tsserver_path = tsserver_path
endif
endif
endfunction
function! s:on_ft() abort
if SpaceVim#layers#lsp#check_filetype('typescript')
nnoremap <silent><buffer> K :call SpaceVim#lsp#show_doc()<CR>
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'],
\ 'call SpaceVim#lsp#show_doc()', 'show_document', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'],
\ 'call SpaceVim#lsp#rename()', 'rename symbol', 1)
else
if has('nvim')
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'], 'TsDoc',
\ 'show document', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'], 'TSRename',
\ 'rename symbol', 1)
else
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'], 'TsuquyomiSignatureHelp',
\ 'show document', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'], 'TsuquyomiRenameSymbol',
\ 'rename symbol', 1)
endif
endif
endfunction

View File

@ -10,7 +10,7 @@ function! SpaceVim#layers#lsp#plugins() abort
let plugins = []
if has('nvim')
call add(plugins, ['SpaceVim/LanguageClient-neovim',
call add(plugins, ['autozimu/LanguageClient-neovim',
\ { 'merged': 0, 'if': has('python3') }])
else
call add(plugins, ['prabirshrestha/async.vim', {'merged' : 0}])
@ -92,7 +92,8 @@ let s:lsp_servers = {
\ 'python' : ['pyls'],
\ 'html' : ['html-languageserver', '--stdio'],
\ 'php' : ['php', g:spacevim_plugin_bundle_dir . 'repos/github.com/felixfbecker/php-language-server/bin/php-language-server.php'],
\ 'julia' : ['julia', '--startup-file=no', '--history-file=no', '-e', 'using LanguageServer; server = LanguageServer.LanguageServerInstance(STDIN, STDOUT, false); server.runlinter = true; run(server);']
\ 'julia' : ['julia', '--startup-file=no', '--history-file=no', '-e', 'using LanguageServer; server = LanguageServer.LanguageServerInstance(STDIN, STDOUT, false); server.runlinter = true; run(server);'],
\ 'typescript' : ['javascript-typescript-stdio']
\ }
function! SpaceVim#layers#lsp#set_variable(var) abort

View File

@ -12,6 +12,7 @@ lang: cn
- [启用模块](#启用模块)
- [功能特性](#功能特性)
- [模块配置](#模块配置)
- [快捷键](#快捷键)
<!-- vim-markdown-toc -->
@ -42,7 +43,15 @@ npm install -g typescript
- 类型图标标记
- 跳至定义处
- 查询函数引用
- lsp 支持
## 模块配置
`typescript_server_path`: 该模块选项可以设置 tsserver 的路径。
## 快捷键
| 快捷键 | 按键描述 |
| --------- | -------------------- |
| `SPC l d` | 显示相关文档 |
| `SPC l e` | 重命名光标函数或变量 |

View File

@ -11,6 +11,7 @@ description: "This layer is for TypeScript development"
- [Install](#install)
- [Features](#features)
- [Layer configuration](#layer-configuration)
- [Key bindings](#key-bindings)
<!-- vim-markdown-toc -->
@ -41,7 +42,15 @@ npm install -g typescript
- type-signature
- goto definition
- refernce finder
- lsp support
## Layer configuration
`typescript_server_path`: set the path of the tsserver.
## Key bindings
| key binding | Description |
| ----------- | ------------------ |
| `SPC l d` | show documentation |
| `SPC l e` | rename symbol |

View File

@ -11,6 +11,7 @@ The next release is v0.9.0.
- Add `SPC b b ` key binding in fzf layer ([#1725](https://github.com/SpaceVim/SpaceVim/pull/1725))
- Add test for toml, number, file, icon and highlight API ([#1849](https://github.com/SpaceVim/SpaceVim/pull/1849))
- Add lsp support for julia ([#1850](https://github.com/SpaceVim/SpaceVim/pull/1850))
- Add lsp support for typescript ([#1870](https://github.com/SpaceVim/SpaceVim/pull/1870))
### Changed