rust-lang / rust-lang/rust-analyzer
Idea: create struct from function parameters
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Sometimes when a methods signature gets fairly long, it's nice to extract the parameters into a struct, both for readability, and to avoid annoyances/errors around parameter ordering. I was wondering if a code action to do that would be a welcome addition, and if so, I'd love to take a crack at it! It would be my first RA contribution so I might ask a few questions, but I'd be very interested in helping out!
Currently I'm imagining a code action that operates on a selection of parameters in a function,creates a struct with the required fields, using the names of the parameters (excluding self | &self | etc.) replaces them in the call sites with the initialization of a struct which is public enough to be used by all the call sites, and then the arguments are de-structured, leaving the function body unchanged.
Let me know what you think!
Thanks!
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 reviewing existing rust-analyzer code actions and the issue discussion, since no files or tests are named. Trace how a selected parameter range could affect struct creation, all call sites, and argument destructuring. Done means the action handles the stated parameter cases without changing the function body and is covered by appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100