1

I work primarily in Rust where I don't have type information written in the file (the compiler infers the type information for me). I normally rely on the type inlay hints, and in the JetBrains IDEs that I used to use, I could control-click on the type in the hint to go to its definition.

With Neovim, I have my type inlay hints, and the go-to-definition functionality, but I don't have a way to trigger LSP actions on the type information, since it isn't real text in the source file.

Here's a small example of what I'm talking about:

fn main() { let a: i32 = 3; // ^---^ - type inlay hint, virtual text // - if my cursor is there, all LSP actions only // work on the variable itself, not the type } 

I'm looking for a way to trigger LSP actions (e.g. vim.lsp.buf.type_definition() and vim.lsp.buf.hover()) on the type information in inlay hints, or in the hover window. This would allow me to act on the type information that isn't written in the source file.

I've tried setting virtualedit to allow me to move my cursor inside the inlay hints, but this doesn't work. The LSP actions just work on the variable the hint is for, and not the type in the hint.

I've also tried triggering LSP actions within the hover window, but this doesn't work (presumably because the hover popup isn't attached to the LSP server).

Additionally, I've tried the Lspsaga plugin because it supposedly works for this purpose, but it didn't help. I still couldn't trigger LSP actions within its hover window.

I'm curious how other people handle this use case. I know that in most cases I can run Telescope or something similar to quickly search for the type, but I'm looking for a method that allows me to "chain" LSP actions on subsequent LSP popup windows, like I'm used to from other IDEs.

Any help would be appreciated!

New contributor
zedseven is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  • Welcome to Vi and Vim! Note that the 'virtualedit' option is unrelated to the virtualtext feature. It won't help with this problem at all, as you already observed. For future reference, 'virtualedit' takes a string, so it would matter what you set it to. Commented 2 days ago
  • 1
    Thank you! I set it to all in my testing, which allowed me to move my cursor inside the inlay hints. This is why I mentioned it, since it looked like it might work, though evidently it did not solve the problem. Commented 2 days ago

1 Answer 1

0

In general, there is some type information in Rust source (at minimum functions are annotated on inputs and output). So you can always use that information.

Or, you can quickly type out the inlay hint and jump from the (now real) text. You might not even need syntactically well-formed code; sometimes, typing i32 anywhere in the buffer and jumping to definition might work.

NB standard library types typically require that you use rustup to install stdlib sources.

2
  • Thank you for your answer! It is true that there is some type information, but often the type I'm working with has not been written anywhere in my current buffer. You're also correct that it's possible to write out the type temporarily, but I'm looking for a way that allows me to navigate from variable -> type -> type (for example), triggering the LSP actions at each step to dig deeper without leaving or modifying my current buffer. Commented yesterday
  • @zedseven Indeed, that would be nice. I don’t have anything to offer on that front, hence the workaround ;) hopefully somebody has something workable. If not, we may need to propose something upstream to make it possible to implement. I’m not quite sure what that would be though. Commented yesterday

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.