@@ -35,6 +35,7 @@ import Data.Maybe
35
35
import qualified Data.Rope.UTF16 as Rope
36
36
import qualified Data.Set as S
37
37
import qualified Data.Text as T
38
+ import Data.Tuple.Extra (fst3 )
38
39
import Development.IDE.Core.RuleTypes
39
40
import Development.IDE.Core.Rules
40
41
import Development.IDE.Core.Service
@@ -740,7 +741,7 @@ getIndentedGroupsBy pred inp = case dropWhile (not.pred) inp of
740
741
indentation :: T. Text -> Int
741
742
indentation = T. length . T. takeWhile isSpace
742
743
743
- suggestExtendImport :: ExportsMap -> ParsedSource -> Diagnostic -> [(T. Text , Rewrite )]
744
+ suggestExtendImport :: ExportsMap -> ParsedSource -> Diagnostic -> [(T. Text , CodeActionKind , Rewrite )]
744
745
suggestExtendImport exportsMap (L _ HsModule {hsmodImports}) Diagnostic {_range= _range,.. }
745
746
| Just [binding, mod , srcspan] <-
746
747
matchRegexUnifySpaces _message
@@ -759,6 +760,7 @@ suggestExtendImport exportsMap (L _ HsModule {hsmodImports}) Diagnostic{_range=_
759
760
Just decl <- findImportDeclByRange decls range,
760
761
Just ident <- lookupExportMap binding mod
761
762
= [ ( " Add " <> renderImportStyle importStyle <> " to the import list of " <> mod
763
+ , quickFixImportKind' " extend" importStyle
762
764
, uncurry extendImport (unImportStyle importStyle) decl
763
765
)
764
766
| importStyle <- NE. toList $ importStyles ident
@@ -1138,7 +1140,7 @@ removeRedundantConstraints mContents Diagnostic{..}
1138
1140
1139
1141
-------------------------------------------------------------------------------------------------
1140
1142
1141
- suggestNewOrExtendImportForClassMethod :: ExportsMap -> ParsedSource -> Diagnostic -> [(T. Text , [Either TextEdit Rewrite ])]
1143
+ suggestNewOrExtendImportForClassMethod :: ExportsMap -> ParsedSource -> Diagnostic -> [(T. Text , CodeActionKind , [Either TextEdit Rewrite ])]
1142
1144
suggestNewOrExtendImportForClassMethod packageExportsMap ps Diagnostic {_message}
1143
1145
| Just [methodName, className] <-
1144
1146
matchRegexUnifySpaces
@@ -1157,6 +1159,7 @@ suggestNewOrExtendImportForClassMethod packageExportsMap ps Diagnostic {_message
1157
1159
-- extend
1158
1160
Just decl ->
1159
1161
[ ( " Add " <> renderImportStyle style <> " to the import list of " <> moduleNameText,
1162
+ quickFixImportKind' " extend" style,
1160
1163
[Right $ uncurry extendImport (unImportStyle style) decl]
1161
1164
)
1162
1165
| style <- importStyle
@@ -1165,15 +1168,15 @@ suggestNewOrExtendImportForClassMethod packageExportsMap ps Diagnostic {_message
1165
1168
_
1166
1169
| Just (range, indent) <- newImportInsertRange ps
1167
1170
->
1168
- (\ (unNewImport -> x) -> (x, [Left $ TextEdit range (x <> " \n " <> T. replicate indent " " )])) <$>
1169
- [ newUnqualImport moduleNameText rendered False
1171
+ (\ (kind, unNewImport -> x) -> (x, kind , [Left $ TextEdit range (x <> " \n " <> T. replicate indent " " )])) <$>
1172
+ [ (quickFixImportKind' " new " style, newUnqualImport moduleNameText rendered False )
1170
1173
| style <- importStyle,
1171
1174
let rendered = renderImportStyle style
1172
1175
]
1173
- <> [newImportAll moduleNameText]
1176
+ <> [(quickFixImportKind " new.all " , newImportAll moduleNameText) ]
1174
1177
| otherwise -> []
1175
1178
1176
- suggestNewImport :: ExportsMap -> ParsedSource -> Diagnostic -> [(T. Text , TextEdit )]
1179
+ suggestNewImport :: ExportsMap -> ParsedSource -> Diagnostic -> [(T. Text , CodeActionKind , TextEdit )]
1177
1180
suggestNewImport packageExportsMap ps@ (L _ HsModule {.. }) Diagnostic {_message}
1178
1181
| msg <- unifySpaces _message
1179
1182
, Just thingMissing <- extractNotInScopeName msg
@@ -1186,14 +1189,14 @@ suggestNewImport packageExportsMap ps@(L _ HsModule {..}) Diagnostic{_message}
1186
1189
, Just (range, indent) <- newImportInsertRange ps
1187
1190
, extendImportSuggestions <- matchRegexUnifySpaces msg
1188
1191
" Perhaps you want to add ‘[^’]*’ to the import list in the import of ‘([^’]*)’"
1189
- = sortOn fst [(imp, TextEdit range (imp <> " \n " <> T. replicate indent " " ))
1190
- | (unNewImport -> imp) <- constructNewImportSuggestions packageExportsMap (qual <|> qual', thingMissing) extendImportSuggestions
1192
+ = sortOn fst3 [(imp, kind , TextEdit range (imp <> " \n " <> T. replicate indent " " ))
1193
+ | (kind, unNewImport -> imp) <- constructNewImportSuggestions packageExportsMap (qual <|> qual', thingMissing) extendImportSuggestions
1191
1194
]
1192
1195
suggestNewImport _ _ _ = []
1193
1196
1194
1197
constructNewImportSuggestions
1195
- :: ExportsMap -> (Maybe T. Text , NotInScope ) -> Maybe [T. Text ] -> [NewImport ]
1196
- constructNewImportSuggestions exportsMap (qual, thingMissing) notTheseModules = nubOrd
1198
+ :: ExportsMap -> (Maybe T. Text , NotInScope ) -> Maybe [T. Text ] -> [( CodeActionKind , NewImport ) ]
1199
+ constructNewImportSuggestions exportsMap (qual, thingMissing) notTheseModules = nubOrdOn snd
1197
1200
[ suggestion
1198
1201
| Just name <- [T. stripPrefix (maybe " " (<> " ." ) qual) $ notInScope thingMissing]
1199
1202
, identInfo <- maybe [] Set. toList $ Map. lookup name (getExportsMap exportsMap)
@@ -1202,14 +1205,14 @@ constructNewImportSuggestions exportsMap (qual, thingMissing) notTheseModules =
1202
1205
, suggestion <- renderNewImport identInfo
1203
1206
]
1204
1207
where
1205
- renderNewImport :: IdentInfo -> [NewImport ]
1208
+ renderNewImport :: IdentInfo -> [( CodeActionKind , NewImport ) ]
1206
1209
renderNewImport identInfo
1207
1210
| Just q <- qual
1208
- = [newQualImport m q]
1211
+ = [(quickFixImportKind " new.qualified " , newQualImport m q) ]
1209
1212
| otherwise
1210
- = [newUnqualImport m (renderImportStyle importStyle) False
1213
+ = [(quickFixImportKind' " new " importStyle, newUnqualImport m (renderImportStyle importStyle) False )
1211
1214
| importStyle <- NE. toList $ importStyles identInfo] ++
1212
- [newImportAll m]
1215
+ [(quickFixImportKind " new.all " , newImportAll m) ]
1213
1216
where
1214
1217
m = moduleNameText identInfo
1215
1218
@@ -1554,3 +1557,10 @@ renderImportStyle (ImportViaParent x p) = p <> "(" <> x <> ")"
1554
1557
unImportStyle :: ImportStyle -> (Maybe String , String )
1555
1558
unImportStyle (ImportTopLevel x) = (Nothing , T. unpack x)
1556
1559
unImportStyle (ImportViaParent x y) = (Just $ T. unpack y, T. unpack x)
1560
+
1561
+ quickFixImportKind' :: T. Text -> ImportStyle -> CodeActionKind
1562
+ quickFixImportKind' x (ImportTopLevel _) = CodeActionUnknown $ " quickfix.import." <> x <> " .list.topLevel"
1563
+ quickFixImportKind' x (ImportViaParent _ _) = CodeActionUnknown $ " quickfix.import." <> x <> " .list.withParent"
1564
+
1565
+ quickFixImportKind :: T. Text -> CodeActionKind
1566
+ quickFixImportKind x = CodeActionUnknown $ " quickfix.import." <> x
0 commit comments