rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

More IDE features for control flow keywords

Open Veykril opened this issue 1 year ago • 5 comments

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

Veykril avatar Jun 30 '24 10:06 Veykril

@rustbot claim

roife avatar Jul 01 '24 07:07 roife

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

roife avatar Jul 01 '24 13:07 roife

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

Veykril avatar Jul 01 '24 13:07 Veykril

I've encountered some difficulties handling macros:

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

  • Jumping directly to the function.
  • Inside a macro, and jump to a function within the macro.
  • Inside a macro, but jump to a function outside the macro.

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?

roife avatar Jul 02 '24 07:07 roife

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

Veykril avatar Jul 02 '24 07:07 Veykril

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:

  • return corresponds to the { of the async block
  • async kw corresponds to await kw

roife avatar Jul 02 '24 12:07 roife

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

Veykril avatar Jul 02 '24 12:07 Veykril