autozimu / LanguageClient-neovim

Language Server Protocol (LSP) support for vim and neovim.
MIT License
3.55k stars 272 forks source link

`:LanguageClientStop` or `:call LanguageClient#exit()` not killing language server process #390

Closed TylerLeonhardt closed 6 years ago

TylerLeonhardt commented 6 years ago

Summary

For the PowerShell language server, "PowerShell Editor Services", it runs a powershell script that starts the language server in a powershell instance. (see below init.vim for details) When :LanguageClientStop or :call LanguageClient#exit() get called, that powershell process hangs around leading to stray processes.

LanguageClient-neovim should kill these processes when calling Stop or Exit.

Reproduction

init.vim

call plug#begin('~/.local/share/nvim/plugged')

Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'autozimu/LanguageClient-neovim', {
        \ 'branch': 'next',
        \ 'do': 'bash install.sh',
        \ }
Plug 'sheerun/vim-polyglot'
"Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
"let g:deoplete#enable_at_startup = 1
Plug 'roxma/nvim-completion-manager'
call plug#end()

"LanguageServerProtocol setup
"required for operations modifying multiple buffers like rename.
set hidden

"note call to powershell (pwsh)
let g:LanguageClient_serverCommands = {
    \ 'ps1': ['pwsh', '~/Desktop/PowerShellEditorServices/module/Start-EditorServices.ps1', '-HostName', 'nvim', '-HostProfileId', '0', '-HostVersion', '1.0.0', '-EditorServicesVersion', '1.6.0', '-LogPath', '~/Desktop/pses.log.txt', '-LogLevel', 'Diagnostic', '-BundledModulesPath', '~/Desktop/PowerShellEditorServices/module', '-Stdio', '-SessionDetailsPath', '~/Desktop/.pses_session']
    \ }
let g:LanguageClient_loggingLevel = 'DEBUG'

autocmd FileType ps1 call VsimEnableLanguageServerKeys()
function! VsimEnableLanguageServerKeys()
        " TODO hover with timer
        nnoremap <silent> <S-K> :call LanguageClient_textDocument_hover()<CR>
        nnoremap <silent> <F2> :call LanguageClient_textDocument_rename()<CR>
        nnoremap <silent> gd :call LanguageClient_textDocument_definition()<CR>
        nnoremap <silent> <F12> :call LanguageClient_textDocument_definition()<CR>
        set formatexpr=LanguageClient_textDocument_rangeFormatting()
        vnoremap = :call LanguageClient_textDocument_rangeFormatting()<CR>
        nnoremap <C-k><C-r> :call LanguageClient_textDocument_references()<CR>
        nnoremap <C-e><C-d> :call LanguageClient_textDocument_formatting()<CR>
        autocmd! CursorHold * call LanguageClient_textDocument_hover()

        autocmd! VimLeave * :LanguageClientStop

endfunction

This will allow PowerShell Editor Services to listen on stdio to be able to work with LanguageClient-neovim

@yatli's fork is here: https://github.com/yatli/PowerShellEditorServices

clone that to ~/Desktop

You'll need to run the build step to get it working: https://github.com/powershell/powershelleditorservices#development

Expected Behavior

LanguageClient-neovim would close the running instance of powershell (where the language server is running)

Current Behavior

The process is still running:

tylerleonhardt   19425   0.0  0.7  6606068 118280 s001  S+   11:13PM   0:04.18 pwsh /Users/tylerleonhardt/Desktop/PowerShellEditorServices/module/Start-EditorServices.ps1 -HostName nvim -HostProfileId 0 -HostVersion 1.0.0 -EditorServicesVersion 1.6.0 -LogPath /Users/tylerleonhardt/Desktop/pses.log.txt -LogLevel Diagnostic -BundledModulesPath /Users/tylerleonhardt/Desktop/PowerShellEditorServices/module -Stdio -SessionDetailsPath /Users/tylerleonhardt/Desktop/.pses_session

This is bad because I often close and open neovim all the time and every time that happens a new process is left behind. Too many stray processes.

TylerLeonhardt commented 6 years ago

Once I address this last issue I promise to submit a PR on how to set PowerShell up with LanguageClient-neovim 😄

autozimu commented 6 years ago

According to spec the server should quit itself when receiving exit(), no matter what the mode is (TCP or STDIO). This is at least my understanding. PS server should fix it's own problem correctly handling this exit() notification.