Neovim LSP CodeLens for Rust

3 min readAug 2, 2021

Setting up code lens for Rust.

Neovim LSP CodeLens for Rust


CodeLens is a very useful feature for developers to easily identify the actions or references in a particular file. This article explores using the Neovim LSP code lens and hover action features to run or debug Rust applications.

Code Lens for Rust


I use Neovim 0.6 and configure rust-analyzer as the language server. Since I have already gone through the configuration in previous articles, the details are skipped here.

You can check out the following articles for the instructions.

Code lens is not supported by all language servers. Normally we should check if the capability is supported before setting any custom configuration.

E.g. I checked if the code lens feature is supported before setting any key mappings.


  • Now open a Rust project and type :lua vim.lsp.codelens.refresh()
  • You should see the options to Run or Debug the methods and tests.
Code Lens for Rust
  • Type :lua
  • You are prompted to choose the code lens action.

Software engineer, Data Science and ML practitioner.