flutter / flutter-intellij

Flutter Plugin for IntelliJ
https://flutter.dev/using-ide
BSD 3-Clause "New" or "Revised" License
1.97k stars 316 forks source link

Type Hierarchy stopped working in Android Studio #5899

Closed iLoveDocs closed 2 years ago

iLoveDocs commented 2 years ago

As you can see in the Type Hierarchy (right side), I don't see any dropdown button which can show ImageProvider's subclasses.

However, you can see (in the middle window) that there are many classes which extends ImageProvider. I should be seeing them in the Type Hierarchy but I don't.

It only works the first time I open Android Studio (or IntelliJ IDEA), and after that it just shows * sign and doesn't work as intended. This question has already been asked on Stack Overflow, here's the link

enter image description here

Flutter Doctor:

[✓] Flutter (Channel dev, 2.9.0-0.1.pre, on macOS 12.0.1 21A559 darwin-arm, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[☠] IntelliJ IDEA Community Edition (the doctor check crashed)
    ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at
      https://github.com/flutter/flutter/issues.
    ✗ FormatException: Unexpected extension byte (at offset 5)
[✓] VS Code (version 1.63.1)
[✓] Connected device (2 available)
stevemessick commented 2 years ago

I can't reproduce this problem. My Hierarchy tool window shows eight direct subclasses of ImageProvider.

Does this problem occur if you switch to the stable Flutter channel?

Does restarting the Dart analysis server fix the problem (at least temporarily)?

stevemessick commented 2 years ago

There are other problems in the hierarchy. I created https://youtrack.jetbrains.com/issue/WEB-54279 for that.

iLoveDocs commented 2 years ago

Here's something weird I noticed.

In one of my projects, if I open view hierarchy, it works for the first time and then starts showing asterisk sign after that. But if I do the same thing in another projects, then no matter how many times I view, it works every time.

I haven't tested this in stable channel, will do if you say (maybe above will provide you some insights).

I don't know how to restart Dart analysis server, but the problem persist after I had deleted ~/.dartServer/.analysis-driver folder.

stevemessick commented 2 years ago

You can restart the analysis server from the analyzer tool window. Use the menu View > Tool Windows > Dart Analysis to make it visible if it is hidden. Click the red circle-arrow icon in the top-left part of the view.

And yes, I'd like to know if this happens with the stable channel.

iLoveDocs commented 2 years ago

Restarting analyzer didn't make any difference. Switched to stable channel, invalidated the cache and restarted Android Studio and the problem persist.

Here's the Flutter doctor:

[✓] Flutter (Channel stable, 2.8.1, on macOS 12.0.1 21A559 darwin-arm, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[☠] IntelliJ IDEA Community Edition (the doctor check crashed)
    ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues.
    ✗ FormatException: Unexpected extension byte (at offset 5)
[✓] VS Code (version 1.63.1)
[✓] Connected device (2 available)
stevemessick commented 2 years ago

Thanks for the info.

Which versions of the Dart and Flutter plugins do you have installed?

You mentioned the problem does not happen for all projects. Are you using the same Flutter SDK in all projects?

iLoveDocs commented 2 years ago

Your welcome :)

Dart plugin version: 203.8452 Flutter plugin version: 63.2.1

Are you using the same Flutter SDK in all projects?

Sorry, I don't know how to check this. But if I run which flutter from both project's root directory they point to the same location and in the AS settings, the same path is selected for Flutter SDK path in Language & Frameworks > Flutter

And I'm using the same Dart SDK in all my projects.

environment:
  sdk: ">=2.15.1 <3.0.0"
stevemessick commented 2 years ago

Let me summarize this issue. You have at least one project in which the type hierarchy view works as expected. You also have at least one project in which type hierarchy is not working properly for Flutter SDK classes. You are using the stable version of Android Studio with the latest versions of the Dart and Flutter plugin. You have the latest stable and dev channel for the Flutter SDK. The broken project is broken for both stable and dev channels.

Questions for @iLoveDocs: Does the type hierarchy work correctly for your own code (that is, not SDK and not from pub)? Does it work for code in a pub package?

And, since I'm running out of ideas, could @alexander-doroshko or @bwilkerson suggest anything that might help?

iLoveDocs commented 2 years ago

Yes, the summary is correct except that I don't have both stable and dev channel. I had dev but then I changed it to stable using flutter channel stable && flutter upgrade, so at a time only one of the channel is there on my machine (provided the command doesn't create a separate folders somewhere in the flutter directory for each of the channels)

Does the type hierarchy work correctly for your own code (that is, not SDK and not from pub)?

Yes, it works for the files created by me in my project.

