@@ -24,6 +24,7 @@ import Control.Monad.IO.Class (MonadIO (liftIO))
2424import Control.Monad.Trans.Class (MonadTrans (lift ))
2525import Data.Aeson.Types (toJSON )
2626import qualified Data.Aeson.Types as A
27+ import qualified Data.Foldable as F
2728import Data.Generics (GenericQ , everything ,
2829 extQ , mkQ , something )
2930import Data.List (find )
@@ -89,6 +90,7 @@ import Language.LSP.Protocol.Types (ApplyWorkspaceEditParams
8990 TextDocumentIdentifier (TextDocumentIdentifier ),
9091 TextEdit (TextEdit ),
9192 WorkspaceEdit (WorkspaceEdit ),
93+ isSubrangeOf ,
9294 type (|? ) (.. ))
9395import Text.Regex.TDFA ((=~) )
9496
@@ -127,7 +129,7 @@ properties = emptyProperties
127129 ] Always
128130 & defineBooleanProperty # localBindingInlayHintOn
129131 " Display inlay hints of local bindings"
130- True
132+ False
131133
132134codeLensProvider :: PluginMethodHandler IdeState Method_TextDocumentCodeLens
133135codeLensProvider ideState pId CodeLensParams {_textDocument = TextDocumentIdentifier uri} = do
@@ -538,7 +540,7 @@ generateWhereInlayHints name ty range offset =
538540 insertRange = Range startPos' startPos'
539541 in TextEdit insertRange (text <> " \n " <> T. replicate (fromIntegral insertChar) " " )
540542
541- generateWhereLens :: PluginId -> Uri -> Id -> T. Text -> Range -> Int -> CodeLens
543+ generateWhereLens :: PluginId -> Uri -> LocalBindingHintRenderer CodeLens
542544generateWhereLens plId uri _ title range _ = CodeLens range (Just cmd) Nothing
543545 where
544546 cmd = mkLspCommand plId typeLensCommandId title (Just [A. toJSON (makeEdit range title)])
@@ -557,8 +559,8 @@ bindingToHints :: LocalBindingHintRenderer a -> Id -> Maybe String -> Range -> I
557559bindingToHints render id (Just sig) range offset = Just $ render id (T. pack sig) range offset
558560bindingToHints _ _ Nothing _ _ = Nothing
559561
560- renderLocalHints :: MonadIO m => LocalBindingHintRenderer a -> Uri -> IdeState -> ExceptT PluginError m ([a ] |? b )
561- renderLocalHints render uri state = do
562+ renderLocalHints :: MonadIO m => LocalBindingHintRenderer a -> Maybe Range -> Uri -> IdeState -> ExceptT PluginError m ([a ] |? b )
563+ renderLocalHints render visibleRange uri state = do
562564 nfp <- getNormalizedFilePathE uri
563565 (LocalBindingTypeSigsResult (localBindings, sigMap), pm)
564566 <- runActionE " InlayHint.GetWhereBindingTypeSigs" state $ useWithStaleE GetLocalBindingTypeSigs nfp
@@ -576,8 +578,8 @@ renderLocalHints render uri state = do
576578 , bindingSpan `notElem` sigSpans
577579 , Just bindingRange <- maybeToList $ toCurrentRange pm <$> srcSpanToRange bindingLoc
578580 -- Show inlay hints only within visible range
579- -- TODO: there's no "visibleRange" on CodeLens'
580- -- , isSubrangeOf bindingRange visibleRange
581+ -- CodeLenses don't have a visible range
582+ , maybe True ( isSubrangeOf bindingRange) visibleRange
581583 ]
582584 pure $ InL hints
583585
@@ -587,12 +589,12 @@ localBindingCodeLens state plId (CodeLensParams{..}) = do
587589 let uri = _textDocument ^. L. uri
588590 if enabled
589591 then pure $ InL []
590- else renderLocalHints (generateWhereLens plId uri) uri state
592+ else renderLocalHints (generateWhereLens plId uri) Nothing uri state
591593
592594-- | Provide inlay hints for local bindings
593595localBindingInlayHints :: PluginMethodHandler IdeState Method_TextDocumentInlayHint
594- localBindingInlayHints state plId (InlayHintParams _ (TextDocumentIdentifier uri) _ ) = do
596+ localBindingInlayHints state plId (InlayHintParams _ (TextDocumentIdentifier uri) visibleRange ) = do
595597 enabled <- liftIO $ runAction " inlayHint.config" state $ usePropertyAction # localBindingInlayHintOn plId properties
596598 if not enabled
597599 then pure $ InL []
598- else renderLocalHints generateWhereInlayHints uri state
600+ else renderLocalHints generateWhereInlayHints ( Just visibleRange) uri state
0 commit comments