@@ -1520,7 +1520,7 @@ suggestNewImport packageExportsMap ps fileContents Diagnostic{_message}
1520
1520
, Just (range, indent) <- newImportInsertRange ps fileContents
1521
1521
, extendImportSuggestions <- matchRegexUnifySpaces msg
1522
1522
" Perhaps you want to add ‘[^’]*’ to the import list in the import of ‘([^’]*)’"
1523
- = let suggestions = nubSort
1523
+ = let suggestions = nubSortBy simpleCompareImportSuggestion
1524
1524
(constructNewImportSuggestions packageExportsMap (qual <|> qual', thingMissing) extendImportSuggestions) in
1525
1525
map (\ (ImportSuggestion _ kind (unNewImport -> imp)) -> (imp, kind, TextEdit range (imp <> " \n " <> T. replicate indent " " ))) suggestions
1526
1526
where
@@ -1529,7 +1529,7 @@ suggestNewImport _ _ _ _ = []
1529
1529
1530
1530
constructNewImportSuggestions
1531
1531
:: ExportsMap -> (Maybe T. Text , NotInScope ) -> Maybe [T. Text ] -> [ImportSuggestion ]
1532
- constructNewImportSuggestions exportsMap (qual, thingMissing) notTheseModules = nubOrd
1532
+ constructNewImportSuggestions exportsMap (qual, thingMissing) notTheseModules = nubOrdBy simpleCompareImportSuggestion
1533
1533
[ suggestion
1534
1534
| Just name <- [T. stripPrefix (maybe " " (<> " ." ) qual) $ notInScope thingMissing] -- strip away qualified module names from the unknown name
1535
1535
, identInfo <- maybe [] Set. toList $ Map. lookup name (getExportsMap exportsMap) -- look up the modified unknown name in the export map
@@ -1568,16 +1568,18 @@ constructNewImportSuggestions exportsMap (qual, thingMissing) notTheseModules =
1568
1568
| otherwise = 0
1569
1569
m = moduleNameText identInfo
1570
1570
1571
- -- | Implements a lexicographic order for import suggestions.
1572
- -- First compares the importance score in DESCENDING order.
1573
- -- If the scores are equal it compares the import names alphabetical order.
1574
1571
data ImportSuggestion = ImportSuggestion ! Int ! CodeActionKind ! NewImport
1575
1572
deriving ( Eq )
1576
1573
1577
- instance Ord ImportSuggestion where
1578
- compare (ImportSuggestion s1 _ i1) (ImportSuggestion s2 _ i2)
1579
- | s1 == s2 = compare i1 i2
1580
- | otherwise = flip compare s1 s2
1574
+ -- | Implements a lexicographic order for import suggestions that ignores the code action.
1575
+ -- First it compares the importance score in DESCENDING order.
1576
+ -- If the scores are equal it compares the import names alphabetical order.
1577
+ --
1578
+ -- TODO: this should be a correct Ord instance but CodeActionKind does not implement a Ord
1579
+ -- which would lead to an unlawful Ord instance.
1580
+ simpleCompareImportSuggestion :: ImportSuggestion -> ImportSuggestion -> Ordering
1581
+ simpleCompareImportSuggestion (ImportSuggestion s1 _ i1) (ImportSuggestion s2 _ i2)
1582
+ = flip compare s1 s2 <> compare i1 i2
1581
1583
1582
1584
newtype NewImport = NewImport { unNewImport :: T. Text}
1583
1585
deriving (Show , Eq , Ord )
0 commit comments