Neovim / rust-analyzer: get a list of all structs / enums to jump to?

Using neovim / rust-analyzer, is it possible to get the following:

  1. we have a cargo workspace

  2. we hit some hot key

  3. we get a list of all structs / enums / traits, and selection = jump to the file / line where it is defined

Maybe irrelevant to your question:

vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  • To get all type definitions in your local project at one time, you can use the search command tool like:
rg "struct .* \{"
rg "enum .* \{"

Yes, I have this working in neovim. This works like IntelliJ's 'goto definition" -- it jumps to the struct/enum/fn under the cursor.

IntelliJ has another feature 'goto class' where it opens something that has a text field and a list of all structs/enums; then, as we type characters in the text field, it narrows it down to the structs / enums that matches. We can even type regex!

This is the feature I am trying to replicate, when I remember parts (but not all of) the struct / enum name.

Sounds nice.
Would GitHub - nvim-telescope/telescope.nvim: Find, Filter, Preview, Pick. All lua, all the time. help?

:lua require'telescope.builtin'.lsp_workspace_symbols{}



I was not aware neo-vim was capable of this.

This is more related to my other question: Rust-analyzer as persistent program? than the current one, but since you operate on another level with neovim:

Do you:

(1) never :q in neovim or
(2) somehow avoid paying the cost of 'rust-analyzer boot time' ?

My current finger memory with vim is:

move around in bash
move around in bash

and basically this incurs a rust-analyzer startup time on every nvim session until things like goto-def start working

Well, I never thought about that, but it would be great if nvim can attach to RA again without closing RA's process.

You can ask for help in neovim community like Lag at neovim shutdown - LSP+rust-analyzer suspected - Neovim - Neovim Discourse.