Does it work for code in a pub package?

Yes, it does.

Here's the screen recording showing three classes:

  1. change_notifier.dart from flutter/material.dart => Not working second time
  2. dummy.dart from my project => Working
  3. change_notifier_provider.dart from provider package => Working

https://user-images.githubusercontent.com/65380329/148640715-3d5aca62-ef7d-43c2-a11c-0ffe69261d9b.mov

stevemessick commented 2 years ago

Thanks @iLoveDocs !

@scheglov, @pq can you think of anything that might help diagnose this problem?

pq commented 2 years ago

Hrmmm. I'd have to defer to @scheglov or @jwren?

scheglov commented 2 years ago

Seeing the protocol between the IDE and the analysis server might help.

  1. Help | Find Action...
  2. Registry...
  3. Add to dart.server.additional.arguments simething like this--protocol-traffic-log=/Users/scheglov/tmp/das_protocol.log

The resulting file has a lot of data, including the content of some files.

iLoveDocs commented 2 years ago

@stevemessick You're welcome

@scheglov I added that flag, restarted Android Studio, clicked on the view hierarchy and now my existing files stopped showing View Hierarchy. I also don't see any logs or directory created in /Users/<username>.

What am I supposed to do next?

image
scheglov commented 2 years ago

You need to restart DAS after updating Registry... image

iLoveDocs commented 2 years ago

I get an error.

image

This is the error in the event log.

## Dart analysis issue

FileSystemException: Cannot open file, path = '/Users/iLoveDocs/tmp/das_protocol.log' (OS Error: No such file or directory, errno = 2)

## Version information

- Dart SDK 2.16.0-80.1.beta
- Dart IntelliJ 203.8452
- Android Studio Arctic Fox | 2020.3.1 Patch 4
- Mac OS X 12.0.1

## Details

FileSystemException: Cannot open file, path = '/Users/iLoveDocs/tmp/das_protocol.log' (OS Error: No such file or directory, errno = 2)

0 _File.open. (dart:io/file_impl.dart:356:9)

