avataralpha2phi

Summary

This article provides a guide on configuring LSP inlay hints for certain programming languages in Neovim using the inlay-hints.nvim plugin.

Abstract

The article "Neovim for Beginners — LSP Inlay Hints" is a guide on configuring LSP inlay hints for programming languages that support this feature in Neovim. The guide uses the inlay-hints.nvim plugin and provides instructions on how to install it using packer.nvim. The article also covers the configuration of settings for the sumneko_lua, gopls, and tsserver language servers. Additionally, the article includes code snippets for attaching to the language server in the on_attach method and configuring inlay hints for Rust in the lua/config/lsp/installer.lua file. The article concludes with examples of inlay hints for Rust, Lua, Go, and Typescript, and suggests alternative plugins to try.

Bullet points

  • The article is part of the "Neovim for Beginners" series.
  • The Neovim configuration files are available in a GitHub repository.
  • The inlay-hints.nvim plugin is used to configure LSP inlay hints.
  • The plugin is installed using packer.nvim.
  • The settings for the sumneko_lua, gopls, and tsserver language servers are configured.
  • Code is added to attach to the language server in the on_attach method.
  • Inlay hints for Rust are configured in the lua/config/lsp/installer.lua file.
  • Examples of inlay hints for Rust, Lua, Go, and Typescript are provided.
  • Alternative plugins to try are suggested.
  • The article is part of a series on learning Neovim the practical way.

Neovim for Beginners — LSP Inlay Hints

Configure LSP inlay hints.

Neovim for Beginners — LSP Inlay Hints

For certain programming languages, inlay hints make it a lot easier for us to code. In this short article, let’s configure LSP inlay hints for those languages that support this feature.

This article is part of the Neovim for Beginners series.

The Neovim configuration files are available in this repository.

Configuration

We are going to use the inlay-hints.nvim plugin. In the lua/plugins.lua file, we add the lines to install this plugin using packer.nvim.

Language Server Configuration

In the lua/config/lsp/init.lua file, we configure the settings for the sumneko_lua, gopls, and tsserver language servers.

LSP Configuration

In the lua/config/lsp/init.lua file, we add the code to attach to the language server in the on_attach method.

For Rust, we configure the inlay hints in the lua/config/lsp/installer.lua file.

Testing

Now inlay hints should work for those languages that support it.

Rust

Inlay Hints for Rust

Using rust-tools.nvim, we can use the commands RustEnableInlayHints and RustDisableInlayHints to enable or disable this feature.

Lua

Inlay Hints for Lua

Go

Inlay Hints for Go

Alternatively, we can use the go.nvim plugin which also has the inlay hints feature.

Typescript

Inlay Hints for Typescript

Other Plugins

Similar plugins that you can try

Check out the article Learn Neovim The Practical Way for all the Vim/Neovim articles!

If you are not a Medium member yet and want to become one, click here. You will gain unlimited access to all Medium articles and support my work directly.

Vim
Programming
Software Development
Coding
Software Engineering
Recommended from ReadMedium