Skip to content

Commit

Permalink
Add LSClientRestartServer command
Browse files Browse the repository at this point in the history
- Add s:StartByCommand function to start by command instead of filetype,
  and to iterated over open files for all filetypes tracked by the
  server.
- Add lsc#server#restart() to restart the server for the current
  filetype.
- Track commands with a requested restart in s:restart_commands and upon
  process exit start them again.
  • Loading branch information
natebosch committed Jun 15, 2017
1 parent 31a6e93 commit e61c575
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# 0.2.1-dev
# 0.2.1

- Handle language server restarts:
- Clean up local state when a language server exits.
- Call `didOpen` for all open files when a language server (re)starts.
- Add LSClientRestart command to restart the server for the current filetype.

# 0.2.0

Expand Down
22 changes: 20 additions & 2 deletions autoload/lsc/server.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ if !exists('s:initialized')
let s:running_servers = {}
let s:initialized_servers = []
let s:initialized = v:true
let s:restart_commands = []
endif

function! lsc#server#start(filetype) abort
if <SID>RunCommand(g:lsc_server_commands[a:filetype])
call lsc#file#trackAll(a:filetype)
call <SID>StartByCommand(g:lsc_server_commands[a:filetype])
endfunction

function! s:StartByCommand(command) abort
if <SID>RunCommand(a:command)
for filetype in keys(g:lsc_server_commands)
if g:lsc_server_commands[filetype] != a:command | continue | endif
call lsc#file#trackAll(filetype)
endfor
endif
endfunction

Expand All @@ -20,6 +28,11 @@ function! lsc#server#kill(file_type) abort
call lsc#server#call(a:file_type, 'exit', '')
endfunction

function! lsc#server#restart() abort
call add(s:restart_commands, g:lsc_server_commands[&filetype])
call lsc#server#kill(&filetype)
endfunction

" Call a method on the language server for `file_type`.
"
" Formats a message calling `method` with parameters `params`. If called with 4
Expand Down Expand Up @@ -118,6 +131,11 @@ function! s:OnCommandExit(command) abort
call lsc#diagnostics#clean(filetype)
call lsc#file#clean(filetype)
endfor
let restart = index(s:restart_commands, a:command)
if restart >= 0
call remove(s:restart_commands, restart)
call <SID>StartByCommand(a:command)
endif
endfunction

" Append to the buffer for the channel and try to consume a message.
Expand Down
1 change: 1 addition & 0 deletions plugin/lsc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ endif

command! LSClientGoToDefinition call lsc#reference#goToDefinition()
command! LSClientFindReferences call lsc#reference#findReferences()
command! LSClientRestartServer call <SID>IfEnabled('lsc#server#restart')

" RegisterLanguageServer
"
Expand Down

0 comments on commit e61c575

Please sign in to comment.