One thing I love about Neovim

2019/04/20

Like some Vimmers, I like to use a few plugins for finnicky things like “smart” code completion. These plugins often rely on some assumptions about the state of your development environment outside of the editor: they might need a utility program installed (such as rls), or a configuration file somewhere, something like that.

If you’ve ever set up a plugin like YouCompleteMe with a project having a non-trivial build system, you know how painful debugging this can be!

In Neovim, :checkhealth executes “health checks”, which the editor and third-party plugins can arbitrarily define. When each check succeeds or fails, it is logged to a window for the user to read.

A failed health check represents a failed expectation about the development environment by the plugin or editor component. A good one also enumerates what the plugin specifically tried to do but which failed.

As an example, suppose you thought to try out Neovim’s python2 integration. So you type in one of the examples from the help file:

:py print(sys.version)

But are greeted with a friendly error message:

E319: No "python" provider found.  Run ":checkhealth provider"

Execute that command, and Neovim runs health checks for its “provider” components.

screenshot of neovim showing mixed health check results

Neovim’s Python 2 provider is in a degraded state. Apparently, none of the python2 interpreters that were found could import the neovim module. What to do now? Like the message says, check :h provider-python:

- For Python 2 plugins, make sure Python 2.7 is available in your $PATH, then
  install the package systemwide:
    sudo pip2 install --upgrade pynvim
  or for the current user:
    pip2 install --user --upgrade pynvim

So, try that in another terminal, and then run :checkhealth provider again.

screenshot of neovim showing better healte check results

All looks good! Now try the :py command de nuevo:

:py print(sys.version)
2.7.16 (default, Apr 12 2019, 15:32:40)                                                        
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.3)]                                   
Press ENTER or type command to continue                 

Great! What a nice experience.

For more on health checks, see Neovim’s documentation (:h pi_health).