rust-lang / rust-lang/rust-analyzer

feature request: text edits for bind_pat inlay hints.

Open
#13,812 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Inlay hints can have text edits which can be provided to "apply" the inlay hint when double clicked on. I noticed this recently in the python language server's inlay hints, that I could do:

image

We could provide text edits which would auto-import any type that is referred to, and insert the type annotation, where syntactically valid.

For example:

fn foo() {
   let eligible = "hello".starts_with(|c| c.is_uppercase());
   //         ^ `: bool `              ^ `: char`
   match Some(eligible) {
        Some(n) => { }
        //   ^ not eligible, because inserting `: bool` here would not be valid syntax.
        None => { }
   }
}

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 bind_pat inlay-hint generation and the existing support for applying LSP text edits. Implement edits for eligible bindings that add type annotations and imports where syntactically valid; verify that cases such as the match binding example do not offer invalid edits.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.