简体   繁体   English

使用 Dart 在 VSCode 中重构不起作用

[英]Refactoring in VSCode with Dart not working

I just started working with flutter and I am unable to refactor dart/flutter in VSCode.我刚开始使用 flutter,我无法在 VSCode 中重构 dart/flutter。

I am running VSCode on MacOSX and installed VSCode as per the flutter documentation, installed the dart and flutter plugins.我在 MacOSX 上运行 VSCode 并根据 flutter 文档安装了 VSCode,安装了 dart 和 flutter 插件。 flutter doctor shows no issues. flutter 医生显示没有问题。

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'尝试重命名 class 时,我得到“没有可用的重构”

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?关于我可以检查什么,在 VSCode 中更改的任何建议?

If you mean refactorings like Wrap with Container , press Ctrl+.如果您指的是像Wrap with Container这样的重构,请按Ctrl+.

Earlier button called "Refactor" in context menu was available, but it isn't now, and Ctrl+Shift+R doesn't help.上下文菜单中名为“重构”的早期按钮可用,但现在不可用, Ctrl+Shift+R也无济于事。 So you can use my advice.所以你可以使用我的建议。

Also reinstalling VSCode helped me to get back the "Refactor" button to the context menu还重新安装 VSCode 帮助我将“重构”按钮返回到上下文菜单

Disabling the dart LSP analyzer will bring back the refactor back to the context menu.禁用 dart LSP 分析器会将重构带回上下文菜单。

在此处输入图片说明

Highlight property or class name and click on Rename Symbol突出显示属性或类名,然后单击重命名符号在此处输入图片说明

As per below document, I don't see those options available as yet in VSCode plugin.根据下面的文档,我在 VSCode 插件中还没有看到这些选项。 https://dartcode.org/docs/refactorings-and-code-fixes/ https://dartcode.org/docs/refactorings-and-code-fixes/

https://github.com/Dart-Code/Dart-Code/issues/548 https://github.com/Dart-Code/Dart-Code/issues/548

你可以在https://dartcode.org/docs/refactorings-and-code-fixes/看到哪些重构列表

Highlight property or class name and use F2 to rename.突出显示属性或类名并使用F2重命名。

If refactoring in Flutter/Dart is not working, try disabling other extensions.如果 Flutter/Dart 中的重构不起作用,请尝试禁用其他扩展。 Sometimes another extension can interfere with refactoring using Flutter/Dart extensions.有时另一个扩展会干扰使用 Flutter/Dart 扩展的重构。 At least it did in my case.至少在我的情况下是这样。

重新安装 VS 代码是我案例的最佳解决方案......

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首先 select 您要重命名和重构的代码,然后按 F2 重命名,然后按 Shift + Enter 进行重构,您可以在此处看到您的 Refactor View

then just press Apply然后只需按应用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM