Member-only story
Setting up code lens for Rust.

Overview
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.

Setup
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.
Neovim LSP Enhanced
Additional features to enhance your LSP experience in Neovim.
alpha2phi.medium.com
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.
Problem
- 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.

- Type
:lua vim.lsp.codelens.run()
- You are prompted to choose the code lens action.