From 9d9ad29a4bf422c7e8e3a80a0cf22e0a56f8f939 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Tue, 26 Jun 2018 21:29:48 +0800 Subject: [PATCH] Improve lang#typescript layer (#1870) * Improve lang#typescript layer * Improve lang#typescript layer * Use next branch of lsc * Update wiki --- autoload/SpaceVim/layers/lang/typescript.vim | 69 +++++++++++++++----- autoload/SpaceVim/layers/lsp.vim | 5 +- docs/cn/layers/lang/typescript.md | 9 +++ docs/layers/lang/typescript.md | 9 +++ wiki/en/Following-HEAD.md | 1 + 5 files changed, 73 insertions(+), 20 deletions(-) diff --git a/autoload/SpaceVim/layers/lang/typescript.vim b/autoload/SpaceVim/layers/lang/typescript.vim index 3f6bcded2..e8712f7b3 100644 --- a/autoload/SpaceVim/layers/lang/typescript.vim +++ b/autoload/SpaceVim/layers/lang/typescript.vim @@ -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 K :call SpaceVim#lsp#show_doc() + + 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 diff --git a/autoload/SpaceVim/layers/lsp.vim b/autoload/SpaceVim/layers/lsp.vim index 8110c7ff1..a3b393628 100644 --- a/autoload/SpaceVim/layers/lsp.vim +++ b/autoload/SpaceVim/layers/lsp.vim @@ -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 diff --git a/docs/cn/layers/lang/typescript.md b/docs/cn/layers/lang/typescript.md index 0882e8690..1a97e3e5a 100644 --- a/docs/cn/layers/lang/typescript.md +++ b/docs/cn/layers/lang/typescript.md @@ -12,6 +12,7 @@ lang: cn - [启用模块](#启用模块) - [功能特性](#功能特性) - [模块配置](#模块配置) +- [快捷键](#快捷键) @@ -42,7 +43,15 @@ npm install -g typescript - 类型图标标记 - 跳至定义处 - 查询函数引用 +- lsp 支持 ## 模块配置 `typescript_server_path`: 该模块选项可以设置 tsserver 的路径。 + +## 快捷键 + +| 快捷键 | 按键描述 | +| --------- | -------------------- | +| `SPC l d` | 显示相关文档 | +| `SPC l e` | 重命名光标函数或变量 | diff --git a/docs/layers/lang/typescript.md b/docs/layers/lang/typescript.md index 618f0ec58..f8f9b2ee1 100644 --- a/docs/layers/lang/typescript.md +++ b/docs/layers/lang/typescript.md @@ -11,6 +11,7 @@ description: "This layer is for TypeScript development" - [Install](#install) - [Features](#features) - [Layer configuration](#layer-configuration) +- [Key bindings](#key-bindings) @@ -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 | diff --git a/wiki/en/Following-HEAD.md b/wiki/en/Following-HEAD.md index 718172b0c..a9d471c86 100644 --- a/wiki/en/Following-HEAD.md +++ b/wiki/en/Following-HEAD.md @@ -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