rust-lang / rust-lang/rust-analyzer

Ambitious feature request: add a roogle-like interface for workspace/symbol search

Open
#10,813 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-ide C-Architecture C-feature E-unknown
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

You may have seen roogle - a hoogle-like search for rust APIs by a combination of function or type names and type signature.
https://github.com/roogle-rs/roogle

Live demo
https://roogle.hkmatsumoto.com/

Playing around with it reminded me of my interactions with rust-analyzer through lsp-ivy - an emacs package that helps fuzzy find and narrow search results with strings. It's a really fun and quick way to find an API (struct, enum, method) with a substring. It's already amazing to have something like this.

Follow the URL below for a static picture example (sadly no gif).
https://github.com/emacs-lsp/lsp-ivy#screenshot

Often my searches are related to a specific struct or enum and I am trying to work out if I can convert type U -> T or call a method on T that would return a boolean.

eg.
I thought wouldn't it be cool, if I could use rust-analyzer to quickly find a method with "valid" in the name, related to type T that returns a boolean like so
fn valid*(T) -> bool

I feel like it would really help me interactively ask questions and learn about the APIs offered by different crates in a new project.

Sounds like there has already been a conversation between roogle developers and rustdoc, which could lead to this being adopted for docs.rs search.
https://github.com/roogle-rs/roogle/issues/12

I was wondering how realistic it would be to enable rust-analyzer to service (a subset of) queries like this.

Prior Art

Rust-analyzer already supports workspace symbol search as defined by the LSP spec.
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_symbol

In fact rust analyzer has also expanded the workspace/symbol interface to filter by type and scope
https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#workspace-symbols-filtering

Rust-analyzer previously successfully added other major search(-and-replace) interfaces that extend the LSP spec like SSR
https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#structural-search-replace-ssr

Potential required steps
  • A query grammar
  • An LSP extension
  • An error-prone parser of user queries with friendly error messages
  • An index data structure independent from cargo doc (that roogle seems to rely on atm) that allows this kind of search
  • Measurements and benchmarks to see if expanding the rust analyzer index structure to support this has a penalty on indexing times, request-response times and RAM required by rust-analyzer. Ideally tested on a mega-project with loads of dependencies to see the worst-case scenario.
  • Investigation of how much code can be shared between roogle and rust-analyzer?

I appreciate this is a huge feature and it may have been discussed already. I decided to open an issue after not seeing any mentions of roogle on rust-analyzer.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing workspace/symbol behavior and the workspace-symbols filtering section in docs/dev/lsp-extensions.md, then compare the proposed query grammar and LSP extension with roogle's approach. Investigate indexing, parsing, error messages, benchmarks, and possible code sharing; done would require a defined, tested query interface with acceptable indexing, response-time, and memory costs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
search
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.