Neovim 101 — Semantic Highlighting

Semantic highlighting using Tree-sitter and LSP semantic tokens.

alpha2phi

--

Neovim — Semantic Highlighting

We briefly went through semantic highlighting using Tree-sitter previously. In this article, let’s go through this feature using Tree-sitter and LSP.

This article is part of the Neovim 101 series.

The Neovim configuration files are available in this repository.

Getting Started

Without semantic highlighting, we are unable to highlight the variables correctly.

In the screenshot below, the passed-in parameters are not highlighted correctly using the same color.

Python Code without Semantic Highlighting

For Neovim, we can address this issue using Tree-sitter or LSP semantic tokens.

Semantic Highlighting using Tree-sitter

We can use the hlargs.nvim plugin to highlight arguments’ definitions and usages, asynchronously, using Treesitter.

In the lua/plugins.lua file, we install the plugin using packer.nvim.

--

--

alpha2phi

Software engineer, Data Science and ML practitioner.