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.21k stars 1.57k forks source link

Analyzer output doesn't contain traceable target links #50832

Open humblerookie opened 1 year ago

humblerookie commented 1 year ago

Dart/Flutter analyzer emits broken links that IntelliJ isn't able to map for eg. here's the output of a sample project

Analyzing project-template-flutter...                                   

   info • Unused import: 'package:fast_immutable_collections/fast_immutable_collections.dart' • lib/data/persistence/characters_dao.dart:1:8 • unused_import
   info • Unused import: 'package:flutter/cupertino.dart' • lib/domain/core/stream_utils.dart:1:8 • unused_import

Whereas the import is fully qualified with the package: prefix making it clickable and traceable to source in IntelliJ, the actual file that needs change isn't and is misleading always warranting a false click from the user as shown in the image below.

image

Here are my setup details.

Flutter 3.3.9 • channel stable • https://github.com/flutter/flutter.git
Framework • revision b8f7f1f986 (4 weeks ago) • 2022-11-23 06:43:51 +0900
Engine • revision 8f2221fbef
Tools • Dart 2.18.5 • DevTools 2.15.0
asashour commented 1 year ago

Is there a a chance to share a small reproducible example (a minimal project or file)?

humblerookie commented 1 year ago

Sure PFA. Running flutter analyze on this would result in this Screenshot 2022-12-23 at 12 04 37 AM

issue-demo.zip

asashour commented 1 year ago

I understand that for the below line:

info - Unused import: 'package:flutter/foundation.dart' - lib/main.dart:2:8 - unused_import                          

it is expected that lib/main.dart:2:8 is clickable and points to the given position. And the link 'package:flutter/foundation.dart' isn't important, since it is not the user code.

lrhn commented 1 year ago

The analyzer emits plain text, so it seems intellij makes anything URI-shaped into a link, like the package: URI, and not plain paths, even if they are valid relative to the project.

humblerookie commented 1 year ago

@asashour precisely.

jacob314 commented 1 year ago

Are you aware that the analyzer output also shows up in the Dart Analysis Tool Window in IntelliJ? I would recommend using that window over the command line output both because the links are clickable, the analysis results update realtime with code changes, and you can right click on lines to trigger quick fixes for issues like unused import that have quick fixes.

humblerookie commented 1 year ago

@jacob314 Thanks, Yes I'm aware, the issue is I run multiple checks not limited to the analyzer output, so it's easier to run them all at once from a command line script. While I could still probably switch to the dart analysis window once the analyzer command fails, it could be improved upon UX wise.