rust-lang / rust-lang/rust-analyzer

Better workflow for creating trait impls

Open
#19,527 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

          I feel like a better workflow (that we should enable) would be the following maybe?:
  • write impl / get a impl $0 {} completion
  • start writing a trait name -> get a Trait<$1, $2, ...> for $0 completion (with each required trait arg as a tabstop), that is we now have the following state impl Trait<$1, $2, ...> for $0 {}
  • then offer assists (diagnostic quickfix) for adding unresolved name segments as a new generic parameter to the surrounding impl (this one we should really have either way, its so useful)

That is, I feel like the user shouldn't even need to jump back to the generic parameter listing in the first place. If you create a generic parameter there, you will have to use it anyways and so typing out the reference to it first and then have r-a just create the definition for you sounds more ergonomic to me?

To be clear, I do agree there is an ergonomics gap here. Its just tabstop snippet completions can be a lot more annoying than helpful depending on how they are designed, and duplicating completions to accomodate for a variety of snippet setups can be more confusing than helpful which is why I (and presumably Florian) are a bit wary of this here.

Originally posted by @Veykril in https://github.com/rust-lang/rust-analyzer/issues/19447#issuecomment-2760611811

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 rust-analyzer's trait-impl completion and diagnostic quickfix paths described in the issue. Determine how to offer the impl skeleton, trait generic parameters as tabstops, and assists that add unresolved name segments as surrounding impl generics; done means this workflow works without returning to the generic parameter list.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.