rust-lang / rust-lang/rust-analyzer

No completion in Rocket `routes` macro

Open
#11,457 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-completion A-macro C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Trying out the basic Rocket example, I noticed we don't provide completions in the routes macro, and I'm not sure why.

#[macro_use] extern crate rocket;

#[get("/")]
fn index() -> &'static str {
    "Hello, world!"
}

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![ind/*cursor here*/])
}

Macro-expanding the routes! call gives:

{
  let ___vec: ::std::vec::Vec< ::rocket::Route>  = (<[_]>::into_vec(box[{
    let ___struct = ind{}
    ;
    let ___item: ::rocket::Route = ___struct.into_route();
    ___item
  }]));
  ___vec
}

so the ind token shows up in the expanded code, and in a position where we would provide completions. And we do provide the generated index struct as a completion outside the macro call. Maybe we lose track of the token identity / spans somehow?

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 tracing completion handling for the routes! macro expansion at the ind cursor, then compare it with completion for the generated index struct outside the macro call. Done means the index route completion is available at the cursor inside routes! without regressing the existing completion behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.