rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.16k stars 1.58k forks source link

More IDE features for control flow keywords #17517

Closed Veykril closed 2 months ago

Veykril commented 3 months ago

We currently highlight relevant control flow structures when the cursor is on a relevant keyword, an example being highlighting all awaits when on an async fn's async keyword, or all loop control flow keywords when it is on the loops keyword. We can do more things here I'd say. Go to def/decl on return could go the relevant closure/fn, continue and break to the corresponding loop (or block for labeled blocks), go to references could do the same as the highlighting

roife commented 3 months ago

@rustbot claim

roife commented 3 months ago

For the return kw, should we navigate to the def (i.e., the function name), the arrow-> or the fn keyword of the function?

Veykril commented 3 months ago

fn keyword I'd say, for closures the opening bar and for async blocks the async keyword

roife commented 3 months ago

I've encountered some difficulties handling macros:

Currently, for functions, I can correctly handle three scenarios (see GIF):

and mixture of them.

录屏2024-07-02 13 30 31

These can be handled using NavigationTarget::from_named (orig_range_with_focus). However, how should I handle closures? Since closures don't have names, can they be mapped through SpanMap?

Veykril commented 3 months ago

They can be mapped just fine, it's just that we have no API in NavigationTarget for anything without names.

roife commented 3 months ago

Currently, placing the cursor over return (in async block) highlights the corresponding async, while placing it over async just highlights all await. It's a bit inconsistent.

Should we implement a similar approach for goto-definition and goto-references? 🤔 Or changed it to be:

Veykril commented 3 months ago

I think for async blocks we might just wanna highlight await and return together. { isnt really intuitive for this