Neovim: Language Servers, DAP and Treesitter

In the previous post, I mentioned how NeoVim can be configured to be more like an IDE. This means features like autocomplete and so on. Let us take a look at some tools which we can interface with NeoVim.

Language Servers

Regular Vim always had support for these to some extent using tags files and other mechanisms to provide autocomplete. However, it never had the ability to analyse the code and make the autocomplete context based like a regular coding IDE.

For example, if I am working on a certain object, I would like to see autocomplete suggestions for that object. And in python the data type might not be directly mentioned but inferred from elsewhere in the code. With async tasks in NeoVim, the editor can now interface with external tools called language servers.

Language servers were first standardised by Microsoft for use in VSCode. These servers analyse the code and provide diagnostic messages (errors, warnings) as well as autocomplete suggestions via an API protocol called Language Server Protocol (LSP). There are separate language servers for every programming language that know how to understand and parse that language. For python, PyRight is the most popular language server. Once you install the language server, NeoVim will use the standard API and get diagnostics and autocomplete suggestions from there.

Although NeoVim has language server support built in, there are various plugins that simplify the process of installing and managing the language servers. The most popular are:


In a similar vein to language servers, Microsoft also releasd a Debug Adapter Protocol (DAP) to interface VSCode with various debuggers. And NeoVim also has a capability to use this protocol. Through this, you can install plugins that provide the debug UI (breakpoints, watches etc) and send the commands to any backend debugger that supports DAP.

Once again, Mason can be used to manage DAP servers as well.

Syntax Highlighting

Normally, syntax highlighting is done using regular expressions. Using these regex, the editor is able to identify keywords, variables, functions and so on, and highlight them appropriately. The editor doesn't actually analyse the code to do this. So, it cannot give different highlighting for global variables, local variables and parameters - since they all match the same regex pattern.

NeoVim has implemented integration with Treesitter, which is a fast, incremental code parser that can parse code as you type. Since treesitter parses the code and gives back data, it is possible for NeoVim to understand the code and apply semantic highlighting - differentiating local and global variables for example. Not only that, by using this data, NeoVim allows many new movement and selection commands. For example, you can press a key to select the function that the cursor is in, and then cut and move it elsewhere. Treesitter information will tell NeoVim where the function starts and ends and allows these kinds of features to be enabled.

So those are some of the tools that NeoVim will integrate with to behave more like a traditional coding IDE.

In the next post, I'll walk through my sepcific NeoVim configuration and how I have configured it, mainly for python programming.