intellij-rust / intellij-rust

Rust plugin for the IntelliJ Platform
https://intellij-rust.github.io
MIT License
4.53k stars 380 forks source link

How to convert "v :=" into "let v = " #9709

Open wcarmon opened 1 year ago

wcarmon commented 1 year ago

Environment

Problem description

I write a lot of both go and rust. I'm trying to reduce context-switch friction. Is there a simple way for the rust plugin to convert v := into let v =?

Maybe a live template? postfix templates don't seem to work for since there is no dot/period

Steps to reproduce

  1. open a rust file
  2. make a function
  3. in the function try to declare a variable (incorrectly) using go syntax (v :=)
  4. wish that the awesome rust plugin would auto convert to let v =
vlad20012 commented 1 year ago

Hi! I'm sorry, but I don't think there is such a way.

wcarmon commented 1 year ago

Sure, I imagine there's not way to do it today.

I'm asking how would it work? What would have to change?

This plugin already does some code rewriting (maybe ast rewriting) (example)

vlad20012 commented 1 year ago

Hmm, I'd suggest to do it using RsElementBaseIntentionAction, like AddElseIntention. See these blog posts (1, 2) (thank to @Kobzol!). But since v := can't be parsed as a valid Rust syntax, I wouldn't expect it to be very easy 😅