rust-lang / rust-lang/rust-analyzer

Idea: create struct from function parameters

Open
#17,680 17 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists C-feature
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.