Repository: autozimu/LanguageClient-neovim (language: rust)

Issue:
Getting " [LC] 'Vim(return):Can''t send data to closed stream' " from neovim after closing .sh & init.vim
- Did you upgrade to latest plugin version? 
**Yes**
- Did you upgrade to/compile latest binary? Run shell command
  `bin/languageclient --version` to get its version number.
**languageclient 0.1.160**
- (Neovim users only) Did you check output of `:checkhealth LanguageClient`?
```
health#LanguageClient#check
========================================================================
  - OK: binary found: /home/idinev/.config/nvim/plugged/LanguageClient-neovim/bin/languageclient
  - OK: languageclient 0.1.160
  - OK: Floating window is supported and will be used for hover
```

- Did you check [troubleshooting]?
**Yes**

[troubleshooting]: https://github.com/autozimu/LanguageClient-neovim/blob/next/INSTALL.md#troubleshooting

## Describe the bug

When I modify files I get the error from the title printed on my terminal.


## Environment

- neovim/vim version (`nvim --version` or `vim --version`):
```
NVIM v0.4.4
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.4.4/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
Compiled by builduser

Features: +acl +iconv +tui
```
- This plugin version (`git rev-parse --short HEAD`):
**d6d6d08**
- This plugin's binary version (`bin/languageclient --version`):
****languageclient 0.1.160****
- Minimal vimrc content (A minimal vimrc is the smallest vimrc that could
  reproduce the issue. Refer to an example [here][min-vimrc.vim]):
- Language server link and version:
[Bash - 1.17.0](https://github.com/bash-lsp/bash-language-server)
[Vim - 2.0.0](https://github.com/iamcco/vim-language-server)
[Python - 0.35.1](https://github.com/palantir/python-language-server)
[min-vimrc.vim]: https://github.com/autozimu/LanguageClient-neovim/blob/next/min-vimrc.vim

## To Reproduce

Steps to reproduce the behavior:

- Open the sample python file (or any other python/bash/vim file) using the min-vimrc.
- Edit the file (remove/add line).
- :wq.

## Current behavior

Most of the times I do the steps I get the error message, sometimes I get the message without modifying the file at all - just doing :wq.

## Expected behavior
This not happening anymore.

## Screenshots

![image](https://user-images.githubusercontent.com/11410938/97812668-8f96f900-1c8b-11eb-906e-425dcc6342b1.png)

## Additional context

Issue mentiond on the bash-language-server repo - https://github.com/bash-lsp/bash-language-server/issues/112
Another person has stated that he has not observed the issue with other LCs (CoC) and that he has observed the problem with other servers when running LanguageClient-neovim.



Discussion / hints:
Yep, can reproduce. Could reproduce with 0.1.158 as well. Will look into it but I'm fairly sure that's just our `handleBufWritePost` autocmd trying to run after `w` but not getting there before `q` so it shouldn't be critical.
As as temporary workaround, if you set `let g:LanguageClient_loggingLevel = 'ERROR'` (instead of `INFO`, which I presume you have) that message won't be visible.
Somehow I managed to spend 30 min troubleshooting the issue with the minimal rc without realizing that this is just a logging message not being written to the proper place...
Indeed I have the logging level set to 'INFO'...

Fix patch:
diff --git a/autoload/LanguageClient.vim b/autoload/LanguageClient.vim
index d4e320b6..656f1639 100644
--- a/autoload/LanguageClient.vim
+++ b/autoload/LanguageClient.vim
@@ -709,6 +709,11 @@ endfunction
 function! LanguageClient#Write(message) abort
     let l:message = a:message . "\n"
     if has('nvim')
+        " abort write if nvim is exiting
+        if get(v:, 'exiting', v:null) isnot v:null
+          return
+        endif
+
         " jobsend respond 1 for success.
         return !jobsend(s:job, l:message)
     elseif has('channel')


Test patch: