rust-lang / rust-lang/rust-analyzer

move items 2.0: move {left,right} or {before,after} and {add, remove}

Open
#8,340 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists fun S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

The item movers feature (https://github.com/rust-analyzer/rust-analyzer/pull/8054, https://github.com/rust-analyzer/rust-analyzer/issues/6823) is really cool. I'd like for it to be explored further. I have some ideas. Let me know if I should create separate issue for each, but I fear this isn't something you want to explore. Here are the ideas:

  1. Idea#1: Left & Right

    My initial idea was to also enable moving left and right. This would allow moving left and right the following:

    • function arguments,
      1. updates definition from fn x(z, y) to fn x(y,z)
      2. updates all callers from x(z,y) to x(y,z)
    • generic arguments,
    • tuple item positions. This would , tuple instantiation to flip/swap the positions of certain arguments. These move item left and move item right commands would have the same UI "API" for the user as currently move item up and move item down do now.
  2. Idea#2 Add & Remove

    New commands: add item and remove item. Remove item is pretty simple as it removes the given provided function arguments, tuple items, struct generics, struct lifetimes etc. Add item is more tricky as it wouldn't make much sense in the context of a tuple or function, but it would be pretty nice for struct generics.

    Add item could work for (including but not limited to):

    • for tuple items

      Very simply just adds the provided type to the end, left and right could be used by the user after.

    • for a function

      It would first add an argument with the type provided by the user to the end, and then the user could move it left and right to their liking to place it where they want

    • type bounds requirements on the struct definition for the given arguments and update all the impls to also include the new bound. Same goes for remove item in this context.

      For example, given struct SomeStruct<T: Sized> with your cursor anywhere in T: Sized is you could hit the Add item command, popup appears and you type in Debug as the other one, and the following happens:

      1. original struct turns into: struct SomeStruct<T: Sized + Debug>
      2. all impls now are impl<T: Sized + Debug> for SomeStruct {..}
    • struct generic arguments/parameters

      For example for a struct SomeStruct<T:Sized> with you cursour anywhere in the SomeStruct adding another item would add another type like struct SomeStruct<T: Sized, U: ProvidedByUser>. With ProvidedByUser being inputed with some sort of popup.

  3. Idea#3 Before & after

    This idea is to replace {up,down,left,right} with a more general solution: before and after. Moving a function "before" would have the same semantics as moving it up currently; conversely for down and "before". Moving an argument "before" would move it as Idea#1's left; conversely for Idea#1's right.

Ideally I would love for the combination of Idea#2 and Idea#3. Also, given Idea#2 and Idea#3 one could have the basics for a future Change signature type of refactor where the user could get a nice UI for modifying the given signature to the new one, as all signature refactoring is moving, renaming, adding and removing (correct me if I'm wrong); but given Idea#2 and Idea#3 the user could in theory do the whole change signature action manually by calling the necessary commands themselves. Another nice addition would be https://github.com/rust-analyzer/rust-analyzer/issues/2178

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 reading the item movers work in pull request 8054, the related issue 6823, and issue 2178. Compare the proposed left/right, add/remove, and before/after ideas, then establish a focused scope and acceptance criteria before implementation; the issue currently describes several possible refactoring features rather than one defined change.

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
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.