rust-lang / rust-lang/rust-analyzer
move items 2.0: move {left,right} or {before,after} and {add, remove}
Nobody has claimed this yet.
- 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:
-
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,
- updates definition from
fn x(z, y)tofn x(y,z) - updates all callers from
x(z,y)tox(y,z)
- updates definition from
- generic arguments,
- tuple item positions. This would , tuple instantiation to flip/swap the positions of certain arguments. These
move item leftandmove item rightcommands would have the same UI "API" for the user as currentlymove item upandmove item downdo now.
- function arguments,
-
Idea#2 Add & Remove
New commands:
add itemandremove item.Remove itemis pretty simple as it removes the given provided function arguments, tuple items, struct generics, struct lifetimes etc.Add itemis 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 itemcould 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 forremove itemin this context.For example, given
struct SomeStruct<T: Sized>with your cursor anywhere inT: Sizedis you could hit theAdd itemcommand, popup appears and you type inDebugas the other one, and the following happens:- original struct turns into:
struct SomeStruct<T: Sized + Debug> - all impls now are
impl<T: Sized + Debug> for SomeStruct {..}
- original struct turns into:
-
struct generic arguments/parameters
For example for a
struct SomeStruct<T:Sized>with you cursour anywhere in theSomeStructadding another item would add another type likestruct SomeStruct<T: Sized, U: ProvidedByUser>. WithProvidedByUserbeing inputed with some sort of popup.
-
-
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
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 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