@@ -52,6 +52,11 @@ import Development.IDE.GHC.Compat hiding ((<+>))
52
52
import Development.IDE.GHC.Compat.Util (mkFastString )
53
53
import Development.IDE.Graph.Classes
54
54
import GHC.Generics (Generic )
55
+ import GHC.Num (integerFromInt )
56
+ import GHC.Parser.Annotation (EpAnn (entry ),
57
+ HasLoc (getHasLoc ),
58
+ realSrcSpan )
59
+ import GHC.Types.PkgQual (RawPkgQual (NoRawPkgQual ))
55
60
import Ide.Plugin.Error (PluginError (.. ),
56
61
getNormalizedFilePathE ,
57
62
handleMaybe )
@@ -250,6 +255,23 @@ importPackageInlayHintProvider _ state _ InlayHintParams {_textDocument = TextDo
250
255
ast <- handleMaybe
251
256
(PluginRuleFailed " GetHieAst" )
252
257
(getAsts hieAst Map. !? (HiePath . mkFastString . fromNormalizedFilePath) nfp)
258
+ parsedModule <- runActionE " GADT.GetParsedModuleWithComments" state $ useE GetParsedModule nfp
259
+ let (L _ hsImports) = hsmodImports <$> pm_parsed_source parsedModule
260
+
261
+ let isPackageImport :: ImportDecl GhcPs -> Bool
262
+ isPackageImport ImportDecl {ideclPkgQual = NoRawPkgQual } = False
263
+ isPackageImport _ = True
264
+
265
+ annotationToLineNumber :: EpAnn a -> Integer
266
+ annotationToLineNumber = integerFromInt . srcSpanEndLine . realSrcSpan . getHasLoc . entry
267
+
268
+ packageImportLineNumbers :: S. Set Integer
269
+ packageImportLineNumbers =
270
+ S. fromList $
271
+ hsImports
272
+ & filter (\ (L _ importDecl) -> isPackageImport importDecl)
273
+ & map (\ (L annotation _) -> annotationToLineNumber annotation)
274
+
253
275
hintsInfo <- liftIO $ getAllImportedPackagesHints (hscEnv hscEnvEq) (moduleName hieModule) ast
254
276
-- Sort the hints by position and group them by line
255
277
-- Show only first hint in each line
@@ -258,6 +280,8 @@ importPackageInlayHintProvider _ state _ InlayHintParams {_textDocument = TextDo
258
280
compare l1 l2 <> compare c1 c2)
259
281
& groupBy (\ (Range (Position l1 _) _, _) (Range (Position l2 _) _, _) -> l1 == l2)
260
282
& map Data.List.NonEmpty. head
283
+ -- adding 1 because RealSrcLoc begins with 1
284
+ & filter (\ (Range (Position l _) _, _) -> S. notMember (toInteger l + 1 ) packageImportLineNumbers)
261
285
let inlayHints = [ generateInlayHint newRange txt
262
286
| (range, txt) <- selectedHintsInfo
263
287
, Just newRange <- [toCurrentRange pmap range]
0 commit comments