sdk
sdk copied to clipboard
[analyzer] Code inspections are interruptted frequently
This tracker is for issues related to Analyzer.
Summary
After Dart 2.17, inspections are interrupted frequently when manipulating codes. See the video for a better understanding of what happened:
https://user-images.githubusercontent.com/15884415/170198739-cd7e6d2e-8afd-47b3-97d8-e53f68577663.mp4

flutter doctor -v
[✓] Flutter (Channel stable, 3.0.1, on Microsoft Windows [版本 10.0.22000.675], locale zh-CN)
• Flutter version 3.0.1 at X:\SDK\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision fb57da5f94 (5 days ago), 2022-05-19 15:50:29 -0700
• Engine revision caaafc5604
• Dart version 2.17.1
• DevTools version 2.12.2
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn
[✓] IntelliJ IDEA Ultimate Edition (version 2022.1)
• IntelliJ at X:\IDEs\apps\IDEA-U\ch-0\221.5080.210
• Flutter plugin version 67.1.4
• Dart plugin version 221.5588
analysis_options.yaml
analyzer:
errors:
# allow having TODOs in the code
todo: ignore
linter:
rules:
- always_declare_return_types
- always_put_control_body_on_new_line
- always_require_non_null_named_parameters
- always_specify_types
- annotate_overrides
- avoid_bool_literals_in_conditional_expressions
- avoid_classes_with_only_static_members
- avoid_dynamic_calls
- avoid_empty_else
- avoid_equals_and_hash_code_on_mutable_classes
- avoid_escaping_inner_quotes
- avoid_field_initializers_in_const_classes
- avoid_function_literals_in_foreach_calls
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_redundant_argument_values
- avoid_relative_lib_imports
- avoid_renaming_method_parameters
- avoid_return_types_on_setters
- avoid_returning_null_for_void
- avoid_shadowing_type_parameters
- avoid_single_cascade_in_expression_statements
- avoid_slow_async_io
- avoid_type_to_string
- avoid_types_as_parameter_names
- avoid_unnecessary_containers
- avoid_unused_constructor_parameters
- avoid_void_async
- await_only_futures
- camel_case_extensions
- camel_case_types
- cancel_subscriptions
- control_flow_in_finally
- deprecated_consistency
- directives_ordering
- empty_catches
- empty_constructor_bodies
- empty_statements
- exhaustive_cases
- file_names
- flutter_style_todos
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
- leading_newlines_in_multiline_strings
- library_names
- library_prefixes
- list_remove_unrelated_type
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_duplicate_case_values
- no_logic_in_create_state
- noop_primitive_operations
- non_constant_identifier_names
- null_check_on_nullable_type_parameter
- null_closures
- overridden_fields
- package_api_docs
- package_names
- package_prefixed_library_names
- prefer_adjacent_string_concatenation
- prefer_asserts_in_initializer_lists
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_const_constructors
- prefer_const_constructors_in_immutables
- prefer_const_declarations
- prefer_const_literals_to_create_immutables
- prefer_contains
- prefer_equal_for_default_values
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
- prefer_for_elements_to_map_fromIterable
- prefer_foreach
- prefer_function_declarations_over_variables
- prefer_generic_function_type_aliases
- prefer_if_elements_to_conditional_expressions
- prefer_if_null_operators
- prefer_initializing_formals
- prefer_inlined_adds
- prefer_interpolation_to_compose_strings
- prefer_is_empty
- prefer_is_not_empty
- prefer_is_not_operator
- prefer_iterable_whereType
- prefer_null_aware_operators
- prefer_single_quotes
- prefer_spread_collections
- prefer_typing_uninitialized_variables
- prefer_void_to_null
- provide_deprecation_message
- recursive_getters
- require_trailing_commas
- sized_box_for_whitespace
- slash_for_doc_comments
- sort_constructors_first
- sort_unnamed_constructors_first
- test_types_in_equals
- throw_in_finally
- tighten_type_of_initializing_formals
- type_init_formals
- unnecessary_await_in_return
- unnecessary_brace_in_string_interps
- unnecessary_const
- unnecessary_getters_setters
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_checks
- unnecessary_null_in_if_null_operators
- unnecessary_nullable_for_final_variable_declarations
- unnecessary_overrides
- unnecessary_parenthesis
- unnecessary_statements
- unnecessary_string_escapes
- unnecessary_string_interpolations
- unnecessary_this
- unrelated_type_equality_checks
- use_full_hex_values_for_flutter_colors
- use_function_type_syntax_for_parameters
- use_is_even_rather_than_modulo
- use_key_in_widget_constructors
- use_late_for_private_fields_and_variables
- use_named_constants
- use_raw_strings
- use_rethrow_when_possible
- use_test_throws_matchers
- valid_regexps
- void_checks
I am having this for some time, and I thought it was only me (after opening #48611).
@AlexV525 please update the description with your flutter doctor -v.
flutter doctor -v
[√] Flutter (Channel master, 3.1.0-0.0.pre.897, on Microsoft Windows [Version 10.0.19044.1645], locale en-US)
• Flutter version 3.1.0-0.0.pre.897 at c:\use\flutter
• Upstream repository https://github.com/asashour/flutter.git
• Framework revision 680a8192b0 (3 hours ago), 2022-05-24 21:23:09 -0700
• Engine revision 7274f79325
• Dart version 2.18.0 (build 2.18.0-149.0.dev)
• DevTools version 2.13.1
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at C:\Users\ahmed_ashour\AppData\Local\Android\Sdk
• Platform android-32, build-tools 32.0.0
• ANDROID_SDK_ROOT = C:\Users\ahmed_ashour\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.5)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.1.32414.318
• Windows 10 SDK version 10.0.20348.0
[√] Android Studio (version 2021.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
[√] IntelliJ IDEA Community Edition (version 2022.1)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2.1
• Flutter plugin version 67.1.4
• Dart plugin version 221.5591.58
[√] IntelliJ IDEA Ultimate Edition (version 2022.1)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 221.5080.93
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin version 221.5480
[√] VS Code (version 1.67.1)
• VS Code at C:\Users\ahmed_ashour\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.40.0
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19044.1645]
• Chrome (web) • chrome • web-javascript • Google Chrome 101.0.4951.67
• Edge (web) • edge • web-javascript • Microsoft Edge 101.0.1210.47
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
I am having this for some time, and I thought it was only me (after opening #48611).
Yeah, we have received a couple of developers' feedback from our community about the same issue recently.
@AlexV525 please update the description with your
flutter doctor -v.
Updated. I've also added the analysis_options.yaml that I'm using.
The protocol between the Dart analysis server (DAS) and IDE is by design eventually consistent, meaning that there periods when IDE and results from DAS are inconsistent, but eventually you will get for example the semantic highlighting that corresponds to the latest state of the file. If this does not happen, then this is bug that I'd like to be able to reproduce.
If it does happen eventually, but the transitive state is too annoying :-), one mitigation that we could consider is to include a signature of the file content for which the highlighting was produced, so that IDE will check it and apply only if they match. @jwren WDYT?
The protocol between the Dart analysis server (DAS) and IDE is by design eventually consistent, meaning that there periods when IDE and results from DAS are inconsistent, but eventually you will get for example the semantic highlighting that corresponds to the latest state of the file. If this does not happen, then this is bug that I'd like to be able to reproduce.
If it does happen eventually, but the transitive state is too annoying :-), one mitigation that we could consider is to include a signature of the file content for which the highlighting was produced, so that IDE will check it and apply only if they match. @jwren WDYT?
Thanks for the explanation. Actually, it does happen eventually, but it takes almost 10 seconds of the period. It's not like something that used to occur before.
I use the same project to test by switching between Flutter 2.10, Flutter 3, and the latest master of Flutter, it seems to be introduced by some commits between 2.10 and 3. Will do more bisect.
Flutter 2.10.5:
https://user-images.githubusercontent.com/15884415/170394649-f70421bc-4e1b-476d-aba7-7817d781c17a.mp4
Flutter 3.0.1:
https://user-images.githubusercontent.com/15884415/170394723-7344b887-6775-44b9-b959-66c0bdc4d66f.mp4
Done bisecting and the https://github.com/flutter/flutter/commit/2d186585136bae7ee64a7298e34cc3fedaccad8d is the first bad commit, which means the issue might be introduced between 24bf86f and 5bc905e:
2d186585136bae7ee64a7298e34cc3fedaccad8d is the first bad commit
commit 2d186585136bae7ee64a7298e34cc3fedaccad8d
Author: engine-flutter-autoroll <[email protected]>
Date: Thu Mar 17 15:55:13 2022 -0400
Roll Engine from 46c2ccae24e4 to dfde2aad73f9 (9 revisions) (#100270)
* 09d7bccc0 Optionally specify the target dir in tools/gn (flutter/engine#32065)
* a00ba24e9 Fix done button click not blur in iOS keyboard (flutter/engine#31718)
* 81547d1f7 Add a display list op to clear to transformation stack. (flutter/engine#32050)
* 2309bcc8c Add WASM target in gn (flutter/engine#31670)
* 852e800f4 [web] Remove the --passfail flag when calling goldctl in post-submit (flutter/engine#32071)
* eb1c50d46 Fix issues with nested gradients in html renderer. (flutter/engine#31887)
* fb0fd744e Update the magic number for JPEG to just FF D8 FF. (flutter/engine#32076)
* 233c17cb7 Wrap the global timeline event handler callback in a std::atomic (flutter/engine#32073)
* dfde2aad7 Roll Dart SDK from 24bf86f16411 to 5bc905e69609 (9 revisions) (flutter/engine#32075)
I too have been seeing this issue for a while now and found something that might help somebody diagnose it. I've found that this only happens when VCS integration in IntelliJ is turned on, and only occurs when a file is changed back to its unmodified state. Turning off VCS integration makes the problem disappear, and making further changes to already modified file doesn't exhibit the problem. Also, this happens on both Windows and MacOS in all recent versions of IntelliJ/Android Studio.
Hope this helps identify the issue.
@scheglov Can we have a higher priority here? As @RobertV212 said, this is annoying when codes are involved with version controls, also it almost breaks the analysis in my project when a file is not changed in the version control and usages of this file are reporting errors. Regenerate doesn't help, and only will errors be dismissed by changing it's real content. The code highlight flashes like a flashlight.

cc @asashour @mit-mit
73 commits between https://github.com/dart-lang/sdk/commit/24bf86f164113079745a261022f794681bcbcb10 and https://github.com/dart-lang/sdk/commit/5bc905e6960916bc250511fcb66452a4aac5c0e4. 22 are the analyzer-related (excluding test changes):
- https://github.com/dart-lang/sdk/commit/0d1cafe1dbd116ba16c10568fcf8edf4c17d8655 - "Don't check consistency if an exception occurs during analysis." (suspicious)
- https://github.com/dart-lang/sdk/commit/1ffba326095d2467c5ae2db60190d1746b587d8b - "Rework type inference logic to avoid redundant constraint gathering." (unlikely)
- https://github.com/dart-lang/sdk/commit/2ce7aa3b169b13bbdbfbdb45d8b56f46c4ee2c33 - "Add a fix for the use_enums lint" (unlikely)
- https://github.com/dart-lang/sdk/commit/0d130c3148e67d5b7340e3b5c1059cf4bc4f527c - "fix for unnecessary_null_aware_assignments" (unlikely)
- https://github.com/dart-lang/sdk/commit/7642021418eabbcfb99725b2929726ac2372181a - "Verify invariant of TypeConstraintGatherer.trySubtypeMatch." (unlikely)
- https://github.com/dart-lang/sdk/commit/b9a7f00a9adfff52fab53b61aa43a5ece7c30fee - "[analysis_server] Add server snippets for classes, and test/groups in test files" (unlikely)
- https://github.com/dart-lang/sdk/commit/6de7ea74328ef752a00db3d6b1e8a44d354caea3 - "Don't remove overlays immediately, wait for the next watch event." (suspicious)
- https://github.com/dart-lang/sdk/commit/e1e54ef807b3eaa456394ea2a7a80c469835e1d0 - "Catch InconsistentAnalysisException in getParsedUnit() in server." (suspicious)
- https://github.com/dart-lang/sdk/commit/5eba89dc30b1db0d3f463cc817547bfe108cc937 - "Rewrite the assist to convert to super parameters" (unlikely)
- https://github.com/dart-lang/sdk/commit/189cf35a96010c85e1aa2ae07a0449aabd084e18 - "Add ClassElementImpl.isMacro" (unlikely)
- https://github.com/dart-lang/sdk/commit/935faa6c8a860125a4762296ebca5ff7b4174281 - "Return potentially affected files from applyPendingFileChanges()" (suspicious)
- https://github.com/dart-lang/sdk/commit/aec5b376d8ad88b13a0b757bf3fc839baddc742b - "Fix handling of named constructors in convert_to_super_parameters" (unlikely)
- https://github.com/dart-lang/sdk/commit/0d1cafe1dbd116ba16c10568fcf8edf4c17d8655 - "Don't check consistency if an exception occurs during analysis." (suspicious)
- https://github.com/dart-lang/sdk/commit/111101039b3a0f5363d3daca3e1458713feb4e6c - "Don't create default constructors for mixins." (unlikely)
- https://github.com/dart-lang/sdk/commit/c4752d7f20f5c854a3445a875dc2ee7193e758c8 - "Include null suffix in Cider error verifier diagnostics." (unlikely)
- https://github.com/dart-lang/sdk/commit/c305b6b6f07c119f54be984469c9d383f26c712e - "bump linter to 1.20.0" (unlikely)
- https://github.com/dart-lang/sdk/commit/8fbb5bbf5b15fa1e0defff6c2d862fd8b41ef0fb - "Remove GenericInferrer.considerExtendsClause." (unlikely)
- https://github.com/dart-lang/sdk/commit/41a330b8f45ee062cdea637cc71d31342ca666a9 - "Remove _functionNestingLevel from flow analysis logic." (unlikely)
- https://github.com/dart-lang/sdk/commit/7d6c965fc90d18d22065a3076658ef3b86288957 - "[analysis_server] Handle InconsistentAnalysisException centrally in request handlers" (suspicious)
- https://github.com/dart-lang/sdk/commit/094c598703402dbb8ba5831e76053f14f9c9662e - "[analysis_server] Change empty linked edit groups to have placeholder text" (Maybe suspicious?)
- https://github.com/dart-lang/sdk/commit/37e67cccfab6f07347c4cb3207b9abec67b26108 - "Add a quick fix for convert_to_super_parameters" (unlikely)
- https://github.com/dart-lang/sdk/commit/f58adc5dc3e9ecd9186771a1e62df84372cbcbe4 - "Rework heuristic for "fixing" type parameters after downwards inference." (unlikely)
@scheglov would you mind taking a look at this? In particular, https://github.com/dart-lang/sdk/commit/0d1cafe1dbd116ba16c10568fcf8edf4c17d8655, https://github.com/dart-lang/sdk/commit/6de7ea74328ef752a00db3d6b1e8a44d354caea3, https://github.com/dart-lang/sdk/commit/e1e54ef807b3eaa456394ea2a7a80c469835e1d0, https://github.com/dart-lang/sdk/commit/935faa6c8a860125a4762296ebca5ff7b4174281, https://github.com/dart-lang/sdk/commit/0d1cafe1dbd116ba16c10568fcf8edf4c17d8655, and https://github.com/dart-lang/sdk/commit/7d6c965fc90d18d22065a3076658ef3b86288957 seem like they very much could affect this flickering bug. Maybe https://github.com/dart-lang/sdk/commit/094c598703402dbb8ba5831e76053f14f9c9662e as well. The videos above make it clear that the UI was previously much more calm, and left syntax highlighting in particular in a steady, happy place than in Dart 2.17.0
I think we can find a Dart project for this. When I was developing flutter_tools it also happened. I will provide feedback later.
I have some doubts that this is caused by the analyzer itself. If the code and the highlighting eventually get consistent, this means that the analyzer invalidates and analysis what necessary.
I tried to do a bunch of insert a line, undo, insert again, undo sequences as fast as I can in my IntelliJ, and it does happen, but extremely rarely, and quickly fixes itself. Almost always semantic highlighting of any code below or above is absolutely stable.
I tried to do a bunch of insert a line, undo, insert again, undo sequences as fast as I can in my IntelliJ, and it does happen, but extremely rarely, and quickly fixes itself. Almost always semantic highlighting of any code below or above is absolutely stable.
Let me provide some reproducible steps, with a standalone Dart project, which I can easily reproduce locally.
- Clone the dart project: https://github.com/AlexV525/download_files.
- Open it with IDEA and wait until the project is analyzed.
- Follow the screen record, that is: click at the end of line 10, delete the
;, then press revert (Ctrl+Z).
https://user-images.githubusercontent.com/15884415/186723798-639010d2-6a13-4481-8bcc-e93e0a5874b9.mp4
OK, I can reproduce it sometimes. The observation that it takes 10 seconds is the right one, and it makes me think that this happens because of https://github.com/dart-lang/sdk/commit/6de7ea74328ef752a00db3d6b1e8a44d354caea3. There might be some race condition that we don't handle correctly.
OK, I can reproduce it sometimes.
Great to hear that. Meanwhile should I do more bisecting since I'm trying to setup the SDK environment?
I don't know. If my suspicion is right, there is no need to do bisecting anymore.
I don't know. If my suspicion is right, there is no need to do bisecting anymore.
Well since it is able to reproduce I think there's no need to.
Any news on this?
Has any progress been made on this? I have also observed that it takes exactly 10 seconds to correct itself so I suspect that commit is likely the culprit.
No news on this.
I just can't believe that such issue will stay in P3 and hung for half a year. These kind of issues will destroy developers' confidence during their development since they will lost all references and analysis for many many 10s. Maybe some developers don't realize that it's an issue, then accept it as a default behavior. It's kinda frustrating TBH.
cc @DanTup @asashour who worked on the analysis server recently.
One of the things I would imagine, that could help speed this up, is to try to look into the request/response in the analysis server logs, in order to find the reason (which may also be with IntelliJ plugin).
From the issues history, P3 (even P2) could possibly take months (if not years), I would question the value of adding arbitrary contributors. The team sees the discussions and I trust they work on their priority list.
https://github.com/dart-lang/sdk/commit/6de7ea74328ef752a00db3d6b1e8a44d354caea3 was also the decided culprit in https://github.com/dart-lang/sdk/issues/50960.
https://dart-review.googlesource.com/c/sdk/+/278883
Can we CP this into 2.19 beta?