@@ -31,7 +31,8 @@ import Data.Functor ((<&>))
31
31
import qualified Data.IntMap as IM (IntMap , elems ,
32
32
fromList , (!?) )
33
33
import Data.IORef (readIORef )
34
- import Data.List (singleton )
34
+ import Data.List (singleton , sortBy )
35
+ import Data.List.NonEmpty (groupBy , head )
35
36
import qualified Data.Map.Strict as Map
36
37
import Data.Maybe (isJust , isNothing ,
37
38
listToMaybe , mapMaybe )
@@ -250,8 +251,13 @@ importPackageInlayHintProvider _ state _ InlayHintParams {_textDocument = TextDo
250
251
(PluginRuleFailed " GetHieAst" )
251
252
(getAsts hieAst Map. !? (HiePath . mkFastString . fromNormalizedFilePath) nfp)
252
253
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
255
261
let inlayHints = [ generateInlayHint newRange txt
256
262
| (range, txt) <- selectedHintsInfo
257
263
, Just newRange <- [toCurrentRange pmap range]
0 commit comments