sdk icon indicating copy to clipboard operation
sdk copied to clipboard

[pkg/analysis_server] Sort imports fix - issue with multi-line import

Open osaxma opened this issue 1 year ago • 1 comments
trafficstars

Applying sort imports fix when there's an import statement that spans across two lines does not work properly:

https://github.com/dart-lang/sdk/assets/46427323/ce45d8a8-b0dc-4cd2-aaf2-56cf971b467e

Code Sample:

The code sample is for reproduction purposes. In reality, this is an issue with long paths where the formatter would move the show combinator to the next line if the import statement exceeds the specified formatting length.

import 'dart:math';
import 'dart:collection' 
  show HashMap;

p.s. please advice if this is Dart Code issue and I will transfer the issue there.

Dart SDK version: 3.2.3 (stable) (Tue Dec 5 17:58:33 2023 +0000) on "macos_x64"

osaxma avatar Feb 12 '24 17:02 osaxma

Thanks for the report. This is the correct repo for reporting the issue.

bwilkerson avatar Feb 12 '24 19:02 bwilkerson

@osaxma , I am unable to reproduce the issue with the given example. Sorts fine for me.

https://github.com/dart-lang/sdk/assets/2192312/76448024-c05d-40ed-9fc0-a95caec1acb7

keertip avatar Mar 28 '24 16:03 keertip

Hi @keertip

The fix in question is Sort Imports which would appear under "Quick Fix" (by clicking the light bulb or "command + dot").

I was not aware of Organize Imports but that seems to work fine (tho it deletes unused imports unlike sort imports).

osaxma avatar Mar 28 '24 17:03 osaxma

@osaxma, I do not see an option Sort Imports in the quick fix menu, either from the light bulb or command+dot. Is there anything else in your setup that's unique?

keertip avatar Mar 28 '24 18:03 keertip

Oops! I've always thought the "Sort Imports" is part of the Dart Code Extension but apparently it comes from from Dart Data Class Generator extension.

Sorry about that!

osaxma avatar Mar 28 '24 18:03 osaxma