1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-04-13 12:30:40 +08:00

Merge branch 'feature/js-lsp' into feature/haskell-lsp

This commit is contained in:
Seong Yong-ju 2017-12-09 17:57:53 +09:00
commit 9c5fddeb98
4 changed files with 68 additions and 20 deletions

View File

@ -5,22 +5,30 @@ function! SpaceVim#layers#lang#javascript#plugins() abort
\ ['othree/es.next.syntax.vim', { 'on_ft' : 'javascript' }],
\ ['othree/javascript-libraries-syntax.vim', { 'on_ft' : ['javascript', 'coffee', 'ls', 'typescript'] }],
\ ['MaxMEllon/vim-jsx-pretty', { 'on_ft' : 'javascript' }],
\ ['ternjs/tern_for_vim', { 'on_ft' : 'javascript', 'build' : 'npm install' }],
\ ['Galooshi/vim-import-js', { 'on_ft' : 'javascript', 'build' : 'npm install -g import-js' }],
\ ['maksimr/vim-jsbeautify', { 'on_ft' : 'javascript' }],
\ ['mmalecki/vim-node.js', { 'on_ft' : 'javascript' }],
\ ]
if has('nvim')
call add(plugins,['carlitux/deoplete-ternjs', { 'on_ft' : ['javascript'] }])
if !s:use_lsp
call add(plugins, ['ternjs/tern_for_vim', {
\ 'on_ft': 'javascript', 'build' : 'npm install' }])
if has('nvim')
call add(plugins, ['carlitux/deoplete-ternjs', { 'on_ft': [
\ 'javascript'] }])
endif
endif
return plugins
endfunction
let s:use_lsp = 0
let s:auto_fix = 0
function! SpaceVim#layers#lang#javascript#set_variable(var) abort
let s:use_lsp = get(a:var, 'use_lsp', 0) && has('nvim')
\ && executable('javascript-typescript-stdio')
let s:auto_fix = get(a:var, 'auto_fix', 0)
endfunction
@ -34,9 +42,17 @@ function! SpaceVim#layers#lang#javascript#config() abort
let g:vim_jsx_pretty_colorful_config = 1
" }}}
call SpaceVim#mapping#gd#add('javascript', function('s:gotodef'))
call SpaceVim#plugins#runner#reg_runner('javascript', 'node %s')
call SpaceVim#mapping#space#regesit_lang_mappings('javascript', funcref('s:language_specified_mappings'))
call SpaceVim#mapping#space#regesit_lang_mappings('javascript',
\ funcref('s:on_ft'))
if s:use_lsp
call SpaceVim#lsp#reg_server('javascript', ['javascript-typescript-stdio'])
call SpaceVim#mapping#gd#add('javascript',
\ function('SpaceVim#lsp#go_to_def'))
else
call SpaceVim#mapping#gd#add('javascript', function('s:tern_go_to_def'))
endif
if s:auto_fix
" Only use eslint
@ -52,12 +68,7 @@ function! SpaceVim#layers#lang#javascript#config() abort
endif
endfunction
function! s:language_specified_mappings() abort
" ternjs/tern_for_vim {{{
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'], 'TernDoc', 'Look up the documentation of something', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'], 'TernRename', 'Rename the variable under the cursor', 1)
" }}}
function! s:on_ft() abort
" Galooshi/vim-import-js {{{
nnoremap <silent><buffer> <F4> :ImportJSWord<CR>
nnoremap <silent><buffer> <Leader>ji :ImportJSWord<CR>
@ -70,14 +81,28 @@ function! s:language_specified_mappings() abort
inoremap <silent><buffer> <C-j>g <Esc>:ImportJSGoto<CR>a
" }}}
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'r'], 'call SpaceVim#plugins#runner#open()', 'execute current file', 1)
if s:use_lsp
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
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'], 'TernDoc',
\ 'show document', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'], 'TernRename',
\ 'rename symbol', 1)
endif
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'r'],
\ 'call SpaceVim#plugins#runner#open()', 'execute current file', 1)
endfunction
function! s:gotodef() abort
function! s:tern_go_to_def() abort
if exists(':TernDef')
TernDef
endif
endfunction
" vim:set et sw=2 cc=80:
" vi: et sw=2 cc=80

View File

@ -58,7 +58,7 @@ function! SpaceVim#layers#lsp#config() abort
let g:LanguageClient_diagnosticsDisplay[4].signTexthl = 'ALEInfoSign'
endif
let g:LanguageClient_autoStart = 0
let g:LanguageClient_autoStart = 1
" }}}
endfunction

22
autoload/SpaceVim/lsp.vim Normal file
View File

@ -0,0 +1,22 @@
scriptencoding utf-8
" lsp.vim
" author: Seong Yong-ju ( @sei40kr )
function! SpaceVim#lsp#reg_server(ft, cmds) abort
let g:LanguageClient_serverCommands[a:ft] = copy(a:cmds)
endfunction
function! SpaceVim#lsp#show_doc() abort
call LanguageClient_textDocument_hover()
endfunction
function! SpaceVim#lsp#go_to_def() abort
call LanguageClient_textDocument_definition()
endfunction
function! SpaceVim#lsp#rename() abort
call LanguageClient_textDocument_rename()
endfunction
" vi: et sw=2 cc=80

View File

@ -7,10 +7,10 @@ description: "This layer is for JaveScript development"
<!-- vim-markdown-toc GFM -->
- [Description](#description)
- [Layer Installation](#layer-installation)
- [Features](#features)
- [Layer configuration](#layer-configuration)
* [Description](#description)
* [Layer Installation](#layer-installation)
* [Features](#features)
* [Layer configuration](#layer-configuration)
<!-- vim-markdown-toc -->
@ -31,6 +31,7 @@ To use this configuration layer, add `call SpaceVim#layers#load('lang#javascript
## Layer configuration
`use_lsp`: Use language server if possible. The default value is `0`.
`auto_fix`: auto fix problems when save files, disabled by default. if you need this feature, you can load this layer via:
```vim