Neovim for Beginners —LSP using null-ls.nvim

Improve the built-in LSP using null-ls.nvim.

alpha2phi
5 min readFeb 12, 2022

--

Neovim for Beginners — null-ls.nvim

We configured the built-in Neovim LSP in the previous articles. However, depending on the language servers' implementation, some LSP features may not be available.

E.g. if we are using Pyright as the Python language server, the code formatting feature is not supported. Even if the feature is available, we may still want to use other tools for the same purpose.

There are several options available to complement the missing language server features, e.g. use a general-purpose language server like efm, or plugins like nvim-lintor null-ls.nvim to inject LSP diagnostics, code actions, and more by allowing third-party tools and utilities to hook into the LSP client.

In this article, we are going to

  • Configure the null-ls.nvim plugin for diagnostics/linting, code actions, formatting, and hover dictionary.
  • Configure auto-formatting.
  • Enhance the status line to display the third-party diagnostics and formatting tools used by null-ls.nvim.

This article is part of the Neovim for Beginners series.

The Neovim configuration files can be found in this repository.

Installation

null-ls.nvim sources are able to hook into the following LSP features:

  • Code actions
  • Diagnostics (file- and project-level)
  • Formatting (including range formatting)
  • Hover
  • Completion

Tip: To see the capabilities of the language server attached to the current buffer, run :lua print(vim.inspect(vim.lsp.buf_get_clients()[1].resolved_capabilities)).

Let’s get started by installing the plugin. In the lua/plugins.lua file, add the lines to install null-ls.nvim.

  • We install null-ls.nvim (line 5 and line 13).

--

--

alpha2phi

Software engineer, Data Science and ML practitioner.