Skip to content

Commit 7c6ebea

Browse files
committed
Handle all Nothings
1 parent 36d9b9f commit 7c6ebea

File tree

1 file changed

+18
-11
lines changed
  • plugins/hls-cabal-plugin/src/Ide/Plugin

1 file changed

+18
-11
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ import Text.Regex.TDFA
6969

7070
import Data.Either.Extra (eitherToMaybe)
7171
import qualified Data.Text ()
72-
import qualified Development.IDE.GHC.Compat as T
73-
import Development.IDE.Spans.Common (spanDocToMarkdown,
74-
spanDocToMarkdownForTest)
72+
import Development.IDE.Spans.Common (spanDocToMarkdownForTest)
7573
import qualified Ide.Plugin.Cabal.CabalAdd as CabalAdd
7674
import Ide.Plugin.Cabal.CabalInfoParser (parseCabalInfo)
7775
import System.Exit (ExitCode (ExitSuccess))
@@ -368,20 +366,23 @@ hover ide _ msgParam = getHoverMessage >>= showHoverMessage
368366
-- ... at the cursor position...
369367
cursorText <- hoistMaybe $ CabalFields.findTextWord cursor cabalFields
370368
-- ... without any version information...
371-
txt <- hoistMaybe $ filterVersion cursorText
369+
packageName <- hoistMaybe $ filterVersion cursorText
372370
-- ... and only if it's a listed depdendency.
373371
gpd <- lift $ runActionE "cabal.GPD" ide $ useE ParseCabalFile nfp
374372
let depsNames = map dependencyName $ allBuildDepends $ flattenPackageDescription gpd
375-
guard $ txt `elem` depsNames
373+
guard $ packageName `elem` depsNames
376374

377-
cabalInfoRaw <- MaybeT $ liftIO $ execCabalInfo txt
378-
cabalInfoData <- hoistMaybe $ eitherToMaybe $ parseCabalInfo cabalInfoRaw
375+
rawCabalInfo <- MaybeT $ liftIO $ execCabalInfo packageName
379376

380-
let fields = cabalInfoData Map.! txt
381-
let description = T.unlines $ fields Map.! "Description"
382-
let descriptionMarkdown = T.pack $ spanDocToMarkdownForTest $ T.unpack description
377+
let cabalInfo = eitherToMaybe $ parseCabalInfo rawCabalInfo
378+
liftIO $ print cabalInfo
383379

384-
pure [txt <> "\n", descriptionMarkdown <> "\n", documentationText txt]
380+
case getDescription rawCabalInfo packageName of
381+
Nothing ->
382+
pure [packageName <> "\n", "Description not available\n", documentationText packageName]
383+
Just description -> do
384+
let descriptionMarkdown = T.pack $ spanDocToMarkdownForTest $ T.unpack description
385+
pure [packageName <> "\n", descriptionMarkdown <> "\n", documentationText packageName]
385386

386387
showHoverMessage = \case
387388
Nothing -> pure $ InR Null
@@ -422,6 +423,12 @@ hover ide _ msgParam = getHoverMessage >>= showHoverMessage
422423
documentationText :: T.Text -> T.Text
423424
documentationText package = "[Documentation](https://hackage.haskell.org/package/" <> package <> ")"
424425

426+
getDescription :: T.Text -> T.Text -> Maybe T.Text
427+
getDescription rawCabalInfo packageName = do
428+
cabalInfo <- eitherToMaybe $ parseCabalInfo rawCabalInfo
429+
pkInfo <- cabalInfo Map.!? packageName
430+
T.unlines <$> pkInfo Map.!? "Description"
431+
425432

426433
-- ----------------------------------------------------------------
427434
-- Cabal file of Interest rules and global variable

0 commit comments

Comments
 (0)