-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve "extract function" dialog #2186
Comments
3827: REF: improve extract method dialog UI r=ortem a=Kobzol This PR attempts to improve the Extract method dialog UI. Related issues: #2186, #2183 Right now it fixes an exception that was thrown when an invalid name was used for the name of the function (#1934). I also tried to use a simple text field instead of the dropdown list if there are no suggestions to offer, however `NameSuggestionsField` always returns true from `hasSuggestions()` method (which is caused by the way it's used in the dialog), so I'm not sure how to recognize when there are no suggestions (maybe use a different component altogether)? Co-authored-by: Jakub Beránek <berykubik@gmail.com>
5313: REF: allow the user to select mutability of parameters in ExtractFunction r=mchernyavsky a=Kobzol This PR adds mutability selection to the UI of `ExtractFunction`. I separated mutability from references, which should make it easier to add another option to choose "by value" or "by ref" parameters in the future. There is a slightly weird interaction with `requiresMut` (formerly called `isMutableValue`), for example here: ```rust fn test(mut v: Vec<i32>) {} fn test2(v: &mut Vec<i32>) {} fn foo() { let mut vec = vec![1, 2, 3]; let mut vec2 = vec![1, 2, 3]; /*caret*/bar(vec, &mut vec2); } fn bar(mut vec: Vec<i32>, mut vec2: &mut Vec<i32>) { test(vec); test2(&mut vec2); } ``` If I turn off the mutability of `vec2`, it switches from `mut vec2: &mut Vec<i32>` to `vec2: &Vec<i32>`. A better solution would be to not require `mut` there and just pass `vec2` to `test2` directly: `test2(vec2)`. But that would require further changes in how the function is generated, as the extracted code would have to be modified. Umbrella issue: #2186 Co-authored-by: Jakub Beránek <berykubik@gmail.com>
Should we also support the last item on the list, For example, the Kotlin plugin is pretty restrictive and doesn't allow type changes apart from subtyping. It also disallows removing the parameters. We already allow removing the parameter though, so maybe we should also allow changing the type. It shouldn't be hard to implement, we could just allow the user to type in the new type, although it's pretty easy to break the extracted code with that. I will try to implement it if you think that it's a valid option to offer to the users. |
Current "extract function" dialog is not ideal and can be improved:
T
/&T
/&mut T
/mut T
)Good example is kotlin "Extract function" dialog
![screen shot 2018-01-11 at 00 14 55](https://user-images.githubusercontent.com/2539310/34795786-8054f438-f664-11e7-84ed-2cfcd47596d8.png)
The text was updated successfully, but these errors were encountered: