Refactoring in VSCode with Dart not working

Viewed 9073

I just started working with flutter and I am unable to refactor dart/flutter in VSCode.

I am running VSCode on MacOSX and installed VSCode as per the flutter documentation, installed the dart and flutter plugins. flutter doctor shows no issues.

The app I am creating runs fine on simulator and devices.

When trying to rename a property, using the refactor shortcut, no option to rename is available. When trying to rename a class, I get 'No refactorings available'

I can't believe this kind of refactoring would not be available.

What am I missing in my setup? Any suggestions on what I can check, change in VSCode?

7 Answers

If you mean refactorings like Wrap with Container, press Ctrl+.

Earlier button called "Refactor" in context menu was available, but it isn't now, and Ctrl+Shift+R doesn't help. So you can use my advice.

Also reinstalling VSCode helped me to get back the "Refactor" button to the context menu

Highlight property or class name and click on Rename Symbol enter image description here

Disabling the dart LSP analyzer will bring back the refactor back to the context menu.

enter image description here

Highlight property or class name and use F2 to rename.

If refactoring in Flutter/Dart is not working, try disabling other extensions. Sometimes another extension can interfere with refactoring using Flutter/Dart extensions. At least it did in my case.

Reinstalling the VS code is the best solution for my case ....

First select the code you want to rename and Refactor, then press F2 to rename after that just press Shift + Enter to refactor you can see your Refactor View here

then just press Apply

Related