never executed always true always false
    1 module Conjure.LSP.Handlers.Hover where
    2 import Language.LSP.Server (requestHandler, LspM, Handlers)
    3 import Language.LSP.Types
    4 
    5 import Conjure.Prelude
    6 import Data.Text as T (pack)
    7 import Conjure.LSP.Util (getRelevantRegions, withProcessedDoc, ProcessedFile (ProcessedFile), snippet)
    8 import Conjure.Language.Validator (RegionInfo (..), RegionType (..))
    9 import Prettyprinter
   10 
   11 import Conjure.LSP.Documentation ( getDocsForBuiltin)
   12 import qualified Conjure.Language.Pretty as CPr
   13 
   14 hoverHandler :: Handlers (LspM ())
   15 hoverHandler = requestHandler STextDocumentHover $ \ req res -> do
   16     let RequestMessage _ _ _ (HoverParams _doc pos _workDone) = req
   17     let Position _l _c' = pos
   18     withProcessedDoc _doc $ \(ProcessedFile _ _ st _) -> do
   19         let ranges = getRelevantRegions st pos
   20         texts <- mapM prettySymbol ranges
   21         let ms = HoverContents  $ mconcat (catMaybes texts)
   22         let range = Range pos pos
   23         let rsp = Hover ms (Just range)
   24         res (Right $ Just rsp)
   25 
   26 
   27 prettySymbol :: RegionInfo -> LspM () (Maybe MarkupContent)
   28 prettySymbol (RegionInfo _ _ dt _ _) = case dt of
   29     Definition nm ty -> return $ Just . snippet . pack.show $ hcat [pretty $ nm ," : ",pretty.show $ CPr.pretty ty]
   30     LiteralDecl{} -> return Nothing
   31     Ref nm k _ -> return . Just .snippet . pack.show $ hcat [pretty $ nm," : ",pretty.show $ CPr.pretty k] --pack.show $ vcat [hcat [text.unpack $ nm ,":",pretty ty]," Declared : "<> pretty (sourcePosToPosition sp)]
   32     Documentation {} -> liftIO $ getDocsForBuiltin dt
   33     _ -> return Nothing
   34