Skip to content

Commit 3305973

Browse files
committed
Filter explict imports inlay hints by visible range
1 parent b7da1f5 commit 3305973

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Ide.Plugin.ExplicitImports
1111
( descriptor
1212
, descriptorForModules
1313
, abbreviateImportTitle
14+
, squashedAbbreviateImportTitle
1415
, Log(..)
1516
) where
1617

@@ -174,11 +175,12 @@ lensResolveProvider _ _ _ _ _ rd = do
174175

175176

176177
inlayHintProvider :: Recorder (WithPriority Log) -> PluginMethodHandler IdeState 'Method_TextDocumentInlayHint
177-
inlayHintProvider _ state _ InlayHintParams {_textDocument = TextDocumentIdentifier {_uri}} = do
178+
inlayHintProvider _ state _ InlayHintParams {_textDocument = TextDocumentIdentifier {_uri}, _range = visibleRange} = do
178179
nfp <- getNormalizedFilePathE _uri
179180
(ImportActionsResult {forLens, forResolve}, pm) <- runActionE "ImportActions" state $ useWithStaleE ImportActions nfp
180181
let inlayHints = [ generateInlayHints newRange ie
181182
| (range, int) <- forLens
183+
, range < visibleRange
182184
, Just newRange <- [toCurrentRange pm range]
183185
, Just ie <- [forResolve IM.!? int]]
184186
pure $ InL inlayHints
@@ -194,10 +196,10 @@ inlayHintProvider _ state _ InlayHintParams {_textDocument = TextDocumentIdentif
194196
, _paddingRight = Nothing
195197
, _data_ = Nothing
196198
}
197-
mkLabel :: ImportEdit -> T.Text |? [InlayHintLabelPart]
199+
mkLabel :: ImportEdit -> T.Text |? [InlayHintLabelPart]
198200
mkLabel (ImportEdit{ieResType, ieText}) =
199-
let title ExplicitImport = abbreviateImportTitle $ (T.intercalate " " . filter (not . T.null) . T.split isSpace . T.dropWhile (/= '(')) ieText
200-
title RefineImport = T.intercalate ", " (T.lines ieText)
201+
let title ExplicitImport = squashedAbbreviateImportTitle ieText
202+
title RefineImport = T.intercalate ", " (T.lines ieText)
201203
in InL $ title ieResType
202204

203205

@@ -445,7 +447,6 @@ isExplicitImport _ = False
445447
maxColumns :: Int
446448
maxColumns = 120
447449

448-
-- | The title of the command is ideally the minimal explicit import decl, but
449450
-- we don't want to create a really massive code lens (and the decl can be extremely large!).
450451
-- So we abbreviate it to fit a max column size, and indicate how many more items are in the list
451452
-- after the abbreviation
@@ -478,6 +479,10 @@ abbreviateImportTitle input =
478479
else actualPrefix <> suffixText
479480
in title
480481

482+
squashedAbbreviateImportTitle :: T.Text -> T.Text
483+
squashedAbbreviateImportTitle ieText = abbreviateImportTitle $ (T.intercalate " " . filter (not . T.null) . T.split isSpace . T.dropWhile (/= '(')) ieText
484+
485+
-- | The title of the command is ideally the minimal explicit import decl, but
481486
--------------------------------------------------------------------------------
482487

483488

0 commit comments

Comments
 (0)