From e61c5752a13a953c8862ae961b8a775b59c968e3 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Thu, 15 Jun 2017 12:52:00 -0700 Subject: [PATCH] Add LSClientRestartServer command - 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. --- CHANGELOG.md | 3 ++- autoload/lsc/server.vim | 22 ++++++++++++++++++++-- plugin/lsc.vim | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de2b39d8..845c0a66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/autoload/lsc/server.vim b/autoload/lsc/server.vim index 17cd3324..80c82b07 100644 --- a/autoload/lsc/server.vim +++ b/autoload/lsc/server.vim @@ -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 RunCommand(g:lsc_server_commands[a:filetype]) - call lsc#file#trackAll(a:filetype) + call StartByCommand(g:lsc_server_commands[a:filetype]) +endfunction + +function! s:StartByCommand(command) abort + if 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 @@ -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 @@ -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 StartByCommand(a:command) + endif endfunction " Append to the buffer for the channel and try to consume a message. diff --git a/plugin/lsc.vim b/plugin/lsc.vim index c3ff14c4..fae4eb24 100644 --- a/plugin/lsc.vim +++ b/plugin/lsc.vim @@ -10,6 +10,7 @@ endif command! LSClientGoToDefinition call lsc#reference#goToDefinition() command! LSClientFindReferences call lsc#reference#findReferences() +command! LSClientRestartServer call IfEnabled('lsc#server#restart') " RegisterLanguageServer "