flutter-intellij icon indicating copy to clipboard operation
flutter-intellij copied to clipboard

Switch-cases completion is missing after Dart 3.0

Open AlexV525 opened this issue 2 years ago • 16 comments

Steps to Reproduce

  1. Set the sdk constraint to >=3.0.0 in pubspec.yaml and run pub get.
  2. Try the below code.
enum MyEnum { foo, bar }

void f(MyEnum e) {
  switch (e) {}
}

image

Version info

[√] Flutter (Channel stable, 3.10.5, on Microsoft Windows [Version 10.0.22621.1848], locale en-US)
    • Flutter version 3.10.5 on channel stable at X:\SDK\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (3 weeks ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

AlexV525 avatar Jul 05 '23 12:07 AlexV525

I can't tell where the cursor is. If it is between the braces (i.e. the | in this: {|}) then this is a problem with the analyzer. If it is somewhere else then I think it is ok.

stevemessick avatar Jul 05 '23 15:07 stevemessick

No, the cursor is pointing to the switch keyword. This is easy to reproduce, just switch on any enumeration value and you'll see it.

AlexV525 avatar Jul 05 '23 15:07 AlexV525

@bwilkerson @scheglov What completion should be expected in this case?

stevemessick avatar Jul 05 '23 16:07 stevemessick

Given that ( and ) are highlighted, I think the caret is at one or another. In this case, we get image

If I put the caret at switch, I get image

scheglov avatar Jul 05 '23 16:07 scheglov

Testing on IDEA 2023.1, Windows

https://github.com/flutter/flutter-intellij/assets/15884415/974e0446-afe6-4760-ace3-30e1e5cde43b

AlexV525 avatar Jul 05 '23 16:07 AlexV525

Testing on IDEA 2023.1, macOS

https://github.com/flutter/flutter-intellij/assets/15884415/4896248d-6e45-4c4f-8998-7b5671ea48a9

AlexV525 avatar Jul 05 '23 16:07 AlexV525

When the SDK constraint was set to >=3.0.0, the issue occurred, if your project has a constraint like >=2.19.0, it won't break at all. I've updated the top comment with this info.

AlexV525 avatar Jul 05 '23 16:07 AlexV525

@AlexV525 I can confirm that this problem exists with the current stable SDK. However, it is fixed in master, as @scheglov's screen shot shows, and my own test confirmed. See https://github.com/dart-lang/sdk/issues/52607

stevemessick avatar Jul 05 '23 22:07 stevemessick

Also see https://github.com/dart-lang/sdk/issues/52180 for why it only inserts a single case now.

stevemessick avatar Jul 05 '23 22:07 stevemessick

Oddly, it will do all of them eventually, but only one at a time. Seems like the quick fix could automatically run itself until it doesn't find any more. @bwilkerson is that feasible?

stevemessick avatar Jul 05 '23 22:07 stevemessick

https://github.com/dart-lang/sdk/issues/51985 is open because we need support from _fe_analyzer_shared to get more than one witness for a failed exhaustiveness validation. But I don't think this is high priority.

I'm against adding workarounds like running the fix multiple time. This is not the level at which the problem should be fixed.

scheglov avatar Jul 05 '23 23:07 scheglov

I wonder if we could do it in the IDE? I don't know when I'd have time to investigate, but I'll keep this open as a reminder.

stevemessick avatar Jul 05 '23 23:07 stevemessick

Can confirm it's working (add 1 missing case at once) on the main channel of Flutter.

AlexV525 avatar Jul 06 '23 02:07 AlexV525

Seems like the quick fix could automatically run itself until it doesn't find any more. @bwilkerson is that feasible?

Maybe. There are a few potential blockers:

  • it might not be fast enough
  • the edits might not be composable
  • it might not be possible to update the file state for re-analysis purposes without causing chaos in the UI

But I agree with Konstantin that this isn't the preferred way to solve the problem, and I'd rather put resources toward the better solution if at all possible. If someone did implement an iterative approach I'd consider it to be technical debt that needed to be cleaned up, and we don't need more technical debt.

bwilkerson avatar Jul 06 '23 04:07 bwilkerson

Any updates?

AbdulazizRasulbek avatar Oct 21 '23 20:10 AbdulazizRasulbek

Please fix this! It still happens in December 2023.

devnta avatar Dec 18 '23 07:12 devnta