Member-only story

Neovim LSP CodeLens for Rust

alpha2phi
3 min readAug 2, 2021

--

Setting up code lens for Rust.

Neovim LSP CodeLens 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.

Code Lens for Rust

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.

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.
Code Lens for Rust
  • Type :lua vim.lsp.codelens.run()
  • You are prompted to choose the code lens action.

--

--

alpha2phi
alpha2phi

Written by alpha2phi

Software engineer, Data Science and ML practitioner.

No responses yet

Write a response