Skip to content

Commit

Permalink
Auto merge of rust-lang#16670 - rikhuijzer:rh/inlay-hints-nvim, r=Vey…
Browse files Browse the repository at this point in the history
…kril

Document nvim 0.10 `inlay_hint`

It took me a few hours to figure out how to enable inlay type hints on Nvim 0.10 with `lspconfig`. `rustaceanvim` has already dropped support for them (mrcjkb/rustaceanvim#46 (comment)) and most other plugins, like `rust-tools`, are depreciated in favor of `rustaceanvim`.

This PR documents how to enable the inlay hints on Neovim 0.10 and later. I've tested this and changing the `on_attach` function is the only step that is required.
  • Loading branch information
bors committed Feb 26, 2024
2 parents 309e087 + 4060377 commit 4585b46
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions docs/user/manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,14 @@ You can also pass LSP settings to the server:
[source,vim]
----
lua << EOF
local nvim_lsp = require'lspconfig'
local lspconfig = require'lspconfig'
local on_attach = function(client)
require'completion'.on_attach(client)
end
nvim_lsp.rust_analyzer.setup({
on_attach=on_attach,
lspconfig.rust_analyzer.setup({
on_attach = on_attach,
settings = {
["rust-analyzer"] = {
imports = {
Expand All @@ -367,6 +367,19 @@ nvim_lsp.rust_analyzer.setup({
EOF
----

If you're running Neovim 0.10 or later, you can enable inlay hints via `on_attach`:

[source,vim]
----
lspconfig.rust_analyzer.setup({
on_attach = function(client, bufnr)
vim.lsp.inlay_hint.enable(bufnr)
end
})
----

Note that the hints are only visible after `rust-analyzer` has finished loading **and** you have to edit the file to trigger a re-render.

See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started.

Check out https://github.com/mrcjkb/rustaceanvim for a batteries included rust-analyzer setup for Neovim.
Expand Down

0 comments on commit 4585b46

Please sign in to comment.