@@ -12,7 +12,9 @@ import Control.Lens ((^.))
12
12
import Control.Monad.Extra
13
13
import Control.Monad.IO.Class
14
14
import Control.Monad.Trans.Class (lift )
15
- import Control.Monad.Trans.Maybe (runMaybeT )
15
+ import Control.Monad.Trans.Maybe (MaybeT (.. ),
16
+ hoistMaybe ,
17
+ runMaybeT )
16
18
import qualified Data.ByteString as BS
17
19
import Data.Hashable
18
20
import Data.HashMap.Strict (HashMap )
@@ -349,22 +351,27 @@ cabalAddCodeAction state plId (CodeActionParams _ _ (TextDocumentIdentifier uri)
349
351
-- If found that the filtered hover message is a dependency,
350
352
-- adds a Documentation link.
351
353
hover :: PluginMethodHandler IdeState LSP. Method_TextDocumentHover
352
- hover ide _ msgParam = do
353
- nfp <- getNormalizedFilePathE uri
354
- cabalFields <- runActionE " cabal.cabal-hover" ide $ useE ParseCabalFields nfp
355
- case CabalFields. findTextWord cursor cabalFields of
356
- Nothing ->
357
- pure $ InR Null
358
- Just cursorText -> do
359
- gpd <- runActionE " cabal.GPD" ide $ useE ParseCabalFile nfp
360
- let depsNames = map dependencyName $ allBuildDepends $ flattenPackageDescription gpd
361
- case filterVersion cursorText of
362
- Nothing -> pure $ InR Null
363
- Just txt ->
364
- if txt `elem` depsNames
365
- then pure $ foundHover (Nothing , [txt <> " \n " , documentationText txt])
366
- else pure $ InR Null
354
+ hover ide _ msgParam = getHoverMessage >>= showHoverMessage
367
355
where
356
+ -- Return the tooltip content for a hovered name...
357
+ getHoverMessage = runMaybeT $ do
358
+ nfp <- lift $ getNormalizedFilePathE uri
359
+ cabalFields <- lift $ runActionE " cabal.cabal-hover" ide $ useE ParseCabalFields nfp
360
+ -- ... at the cursor position...
361
+ cursorText <- hoistMaybe $ CabalFields. findTextWord cursor cabalFields
362
+ -- ... without any version information...
363
+ txt <- hoistMaybe $ filterVersion cursorText
364
+ -- ... and only if it's a listed depdendency.
365
+ gpd <- lift $ runActionE " cabal.GPD" ide $ useE ParseCabalFile nfp
366
+ let depsNames = map dependencyName $ allBuildDepends $ flattenPackageDescription gpd
367
+ guard $ txt `elem` depsNames
368
+
369
+ pure [txt <> " \n " , documentationText txt]
370
+
371
+ showHoverMessage = \ case
372
+ Nothing -> pure $ InR Null
373
+ Just message -> pure $ foundHover (Nothing , message)
374
+
368
375
cursor = Types. lspPositionToCabalPosition (msgParam ^. JL. position)
369
376
uri = msgParam ^. JL. textDocument . JL. uri
370
377
0 commit comments