dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.08k stars 1.56k forks source link

Analyzer doesn't promt quick-fix about extension importing #56328

Open ChaserVasya opened 1 month ago

ChaserVasya commented 1 month ago

extension.dart

extension MapT<T extends Object> on T {
  Output map<Output>(Output Function(T) mapper) => mapper(this);
}

main.dart

void main(){
    String? str = null;
    str?.map(print);
}

Analyzer doesn't find quick-fix for extension importing:

Снимок экрана 2024-07-28 в 20 08 50

But quick-fix is exists: import adding. main.dart

import 'extension.dart';

void main() {
  String? str = null;
  str?.map(print);
}

Desired behavior:

Quick-fix shows import extension.dart

fvm dart info

General info

Process info

Memory CPU Elapsed time Command line
3 MB 0.0% 32-00:43:27 dart devtools --no-launch-browser
11 MB 0.0% 01-21:24:48 dart devtools --no-launch-browser
3 MB 0.0% 37-00:34:47 dart devtools --no-launch-browser
3 MB 0.0% 52-23:03:27 dart devtools --no-launch-browser
4 MB 0.0% 33-11:34:33 dart devtools --no-launch-browser
3 MB 0.0% 53-21:23:57 dart devtools --no-launch-browser
1656 MB 0.0% 01:55:10 dart language-server --client-id=Android-Studio --client-version=AI-233.14808.21 --protocol=analyzer
137 MB 0.0% 01:55:12 flutter_tools.snapshot daemon
90 MB 59.8% 00:01 main.dart-3.4.0.snapshot dart info
dart-github-bot commented 1 month ago

Summary: The Dart analyzer fails to suggest importing an extension file when a user attempts to use an extension method defined in that file. The expected behavior is for the analyzer to provide a quick-fix that adds the necessary import statement.