rust-lang / rust-lang/rust-analyzer
sub-optimal completion when completing a type
Nobody has claimed this yet.
- 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()andSomeLongNamedStruct::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 suggestSomeLongNamedStruct::with_baras well. - supposing
SomeLongNamedStructimplementedDefault, it would also suggestDefault::default()as a completion option as well.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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