-
Notifications
You must be signed in to change notification settings - Fork 1.8k
internal: use ControlFlow
in "extract function" assist
#10309
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
Conversation
There is one slight problem here, For this to then also work in unit tests you will need to add a |
I need help. In let scope = ImportScope::find_insert_use_container_with_macros(path.syntax(), &ctx.sema)?; But how should I do in this case? What arguments should I pass into I'm sorry, I have many concepts that are not clear to me :(. Thank you for your time and suggestion. |
No problem, you can always ask when something's not clear. The arguments passed to to |
Ah right use insertion logic requires mutable node edits. So this is a bit more tricky to get the edit out of as I can take a look at doing that first, then you can rebase your changes on top of that if you'd like. |
77bbc8d
to
5818358
Compare
@Veykril Thanks so much for your explanation. I've finished the import job. Could you give it a review again if you have time? :) |
Lgtm thanks! |
ControlFlow
in "extract function" assistControlFlow
in "extract function" assist
fix: bug in extract_function.rs There is a little bug in extract_function: It appends `use path::to::ControlFlow;` if the function created contains string "ControlFlow". A case below (also in the test named `does_not_import_control_flow` which will fail in the original code) <img width="322" alt="image" src="https://github.com/rust-lang/rust-analyzer/assets/53432474/4b80bb58-0cfd-4d56-b64c-d9649eed336e"> <img width="391" alt="image" src="https://github.com/rust-lang/rust-analyzer/assets/53432474/3d7262f4-8a4c-44ea-822d-304b8b23fe28"> Now I have changed the condition determining whether adding import statement. Only when the new function body contains ControlFlow::Break or ControlFlow::Continue can the import statement be added. Last related PR: #10309
Fixes #10272