Add getHover
authorLuke Lau <luke_lau@icloud.com>
Mon, 16 Jul 2018 23:20:21 +0000 (00:20 +0100)
committerLuke Lau <luke_lau@icloud.com>
Mon, 16 Jul 2018 23:20:21 +0000 (00:20 +0100)
src/Language/Haskell/LSP/Test.hs
test/Test.hs

index d4c63110890707bcbb40a2457ffb2ac68b844590..403c0e112600acda919a77656434e8a792f089d8 100644 (file)
@@ -69,6 +69,8 @@ module Language.Haskell.LSP.Test
   , getDefinitions
   -- ** Renaming
   , rename
+  -- ** Hover
+  , getHover
   -- ** Edits
   , applyEdit
   ) where
@@ -459,6 +461,12 @@ rename doc pos newName = do
       req = RequestMessage "" (IdInt 0) WorkspaceApplyEdit (ApplyWorkspaceEditParams wEdit)
   updateState (ReqApplyWorkspaceEdit req)
 
+-- ^ Returns the hover information at the specified position.
+getHover :: TextDocumentIdentifier -> Position -> Session (Maybe Hover)
+getHover doc pos = do
+  let params = TextDocumentPositionParams doc pos
+  getResponseResult <$> sendRequest TextDocumentHover params
+
 -- | Checks the response for errors and throws an exception if needed.
 -- Returns the result if successful.
 getResponseResult :: ResponseMessage a -> a 
index 0bd7965e6c28031b96b83d682420268c36fa420e..e34244041de3fbbdaf36d8973d479cffd0cf287f 100644 (file)
@@ -7,6 +7,7 @@ import           Test.Hspec
 import           Data.Aeson
 import           Data.Default
 import qualified Data.HashMap.Strict as HM
+import           Data.Maybe
 import qualified Data.Text as T
 import           Control.Applicative.Combinators
 import           Control.Concurrent
@@ -259,6 +260,14 @@ main = hspec $ do
       rename doc (Position 1 0) "bar"
       documentContents doc >>= liftIO . shouldBe "main = bar\nbar = return 42\n"
 
+  describe "getHover" $
+    it "works" $ runSession "hie --lsp" "test/data/renamePass" $ do
+      doc <- openDoc "Desktop/simple.hs" "haskell"
+      -- hover returns nothing until module is loaded
+      skipManyTill loggingNotification $ count 2 noDiagnostics
+      hover <- getHover doc (Position 45 9) -- putStrLn
+      liftIO $ hover `shouldSatisfy` isJust
+
 mkRange sl sc el ec = Range (Position sl sc) (Position el ec)
 
 didChangeCaps :: ClientCapabilities