From: Luke Lau Date: Mon, 16 Jul 2018 23:20:21 +0000 (+0100) Subject: Add getHover X-Git-Tag: 0.1.0.0~30 X-Git-Url: http://git.lukelau.me/?p=lsp-test.git;a=commitdiff_plain;h=0d03bbc4a85a2d625fa663a47bcd079883bf7900 Add getHover --- diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index d4c6311..403c0e1 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -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 diff --git a/test/Test.hs b/test/Test.hs index 0bd7965..e342440 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -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