mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-13 13:10:39 +08:00
Add language server configuration for JavaScript
* Add APIs for register server commands for LSP * Add server command for JavaScript language server * Add a new layer option `use_lsp` for layer `javascript` * Update key mappings for Javascript
This commit is contained in:
parent
e49787ecf0
commit
df4101e8fd
@ -5,22 +5,29 @@ 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')
|
||||
let s:auto_fix = get(a:var, 'auto_fix', 0)
|
||||
endfunction
|
||||
|
||||
@ -34,9 +41,16 @@ 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 && executable('javascript-typescript-stdio')
|
||||
call SpaceVim#lsp#reg_server('javascript', ['javascript-typescript-stdio'])
|
||||
call SpaceVim#mapping#gd#add('javascript', function('s: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 +66,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 +79,34 @@ 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 LanguageClient_textDocument_hover()<CR>
|
||||
|
||||
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'],
|
||||
\ 'call LanguageClient_textDocument_hover()', 'show_document', 1)
|
||||
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'],
|
||||
\ 'call LanguageClient_textDocument_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:lsp_go_to_def() abort
|
||||
if exists('*LanguageClient_textDocument_definition')
|
||||
call LanguageClient_textDocument_definition()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
||||
|
10
autoload/SpaceVim/lsp.vim
Normal file
10
autoload/SpaceVim/lsp.vim
Normal file
@ -0,0 +1,10 @@
|
||||
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
|
||||
|
||||
" vi: et sw=2 cc=80
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user