``` ## Debug log ``` 1641842065902 started analysis server: /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/dart /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --client-id=Android-Studio --client-version=AI-203.7717.5... 1641842066420 <= {"event":"server.connected","params":{"version":"1.32.7","pid":49620}} 1641842067555 started analysis server: /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/dart /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --client-id=Android-Studio --client-version=AI-203.7717.5... 1641842068023 <= {"event":"server.connected","params":{"version":"1.32.7","pid":49626}} 1641842075081 started analysis server: /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/dart /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --client-id=Android-Studio --client-version=AI-203.7717.5... 1641842075619 <= {"event":"server.connected","params":{"version":"1.32.7","pid":49640}} 1641842075956 started analysis server: /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/dart /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --client-id=Android-Studio --client-version=AI-203.7717.5... 1641842076510 <= {"event":"server.connected","params":{"version":"1.32.7","pid":49641}} 1641842076723 started analysis server: /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/dart /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --client-id=Android-Studio --client-version=AI-203.7717.5... 1641842077268 <= {"event":"server.connected","params":{"version":"1.32.7","pid":49642}} 1641842077644 started analysis server: /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/dart /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --client-id=Android-Studio --client-version=AI-203.7717.5... 1641842078151 <= {"event":"server.connected","params":{"version":"1.32.7","pid":49643}} 1641842081056 started analysis server: /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/dart /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --client-id=Android-Studio --client-version=AI-203.7717.5... 1641842081541 <= {"event":"server.connected","params":{"version":"1.32.7","pid":49648}} 1641842082245 started analysis server: /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/dart /Users/iLoveDocs/flutter/bin/cache/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --client-id=Android-Studio --client-version=AI-203.7717.5... 1641842082726 <= {"event":"server.connected","params":{"version":"1.32.7","pid":49649}} ```
scheglov commented 2 years ago

Does /Users/iLoveDocs/tmp exist?

iLoveDocs commented 2 years ago

No

iLoveDocs commented 2 years ago

Let me know if I did something wrong.

image
stevemessick commented 2 years ago

Please use an existing directory. If your user home is /Users/iLoveDocs, then just create a directory named tmp.

iLoveDocs commented 2 years ago

@stevemessick Yes, that worked, but I've been trying to upload that file, and Github is showing "is not included in the list" error.

iLoveDocs commented 2 years ago

The file is 28.6 MB in size. Should I upload it on the Google Drive or something and share its link?

iLoveDocs commented 2 years ago

Here's the file link:

https://drive.google.com/file/d/192IOtj_DJMBiEWZBD4icwAJg0NhhFbql/view?usp=sharing

scheglov commented 2 years ago

I see the first response with subclasses.

1641843976835:Req:{"id"::"19","method"::"search.getTypeHierarchy","params"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/foundation/change_notifier.dart","offset"::15179,"superOnly"::false},"clientRequestTime"::1641843976692}
1641843976945:Res:{"id"::"19","result"::{"hierarchyItems"::[{"classElement"::{"kind"::"CLASS","name"::"ValueNotifier","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/foundation/change_notifier.dart","offset"::15179,"length"::13,"startLine"::396,"startColumn"::7,"endLine"::396,"endColumn"::20},"flags"::0,"typeParameters"::"<T>"},"superclass"::1,"interfaces"::[4],"mixins"::[],"subclasses"::[5,6,7,8]},{"classElement"::{"kind"::"CLASS","name"::"ChangeNotifier","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/foundation/change_notifier.dart","offset"::4470,"length"::14,"startLine"::104,"startColumn"::7,"endLine"::104,"endColumn"::21},"flags"::0},"superclass"::2,"interfaces"::[3],"mixins"::[],"subclasses"::[]},{"classElement"::{"kind"::"CLASS","name"::"Object","location"::{"file"::"/Users/iLoveDocs/flutter/bin/cache/pkg/sky_engine/lib/core/object.dart","offset"::867,"length"::6,"startLine"::18,"startColumn"::7,"endLine"::18,"endColumn"::13},"flags"::0},"interfaces"::[],"mixins"::[],"subclasses"::[]},{"classElement"::{"kind"::"CLASS","name"::"Listenable","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/foundation/change_notifier.dart","offset"::2398,"length"::10,"startLine"::53,"startColumn"::16,"endLine"::53,"endColumn"::26},"flags"::1},"superclass"::2,"interfaces"::[],"mixins"::[],"subclasses"::[]},{"classElement"::{"kind"::"CLASS","name"::"ValueListenable","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/foundation/change_notifier.dart","offset"::3721,"length"::15,"startLine"::85,"startColumn"::16,"endLine"::85,"endColumn"::31},"flags"::1,"typeParameters"::"<T>"},"displayName"::"ValueListenable<T>","superclass"::3,"interfaces"::[],"mixins"::[],"subclasses"::[]},{"classElement"::{"kind"::"CLASS","name"::"ClipboardStatusNotifier","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/widgets/text_selection.dart","offset"::57643,"length"::23,"startLine"::1570,"startColumn"::7,"endLine"::1570,"endColumn"::30},"flags"::0},"superclass"::0,"interfaces"::[],"mixins"::[],"subclasses"::[]},{"classElement"::{"kind"::"CLASS","name"::"TextEditingController","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/widgets/editable_text.dart","offset"::4720,"length"::21,"startLine"::106,"startColumn"::7,"endLine"::106,"endColumn"::28},"flags"::0},"superclass"::0,"interfaces"::[],"mixins"::[],"subclasses"::[9]},{"classElement"::{"kind"::"CLASS","name"::"TransformationController","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/widgets/interactive_viewer.dart","offset"::40807,"length"::24,"startLine"::1114,"startColumn"::7,"endLine"::1114,"endColumn"::31},"flags"::0},"superclass"::0,"interfaces"::[],"mixins"::[],"subclasses"::[]},{"classElement"::{"kind"::"CLASS","name"::"VideoPlayerController","location"::{"file"::"/Users/iLoveDocs/flutter/.pub-cache/hosted/pub.dartlang.org/video_player-2.1.1/lib/video_player.dart","offset"::5764,"length"::21,"startLine"::180,"startColumn"::7,"endLine"::180,"endColumn"::28},"flags"::0},"superclass"::0,"interfaces"::[],"mixins"::[],"subclasses"::[]},{"classElement"::{"kind"::"CLASS","name"::"_TextSpanEditingController","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/material/selectable_text.dart","offset"::886,"length"::26,"startLine"::26,"startColumn"::7,"endLine"::26,"endColumn"::33},"flags"::16},"superclass"::5,"interfaces"::[],"mixins"::[],"subclasses"::[]}]}}

And the second response without subclasses.

1641843982746:Req:{"id"::"23","method"::"search.getTypeHierarchy","params"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/foundation/change_notifier.dart","offset"::15179,"superOnly"::false},"clientRequestTime"::1641843982746}
1641843982770:Res:{"id"::"23","result"::{"hierarchyItems"::[{"classElement"::{"kind"::"CLASS","name"::"ValueNotifier","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/foundation/change_notifier.dart","offset"::15179,"length"::13,"startLine"::396,"startColumn"::7,"endLine"::396,"endColumn"::20},"flags"::0,"typeParameters"::"<T>"},"superclass"::1,"interfaces"::[4],"mixins"::[],"subclasses"::[]},{"classElement"::{"kind"::"CLASS","name"::"ChangeNotifier","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/foundation/change_notifier.dart","offset"::4470,"length"::14,"startLine"::104,"startColumn"::7,"endLine"::104,"endColumn"::21},"flags"::0},"superclass"::2,"interfaces"::[3],"mixins"::[],"subclasses"::[]},{"classElement"::{"kind"::"CLASS","name"::"Object","location"::{"file"::"/Users/iLoveDocs/flutter/bin/cache/dart-sdk/lib/core/object.dart","offset"::867,"length"::6,"startLine"::18,"startColumn"::7,"endLine"::18,"endColumn"::13},"flags"::0},"interfaces"::[],"mixins"::[],"subclasses"::[]},{"classElement"::{"kind"::"CLASS","name"::"Listenable","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/foundation/change_notifier.dart","offset"::2398,"length"::10,"startLine"::53,"startColumn"::16,"endLine"::53,"endColumn"::26},"flags"::1},"superclass"::2,"interfaces"::[],"mixins"::[],"subclasses"::[]},{"classElement"::{"kind"::"CLASS","name"::"ValueListenable","location"::{"file"::"/Users/iLoveDocs/flutter/packages/flutter/lib/src/foundation/change_notifier.dart","offset"::3721,"length"::15,"startLine"::85,"startColumn"::16,"endLine"::85,"endColumn"::31},"flags"::1,"typeParameters"::"<T>"},"displayName"::"ValueListenable<T>","superclass"::3,"interfaces"::[],"mixins"::[],"subclasses"::[]}]}}

There is nothing interesting in the log, and it seems that both requests were done in change_notifier.dart, with the same offset 15179. So, I also would expect the same result.

scheglov commented 2 years ago

I'm not able to reproduce this, no matter where I request the hierarchy, once I start getting it, it stays the same, with subclasses.

iLoveDocs commented 2 years ago

Thanks for looking into it. The problem is it only happens on my main project, other dummy projects work as expected. I think I should create a new project and transfer all my code to it.

stevemessick commented 2 years ago

Yes, I think re-creating the project is probably your easiest path forward.

As @scheglov observed, the analyzer reports the correct hierarchy the first time, but not subsequently. That indicates a problem in the analyzer. Unfortunately, I don't have enough info to create an actionable issue. Any chance you can share your project with us? If not, I'll have to close this issue as it isn't a plugin problem.

iLoveDocs commented 2 years ago

@stevemessick I created a new project, it worked but after I copied all the files and folder, the problem came back that means there's an issue with my project.

To figure it out, I repeated the steps and started copying each folders from my existing project to new one one by one, and started seeing View Hierarchy after each folder copy.

I found out the problem and it was that I had copied (modified) a pub package called english_words (which supports null safety) and this was the directory which was creating an issue, including this directory was preventing View Hierarchy from working the second time. Maybe you guys can better understand it now.

I removed that directory all together, and now I'm happy with the View Hierarchy. Thank you guys for helping me dig this issue. Much appreciated 👍

stevemessick commented 2 years ago

@iLoveDocs Good work, tracking that down. I'm unclear on one thing. Did you modify english_words? If so, can you show us your changes? In theory, Dart code should not cause the hierarchy to stop working and I'd like to understand what went wrong.

iLoveDocs commented 2 years ago

@stevemessick Yes, I modified it. I'm sharing the file here.

english_words-4.0.0_modified.zip

I put it in myproject/english_words-4.0.0-modified directory, here's my pubspec.yaml file.

image

For now, it's giving me an error as I've deleted this directory but when I had this, it was working as expected. I was able to use this package's code without any issues.

iLoveDocs commented 2 years ago

@stevemessick For the changes, I only edited some strings there (I don't remember them now), but no Dart file or code was modified at all.

Thanks

NanoMichael commented 2 years ago

I'm having the same problem. The plugin does not show the type hierarchy completely. For example, the hierarchy of the type Widget shows only a few of its children.

image

UPDATE

After some tests, I found it gives the wrong hierarchy tree, for example, the hierarchy of the type Layer:

image

TextureLayer, PictureLayer, and PlatformViewLayer is not the child of the ContainerLayer, instead, it's Layer's child.

hcanyz commented 1 year ago

image image image

Issues encountered have been resolved.

alexander-doroshko commented 1 year ago

The problem has been fixed in the Dart Analysis Server. The fix is available starting from Dart SDK 2.19 (which currently has 'beta' status). No fixes needed in the Dart or Flutter plugin.