rust-lang / rust-lang/rust-analyzer

sub-optimal completion when completing a type

Open
#13,889 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Consider the following code:

fn main() {
    do_thing($0)
}

struct SomeLongNamedStruct {
    bar: usize,
}

impl SomeLongNamedStruct {
    fn new() -> Self {
        Self { bar: 0 }
    }

    fn with_bar(bar: usize) -> Self {
        Self { bar }
    }
}

fn do_thing(x: SomeLongNamedStruct) {}

The completion at $0 will suggest SomeLongNamedStruct { bar: () }. It would be much nicer if it also suggested (probably one or the other, preference towards the latter).

  • SomeLongNamedStruct:: (assumes that the type itself will have some associated function that might construct it)
  • SomeLongNamedStruct::new() and SomeLongNamedStruct::with_bar() - these are associated methods found within the type that construct the type.

Right now, in order to get to SomeLongNamedStruct::new(), I have to either type it out myself, or accept the completion SomeLongNamedStruct { bar: () }, and then erase { bar: () } and then type ::.

Additionally:

  • supposing the completion was do_thing(wit$0) it would be cool if it could suggest SomeLongNamedStruct::with_bar as well.
  • supposing SomeLongNamedStruct implemented Default, it would also suggest Default::default() as a completion option as well.

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 locating rust-analyzer's type-completion implementation and related completion tests, then reproduce the examples from the issue. Done means completion offers suitable constructors or associated-function forms, including the partial-name case, with tests covering the requested suggestions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, tooling
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.