You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling "Extract to function" on some code, Rust analyzer ignores this parameter order and I often end up with functions where I need to manually rearrange the parameter order to my liking.
Suggested solution
When "Extract to function" decides the parameter order of the new function, it should use the following algorithm:
A) Categorize the arguments based on wether or not they were parameters to the already existing function
B) If yes, put them first, and in the same order as in the existing function
C) if no, put them last, in whatever order (I have no strong opinion here - can use same heuristic as the current code)
Effect
fnexisting(a:A,b:B,c:C){let x = 32;let y = 1.0;long_code_block_that_uses(x,b,a,y)// <--- call "Extract to function" on this code block}
Results in ->
fnexisting(a:A,b:B,c:C){let x = 32;let y = 1.0;fun(a, b, x, y);}fnfun(a:A,b:B,x:i32,y:f32){long_code_block_that_uses(x,b,a,y)}
The text was updated successfully, but these errors were encountered:
C) if no, put them last, in whatever order (I have no strong opinion here - can use same heuristic as the current code)
The current emitted ordering is dependent on appearance order in the extracted snippet, so we probably want to use that for C) here as well. Generally agree though, the assist should preserve parent function parameter ordering where possible!
Problem
I often have a list of similar "context" parameters to my functions, and I try to be consistent with their order. For example:
When calling "Extract to function" on some code, Rust analyzer ignores this parameter order and I often end up with functions where I need to manually rearrange the parameter order to my liking.
Suggested solution
When "Extract to function" decides the parameter order of the new function, it should use the following algorithm:
A) Categorize the arguments based on wether or not they were parameters to the already existing function
B) If yes, put them first, and in the same order as in the existing function
C) if no, put them last, in whatever order (I have no strong opinion here - can use same heuristic as the current code)
Effect
Results in ->
The text was updated successfully, but these errors were encountered: