After months of problems with CoC: https://github.com/neoclide/coc-eslint/issues/72 I’ve given up and I’m trying other plugins.
I used ALE for ages with eslint, but never got it decently working using LSP. I tried ALE with Deoplete – but ALE is very slow and deoplete took ages to configure (python3 + pip + msgpack 1.0+ is a pain to install).
I came across this blog post showing love for Language Server Client (LSC): https://bluz71.github.io/2019/10/16/lsp-in-vim-with-the-lsc-plugin.html.
But this had a problem that it doesn’t work for linting, only LSP and I need eslint.
However this reddit comment described perfectly the use of installing ALE and LSC.
ALE with eslint, LSC with tsserver (+ LSP compliant wrapper
This seems like a good combo. ALE was reliable for ages and slow linting doesn’t matter too much, it’s slow auto-completion that’s a problem. Also ALE doesn’t have the floating window features that CoC and LSC do.
LSC along with ALE is almost entirely Vimscript (with some Dart that doesn’t require a further install) which makes it an easy install – no further dependencies makes plugins much better with Vim.
Installation of raw plugin
First thing that disappoints me currently in the instructions of the plugin is not having the Plugin code to copy-paste, I love where I can blindly follow the instructions with copy paste and it all magically works.
So to install the plugin in your
init.nvim for example using Plug or Vundle:
git clone https://github.com/natebosch/vim-lsc ~/.vim/bundle/vim-lsc
:Helptags to generate help tags
This will work too with any of the other plugin managers that support github plugins as sources.
Installation of typescript language server
However at this point you have a problem because there is nothing to indicate that anything is working. No auto-completion happens, nothing.
If you install Coc, from what I remember immediately auto-completion starts happening.
You can run
:LSC<tab> which should open up a list of the possible LSC commands to at least show that you have it installed.
Coc starts working for pretty much every file with an auto-complete using the words in the current file. This is great for seeing the immediate response that you know you’ve installed the plugin correctly. Plus with Coc you can run
:CocInstall coc-eslint which starts installing the eslint and then works again immediately from what I remember.
I want to test LSC with the typescript LSP, which I’d already installed with:
npm install --global typescript
Now fair enough but rather frustratingly the typescript tsserver isn’t a fully compliant LSP, so you need the LSP compliant wrapper
typescript-language-server mentioned above install globally same as typescript:
npm install --global typescript-language-server
I have two specific requirements which makes my commands differ:
- I use yarn
- I installed yarn/npm using
So my actual command was:
sudo yarn global add typescript typescript-language-server
Coc mimics VS Code and works with tsserver out of the box which saves you from having to install the extra library. If LSC could be made to work with tsserver it would be a nice step. Coc even goes so far as to install tsserver for you so you just need
CocInstall coc-tsserver and the magic starts happening. So you can install and get Coc working without having to leave Vim – the same happens for eslint because typically developers using eslint will already have it in their project and this just gets picked up magically.
The frustration of
typescript-language-server is that there is the far too similarly named
I’m very much a proponent for the “don’t make me think” mantra because that’s what most people are after when they’re trying to install a plugin.
Why go through all the work of writing your plugin in Vimscript only to leave the documentation bare leaving people frustrated.
So I already have tsserver installed and that’s used by VS Code and so is used by 90% of all developers now and so I’ll use that.
Futher frustration though is that there’s no comments in there giving helpful tips on how to set them up properly. The bluz71 blog above has the useful extra hint:
For LSC to function please ensure typescript-language-server is available in your
So you should make sure to add the npm/yarn global installation directory into your path – it’s easy enough to find instructions for this. To test make sure you can run this in the directory where you start Vim:
$ typescript-language-server --version 0.4.0
Obviously you’ll probably get some other version number, but you should at least get a response. You don’t set up a path to the language server binary in the config so it assumes you’ve got it directly available.
That’s all folks… not quite
However for me it didn’t, patiently typing a few characters and then reading documentation on how many characters to type before something happened did nothing.
I tried a
:LSClientGoToDefinition and it spewed out an error:
Error detected while processing function lsc#reference#goToDefinition..lsc#server#userCall: line 2: E684: list index out of range: 0 E15: Invalid expression: lsc#server#forFileType(&filetype)
Firstly getting errors is always bad and secondly this error message makes no sense.
The problem here is that there is no ‘health check’ that I could find. ALE gives a very good diagnostics page via
:LSClientWindowDiagnostics that sound like they might be useful aren’t at all in this situation.
Even after reading through
:help lsc I did not spot anything to help with spotting issues. But the intro there is very helpful:
There is no install step for vim-lsc. Configure the filetypes that are tracked
by installed language servers in the variable “g:lsc_server_commands”. Each
value in this dict should be a string which corresponds to either an
executable in your “$PATH”, an absolute path to an executable, or a
“host:port” pair. If multiple filetypes are tracked by the same server they
should be entered as separate keys with the same value. The value may also be
dictto allow for additional configuration.
It was only after re-reading the bluz71 blog again that I spotted my problem:
For a given filetype the LSC plugin will take care of launching, communicating and shutting down the named language server command.
My problem is that because I have the
Now I did a re-source of my
However doing a restart of Vim, now I got an error that flashed up in the Vim command line and disappeared, but then finally the magic started to happen.
So to know if LSC is working, the first thing you notice is that it subtly highlights the word you are on and any other words (‘symbols’) that match that.
Now auto-completion starts working and I can tweak away with key mappings. However I don’t really care about key mappings – they’re easy to tweak.
This does seem like a great plugin now that it’s working. It has the speed and functionality of Coc and it works which is a major plus point over Coc at the moment.
What I fundamentally care about when trying these LSP plugins is getting something to work as fast as possible so I can test out the plugin. I can then add other language servers and configurations, but until I’ve got something working there’s nothing but frustration.