Skip to content

Commit 621f2d6

Browse files
committed
Show only one inlay hint in each line
1 parent bd0e4ca commit 621f2d6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import Data.Functor ((<&>))
3131
import qualified Data.IntMap as IM (IntMap, elems,
3232
fromList, (!?))
3333
import Data.IORef (readIORef)
34-
import Data.List (singleton)
34+
import Data.List (singleton, sortBy)
35+
import Data.List.NonEmpty (groupBy, head)
3536
import qualified Data.Map.Strict as Map
3637
import 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

Comments
 (0)