@@ -31,7 +31,8 @@ import Data.Functor ((<&>))
3131import qualified Data.IntMap as IM (IntMap , elems ,
3232 fromList , (!?) )
3333import Data.IORef (readIORef )
34- import Data.List (singleton )
34+ import Data.List (singleton , sortBy )
35+ import Data.List.NonEmpty (groupBy , head )
3536import qualified Data.Map.Strict as Map
3637import Data.Maybe (isJust , isNothing ,
3738 listToMaybe , mapMaybe )
@@ -250,8 +251,13 @@ importPackageInlayHintProvider _ state _ InlayHintParams {_textDocument = TextDo
250251 (PluginRuleFailed " GetHieAst" )
251252 (getAsts hieAst Map. !? (HiePath . mkFastString . fromNormalizedFilePath) nfp)
252253 hintsInfo <- liftIO $ getAllImportedPackagesHints (hscEnv hscEnvEq) (moduleName hieModule) ast
253- -- Filter out empty package names
254- let selectedHintsInfo = hintsInfo & filter (\ (_, mbPkg) -> (not . T. null ) mbPkg)
254+ -- Sort the hints by position and group them by line
255+ -- Show only first hint in each line
256+ let selectedHintsInfo = hintsInfo
257+ & sortBy (\ (Range (Position l1 c1) _, _) (Range (Position l2 c2) _, _) ->
258+ compare l1 l2 <> compare c1 c2)
259+ & groupBy (\ (Range (Position l1 _) _, _) (Range (Position l2 _) _, _) -> l1 == l2)
260+ & map Data.List.NonEmpty. head
255261 let inlayHints = [ generateInlayHint newRange txt
256262 | (range, txt) <- selectedHintsInfo
257263 , Just newRange <- [toCurrentRange pmap range]
0 commit comments